From 535ac1eb1558807f217c367a456f53c612861dd1 Mon Sep 17 00:00:00 2001 From: Chris Hodapp Date: Sat, 11 Jul 2020 20:00:00 -0400 Subject: [PATCH] Attempt to host (large) JavaScript --- README.md | 6 + resources/public/js/main.js | 361 + resources/public/js/optimized/cljs/core.cljs | 11722 ++ resources/public/js/optimized/cljs/core.js | 37895 +++++++ .../js/optimized/cljs/core/constants.js | 386 + resources/public/js/optimized/cljsc_opts.edn | 1 + .../cljsjs/p5/production/p5.min.inc.js | 90025 ++++++++++++++++ .../public/js/optimized/clojure/string.cljs | 289 + .../public/js/optimized/clojure/string.js | 478 + .../public/js/optimized/curlnoise/core.js | 560 + .../public/js/optimized/goog/array/array.js | 1665 + .../js/optimized/goog/asserts/asserts.js | 369 + resources/public/js/optimized/goog/base.js | 2921 + .../goog/debug/entrypointregistry.js | 159 + .../public/js/optimized/goog/debug/error.js | 63 + .../optimized/goog/disposable/disposable.js | 305 + .../optimized/goog/disposable/idisposable.js | 45 + .../public/js/optimized/goog/dom/asserts.js | 311 + .../js/optimized/goog/dom/browserfeature.js | 73 + resources/public/js/optimized/goog/dom/dom.js | 3233 + .../js/optimized/goog/dom/htmlelement.js | 29 + .../public/js/optimized/goog/dom/nodetype.js | 48 + .../public/js/optimized/goog/dom/safe.js | 458 + .../public/js/optimized/goog/dom/tagname.js | 562 + .../public/js/optimized/goog/dom/tags.js | 41 + .../public/js/optimized/goog/dom/vendor.js | 97 + .../js/optimized/goog/events/browserevent.js | 409 + .../optimized/goog/events/browserfeature.js | 122 + .../public/js/optimized/goog/events/event.js | 143 + .../js/optimized/goog/events/eventid.js | 46 + .../public/js/optimized/goog/events/events.js | 1003 + .../js/optimized/goog/events/eventtype.js | 295 + .../js/optimized/goog/events/listenable.js | 338 + .../js/optimized/goog/events/listener.js | 128 + .../js/optimized/goog/events/listenermap.js | 307 + resources/public/js/optimized/goog/fs/url.js | 106 + .../js/optimized/goog/functions/functions.js | 483 + .../optimized/goog/html/legacyconversions.js | 195 + .../public/js/optimized/goog/html/safehtml.js | 994 + .../js/optimized/goog/html/safescript.js | 234 + .../js/optimized/goog/html/safestyle.js | 560 + .../js/optimized/goog/html/safestylesheet.js | 344 + .../public/js/optimized/goog/html/safeurl.js | 454 + .../optimized/goog/html/trustedresourceurl.js | 408 + .../goog/html/uncheckedconversions.js | 228 + .../public/js/optimized/goog/i18n/bidi.js | 876 + .../public/js/optimized/goog/iter/iter.js | 1284 + .../optimized/goog/labs/useragent/browser.js | 338 + .../optimized/goog/labs/useragent/engine.js | 156 + .../optimized/goog/labs/useragent/platform.js | 160 + .../js/optimized/goog/labs/useragent/util.js | 147 + .../public/js/optimized/goog/math/box.js | 402 + .../js/optimized/goog/math/coordinate.js | 279 + .../public/js/optimized/goog/math/integer.js | 808 + .../public/js/optimized/goog/math/irect.js | 45 + .../public/js/optimized/goog/math/long.js | 965 + .../public/js/optimized/goog/math/math.js | 448 + .../public/js/optimized/goog/math/rect.js | 477 + .../public/js/optimized/goog/math/size.js | 227 + .../public/js/optimized/goog/object/object.js | 751 + .../js/optimized/goog/reflect/reflect.js | 138 + .../public/js/optimized/goog/string/const.js | 186 + .../public/js/optimized/goog/string/string.js | 1641 + .../js/optimized/goog/string/stringbuffer.js | 103 + .../js/optimized/goog/string/typedstring.js | 48 + .../public/js/optimized/goog/structs/map.js | 458 + .../js/optimized/goog/structs/structs.js | 354 + .../public/js/optimized/goog/style/style.js | 2071 + resources/public/js/optimized/goog/uri/uri.js | 1547 + .../public/js/optimized/goog/uri/utils.js | 1103 + .../js/optimized/goog/useragent/useragent.js | 580 + .../public/js/optimized/process/env.cljs | 12 + resources/public/js/optimized/process/env.js | 7 + resources/public/js/optimized/quil/core.cljc | 5066 + resources/public/js/optimized/quil/core.js | 4963 + .../public/js/optimized/quil/middleware.cljc | 143 + .../public/js/optimized/quil/middleware.js | 118 + .../quil/middlewares/deprecated_options.cljc | 26 + .../quil/middlewares/deprecated_options.js | 96 + .../optimized/quil/middlewares/fun_mode.cljc | 78 + .../js/optimized/quil/middlewares/fun_mode.js | 142 + .../quil/middlewares/navigation_2d.cljc | 89 + .../quil/middlewares/navigation_2d.js | 119 + .../quil/middlewares/navigation_3d.cljc | 188 + .../quil/middlewares/navigation_3d.js | 282 + .../public/js/optimized/quil/sketch.cljs | 191 + resources/public/js/optimized/quil/sketch.js | 483 + resources/public/js/optimized/quil/util.cljc | 131 + resources/public/js/optimized/quil/util.js | 190 + 89 files changed, 186815 insertions(+) create mode 100644 resources/public/js/main.js create mode 100644 resources/public/js/optimized/cljs/core.cljs create mode 100644 resources/public/js/optimized/cljs/core.js create mode 100644 resources/public/js/optimized/cljs/core/constants.js create mode 100644 resources/public/js/optimized/cljsc_opts.edn create mode 100644 resources/public/js/optimized/cljsjs/p5/production/p5.min.inc.js create mode 100644 resources/public/js/optimized/clojure/string.cljs create mode 100644 resources/public/js/optimized/clojure/string.js create mode 100644 resources/public/js/optimized/curlnoise/core.js create mode 100644 resources/public/js/optimized/goog/array/array.js create mode 100644 resources/public/js/optimized/goog/asserts/asserts.js create mode 100644 resources/public/js/optimized/goog/base.js create mode 100644 resources/public/js/optimized/goog/debug/entrypointregistry.js create mode 100644 resources/public/js/optimized/goog/debug/error.js create mode 100644 resources/public/js/optimized/goog/disposable/disposable.js create mode 100644 resources/public/js/optimized/goog/disposable/idisposable.js create mode 100644 resources/public/js/optimized/goog/dom/asserts.js create mode 100644 resources/public/js/optimized/goog/dom/browserfeature.js create mode 100644 resources/public/js/optimized/goog/dom/dom.js create mode 100644 resources/public/js/optimized/goog/dom/htmlelement.js create mode 100644 resources/public/js/optimized/goog/dom/nodetype.js create mode 100644 resources/public/js/optimized/goog/dom/safe.js create mode 100644 resources/public/js/optimized/goog/dom/tagname.js create mode 100644 resources/public/js/optimized/goog/dom/tags.js create mode 100644 resources/public/js/optimized/goog/dom/vendor.js create mode 100644 resources/public/js/optimized/goog/events/browserevent.js create mode 100644 resources/public/js/optimized/goog/events/browserfeature.js create mode 100644 resources/public/js/optimized/goog/events/event.js create mode 100644 resources/public/js/optimized/goog/events/eventid.js create mode 100644 resources/public/js/optimized/goog/events/events.js create mode 100644 resources/public/js/optimized/goog/events/eventtype.js create mode 100644 resources/public/js/optimized/goog/events/listenable.js create mode 100644 resources/public/js/optimized/goog/events/listener.js create mode 100644 resources/public/js/optimized/goog/events/listenermap.js create mode 100644 resources/public/js/optimized/goog/fs/url.js create mode 100644 resources/public/js/optimized/goog/functions/functions.js create mode 100644 resources/public/js/optimized/goog/html/legacyconversions.js create mode 100644 resources/public/js/optimized/goog/html/safehtml.js create mode 100644 resources/public/js/optimized/goog/html/safescript.js create mode 100644 resources/public/js/optimized/goog/html/safestyle.js create mode 100644 resources/public/js/optimized/goog/html/safestylesheet.js create mode 100644 resources/public/js/optimized/goog/html/safeurl.js create mode 100644 resources/public/js/optimized/goog/html/trustedresourceurl.js create mode 100644 resources/public/js/optimized/goog/html/uncheckedconversions.js create mode 100644 resources/public/js/optimized/goog/i18n/bidi.js create mode 100644 resources/public/js/optimized/goog/iter/iter.js create mode 100644 resources/public/js/optimized/goog/labs/useragent/browser.js create mode 100644 resources/public/js/optimized/goog/labs/useragent/engine.js create mode 100644 resources/public/js/optimized/goog/labs/useragent/platform.js create mode 100644 resources/public/js/optimized/goog/labs/useragent/util.js create mode 100644 resources/public/js/optimized/goog/math/box.js create mode 100644 resources/public/js/optimized/goog/math/coordinate.js create mode 100644 resources/public/js/optimized/goog/math/integer.js create mode 100644 resources/public/js/optimized/goog/math/irect.js create mode 100644 resources/public/js/optimized/goog/math/long.js create mode 100644 resources/public/js/optimized/goog/math/math.js create mode 100644 resources/public/js/optimized/goog/math/rect.js create mode 100644 resources/public/js/optimized/goog/math/size.js create mode 100644 resources/public/js/optimized/goog/object/object.js create mode 100644 resources/public/js/optimized/goog/reflect/reflect.js create mode 100644 resources/public/js/optimized/goog/string/const.js create mode 100644 resources/public/js/optimized/goog/string/string.js create mode 100644 resources/public/js/optimized/goog/string/stringbuffer.js create mode 100644 resources/public/js/optimized/goog/string/typedstring.js create mode 100644 resources/public/js/optimized/goog/structs/map.js create mode 100644 resources/public/js/optimized/goog/structs/structs.js create mode 100644 resources/public/js/optimized/goog/style/style.js create mode 100644 resources/public/js/optimized/goog/uri/uri.js create mode 100644 resources/public/js/optimized/goog/uri/utils.js create mode 100644 resources/public/js/optimized/goog/useragent/useragent.js create mode 100644 resources/public/js/optimized/process/env.cljs create mode 100644 resources/public/js/optimized/process/env.js create mode 100644 resources/public/js/optimized/quil/core.cljc create mode 100644 resources/public/js/optimized/quil/core.js create mode 100644 resources/public/js/optimized/quil/middleware.cljc create mode 100644 resources/public/js/optimized/quil/middleware.js create mode 100644 resources/public/js/optimized/quil/middlewares/deprecated_options.cljc create mode 100644 resources/public/js/optimized/quil/middlewares/deprecated_options.js create mode 100644 resources/public/js/optimized/quil/middlewares/fun_mode.cljc create mode 100644 resources/public/js/optimized/quil/middlewares/fun_mode.js create mode 100644 resources/public/js/optimized/quil/middlewares/navigation_2d.cljc create mode 100644 resources/public/js/optimized/quil/middlewares/navigation_2d.js create mode 100644 resources/public/js/optimized/quil/middlewares/navigation_3d.cljc create mode 100644 resources/public/js/optimized/quil/middlewares/navigation_3d.js create mode 100644 resources/public/js/optimized/quil/sketch.cljs create mode 100644 resources/public/js/optimized/quil/sketch.js create mode 100644 resources/public/js/optimized/quil/util.cljc create mode 100644 resources/public/js/optimized/quil/util.js diff --git a/README.md b/README.md index c8f1f70..d9f5605 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,12 @@ Uncomment the `(run-sketch)` and the below should work: - Emacs - run cider, open `core.clj` and press `C-c C-k` to evaluate the file. - REPL - run `(require 'quil_perlin.core)`. +## Demo + +See +[here](https://cdn.jsdelivr.net/gh/hodapp87/curlnoise@master/resources/public/index.html) +to run the ClojureScript version in the browser. + ## TODO - Better docs. diff --git a/resources/public/js/main.js b/resources/public/js/main.js new file mode 100644 index 0000000..e67a6af --- /dev/null +++ b/resources/public/js/main.js @@ -0,0 +1,361 @@ +if(typeof Math.imul == "undefined" || (Math.imul(0xffffffff,5) == 0)) { + Math.imul = function (a, b) { + var ah = (a >>> 16) & 0xffff; + var al = a & 0xffff; + var bh = (b >>> 16) & 0xffff; + var bl = b & 0xffff; + // the shift by 0 fixes the sign on the high part + // the final |0 converts the unsigned value into a signed value + return ((al * bl) + (((ah * bl + al * bh) << 16) >>> 0)|0); + } +} + +/*! p5.js v0.9.0 July 01, 2019 */ + +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).p5=e()}}(function(){return function o(a,s,h){function l(t,e){if(!s[t]){if(!a[t]){var r="function"==typeof require&&require;if(!e&&r)return r(t,!0);if(u)return u(t,!0);var i=new Error("Cannot find module '"+t+"'");throw i.code="MODULE_NOT_FOUND",i}var n=s[t]={exports:{}};a[t][0].call(n.exports,function(e){return l(a[t][1][e]||e)},n,n.exports,o,a,s,h)}return s[t].exports}for(var u="function"==typeof require&&require,e=0;e>16&255,o[a++]=t>>8&255,o[a++]=255&t;var l,u;2===n&&(t=c[e.charCodeAt(h)]<<2|c[e.charCodeAt(h+1)]>>4,o[a++]=255&t);1===n&&(t=c[e.charCodeAt(h)]<<10|c[e.charCodeAt(h+1)]<<4|c[e.charCodeAt(h+2)]>>2,o[a++]=t>>8&255,o[a++]=255&t);return o},r.fromByteArray=function(e){for(var t,r=e.length,i=r%3,n=[],o=0,a=r-i;o>2]+s[t<<4&63]+"==")):2===i&&(t=(e[r-2]<<8)+e[r-1],n.push(s[t>>10]+s[t>>4&63]+s[t<<2&63]+"="));return n.join("")};for(var s=[],c=[],p="undefined"!=typeof Uint8Array?Uint8Array:Array,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=0,o=i.length;n>18&63]+s[n>>12&63]+s[n>>6&63]+s[63&n]);return o.join("")}c["-".charCodeAt(0)]=62,c["_".charCodeAt(0)]=63},{}],2:[function(e,t,r){},{}],3:[function(e,t,r){"use strict";var i=e("base64-js"),o=e("ieee754");r.Buffer=c,r.SlowBuffer=function(e){+e!=e&&(e=0);return c.alloc(+e)},r.INSPECT_MAX_BYTES=50;var n=2147483647;function a(e){if(n>>1;case"base64":return A(e).length;default:if(n)return i?-1:k(e).length;t=(""+t).toLowerCase(),n=!0}}function f(e,t,r){var i=e[t];e[t]=e[r],e[r]=i}function m(e,t,r,i,n){if(0===e.length)return-1;if("string"==typeof r?(i=r,r=0):2147483647=e.length){if(n)return-1;r=e.length-1}else if(r<0){if(!n)return-1;r=0}if("string"==typeof t&&(t=c.from(t,i)),c.isBuffer(t))return 0===t.length?-1:v(e,t,r,i,n);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?n?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):v(e,[t],r,i,n);throw new TypeError("val must be string, number or Buffer")}function v(e,t,r,i,n){var o,a=1,s=e.length,h=t.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(e.length<2||t.length<2)return-1;s/=a=2,h/=2,r/=2}function l(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}if(n){var u=-1;for(o=r;o>>10&1023|55296),u=56320|1023&u),i.push(u),n+=c}return function(e){var t=e.length;if(t<=x)return String.fromCharCode.apply(String,e);var r="",i=0;for(;ithis.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return T(this,t,r);case"utf8":case"utf-8":return _(this,t,r);case"ascii":return w(this,t,r);case"latin1":case"binary":return S(this,t,r);case"base64":return b(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return M(this,t,r);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}.apply(this,arguments)},c.prototype.equals=function(e){if(!c.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===c.compare(this,e)},c.prototype.inspect=function(){var e="",t=r.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),""},c.prototype.compare=function(e,t,r,i,n){if(O(e,Uint8Array)&&(e=c.from(e,e.offset,e.byteLength)),!c.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===i&&(i=0),void 0===n&&(n=this.length),t<0||r>e.length||i<0||n>this.length)throw new RangeError("out of range index");if(n<=i&&r<=t)return 0;if(n<=i)return-1;if(r<=t)return 1;if(this===e)return 0;for(var o=(n>>>=0)-(i>>>=0),a=(r>>>=0)-(t>>>=0),s=Math.min(o,a),h=this.slice(i,n),l=e.slice(t,r),u=0;u>>=0,isFinite(r)?(r>>>=0,void 0===i&&(i="utf8")):(i=r,r=void 0)}var n=this.length-t;if((void 0===r||nthis.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var o,a,s,h,l,u,c,p,d,f=!1;;)switch(i){case"hex":return g(this,e,t,r);case"utf8":case"utf-8":return p=t,d=r,U(k(e,(c=this).length-p),c,p,d);case"ascii":return y(this,e,t,r);case"latin1":case"binary":return y(this,e,t,r);case"base64":return h=this,l=t,u=r,U(A(e),h,l,u);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return a=t,s=r,U(function(e,t){for(var r,i,n,o=[],a=0;a>8,n=r%256,o.push(n),o.push(i);return o}(e,(o=this).length-a),o,a,s);default:if(f)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),f=!0}},c.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var x=4096;function w(e,t,r){var i="";r=Math.min(e.length,r);for(var n=t;ne.length)throw new RangeError("Index out of range")}function R(e,t,r,i,n,o){if(r+i>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(e,t,r,i,n){return t=+t,r>>>=0,n||R(e,0,r,4),o.write(e,t,r,i,23,4),r+4}function D(e,t,r,i,n){return t=+t,r>>>=0,n||R(e,0,r,8),o.write(e,t,r,i,52,8),r+8}c.prototype.slice=function(e,t){var r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):r>>=0,t>>>=0,r||E(e,t,this.length);for(var i=this[e],n=1,o=0;++o>>=0,t>>>=0,r||E(e,t,this.length);for(var i=this[e+--t],n=1;0>>=0,t||E(e,1,this.length),this[e]},c.prototype.readUInt16LE=function(e,t){return e>>>=0,t||E(e,2,this.length),this[e]|this[e+1]<<8},c.prototype.readUInt16BE=function(e,t){return e>>>=0,t||E(e,2,this.length),this[e]<<8|this[e+1]},c.prototype.readUInt32LE=function(e,t){return e>>>=0,t||E(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},c.prototype.readUInt32BE=function(e,t){return e>>>=0,t||E(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},c.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||E(e,t,this.length);for(var i=this[e],n=1,o=0;++o>>=0,t>>>=0,r||E(e,t,this.length);for(var i=t,n=1,o=this[e+--i];0>>=0,t||E(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},c.prototype.readInt16LE=function(e,t){e>>>=0,t||E(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt16BE=function(e,t){e>>>=0,t||E(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},c.prototype.readInt32LE=function(e,t){return e>>>=0,t||E(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},c.prototype.readInt32BE=function(e,t){return e>>>=0,t||E(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},c.prototype.readFloatLE=function(e,t){return e>>>=0,t||E(e,4,this.length),o.read(this,e,!0,23,4)},c.prototype.readFloatBE=function(e,t){return e>>>=0,t||E(e,4,this.length),o.read(this,e,!1,23,4)},c.prototype.readDoubleLE=function(e,t){return e>>>=0,t||E(e,8,this.length),o.read(this,e,!0,52,8)},c.prototype.readDoubleBE=function(e,t){return e>>>=0,t||E(e,8,this.length),o.read(this,e,!1,52,8)},c.prototype.writeUIntLE=function(e,t,r,i){(e=+e,t>>>=0,r>>>=0,i)||C(this,e,t,r,Math.pow(2,8*r)-1,0);var n=1,o=0;for(this[t]=255&e;++o>>=0,r>>>=0,i)||C(this,e,t,r,Math.pow(2,8*r)-1,0);var n=r-1,o=1;for(this[t+n]=255&e;0<=--n&&(o*=256);)this[t+n]=e/o&255;return t+r},c.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,1,255,0),this[t]=255&e,t+1},c.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},c.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeIntLE=function(e,t,r,i){if(e=+e,t>>>=0,!i){var n=Math.pow(2,8*r-1);C(this,e,t,r,n-1,-n)}var o=0,a=1,s=0;for(this[t]=255&e;++o>0)-s&255;return t+r},c.prototype.writeIntBE=function(e,t,r,i){if(e=+e,t>>>=0,!i){var n=Math.pow(2,8*r-1);C(this,e,t,r,n-1,-n)}var o=r-1,a=1,s=0;for(this[t+o]=255&e;0<=--o&&(a*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/a>>0)-s&255;return t+r},c.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},c.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},c.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},c.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},c.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||C(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},c.prototype.writeFloatLE=function(e,t,r){return L(this,e,t,!0,r)},c.prototype.writeFloatBE=function(e,t,r){return L(this,e,t,!1,r)},c.prototype.writeDoubleLE=function(e,t,r){return D(this,e,t,!0,r)},c.prototype.writeDoubleBE=function(e,t,r){return D(this,e,t,!1,r)},c.prototype.copy=function(e,t,r,i){if(!c.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),i||0===i||(i=this.length),t>=e.length&&(t=e.length),t||(t=0),0=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(o=t;o>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function A(e){return i.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(P,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function U(e,t,r,i){for(var n=0;n=t.length||n>=e.length);++n)t[n+r]=e[n];return n}function O(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function B(e){return e!=e}},{"base64-js":1,ieee754:7}],4:[function(z,r,i){(function(F,V){var e,t;e=this,t=function(){"use strict";function l(e){return"function"==typeof e}var r=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},i=0,t=void 0,n=void 0,s=function(e,t){p[i]=e,p[i+1]=t,2===(i+=2)&&(n?n(d):y())};var e="undefined"!=typeof window?window:void 0,o=e||{},a=o.MutationObserver||o.WebKitMutationObserver,h="undefined"==typeof self&&void 0!==F&&"[object process]"==={}.toString.call(F),u="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel;function c(){var e=setTimeout;return function(){return e(d,1)}}var p=new Array(1e3);function d(){for(var e=0;e>1,u=-7,c=r?n-1:0,p=r?-1:1,d=e[t+c];for(c+=p,o=d&(1<<-u)-1,d>>=-u,u+=s;0>=-u,u+=i;0>1,p=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,d=i?0:o-1,f=i?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,a=u):(a=Math.floor(Math.log(t)/Math.LN2),t*(h=Math.pow(2,-a))<1&&(a--,h*=2),2<=(t+=1<=a+c?p/h:p*Math.pow(2,1-c))*h&&(a++,h/=2),u<=a+c?(s=0,a=u):1<=a+c?(s=(t*h-1)*Math.pow(2,n),a+=c):(s=t*Math.pow(2,c-1)*Math.pow(2,n),a=0));8<=n;e[r+d]=255&s,d+=f,s/=256,n-=8);for(a=a<Math.abs(e[0])&&(t=1),Math.abs(e[2])>Math.abs(e[t])&&(t=2),t}var C=4e150;function R(e,t){e.f+=t.f,e.b.f+=t.b.f}function l(e,t,r){return e=e.a,t=t.a,r=r.a,t.b.a===e?r.b.a===e?g(t.a,r.a)?b(r.b.a,t.a,r.a)<=0:0<=b(t.b.a,r.a,t.a):b(r.b.a,e,r.a)<=0:r.b.a===e?0<=b(t.b.a,e,t.a):(t=y(t.b.a,e,t.a),(e=y(r.b.a,e,r.a))<=t)}function L(e){e.a.i=null;var t=e.e;t.a.c=t.c,t.c.a=t.a,e.e=null}function u(e,t){c(e.a),e.c=!1,(e.a=t).i=e}function D(e){for(var t=e.a.a;(e=pe(e)).a.a===t;);return e.c&&(u(e,t=p(ce(e).a.b,e.a.e)),e=pe(e)),e}function P(e,t,r){var i=new ue;return i.a=r,i.e=X(e.f,t.e,i),r.i=i}function I(e,t){switch(e.s){case 100130:return 0!=(1&t);case 100131:return 0!==t;case 100132:return 0>1]],s[a[l]])?he(r,l):le(r,l)),s[o]=null,h[o]=r.b,r.b=o}else for(r.c[-(o+1)]=null;0Math.max(a.a,h.a))return!1;if(g(o,a)){if(0i.f&&(i.f*=2,i.c=oe(i.c,i.f+1)),0===i.b?r=n:(r=i.b,i.b=i.c[i.b]),i.e[r]=t,i.c[r]=n,i.d[n]=r,i.h&&le(i,n),r}return i=e.a++,e.c[i]=t,-(i+1)}function ie(e){if(0===e.a)return se(e.b);var t=e.c[e.d[e.a-1]];if(0!==e.b.a&&g(ae(e.b),t))return se(e.b);for(;--e.a,0e.a||g(i[a],i[h])){n[r[o]=a]=o;break}n[r[o]=h]=o,o=s}}function le(e,t){for(var r=e.d,i=e.e,n=e.c,o=t,a=r[o];;){var s=o>>1,h=r[s];if(0===s||g(i[h],i[a])){n[r[o]=a]=o;break}n[r[o]=h]=o,o=s}}function ue(){this.e=this.a=null,this.f=0,this.c=this.b=this.h=this.d=!1}function ce(e){return e.e.c.b}function pe(e){return e.e.a.b}(i=q.prototype).x=function(){Y(this,0)},i.B=function(e,t){switch(e){case 100142:return;case 100140:switch(t){case 100130:case 100131:case 100132:case 100133:case 100134:return void(this.s=t)}break;case 100141:return void(this.m=!!t);default:return void Z(this,100900)}Z(this,100901)},i.y=function(e){switch(e){case 100142:return 0;case 100140:return this.s;case 100141:return this.m;default:Z(this,100900)}return!1},i.A=function(e,t,r){this.j[0]=e,this.j[1]=t,this.j[2]=r},i.z=function(e,t){var r=t||null;switch(e){case 100100:case 100106:this.h=r;break;case 100104:case 100110:this.l=r;break;case 100101:case 100107:this.k=r;break;case 100102:case 100108:this.i=r;break;case 100103:case 100109:this.p=r;break;case 100105:case 100111:this.o=r;break;case 100112:this.r=r;break;default:Z(this,100900)}},i.C=function(e,t){var r=!1,i=[0,0,0];Y(this,2);for(var n=0;n<3;++n){var o=e[n];o<-1e150&&(o=-1e150,r=!0),1e150n[l]&&(n[l]=u,a[l]=h)}if(h=0,n[1]-o[1]>n[0]-o[0]&&(h=1),n[2]-o[2]>n[h]-o[h]&&(h=2),o[h]>=n[h])i[0]=0,i[1]=0,i[2]=1;else{for(n=0,o=s[h],a=a[h],s=[0,0,0],o=[o.g[0]-a.g[0],o.g[1]-a.g[1],o.g[2]-a.g[2]],l=[0,0,0],h=r.e;h!==r;h=h.e)l[0]=h.g[0]-a.g[0],l[1]=h.g[1]-a.g[1],l[2]=h.g[2]-a.g[2],s[0]=o[1]*l[2]-o[2]*l[1],s[1]=o[2]*l[0]-o[0]*l[2],s[2]=o[0]*l[1]-o[1]*l[0],n<(u=s[0]*s[0]+s[1]*s[1]+s[2]*s[2])&&(n=u,i[0]=s[0],i[1]=s[1],i[2]=s[2]);n<=0&&(i[0]=i[1]=i[2]=0,i[E(o)]=1)}r=!0}for(s=E(i),h=this.b.c,n=(s+1)%3,a=(s+2)%3,s=0>>=1,t}function _(e,t,r){if(!t)return r;for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>16-t;return e.tag>>>=t,e.bitcount-=t,i+r}function x(e,t){for(;e.bitcount<24;)e.tag|=e.source[e.sourceIndex++]<>>=1,++n,r+=t.table[n],0<=(i-=t.table[n]););return e.tag=o,e.bitcount-=n,t.trans[r+i]}function w(e,t,r){var i,n,o,a,s,h;for(i=_(e,5,257),n=_(e,5,1),o=_(e,4,4),a=0;a<19;++a)v[a]=0;for(a=0;athis.x2&&(this.x2=e)),"number"==typeof t&&((isNaN(this.y1)||isNaN(this.y2))&&(this.y1=t,this.y2=t),tthis.y2&&(this.y2=t))},C.prototype.addX=function(e){this.addPoint(e,null)},C.prototype.addY=function(e){this.addPoint(null,e)},C.prototype.addBezier=function(e,t,r,i,n,o,a,s){var h=this,l=[e,t],u=[r,i],c=[n,o],p=[a,s];this.addPoint(e,t),this.addPoint(a,s);for(var d=0;d<=1;d++){var f=6*l[d]-12*u[d]+6*c[d],m=-3*l[d]+9*u[d]-9*c[d]+3*p[d],v=3*u[d]-3*l[d];if(0!==m){var g=Math.pow(f,2)-4*v*m;if(!(g<0)){var y=(-f+Math.sqrt(g))/(2*m);0>8&255,255&e]},A.USHORT=O(2),k.SHORT=function(e){return 32768<=e&&(e=-(65536-e)),[e>>8&255,255&e]},A.SHORT=O(2),k.UINT24=function(e){return[e>>16&255,e>>8&255,255&e]},A.UINT24=O(3),k.ULONG=function(e){return[e>>24&255,e>>16&255,e>>8&255,255&e]},A.ULONG=O(4),k.LONG=function(e){return P<=e&&(e=-(2*P-e)),[e>>24&255,e>>16&255,e>>8&255,255&e]},A.LONG=O(4),k.FIXED=k.ULONG,A.FIXED=A.ULONG,k.FWORD=k.SHORT,A.FWORD=A.SHORT,k.UFWORD=k.USHORT,A.UFWORD=A.USHORT,k.LONGDATETIME=function(e){return[0,0,0,0,e>>24&255,e>>16&255,e>>8&255,255&e]},A.LONGDATETIME=O(8),k.TAG=function(e){return D.argument(4===e.length,"Tag should be exactly 4 ASCII characters."),[e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3)]},A.TAG=O(4),k.Card8=k.BYTE,A.Card8=A.BYTE,k.Card16=k.USHORT,A.Card16=A.USHORT,k.OffSize=k.BYTE,A.OffSize=A.BYTE,k.SID=k.USHORT,A.SID=A.USHORT,k.NUMBER=function(e){return-107<=e&&e<=107?[e+139]:108<=e&&e<=1131?[247+((e-=108)>>8),255&e]:-1131<=e&&e<=-108?[251+((e=-e-108)>>8),255&e]:-32768<=e&&e<=32767?k.NUMBER16(e):k.NUMBER32(e)},A.NUMBER=function(e){return k.NUMBER(e).length},k.NUMBER16=function(e){return[28,e>>8&255,255&e]},A.NUMBER16=O(3),k.NUMBER32=function(e){return[29,e>>24&255,e>>16&255,e>>8&255,255&e]},A.NUMBER32=O(5),k.REAL=function(e){var t=e.toString(),r=/\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(t);if(r){var i=parseFloat("1e"+((r[2]?+r[2]:0)+r[1].length));t=(Math.round(e*i)/i).toString()}for(var n="",o=0,a=t.length;o>8&255,t[t.length]=255&i}return t},A.UTF16=function(e){return 2*e.length};var B={"x-mac-croatian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø¿¡¬√ƒ≈ƫȅ ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ","x-mac-cyrillic":"АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњјЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю","x-mac-gaelic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæøṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ","x-mac-greek":"Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩάΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ­","x-mac-icelandic":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüݰ¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-inuit":"ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł","x-mac-ce":"ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ",macintosh:"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-romanian":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ","x-mac-turkish":"ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ"};I.MACSTRING=function(e,t,r,i){var n=B[i];if(void 0!==n){for(var o="",a=0;a>8&255,h+256&255)}return o}k.MACSTRING=function(e,t){var r=function(e){if(!N)for(var t in N={},B)N[t]=new String(t);var r=N[e];if(void 0!==r){if(G){var i=G.get(r);if(void 0!==i)return i}var n=B[e];if(void 0!==n){for(var o={},a=0;a>8,t[c+1]=255&p,t=t.concat(i[u])}return t},A.TABLE=function(e){for(var t=0,r=e.fields.length,i=0;i>1,t.skip("uShort",3),e.glyphIndexMap={};for(var a=new se.Parser(r,i+n+14),s=new se.Parser(r,i+n+16+2*o),h=new se.Parser(r,i+n+16+4*o),l=new se.Parser(r,i+n+16+6*o),u=i+n+16+8*o,c=0;c>4,o=15&i;if(15===n)break;if(t+=r[n],15===o)break;t+=r[o]}return parseFloat(t)}(e);if(32<=t&&t<=246)return t-139;if(247<=t&&t<=250)return 256*(t-247)+e.parseByte()+108;if(251<=t&&t<=254)return 256*-(t-251)-e.parseByte()-108;throw new Error("Invalid b0 "+t)}function Ee(e,t,r){t=void 0!==t?t:0;var i=new se.Parser(e,t),n=[],o=[];for(r=void 0!==r?r:e.length;i.relativeOffset>1,E.length=0,R=!0}return function e(t){for(var r,i,n,o,a,s,h,l,u,c,p,d,f=0;fMath.abs(d-P)?D=p+E.shift():P=d+E.shift(),M.curveTo(y,b,_,x,h,l),M.curveTo(u,c,p,d,D,P);break;default:console.log("Glyph "+g.index+": unknown operator 1200"+m),E.length=0}break;case 14:0>3;break;case 21:2>16),f+=2;break;case 29:a=E.pop()+v.gsubrsBias,(s=v.gsubrs[a])&&e(s);break;case 30:for(;0=r.begin&&e=pe.length){var a=i.parseChar();r.names.push(i.parseString(a))}break;case 2.5:r.numberOfGlyphs=i.parseUShort(),r.offset=new Array(r.numberOfGlyphs);for(var s=0;st.value.tag?1:-1}),t.fields=t.fields.concat(i),t.fields=t.fields.concat(n),t}function vt(e,t,r){for(var i=0;i 123 are reserved for internal usage");d|=1<>>1,o=e[n].tag;if(o===t)return n;o>>1,o=e[n];if(o===t)return n;o>>1,a=(r=e[o]).start;if(a===t)return r;a(r=e[i-1]).end?0:r}function xt(e,t){this.font=e,this.tableName=t}function wt(e){xt.call(this,e,"gpos")}function St(e){xt.call(this,e,"gsub")}function Tt(e,t){var r=e.length;if(r!==t.length)return!1;for(var i=0;it.points.length-1||i.matchedPoints[1]>n.points.length-1)throw Error("Matched points out of range in "+t.name);var a=t.points[i.matchedPoints[0]],s=n.points[i.matchedPoints[1]],h={xScale:i.xScale,scale01:i.scale01,scale10:i.scale10,yScale:i.yScale,dx:0,dy:0};s=Dt([s],h)[0],h.dx=a.x-s.x,h.dy=a.y-s.y,o=Dt(n.points,h)}t.points=t.points.concat(o)}}return Pt(t.points)}(wt.prototype=xt.prototype={searchTag:yt,binSearch:bt,getTable:function(e){var t=this.font.tables[this.tableName];return!t&&e&&(t=this.font.tables[this.tableName]=this.createDefaultTable()),t},getScriptNames:function(){var e=this.getTable();return e?e.scripts.map(function(e){return e.tag}):[]},getDefaultScriptName:function(){var e=this.getTable();if(e){for(var t=!1,r=0;r=s[l-1].tag,"Features must be added in alphabetical order."),o={tag:r,feature:{params:0,lookupListIndexes:[]}},s.push(o),a.push(l),o.feature}}},getLookupTables:function(e,t,r,i,n){var o=this.getFeatureTable(e,t,r,n),a=[];if(o){for(var s,h=o.lookupListIndexes,l=this.font.tables[this.tableName].lookups,u=0;u",s),t.stack.push(Math.round(64*s))}function gr(e,t){var r=t.stack,i=r.pop(),n=t.fv,o=t.pv,a=t.ppem,s=t.deltaBase+16*(e-1),h=t.deltaShift,l=t.z0;M.DEBUG&&console.log(t.step,"DELTAP["+e+"]",i,r);for(var u=0;u>4)===a){var d=(15&p)-8;0<=d&&d++,M.DEBUG&&console.log(t.step,"DELTAPFIX",c,"by",d*h);var f=l[c];n.setRelative(f,f,d*h,o)}}}function yr(e,t){var r=t.stack,i=r.pop();M.DEBUG&&console.log(t.step,"ROUND[]"),r.push(64*t.round(i/64))}function br(e,t){var r=t.stack,i=r.pop(),n=t.ppem,o=t.deltaBase+16*(e-1),a=t.deltaShift;M.DEBUG&&console.log(t.step,"DELTAC["+e+"]",i,r);for(var s=0;s>4)===n){var u=(15&l)-8;0<=u&&u++;var c=u*a;M.DEBUG&&console.log(t.step,"DELTACFIX",h,"by",c),t.cvt[h]+=c}}}function _r(e,t){var r,i,n=t.stack,o=n.pop(),a=n.pop(),s=t.z2[o],h=t.z1[a];M.DEBUG&&console.log(t.step,"SDPVTL["+e+"]",o,a),i=e?(r=s.y-h.y,h.x-s.x):(r=h.x-s.x,h.y-s.y),t.dpv=Zt(r,i)}function xr(e,t){var r=t.stack,i=t.prog,n=t.ip;M.DEBUG&&console.log(t.step,"PUSHB["+e+"]");for(var o=0;o":"_")+(i?"R":"_")+(0===n?"Gr":1===n?"Bl":2===n?"Wh":"")+"]",e?c+"("+o.cvt[c]+","+l+")":"",p,"(d =",a,"->",h*s,")"),o.rp1=o.rp0,o.rp2=p,t&&(o.rp0=p)}Nt.prototype.exec=function(e,t){if("number"!=typeof t)throw new Error("Point size is not a number!");if(!(2",i),s.interpolate(c,o,a,h),s.touch(c)}e.loop=1},dr.bind(void 0,0),dr.bind(void 0,1),function(e){for(var t=e.stack,r=e.rp0,i=e.z0[r],n=e.loop,o=e.fv,a=e.pv,s=e.z1;n--;){var h=t.pop(),l=s[h];M.DEBUG&&console.log(e.step,(1=a.width||t>=a.height?[0,0,0,0]:this._getPixel(e,t);var s=new h.Image(r,i);return s.canvas.getContext("2d").drawImage(a,e,t,r*o,i*o,0,0,r,i),s},h.Renderer.prototype.textLeading=function(e){return"number"==typeof e?(this._setProperty("_textLeading",e),this._pInst):this._textLeading},h.Renderer.prototype.textSize=function(e){return"number"==typeof e?(this._setProperty("_textSize",e),this._setProperty("_textLeading",e*y._DEFAULT_LEADMULT),this._applyTextProperties()):this._textSize},h.Renderer.prototype.textStyle=function(e){return e?(e!==y.NORMAL&&e!==y.ITALIC&&e!==y.BOLD&&e!==y.BOLDITALIC||this._setProperty("_textStyle",e),this._applyTextProperties()):this._textStyle},h.Renderer.prototype.textAscent=function(){return null===this._textAscent&&this._updateTextMetrics(),this._textAscent},h.Renderer.prototype.textDescent=function(){return null===this._textDescent&&this._updateTextMetrics(),this._textDescent},h.Renderer.prototype.textAlign=function(e,t){return void 0!==e?(this._setProperty("_textAlign",e),void 0!==t&&this._setProperty("_textBaseline",t),this._applyTextProperties()):{horizontal:this._textAlign,vertical:this._textBaseline}},h.Renderer.prototype.text=function(e,t,r,i,n){var o,a,s,h,l,u,c,p,d=this._pInst,f=Number.MAX_VALUE;if((this._doFill||this._doStroke)&&void 0!==e){if("string"!=typeof e&&(e=e.toString()),o=(e=e.replace(/(\t)/g," ")).split("\n"),void 0!==i){for(s=p=0;sa.HALF_PI&&e<=3*a.HALF_PI?Math.atan(r/i*Math.tan(e))+a.PI:Math.atan(r/i*Math.tan(e))+a.TWO_PI,t=t<=a.HALF_PI?Math.atan(r/i*Math.tan(t)):t>a.HALF_PI&&t<=3*a.HALF_PI?Math.atan(r/i*Math.tan(t))+a.PI:Math.atan(r/i*Math.tan(t))+a.TWO_PI),t_||Math.abs(this.accelerationY-this.pAccelerationY)>_||Math.abs(this.accelerationZ-this.pAccelerationZ)>_)&&e();var t=this.deviceTurned||window.deviceTurned;if("function"==typeof t){var r=this.rotationX+180,i=this.pRotationX+180,n=f+180;0>>24],i+=x[(16711680&C)>>16],n+=x[(65280&C)>>8],o+=x[255&C],r+=D[_],s++}w[h=E+y]=a/r,S[h]=i/r,T[h]=n/r,M[h]=o/r}E+=d}for(u=(l=-R)*d,b=E=0;b>>16,e[r+1]=(65280&t[i])>>>8,e[r+2]=255&t[i],e[r+3]=(4278190080&t[i])>>>24},I._toImageData=function(e){return e instanceof ImageData?e:e.getContext("2d").getImageData(0,0,e.width,e.height)},I._createImageData=function(e,t){return I._tmpCanvas=document.createElement("canvas"),I._tmpCtx=I._tmpCanvas.getContext("2d"),this._tmpCtx.createImageData(e,t)},I.apply=function(e,t,r){var i=e.getContext("2d"),n=i.getImageData(0,0,e.width,e.height),o=t(n,r);o instanceof ImageData?i.putImageData(o,0,0,0,0,e.width,e.height):i.putImageData(n,0,0,0,0,e.width,e.height)},I.threshold=function(e,t){var r=I._toPixels(e);void 0===t&&(t=.5);for(var i=Math.floor(255*t),n=0;n>8)/i,r[n+1]=255*(a*t>>8)/i,r[n+2]=255*(s*t>>8)/i}},I.dilate=function(e){for(var t,r,i,n,o,a,s,h,l,u,c,p,d,f,m,v,g,y=I._toPixels(e),b=0,_=y.length?y.length/4:0,x=new Int32Array(_);b<_;)for(r=(t=b)+e.width;b>16&255)+151*(i>>8&255)+28*(255&i))<(m=77*(c>>16&255)+151*(c>>8&255)+28*(255&c))&&(n=c,o=m),o<(f=77*((u=I._getARGB(y,a))>>16&255)+151*(u>>8&255)+28*(255&u))&&(n=u,o=f),o<(v=77*(p>>16&255)+151*(p>>8&255)+28*(255&p))&&(n=p,o=v),o<(g=77*(d>>16&255)+151*(d>>8&255)+28*(255&d))&&(n=d,o=g),x[b++]=n;I._setPixels(y,x)},I.erode=function(e){for(var t,r,i,n,o,a,s,h,l,u,c,p,d,f,m,v,g,y=I._toPixels(e),b=0,_=y.length?y.length/4:0,x=new Int32Array(_);b<_;)for(r=(t=b)+e.width;b>16&255)+151*(c>>8&255)+28*(255&c))<(o=77*(i>>16&255)+151*(i>>8&255)+28*(255&i))&&(n=c,o=m),(f=77*((u=I._getARGB(y,a))>>16&255)+151*(u>>8&255)+28*(255&u))>16&255)+151*(p>>8&255)+28*(255&p))>16&255)+151*(d>>8&255)+28*(255&d))/g,">").replace(/"/g,""").replace(/'/g,"'")}function h(e,t){t&&!0!==t&&"true"!==t||(t=""),e||(e="untitled");var r="";return e&&-1"),n.print("");if('="text/html;charset=utf-8" />',n.print(' '),n.print(""),n.print(""),n.print(" "),"0"!==o[0]){n.print(" ");for(var u=0;u"+c),n.print(" ")}n.print(" ")}for(var p=0;p");for(var d=0;d"+f),n.print(" ")}n.print(" ")}n.print("
"),n.print(""),n.print("")}n.close(),n.clear()},g.prototype.writeFile=function(e,t,r){var i="application/octet-stream";g.prototype._isSafari()&&(i="text/plain");var n=new Blob(e,{type:i});g.prototype.downloadFile(n,t,r)},g.prototype.downloadFile=function(e,t,r){var i=h(t,r),n=i[0];if(e instanceof Blob){s("file-saver").saveAs(e,n)}else{var o=document.createElement("a");if(o.href=e,o.download=n,o.onclick=function(e){var t;t=e,document.body.removeChild(t.target),e.stopPropagation()},o.style.display="none",document.body.appendChild(o),g.prototype._isSafari()){var a="Hello, Safari user! To download this file...\n";a+="1. Go to File --\x3e Save As.\n",a+='2. Choose "Page Source" as the Format.\n',a+='3. Name it with this extension: ."'+i[1]+'"',alert(a)}o.click()}},g.prototype._checkFileExtension=h,g.prototype._isSafari=function(){return 0>>0},getSeed:function(){return t},rand:function(){return(r=(1664525*r+1013904223)%i)/i}});n.setSeed(e),b=new Array(4096);for(var o=0;o<4096;o++)b[o]=n.rand()},t.exports=i},{"../core/main":23}],54:[function(e,t,r){"use strict";var s=e("../core/main"),o=e("../core/constants");s.Vector=function(){var e,t,r;r=arguments[0]instanceof s?(this.p5=arguments[0],e=arguments[1][0]||0,t=arguments[1][1]||0,arguments[1][2]||0):(e=arguments[0]||0,t=arguments[1]||0,arguments[2]||0),this.x=e,this.y=t,this.z=r},s.Vector.prototype.toString=function(){return"p5.Vector Object : ["+this.x+", "+this.y+", "+this.z+"]"},s.Vector.prototype.set=function(e,t,r){return e instanceof s.Vector?(this.x=e.x||0,this.y=e.y||0,this.z=e.z||0):e instanceof Array?(this.x=e[0]||0,this.y=e[1]||0,this.z=e[2]||0):(this.x=e||0,this.y=t||0,this.z=r||0),this},s.Vector.prototype.copy=function(){return this.p5?new s.Vector(this.p5,[this.x,this.y,this.z]):new s.Vector(this.x,this.y,this.z)},s.Vector.prototype.add=function(e,t,r){return e instanceof s.Vector?(this.x+=e.x||0,this.y+=e.y||0,this.z+=e.z||0):e instanceof Array?(this.x+=e[0]||0,this.y+=e[1]||0,this.z+=e[2]||0):(this.x+=e||0,this.y+=t||0,this.z+=r||0),this},s.Vector.prototype.sub=function(e,t,r){return e instanceof s.Vector?(this.x-=e.x||0,this.y-=e.y||0,this.z-=e.z||0):e instanceof Array?(this.x-=e[0]||0,this.y-=e[1]||0,this.z-=e[2]||0):(this.x-=e||0,this.y-=t||0,this.z-=r||0),this},s.Vector.prototype.mult=function(e){return"number"==typeof e&&isFinite(e)?(this.x*=e,this.y*=e,this.z*=e):console.warn("p5.Vector.prototype.mult:","n is undefined or not a finite number"),this},s.Vector.prototype.div=function(e){return"number"==typeof e&&isFinite(e)?0===e?console.warn("p5.Vector.prototype.div:","divide by 0"):(this.x/=e,this.y/=e,this.z/=e):console.warn("p5.Vector.prototype.div:","n is undefined or not a finite number"),this},s.Vector.prototype.mag=function(){return Math.sqrt(this.magSq())},s.Vector.prototype.magSq=function(){var e=this.x,t=this.y,r=this.z;return e*e+t*t+r*r},s.Vector.prototype.dot=function(e,t,r){return e instanceof s.Vector?this.dot(e.x,e.y,e.z):this.x*(e||0)+this.y*(t||0)+this.z*(r||0)},s.Vector.prototype.cross=function(e){var t=this.y*e.z-this.z*e.y,r=this.z*e.x-this.x*e.z,i=this.x*e.y-this.y*e.x;return this.p5?new s.Vector(this.p5,[t,r,i]):new s.Vector(t,r,i)},s.Vector.prototype.dist=function(e){return e.copy().sub(this).mag()},s.Vector.prototype.normalize=function(){var e=this.mag();return 0!==e&&this.mult(1/e),this},s.Vector.prototype.limit=function(e){var t=this.magSq();return e*e>>0},getSeed:function(){return i},rand:function(){return(n=(1103515245*n+12345)%o)/o}});a.prototype.randomSeed=function(e){u.setSeed(e),h=!(s=!0)},a.prototype.random=function(e,t){var r;if(r=s?u.rand():Math.random(),void 0===e)return r;if(void 0===t)return e instanceof Array?e[Math.floor(r*e.length)]:r*e;if(tg){var R=p,L=h,D=l;p=c+g*(s&&c=t&&(r=r.substring(r.length-t,r.length)),r}},i.prototype.unhex=function(e){return e instanceof Array?e.map(i.prototype.unhex):parseInt("0x"+e,16)},t.exports=i},{"../core/main":23}],62:[function(e,t,r){"use strict";var a=e("../core/main");function i(e,t,r){var i=e<0,n=i?e.toString().substring(1):e.toString(),o=n.indexOf("."),a=-1!==o?n.substring(0,o):n,s=-1!==o?n.substring(o+1):"",h=i?"-":"";if(void 0!==r){var l="";(-1!==o||0r&&(s=s.substring(0,r));for(var u=0;ui.length)for(var o=t-(i+=-1===r?".":"").length+1,a=0;a=d.TWO_PI?(t="ellipse")+"|"+u+"|":(t="arc")+"|"+s+"|"+h+"|"+l+"|"+u+"|",!this.geometryInHash(r)){var c=new E.Geometry(u,1,function(){if(this.strokeIndices=[],s.toFixed(10)!==h.toFixed(10)){l!==d.PIE&&void 0!==l||(this.vertices.push(new E.Vector(.5,.5,0)),this.uvs.push([.5,.5]));for(var e=0;e<=u;e++){var t=e/u*(h-s)+s,r=.5+Math.cos(t)/2,i=.5+Math.sin(t)/2;this.vertices.push(new E.Vector(r,i,0)),this.uvs.push([r,i]),e>5&31)/31,(y>>10&31)/31):(r=a,i=s,h)}for(var b=1;b<=3;b++){var _=f+12*b,x=new S.Vector(l.getFloat32(_,!0),l.getFloat32(_+8,!0),l.getFloat32(_+4,!0));e.vertices.push(x),c&&o.push(r,i,n)}var w=new S.Vector(m,v,g);e.vertexNormals.push(w,w,w),e.faces.push([3*d,3*d+1,3*d+2])}}(e,t);else{var r=new DataView(t);if(!("TextDecoder"in window))return console.warn("Sorry, ASCII STL loading only works in browsers that support TextDecoder (https://caniuse.com/#feat=textencoder)");var i=new TextDecoder("utf-8"),n=i.decode(r),o=n.split("\n");!function(e,t){for(var r,i,n="",o=[],a=0;aMath.PI?h=Math.PI:h<=0&&(h=.001);var l=Math.sin(h)*a*Math.sin(s),u=Math.cos(h)*a,c=Math.sin(h)*a*Math.cos(s);this.camera(l+this.centerX,u+this.centerY,c+this.centerZ,this.centerX,this.centerY,this.centerZ,0,1,0)},m.Camera.prototype._isActive=function(){return this===this._renderer._curCamera},m.prototype.setCamera=function(e){this._renderer._curCamera=e,this._renderer.uPMatrix.set(e.projMatrix.mat4[0],e.projMatrix.mat4[1],e.projMatrix.mat4[2],e.projMatrix.mat4[3],e.projMatrix.mat4[4],e.projMatrix.mat4[5],e.projMatrix.mat4[6],e.projMatrix.mat4[7],e.projMatrix.mat4[8],e.projMatrix.mat4[9],e.projMatrix.mat4[10],e.projMatrix.mat4[11],e.projMatrix.mat4[12],e.projMatrix.mat4[13],e.projMatrix.mat4[14],e.projMatrix.mat4[15])},t.exports=m.Camera},{"../core/main":23}],70:[function(e,t,r){"use strict";var u=e("../core/main");u.Geometry=function(e,t,r){return this.vertices=[],this.lineVertices=[],this.lineNormals=[],this.vertexNormals=[],this.faces=[],this.uvs=[],this.edges=[],this.detailX=void 0!==e?e:1,this.detailY=void 0!==t?t:1,this.dirtyFlags={},r instanceof Function&&r.call(this),this},u.Geometry.prototype.reset=function(){this.lineVertices.length=0,this.lineNormals.length=0,this.vertices.length=0,this.edges.length=0,this.vertexColors.length=0,this.vertexNormals.length=0,this.uvs.length=0,this.dirtyFlags={}},u.Geometry.prototype.computeFaces=function(){this.faces.length=0;for(var e,t,r,i,n=this.detailX+1,o=0;othis.vertices.length-1-this.detailX;t--)e.add(this.vertexNormals[t]);for(e=u.Vector.div(e,this.detailX),t=this.vertices.length-1;t>this.vertices.length-1-this.detailX;t--)this.vertexNormals[t]=e;return this},u.Geometry.prototype._makeTriangleEdges=function(){if(this.edges.length=0,Array.isArray(this.strokeIndices))for(var e=0,t=this.strokeIndices.length;e vTexCoord.y;\n bool y1 = p1.y > vTexCoord.y;\n bool y2 = p2.y > vTexCoord.y;\n\n // could web be under the curve (after t1)?\n if (y1 ? !y2 : y0) {\n // add the coverage for t1\n coverage.x += saturate(C1.x + 0.5);\n // calculate the anti-aliasing for t1\n weight.x = min(weight.x, abs(C1.x));\n }\n\n // are we outside the curve (after t2)?\n if (y1 ? !y0 : y2) {\n // subtract the coverage for t2\n coverage.x -= saturate(C2.x + 0.5);\n // calculate the anti-aliasing for t2\n weight.x = min(weight.x, abs(C2.x));\n }\n}\n\n// this is essentially the same as coverageX, but with the axes swapped\nvoid coverageY(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n bool x0 = p0.x > vTexCoord.x;\n bool x1 = p1.x > vTexCoord.x;\n bool x2 = p2.x > vTexCoord.x;\n\n if (x1 ? !x2 : x0) {\n coverage.y -= saturate(C1.y + 0.5);\n weight.y = min(weight.y, abs(C1.y));\n }\n\n if (x1 ? !x0 : x2) {\n coverage.y += saturate(C2.y + 0.5);\n weight.y = min(weight.y, abs(C2.y));\n }\n}\n\nvoid main() {\n\n // calculate the pixel scale based on screen-coordinates\n pixelScale = hardness / fwidth(vTexCoord);\n\n // which grid cell is this pixel in?\n ivec2 gridCoord = ifloor(vTexCoord * vec2(uGridSize));\n\n // intersect curves in this row\n {\n // the index into the row info bitmap\n int rowIndex = gridCoord.y + uGridOffset.y;\n // fetch the info texel\n vec4 rowInfo = getTexel(uSamplerRows, rowIndex, uGridImageSize);\n // unpack the rowInfo\n int rowStrokeIndex = getInt16(rowInfo.xy);\n int rowStrokeCount = getInt16(rowInfo.zw);\n\n for (int iRowStroke = INT(0); iRowStroke < N; iRowStroke++) {\n if (iRowStroke >= rowStrokeCount)\n break;\n\n // each stroke is made up of 3 points: the start and control point\n // and the start of the next curve.\n // fetch the indices of this pair of strokes:\n vec4 strokeIndices = getTexel(uSamplerRowStrokes, rowStrokeIndex++, uCellsImageSize);\n\n // unpack the stroke index\n int strokePos = getInt16(strokeIndices.xy);\n\n // fetch the two strokes\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n\n // calculate the coverage\n coverageX(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n // intersect curves in this column\n {\n int colIndex = gridCoord.x + uGridOffset.x;\n vec4 colInfo = getTexel(uSamplerCols, colIndex, uGridImageSize);\n int colStrokeIndex = getInt16(colInfo.xy);\n int colStrokeCount = getInt16(colInfo.zw);\n \n for (int iColStroke = INT(0); iColStroke < N; iColStroke++) {\n if (iColStroke >= colStrokeCount)\n break;\n\n vec4 strokeIndices = getTexel(uSamplerColStrokes, colStrokeIndex++, uCellsImageSize);\n\n int strokePos = getInt16(strokeIndices.xy);\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n coverageY(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n weight = saturate(1.0 - weight * 2.0);\n float distance = max(weight.x + weight.y, minDistance); // manhattan approx.\n float antialias = abs(dot(coverage, weight) / distance);\n float cover = min(abs(coverage.x), abs(coverage.y));\n gl_FragColor = uMaterialColor;\n gl_FragColor.a *= saturate(max(antialias, cover));\n}",lineVert:"/*\n Part of the Processing project - http://processing.org\n Copyright (c) 2012-15 The Processing Foundation\n Copyright (c) 2004-12 Ben Fry and Casey Reas\n Copyright (c) 2001-04 Massachusetts Institute of Technology\n This library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation, version 2.1.\n This library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n You should have received a copy of the GNU Lesser General\n Public License along with this library; if not, write to the\n Free Software Foundation, Inc., 59 Temple Place, Suite 330,\n Boston, MA 02111-1307 USA\n*/\n\n#define PROCESSING_LINE_SHADER\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uStrokeWeight;\n\nuniform vec4 uViewport;\n\nattribute vec4 aPosition;\nattribute vec4 aDirection;\n \nvoid main() {\n // using a scale <1 moves the lines towards the camera\n // in order to prevent popping effects due to half of\n // the line disappearing behind the geometry faces.\n vec3 scale = vec3(0.9995);\n\n vec4 posp = uModelViewMatrix * aPosition;\n vec4 posq = uModelViewMatrix * (aPosition + vec4(aDirection.xyz, 0));\n\n // Moving vertices slightly toward the camera\n // to avoid depth-fighting with the fill triangles.\n // Discussed here:\n // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 \n posp.xyz = posp.xyz * scale;\n posq.xyz = posq.xyz * scale;\n\n vec4 p = uProjectionMatrix * posp;\n vec4 q = uProjectionMatrix * posq;\n\n // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])\n // screen_p = (p.xy/p.w + <1,1>) * 0.5 * uViewport.zw\n\n // prevent division by W by transforming the tangent formula (div by 0 causes\n // the line to disappear, see https://github.com/processing/processing/issues/5183)\n // t = screen_q - screen_p\n //\n // tangent is normalized and we don't care which aDirection it points to (+-)\n // t = +- normalize( screen_q - screen_p )\n // t = +- normalize( (q.xy/q.w+<1,1>)*0.5*uViewport.zw - (p.xy/p.w+<1,1>)*0.5*uViewport.zw )\n //\n // extract common factor, <1,1> - <1,1> cancels out\n // t = +- normalize( (q.xy/q.w - p.xy/p.w) * 0.5 * uViewport.zw )\n //\n // convert to common divisor\n // t = +- normalize( ((q.xy*p.w - p.xy*q.w) / (p.w*q.w)) * 0.5 * uViewport.zw )\n //\n // remove the common scalar divisor/factor, not needed due to normalize and +-\n // (keep uViewport - can't remove because it has different components for x and y\n // and corrects for aspect ratio, see https://github.com/processing/processing/issues/5181)\n // t = +- normalize( (q.xy*p.w - p.xy*q.w) * uViewport.zw )\n\n vec2 tangent = normalize((q.xy*p.w - p.xy*q.w) * uViewport.zw);\n\n // flip tangent to normal (it's already normalized)\n vec2 normal = vec2(-tangent.y, tangent.x);\n\n float thickness = aDirection.w * uStrokeWeight;\n vec2 offset = normal * thickness / 2.0;\n\n // Perspective ---\n // convert from world to clip by multiplying with projection scaling factor\n // to get the right thickness (see https://github.com/processing/processing/issues/5182)\n // invert Y, projections in Processing invert Y\n vec2 perspScale = (uProjectionMatrix * vec4(1, -1, 0, 0)).xy;\n\n // No Perspective ---\n // multiply by W (to cancel out division by W later in the pipeline) and\n // convert from screen to clip (derived from clip to screen above)\n vec2 noPerspScale = p.w / (0.5 * uViewport.zw);\n\n //gl_Position.xy = p.xy + offset.xy * mix(noPerspScale, perspScale, float(perspective > 0));\n gl_Position.xy = p.xy + offset.xy * perspScale;\n gl_Position.zw = p.zw;\n}\n",lineFrag:"precision mediump float;\nprecision mediump int;\n\nuniform vec4 uMaterialColor;\n\nvoid main() {\n gl_FragColor = uMaterialColor;\n}",pointVert:"attribute vec3 aPosition;\nuniform float uPointSize;\nvarying float vStrokeWeight;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nvoid main() {\n\tvec4 positionVec4 = vec4(aPosition, 1.0);\n\tgl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n\tgl_PointSize = uPointSize;\n\tvStrokeWeight = uPointSize;\n}",pointFrag:"precision mediump float;\nprecision mediump int;\nuniform vec4 uMaterialColor;\nvarying float vStrokeWeight;\n\nvoid main(){\n\tfloat mask = 0.0;\n\n\t// make a circular mask using the gl_PointCoord (goes from 0 - 1 on a point)\n // might be able to get a nicer edge on big strokeweights with smoothstep but slightly less performant\n\n\tmask = step(0.98, length(gl_PointCoord * 2.0 - 1.0));\n\n\t// if strokeWeight is 1 or less lets just draw a square\n\t// this prevents weird artifacting from carving circles when our points are really small\n\t// if strokeWeight is larger than 1, we just use it as is\n\n\tmask = mix(0.0, mask, clamp(floor(vStrokeWeight - 0.5),0.0,1.0));\n\n\t// throw away the borders of the mask\n // otherwise we get weird alpha blending issues\n\n\tif(mask > 0.98){\n discard;\n \t}\n\n \tgl_FragColor = vec4(uMaterialColor.rgb * (1.0 - mask), uMaterialColor.a) ;\n}"};l.RendererGL=function(e,t,r,i){return l.Renderer.call(this,e,t,r),this._setAttributeDefaults(t),this._initContext(),this.isP3D=!0,this.GL=this.drawingContext,this._enableLighting=!1,this.ambientLightColors=[],this.directionalLightDirections=[],this.directionalLightColors=[],this.pointLightPositions=[],this.pointLightColors=[],this.drawMode=o.FILL,this.curFillColor=[1,1,1,1],this.curStrokeColor=[0,0,0,1],this.curBlendMode=o.BLEND,this.blendExt=this.GL.getExtension("EXT_blend_minmax"),this._useSpecularMaterial=!1,this._useNormalMaterial=!1,this._useShininess=1,this._tint=[255,255,255,255],this.constantAttenuation=1,this.linearAttenuation=0,this.quadraticAttenuation=0,this.uMVMatrix=new l.Matrix,this.uPMatrix=new l.Matrix,this.uNMatrix=new l.Matrix("mat3"),this._curCamera=new l.Camera(this),this._curCamera._computeCameraDefaultSettings(),this._curCamera._setDefaultCamera(),this.gHash={},this._defaultLightShader=void 0,this._defaultImmediateModeShader=void 0,this._defaultNormalShader=void 0,this._defaultColorShader=void 0,this._defaultPointShader=void 0,this._pointVertexBuffer=this.GL.createBuffer(),this.userFillShader=void 0,this.userStrokeShader=void 0,this.userPointShader=void 0,this.isImmediateDrawing=!1,this.immediateMode={},this.pointSize=5,this.curStrokeWeight=1,this.textures=[],this.textureMode=o.IMAGE,this.textureWrapX=o.CLAMP,this.textureWrapY=o.CLAMP,this._tex=null,this._curveTightness=6,this._lookUpTableBezier=[],this._lookUpTableQuadratic=[],this._lutBezierDetail=0,this._lutQuadraticDetail=0,this._tessy=this._initTessy(),this.fontInfos={},this},l.RendererGL.prototype=Object.create(l.Renderer.prototype),l.RendererGL.prototype._setAttributeDefaults=function(e){var t={alpha:!0,depth:!0,stencil:!0,antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0,perPixelLighting:!1};null===e._glAttributes?e._glAttributes=t:e._glAttributes=Object.assign(t,e._glAttributes)},l.RendererGL.prototype._initContext=function(){try{if(this.drawingContext=this.canvas.getContext("webgl",this._pInst._glAttributes)||this.canvas.getContext("experimental-webgl",this._pInst._glAttributes),null===this.drawingContext)throw new Error("Error creating webgl context");var e=this.drawingContext;e.enable(e.DEPTH_TEST),e.depthFunc(e.LEQUAL),e.viewport(0,0,e.drawingBufferWidth,e.drawingBufferHeight),this._viewport=this.drawingContext.getParameter(this.drawingContext.VIEWPORT)}catch(e){throw e}},l.RendererGL.prototype._resetContext=function(e,t){var r=this.width,i=this.height,n=this.canvas.id,o=this._pInst instanceof l.Graphics;if(o){var a=this._pInst;a.canvas.parentNode.removeChild(a.canvas),a.canvas=document.createElement("canvas"),(a._pInst._userNode||document.body).appendChild(a.canvas),l.Element.call(a,a.canvas,a._pInst),a.width=r,a.height=i}else{var s=this.canvas;s&&s.parentNode.removeChild(s),(s=document.createElement("canvas")).id=n,this._pInst._userNode?this._pInst._userNode.appendChild(s):document.body.appendChild(s),this._pInst.canvas=s}var h=new l.RendererGL(this._pInst.canvas,this._pInst,!o);this._pInst._setProperty("_renderer",h),h.resize(r,i),h._applyDefaults(),o||this._pInst._elements.push(h),"function"==typeof t&&setTimeout(function(){t.apply(window._renderer,e)},0)},l.prototype.setAttributes=function(e,t){if(void 0!==this._glAttributes){var r=!0;if(void 0!==t?(null===this._glAttributes&&(this._glAttributes={}),this._glAttributes[e]!==t&&(this._glAttributes[e]=t,r=!1)):e instanceof Object&&this._glAttributes!==e&&(this._glAttributes=e,r=!1),this._renderer.isP3D&&!r){if(!this._setupDone)for(var i in this._renderer.gHash)if(this._renderer.gHash.hasOwnProperty(i))return void console.error("Sorry, Could not set the attributes, you need to call setAttributes() before calling the other drawing methods in setup()");this.push(),this._renderer._resetContext(),this.pop(),this._renderer._curCamera&&(this._renderer._curCamera._renderer=this._renderer)}}else console.log("You are trying to use setAttributes on a p5.Graphics object that does not use a WEBGL renderer.")},l.RendererGL.prototype._update=function(){this.uMVMatrix.set(this._curCamera.cameraMatrix.mat4[0],this._curCamera.cameraMatrix.mat4[1],this._curCamera.cameraMatrix.mat4[2],this._curCamera.cameraMatrix.mat4[3],this._curCamera.cameraMatrix.mat4[4],this._curCamera.cameraMatrix.mat4[5],this._curCamera.cameraMatrix.mat4[6],this._curCamera.cameraMatrix.mat4[7],this._curCamera.cameraMatrix.mat4[8],this._curCamera.cameraMatrix.mat4[9],this._curCamera.cameraMatrix.mat4[10],this._curCamera.cameraMatrix.mat4[11],this._curCamera.cameraMatrix.mat4[12],this._curCamera.cameraMatrix.mat4[13],this._curCamera.cameraMatrix.mat4[14],this._curCamera.cameraMatrix.mat4[15]),this.ambientLightColors.length=0,this.directionalLightDirections.length=0,this.directionalLightColors.length=0,this.pointLightPositions.length=0,this.pointLightColors.length=0,this._enableLighting=!1,this._tint=[255,255,255,255]},l.RendererGL.prototype.background=function(){var e=this._pInst.color.apply(this._pInst,arguments),t=e.levels[0]/255,r=e.levels[1]/255,i=e.levels[2]/255,n=e.levels[3]/255;this.GL.clearColor(t,r,i,n),this.GL.depthMask(!0),this.GL.clear(this.GL.COLOR_BUFFER_BIT|this.GL.DEPTH_BUFFER_BIT),this._pixelsState._pixelsDirty=!0},l.RendererGL.prototype.fill=function(e,t,r,i){var n=l.prototype.color.apply(this._pInst,arguments);this.curFillColor=n._array,this.drawMode=o.FILL,this._useNormalMaterial=!1,this._tex=null},l.RendererGL.prototype.stroke=function(e,t,r,i){i=255;var n=l.prototype.color.apply(this._pInst,arguments);this.curStrokeColor=n._array},l.RendererGL.prototype.strokeCap=function(e){console.error("Sorry, strokeCap() is not yet implemented in WEBGL mode")},l.RendererGL.prototype.blendMode=function(e){e===o.DARKEST||e===o.LIGHTEST||e===o.ADD||e===o.BLEND||e===o.SUBTRACT||e===o.SCREEN||e===o.EXCLUSION||e===o.REPLACE||e===o.MULTIPLY?this.curBlendMode=e:e!==o.BURN&&e!==o.OVERLAY&&e!==o.HARD_LIGHT&&e!==o.SOFT_LIGHT&&e!==o.DODGE||console.warn("BURN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, and DODGE only work for blendMode in 2D mode.")},l.RendererGL.prototype.strokeWeight=function(e){this.curStrokeWeight!==e&&(this.pointSize=e,this.curStrokeWeight=e)},l.RendererGL.prototype._getPixel=function(e,t){var r,i,n=this._pixelsState;return i=n._pixelsDirty?(r=new Uint8Array(4),this.drawingContext.readPixels(e,t,1,1,this.drawingContext.RGBA,this.drawingContext.UNSIGNED_BYTE,r),0):(r=n.pixels,4*(Math.floor(e)+Math.floor(t)*this.canvas.width)),[r[i+0],r[i+1],r[i+2],r[i+3]]},l.RendererGL.prototype.loadPixels=function(){var e=this._pixelsState;if(e._pixelsDirty)if(!(e._pixelsDirty=!1)===this._pInst._glAttributes.preserveDrawingBuffer){var t=e.pixels,r=this.GL.drawingBufferWidth*this.GL.drawingBufferHeight*4;t instanceof Uint8Array&&t.length===r||(t=new Uint8Array(r),this._pixelsState._setProperty("pixels",t));var i=this._pInst._pixelDensity;this.GL.readPixels(0,0,this.width*i,this.height*i,this.GL.RGBA,this.GL.UNSIGNED_BYTE,t)}else console.log("loadPixels only works in WebGL when preserveDrawingBuffer is true.")},l.RendererGL.prototype.geometryInHash=function(e){return void 0!==this.gHash[e]},l.RendererGL.prototype.resize=function(e,t){l.Renderer.prototype.resize.call(this,e,t),this.GL.viewport(0,0,this.GL.drawingBufferWidth,this.GL.drawingBufferHeight),this._viewport=this.GL.getParameter(this.GL.VIEWPORT),this._curCamera._resize();var r=this._pixelsState;r._pixelsDirty=!0,void 0!==r.pixels&&r._setProperty("pixels",new Uint8Array(this.GL.drawingBufferWidth*this.GL.drawingBufferHeight*4))},l.RendererGL.prototype.clear=function(){var e=arguments[0]||0,t=arguments[1]||0,r=arguments[2]||0,i=arguments[3]||0;this.GL.clearColor(e,t,r,i),this.GL.clear(this.GL.COLOR_BUFFER_BIT|this.GL.DEPTH_BUFFER_BIT),this._pixelsState._pixelsDirty=!0},l.RendererGL.prototype.applyMatrix=function(e,t,r,i,n,o){16===arguments.length?l.Matrix.prototype.apply.apply(this.uMVMatrix,arguments):this.uMVMatrix.apply([e,t,0,0,r,i,0,0,0,0,1,0,n,o,0,1])},l.RendererGL.prototype.translate=function(e,t,r){return e instanceof l.Vector&&(r=e.z,t=e.y,e=e.x),this.uMVMatrix.translate([e,t,r]),this},l.RendererGL.prototype.scale=function(e,t,r){return this.uMVMatrix.scale(e,t,r),this},l.RendererGL.prototype.rotate=function(e,t){return void 0===t?this.rotateZ(e):(l.Matrix.prototype.rotate.apply(this.uMVMatrix,arguments),this)},l.RendererGL.prototype.rotateX=function(e){return this.rotate(e,1,0,0),this},l.RendererGL.prototype.rotateY=function(e){return this.rotate(e,0,1,0),this},l.RendererGL.prototype.rotateZ=function(e){return this.rotate(e,0,0,1),this},l.RendererGL.prototype.push=function(){var e=l.Renderer.prototype.push.apply(this),t=e.properties;return t.uMVMatrix=this.uMVMatrix.copy(),t.uPMatrix=this.uPMatrix.copy(),t._curCamera=this._curCamera,this._curCamera=this._curCamera.copy(),t.ambientLightColors=this.ambientLightColors.slice(),t.directionalLightDirections=this.directionalLightDirections.slice(),t.directionalLightColors=this.directionalLightColors.slice(),t.pointLightPositions=this.pointLightPositions.slice(),t.pointLightColors=this.pointLightColors.slice(),t.userFillShader=this.userFillShader,t.userStrokeShader=this.userStrokeShader,t.userPointShader=this.userPointShader,t.pointSize=this.pointSize,t.curStrokeWeight=this.curStrokeWeight,t.curStrokeColor=this.curStrokeColor,t.curFillColor=this.curFillColor,t._useSpecularMaterial=this._useSpecularMaterial,t._useShininess=this._useShininess,t.constantAttenuation=this.constantAttenuation,t.linearAttenuation=this.linearAttenuation,t.quadraticAttenuation=this.quadraticAttenuation,t._enableLighting=this._enableLighting,t._useNormalMaterial=this._useNormalMaterial,t._tex=this._tex,t.drawMode=this.drawMode,e},l.RendererGL.prototype.resetMatrix=function(){return this.uMVMatrix=l.Matrix.identity(this._pInst),this},l.RendererGL.prototype._getImmediateStrokeShader=function(){var e=this.userStrokeShader;return e&&e.isStrokeShader()?e:this._getLineShader()},l.RendererGL.prototype._getRetainedStrokeShader=l.RendererGL.prototype._getImmediateStrokeShader,l.RendererGL.prototype._getImmediateFillShader=function(){if(this._useNormalMaterial)return console.log("Sorry, normalMaterial() does not currently work with custom WebGL geometry created with beginShape(). Falling back to standard fill material."),this._getImmediateModeShader();var e=this.userFillShader;if(this._enableLighting){if(!e||!e.isLightShader())return this._getLightShader()}else if(this._tex){if(!e||!e.isTextureShader())return this._getLightShader()}else if(!e)return this._getImmediateModeShader();return e},l.RendererGL.prototype._getRetainedFillShader=function(){if(this._useNormalMaterial)return this._getNormalShader();var e=this.userFillShader;if(this._enableLighting){if(!e||!e.isLightShader())return this._getLightShader()}else if(this._tex){if(!e||!e.isTextureShader())return this._getLightShader()}else if(!e)return this._getColorShader();return e},l.RendererGL.prototype._getImmediatePointShader=function(){var e=this.userPointShader;return e&&e.isPointShader()?e:this._getPointShader()},l.RendererGL.prototype._getRetainedLineShader=l.RendererGL.prototype._getImmediateLineShader,l.RendererGL.prototype._getLightShader=function(){return this._defaultLightShader||(this._pInst._glAttributes.perPixelLighting?this._defaultLightShader=new l.Shader(this,a.phongVert,a.phongFrag):this._defaultLightShader=new l.Shader(this,a.lightVert,a.lightTextureFrag)),this._defaultLightShader},l.RendererGL.prototype._getImmediateModeShader=function(){return this._defaultImmediateModeShader||(this._defaultImmediateModeShader=new l.Shader(this,a.immediateVert,a.vertexColorFrag)),this._defaultImmediateModeShader},l.RendererGL.prototype._getNormalShader=function(){return this._defaultNormalShader||(this._defaultNormalShader=new l.Shader(this,a.normalVert,a.normalFrag)),this._defaultNormalShader},l.RendererGL.prototype._getColorShader=function(){return this._defaultColorShader||(this._defaultColorShader=new l.Shader(this,a.normalVert,a.basicFrag)),this._defaultColorShader},l.RendererGL.prototype._getPointShader=function(){return this._defaultPointShader||(this._defaultPointShader=new l.Shader(this,a.pointVert,a.pointFrag)),this._defaultPointShader},l.RendererGL.prototype._getLineShader=function(){return this._defaultLineShader||(this._defaultLineShader=new l.Shader(this,a.lineVert,a.lineFrag)),this._defaultLineShader},l.RendererGL.prototype._getFontShader=function(){return this._defaultFontShader||(this.GL.getExtension("OES_standard_derivatives"),this._defaultFontShader=new l.Shader(this,a.fontVert,a.fontFrag)),this._defaultFontShader},l.RendererGL.prototype._getEmptyTexture=function(){if(!this._emptyTexture){var e=new l.Image(1,1);e.set(0,0,255),this._emptyTexture=new l.Texture(this,e)}return this._emptyTexture},l.RendererGL.prototype.getTexture=function(e){for(var t=this.textures,r=0;r>7,127&p,c>>7,127&c);for(var d=0;d>7,127&f,0,0)}}return{cellImageInfo:h,dimOffset:o,dimImageInfo:n}}return(t=this.glyphInfos[e.index]={glyph:e,uGlyphRect:[i.x1,-i.y1,i.x2,-i.y2],strokeImageInfo:I,strokes:d,colInfo:O(m,this.colDimImageInfos,this.colCellImageInfos),rowInfo:O(f,this.rowDimImageInfos,this.rowCellImageInfos)}).uGridOffset=[t.colInfo.dimOffset,t.rowInfo.dimOffset],t}};B.RendererGL.prototype._renderText=function(e,t,r,i,n){if(this._textFont&&"string"!=typeof this._textFont){if(!(n<=i)&&this._doFill){if(!this._isOpenType())return console.log("WEBGL: only opentype fonts are supported"),e;e.push();var o=this._doStroke,a=this.drawMode;this._doStroke=!1,this.drawMode=T.TEXTURE;var s=this._textFont.font,h=this._textFont._fontInfo;h||(h=this._textFont._fontInfo=new M(s));var l=this._textFont._handleAlignment(this,t,r,i),u=this._textSize/s.unitsPerEm;this.translate(l.x,l.y,0),this.scale(u,u,1);var c=this.GL,p=!this._defaultFontShader,d=this._getFontShader();d.init(),d.bindShader(),p&&(d.setUniform("uGridImageSize",[64,64]),d.setUniform("uCellsImageSize",[64,64]),d.setUniform("uStrokeImageSize",[64,64]),d.setUniform("uGridSize",[9,9])),this._applyColorBlend(this.curFillColor);var f=this.gHash.glyph;if(!f){var m=this._textGeom=new B.Geometry(1,1,function(){for(var e=0;e<=1;e++)for(var t=0;t<=1;t++)this.vertices.push(new B.Vector(t,e,0)),this.uvs.push(t,e)});m.computeFaces().computeNormals(),f=this.createBuffers("glyph",m)}this._prepareBuffers(f,d,B.RendererGL._textBuffers),this._bindBuffer(f.indexBuffer,c.ELEMENT_ARRAY_BUFFER),d.setUniform("uMaterialColor",this.curFillColor);try{for(var v=0,g=null,y=s.stringToGlyphs(t),b=0;b>>0),la=0;function ma(a,b){a=a.split(".");var c=aa;a[0]in c||!c.execScript||c.execScript("var "+a[0]);for(var d;a.length&&(d=a.shift());)a.length||void 0===b?c=c[d]&&c[d]!==Object.prototype[d]?c[d]:c[d]={}:c[d]=b} +function na(a,b){function c(){}c.prototype=b.prototype;a.Qb=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.mb=function(a,c,f){for(var d=Array(arguments.length-2),e=2;eb?1:0};var ua=Array.prototype.indexOf?function(a,b){return Array.prototype.indexOf.call(a,b,void 0)}:function(a,b){if(ba(a))return ba(b)&&1==b.length?a.indexOf(b,0):-1;for(var c=0;cb?1:aa){var b=Ba[a];if(b)return b}b=new Aa([a|0],0>a?-1:0);-128<=a&&128>a&&(Ba[a]=b);return b}function Da(a){if(isNaN(a)||!isFinite(a))return Ea;if(0>a)return Fa(Da(-a));for(var b=[],c=1,d=0;a>=c;d++)b[d]=a/c|0,c*=Ga;return new Aa(b,0)}var Ga=4294967296,Ea=Ca(0),Ha=Ca(1),Ia=Ca(16777216); +function Ja(a){if(-1==a.J)return-Ja(Fa(a));for(var b=0,c=1,d=0;da||36>>0).toString(a);c=e;if(La(c))return f+d;for(;6>f.length;)f="0"+f;d=""+f+d}}; +function Ka(a,b){return 0>b?0:b>5;a=(a-1)%32;for(var c=[],d=0;d>>16)+(Ka(this,e)>>>16)+(Ka(a,e)>>>16);d=h>>>16;f&=65535;h&=65535;c[e]=h<<16|f}return new Aa(c,c[c.length-1]&-2147483648?-1:0)}; +g.multiply=function(a){if(La(this)||La(a))return Ea;if(-1==this.J)return-1==a.J?Fa(this).multiply(Fa(a)):Fa(Fa(this).multiply(a));if(-1==a.J)return Fa(this.multiply(Fa(a)));if(0>this.compare(Ia)&&0>a.compare(Ia))return Da(Ja(this)*Ja(a));for(var b=this.I.length+a.I.length,c=[],d=0;d<2*b;d++)c[d]=0;for(d=0;d>>16,h=Ka(this,d)&65535,k=Ka(a,e)>>>16,l=Ka(a,e)&65535;c[2*d+2*e]+=h*l;Pa(c,2*d+2*e);c[2*d+2*e+1]+=f*l;Pa(c,2*d+2*e+1);c[2*d+2* +e+1]+=h*k;Pa(c,2*d+2*e+1);c[2*d+2*e+2]+=f*k;Pa(c,2*d+2*e+2)}for(d=0;d>>16,a[b]&=65535,b++} +function Na(a,b){if(La(b))throw Error("division by zero");if(La(a))return Ea;if(-1==a.J)return-1==b.J?Na(Fa(a),Fa(b)):Fa(Na(Fa(a),b));if(-1==b.J)return Fa(Na(a,Fa(b)));if(30=b.compare(a);)c=c.shiftLeft(1),b=b.shiftLeft(1);var d=Qa(c,1),e=Qa(b,1);b=Qa(b,2);for(c=Qa(c,2);!La(b);){var f=e.add(b);0>=f.compare(a)&&(d=d.add(c),e=f);b=Qa(b,1);c=Qa(c,1)}return d}for(c=Ea;0<=a.compare(b);){d=Math.max(1, +Math.floor(Ja(a)/Ja(b)));e=Math.ceil(Math.log(d)/Math.LN2);e=48>=e?1:Math.pow(2,e-48);f=Da(d);for(var h=f.multiply(b);-1==h.J||0>5;a%=32;for(var c=this.I.length+b+(0>>32-a:Ka(this,e-b);return new Aa(d,this.J)};function Qa(a,b){var c=b>>5;b%=32;for(var d=a.I.length-c,e=[],f=0;f>>b|Ka(a,f+c+1)<<32-b:Ka(a,f+c);return new Aa(e,a.J)};function Ra(a,b){null!=a&&this.append.apply(this,arguments)}g=Ra.prototype;g.Na="";g.set=function(a){this.Na=""+a};g.append=function(a,b,c){this.Na+=String(a);if(null!=b)for(var d=1;d>>16&65535)*d+c*(b>>>16&65535)<<16>>>0)|0};function Ac(a){a=zc(a|0,-862048943);return zc(a<<15|a>>>-15,461845907)}function Bc(a,b){a=(a|0)^(b|0);return zc(a<<13|a>>>-13,5)+-430675100|0}function Cc(a,b){a=(a|0)^b;a=zc(a^a>>>16,-2048144789);a=zc(a^a>>>13,-1028477387);return a^a>>>16} +function Dc(a){a:{var b=1;for(var c=0;;)if(b>2)} +function Jc(a,b){if(a.str===b.str)return 0;var c=ob(a.aa);if(t(c?b.aa:c))return-1;if(t(a.aa)){if(ob(b.aa))return 1;c=xa(a.aa,b.aa);return 0===c?xa(a.name,b.name):c}return xa(a.name,b.name)}function Kc(a,b,c,d,e){this.aa=a;this.name=b;this.str=c;this.Ra=d;this.sa=e;this.i=2154168321;this.w=4096}g=Kc.prototype;g.toString=function(){return this.str};g.equiv=function(a){return this.u(null,a)};g.u=function(a,b){return b instanceof Kc?this.str===b.str:!1}; +g.call=function(){var a=null;a=function(a,c,d){switch(arguments.length){case 2:return H.b(c,this);case 3:return H.f(c,this,d)}throw Error("Invalid arity: "+(arguments.length-1));};a.b=function(a,c){return H.b(c,this)};a.f=function(a,c,d){return H.f(c,this,d)};return a}();g.apply=function(a,b){return this.call.apply(this,[this].concat(sb(b)))};g.a=function(a){return H.b(a,this)};g.b=function(a,b){return H.f(a,this,b)};g.O=function(){return this.sa}; +g.T=function(a,b){return new Kc(this.aa,this.name,this.str,this.Ra,b)};g.S=function(){var a=this.Ra;return null!=a?a:this.Ra=a=Ic(Dc(this.name),Gc(this.aa))};g.Hb=function(){return this.name};g.Ib=function(){return this.aa};g.P=function(a,b){return G(b,this.str)};function Lc(a){return null!=a?a.w&131072||r===a.rc?!0:a.w?!1:v(vc,a):v(vc,a)} +function I(a){if(null==a)return null;if(null!=a&&(a.i&8388608||r===a.bc))return Zb(a);if(nb(a)||"string"===typeof a)return 0===a.length?null:new J(a,0,null);if(v(Yb,a))return Zb(a);throw Error([A.a(a)," is not ISeqable"].join(""));}function K(a){if(null==a)return null;if(null!=a&&(a.i&64||r===a.sb))return D(a);a=I(a);return null==a?null:D(a)}function Mc(a){return null!=a?null!=a&&(a.i&64||r===a.sb)?yb(a):(a=I(a))?a.ia(null):L:L} +function M(a){return null==a?null:null!=a&&(a.i&128||r===a.ab)?Ab(a):I(Mc(a))}var N=function N(a){switch(arguments.length){case 1:return N.a(arguments[0]);case 2:return N.b(arguments[0],arguments[1]);default:for(var c=[],d=arguments.length,e=0;;)if(e=d)return-1;!(0c&&(c+=d,c=0>c?0:c);for(;;)if(cc?d+c:c;for(;;)if(0<=c){if(N.b(dd(a,c),b))return c;--c}else return-1}function ed(a,b){this.c=a;this.j=b}ed.prototype.Z=function(){return this.ja?0:a};g.rb=function(){var a=this.M(null);return 0b)throw Error("Index out of bounds");a:for(;;){if(null==a)throw Error("Index out of bounds"); +if(0===b){if(I(a)){a=K(a);break a}throw Error("Index out of bounds");}if(cd(a)){a=C.b(a,b);break a}if(I(a))a=M(a),--b;else throw Error("Index out of bounds");}return a}if(v(xb,a))return C.b(a,b);throw Error(["nth not supported on this type ",A.a(pb(null==a?null:a.constructor))].join(""));} +function T(a,b){if("number"!==typeof b)throw Error("Index argument to nth must be a number.");if(null==a)return null;if(null!=a&&(a.i&16||r===a.Gb))return C.f(a,b,null);if(nb(a))return-1b?null:nd(a,b);if(v(xb,a))return C.f(a,b,null);throw Error(["nth not supported on this type ",A.a(pb(null==a?null:a.constructor))].join(""));} +var H=function H(a){switch(arguments.length){case 2:return H.b(arguments[0],arguments[1]);case 3:return H.f(arguments[0],arguments[1],arguments[2]);default:throw Error(["Invalid arity: ",A.a(arguments.length)].join(""));}};H.b=function(a,b){return null==a?null:null!=a&&(a.i&256||r===a.Vb)?Cb.b(a,b):nb(a)?null!=b&&bd)a=1;else if(0===c)a=0;else a:for(d=0;;){var e=Hd(dd(a,d),dd(b,d));if(0===e&&d+1>1&1431655765;a=(a&858993459)+(a>>2&858993459);return 16843009*(a+(a>>4)&252645135)>>24}var A=function A(a){switch(arguments.length){case 0:return A.o();case 1:return A.a(arguments[0]);default:for(var c=[],d=arguments.length,e=0;;)if(ea?0:a-1>>>5<<5}function Pe(a,b,c){for(;;){if(0===b)return c;var d=Ne(a);d.c[0]=c;c=d;b-=5}}var Qe=function Qe(a,b,c,d){var f=new Me(c.G,sb(c.c)),h=a.h-1>>>b&31;5===b?f.c[h]=d:(c=c.c[h],null!=c?(b-=5,a=Qe.F?Qe.F(a,b,c,d):Qe.call(null,a,b,c,d)):a=Pe(null,b-5,d),f.c[h]=a);return f};function Re(a,b){throw Error(["No item ",A.a(a)," in vector of length ",A.a(b)].join(""));} +function Se(a,b){if(b>=Oe(a))return a.ja;var c=a.root;for(a=a.shift;;)if(0>>a&31];a=d}else return c.c}var Te=function Te(a,b,c,d,e){var h=new Me(c.G,sb(c.c));if(0===b)h.c[d&31]=e;else{var k=d>>>b&31;b-=5;c=c.c[k];a=Te.V?Te.V(a,b,c,d,e):Te.call(null,a,b,c,d,e);h.c[k]=a}return h};function Ue(a,b,c){this.mb=this.j=0;this.c=a;this.lc=b;this.start=0;this.end=c}Ue.prototype.Z=function(){return this.j=this.h)a=new J(this.ja,0,null);else{a:{a=this.root;for(var b=this.shift;;)if(0this.h-Oe(this)){a=this.ja.length;for(var c=Array(a+1),d=0;;)if(d>>5>1<b)a=new W(null,b,5,Y,a,null);else for(var c=32,d=(new W(null,32,5,Y,a.slice(0,32),null)).Ua(null);;)if(c>>b&31;if(5===b)a=d;else{var h=c.c[f];null!=h?(b-=5,a=cf.F?cf.F(a,b,h,d):cf.call(null,a,b,h,d)):a=Pe(a.root.G,b-5,d)}c.c[f]=a;return c};function Ye(a,b,c,d){this.h=a;this.shift=b;this.root=c;this.ja=d;this.w=88;this.i=275}g=Ye.prototype; +g.Wa=function(a,b){if(this.root.G){if(32>this.h-Oe(this))this.ja[this.h&31]=b;else{a=new Me(this.root.G,this.ja);var c=[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];c[0]=b;this.ja=c;this.h>>>5>1<>>d&31;d=k(d-5,h.c[f]);h.c[f]=d}return h}}(a)(a.shift,a.root)}();a.root=d}return a}if(b===a.h)return a.Wa(null,c);throw Error(["Index ",A.a(b)," out of bounds for TransientVector of length",A.a(a.h)].join(""));}throw Error("assoc! after persistent!");} +g.M=function(){if(this.root.G)return this.h;throw Error("count after persistent!");};g.N=function(a,b){if(this.root.G)return(0<=b&&b=a)return new fb(this.m,this.h-1,c,null);N.b(b,this.c[d])?d+=2:(c[e]=this.c[d],c[e+1]=this.c[d+1],e+=2,d+=2)}}else return this}; +g.Oa=function(a,b,c){a=od(this.c,b);if(-1===a){if(this.hb?4:2*(b+1));Dd(this.c,0,c,0,2*b);return new xf(a,this.H,c)};g.gb=function(){return yf(this.c,0,null)};g.ib=function(a,b){return vf(this.c,a,b)};g.Qa=function(a,b,c,d){var e=1<<(b>>>a&31);if(0===(this.H&e))return d;var f=Ud(this.H&e-1);e=this.c[2*f];f=this.c[2*f+1];return null==e?f.Qa(a+5,b,c,d):rf(c,e)?f:d}; +g.oa=function(a,b,c,d,e,f){var h=1<<(c>>>b&31),k=Ud(this.H&h-1);if(0===(this.H&h)){var l=Ud(this.H);if(2*l>>b&31]=zf.oa(a,b+5,c,d,e,f);for(e=d=0;;)if(32>d)0=== +(this.H>>>d&1)?d+=1:(k[d]=null!=this.c[e]?zf.oa(a,b+5,Hc(this.c[e]),this.c[e],this.c[e+1],f):this.c[e+1],e+=2,d+=1);else break;return new Af(a,l+1,k)}b=Array(2*(l+4));Dd(this.c,0,b,0,2*k);b[2*k]=d;b[2*k+1]=e;Dd(this.c,2*k,b,2*(k+1),2*(l-k));f.L=!0;a=this.Pa(a);a.c=b;a.H|=h;return a}l=this.c[2*k];h=this.c[2*k+1];if(null==l)return l=h.oa(a,b+5,c,d,e,f),l===h?this:uf(this,a,2*k+1,l);if(rf(d,l))return e===h?this:uf(this,a,2*k+1,e);f.L=!0;f=b+5;b=Hc(l);if(b===c)e=new Bf(null,b,2,[l,h,d,e]);else{var m= +new qf;e=zf.oa(a,f,b,l,h,m).oa(a,f,c,d,e,m)}d=2*k;k=2*k+1;a=this.Pa(a);a.c[d]=null;a.c[k]=e;return a}; +g.na=function(a,b,c,d,e){var f=1<<(b>>>a&31),h=Ud(this.H&f-1);if(0===(this.H&f)){var k=Ud(this.H);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]=zf.na(a+5,b,c,d,e);for(d=c=0;;)if(32>c)0===(this.H>>>c&1)?c+=1:(h[c]=null!=this.c[d]?zf.na(a+5,Hc(this.c[d]),this.c[d],this.c[d+1],e):this.c[d+1],d+=2,c+=1);else break;return new Af(null,k+1,h)}a=Array(2*(k+1));Dd(this.c, +0,a,0,2*h);a[2*h]=c;a[2*h+1]=d;Dd(this.c,2*h,a,2*(h+1),2*(k-h));e.L=!0;return new xf(null,this.H|f,a)}var l=this.c[2*h];f=this.c[2*h+1];if(null==l)return k=f.na(a+5,b,c,d,e),k===f?this:new xf(null,this.H,sf(this.c,2*h+1,k));if(rf(c,l))return d===f?this:new xf(null,this.H,sf(this.c,2*h+1,d));e.L=!0;e=this.H;k=this.c;a+=5;var m=Hc(l);if(m===b)c=new Bf(null,m,2,[l,f,c,d]);else{var n=new qf;c=zf.na(a,m,l,f,n).na(a,b,c,d,n)}a=2*h;h=2*h+1;d=sb(k);d[a]=null;d[h]=c;return new xf(null,e,d)}; +g.fb=function(a,b,c,d){var e=1<<(b>>>a&31);if(0===(this.H&e))return d;var f=Ud(this.H&e-1);e=this.c[2*f];f=this.c[2*f+1];return null==e?f.fb(a+5,b,c,d):rf(c,e)?new Xe(e,f):d};g.hb=function(a,b,c){var d=1<<(b>>>a&31);if(0===(this.H&d))return this;var e=Ud(this.H&d-1),f=this.c[2*e],h=this.c[2*e+1];return null==f?(a=h.hb(a+5,b,c),a===h?this:null!=a?new xf(null,this.H,sf(this.c,2*e+1,a)):this.H===d?null:new xf(null,this.H^d,tf(this.c,e))):rf(c,f)?new xf(null,this.H^d,tf(this.c,e)):this};g.ma=function(){return new wf(this.c)}; +var zf=new xf(null,0,[]);function Cf(a){this.c=a;this.j=0;this.qa=null}Cf.prototype.Z=function(){for(var a=this.c.length;;){if(null!=this.qa&&this.qa.Z())return!0;if(this.j>>a&31];return null!=e?e.Qa(a+5,b,c,d):d}; +g.oa=function(a,b,c,d,e,f){var h=c>>>b&31,k=this.c[h];if(null==k)return a=uf(this,a,h,zf.oa(a,b+5,c,d,e,f)),a.h+=1,a;b=k.oa(a,b+5,c,d,e,f);return b===k?this:uf(this,a,h,b)};g.na=function(a,b,c,d,e){var f=b>>>a&31,h=this.c[f];if(null==h)return new Af(null,this.h+1,sf(this.c,f,zf.na(a+5,b,c,d,e)));a=h.na(a+5,b,c,d,e);return a===h?this:new Af(null,this.h,sf(this.c,f,a))};g.fb=function(a,b,c,d){var e=this.c[b>>>a&31];return null!=e?e.fb(a+5,b,c,d):d}; +g.hb=function(a,b,c){var d=b>>>a&31,e=this.c[d];if(null!=e){a=e.hb(a+5,b,c);if(a===e)d=this;else if(null==a)if(8>=this.h)a:{e=this.c;a=e.length;b=Array(2*(this.h-1));c=0;for(var f=1,h=0;;)if(ca?d:rf(c,this.c[a])?this.c[a+1]:d}; +g.oa=function(a,b,c,d,e,f){if(c===this.Ja){b=Ef(this.c,this.h,d);if(-1===b){if(this.c.length>2*this.h)return b=2*this.h,c=2*this.h+1,a=this.Pa(a),a.c[b]=d,a.c[c]=e,f.L=!0,a.h+=1,a;c=this.c.length;b=Array(c+2);Dd(this.c,0,b,0,c);b[c]=d;b[c+1]=e;f.L=!0;d=this.h+1;a===this.G?(this.c=b,this.h=d,a=this):a=new Bf(this.G,this.Ja,d,b);return a}return this.c[b+1]===e?this:uf(this,a,b+1,e)}return(new xf(a,1<<(this.Ja>>>b&31),[null,this,null,null])).oa(a,b,c,d,e,f)}; +g.na=function(a,b,c,d,e){return b===this.Ja?(a=Ef(this.c,this.h,c),-1===a?(a=2*this.h,b=Array(a+2),Dd(this.c,0,b,0,a),b[a]=c,b[a+1]=d,e.L=!0,new Bf(null,this.Ja,this.h+1,b)):N.b(this.c[a+1],d)?this:new Bf(null,this.Ja,this.h,sf(this.c,a+1,d))):(new xf(null,1<<(this.Ja>>>a&31),[null,this])).na(a,b,c,d,e)};g.fb=function(a,b,c,d){a=Ef(this.c,this.h,c);return 0>a?d:rf(c,this.c[a])?new Xe(this.c[a],this.c[a+1]):d}; +g.hb=function(a,b,c){a=Ef(this.c,this.h,c);return-1===a?this:1===this.h?null:new Bf(null,this.Ja,this.h-1,tf(this.c,Td(a)))};g.ma=function(){return new wf(this.c)};function Ff(a,b,c,d,e){this.m=a;this.ra=b;this.j=c;this.C=d;this.s=e;this.i=32374988;this.w=0}g=Ff.prototype;g.toString=function(){return yc(this)};g.equiv=function(a){return this.u(null,a)}; +g.indexOf=function(){var a=null;a=function(a,c){switch(arguments.length){case 1:return P(this,a,0);case 2:return P(this,a,c)}throw Error("Invalid arity: "+arguments.length);};a.a=function(a){return P(this,a,0)};a.b=function(a,c){return P(this,a,c)};return a}(); +g.lastIndexOf=function(){function a(a){return R(this,a,Q(this))}var b=null;b=function(b,d){switch(arguments.length){case 1:return a.call(this,b);case 2:return R(this,b,d)}throw Error("Invalid arity: "+arguments.length);};b.a=a;b.b=function(a,b){return R(this,a,b)};return b}();g.O=function(){return this.m};g.W=function(){return null==this.C?yf(this.ra,this.j+2,null):yf(this.ra,this.j,M(this.C))};g.S=function(){var a=this.s;return null!=a?a:this.s=a=Rc(this)};g.u=function(a,b){return gd(this,b)}; +g.Y=function(){return L};g.ea=function(a,b){return id(b,this)};g.fa=function(a,b,c){return jd(b,c,this)};g.ga=function(){return null==this.C?new Xe(this.ra[this.j],this.ra[this.j+1]):K(this.C)};g.ia=function(){var a=null==this.C?yf(this.ra,this.j+2,null):yf(this.ra,this.j,M(this.C));return null!=a?a:L};g.R=function(){return this};g.T=function(a,b){return b===this.m?this:new Ff(b,this.ra,this.j,this.C,this.s)};g.U=function(a,b){return S(b,this)};Ff.prototype[rb]=function(){return Oc(this)}; +function yf(a,b,c){if(null==c)for(c=a.length;;)if(b=this.count)throw Error("-drop-first of empty chunk");return new Wf(this.start+this.step,this.step,this.count-1)};function Xf(a,b,c){this.j=a;this.end=b;this.step=c}Xf.prototype.Z=function(){return 0this.end};Xf.prototype.next=function(){var a=this.j;this.j+=this.step;return a}; +function Yf(a,b,c,d,e,f,h){this.m=a;this.start=b;this.end=c;this.step=d;this.ca=e;this.nb=f;this.s=h;this.i=32375006;this.w=140800}g=Yf.prototype;g.toString=function(){return yc(this)};g.equiv=function(a){return this.u(null,a)};g.indexOf=function(){var a=null;a=function(a,c){switch(arguments.length){case 1:return P(this,a,0);case 2:return P(this,a,c)}throw Error("Invalid arity: "+arguments.length);};a.a=function(a){return P(this,a,0)};a.b=function(a,c){return P(this,a,c)};return a}(); +g.lastIndexOf=function(){function a(a){return R(this,a,Q(this))}var b=null;b=function(b,d){switch(arguments.length){case 1:return a.call(this,b);case 2:return R(this,b,d)}throw Error("Invalid arity: "+arguments.length);};b.a=a;b.b=function(a,b){return R(this,a,b)};return b}();function Zf(a){if(null==a.ca){var b=a.M(null);32this.end&&0===this.step)return this.start;throw Error("Index out of bounds");};g.da=function(a,b,c){return 0<=b&&bthis.end&&0===this.step?this.start:c};g.ma=function(){return new Xf(this.start,this.end,this.step)};g.O=function(){return this.m}; +g.W=function(){return 0this.end?new Yf(null,this.start+this.step,this.end,this.step,null,null,null):null};g.M=function(){return Math.ceil((this.end-this.start)/this.step)};g.S=function(){var a=this.s;return null!=a?a:this.s=a=Rc(this)};g.u=function(a,b){return gd(this,b)};g.Y=function(){return L};g.ea=function(a,b){return Yc(this,b)}; +g.fa=function(a,b,c){for(a=this.start;;)if(0this.end){c=b.b?b.b(c,a):b.call(null,c,a);if(Xc(c))return Ob(c);a+=this.step}else return c};g.ga=function(){return this.start};g.ia=function(){var a=this.W(null);return null==a?L:a};g.R=function(){return this};g.pb=function(){Zf(this);return this.ca};g.Sa=function(){Zf(this);return null==this.nb?L:this.nb};g.T=function(a,b){return b===this.m?this:new Yf(b,this.start,this.end,this.step,this.ca,this.nb,this.s)}; +g.U=function(a,b){return S(b,this)};g.yb=function(){return I(this.Sa(null))};Yf.prototype[rb]=function(){return Oc(this)}; +function $f(a,b,c,d,e,f,h){var k=cb;cb=null==cb?null:cb-1;try{if(null!=cb&&0>cb)return G(a,"#");G(a,c);if(0===kb.a(f))I(h)&&G(a,function(){var a=ag.a(f);return t(a)?a:"..."}());else{if(I(h)){var l=K(h);b.f?b.f(l,a,f):b.call(null,l,a,f)}for(var m=M(h),n=kb.a(f)-1;;)if(!m||null!=n&&0===n){I(m)&&0===n&&(G(a,d),G(a,function(){var a=ag.a(f);return t(a)?a:"..."}()));break}else{G(a,d);var q=K(m);c=a;h=f;b.f?b.f(q,c,h):b.call(null,q,c,h);var u=M(m);c=n-1;m=u;n=c}}return G(a,e)}finally{cb=k}} +function dg(a,b){b=I(b);for(var c=null,d=0,e=0;;)if(eparseFloat(Pi)){Oi=String(Ri);break a}}Oi=Pi}var Ua={}; +function Si(a){return Ta(a,function(){for(var b=0,c=pa(String(Oi)).split("."),d=pa(String(a)).split("."),e=Math.max(c.length,d.length),f=0;0==b&&f=a.keyCode)a.keyCode=-1}catch(b){}};var dj="closure_listenable_"+(1E6*Math.random()|0),ej=0;function fj(a,b,c,d,e){this.listener=a;this.proxy=null;this.src=b;this.type=c;this.capture=!!d;this.Cb=e;this.key=++ej;this.lb=this.wb=!1}function gj(a){a.lb=!0;a.listener=null;a.proxy=null;a.src=null;a.Cb=null};function hj(a){this.src=a;this.ua={};this.ub=0}hj.prototype.add=function(a,b,c,d,e){var f=a.toString();a=this.ua[f];a||(a=this.ua[f]=[],this.ub++);var h=ij(a,b,d,e);-1d.keyCode||void 0!=d.returnValue)){a:{var e=!1;if(0==d.keyCode)try{d.keyCode=-1;break a}catch(h){e=!0}if(e||void 0==d.returnValue)d.returnValue=!0}d=[];for(e=b.currentTarget;e;e=e.parentNode)d.push(e);a=a.type;for(e=d.length-1;!b.Eb&&0<=e;e--){b.currentTarget=d[e];var f=uj(d[e],a,!0,b);c=c&&f}for(e=0;!b.Eb&&e>>0);function oj(a){if(da(a))return a;a[wj]||(a[wj]=function(b){return a.handleEvent(b)});return a[wj]};var xj=new fb(null,2,[Ag,60,Qh,!0],null);var Z=null,Md=new fb(null,4,[Og,p5.prototype.JAVA2D,Uh,p5.prototype.P2D,yi,p5.prototype.P3D,eh,p5.prototype.OPENGL],null);function yj(a){if(N.b(yi,a))a=p5.prototype.WEBGL;else if(t(H.b(Md,a)))a=H.b(Md,a);else if(!t(ye(Uf([a]),mf(Md))))throw Error(["Expecting a keyword, got: ",A.a(a),". Expected one of: ",A.a($e(Kd()))].join(""));return a} +function zj(a,b,c){var d=a.Ob;return t(d)?(d=d.querySelector("canvas"),a.resizeCanvas(b,c),d.setAttribute("width",b),d.setAttribute("height",c),d.style.width=[A.a(b),"px"].join(""),d.style.height=[A.a(c),"px"].join(""),a.width=window.parseInt(Yi(d,"width")),a.height=window.parseInt(Yi(d,"height"))):null} +var Aj=function Aj(a){switch(arguments.length){case 2:return Aj.b(arguments[0],arguments[1]);case 3:return Aj.f(arguments[0],arguments[1],arguments[2]);default:throw Error(["Invalid arity: ",A.a(arguments.length)].join(""));}};Aj.b=function(a,b){return Z.createCanvas(a|0,b|0)};Aj.f=function(a,b,c){return Z.createCanvas(a|0,b|0,yj(c))};Aj.A=3; +function Bj(a,b){for(var c=I(Kf([ah,hh,mh,sh,wh,Mh,Rh,Wh,Xh,Yh,$h,gi,si],[Jh,Lg,zi,sh,Zg,Kh,Fg,Gg,th,fh,Bh,Eg,si])),d=null,e=0,f=0;;)if(f=document.body.childNodes.length,b=I(Ob(Gj)),c=null,d=0,e=0;;)if(ea?0:a>b?b:a} +function ck(){Kj().background(255);Ee.F(Z.jc,U,Ag,60);Z.frameRate(60);var a=Z.createGraphics(500,500);var b=Jj;Jj=a;try{Kj().background(255,40)}finally{Jj=b}return new fb(null,3,[Le,0,bh,ak(),ni,a],null)} +function dk(a){var b=Z.width,c=Z.height,d=.001*b,e=Z.mouseX,f=Z.mouseY,h=function(a,b,c,d,e,f,h,k,l,m,n){return function(a,b){t(Z.mouseIsPressed)?(a=m-a,b=n-b,b=Math.sqrt(a*a+b*b)-f):b=1E6;return b}}(b,c,.1,400,4E3,20,100,0,d,e,f,.0025,150),k=function(a,b,c,d,e,f,h){return function(c,d){var e=.5*(a-2*h),f=.5*(b-2*h);c=Math.abs(c-h-e)-e;f=Math.abs(d-h-f)-f;d=c>f?c:f;c=0>c?0:c;f=0>f?0:f;return h-(Math.sqrt(c*c+f*f)+(0>d?d:0))}}(b,c,.1,400,4E3,20,100,0,d,e,f,.0025,150,h),l=function(){return function(){return 1}}(b, +c,.1,400,4E3,20,100,0,d,e,f,.0025,150,h,k),m=function(a,b,c,d,e,f,h,k,l,m,n){return function(c,d){return t(Z.mouseIsPressed)?(m/a-.5)*d*.01+(n/b-.5)*c*-.01:0}}(b,c,.1,400,4E3,20,100,0,d,e,f,.0025,150,h,k,l),n=function(a,b,c,d,e,f,h,k,l,m,n,E,bg,fa,ia,ja,oa){return function(a,b,c){return e*(oa(a,b)+Z.noise(E*a,E*b,E*c))}}(b,c,.1,400,4E3,20,100,0,d,e,f,.0025,150,h,k,l,m);b=Fe.b(function(b,c,d,e,f,h,k,l,m,n,ha,E,bg,fa,ia,ja,oa,qa,ra){return function(d){var e=T(d,0),f=T(d,1),h=T(d,2);d=T(d,3);var k=Le.a(a)/ +20,l=ra(h,d,k),n=ra(h+m,d,k);k=(ra(h,d+m,k)-l)/m;h+=k;d+=(l-n)/m;d=0>h||h>b||0>d||d>c?new W(null,2,5,Y,[Z.random(b),Z.random(c)],null):new W(null,2,5,Y,[h,d],null);h=T(d,0);d=T(d,1);return new W(null,4,5,Y,[e,f,h,d],null)}}(b,c,.1,400,4E3,20,100,0,d,e,f,.0025,150,h,k,l,m,n,function(a,b,c,d,e,f,h,k,l,m,n,E,bg,fa,ia,ja,oa,qa){return function(a,b,d){return c*ja(a,b)*qa(a,b,d)}}(b,c,.1,400,4E3,20,100,0,d,e,f,.0025,150,h,k,l,m,n)),bh.a(a));return U.f(Ke(a),bh,b)} +function ek(a){var b=ni.a(a);Kj().image(b,0,0);b=Kj();b.loadPixels();b=b.pixels;var c=Z.width,d=Z.height;Kj().color(0);a=I(bh.a(a));for(var e=null,f=0,h=0;;)if(hstr [ty] + (if-let [s (.-cljs$lang$ctorStr ty)] + s + (str ty))) + +;; INTERNAL - do not use, only for Node.js +(defn load-file [file] + (when-not js/COMPILED + (cljs.core/load-file* file))) + +(if (and (exists? js/Symbol) + (identical? (goog/typeOf js/Symbol) "function")) + (def ITER_SYMBOL (.-iterator js/Symbol)) + (def ITER_SYMBOL "@@iterator")) + +(def ^{:jsdoc ["@enum {string}"]} + CHAR_MAP + #js {"-" "_" + ":" "_COLON_" + "+" "_PLUS_" + ">" "_GT_" + "<" "_LT_" + "=" "_EQ_" + "~" "_TILDE_" + "!" "_BANG_" + "@" "_CIRCA_" + "#" "_SHARP_" + "'" "_SINGLEQUOTE_" + "\\\"" "_DOUBLEQUOTE_" + "%" "_PERCENT_" + "^" "_CARET_" + "&" "_AMPERSAND_" + "*" "_STAR_" + "|" "_BAR_" + "{" "_LBRACE_" + "}" "_RBRACE_" + "[" "_LBRACK_" + "]" "_RBRACK_" + "/" "_SLASH_" + "\\\\" "_BSLASH_" + "?" "_QMARK_"}) + +(def ^{:jsdoc ["@enum {string}"]} + DEMUNGE_MAP + #js {"_" "-" + "_COLON_" ":" + "_PLUS_" "+" + "_GT_" ">" + "_LT_" "<" + "_EQ_" "=" + "_TILDE_" "~" + "_BANG_" "!" + "_CIRCA_" "@" + "_SHARP_" "#" + "_SINGLEQUOTE_" "'" + "_DOUBLEQUOTE_" "\\\"" + "_PERCENT_" "%" + "_CARET_" "^" + "_AMPERSAND_" "&" + "_STAR_" "*" + "_BAR_" "|" + "_LBRACE_" "{" + "_RBRACE_" "}" + "_LBRACK_" "[" + "_RBRACK_" "]" + "_SLASH_" "/" + "_BSLASH_" "\\\\" + "_QMARK_" "?"}) + +(def DEMUNGE_PATTERN nil) + +(defn system-time + "Returns highest resolution time offered by host in milliseconds." + [] + (cond + (and (exists? js/performance) + (not (nil? (. js/performance -now)))) + (.now js/performance) + + (and (exists? js/process) + (not (nil? (. js/process -hrtime)))) + (let [t (.hrtime js/process)] + (/ (+ (* (aget t 0) 1e9) (aget t 1)) 1e6)) + + :else (.getTime (js/Date.)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; arrays ;;;;;;;;;;;;;;;; + +(declare apply) + +(defn ^array make-array + "Construct a JavaScript array of the specified dimensions. Accepts ignored + type argument for compatibility with Clojure. Note that there is no efficient + way to allocate multi-dimensional arrays in JavaScript; as such, this function + will run in polynomial time when called with 3 or more arguments." + ([size] + (js/Array. size)) + ([type size] + (make-array size)) + ([type size & more-sizes] + (let [dims more-sizes + dimarray (make-array size)] + (dotimes [i (alength dimarray)] + (aset dimarray i (apply make-array nil dims))) + dimarray))) + +(defn aclone + "Returns a javascript array, cloned from the passed in array" + [arr] + (let [len (alength arr) + new-arr (make-array len)] + (dotimes [i len] + (aset new-arr i (aget arr i))) + new-arr)) + +(defn ^array array + "Creates a new javascript array. +@param {...*} var_args" ;;array is a special case, don't emulate this doc string + [var-args] ;; [& items] + (let [a (js/Array. (alength (cljs.core/js-arguments)))] + (loop [i 0] + (if (< i (alength a)) + (do + (aset a i (aget (cljs.core/js-arguments) i)) + (recur (inc i))) + a)))) + +(defn- maybe-warn + [e] + (when *print-err-fn* + (*print-err-fn* e))) + +(defn- checked-aget + ([array idx] + (when-assert + (try + (assert (or (array? array) (goog/isArrayLike array))) + (assert (number? idx)) + (assert (not (neg? idx))) + (assert (< idx (alength array))) + (catch :default e + (maybe-warn e)))) + (unchecked-get array idx)) + ([array idx & idxs] + (apply checked-aget (checked-aget array idx) idxs))) + +(defn- checked-aset + ([array idx val] + (when-assert + (try + (assert (or (array? array) (goog/isArrayLike array))) + (assert (number? idx)) + (assert (not (neg? idx))) + (assert (< idx (alength array))) + (catch :default e + (maybe-warn e)))) + (unchecked-set array idx val)) + ([array idx idx2 & idxv] + (apply checked-aset (checked-aget array idx) idx2 idxv))) + +(defn- checked-aget' + ([array idx] + {:pre [(or (array? array) (goog/isArrayLike array)) + (number? idx) (not (neg? idx)) (< idx (alength array))]} + (unchecked-get array idx)) + ([array idx & idxs] + (apply checked-aget' (checked-aget' array idx) idxs))) + +(defn- checked-aset' + ([array idx val] + {:pre [(or (array? array) (goog/isArrayLike array)) + (number? idx) (not (neg? idx)) (< idx (alength array))]} + (unchecked-set array idx val)) + ([array idx idx2 & idxv] + (apply checked-aset' (checked-aget' array idx) idx2 idxv))) + +(defn aget + "Returns the value at the index/indices. Works on JavaScript arrays." + ([array idx] + (cljs.core/aget array idx)) + ([array idx & idxs] + (apply aget (aget array idx) idxs))) + +(defn aset + "Sets the value at the index/indices. Works on JavaScript arrays. + Returns val." + ([array idx val] + (cljs.core/aset array idx val)) + ([array idx idx2 & idxv] + (apply aset (aget array idx) idx2 idxv))) + +(defn ^number alength + "Returns the length of the array. Works on arrays of all types." + [array] + (cljs.core/alength array)) + +(declare reduce) + +(defn ^array into-array + "Returns an array with components set to the values in aseq. Optional type + argument accepted for compatibility with Clojure." + ([aseq] + (into-array nil aseq)) + ([type aseq] + (reduce (fn [a x] (.push a x) a) (array) aseq))) + +(defn js-invoke + "Invoke JavaScript object method via string. Needed when the + string is not a valid unquoted property name." + [obj s & args] + (.apply (unchecked-get obj s) obj (into-array args))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;; core protocols ;;;;;;;;;;;;; + +(defprotocol Fn + "Marker protocol") + +(defprotocol IFn + "Protocol for adding the ability to invoke an object as a function. + For example, a vector can also be used to look up a value: + ([1 2 3 4] 1) => 2" + (-invoke + [this] + [this a] + [this a b] + [this a b c] + [this a b c d] + [this a b c d e] + [this a b c d e f] + [this a b c d e f g] + [this a b c d e f g h] + [this a b c d e f g h i] + [this a b c d e f g h i j] + [this a b c d e f g h i j k] + [this a b c d e f g h i j k l] + [this a b c d e f g h i j k l m] + [this a b c d e f g h i j k l m n] + [this a b c d e f g h i j k l m n o] + [this a b c d e f g h i j k l m n o p] + [this a b c d e f g h i j k l m n o p q] + [this a b c d e f g h i j k l m n o p q r] + [this a b c d e f g h i j k l m n o p q r s] + [this a b c d e f g h i j k l m n o p q r s t] + [this a b c d e f g h i j k l m n o p q r s t rest])) + +(defprotocol ICloneable + "Protocol for cloning a value." + (^clj -clone [value] + "Creates a clone of value.")) + +(defprotocol ICounted + "Protocol for adding the ability to count a collection in constant time." + (^number -count [coll] + "Calculates the count of coll in constant time. Used by cljs.core/count.")) + +(defprotocol IEmptyableCollection + "Protocol for creating an empty collection." + (-empty [coll] + "Returns an empty collection of the same category as coll. Used + by cljs.core/empty.")) + +(defprotocol ICollection + "Protocol for adding to a collection." + (^clj -conj [coll o] + "Returns a new collection of coll with o added to it. The new item + should be added to the most efficient place, e.g. + (conj [1 2 3 4] 5) => [1 2 3 4 5] + (conj '(2 3 4 5) 1) => '(1 2 3 4 5)")) + +#_(defprotocol IOrdinal + (-index [coll])) + +(defprotocol IIndexed + "Protocol for collections to provide indexed-based access to their items." + (-nth [coll n] [coll n not-found] + "Returns the value at the index n in the collection coll. + Returns not-found if index n is out of bounds and not-found is supplied.")) + +(defprotocol ASeq + "Marker protocol indicating an array sequence.") + +(defprotocol ISeq + "Protocol for collections to provide access to their items as sequences." + (-first [coll] + "Returns the first item in the collection coll. Used by cljs.core/first.") + (^clj -rest [coll] + "Returns a new collection of coll without the first item. It should + always return a seq, e.g. + (rest []) => () + (rest nil) => ()")) + +(defprotocol INext + "Protocol for accessing the next items of a collection." + (^clj-or-nil -next [coll] + "Returns a new collection of coll without the first item. In contrast to + rest, it should return nil if there are no more items, e.g. + (next []) => nil + (next nil) => nil")) + +(defprotocol ILookup + "Protocol for looking up a value in a data structure." + (-lookup [o k] [o k not-found] + "Use k to look up a value in o. If not-found is supplied and k is not + a valid value that can be used for look up, not-found is returned.")) + +(defprotocol IAssociative + "Protocol for adding associativity to collections." + (^boolean -contains-key? [coll k] + "Returns true if k is a key in coll.") + #_(-entry-at [coll k]) + (^clj -assoc [coll k v] + "Returns a new collection of coll with a mapping from key k to + value v added to it.")) + +(defprotocol IFind + "Protocol for implementing entry finding in collections." + (-find [coll k] "Returns the map entry for key, or nil if key not present.")) + +(defprotocol IMap + "Protocol for adding mapping functionality to collections." + #_(-assoc-ex [coll k v]) + (^clj -dissoc [coll k] + "Returns a new collection of coll without the mapping for key k.")) + +(defprotocol IMapEntry + "Protocol for examining a map entry." + (-key [coll] + "Returns the key of the map entry.") + (-val [coll] + "Returns the value of the map entry.")) + +(defprotocol ISet + "Protocol for adding set functionality to a collection." + (^clj -disjoin [coll v] + "Returns a new collection of coll that does not contain v.")) + +(defprotocol IStack + "Protocol for collections to provide access to their items as stacks. The top + of the stack should be accessed in the most efficient way for the different + data structures." + (-peek [coll] + "Returns the item from the top of the stack. Is used by cljs.core/peek.") + (^clj -pop [coll] + "Returns a new stack without the item on top of the stack. Is used + by cljs.core/pop.")) + +(defprotocol IVector + "Protocol for adding vector functionality to collections." + (^clj -assoc-n [coll n val] + "Returns a new vector with value val added at position n.")) + +(defprotocol IDeref + "Protocol for adding dereference functionality to a reference." + (-deref [o] + "Returns the value of the reference o.")) + +(defprotocol IDerefWithTimeout + (-deref-with-timeout [o msec timeout-val])) + +(defprotocol IMeta + "Protocol for accessing the metadata of an object." + (^clj-or-nil -meta [o] + "Returns the metadata of object o.")) + +(defprotocol IWithMeta + "Protocol for adding metadata to an object." + (^clj -with-meta [o meta] + "Returns a new object with value of o and metadata meta added to it.")) + +(defprotocol IReduce + "Protocol for seq types that can reduce themselves. + Called by cljs.core/reduce." + (-reduce [coll f] [coll f start] + "f should be a function of 2 arguments. If start is not supplied, + returns the result of applying f to the first 2 items in coll, then + applying f to that result and the 3rd item, etc.")) + +(defprotocol IKVReduce + "Protocol for associative types that can reduce themselves + via a function of key and val. Called by cljs.core/reduce-kv." + (-kv-reduce [coll f init] + "Reduces an associative collection and returns the result. f should be + a function that takes three arguments.")) + +(defprotocol IEquiv + "Protocol for adding value comparison functionality to a type." + (^boolean -equiv [o other] + "Returns true if o and other are equal, false otherwise.")) + +(defprotocol IHash + "Protocol for adding hashing functionality to a type." + (-hash [o] + "Returns the hash code of o.")) + +(defprotocol ISeqable + "Protocol for adding the ability to a type to be transformed into a sequence." + (^clj-or-nil -seq [o] + "Returns a seq of o, or nil if o is empty.")) + +(defprotocol ISequential + "Marker interface indicating a persistent collection of sequential items") + +(defprotocol IList + "Marker interface indicating a persistent list") + +(defprotocol IRecord + "Marker interface indicating a record object") + +(defprotocol IReversible + "Protocol for reversing a seq." + (^clj -rseq [coll] + "Returns a seq of the items in coll in reversed order.")) + +(defprotocol ISorted + "Protocol for a collection which can represent their items + in a sorted manner. " + (^clj -sorted-seq [coll ascending?] + "Returns a sorted seq from coll in either ascending or descending order.") + (^clj -sorted-seq-from [coll k ascending?] + "Returns a sorted seq from coll in either ascending or descending order. + If ascending is true, the result should contain all items which are > or >= + than k. If ascending is false, the result should contain all items which + are < or <= than k, e.g. + (-sorted-seq-from (sorted-set 1 2 3 4 5) 3 true) => (3 4 5) + (-sorted-seq-from (sorted-set 1 2 3 4 5) 3 false) => (3 2 1)") + (-entry-key [coll entry] + "Returns the key for entry.") + (-comparator [coll] + "Returns the comparator for coll.")) + +(defprotocol IWriter + "Protocol for writing. Currently only implemented by StringBufferWriter." + (-write [writer s] + "Writes s with writer and returns the result.") + (-flush [writer] + "Flush writer.")) + +(defprotocol IPrintWithWriter + "The old IPrintable protocol's implementation consisted of building a giant + list of strings to concatenate. This involved lots of concat calls, + intermediate vectors, and lazy-seqs, and was very slow in some older JS + engines. IPrintWithWriter implements printing via the IWriter protocol, so it + be implemented efficiently in terms of e.g. a StringBuffer append." + (-pr-writer [o writer opts])) + +(defprotocol IPending + "Protocol for types which can have a deferred realization. Currently only + implemented by Delay and LazySeq." + (^boolean -realized? [x] + "Returns true if a value for x has been produced, false otherwise.")) + +(defprotocol IWatchable + "Protocol for types that can be watched. Currently only implemented by Atom." + (-notify-watches [this oldval newval] + "Calls all watchers with this, oldval and newval.") + (-add-watch [this key f] + "Adds a watcher function f to this. Keys must be unique per reference, + and can be used to remove the watch with -remove-watch.") + (-remove-watch [this key] + "Removes watcher that corresponds to key from this.")) + +(defprotocol IEditableCollection + "Protocol for collections which can transformed to transients." + (^clj -as-transient [coll] + "Returns a new, transient version of the collection, in constant time.")) + +(defprotocol ITransientCollection + "Protocol for adding basic functionality to transient collections." + (^clj -conj! [tcoll val] + "Adds value val to tcoll and returns tcoll.") + (^clj -persistent! [tcoll] + "Creates a persistent data structure from tcoll and returns it.")) + +(defprotocol ITransientAssociative + "Protocol for adding associativity to transient collections." + (^clj -assoc! [tcoll key val] + "Returns a new transient collection of tcoll with a mapping from key to + val added to it.")) + +(defprotocol ITransientMap + "Protocol for adding mapping functionality to transient collections." + (^clj -dissoc! [tcoll key] + "Returns a new transient collection of tcoll without the mapping for key.")) + +(defprotocol ITransientVector + "Protocol for adding vector functionality to transient collections." + (^clj -assoc-n! [tcoll n val] + "Returns tcoll with value val added at position n.") + (^clj -pop! [tcoll] + "Returns tcoll with the last item removed from it.")) + +(defprotocol ITransientSet + "Protocol for adding set functionality to a transient collection." + (^clj -disjoin! [tcoll v] + "Returns tcoll without v.")) + +(defprotocol IComparable + "Protocol for values that can be compared." + (^number -compare [x y] + "Returns a negative number, zero, or a positive number when x is logically + 'less than', 'equal to', or 'greater than' y.")) + +(defprotocol IChunk + "Protocol for accessing the items of a chunk." + (-drop-first [coll] + "Return a new chunk of coll with the first item removed.")) + +(defprotocol IChunkedSeq + "Protocol for accessing a collection as sequential chunks." + (-chunked-first [coll] + "Returns the first chunk in coll.") + (-chunked-rest [coll] + "Return a new collection of coll with the first chunk removed.")) + +(defprotocol IChunkedNext + "Protocol for accessing the chunks of a collection." + (-chunked-next [coll] + "Returns a new collection of coll without the first chunk.")) + +(defprotocol INamed + "Protocol for adding a name." + (^string -name [x] + "Returns the name String of x.") + ( ^{:tag #{string clj-nil}}-namespace [x] + "Returns the namespace String of x.")) + +(defprotocol IAtom + "Marker protocol indicating an atom.") + +(defprotocol IReset + "Protocol for adding resetting functionality." + (-reset! [o new-value] + "Sets the value of o to new-value.")) + +(defprotocol ISwap + "Protocol for adding swapping functionality." + (-swap! [o f] [o f a] [o f a b] [o f a b xs] + "Swaps the value of o to be (apply f current-value-of-atom args).")) + +(defprotocol IVolatile + "Protocol for adding volatile functionality." + (-vreset! [o new-value] + "Sets the value of volatile o to new-value without regard for the + current value. Returns new-value.")) + +(defprotocol IIterable + "Protocol for iterating over a collection." + (-iterator [coll] + "Returns an iterator for coll.")) + +;; Printing support + +(deftype StringBufferWriter [sb] + IWriter + (-write [_ s] (.append sb s)) + (-flush [_] nil)) + +(defn pr-str* + "Support so that collections can implement toString without + loading all the printing machinery." + [^not-native obj] + (let [sb (StringBuffer.) + writer (StringBufferWriter. sb)] + (-pr-writer obj writer (pr-opts)) + (-flush writer) + (str sb))) + +;;;;;;;;;;;;;;;;;;; Murmur3 ;;;;;;;;;;;;;;; + +;;http://hg.openjdk.java.net/jdk7u/jdk7u6/jdk/file/8c2c5d63a17e/src/share/classes/java/lang/Integer.java +(defn ^number int-rotate-left [x n] + (bit-or + (bit-shift-left x n) + (unsigned-bit-shift-right x (- n)))) + +;; http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul +(if (and (exists? Math/imul) + (not (zero? (Math/imul 0xffffffff 5)))) + (defn ^number imul [a b] (Math/imul a b)) + (defn ^number imul [a b] + (let [ah (bit-and (unsigned-bit-shift-right a 16) 0xffff) + al (bit-and a 0xffff) + bh (bit-and (unsigned-bit-shift-right b 16) 0xffff) + bl (bit-and b 0xffff)] + (bit-or + (+ (* al bl) + (unsigned-bit-shift-right + (bit-shift-left (+ (* ah bl) (* al bh)) 16) 0)) 0)))) + +;; http://smhasher.googlecode.com/svn/trunk/MurmurHash3.cpp +(def m3-seed 0) +(def m3-C1 (int 0xcc9e2d51)) +(def m3-C2 (int 0x1b873593)) + +(defn ^number m3-mix-K1 [k1] + (-> (int k1) (imul m3-C1) (int-rotate-left 15) (imul m3-C2))) + +(defn ^number m3-mix-H1 [h1 k1] + (int (-> (int h1) (bit-xor (int k1)) (int-rotate-left 13) (imul 5) (+ (int 0xe6546b64))))) + +(defn ^number m3-fmix [h1 len] + (as-> (int h1) h1 + (bit-xor h1 len) + (bit-xor h1 (unsigned-bit-shift-right h1 16)) + (imul h1 (int 0x85ebca6b)) + (bit-xor h1 (unsigned-bit-shift-right h1 13)) + (imul h1 (int 0xc2b2ae35)) + (bit-xor h1 (unsigned-bit-shift-right h1 16)))) + +(defn ^number m3-hash-int [in] + (if (zero? in) + in + (let [k1 (m3-mix-K1 in) + h1 (m3-mix-H1 m3-seed k1)] + (m3-fmix h1 4)))) + +(defn ^number m3-hash-unencoded-chars [in] + (let [h1 (loop [i 1 h1 m3-seed] + (if (< i (.-length in)) + (recur (+ i 2) + (m3-mix-H1 h1 + (m3-mix-K1 + (bit-or (.charCodeAt in (dec i)) + (bit-shift-left (.charCodeAt in i) 16))))) + h1)) + h1 (if (== (bit-and (.-length in) 1) 1) + (bit-xor h1 (m3-mix-K1 (.charCodeAt in (dec (.-length in))))) + h1)] + (m3-fmix h1 (imul 2 (.-length in))))) + +;;;;;;;;;;;;;;;;;;; symbols ;;;;;;;;;;;;;;; + +(declare list Symbol = compare) + +;; Simple caching of string hashcode +(def string-hash-cache (js-obj)) +(def string-hash-cache-count 0) + +;;http://hg.openjdk.java.net/jdk7u/jdk7u6/jdk/file/8c2c5d63a17e/src/share/classes/java/lang/String.java +(defn hash-string* [s] + (if-not (nil? s) + (let [len (.-length s)] + (if (pos? len) + (loop [i 0 hash 0] + (if (< i len) + (recur (inc i) (+ (imul 31 hash) (.charCodeAt s i))) + hash)) + 0)) + 0)) + +(defn add-to-string-hash-cache [k] + (let [h (hash-string* k)] + (gobject/set string-hash-cache k h) + (set! string-hash-cache-count (inc string-hash-cache-count)) + h)) + +(defn hash-string [k] + (when (> string-hash-cache-count 255) + (set! string-hash-cache (js-obj)) + (set! string-hash-cache-count 0)) + (if (nil? k) + 0 + (let [h (unchecked-get string-hash-cache k)] + (if (number? h) + h + (add-to-string-hash-cache k))))) + +(defn hash + "Returns the hash code of its argument. Note this is the hash code + consistent with =." + [o] + (cond + (implements? IHash o) + (bit-xor (-hash o) 0) + + (number? o) + (if (js/isFinite o) + (js-mod (Math/floor o) 2147483647) + (case o + ##Inf + 2146435072 + ##-Inf + -1048576 + 2146959360)) + + ;; note: mirrors Clojure's behavior on the JVM, where the hashCode is + ;; 1231 for true and 1237 for false + ;; http://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#hashCode%28%29 + (true? o) 1231 + + (false? o) 1237 + + (string? o) + (m3-hash-int (hash-string o)) + + (instance? js/Date o) + (bit-xor (.valueOf o) 0) + + (nil? o) 0 + + :else + (bit-xor (-hash o) 0))) + +(defn hash-combine [seed hash] + ; a la boost + (bit-xor seed + (+ hash 0x9e3779b9 + (bit-shift-left seed 6) + (bit-shift-right seed 2)))) + +(defn ^boolean instance? + "Evaluates x and tests if it is an instance of the type + c. Returns true or false" + [c x] + (cljs.core/instance? c x)) + +(defn ^boolean symbol? + "Return true if x is a Symbol" + [x] + (instance? Symbol x)) + +(defn- hash-symbol [sym] + (hash-combine + (m3-hash-unencoded-chars (.-name sym)) + (hash-string (.-ns sym)))) + +(defn- compare-symbols [a b] + (cond + (identical? (.-str a) (.-str b)) 0 + (and (not (.-ns a)) (.-ns b)) -1 + (.-ns a) (if-not (.-ns b) + 1 + (let [nsc (garray/defaultCompare (.-ns a) (.-ns b))] + (if (== 0 nsc) + (garray/defaultCompare (.-name a) (.-name b)) + nsc))) + :default (garray/defaultCompare (.-name a) (.-name b)))) + +(declare get) + +(deftype Symbol [ns name str ^:mutable _hash _meta] + Object + (toString [_] str) + (equiv [this other] (-equiv this other)) + + IEquiv + (-equiv [_ other] + (if (instance? Symbol other) + (identical? str (.-str other)) + false)) + + IFn + (-invoke [sym coll] + (get coll sym)) + (-invoke [sym coll not-found] + (get coll sym not-found)) + + IMeta + (-meta [_] _meta) + + IWithMeta + (-with-meta [_ new-meta] (Symbol. ns name str _hash new-meta)) + + IHash + (-hash [sym] + (caching-hash sym hash-symbol _hash)) + + INamed + (-name [_] name) + (-namespace [_] ns) + + IPrintWithWriter + (-pr-writer [o writer _] (-write writer str))) + +(defn var? + "Returns true if v is of type cljs.core.Var" + [v] + (instance? cljs.core.Var v)) + +(defn symbol + "Returns a Symbol with the given namespace and name. Arity-1 works + on strings, keywords, and vars." + ([name] + (cond (symbol? name) name + (string? name) (let [idx (.indexOf name "/")] + (if (< idx 1) + (symbol nil name) + (symbol (.substring name 0 idx) + (.substring name (inc idx) (. name -length))))) + (var? name) (.-sym name) + (keyword? name) (recur (.-fqn name)) + :else (throw (new js/Error "no conversion to symbol")))) + ([ns name] + (let [sym-str (if-not (nil? ns) + (str ns "/" name) + name)] + (Symbol. ns name sym-str nil nil)))) + +(deftype Var [val sym _meta] + Object + (isMacro [_] + (. (val) -cljs$lang$macro)) + (toString [_] + (str "#'" sym)) + IDeref + (-deref [_] (val)) + IMeta + (-meta [_] _meta) + IWithMeta + (-with-meta [_ new-meta] + (Var. val sym new-meta)) + IEquiv + (-equiv [this other] + (if (instance? Var other) + (= (.-sym this) (.-sym other)) + false)) + IHash + (-hash [_] + (hash-symbol sym)) + Fn + IFn + (-invoke [_] + ((val))) + (-invoke [_ a] + ((val) a)) + (-invoke [_ a b] + ((val) a b)) + (-invoke [_ a b c] + ((val) a b c)) + (-invoke [_ a b c d] + ((val) a b c d)) + (-invoke [_ a b c d e] + ((val) a b c d e)) + (-invoke [_ a b c d e f] + ((val) a b c d e f)) + (-invoke [_ a b c d e f g] + ((val) a b c d e f g)) + (-invoke [_ a b c d e f g h] + ((val) a b c d e f g h)) + (-invoke [_ a b c d e f g h i] + ((val) a b c d e f g h i)) + (-invoke [_ a b c d e f g h i j] + ((val) a b c d e f g h i j)) + (-invoke [_ a b c d e f g h i j k] + ((val) a b c d e f g h i j k)) + (-invoke [_ a b c d e f g h i j k l] + ((val) a b c d e f g h i j k l)) + (-invoke [_ a b c d e f g h i j k l m] + ((val) a b c d e f g h i j k l m)) + (-invoke [_ a b c d e f g h i j k l m n] + ((val) a b c d e f g h i j k l m n)) + (-invoke [_ a b c d e f g h i j k l m n o] + ((val) a b c d e f g h i j k l m n o)) + (-invoke [_ a b c d e f g h i j k l m n o p] + ((val) a b c d e f g h i j k l m n o p)) + (-invoke [_ a b c d e f g h i j k l m n o p q] + ((val) a b c d e f g h i j k l m n o p q)) + (-invoke [_ a b c d e f g h i j k l m n o p q r] + ((val) a b c d e f g h i j k l m n o p q r)) + (-invoke [_ a b c d e f g h i j k l m n o p q r s] + ((val) a b c d e f g h i j k l m n o p q r s)) + (-invoke [_ a b c d e f g h i j k l m n o p q r s t] + ((val) a b c d e f g h i j k l m n o p q r s t)) + (-invoke [_ a b c d e f g h i j k l m n o p q r s t rest] + (apply (val) a b c d e f g h i j k l m n o p q r s t rest))) + +;;;;;;;;;;;;;;;;;;; fundamentals ;;;;;;;;;;;;;;; + +(declare array-seq prim-seq IndexedSeq) + +(defn iterable? + "Return true if x implements IIterable protocol." + [x] + (satisfies? IIterable x)) + +(defn clone + "Clone the supplied value which must implement ICloneable." + [value] + (-clone value)) + +(defn cloneable? + "Return true if x implements ICloneable protocol." + [value] + (satisfies? ICloneable value)) + +(defn ^seq seq + "Returns a seq on the collection. If the collection is + empty, returns nil. (seq nil) returns nil. seq also works on + Strings." + [coll] + (when-not (nil? coll) + (cond + (implements? ISeqable coll) + (-seq coll) + + (array? coll) + (when-not (zero? (alength coll)) + (IndexedSeq. coll 0 nil)) + + (string? coll) + (when-not (zero? (.-length coll)) + (IndexedSeq. coll 0 nil)) + + (native-satisfies? ISeqable coll) + (-seq coll) + + :else (throw (js/Error. (str coll " is not ISeqable")))))) + +(defn first + "Returns the first item in the collection. Calls seq on its + argument. If coll is nil, returns nil." + [coll] + (when-not (nil? coll) + (if (implements? ISeq coll) + (-first coll) + (let [s (seq coll)] + (when-not (nil? s) + (-first s)))))) + +(defn ^seq rest + "Returns a possibly empty seq of the items after the first. Calls seq on its + argument." + [coll] + (if-not (nil? coll) + (if (implements? ISeq coll) + (-rest coll) + (let [s (seq coll)] + (if s + (-rest ^not-native s) + ()))) + ())) + +(defn ^seq next + "Returns a seq of the items after the first. Calls seq on its + argument. If there are no more items, returns nil" + [coll] + (when-not (nil? coll) + (if (implements? INext coll) + (-next coll) + (seq (rest coll))))) + +(defn ^boolean = + "Equality. Returns true if x equals y, false if not. Compares + numbers and collections in a type-independent manner. Clojure's immutable data + structures define -equiv (and thus =) as a value, not an identity, + comparison." + ([x] true) + ([x y] + (if (nil? x) + (nil? y) + (or (identical? x y) + ^boolean (-equiv x y)))) + ([x y & more] + (if (= x y) + (if (next more) + (recur y (first more) (next more)) + (= y (first more))) + false))) + +;; EXPERIMENTAL: subject to change +(deftype ES6Iterator [^:mutable s] + Object + (next [_] + (if-not (nil? s) + (let [x (first s)] + (set! s (next s)) + #js {:value x :done false}) + #js {:value nil :done true}))) + +(defn es6-iterator + "EXPERIMENTAL: Return a ES2015 compatible iterator for coll." + [coll] + (ES6Iterator. (seq coll))) + +(declare es6-iterator-seq) + +(deftype ES6IteratorSeq [value iter ^:mutable _rest] + ISeqable + (-seq [this] this) + ISeq + (-first [_] value) + (-rest [_] + (when (nil? _rest) + (set! _rest (es6-iterator-seq iter))) + _rest)) + +(defn es6-iterator-seq + "EXPERIMENTAL: Given an ES2015 compatible iterator return a seq." + [iter] + (let [v (.next iter)] + (if (.-done v) + () + (ES6IteratorSeq. (.-value v) iter nil)))) + +;;;;;;;;;;;;;;;;;;; Murmur3 Helpers ;;;;;;;;;;;;;;;; + +(defn ^number mix-collection-hash + "Mix final collection hash for ordered or unordered collections. + hash-basis is the combined collection hash, count is the number + of elements included in the basis. Note this is the hash code + consistent with =, different from .hashCode. + See http://clojure.org/data_structures#hash for full algorithms." + [hash-basis count] + (let [h1 m3-seed + k1 (m3-mix-K1 hash-basis) + h1 (m3-mix-H1 h1 k1)] + (m3-fmix h1 count))) + +(defn ^number hash-ordered-coll + "Returns the hash code, consistent with =, for an external ordered + collection implementing Iterable. + See http://clojure.org/data_structures#hash for full algorithms." + [coll] + (loop [n 0 hash-code 1 coll (seq coll)] + (if-not (nil? coll) + (recur (inc n) (bit-or (+ (imul 31 hash-code) (hash (first coll))) 0) + (next coll)) + (mix-collection-hash hash-code n)))) + +(def ^:private empty-ordered-hash + (mix-collection-hash 1 0)) + +(defn ^number hash-unordered-coll + "Returns the hash code, consistent with =, for an external unordered + collection implementing Iterable. For maps, the iterator should + return map entries whose hash is computed as + (hash-ordered-coll [k v]). + See http://clojure.org/data_structures#hash for full algorithms." + [coll] + (loop [n 0 hash-code 0 coll (seq coll)] + (if-not (nil? coll) + (recur (inc n) (bit-or (+ hash-code (hash (first coll))) 0) (next coll)) + (mix-collection-hash hash-code n)))) + +(def ^:private empty-unordered-hash + (mix-collection-hash 0 0)) + +;;;;;;;;;;;;;;;;;;; protocols on primitives ;;;;;;;; +(declare hash-map list equiv-sequential) + +(extend-type nil + ICounted + (-count [_] 0)) + +;; TODO: we should remove this and handle date equality checking +;; by some other means, probably by adding a new primitive type +;; case to the hash table lookup - David + +(extend-type js/Date + IEquiv + (-equiv [o other] + (and (instance? js/Date other) + (== (.valueOf o) (.valueOf other)))) + + IComparable + (-compare [this other] + (if (instance? js/Date other) + (garray/defaultCompare (.valueOf this) (.valueOf other)) + (throw (js/Error. (str "Cannot compare " this " to " other)))))) + +(defprotocol Inst + (inst-ms* [inst])) + +(extend-protocol Inst + js/Date + (inst-ms* [inst] (.getTime inst))) + +(defn inst-ms + "Return the number of milliseconds since January 1, 1970, 00:00:00 GMT" + [inst] + (inst-ms* inst)) + +(defn inst? + "Return true if x satisfies Inst" + [x] + (satisfies? Inst x)) + +(extend-type number + IEquiv + (-equiv [x o] (identical? x o))) + +(declare with-meta) + +(extend-type function + Fn + IMeta + (-meta [_] nil)) + +(extend-type default + IHash + (-hash [o] + (goog/getUid o))) + +;;this is primitive because & emits call to array-seq +(defn inc + "Returns a number one greater than num." + [x] (cljs.core/+ x 1)) + +(declare deref) + +(deftype Reduced [val] + IDeref + (-deref [o] val)) + +(defn reduced + "Wraps x in a way such that a reduce will terminate with the value x" + [x] + (Reduced. x)) + +(defn reduced? + "Returns true if x is the result of a call to reduced" + [r] + (instance? Reduced r)) + +(defn ensure-reduced + "If x is already reduced?, returns it, else returns (reduced x)" + [x] + (if (reduced? x) x (reduced x))) + +(defn unreduced + "If x is reduced?, returns (deref x), else returns x" + [x] + (if (reduced? x) (deref x) x)) + +;; generic to all refs +;; (but currently hard-coded to atom!) +(defn deref + "Also reader macro: @var/@atom/@delay. Returns the + most-recently-committed value of ref. When applied to a var + or atom, returns its current state. When applied to a delay, forces + it if not already forced. See also - realized?." + [o] + (-deref o)) + +(defn- ci-reduce + "Accepts any collection which satisfies the ICount and IIndexed protocols and +reduces them without incurring seq initialization" + ([cicoll f] + (let [cnt (-count cicoll)] + (if (zero? cnt) + (f) + (loop [val (-nth cicoll 0), n 1] + (if (< n cnt) + (let [nval (f val (-nth cicoll n))] + (if (reduced? nval) + @nval + (recur nval (inc n)))) + val))))) + ([cicoll f val] + (let [cnt (-count cicoll)] + (loop [val val, n 0] + (if (< n cnt) + (let [nval (f val (-nth cicoll n))] + (if (reduced? nval) + @nval + (recur nval (inc n)))) + val)))) + ([cicoll f val idx] + (let [cnt (-count cicoll)] + (loop [val val, n idx] + (if (< n cnt) + (let [nval (f val (-nth cicoll n))] + (if (reduced? nval) + @nval + (recur nval (inc n)))) + val))))) + +(defn- array-reduce + ([arr f] + (let [cnt (alength arr)] + (if (zero? (alength arr)) + (f) + (loop [val (aget arr 0), n 1] + (if (< n cnt) + (let [nval (f val (aget arr n))] + (if (reduced? nval) + @nval + (recur nval (inc n)))) + val))))) + ([arr f val] + (let [cnt (alength arr)] + (loop [val val, n 0] + (if (< n cnt) + (let [nval (f val (aget arr n))] + (if (reduced? nval) + @nval + (recur nval (inc n)))) + val)))) + ([arr f val idx] + (let [cnt (alength arr)] + (loop [val val, n idx] + (if (< n cnt) + (let [nval (f val (aget arr n))] + (if (reduced? nval) + @nval + (recur nval (inc n)))) + val))))) + +(declare hash-coll cons drop count nth RSeq List) + +(defn counted? + "Returns true if coll implements count in constant time" + [x] (satisfies? ICounted x)) + +(defn indexed? + "Returns true if coll implements nth in constant time" + [x] (satisfies? IIndexed x)) + +(defn- -indexOf + ([coll x] + (-indexOf coll x 0)) + ([coll x start] + (let [len (count coll)] + (if (>= start len) + -1 + (loop [idx (cond + (pos? start) start + (neg? start) (max 0 (+ start len)) + :else start)] + (if (< idx len) + (if (= (nth coll idx) x) + idx + (recur (inc idx))) + -1)))))) + +(defn- -lastIndexOf + ([coll x] + (-lastIndexOf coll x (count coll))) + ([coll x start] + (let [len (count coll)] + (if (zero? len) + -1 + (loop [idx (cond + (pos? start) (min (dec len) start) + (neg? start) (+ len start) + :else start)] + (if (>= idx 0) + (if (= (nth coll idx) x) + idx + (recur (dec idx))) + -1)))))) + +(deftype IndexedSeqIterator [arr ^:mutable i] + Object + (hasNext [_] + (< i (alength arr))) + (next [_] + (let [ret (aget arr i)] + (set! i (inc i)) + ret))) + +(deftype IndexedSeq [arr i meta] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + ICloneable + (-clone [_] (IndexedSeq. arr i meta)) + + ISeqable + (-seq [this] + (when (< i (alength arr)) + this)) + + IMeta + (-meta [coll] meta) + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (IndexedSeq. arr i new-meta))) + + ASeq + ISeq + (-first [_] (aget arr i)) + (-rest [_] (if (< (inc i) (alength arr)) + (IndexedSeq. arr (inc i) nil) + (list))) + + INext + (-next [_] (if (< (inc i) (alength arr)) + (IndexedSeq. arr (inc i) nil) + nil)) + + ICounted + (-count [_] + (max 0 (- (alength arr) i))) + + IIndexed + (-nth [coll n] + (let [i (+ n i)] + (if (and (<= 0 i) (< i (alength arr))) + (aget arr i) + (throw (js/Error. "Index out of bounds"))))) + (-nth [coll n not-found] + (let [i (+ n i)] + (if (and (<= 0 i) (< i (alength arr))) + (aget arr i) + not-found))) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IIterable + (-iterator [coll] + (IndexedSeqIterator. arr i)) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + IReduce + (-reduce [coll f] + (array-reduce arr f (aget arr i) (inc i))) + (-reduce [coll f start] + (array-reduce arr f start i)) + + IHash + (-hash [coll] (hash-ordered-coll coll)) + + IReversible + (-rseq [coll] + (let [c (-count coll)] + (if (pos? c) + (RSeq. coll (dec c) nil))))) + +(es6-iterable IndexedSeq) + +(defn prim-seq + "Create seq from a primitive JavaScript Array-like." + ([prim] + (prim-seq prim 0)) + ([prim i] + (when (< i (alength prim)) + (IndexedSeq. prim i nil)))) + +(defn array-seq + "Create a seq from a JavaScript array." + ([array] + (prim-seq array 0)) + ([array i] + (prim-seq array i))) + +(declare with-meta seq-reduce) + +(deftype RSeq [ci i meta] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + ICloneable + (-clone [_] (RSeq. ci i meta)) + + IMeta + (-meta [coll] meta) + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (RSeq. ci i new-meta))) + + ISeqable + (-seq [coll] coll) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + ISeq + (-first [coll] + (-nth ci i)) + (-rest [coll] + (if (pos? i) + (RSeq. ci (dec i) nil) + ())) + + INext + (-next [coll] + (when (pos? i) + (RSeq. ci (dec i) nil))) + + ICounted + (-count [coll] (inc i)) + + ICollection + (-conj [coll o] + (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + IHash + (-hash [coll] (hash-ordered-coll coll)) + + IReduce + (-reduce [col f] (seq-reduce f col)) + (-reduce [col f start] (seq-reduce f start col))) + +(es6-iterable RSeq) + +(defn second + "Same as (first (next x))" + [coll] + (first (next coll))) + +(defn ffirst + "Same as (first (first x))" + [coll] + (first (first coll))) + +(defn nfirst + "Same as (next (first x))" + [coll] + (next (first coll))) + +(defn fnext + "Same as (first (next x))" + [coll] + (first (next coll))) + +(defn nnext + "Same as (next (next x))" + [coll] + (next (next coll))) + +(defn last + "Return the last item in coll, in linear time" + [s] + (let [sn (next s)] + (if-not (nil? sn) + (recur sn) + (first s)))) + +(extend-type default + IEquiv + (-equiv [x o] (identical? x o))) + +(defn conj + "conj[oin]. Returns a new collection with the xs + 'added'. (conj nil item) returns (item). The 'addition' may + happen at different 'places' depending on the concrete type." + ([] []) + ([coll] coll) + ([coll x] + (if-not (nil? coll) + (-conj coll x) + (list x))) + ([coll x & xs] + (if xs + (recur (conj coll x) (first xs) (next xs)) + (conj coll x)))) + +(defn empty + "Returns an empty collection of the same category as coll, or nil" + [coll] + (when-not (nil? coll) + (cond + (implements? IEmptyableCollection coll) + (-empty coll) + + (satisfies? IEmptyableCollection coll) + (-empty coll) + + :else nil))) + +(defn- accumulating-seq-count [coll] + (loop [s (seq coll) acc 0] + (if (counted? s) ; assumes nil is counted, which it currently is + (+ acc (-count s)) + (recur (next s) (inc acc))))) + +(defn count + "Returns the number of items in the collection. (count nil) returns + 0. Also works on strings, arrays, and Maps" + [coll] + (if-not (nil? coll) + (cond + (implements? ICounted coll) + (-count coll) + + (array? coll) + (alength coll) + + (string? coll) + ^number (.-length coll) + + (implements? ISeqable coll) + (accumulating-seq-count coll) + + :else (-count coll)) + 0)) + +(defn- linear-traversal-nth + ([coll n] + (cond + (nil? coll) (throw (js/Error. "Index out of bounds")) + (zero? n) (if (seq coll) + (first coll) + (throw (js/Error. "Index out of bounds"))) + (indexed? coll) (-nth coll n) + (seq coll) (recur (next coll) (dec n)) + :else (throw (js/Error. "Index out of bounds")))) + ([coll n not-found] + (cond + (nil? coll) not-found + (zero? n) (if (seq coll) + (first coll) + not-found) + (indexed? coll) (-nth coll n not-found) + (seq coll) (recur (next coll) (dec n) not-found) + :else not-found))) + +(defn nth + "Returns the value at the index. get returns nil if index out of + bounds, nth throws an exception unless not-found is supplied. nth + also works for strings, arrays, regex Matchers and Lists, and, + in O(n) time, for sequences." + ([coll n] + (cond + (not (number? n)) + (throw (js/Error. "Index argument to nth must be a number")) + + (nil? coll) + coll + + (implements? IIndexed coll) + (-nth coll n) + + (array? coll) + (if (and (< -1 n (.-length coll))) + (aget coll (int n)) + (throw (js/Error. "Index out of bounds"))) + + (string? coll) + (if (and (< -1 n (.-length coll))) + (.charAt coll (int n)) + (throw (js/Error. "Index out of bounds"))) + + (or (implements? ISeq coll) + (implements? ISequential coll)) + (if (neg? n) + (throw (js/Error. "Index out of bounds")) + (linear-traversal-nth coll n)) + + (native-satisfies? IIndexed coll) + (-nth coll n) + + :else + (throw (js/Error. (str "nth not supported on this type " + (type->str (type coll))))))) + ([coll n not-found] + (cond + (not (number? n)) + (throw (js/Error. "Index argument to nth must be a number.")) + + (nil? coll) + not-found + + (implements? IIndexed coll) + (-nth coll n not-found) + + (array? coll) + (if (and (< -1 n (.-length coll))) + (aget coll (int n)) + not-found) + + (string? coll) + (if (and (< -1 n (.-length coll))) + (.charAt coll (int n)) + not-found) + + (or (implements? ISeq coll) + (implements? ISequential coll)) + (if (neg? n) + not-found + (linear-traversal-nth coll n not-found)) + + (native-satisfies? IIndexed coll) + (-nth coll n not-found) + + :else + (throw (js/Error. (str "nth not supported on this type " + (type->str (type coll)))))))) + +(defn nthrest + "Returns the nth rest of coll, coll when n is 0." + [coll n] + (loop [n n xs coll] + (if-let [xs (and (pos? n) (seq xs))] + (recur (dec n) (rest xs)) + xs))) + +(defn get + "Returns the value mapped to key, not-found or nil if key not present." + ([o k] + (when-not (nil? o) + (cond + (implements? ILookup o) + (-lookup o k) + + (array? o) + (when (and (some? k) (< k (.-length o))) + (aget o (int k))) + + (string? o) + (when (and (some? k) (< k (.-length o))) + (.charAt o (int k))) + + (native-satisfies? ILookup o) + (-lookup o k) + + :else nil))) + ([o k not-found] + (if-not (nil? o) + (cond + (implements? ILookup o) + (-lookup o k not-found) + + (array? o) + (if (and (some? k) (< -1 k (.-length o))) + (aget o (int k)) + not-found) + + (string? o) + (if (and (some? k) (< -1 k (.-length o))) + (.charAt o (int k)) + not-found) + + (native-satisfies? ILookup o) + (-lookup o k not-found) + + :else not-found) + not-found))) + +(declare PersistentHashMap PersistentArrayMap MapEntry) + +(defn assoc + "assoc[iate]. When applied to a map, returns a new map of the + same (hashed/sorted) type, that contains the mapping of key(s) to + val(s). When applied to a vector, returns a new vector that + contains val at index." + ([coll k v] + (if-not (nil? coll) + (-assoc coll k v) + (array-map k v))) + ([coll k v & kvs] + (let [ret (assoc coll k v)] + (if kvs + (recur ret (first kvs) (second kvs) (nnext kvs)) + ret)))) + +(defn dissoc + "dissoc[iate]. Returns a new map of the same (hashed/sorted) type, + that does not contain a mapping for key(s)." + ([coll] coll) + ([coll k] + (when-not (nil? coll) + (-dissoc coll k))) + ([coll k & ks] + (when-not (nil? coll) + (let [ret (dissoc coll k)] + (if ks + (recur ret (first ks) (next ks)) + ret))))) + +(defn fn? + "Return true if f is a JavaScript function or satisfies the Fn protocol." + [f] + (or ^boolean (goog/isFunction f) (satisfies? Fn f))) + +(deftype MetaFn [afn meta] + IMeta + (-meta [_] meta) + IWithMeta + (-with-meta [_ new-meta] + (MetaFn. afn new-meta)) + Fn + IFn + (-invoke [_] + (afn)) + (-invoke [_ a] + (afn a)) + (-invoke [_ a b] + (afn a b)) + (-invoke [_ a b c] + (afn a b c)) + (-invoke [_ a b c d] + (afn a b c d)) + (-invoke [_ a b c d e] + (afn a b c d e)) + (-invoke [_ a b c d e f] + (afn a b c d e f)) + (-invoke [_ a b c d e f g] + (afn a b c d e f g)) + (-invoke [_ a b c d e f g h] + (afn a b c d e f g h)) + (-invoke [_ a b c d e f g h i] + (afn a b c d e f g h i)) + (-invoke [_ a b c d e f g h i j] + (afn a b c d e f g h i j)) + (-invoke [_ a b c d e f g h i j k] + (afn a b c d e f g h i j k)) + (-invoke [_ a b c d e f g h i j k l] + (afn a b c d e f g h i j k l)) + (-invoke [_ a b c d e f g h i j k l m] + (afn a b c d e f g h i j k l m)) + (-invoke [_ a b c d e f g h i j k l m n] + (afn a b c d e f g h i j k l m n)) + (-invoke [_ a b c d e f g h i j k l m n o] + (afn a b c d e f g h i j k l m n o)) + (-invoke [_ a b c d e f g h i j k l m n o p] + (afn a b c d e f g h i j k l m n o p)) + (-invoke [_ a b c d e f g h i j k l m n o p q] + (afn a b c d e f g h i j k l m n o p q)) + (-invoke [_ a b c d e f g h i j k l m n o p q r] + (afn a b c d e f g h i j k l m n o p q r)) + (-invoke [_ a b c d e f g h i j k l m n o p q r s] + (afn a b c d e f g h i j k l m n o p q r s)) + (-invoke [_ a b c d e f g h i j k l m n o p q r s t] + (afn a b c d e f g h i j k l m n o p q r s t)) + (-invoke [_ a b c d e f g h i j k l m n o p q r s t rest] + (apply afn a b c d e f g h i j k l m n o p q r s t rest))) + +(defn with-meta + "Returns an object of the same type and value as obj, with + map m as its metadata." + [o meta] + (if ^boolean (goog/isFunction o) + (MetaFn. o meta) + (when-not (nil? o) + (-with-meta o meta)))) + +(defn meta + "Returns the metadata of obj, returns nil if there is no metadata." + [o] + (when (and (not (nil? o)) + (satisfies? IMeta o)) + (-meta o))) + +(defn peek + "For a list or queue, same as first, for a vector, same as, but much + more efficient than, last. If the collection is empty, returns nil." + [coll] + (when-not (nil? coll) + (-peek coll))) + +(defn pop + "For a list or queue, returns a new list/queue without the first + item, for a vector, returns a new vector without the last item. + Note - not the same as next/butlast." + [coll] + (when-not (nil? coll) + (-pop coll))) + +(defn disj + "disj[oin]. Returns a new set of the same (hashed/sorted) type, that + does not contain key(s)." + ([coll] coll) + ([coll k] + (when-not (nil? coll) + (-disjoin coll k))) + ([coll k & ks] + (when-not (nil? coll) + (let [ret (disj coll k)] + (if ks + (recur ret (first ks) (next ks)) + ret))))) + +(defn empty? + "Returns true if coll has no items - same as (not (seq coll)). + Please use the idiom (seq x) rather than (not (empty? x))" + [coll] (or (nil? coll) + (not (seq coll)))) + +(defn coll? + "Returns true if x satisfies ICollection" + [x] + (if (nil? x) + false + (satisfies? ICollection x))) + +(defn set? + "Returns true if x satisfies ISet" + [x] + (if (nil? x) + false + (satisfies? ISet x))) + +(defn associative? + "Returns true if coll implements IAssociative" + [x] (satisfies? IAssociative x)) + +(defn ifind? + "Returns true if coll implements IFind" + [x] (satisfies? IFind x)) + +(defn sequential? + "Returns true if coll satisfies ISequential" + [x] (satisfies? ISequential x)) + +(defn sorted? + "Returns true if coll satisfies ISorted" + [x] (satisfies? ISorted x)) + +(defn reduceable? + "Returns true if coll satisfies IReduce" + [x] (satisfies? IReduce x)) + +(defn map? + "Return true if x satisfies IMap" + [x] + (if (nil? x) + false + (satisfies? IMap x))) + +(defn record? + "Return true if x satisfies IRecord" + [x] + (satisfies? IRecord x)) + +(defn vector? + "Return true if x satisfies IVector" + [x] (satisfies? IVector x)) + +(declare ChunkedCons ChunkedSeq) + +(defn chunked-seq? + "Return true if x is satisfies IChunkedSeq." + [x] (implements? IChunkedSeq x)) + +;;;;;;;;;;;;;;;;;;;; js primitives ;;;;;;;;;;;; +(defn js-obj + "Create JavaSript object from an even number arguments representing + interleaved keys and values." + ([] + (cljs.core/js-obj)) + ([& keyvals] + (apply gobject/create keyvals))) + +(defn js-keys + "Return the JavaScript keys for an object." + [obj] + (gobject/getKeys obj)) + +(defn js-delete + "Delete a property from a JavaScript object. + Returns true upon success, false otherwise." + [obj key] + (cljs.core/js-delete obj key)) + +(defn- array-copy + ([from i to j len] + (loop [i i j j len len] + (if (zero? len) + to + (do (aset to j (aget from i)) + (recur (inc i) (inc j) (dec len))))))) + +(defn- array-copy-downward + ([from i to j len] + (loop [i (+ i (dec len)) j (+ j (dec len)) len len] + (if (zero? len) + to + (do (aset to j (aget from i)) + (recur (dec i) (dec j) (dec len))))))) + +;;;;;;;;;;;;;;;; preds ;;;;;;;;;;;;;;;;;; + +(def ^:private lookup-sentinel (js-obj)) + +(defn ^boolean false? + "Returns true if x is the value false, false otherwise." + [x] (cljs.core/false? x)) + +(defn ^boolean true? + "Returns true if x is the value true, false otherwise." + [x] (cljs.core/true? x)) + +(defn boolean? + "Return true if x is a Boolean" + [x] (or (cljs.core/true? x) (cljs.core/false? x))) + +(defn ^boolean undefined? + "Returns true if x identical to the JavaScript undefined value." + [x] + (cljs.core/undefined? x)) + +(defn seq? + "Return true if s satisfies ISeq" + [s] + (if (nil? s) + false + (satisfies? ISeq s))) + +(defn seqable? + "Return true if the seq function is supported for s" + [s] + (or + (nil? s) + (satisfies? ISeqable s) + (array? s) + (string? s))) + +(defn boolean + "Coerce to boolean" + [x] + (cond + (nil? x) false + (false? x) false + :else true)) + +(defn ifn? + "Returns true if f returns true for fn? or satisfies IFn." + [f] + (or (fn? f) (satisfies? IFn f))) + +(defn integer? + "Returns true if n is a JavaScript number with no decimal part." + [n] + (and (number? n) + (not ^boolean (js/isNaN n)) + (not (identical? n js/Infinity)) + (== (js/parseFloat n) (js/parseInt n 10)))) + +(defn int? + "Return true if x satisfies integer? or is an instance of goog.math.Integer + or goog.math.Long." + [x] + (or (integer? x) + (instance? goog.math.Integer x) + (instance? goog.math.Long x))) + +(defn pos-int? + "Return true if x satisfies int? and is positive." + [x] + (cond + (integer? x) (pos? x) + + (instance? goog.math.Integer x) + (and (not (.isNegative x)) + (not (.isZero x))) + + (instance? goog.math.Long x) + (and (not (.isNegative x)) + (not (.isZero x))) + + :else false)) + +(defn ^boolean neg-int? + "Return true if x satisfies int? and is negative." + [x] + (cond + (integer? x) (neg? x) + + (instance? goog.math.Integer x) + (.isNegative x) + + (instance? goog.math.Long x) + (.isNegative x) + + :else false)) + +(defn nat-int? + "Return true if x satisfies int? and is a natural integer value." + [x] + (cond + (integer? x) + (not (neg? x)) + + (instance? goog.math.Integer x) + (not (.isNegative x)) + + (instance? goog.math.Long x) + (not (.isNegative x)) + + :else false)) + +(defn float? + "Returns true for JavaScript numbers, false otherwise." + [x] + (number? x)) + +(defn double? + "Returns true for JavaScript numbers, false otherwise." + [x] + (number? x)) + +(defn infinite? + "Returns true for Infinity and -Infinity values." + [x] + (or (identical? x js/Number.POSITIVE_INFINITY) + (identical? x js/Number.NEGATIVE_INFINITY))) + +(defn contains? + "Returns true if key is present in the given collection, otherwise + returns false. Note that for numerically indexed collections like + vectors and arrays, this tests if the numeric key is within the + range of indexes. 'contains?' operates constant or logarithmic time; + it will not perform a linear search for a value. See also 'some'." + [coll v] + (if (identical? (get coll v lookup-sentinel) lookup-sentinel) + false + true)) + +(defn find + "Returns the map entry for key, or nil if key not present." + [coll k] + (if (ifind? coll) + (-find coll k) + (when (and (not (nil? coll)) + (associative? coll) + (contains? coll k)) + (MapEntry. k (get coll k) nil)))) + +(defn ^boolean distinct? + "Returns true if no two of the arguments are =" + ([x] true) + ([x y] (not (= x y))) + ([x y & more] + (if (not (= x y)) + (loop [s #{x y} xs more] + (let [x (first xs) + etc (next xs)] + (if xs + (if (contains? s x) + false + (recur (conj s x) etc)) + true))) + false))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Seq fns ;;;;;;;;;;;;;;;; + +(defn ^number compare + "Comparator. Returns a negative number, zero, or a positive number + when x is logically 'less than', 'equal to', or 'greater than' + y. Uses IComparable if available and google.array.defaultCompare for objects + of the same type and special-cases nil to be less than any other object." + [x y] + (cond + (identical? x y) 0 + + (nil? x) -1 + + (nil? y) 1 + + (number? x) (if (number? y) + (garray/defaultCompare x y) + (throw (js/Error. (str "Cannot compare " x " to " y)))) + + (satisfies? IComparable x) + (-compare x y) + + :else + (if (and (or (string? x) (array? x) (true? x) (false? x)) + (identical? (type x) (type y))) + (garray/defaultCompare x y) + (throw (js/Error. (str "Cannot compare " x " to " y)))))) + +(defn ^:private compare-indexed + "Compare indexed collection." + ([xs ys] + (let [xl (count xs) + yl (count ys)] + (cond + (< xl yl) -1 + (> xl yl) 1 + (== xl 0) 0 + :else (compare-indexed xs ys xl 0)))) + ([xs ys len n] + (let [d (compare (nth xs n) (nth ys n))] + (if (and (zero? d) (< (+ n 1) len)) + (recur xs ys len (inc n)) + d)))) + +(defn ^:private fn->comparator + "Given a fn that might be boolean valued or a comparator, + return a fn that is a comparator." + [f] + (if (= f compare) + compare + (fn [x y] + (let [r (f x y)] + (if (number? r) + r + (if r + -1 + (if (f y x) 1 0))))))) + +(declare to-array) + +(defn sort + "Returns a sorted sequence of the items in coll. Comp can be + boolean-valued comparison function, or a -/0/+ valued comparator. + Comp defaults to compare." + ([coll] + (sort compare coll)) + ([comp coll] + (if (seq coll) + (let [a (to-array coll)] + ;; matching Clojure's stable sort, though docs don't promise it + (garray/stableSort a (fn->comparator comp)) + (seq a)) + ()))) + +(defn sort-by + "Returns a sorted sequence of the items in coll, where the sort + order is determined by comparing (keyfn item). Comp can be + boolean-valued comparison function, or a -/0/+ valued comparator. + Comp defaults to compare." + ([keyfn coll] + (sort-by keyfn compare coll)) + ([keyfn comp coll] + (sort (fn [x y] ((fn->comparator comp) (keyfn x) (keyfn y))) coll))) + +; simple reduce based on seqs, used as default +(defn- seq-reduce + ([f coll] + (if-let [s (seq coll)] + (reduce f (first s) (next s)) + (f))) + ([f val coll] + (loop [val val, coll (seq coll)] + (if coll + (let [nval (f val (first coll))] + (if (reduced? nval) + @nval + (recur nval (next coll)))) + val)))) + +(declare vec) + +(defn shuffle + "Return a random permutation of coll" + [coll] + (let [a (to-array coll)] + (garray/shuffle a) + (vec a))) + +(defn- iter-reduce + ([coll f] + (let [iter (-iterator coll)] + (if (.hasNext iter) + (let [init (.next iter)] + (loop [acc init] + (if ^boolean (.hasNext iter) + (let [nacc (f acc (.next iter))] + (if (reduced? nacc) + @nacc + (recur nacc))) + acc))) + (f)))) + ([coll f init] + (let [iter (-iterator coll)] + (loop [acc init] + (if ^boolean (.hasNext iter) + (let [nacc (f acc (.next iter))] + (if (reduced? nacc) + @nacc + (recur nacc))) + acc))))) + +(defn reduce + "f should be a function of 2 arguments. If val is not supplied, + returns the result of applying f to the first 2 items in coll, then + applying f to that result and the 3rd item, etc. If coll contains no + items, f must accept no arguments as well, and reduce returns the + result of calling f with no arguments. If coll has only 1 item, it + is returned and f is not called. If val is supplied, returns the + result of applying f to val and the first item in coll, then + applying f to that result and the 2nd item, etc. If coll contains no + items, returns val and f is not called." + ([f coll] + (cond + (implements? IReduce coll) + (-reduce coll f) + + (array? coll) + (array-reduce coll f) + + (string? coll) + (array-reduce coll f) + + (native-satisfies? IReduce coll) + (-reduce coll f) + + (iterable? coll) + (iter-reduce coll f) + + :else + (seq-reduce f coll))) + ([f val coll] + (cond + (implements? IReduce coll) + (-reduce coll f val) + + (array? coll) + (array-reduce coll f val) + + (string? coll) + (array-reduce coll f val) + + (native-satisfies? IReduce coll) + (-reduce coll f val) + + (iterable? coll) + (iter-reduce coll f val) + + :else + (seq-reduce f val coll)))) + +(defn reduce-kv + "Reduces an associative collection. f should be a function of 3 + arguments. Returns the result of applying f to init, the first key + and the first value in coll, then applying f to that result and the + 2nd key and value, etc. If coll contains no entries, returns init + and f is not called. Note that reduce-kv is supported on vectors, + where the keys will be the ordinals." + ([f init coll] + (if-not (nil? coll) + (-kv-reduce coll f init) + init))) + +(defn identity + "Returns its argument." + [x] x) + +(defn completing + "Takes a reducing function f of 2 args and returns a fn suitable for + transduce by adding an arity-1 signature that calls cf (default - + identity) on the result argument." + ([f] (completing f identity)) + ([f cf] + (fn + ([] (f)) + ([x] (cf x)) + ([x y] (f x y))))) + +(defn transduce + "reduce with a transformation of f (xf). If init is not + supplied, (f) will be called to produce it. f should be a reducing + step function that accepts both 1 and 2 arguments, if it accepts + only 2 you can add the arity-1 with 'completing'. Returns the result + of applying (the transformed) xf to init and the first item in coll, + then applying xf to that result and the 2nd item, etc. If coll + contains no items, returns init and f is not called. Note that + certain transforms may inject or skip items." + ([xform f coll] (transduce xform f (f) coll)) + ([xform f init coll] + (let [f (xform f) + ret (reduce f init coll)] + (f ret)))) + +;;; Math - variadic forms will not work until the following implemented: +;;; first, next, reduce + +(defn ^number + + "Returns the sum of nums. (+) returns 0." + ([] 0) + ([x] x) + ([x y] (cljs.core/+ x y)) + ([x y & more] + (reduce + (cljs.core/+ x y) more))) + +(defn ^number - + "If no ys are supplied, returns the negation of x, else subtracts + the ys from x and returns the result." + ([x] (cljs.core/- x)) + ([x y] (cljs.core/- x y)) + ([x y & more] (reduce - (cljs.core/- x y) more))) + +(defn ^number * + "Returns the product of nums. (*) returns 1." + ([] 1) + ([x] x) + ([x y] (cljs.core/* x y)) + ([x y & more] (reduce * (cljs.core/* x y) more))) + +(declare divide) + +(defn ^number / + "If no denominators are supplied, returns 1/numerator, + else returns numerator divided by all of the denominators." + ([x] (/ 1 x)) + ([x y] (cljs.core/divide x y)) ;; FIXME: waiting on cljs.core// + ([x y & more] (reduce / (/ x y) more))) + +(defn ^boolean < + "Returns non-nil if nums are in monotonically increasing order, + otherwise false." + ([x] true) + ([x y] (cljs.core/< x y)) + ([x y & more] + (if (cljs.core/< x y) + (if (next more) + (recur y (first more) (next more)) + (cljs.core/< y (first more))) + false))) + +(defn ^boolean <= + "Returns non-nil if nums are in monotonically non-decreasing order, + otherwise false." + ([x] true) + ([x y] (cljs.core/<= x y)) + ([x y & more] + (if (cljs.core/<= x y) + (if (next more) + (recur y (first more) (next more)) + (cljs.core/<= y (first more))) + false))) + +(defn ^boolean > + "Returns non-nil if nums are in monotonically decreasing order, + otherwise false." + ([x] true) + ([x y] (cljs.core/> x y)) + ([x y & more] + (if (cljs.core/> x y) + (if (next more) + (recur y (first more) (next more)) + (cljs.core/> y (first more))) + false))) + +(defn ^boolean >= + "Returns non-nil if nums are in monotonically non-increasing order, + otherwise false." + ([x] true) + ([x y] (cljs.core/>= x y)) + ([x y & more] + (if (cljs.core/>= x y) + (if (next more) + (recur y (first more) (next more)) + (cljs.core/>= y (first more))) + false))) + +(defn dec + "Returns a number one less than num." + [x] (- x 1)) + +(defn ^number max + "Returns the greatest of the nums." + ([x] x) + ([x y] (cljs.core/max x y)) + ([x y & more] + (reduce max (cljs.core/max x y) more))) + +(defn ^number min + "Returns the least of the nums." + ([x] x) + ([x y] (cljs.core/min x y)) + ([x y & more] + (reduce min (cljs.core/min x y) more))) + +(defn ^number byte [x] x) + +(defn char + "Coerce to char" + [x] + (cond + (number? x) (.fromCharCode js/String x) + (and (string? x) (== (.-length x) 1)) x + :else (throw (js/Error. "Argument to char must be a character or number")))) + +(defn ^number short [x] x) +(defn ^number float [x] x) +(defn ^number double [x] x) + +(defn ^number unchecked-byte [x] x) +(defn ^number unchecked-char [x] x) +(defn ^number unchecked-short [x] x) +(defn ^number unchecked-float [x] x) +(defn ^number unchecked-double [x] x) + +(defn ^number unchecked-add + "Returns the sum of nums. (+) returns 0." + ([] 0) + ([x] x) + ([x y] (cljs.core/unchecked-add x y)) + ([x y & more] (reduce unchecked-add (cljs.core/unchecked-add x y) more))) + +(defn ^number unchecked-add-int + "Returns the sum of nums. (+) returns 0." + ([] 0) + ([x] x) + ([x y] (cljs.core/unchecked-add-int x y)) + ([x y & more] (reduce unchecked-add-int (cljs.core/unchecked-add-int x y) more))) + +(defn unchecked-dec + "Returns a number one less than x, an int." + [x] + (cljs.core/unchecked-dec x)) + +(defn unchecked-dec-int + "Returns a number one less than x, an int." + [x] + (cljs.core/unchecked-dec-int x)) + +(defn ^number unchecked-divide-int + "If no denominators are supplied, returns 1/numerator, + else returns numerator divided by all of the denominators." + ([x] (unchecked-divide-int 1 x)) + ([x y] (cljs.core/divide x y)) ;; FIXME: waiting on cljs.core// + ([x y & more] (reduce unchecked-divide-int (unchecked-divide-int x y) more))) + +(defn unchecked-inc [x] + (cljs.core/unchecked-inc x)) + +(defn unchecked-inc-int [x] + (cljs.core/unchecked-inc-int x)) + +(defn ^number unchecked-multiply + "Returns the product of nums. (*) returns 1." + ([] 1) + ([x] x) + ([x y] (cljs.core/unchecked-multiply x y)) + ([x y & more] (reduce unchecked-multiply (cljs.core/unchecked-multiply x y) more))) + +(defn ^number unchecked-multiply-int + "Returns the product of nums. (*) returns 1." + ([] 1) + ([x] x) + ([x y] (cljs.core/unchecked-multiply-int x y)) + ([x y & more] (reduce unchecked-multiply-int (cljs.core/unchecked-multiply-int x y) more))) + +(defn unchecked-negate [x] + (cljs.core/unchecked-negate x)) + +(defn unchecked-negate-int [x] + (cljs.core/unchecked-negate-int x)) + +(declare mod) + +(defn unchecked-remainder-int [x n] + (cljs.core/unchecked-remainder-int x n)) + +(defn ^number unchecked-subtract + "If no ys are supplied, returns the negation of x, else subtracts + the ys from x and returns the result." + ([x] (cljs.core/unchecked-subtract x)) + ([x y] (cljs.core/unchecked-subtract x y)) + ([x y & more] (reduce unchecked-subtract (cljs.core/unchecked-subtract x y) more))) + +(defn ^number unchecked-subtract-int + "If no ys are supplied, returns the negation of x, else subtracts + the ys from x and returns the result." + ([x] (cljs.core/unchecked-subtract-int x)) + ([x y] (cljs.core/unchecked-subtract-int x y)) + ([x y & more] (reduce unchecked-subtract-int (cljs.core/unchecked-subtract-int x y) more))) + +(defn- ^number fix [q] + (if (>= q 0) + (Math/floor q) + (Math/ceil q))) + +(defn int + "Coerce to int by stripping decimal places." + [x] + (bit-or x 0)) + +(defn unchecked-int + "Coerce to int by stripping decimal places." + [x] + (fix x)) + +(defn long + "Coerce to long by stripping decimal places. Identical to `int'." + [x] + (fix x)) + +(defn unchecked-long + "Coerce to long by stripping decimal places. Identical to `int'." + [x] + (fix x)) + +(defn booleans [x] x) +(defn bytes [x] x) +(defn chars [x] x) +(defn shorts [x] x) +(defn ints [x] x) +(defn floats [x] x) +(defn doubles [x] x) +(defn longs [x] x) + +(defn js-mod + "Modulus of num and div with original javascript behavior. i.e. bug for negative numbers" + [n d] + (cljs.core/js-mod n d)) + +(defn mod + "Modulus of num and div. Truncates toward negative infinity." + [n d] + (js-mod (+ (js-mod n d) d) d)) + +(defn quot + "quot[ient] of dividing numerator by denominator." + [n d] + (let [rem (js-mod n d)] + (fix (/ (- n rem) d)))) + +(defn rem + "remainder of dividing numerator by denominator." + [n d] + (let [q (quot n d)] + (- n (* d q)))) + +(defn bit-xor + "Bitwise exclusive or" + ([x y] (cljs.core/bit-xor x y)) + ([x y & more] + (reduce bit-xor (cljs.core/bit-xor x y) more))) + +(defn bit-and + "Bitwise and" + ([x y] (cljs.core/bit-and x y)) + ([x y & more] + (reduce bit-and (cljs.core/bit-and x y) more))) + +(defn bit-or + "Bitwise or" + ([x y] (cljs.core/bit-or x y)) + ([x y & more] + (reduce bit-or (cljs.core/bit-or x y) more))) + +(defn bit-and-not + "Bitwise and with complement" + ([x y] (cljs.core/bit-and-not x y)) + ([x y & more] + (reduce bit-and-not (cljs.core/bit-and-not x y) more))) + +(defn bit-clear + "Clear bit at index n" + [x n] + (cljs.core/bit-clear x n)) + +(defn bit-flip + "Flip bit at index n" + [x n] + (cljs.core/bit-flip x n)) + +(defn bit-not + "Bitwise complement" + [x] (cljs.core/bit-not x)) + +(defn bit-set + "Set bit at index n" + [x n] + (cljs.core/bit-set x n)) + +(defn ^boolean bit-test + "Test bit at index n" + [x n] + (cljs.core/bit-test x n)) + +(defn bit-shift-left + "Bitwise shift left" + [x n] (cljs.core/bit-shift-left x n)) + +(defn bit-shift-right + "Bitwise shift right" + [x n] (cljs.core/bit-shift-right x n)) + +(defn bit-shift-right-zero-fill + "DEPRECATED: Bitwise shift right with zero fill" + [x n] (cljs.core/bit-shift-right-zero-fill x n)) + +(defn unsigned-bit-shift-right + "Bitwise shift right with zero fill" + [x n] (cljs.core/unsigned-bit-shift-right x n)) + +(defn bit-count + "Counts the number of bits set in n" + [v] + (let [v (- v (bit-and (bit-shift-right v 1) 0x55555555)) + v (+ (bit-and v 0x33333333) (bit-and (bit-shift-right v 2) 0x33333333))] + (bit-shift-right (* (bit-and (+ v (bit-shift-right v 4)) 0xF0F0F0F) 0x1010101) 24))) + +(defn ^boolean == + "Returns non-nil if nums all have the equivalent + value, otherwise false. Behavior on non nums is + undefined." + ([x] true) + ([x y] (-equiv x y)) + ([x y & more] + (if (== x y) + (if (next more) + (recur y (first more) (next more)) + (== y (first more))) + false))) + +(defn ^boolean pos? + "Returns true if num is greater than zero, else false" + [x] (cljs.core/pos? x)) + +(defn ^boolean zero? + "Returns true if num is zero, else false" + [x] + (cljs.core/zero? x)) + +(defn ^boolean neg? + "Returns true if num is less than zero, else false" + [x] (cljs.core/neg? x)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; protocols for host types ;;;;;; + +(defn nthnext + "Returns the nth next of coll, (seq coll) when n is 0." + [coll n] + (loop [n n xs (seq coll)] + (if (and xs (pos? n)) + (recur (dec n) (next xs)) + xs))) + +;;;;;;;;;;;;;;;;;;;;;;;;;; basics ;;;;;;;;;;;;;;;;;; + +(defn str + "With no args, returns the empty string. With one arg x, returns + x.toString(). (str nil) returns the empty string. With more than + one arg, returns the concatenation of the str values of the args." + ([] "") + ([x] (if (nil? x) + "" + (.join #js [x] ""))) + ([x & ys] + (loop [sb (StringBuffer. (str x)) more ys] + (if more + (recur (. sb (append (str (first more)))) (next more)) + (.toString sb))))) + +(defn subs + "Returns the substring of s beginning at start inclusive, and ending + at end (defaults to length of string), exclusive." + ([s start] (.substring s start)) + ([s start end] (.substring s start end))) + +(declare map name) + +(defn- equiv-sequential + "Assumes x is sequential. Returns true if x equals y, otherwise + returns false." + [x y] + (boolean + (when (sequential? y) + (if (and (counted? x) (counted? y) + (not (== (count x) (count y)))) + false + (loop [xs (seq x) ys (seq y)] + (cond (nil? xs) (nil? ys) + (nil? ys) false + (= (first xs) (first ys)) (recur (next xs) (next ys)) + :else false)))))) + +(defn- hash-coll [coll] + (if (seq coll) + (loop [res (hash (first coll)) s (next coll)] + (if (nil? s) + res + (recur (hash-combine res (hash (first s))) (next s)))) + 0)) + +(declare key val) + +(defn- hash-imap [m] + ;; a la clojure.lang.APersistentMap + (loop [h 0 s (seq m)] + (if s + (let [e (first s)] + (recur (js-mod (+ h (bit-xor (hash (key e)) (hash (val e)))) + 4503599627370496) + (next s))) + h))) + +(defn- hash-iset [s] + ;; a la clojure.lang.APersistentSet + (loop [h 0 s (seq s)] + (if s + (let [e (first s)] + (recur (js-mod (+ h (hash e)) 4503599627370496) + (next s))) + h))) + +(declare name chunk-first chunk-rest) + +(defn- extend-object! + "Takes a JavaScript object and a map of names to functions and + attaches said functions as methods on the object. Any references to + JavaScript's implicit this (via the this-as macro) will resolve to the + object that the function is attached." + [obj fn-map] + (doseq [[key-name f] fn-map] + (let [str-name (name key-name)] + (gobject/set obj str-name f))) + obj) + +;;;;;;;;;;;;;;;; cons ;;;;;;;;;;;;;;;; +(deftype List [meta first rest count ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x count)) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IList + + ICloneable + (-clone [_] (List. meta first rest count __hash)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (List. new-meta first rest count __hash))) + + IMeta + (-meta [coll] meta) + + ASeq + ISeq + (-first [coll] first) + (-rest [coll] + (if (== count 1) + () + rest)) + + INext + (-next [coll] + (if (== count 1) + nil + rest)) + + IStack + (-peek [coll] first) + (-pop [coll] (-rest coll)) + + ICollection + (-conj [coll o] (List. meta o coll (inc count) nil)) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY List) meta)) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + ISeqable + (-seq [coll] coll) + + ICounted + (-count [coll] count) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(defn list? + "Returns true if x implements IList" + [x] + (satisfies? IList x)) + +(es6-iterable List) + +(deftype EmptyList [meta] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IList + + ICloneable + (-clone [_] (EmptyList. meta)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (EmptyList. new-meta))) + + IMeta + (-meta [coll] meta) + + ISeq + (-first [coll] nil) + (-rest [coll] ()) + + INext + (-next [coll] nil) + + IStack + (-peek [coll] nil) + (-pop [coll] (throw (js/Error. "Can't pop empty list"))) + + ICollection + (-conj [coll o] (List. meta o nil 1 nil)) + + IEmptyableCollection + (-empty [coll] coll) + + ISequential + IEquiv + (-equiv [coll other] + (if (or (list? other) + (sequential? other)) + (nil? (seq other)) + false)) + + IHash + (-hash [coll] empty-ordered-hash) + + ISeqable + (-seq [coll] nil) + + ICounted + (-count [coll] 0) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(set! (.-EMPTY List) (EmptyList. nil)) + +(es6-iterable EmptyList) + +(defn reversible? + "Returns true if coll satisfies? IReversible." + [coll] + (satisfies? IReversible coll)) + +(defn ^seq rseq + "Returns, in constant time, a seq of the items in rev (which + can be a vector or sorted-map), in reverse order. If rev is empty returns nil" + [rev] + (-rseq rev)) + +(defn reverse + "Returns a seq of the items in coll in reverse order. Not lazy." + [coll] + (if (reversible? coll) + (or (rseq coll) ()) + (reduce conj () coll))) + +(defn list + "Creates a new list containing the items." + [& xs] + (let [arr (if (and (instance? IndexedSeq xs) (zero? (.-i xs))) + (.-arr xs) + (let [arr (array)] + (loop [^not-native xs xs] + (if-not (nil? xs) + (do + (.push arr (-first xs)) + (recur (-next xs))) + arr))))] + (loop [i (alength arr) r ()] + (if (> i 0) + (recur (dec i) (-conj r (aget arr (dec i)))) + r)))) + +(deftype Cons [meta first rest ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IList + + ICloneable + (-clone [_] (Cons. meta first rest __hash)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (Cons. new-meta first rest __hash))) + + IMeta + (-meta [coll] meta) + + ASeq + ISeq + (-first [coll] first) + (-rest [coll] (if (nil? rest) () rest)) + + INext + (-next [coll] + (if (nil? rest) nil (seq rest))) + + ICollection + (-conj [coll o] (Cons. nil o coll nil)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + ISeqable + (-seq [coll] coll) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(es6-iterable Cons) + +(defn cons + "Returns a new seq where x is the first element and coll is the rest." + [x coll] + (cond + (nil? coll) (List. nil x nil 1 nil) + (implements? ISeq coll) (Cons. nil x coll nil) + :default (Cons. nil x (seq coll) nil))) + +(defn hash-keyword [k] + (int (+ (hash-symbol k) 0x9e3779b9))) + +(defn- compare-keywords [a b] + (cond + (identical? (.-fqn a) (.-fqn b)) 0 + (and (not (.-ns a)) (.-ns b)) -1 + (.-ns a) (if-not (.-ns b) + 1 + (let [nsc (garray/defaultCompare (.-ns a) (.-ns b))] + (if (== 0 nsc) + (garray/defaultCompare (.-name a) (.-name b)) + nsc))) + :default (garray/defaultCompare (.-name a) (.-name b)))) + +(deftype Keyword [ns name fqn ^:mutable _hash] + Object + (toString [_] (str ":" fqn)) + (equiv [this other] + (-equiv this other)) + + IEquiv + (-equiv [_ other] + (if (instance? Keyword other) + (identical? fqn (.-fqn other)) + false)) + IFn + (-invoke [kw coll] + (get coll kw)) + (-invoke [kw coll not-found] + (get coll kw not-found)) + + IHash + (-hash [this] + (caching-hash this hash-keyword _hash)) + + INamed + (-name [_] name) + (-namespace [_] ns) + + IPrintWithWriter + (-pr-writer [o writer _] (-write writer (str ":" fqn)))) + +(defn keyword? + "Return true if x is a Keyword" + [x] + (instance? Keyword x)) + +(defn keyword-identical? + "Efficient test to determine that two keywords are identical." + [x y] + (if (identical? x y) + true + (if (and (keyword? x) (keyword? y)) + (identical? (.-fqn x) (.-fqn y)) + false))) + +(defn symbol-identical? + "Efficient test to determine that two symbols are identical." + [x y] + (if (identical? x y) + true + (if (and (symbol? x) (symbol? y)) + (identical? (.-str x) (.-str y)) + false))) + +(defn namespace + "Returns the namespace String of a symbol or keyword, or nil if not present." + [x] + (if (implements? INamed x) + (-namespace x) + (throw (js/Error. (str "Doesn't support namespace: " x))))) + +(defn ident? + "Return true if x is a symbol or keyword" + [x] (or (keyword? x) (symbol? x))) + +(defn simple-ident? + "Return true if x is a symbol or keyword without a namespace" + [x] (and (ident? x) (nil? (namespace x)))) + +(defn qualified-ident? + "Return true if x is a symbol or keyword with a namespace" + [x] (boolean (and (ident? x) (namespace x) true))) + +(defn simple-symbol? + "Return true if x is a symbol without a namespace" + [x] (and (symbol? x) (nil? (namespace x)))) + +(defn qualified-symbol? + "Return true if x is a symbol with a namespace" + [x] (boolean (and (symbol? x) (namespace x) true))) + +(defn simple-keyword? + "Return true if x is a keyword without a namespace" + [x] (and (keyword? x) (nil? (namespace x)))) + +(defn qualified-keyword? + "Return true if x is a keyword with a namespace" + [x] (boolean (and (keyword? x) (namespace x) true))) + +(defn keyword + "Returns a Keyword with the given namespace and name. Do not use : + in the keyword strings, it will be added automatically." + ([name] (cond + (keyword? name) name + (symbol? name) (Keyword. + (cljs.core/namespace name) + (cljs.core/name name) (.-str name) nil) + (string? name) (let [parts (.split name "/")] + (if (== (alength parts) 2) + (Keyword. (aget parts 0) (aget parts 1) name nil) + (Keyword. nil (aget parts 0) name nil))))) + ([ns name] + (let [ns (cond + (keyword? ns) (cljs.core/name ns) + (symbol? ns) (cljs.core/name ns) + :else ns) + name (cond + (keyword? name) (cljs.core/name name) + (symbol? name) (cljs.core/name name) + :else name)] + (Keyword. ns name (str (when ns (str ns "/")) name) nil)))) + + +(deftype LazySeq [meta ^:mutable fn ^:mutable s ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (sval [coll] + (if (nil? fn) + s + (do + (set! s (fn)) + (set! fn nil) + s))) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IPending + (-realized? [coll] + (not fn)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (LazySeq. new-meta #(-seq coll) nil __hash))) + + IMeta + (-meta [coll] meta) + + ISeq + (-first [coll] + (-seq coll) + (when-not (nil? s) + (first s))) + (-rest [coll] + (-seq coll) + (if-not (nil? s) + (rest s) + ())) + + INext + (-next [coll] + (-seq coll) + (when-not (nil? s) + (next s))) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY List) meta)) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + ISeqable + (-seq [coll] + (.sval coll) + (when-not (nil? s) + (loop [ls s] + (if (instance? LazySeq ls) + (recur (.sval ls)) + (do (set! s ls) + (seq s)))))) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(es6-iterable LazySeq) + +(declare ArrayChunk) + +(deftype ChunkBuffer [^:mutable buf ^:mutable end] + Object + (add [_ o] + (aset buf end o) + (set! end (inc end))) + + (chunk [_] + (let [ret (ArrayChunk. buf 0 end)] + (set! buf nil) + ret)) + + ICounted + (-count [_] end)) + +(defn chunk-buffer [capacity] + (ChunkBuffer. (make-array capacity) 0)) + +(deftype ArrayChunk [arr off end] + ICounted + (-count [_] (- end off)) + + IIndexed + (-nth [coll i] + (aget arr (+ off i))) + (-nth [coll i not-found] + (if (and (>= i 0) (< i (- end off))) + (aget arr (+ off i)) + not-found)) + + IChunk + (-drop-first [coll] + (if (== off end) + (throw (js/Error. "-drop-first of empty chunk")) + (ArrayChunk. arr (inc off) end))) + + IReduce + (-reduce [coll f] + (array-reduce arr f (aget arr off) (inc off))) + (-reduce [coll f start] + (array-reduce arr f start off))) + +(defn array-chunk + ([arr] + (ArrayChunk. arr 0 (alength arr))) + ([arr off] + (ArrayChunk. arr off (alength arr))) + ([arr off end] + (ArrayChunk. arr off end))) + +(deftype ChunkedCons [chunk more meta ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (ChunkedCons. chunk more new-meta __hash))) + + IMeta + (-meta [coll] meta) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + ISeqable + (-seq [coll] coll) + + ASeq + ISeq + (-first [coll] (-nth chunk 0)) + (-rest [coll] + (if (> (-count chunk) 1) + (ChunkedCons. (-drop-first chunk) more nil nil) + (if (nil? more) + () + more))) + + INext + (-next [coll] + (if (> (-count chunk) 1) + (ChunkedCons. (-drop-first chunk) more nil nil) + (when-not (nil? more) + (-seq more)))) + + IChunkedSeq + (-chunked-first [coll] chunk) + (-chunked-rest [coll] + (if (nil? more) + () + more)) + + IChunkedNext + (-chunked-next [coll] + (if (nil? more) + nil + more)) + + ICollection + (-conj [this o] + (cons o this)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash))) + +(es6-iterable ChunkedCons) + +(defn chunk-cons [chunk rest] + (if (zero? (-count chunk)) + rest + (ChunkedCons. chunk rest nil nil))) + +(defn chunk-append [b x] + (.add b x)) + +(defn chunk [b] + (.chunk b)) + +(defn chunk-first [s] + (-chunked-first s)) + +(defn chunk-rest [s] + (-chunked-rest s)) + +(defn chunk-next [s] + (if (implements? IChunkedNext s) + (-chunked-next s) + (seq (-chunked-rest s)))) + +;;;;;;;;;;;;;;;; + +(defn to-array + "Returns an array containing the contents of coll." + [coll] + (let [ary (array)] + (loop [s (seq coll)] + (if-not (nil? s) + (do (. ary push (first s)) + (recur (next s))) + ary)))) + +(defn to-array-2d + "Returns a (potentially-ragged) 2-dimensional array + containing the contents of coll." + [coll] + (let [ret (make-array (count coll))] + (loop [i 0 xs (seq coll)] + (when-not (nil? xs) + (aset ret i (to-array (first xs))) + (recur (inc i) (next xs)))) + ret)) + +(defn int-array + "Creates an array of ints. Does not coerce array, provided for compatibility + with Clojure." + ([size-or-seq] + (if (number? size-or-seq) + (int-array size-or-seq nil) + (into-array size-or-seq))) + ([size init-val-or-seq] + (let [a (make-array size)] + (if (seq? init-val-or-seq) + (let [s (seq init-val-or-seq)] + (loop [i 0 s s] + (if (and s (< i size)) + (do + (aset a i (first s)) + (recur (inc i) (next s))) + a))) + (do + (dotimes [i size] + (aset a i init-val-or-seq)) + a))))) + +(defn long-array + "Creates an array of longs. Does not coerce array, provided for compatibility + with Clojure." + ([size-or-seq] + (if (number? size-or-seq) + (long-array size-or-seq nil) + (into-array size-or-seq))) + ([size init-val-or-seq] + (let [a (make-array size)] + (if (seq? init-val-or-seq) + (let [s (seq init-val-or-seq)] + (loop [i 0 s s] + (if (and s (< i size)) + (do + (aset a i (first s)) + (recur (inc i) (next s))) + a))) + (do + (dotimes [i size] + (aset a i init-val-or-seq)) + a))))) + +(defn double-array + "Creates an array of doubles. Does not coerce array, provided for compatibility + with Clojure." + ([size-or-seq] + (if (number? size-or-seq) + (double-array size-or-seq nil) + (into-array size-or-seq))) + ([size init-val-or-seq] + (let [a (make-array size)] + (if (seq? init-val-or-seq) + (let [s (seq init-val-or-seq)] + (loop [i 0 s s] + (if (and s (< i size)) + (do + (aset a i (first s)) + (recur (inc i) (next s))) + a))) + (do + (dotimes [i size] + (aset a i init-val-or-seq)) + a))))) + +(defn object-array + "Creates an array of objects. Does not coerce array, provided for compatibility + with Clojure." + ([size-or-seq] + (if (number? size-or-seq) + (object-array size-or-seq nil) + (into-array size-or-seq))) + ([size init-val-or-seq] + (let [a (make-array size)] + (if (seq? init-val-or-seq) + (let [s (seq init-val-or-seq)] + (loop [i 0 s s] + (if (and s (< i size)) + (do + (aset a i (first s)) + (recur (inc i) (next s))) + a))) + (do + (dotimes [i size] + (aset a i init-val-or-seq)) + a))))) + +(defn bounded-count + "If coll is counted? returns its count, else will count at most the first n + elements of coll using its seq" + {:added "1.9"} + [n coll] + (if (counted? coll) + (count coll) + (loop [i 0 s (seq coll)] + (if (and (not (nil? s)) (< i n)) + (recur (inc i) (next s)) + i)))) + +(defn spread + [arglist] + (when-not (nil? arglist) + (let [n (next arglist)] + (if (nil? n) + (seq (first arglist)) + (cons (first arglist) + (spread n)))))) + +(defn concat + "Returns a lazy seq representing the concatenation of the elements in the supplied colls." + ([] (lazy-seq nil)) + ([x] (lazy-seq x)) + ([x y] + (lazy-seq + (let [s (seq x)] + (if s + (if (chunked-seq? s) + (chunk-cons (chunk-first s) (concat (chunk-rest s) y)) + (cons (first s) (concat (rest s) y))) + y)))) + ([x y & zs] + (let [cat (fn cat [xys zs] + (lazy-seq + (let [xys (seq xys)] + (if xys + (if (chunked-seq? xys) + (chunk-cons (chunk-first xys) + (cat (chunk-rest xys) zs)) + (cons (first xys) (cat (rest xys) zs))) + (when zs + (cat (first zs) (next zs)))))))] + (cat (concat x y) zs)))) + +(defn list* + "Creates a new list containing the items prepended to the rest, the + last of which will be treated as a sequence." + ([args] (seq args)) + ([a args] (cons a args)) + ([a b args] (cons a (cons b args))) + ([a b c args] (cons a (cons b (cons c args)))) + ([a b c d & more] + (cons a (cons b (cons c (cons d (spread more))))))) + + +;;; Transients + +(defn transient + "Returns a new, transient version of the collection, in constant time." + [coll] + (-as-transient coll)) + +(defn persistent! + "Returns a new, persistent version of the transient collection, in + constant time. The transient collection cannot be used after this + call, any such use will throw an exception." + [tcoll] + (-persistent! tcoll)) + +(defn conj! + "Adds val to the transient collection, and return tcoll. The 'addition' + may happen at different 'places' depending on the concrete type." + ([] (transient [])) + ([tcoll] tcoll) + ([tcoll val] + (-conj! tcoll val)) + ([tcoll val & vals] + (let [ntcoll (-conj! tcoll val)] + (if vals + (recur ntcoll (first vals) (next vals)) + ntcoll)))) + +(defn assoc! + "When applied to a transient map, adds mapping of key(s) to + val(s). When applied to a transient vector, sets the val at index. + Note - index must be <= (count vector). Returns coll." + ([tcoll key val] + (-assoc! tcoll key val)) + ([tcoll key val & kvs] + (let [ntcoll (-assoc! tcoll key val)] + (if kvs + (recur ntcoll (first kvs) (second kvs) (nnext kvs)) + ntcoll)))) + +(defn dissoc! + "Returns a transient map that doesn't contain a mapping for key(s)." + ([tcoll key] + (-dissoc! tcoll key)) + ([tcoll key & ks] + (let [ntcoll (-dissoc! tcoll key)] + (if ks + (recur ntcoll (first ks) (next ks)) + ntcoll)))) + +(defn pop! + "Removes the last item from a transient vector. If + the collection is empty, throws an exception. Returns tcoll" + [tcoll] + (-pop! tcoll)) + +(defn disj! + "disj[oin]. Returns a transient set of the same (hashed/sorted) type, that + does not contain key(s)." + ([tcoll val] + (-disjoin! tcoll val)) + ([tcoll val & vals] + (let [ntcoll (-disjoin! tcoll val)] + (if vals + (recur ntcoll (first vals) (next vals)) + ntcoll)))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; apply ;;;;;;;;;;;;;;;; + +;; see core.clj +(gen-apply-to) + +(set! *unchecked-if* true) + +(defn- ^seq next* + "Internal. DO NOT USE! Next without the nil? check." + [coll] + (if (implements? INext coll) + (-next ^not-native coll) + (seq (rest coll)))) + +(defn- apply-to-simple + "Internal. DO NOT USE! + Assumes args was already called with seq beforehand!" + ([f ^seq args] + (if (nil? args) + (if (.-cljs$core$IFn$_invoke$arity$0 f) + (.cljs$core$IFn$_invoke$arity$0 f) + (.call f f)) + (apply-to-simple f (-first args) (next* args)))) + ([f a0 ^seq args] + (if (nil? args) + (if (.-cljs$core$IFn$_invoke$arity$1 f) + (.cljs$core$IFn$_invoke$arity$1 f a0) + (.call f f a0)) + (apply-to-simple f a0 (-first args) (next* args)))) + ([f a0 a1 ^seq args] + (if (nil? args) + (if (.-cljs$core$IFn$_invoke$arity$2 f) + (.cljs$core$IFn$_invoke$arity$2 f a0 a1) + (.call f f a0 a1)) + (apply-to-simple f a0 a1 (-first args) (next* args)))) + ([f a0 a1 a2 ^seq args] + (if (nil? args) + (if (.-cljs$core$IFn$_invoke$arity$3 f) + (.cljs$core$IFn$_invoke$arity$3 f a0 a1 a2) + (.call f f a0 a1 a2)) + (apply-to-simple f a0 a1 a2 (-first args) (next* args)))) + ([f a0 a1 a2 a3 ^seq args] + (if (nil? args) + (if (.-cljs$core$IFn$_invoke$arity$4 f) + (.cljs$core$IFn$_invoke$arity$4 f a0 a1 a2 a3) + (.call f f a0 a1 a2 a3)) + (gen-apply-to-simple f 4 args)))) + +(defn apply + "Applies fn f to the argument list formed by prepending intervening arguments to args." + ([f args] + (if (.-cljs$lang$applyTo f) + (let [fixed-arity (.-cljs$lang$maxFixedArity f) + bc (bounded-count (inc fixed-arity) args)] + (if (<= bc fixed-arity) + (apply-to f bc args) + (.cljs$lang$applyTo f args))) + (apply-to-simple f (seq args)))) + ([f x args] + (if (.-cljs$lang$applyTo f) + (let [arglist (list* x args) + fixed-arity (.-cljs$lang$maxFixedArity f) + bc (inc (bounded-count fixed-arity args))] + (if (<= bc fixed-arity) + (apply-to f bc arglist) + (.cljs$lang$applyTo f arglist))) + (apply-to-simple f x (seq args)))) + ([f x y args] + (if (.-cljs$lang$applyTo f) + (let [arglist (list* x y args) + fixed-arity (.-cljs$lang$maxFixedArity f) + bc (+ 2 (bounded-count (dec fixed-arity) args))] + (if (<= bc fixed-arity) + (apply-to f bc arglist) + (.cljs$lang$applyTo f arglist))) + (apply-to-simple f x y (seq args)))) + ([f x y z args] + (if (.-cljs$lang$applyTo f) + (let [arglist (list* x y z args) + fixed-arity (.-cljs$lang$maxFixedArity f) + bc (+ 3 (bounded-count (- fixed-arity 2) args))] + (if (<= bc fixed-arity) + (apply-to f bc arglist) + (.cljs$lang$applyTo f arglist))) + (apply-to-simple f x y z (seq args)))) + ([f a b c d & args] + (if (.-cljs$lang$applyTo f) + (let [spread-args (spread args) + arglist (cons a (cons b (cons c (cons d spread-args)))) + fixed-arity (.-cljs$lang$maxFixedArity f) + bc (+ 4 (bounded-count (- fixed-arity 3) spread-args))] + (if (<= bc fixed-arity) + (apply-to f bc arglist) + (.cljs$lang$applyTo f arglist))) + (apply-to-simple f a b c d (spread args))))) + +(set! *unchecked-if* false) + +(defn vary-meta + "Returns an object of the same type and value as obj, with + (apply f (meta obj) args) as its metadata." + ([obj f] + (with-meta obj (f (meta obj)))) + ([obj f a] + (with-meta obj (f (meta obj) a))) + ([obj f a b] + (with-meta obj (f (meta obj) a b))) + ([obj f a b c] + (with-meta obj (f (meta obj) a b c))) + ([obj f a b c d] + (with-meta obj (f (meta obj) a b c d))) + ([obj f a b c d & args] + (with-meta obj (apply f (meta obj) a b c d args)))) + +(defn ^boolean not= + "Same as (not (= obj1 obj2))" + ([x] false) + ([x y] (not (= x y))) + ([x y & more] + (not (apply = x y more)))) + +(defn not-empty + "If coll is empty, returns nil, else coll" + [coll] (when (seq coll) coll)) + +(defn nil-iter [] + (reify + Object + (hasNext [_] false) + (next [_] (js/Error. "No such element")) + (remove [_] (js/Error. "Unsupported operation")))) + +(deftype StringIter [s ^:mutable i] + Object + (hasNext [_] (< i (.-length s))) + (next [_] + (let [ret (.charAt s i)] + (set! i (inc i)) + ret)) + (remove [_] (js/Error. "Unsupported operation"))) + +(defn string-iter [x] + (StringIter. x 0)) + +(deftype ArrayIter [arr ^:mutable i] + Object + (hasNext [_] (< i (alength arr))) + (next [_] + (let [ret (aget arr i)] + (set! i (inc i)) + ret)) + (remove [_] (js/Error. "Unsupported operation"))) + +(defn array-iter [x] + (ArrayIter. x 0)) + +(def INIT #js {}) +(def START #js {}) + +(deftype SeqIter [^:mutable _seq ^:mutable _next] + Object + (hasNext [_] + (if (identical? _seq INIT) + (do + (set! _seq START) + (set! _next (seq _next))) + (if (identical? _seq _next) + (set! _next (next _seq)))) + (not (nil? _next))) + (next [this] + (if-not ^boolean (.hasNext this) + (throw (js/Error. "No such element")) + (do + (set! _seq _next) + (first _next)))) + (remove [_] (js/Error. "Unsupported operation"))) + +(defn seq-iter [coll] + (SeqIter. INIT coll)) + +(defn iter [coll] + (cond + (iterable? coll) (-iterator coll) + (nil? coll) (nil-iter) + (string? coll) (string-iter coll) + (array? coll) (array-iter coll) + (seqable? coll) (seq-iter coll) + :else (throw (js/Error. (str "Cannot create iterator from " coll))))) + +(deftype Many [vals] + Object + (add [this o] + (.push vals o) + this) + (remove [this] + (.shift vals)) + (isEmpty [this] + (zero? (.-length vals))) + (toString [this] + (str "Many: " vals))) + +(def ^:private NONE #js {}) + +(deftype Single [^:mutable val] + Object + (add [this o] + (if (identical? val NONE) + (do + (set! val o) + this) + (Many. #js [val o]))) + (remove [this] + (if (identical? val NONE) + (throw (js/Error. (str "Removing object from empty buffer"))) + (let [ret val] + (set! val NONE) + ret))) + (isEmpty [this] + (identical? val NONE)) + (toString [this] + (str "Single: " val))) + +(deftype Empty [] + Object + (add [this o] + (Single. o)) + (remove [this] + (throw (js/Error. (str "Removing object from empty buffer")))) + (isEmpty [this] + true) + (toString [this] + "Empty")) + +(def ^:private EMPTY (Empty.)) + +(deftype MultiIterator [iters] + Object + (hasNext [_] + (loop [iters (seq iters)] + (if-not (nil? iters) + (let [iter (first iters)] + (if-not ^boolean (.hasNext iter) + false + (recur (next iters)))) + true))) + (next [_] + (let [nexts (array)] + (dotimes [i (alength iters)] + (aset nexts i (.next (aget iters i)))) + (prim-seq nexts 0)))) + +(defn- chunkIteratorSeq [iter] + (lazy-seq + (when ^boolean (.hasNext iter) + (let [arr (array)] + (loop [n 0] + (if (and (.hasNext iter) (< n 32)) + (do + (aset arr n (.next iter)) + (recur (inc n))) + (chunk-cons (array-chunk arr 0 n) (chunkIteratorSeq iter)))))))) + +(deftype TransformerIterator [^:mutable buffer ^:mutable _next ^:mutable completed ^:mutable xf sourceIter multi] + Object + (step [this] + (if-not (identical? _next NONE) + true + (loop [] + (if (identical? _next NONE) + (if ^boolean (.isEmpty buffer) + (if ^boolean completed + false + (if ^boolean (.hasNext sourceIter) + (let [iter (if ^boolean multi + (apply xf (cons nil (.next sourceIter))) + (xf nil (.next sourceIter)))] + (when (reduced? iter) + (xf nil) + (set! completed true)) + (recur)) + (do + (xf nil) + (set! completed true) + (recur)))) + (do + (set! _next (.remove buffer)) + (recur))) + true)))) + (hasNext [this] + (.step this)) + (next [this] + (if ^boolean (.hasNext this) + (let [ret _next] + (set! _next NONE) + ret) + (throw (js/Error. "No such element")))) + (remove [_] + (js/Error. "Unsupported operation"))) + +(es6-iterable TransformerIterator) + +(defn transformer-iterator + [xform sourceIter multi] + (let [iterator (TransformerIterator. EMPTY NONE false nil sourceIter multi)] + (set! (.-xf iterator) + (xform (fn + ([] nil) + ([acc] acc) + ([acc o] + (set! (.-buffer iterator) (.add (.-buffer iterator) o)) + acc)))) + iterator)) + +(set! (.-create TransformerIterator) + (fn [xform source] + (transformer-iterator xform source false))) + +(set! (.-createMulti TransformerIterator) + (fn [xform sources] + (transformer-iterator xform (MultiIterator. (to-array sources)) true))) + +(defn sequence + "Coerces coll to a (possibly empty) sequence, if it is not already + one. Will not force a lazy seq. (sequence nil) yields (), When a + transducer is supplied, returns a lazy sequence of applications of + the transform to the items in coll(s), i.e. to the set of first + items of each coll, followed by the set of second + items in each coll, until any one of the colls is exhausted. Any + remaining items in other colls are ignored. The transform should accept + number-of-colls arguments" + ([coll] + (if (seq? coll) + coll + (or (seq coll) ()))) + ([xform coll] + (or (chunkIteratorSeq + (.create TransformerIterator xform (iter coll))) + ())) + ([xform coll & colls] + (or (chunkIteratorSeq + (.createMulti TransformerIterator xform (map iter (cons coll colls)))) + ()))) + +(defn every? + "Returns true if (pred x) is logical true for every x in coll, else + false." + [pred coll] + (cond + (nil? (seq coll)) true + (pred (first coll)) (recur pred (next coll)) + :else false)) + +(defn not-every? + "Returns false if (pred x) is logical true for every x in + coll, else true." + [pred coll] (not (every? pred coll))) + +(defn some + "Returns the first logical true value of (pred x) for any x in coll, + else nil. One common idiom is to use a set as pred, for example + this will return :fred if :fred is in the sequence, otherwise nil: + (some #{:fred} coll)" + [pred coll] + (when-let [s (seq coll)] + (or (pred (first s)) (recur pred (next s))))) + +(defn not-any? + "Returns false if (pred x) is logical true for any x in coll, + else true." + [pred coll] (not (some pred coll))) + +(defn even? + "Returns true if n is even, throws an exception if n is not an integer" + [n] (if (integer? n) + (zero? (bit-and n 1)) + (throw (js/Error. (str "Argument must be an integer: " n))))) + +(defn odd? + "Returns true if n is odd, throws an exception if n is not an integer" + [n] (not (even? n))) + +(defn complement + "Takes a fn f and returns a fn that takes the same arguments as f, + has the same effects, if any, and returns the opposite truth value." + [f] + (fn + ([] (not (f))) + ([x] (not (f x))) + ([x y] (not (f x y))) + ([x y & zs] (not (apply f x y zs))))) + +(defn constantly + "Returns a function that takes any number of arguments and returns x." + [x] (fn [& args] x)) + +(defn comp + "Takes a set of functions and returns a fn that is the composition + of those fns. The returned fn takes a variable number of args, + applies the rightmost of fns to the args, the next + fn (right-to-left) to the result, etc." + ([] identity) + ([f] f) + ([f g] + (fn + ([] (f (g))) + ([x] (f (g x))) + ([x y] (f (g x y))) + ([x y z] (f (g x y z))) + ([x y z & args] (f (apply g x y z args))))) + ([f g h] + (fn + ([] (f (g (h)))) + ([x] (f (g (h x)))) + ([x y] (f (g (h x y)))) + ([x y z] (f (g (h x y z)))) + ([x y z & args] (f (g (apply h x y z args)))))) + ([f1 f2 f3 & fs] + (let [fs (reverse (list* f1 f2 f3 fs))] + (fn [& args] + (loop [ret (apply (first fs) args) fs (next fs)] + (if fs + (recur ((first fs) ret) (next fs)) + ret)))))) + +(defn partial + "Takes a function f and fewer than the normal arguments to f, and + returns a fn that takes a variable number of additional args. When + called, the returned function calls f with args + additional args." + ([f] f) + ([f arg1] + (fn + ([] (f arg1)) + ([x] (f arg1 x)) + ([x y] (f arg1 x y)) + ([x y z] (f arg1 x y z)) + ([x y z & args] (apply f arg1 x y z args)))) + ([f arg1 arg2] + (fn + ([] (f arg1 arg2)) + ([x] (f arg1 arg2 x)) + ([x y] (f arg1 arg2 x y)) + ([x y z] (f arg1 arg2 x y z)) + ([x y z & args] (apply f arg1 arg2 x y z args)))) + ([f arg1 arg2 arg3] + (fn + ([] (f arg1 arg2 arg3)) + ([x] (f arg1 arg2 arg3 x)) + ([x y] (f arg1 arg2 arg3 x y)) + ([x y z] (f arg1 arg2 arg3 x y z)) + ([x y z & args] (apply f arg1 arg2 arg3 x y z args)))) + ([f arg1 arg2 arg3 & more] + (fn [& args] (apply f arg1 arg2 arg3 (concat more args))))) + +(defn fnil + "Takes a function f, and returns a function that calls f, replacing + a nil first argument to f with the supplied value x. Higher arity + versions can replace arguments in the second and third + positions (y, z). Note that the function f can take any number of + arguments, not just the one(s) being nil-patched." + ([f x] + (fn + ([a] (f (if (nil? a) x a))) + ([a b] (f (if (nil? a) x a) b)) + ([a b c] (f (if (nil? a) x a) b c)) + ([a b c & ds] (apply f (if (nil? a) x a) b c ds)))) + ([f x y] + (fn + ([a b] (f (if (nil? a) x a) (if (nil? b) y b))) + ([a b c] (f (if (nil? a) x a) (if (nil? b) y b) c)) + ([a b c & ds] (apply f (if (nil? a) x a) (if (nil? b) y b) c ds)))) + ([f x y z] + (fn + ([a b] (f (if (nil? a) x a) (if (nil? b) y b))) + ([a b c] (f (if (nil? a) x a) (if (nil? b) y b) (if (nil? c) z c))) + ([a b c & ds] (apply f (if (nil? a) x a) (if (nil? b) y b) (if (nil? c) z c) ds))))) + +(declare volatile!) + +(defn map-indexed + "Returns a lazy sequence consisting of the result of applying f to 0 + and the first item of coll, followed by applying f to 1 and the second + item in coll, etc, until coll is exhausted. Thus function f should + accept 2 arguments, index and item. Returns a stateful transducer when + no collection is provided." + ([f] + (fn [rf] + (let [i (volatile! -1)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (rf result (f (vswap! i inc) input))))))) + ([f coll] + (letfn [(mapi [idx coll] + (lazy-seq + (when-let [s (seq coll)] + (if (chunked-seq? s) + (let [c (chunk-first s) + size (count c) + b (chunk-buffer size)] + (dotimes [i size] + (chunk-append b (f (+ idx i) (-nth c i)))) + (chunk-cons (chunk b) (mapi (+ idx size) (chunk-rest s)))) + (cons (f idx (first s)) (mapi (inc idx) (rest s)))))))] + (mapi 0 coll)))) + +(defn keep + "Returns a lazy sequence of the non-nil results of (f item). Note, + this means false return values will be included. f must be free of + side-effects. Returns a transducer when no collection is provided." + ([f] + (fn [rf] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (let [v (f input)] + (if (nil? v) + result + (rf result v))))))) + ([f coll] + (lazy-seq + (when-let [s (seq coll)] + (if (chunked-seq? s) + (let [c (chunk-first s) + size (count c) + b (chunk-buffer size)] + (dotimes [i size] + (let [x (f (-nth c i))] + (when-not (nil? x) + (chunk-append b x)))) + (chunk-cons (chunk b) (keep f (chunk-rest s)))) + (let [x (f (first s))] + (if (nil? x) + (keep f (rest s)) + (cons x (keep f (rest s)))))))))) + +;; ============================================================================= +;; Atom + +(deftype Atom [state meta validator watches] + Object + (equiv [this other] + (-equiv this other)) + + IAtom + + IEquiv + (-equiv [o other] (identical? o other)) + + IDeref + (-deref [_] state) + + IMeta + (-meta [_] meta) + + IWatchable + (-notify-watches [this oldval newval] + (doseq [[key f] watches] + (f key this oldval newval))) + (-add-watch [this key f] + (set! (.-watches this) (assoc watches key f)) + this) + (-remove-watch [this key] + (set! (.-watches this) (dissoc watches key))) + + IHash + (-hash [this] (goog/getUid this))) + +(defn atom + "Creates and returns an Atom with an initial value of x and zero or + more options (in any order): + + :meta metadata-map + + :validator validate-fn + + If metadata-map is supplied, it will become the metadata on the + atom. validate-fn must be nil or a side-effect-free fn of one + argument, which will be passed the intended new state on any state + change. If the new state is unacceptable, the validate-fn should + return false or throw an Error. If either of these error conditions + occur, then the value of the atom will not change." + ([x] (Atom. x nil nil nil)) + ([x & {:keys [meta validator]}] (Atom. x meta validator nil))) + +(declare pr-str) + +(defn reset! + "Sets the value of atom to newval without regard for the + current value. Returns new-value." + [a new-value] + (if (instance? Atom a) + (let [validate (.-validator a)] + (when-not (nil? validate) + (when-not (validate new-value) + (throw (js/Error. "Validator rejected reference state")))) + (let [old-value (.-state a)] + (set! (.-state a) new-value) + (when-not (nil? (.-watches a)) + (-notify-watches a old-value new-value)) + new-value)) + (-reset! a new-value))) + +(defn reset-vals! + "Sets the value of atom to newval. Returns [old new], the value of the + atom before and after the reset." + {:added "1.9"} + [a new-value] + (let [validate (.-validator a)] + (when-not (nil? validate) + (when-not (validate new-value) + (throw (js/Error. "Validator rejected reference state")))) + (let [old-value (.-state a)] + (set! (.-state a) new-value) + (when-not (nil? (.-watches a)) + (-notify-watches a old-value new-value)) + [old-value new-value]))) + +(defn swap! + "Atomically swaps the value of atom to be: + (apply f current-value-of-atom args). Note that f may be called + multiple times, and thus should be free of side effects. Returns + the value that was swapped in." + ([a f] + (if (instance? Atom a) + (reset! a (f (.-state a))) + (-swap! a f))) + ([a f x] + (if (instance? Atom a) + (reset! a (f (.-state a) x)) + (-swap! a f x))) + ([a f x y] + (if (instance? Atom a) + (reset! a (f (.-state a) x y)) + (-swap! a f x y))) + ([a f x y & more] + (if (instance? Atom a) + (reset! a (apply f (.-state a) x y more)) + (-swap! a f x y more)))) + +(defn swap-vals! + "Atomically swaps the value of atom to be: + (apply f current-value-of-atom args). Note that f may be called + multiple times, and thus should be free of side effects. + Returns [old new], the value of the atom before and after the swap." + {:added "1.9"} + ([a f] + (reset-vals! a (f (.-state a)))) + ([a f x] + (reset-vals! a (f (.-state a) x))) + ([a f x y] + (reset-vals! a (f (.-state a) x y))) + ([a f x y & more] + (reset-vals! a (apply f (.-state a) x y more)))) + +(defn compare-and-set! + "Atomically sets the value of atom to newval if and only if the + current value of the atom is equal to oldval. Returns true if + set happened, else false." + [^not-native a oldval newval] + (if (= (-deref a) oldval) + (do (reset! a newval) true) + false)) + +(defn set-validator! + "Sets the validator-fn for an atom. validator-fn must be nil or a + side-effect-free fn of one argument, which will be passed the intended + new state on any state change. If the new state is unacceptable, the + validator-fn should return false or throw an Error. If the current state + is not acceptable to the new validator, an Error will be thrown and the + validator will not be changed." + [iref val] + (when (and (some? val) + (not (val (-deref iref)))) + (throw (js/Error. "Validator rejected reference state"))) + (set! (.-validator iref) val)) + +(defn get-validator + "Gets the validator-fn for a var/ref/agent/atom." + [iref] + (.-validator iref)) + +(deftype Volatile [^:mutable state] + IVolatile + (-vreset! [_ new-state] + (set! state new-state)) + + IDeref + (-deref [_] state)) + +(defn volatile! + "Creates and returns a Volatile with an initial value of val." + [val] + (Volatile. val)) + +(defn volatile? + "Returns true if x is a volatile." + [x] (instance? Volatile x)) + +(defn vreset! + "Sets the value of volatile to newval without regard for the + current value. Returns newval." + [vol newval] (-vreset! vol newval)) + +(defn keep-indexed + "Returns a lazy sequence of the non-nil results of (f index item). Note, + this means false return values will be included. f must be free of + side-effects. Returns a stateful transducer when no collection is + provided." + ([f] + (fn [rf] + (let [ia (volatile! -1)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (let [i (vswap! ia inc) + v (f i input)] + (if (nil? v) + result + (rf result v)))))))) + ([f coll] + (letfn [(keepi [idx coll] + (lazy-seq + (when-let [s (seq coll)] + (if (chunked-seq? s) + (let [c (chunk-first s) + size (count c) + b (chunk-buffer size)] + (dotimes [i size] + (let [x (f (+ idx i) (-nth c i))] + (when-not (nil? x) + (chunk-append b x)))) + (chunk-cons (chunk b) (keepi (+ idx size) (chunk-rest s)))) + (let [x (f idx (first s))] + (if (nil? x) + (keepi (inc idx) (rest s)) + (cons x (keepi (inc idx) (rest s)))))))))] + (keepi 0 coll)))) + +(defn every-pred + "Takes a set of predicates and returns a function f that returns true if all of its + composing predicates return a logical true value against all of its arguments, else it returns + false. Note that f is short-circuiting in that it will stop execution on the first + argument that triggers a logical false result against the original predicates." + ([p] + (fn ep1 + ([] true) + ([x] (boolean (p x))) + ([x y] (boolean (and (p x) (p y)))) + ([x y z] (boolean (and (p x) (p y) (p z)))) + ([x y z & args] (boolean (and (ep1 x y z) + (every? p args)))))) + ([p1 p2] + (fn ep2 + ([] true) + ([x] (boolean (and (p1 x) (p2 x)))) + ([x y] (boolean (and (p1 x) (p1 y) (p2 x) (p2 y)))) + ([x y z] (boolean (and (p1 x) (p1 y) (p1 z) (p2 x) (p2 y) (p2 z)))) + ([x y z & args] (boolean (and (ep2 x y z) + (every? #(and (p1 %) (p2 %)) args)))))) + ([p1 p2 p3] + (fn ep3 + ([] true) + ([x] (boolean (and (p1 x) (p2 x) (p3 x)))) + ([x y] (boolean (and (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y)))) + ([x y z] (boolean (and (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y) (p1 z) (p2 z) (p3 z)))) + ([x y z & args] (boolean (and (ep3 x y z) + (every? #(and (p1 %) (p2 %) (p3 %)) args)))))) + ([p1 p2 p3 & ps] + (let [ps (list* p1 p2 p3 ps)] + (fn epn + ([] true) + ([x] (every? #(% x) ps)) + ([x y] (every? #(and (% x) (% y)) ps)) + ([x y z] (every? #(and (% x) (% y) (% z)) ps)) + ([x y z & args] (boolean (and (epn x y z) + (every? #(every? % args) ps)))))))) + +(defn some-fn + "Takes a set of predicates and returns a function f that returns the first logical true value + returned by one of its composing predicates against any of its arguments, else it returns + logical false. Note that f is short-circuiting in that it will stop execution on the first + argument that triggers a logical true result against the original predicates." + ([p] + (fn sp1 + ([] nil) + ([x] (p x)) + ([x y] (or (p x) (p y))) + ([x y z] (or (p x) (p y) (p z))) + ([x y z & args] (or (sp1 x y z) + (some p args))))) + ([p1 p2] + (fn sp2 + ([] nil) + ([x] (or (p1 x) (p2 x))) + ([x y] (or (p1 x) (p1 y) (p2 x) (p2 y))) + ([x y z] (or (p1 x) (p1 y) (p1 z) (p2 x) (p2 y) (p2 z))) + ([x y z & args] (or (sp2 x y z) + (some #(or (p1 %) (p2 %)) args))))) + ([p1 p2 p3] + (fn sp3 + ([] nil) + ([x] (or (p1 x) (p2 x) (p3 x))) + ([x y] (or (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y))) + ([x y z] (or (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y) (p1 z) (p2 z) (p3 z))) + ([x y z & args] (or (sp3 x y z) + (some #(or (p1 %) (p2 %) (p3 %)) args))))) + ([p1 p2 p3 & ps] + (let [ps (list* p1 p2 p3 ps)] + (fn spn + ([] nil) + ([x] (some #(% x) ps)) + ([x y] (some #(or (% x) (% y)) ps)) + ([x y z] (some #(or (% x) (% y) (% z)) ps)) + ([x y z & args] (or (spn x y z) + (some #(some % args) ps))))))) + +(defn map + "Returns a lazy sequence consisting of the result of applying f to + the set of first items of each coll, followed by applying f to the + set of second items in each coll, until any one of the colls is + exhausted. Any remaining items in other colls are ignored. Function + f should accept number-of-colls arguments. Returns a transducer when + no collection is provided." + ([f] + (fn [rf] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (rf result (f input))) + ([result input & inputs] + (rf result (apply f input inputs)))))) + ([f coll] + (lazy-seq + (when-let [s (seq coll)] + (if (chunked-seq? s) + (let [c (chunk-first s) + size (count c) + b (chunk-buffer size)] + (dotimes [i size] + (chunk-append b (f (-nth c i)))) + (chunk-cons (chunk b) (map f (chunk-rest s)))) + (cons (f (first s)) (map f (rest s))))))) + ([f c1 c2] + (lazy-seq + (let [s1 (seq c1) s2 (seq c2)] + (when (and s1 s2) + (cons (f (first s1) (first s2)) + (map f (rest s1) (rest s2))))))) + ([f c1 c2 c3] + (lazy-seq + (let [s1 (seq c1) s2 (seq c2) s3 (seq c3)] + (when (and s1 s2 s3) + (cons (f (first s1) (first s2) (first s3)) + (map f (rest s1) (rest s2) (rest s3))))))) + ([f c1 c2 c3 & colls] + (let [step (fn step [cs] + (lazy-seq + (let [ss (map seq cs)] + (when (every? identity ss) + (cons (map first ss) (step (map rest ss)))))))] + (map #(apply f %) (step (conj colls c3 c2 c1)))))) + +(defn take + "Returns a lazy sequence of the first n items in coll, or all items if + there are fewer than n. Returns a stateful transducer when + no collection is provided." + ([n] + {:pre [(number? n)]} + (fn [rf] + (let [na (volatile! n)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (let [n @na + nn (vswap! na dec) + result (if (pos? n) + (rf result input) + result)] + (if (not (pos? nn)) + (ensure-reduced result) + result))))))) + ([n coll] + {:pre [(number? n)]} + (lazy-seq + (when (pos? n) + (when-let [s (seq coll)] + (cons (first s) (take (dec n) (rest s)))))))) + +(defn drop + "Returns a lazy sequence of all but the first n items in coll. + Returns a stateful transducer when no collection is provided." + ([n] + {:pre [(number? n)]} + (fn [rf] + (let [na (volatile! n)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (let [n @na] + (vswap! na dec) + (if (pos? n) + result + (rf result input)))))))) + ([n coll] + {:pre [(number? n)]} + (let [step (fn [n coll] + (let [s (seq coll)] + (if (and (pos? n) s) + (recur (dec n) (rest s)) + s)))] + (lazy-seq (step n coll))))) + +(defn drop-last + "Return a lazy sequence of all but the last n (default 1) items in coll" + ([s] (drop-last 1 s)) + ([n s] (map (fn [x _] x) s (drop n s)))) + +(defn take-last + "Returns a seq of the last n items in coll. Depending on the type + of coll may be no better than linear time. For vectors, see also subvec." + [n coll] + (loop [s (seq coll), lead (seq (drop n coll))] + (if lead + (recur (next s) (next lead)) + s))) + +(defn drop-while + "Returns a lazy sequence of the items in coll starting from the + first item for which (pred item) returns logical false. Returns a + stateful transducer when no collection is provided." + ([pred] + (fn [rf] + (let [da (volatile! true)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (let [drop? @da] + (if (and drop? (pred input)) + result + (do + (vreset! da nil) + (rf result input))))))))) + ([pred coll] + (let [step (fn [pred coll] + (let [s (seq coll)] + (if (and s (pred (first s))) + (recur pred (rest s)) + s)))] + (lazy-seq (step pred coll))))) + +(deftype Cycle [meta all prev ^:mutable current ^:mutable _next] + Object + (toString [coll] + (pr-str* coll)) + (currentval [coll] + (when-not ^seq current + (if-let [c (next prev)] + (set! current c) + (set! current all))) + current) + + IPending + (-realized? [coll] + (some? current)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (Cycle. new-meta all prev current _next))) + + IMeta + (-meta [coll] meta) + + ISeq + (-first [coll] + (first (.currentval coll))) + (-rest [coll] + (when (nil? _next) + (set! _next (Cycle. nil all (.currentval coll) nil nil))) + _next) + + INext + (-next [coll] + (-rest coll)) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + ISequential + ISeqable + (-seq [coll] coll) + + IReduce + (-reduce [coll f] + (loop [s (.currentval coll) ret (first s)] + (let [s (or (next s) all) + ret (f ret (first s))] + (if (reduced? ret) + @ret + (recur s ret))))) + (-reduce [coll f start] + (loop [s (.currentval coll) ret start] + (let [ret (f ret (first s))] + (if (reduced? ret) + @ret + (recur (or (next s) all) ret)))))) + +(defn cycle + "Returns a lazy (infinite!) sequence of repetitions of the items in coll." + [coll] (if-let [vals (seq coll)] + (Cycle. nil vals nil vals nil) + (.-EMPTY List))) + +(defn split-at + "Returns a vector of [(take n coll) (drop n coll)]" + [n coll] + [(take n coll) (drop n coll)]) + +(deftype Repeat [meta count val ^:mutable next ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x count)) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IPending + (-realized? [coll] false) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (Repeat. new-meta count val next nil))) + + IMeta + (-meta [coll] meta) + + ISeq + (-first [coll] + val) + (-rest [coll] + (if (nil? next) + (if (> count 1) + (do + (set! next (Repeat. nil (dec count) val nil nil)) + next) + (if (== -1 count) + coll + ())) + next)) + + INext + (-next [coll] + (if (nil? next) + (if (> count 1) + (do + (set! next (Repeat. nil (dec count) val nil nil)) + next) + (if (== -1 count) + coll + nil)) + next)) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + ISequential + ISeqable + (-seq [coll] coll) + + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IReduce + (-reduce [coll f] + (if (== count -1) + (loop [ret (f val val)] + (if (reduced? ret) + @ret + (recur (f ret val)))) + (loop [i 1 ret val] + (if (< i count) + (let [ret (f ret val)] + (if (reduced? ret) + @ret + (recur (inc i) ret))) + ret)))) + (-reduce [coll f start] + (if (== count -1) + (loop [ret (f start val)] + (if (reduced? ret) + @ret + (recur (f ret val)))) + (loop [i 0 ret start] + (if (< i count) + (let [ret (f ret val)] + (if (reduced? ret) + @ret + (recur (inc i) ret))) + ret))))) + +(defn repeat + "Returns a lazy (infinite!, or length n if supplied) sequence of xs." + ([x] (Repeat. nil -1 x nil nil)) + ([n x] (if (pos? n) + (Repeat. nil n x nil nil) + (.-EMPTY List)))) + +(defn replicate + "DEPRECATED: Use 'repeat' instead. + Returns a lazy seq of n xs." + [n x] (take n (repeat x))) + +(defn repeatedly + "Takes a function of no args, presumably with side effects, and + returns an infinite (or length n if supplied) lazy sequence of calls + to it" + ([f] (lazy-seq (cons (f) (repeatedly f)))) + ([n f] (take n (repeatedly f)))) + +(def ^:private UNREALIZED-SEED #js {}) + +(deftype Iterate [meta f prev-seed ^:mutable seed ^:mutable next] + Object + (toString [coll] + (pr-str* coll)) + + IPending + (-realized? [coll] + (not (identical? seed UNREALIZED-SEED))) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (Iterate. new-meta f prev-seed seed next))) + + IMeta + (-meta [coll] meta) + + ISeq + (-first [coll] + (when (identical? UNREALIZED-SEED seed) + (set! seed (f prev-seed))) + seed) + (-rest [coll] + (when (nil? next) + (set! next (Iterate. nil f (-first coll) UNREALIZED-SEED nil))) + next) + + INext + (-next [coll] + (-rest coll)) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + ISequential + ISeqable + (-seq [coll] coll) + + IReduce + (-reduce [coll rf] + (let [first (-first coll) + v (f first)] + (loop [ret (rf first v) v v] + (if (reduced? ret) + @ret + (let [v (f v)] + (recur (rf ret v) v)))))) + (-reduce [coll rf start] + (let [v (-first coll)] + (loop [ret (rf start v) v v] + (if (reduced? ret) + @ret + (let [v (f v)] + (recur (rf ret v) v))))))) + +(defn iterate + "Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects" + {:added "1.0"} + [f x] (Iterate. nil f nil x nil)) + +(defn interleave + "Returns a lazy seq of the first item in each coll, then the second etc." + ([] ()) + ([c1] (lazy-seq c1)) + ([c1 c2] + (lazy-seq + (let [s1 (seq c1) s2 (seq c2)] + (when (and s1 s2) + (cons (first s1) (cons (first s2) + (interleave (rest s1) (rest s2)))))))) + ([c1 c2 & colls] + (lazy-seq + (let [ss (map seq (conj colls c2 c1))] + (when (every? identity ss) + (concat (map first ss) (apply interleave (map rest ss)))))))) + +(defn interpose + "Returns a lazy seq of the elements of coll separated by sep. + Returns a stateful transducer when no collection is provided." + ([sep] + (fn [rf] + (let [started (volatile! false)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (if @started + (let [sepr (rf result sep)] + (if (reduced? sepr) + sepr + (rf sepr input))) + (do + (vreset! started true) + (rf result input)))))))) + ([sep coll] (drop 1 (interleave (repeat sep) coll)))) + + + +(defn- flatten1 + "Take a collection of collections, and return a lazy seq + of items from the inner collection" + [colls] + (let [cat (fn cat [coll colls] + (lazy-seq + (if-let [coll (seq coll)] + (cons (first coll) (cat (rest coll) colls)) + (when (seq colls) + (cat (first colls) (rest colls))))))] + (cat nil colls))) + +(declare cat) + +(defn mapcat + "Returns the result of applying concat to the result of applying map + to f and colls. Thus function f should return a collection. Returns + a transducer when no collections are provided" + {:added "1.0" + :static true} + ([f] (comp (map f) cat)) + ([f & colls] + (apply concat (apply map f colls)))) + +(defn filter + "Returns a lazy sequence of the items in coll for which + (pred item) returns logical true. pred must be free of side-effects. + Returns a transducer when no collection is provided." + ([pred] + (fn [rf] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (if (pred input) + (rf result input) + result))))) + ([pred coll] + (lazy-seq + (when-let [s (seq coll)] + (if (chunked-seq? s) + (let [c (chunk-first s) + size (count c) + b (chunk-buffer size)] + (dotimes [i size] + (when (pred (-nth c i)) + (chunk-append b (-nth c i)))) + (chunk-cons (chunk b) (filter pred (chunk-rest s)))) + (let [f (first s) r (rest s)] + (if (pred f) + (cons f (filter pred r)) + (filter pred r)))))))) + +(defn remove + "Returns a lazy sequence of the items in coll for which + (pred item) returns logical false. pred must be free of side-effects. + Returns a transducer when no collection is provided." + ([pred] (filter (complement pred))) + ([pred coll] + (filter (complement pred) coll))) + +(defn tree-seq + "Returns a lazy sequence of the nodes in a tree, via a depth-first walk. + branch? must be a fn of one arg that returns true if passed a node + that can have children (but may not). children must be a fn of one + arg that returns a sequence of the children. Will only be called on + nodes for which branch? returns true. Root is the root node of the + tree." + [branch? children root] + (let [walk (fn walk [node] + (lazy-seq + (cons node + (when (branch? node) + (mapcat walk (children node))))))] + (walk root))) + +(defn flatten + "Takes any nested combination of sequential things (lists, vectors, + etc.) and returns their contents as a single, flat sequence. + (flatten nil) returns nil." + [x] + (filter #(not (sequential? %)) + (rest (tree-seq sequential? seq x)))) + +(defn into + "Returns a new coll consisting of to-coll with all of the items of + from-coll conjoined. A transducer may be supplied." + ([] []) + ([to] to) + ([to from] + (if-not (nil? to) + (if (implements? IEditableCollection to) + (-with-meta (persistent! (reduce -conj! (transient to) from)) (meta to)) + (reduce -conj to from)) + (reduce conj () from))) + ([to xform from] + (if (implements? IEditableCollection to) + (-with-meta (persistent! (transduce xform conj! (transient to) from)) (meta to)) + (transduce xform conj to from)))) + +(defn mapv + "Returns a vector consisting of the result of applying f to the + set of first items of each coll, followed by applying f to the set + of second items in each coll, until any one of the colls is + exhausted. Any remaining items in other colls are ignored. Function + f should accept number-of-colls arguments." + ([f coll] + (-> (reduce (fn [v o] (conj! v (f o))) (transient []) coll) + persistent!)) + ([f c1 c2] + (into [] (map f c1 c2))) + ([f c1 c2 c3] + (into [] (map f c1 c2 c3))) + ([f c1 c2 c3 & colls] + (into [] (apply map f c1 c2 c3 colls)))) + +(defn filterv + "Returns a vector of the items in coll for which + (pred item) returns logical true. pred must be free of side-effects." + [pred coll] + (-> (reduce (fn [v o] (if (pred o) (conj! v o) v)) + (transient []) + coll) + persistent!)) + +(defn partition + "Returns a lazy sequence of lists of n items each, at offsets step + apart. If step is not supplied, defaults to n, i.e. the partitions + do not overlap. If a pad collection is supplied, use its elements as + necessary to complete last partition up to n items. In case there are + not enough padding elements, return a partition with less than n items." + ([n coll] + (partition n n coll)) + ([n step coll] + (lazy-seq + (when-let [s (seq coll)] + (let [p (take n s)] + (when (== n (count p)) + (cons p (partition n step (drop step s)))))))) + ([n step pad coll] + (lazy-seq + (when-let [s (seq coll)] + (let [p (take n s)] + (if (== n (count p)) + (cons p (partition n step pad (drop step s))) + (list (take n (concat p pad))))))))) + +(defn get-in + "Returns the value in a nested associative structure, + where ks is a sequence of keys. Returns nil if the key is not present, + or the not-found value if supplied." + {:added "1.2" + :static true} + ([m ks] + (reduce get m ks)) + ([m ks not-found] + (loop [sentinel lookup-sentinel + m m + ks (seq ks)] + (if-not (nil? ks) + (let [m (get m (first ks) sentinel)] + (if (identical? sentinel m) + not-found + (recur sentinel m (next ks)))) + m)))) + +(defn assoc-in + "Associates a value in a nested associative structure, where ks is a + sequence of keys and v is the new value and returns a new nested structure. + If any levels do not exist, hash-maps will be created." + [m [k & ks] v] + (if ks + (assoc m k (assoc-in (get m k) ks v)) + (assoc m k v))) + +(defn update-in + "'Updates' a value in a nested associative structure, where ks is a + sequence of keys and f is a function that will take the old value + and any supplied args and return the new value, and returns a new + nested structure. If any levels do not exist, hash-maps will be + created." + ([m [k & ks] f] + (if ks + (assoc m k (update-in (get m k) ks f)) + (assoc m k (f (get m k))))) + ([m [k & ks] f a] + (if ks + (assoc m k (update-in (get m k) ks f a)) + (assoc m k (f (get m k) a)))) + ([m [k & ks] f a b] + (if ks + (assoc m k (update-in (get m k) ks f a b)) + (assoc m k (f (get m k) a b)))) + ([m [k & ks] f a b c] + (if ks + (assoc m k (update-in (get m k) ks f a b c)) + (assoc m k (f (get m k) a b c)))) + ([m [k & ks] f a b c & args] + (if ks + (assoc m k (apply update-in (get m k) ks f a b c args)) + (assoc m k (apply f (get m k) a b c args))))) + +(defn update + "'Updates' a value in an associative structure, where k is a + key and f is a function that will take the old value + and any supplied args and return the new value, and returns a new + structure. If the key does not exist, nil is passed as the old value." + ([m k f] + (assoc m k (f (get m k)))) + ([m k f x] + (assoc m k (f (get m k) x))) + ([m k f x y] + (assoc m k (f (get m k) x y))) + ([m k f x y z] + (assoc m k (f (get m k) x y z))) + ([m k f x y z & more] + (assoc m k (apply f (get m k) x y z more)))) + +;;; PersistentVector + +(deftype VectorNode [edit arr]) + +(defn- pv-fresh-node [edit] + (VectorNode. edit (make-array 32))) + +(defn- pv-aget [node idx] + (aget (.-arr node) idx)) + +(defn- pv-aset [node idx val] + (aset (.-arr node) idx val)) + +(defn- pv-clone-node [node] + (VectorNode. (.-edit node) (aclone (.-arr node)))) + +(defn- tail-off [pv] + (let [cnt (.-cnt pv)] + (if (< cnt 32) + 0 + (bit-shift-left (bit-shift-right-zero-fill (dec cnt) 5) 5)))) + +(defn- new-path [edit level node] + (loop [ll level + ret node] + (if (zero? ll) + ret + (let [embed ret + r (pv-fresh-node edit) + _ (pv-aset r 0 embed)] + (recur (- ll 5) r))))) + +(defn- push-tail [pv level parent tailnode] + (let [ret (pv-clone-node parent) + subidx (bit-and (bit-shift-right-zero-fill (dec (.-cnt pv)) level) 0x01f)] + (if (== 5 level) + (do + (pv-aset ret subidx tailnode) + ret) + (let [child (pv-aget parent subidx)] + (if-not (nil? child) + (let [node-to-insert (push-tail pv (- level 5) child tailnode)] + (pv-aset ret subidx node-to-insert) + ret) + (let [node-to-insert (new-path nil (- level 5) tailnode)] + (pv-aset ret subidx node-to-insert) + ret)))))) + +(defn- vector-index-out-of-bounds [i cnt] + (throw (js/Error. (str "No item " i " in vector of length " cnt)))) + +(defn- first-array-for-longvec [pv] + ;; invariants: (count pv) > 32. + (loop [node (.-root pv) + level (.-shift pv)] + (if (pos? level) + (recur (pv-aget node 0) (- level 5)) + (.-arr node)))) + +(defn- unchecked-array-for [pv i] + ;; invariant: i is a valid index of pv (use array-for if unknown). + (if (>= i (tail-off pv)) + (.-tail pv) + (loop [node (.-root pv) + level (.-shift pv)] + (if (pos? level) + (recur (pv-aget node (bit-and (bit-shift-right-zero-fill i level) 0x01f)) + (- level 5)) + (.-arr node))))) + +(defn- array-for [pv i] + (if (and (<= 0 i) (< i (.-cnt pv))) + (unchecked-array-for pv i) + (vector-index-out-of-bounds i (.-cnt pv)))) + +(defn- do-assoc [pv level node i val] + (let [ret (pv-clone-node node)] + (if (zero? level) + (do + (pv-aset ret (bit-and i 0x01f) val) + ret) + (let [subidx (bit-and (bit-shift-right-zero-fill i level) 0x01f)] + (pv-aset ret subidx (do-assoc pv (- level 5) (pv-aget node subidx) i val)) + ret)))) + +(defn- pop-tail [pv level node] + (let [subidx (bit-and (bit-shift-right-zero-fill (- (.-cnt pv) 2) level) 0x01f)] + (cond + (> level 5) (let [new-child (pop-tail pv (- level 5) (pv-aget node subidx))] + (if (and (nil? new-child) (zero? subidx)) + nil + (let [ret (pv-clone-node node)] + (pv-aset ret subidx new-child) + ret))) + (zero? subidx) nil + :else (let [ret (pv-clone-node node)] + (pv-aset ret subidx nil) + ret)))) + +(deftype RangedIterator [^:mutable i ^:mutable base ^:mutable arr v start end] + Object + (hasNext [this] + (< i end)) + (next [this] + (when (== (- i base) 32) + (set! arr (unchecked-array-for v i)) + (set! base (+ base 32))) + (let [ret (aget arr (bit-and i 0x01f))] + (set! i (inc i)) + ret))) + +(defn ranged-iterator [v start end] + (let [i start] + (RangedIterator. i (- i (js-mod i 32)) + (when (< start (count v)) + (unchecked-array-for v i)) + v start end))) + +(defn- pv-reduce + ([pv f start end] + (if (< start end) + (pv-reduce pv f (nth pv start) (inc start) end) + (f))) + ([pv f init start end] + (loop [acc init i start arr (unchecked-array-for pv start)] + (if (< i end) + (let [j (bit-and i 0x01f) + arr (if (zero? j) (unchecked-array-for pv i) arr) + nacc (f acc (aget arr j))] + (if (reduced? nacc) + @nacc + (recur nacc (inc i) arr))) + acc)))) + +(declare tv-editable-root tv-editable-tail TransientVector deref + pr-sequential-writer pr-writer chunked-seq) + +(defprotocol APersistentVector + "Marker protocol") + +(deftype PersistentVector [meta cnt shift root tail ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + ICloneable + (-clone [_] (PersistentVector. meta cnt shift root tail __hash)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentVector. new-meta cnt shift root tail __hash))) + + IMeta + (-meta [coll] meta) + + IStack + (-peek [coll] + (when (> cnt 0) + (-nth coll (dec cnt)))) + (-pop [coll] + (cond + (zero? cnt) (throw (js/Error. "Can't pop empty vector")) + (== 1 cnt) (-with-meta (.-EMPTY PersistentVector) meta) + (< 1 (- cnt (tail-off coll))) + (PersistentVector. meta (dec cnt) shift root (.slice tail 0 -1) nil) + :else (let [new-tail (unchecked-array-for coll (- cnt 2)) + nr (pop-tail coll shift root) + new-root (if (nil? nr) (.-EMPTY-NODE PersistentVector) nr) + cnt-1 (dec cnt)] + (if (and (< 5 shift) (nil? (pv-aget new-root 1))) + (PersistentVector. meta cnt-1 (- shift 5) (pv-aget new-root 0) new-tail nil) + (PersistentVector. meta cnt-1 shift new-root new-tail nil))))) + + ICollection + (-conj [coll o] + (if (< (- cnt (tail-off coll)) 32) + (let [len (alength tail) + new-tail (make-array (inc len))] + (dotimes [i len] + (aset new-tail i (aget tail i))) + (aset new-tail len o) + (PersistentVector. meta (inc cnt) shift root new-tail nil)) + (let [root-overflow? (> (bit-shift-right-zero-fill cnt 5) (bit-shift-left 1 shift)) + new-shift (if root-overflow? (+ shift 5) shift) + new-root (if root-overflow? + (let [n-r (pv-fresh-node nil)] + (pv-aset n-r 0 root) + (pv-aset n-r 1 (new-path nil shift (VectorNode. nil tail))) + n-r) + (push-tail coll shift root (VectorNode. nil tail)))] + (PersistentVector. meta (inc cnt) new-shift new-root (array o) nil)))) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY PersistentVector) meta)) + + ISequential + IEquiv + (-equiv [coll other] + (if (instance? PersistentVector other) + (if (== cnt (count other)) + (let [me-iter (-iterator coll) + you-iter (-iterator other)] + (loop [] + (if ^boolean (.hasNext me-iter) + (let [x (.next me-iter) + y (.next you-iter)] + (if (= x y) + (recur) + false)) + true))) + false) + (equiv-sequential coll other))) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + ISeqable + (-seq [coll] + (cond + (zero? cnt) nil + (<= cnt 32) (IndexedSeq. tail 0 nil) + :else (chunked-seq coll (first-array-for-longvec coll) 0 0))) + + ICounted + (-count [coll] cnt) + + IIndexed + (-nth [coll n] + (aget (array-for coll n) (bit-and n 0x01f))) + (-nth [coll n not-found] + (if (and (<= 0 n) (< n cnt)) + (aget (unchecked-array-for coll n) (bit-and n 0x01f)) + not-found)) + + ILookup + (-lookup [coll k] (-lookup coll k nil)) + (-lookup [coll k not-found] (if (number? k) + (-nth coll k not-found) + not-found)) + + IAssociative + (-assoc [coll k v] + (if (number? k) + (-assoc-n coll k v) + (throw (js/Error. "Vector's key for assoc must be a number.")))) + (-contains-key? [coll k] + (if (integer? k) + (and (<= 0 k) (< k cnt)) + false)) + + IFind + (-find [coll n] + (when (and (<= 0 n) (< n cnt)) + (MapEntry. n (aget (unchecked-array-for coll n) (bit-and n 0x01f)) nil))) + + APersistentVector + IVector + (-assoc-n [coll n val] + (cond + (and (<= 0 n) (< n cnt)) + (if (<= (tail-off coll) n) + (let [new-tail (aclone tail)] + (aset new-tail (bit-and n 0x01f) val) + (PersistentVector. meta cnt shift root new-tail nil)) + (PersistentVector. meta cnt shift (do-assoc coll shift root n val) tail nil)) + (== n cnt) (-conj coll val) + :else (throw (js/Error. (str "Index " n " out of bounds [0," cnt "]"))))) + + IReduce + (-reduce [v f] + (pv-reduce v f 0 cnt)) + (-reduce [v f init] + (loop [i 0 init init] + (if (< i cnt) + (let [arr (unchecked-array-for v i) + len (alength arr) + init (loop [j 0 init init] + (if (< j len) + (let [init (f init (aget arr j))] + (if (reduced? init) + init + (recur (inc j) init))) + init))] + (if (reduced? init) + @init + (recur (+ i len) init))) + init))) + + IKVReduce + (-kv-reduce [v f init] + (loop [i 0 init init] + (if (< i cnt) + (let [arr (unchecked-array-for v i) + len (alength arr) + init (loop [j 0 init init] + (if (< j len) + (let [init (f init (+ j i) (aget arr j))] + (if (reduced? init) + init + (recur (inc j) init))) + init))] + (if (reduced? init) + @init + (recur (+ i len) init))) + init))) + + IFn + (-invoke [coll k] + (-nth coll k)) + (-invoke [coll k not-found] + (-nth coll k not-found)) + + IEditableCollection + (-as-transient [coll] + (TransientVector. cnt shift (tv-editable-root root) (tv-editable-tail tail))) + + IReversible + (-rseq [coll] + (when (pos? cnt) + (RSeq. coll (dec cnt) nil))) + + IIterable + (-iterator [this] + (ranged-iterator this 0 cnt))) + +(set! (.-EMPTY-NODE PersistentVector) (VectorNode. nil (make-array 32))) + +(set! (.-EMPTY PersistentVector) + (PersistentVector. nil 0 5 (.-EMPTY-NODE PersistentVector) (array) empty-ordered-hash)) + +(set! (.-fromArray PersistentVector) + (fn [xs ^boolean no-clone] + (let [l (alength xs) + xs (if no-clone xs (aclone xs))] + (if (< l 32) + (PersistentVector. nil l 5 (.-EMPTY-NODE PersistentVector) xs nil) + (let [node (.slice xs 0 32) + v (PersistentVector. nil 32 5 (.-EMPTY-NODE PersistentVector) node nil)] + (loop [i 32 out (-as-transient v)] + (if (< i l) + (recur (inc i) (conj! out (aget xs i))) + (persistent! out)))))))) + +(es6-iterable PersistentVector) + +(declare map-entry?) + +(defn vec + "Creates a new vector containing the contents of coll. JavaScript arrays + will be aliased and should not be modified." + [coll] + (cond + (map-entry? coll) + [(key coll) (val coll)] + + (vector? coll) + (with-meta coll nil) + + (array? coll) + (.fromArray PersistentVector coll true) + + :else + (-persistent! + (reduce -conj! + (-as-transient (.-EMPTY PersistentVector)) + coll)))) + +(defn vector + "Creates a new vector containing the args." + [& args] + (if (and (instance? IndexedSeq args) (zero? (.-i args))) + (.fromArray PersistentVector (.-arr args) true) + (vec args))) + +(declare subvec) + +(deftype ChunkedSeq [vec node i off meta ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (chunked-seq vec node i off new-meta))) + IMeta + (-meta [coll] meta) + + ISeqable + (-seq [coll] coll) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + ASeq + ISeq + (-first [coll] + (aget node off)) + (-rest [coll] + (if (< (inc off) (alength node)) + (let [s (chunked-seq vec node i (inc off))] + (if (nil? s) + () + s)) + (-chunked-rest coll))) + + INext + (-next [coll] + (if (< (inc off) (alength node)) + (let [s (chunked-seq vec node i (inc off))] + (if (nil? s) + nil + s)) + (-chunked-next coll))) + + ICollection + (-conj [coll o] + (cons o coll)) + + IEmptyableCollection + (-empty [coll] + ()) + + IChunkedSeq + (-chunked-first [coll] + (array-chunk node off)) + (-chunked-rest [coll] + (let [end (+ i (alength node))] + (if (< end (-count vec)) + (chunked-seq vec (unchecked-array-for vec end) end 0) + ()))) + + IChunkedNext + (-chunked-next [coll] + (let [end (+ i (alength node))] + (when (< end (-count vec)) + (chunked-seq vec (unchecked-array-for vec end) end 0)))) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + IReduce + (-reduce [coll f] + (pv-reduce vec f (+ i off) (count vec))) + + (-reduce [coll f start] + (pv-reduce vec f start (+ i off) (count vec)))) + +(es6-iterable ChunkedSeq) + +(defn chunked-seq + ([vec i off] (ChunkedSeq. vec (array-for vec i) i off nil nil)) + ([vec node i off] (ChunkedSeq. vec node i off nil nil)) + ([vec node i off meta] + (ChunkedSeq. vec node i off meta nil))) + +(declare build-subvec) + +(deftype Subvec [meta v start end ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + ICloneable + (-clone [_] (Subvec. meta v start end __hash)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (build-subvec new-meta v start end __hash))) + + IMeta + (-meta [coll] meta) + + IStack + (-peek [coll] + (-nth v (dec end))) + (-pop [coll] + (if (== start end) + (throw (js/Error. "Can't pop empty vector")) + (build-subvec meta v start (dec end) nil))) + + ICollection + (-conj [coll o] + (build-subvec meta (-assoc-n v end o) start (inc end) nil)) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY PersistentVector) meta)) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + ISeqable + (-seq [coll] + (let [subvec-seq (fn subvec-seq [i] + (when-not (== i end) + (cons (-nth v i) + (lazy-seq + (subvec-seq (inc i))))))] + (subvec-seq start))) + + IReversible + (-rseq [coll] + (if-not (== start end) + (RSeq. coll (dec (- end start)) nil))) + + ICounted + (-count [coll] (- end start)) + + IIndexed + (-nth [coll n] + (if (or (neg? n) (<= end (+ start n))) + (vector-index-out-of-bounds n (- end start)) + (-nth v (+ start n)))) + (-nth [coll n not-found] + (if (or (neg? n) (<= end (+ start n))) + not-found + (-nth v (+ start n) not-found))) + + ILookup + (-lookup [coll k] (-lookup coll k nil)) + (-lookup [coll k not-found] (if (number? k) + (-nth coll k not-found) + not-found)) + + IAssociative + (-assoc [coll key val] + (if (number? key) + (-assoc-n coll key val) + (throw (js/Error. "Subvec's key for assoc must be a number.")))) + + IFind + (-find [coll n] + (when-not (neg? n) + (let [idx (+ start n)] + (when (< idx end) + (MapEntry. n (-lookup v idx) nil))))) + + IVector + (-assoc-n [coll n val] + (let [v-pos (+ start n)] + (if (or (neg? n) (<= (inc end) v-pos)) + (throw (js/Error. (str "Index " n " out of bounds [0," (-count coll) "]"))) + (build-subvec meta (assoc v v-pos val) start (max end (inc v-pos)) nil)))) + + IReduce + (-reduce [coll f] + (if (implements? APersistentVector v) + (pv-reduce v f start end) + (ci-reduce coll f))) + (-reduce [coll f init] + (if (implements? APersistentVector v) + (pv-reduce v f init start end) + (ci-reduce coll f init))) + + IKVReduce + (-kv-reduce [coll f init] + (loop [i start j 0 init init] + (if (< i end) + (let [init (f init j (-nth v i))] + (if (reduced? init) + @init + (recur (inc i) (inc j) init))) + init))) + + IFn + (-invoke [coll k] + (-nth coll k)) + (-invoke [coll k not-found] + (-nth coll k not-found)) + + IIterable + (-iterator [coll] + (if (implements? APersistentVector v) + (ranged-iterator v start end) + (seq-iter coll)))) + +(es6-iterable Subvec) + +(defn- build-subvec [meta v start end __hash] + (if (instance? Subvec v) + (recur meta (.-v v) (+ (.-start v) start) (+ (.-start v) end) __hash) + (do + (when-not (vector? v) + (throw (js/Error. "v must satisfy IVector"))) + (let [c (count v)] + (when (or (neg? start) + (neg? end) + (> start c) + (> end c)) + (throw (js/Error. "Index out of bounds")))) + (Subvec. meta v start end __hash)))) + +(defn subvec + "Returns a persistent vector of the items in vector from + start (inclusive) to end (exclusive). If end is not supplied, + defaults to (count vector). This operation is O(1) and very fast, as + the resulting vector shares structure with the original and no + trimming is done." + ([v start] + (subvec v start (count v))) + ([v start end] + (assert (and (not (nil? start)) (not (nil? end)))) + (build-subvec nil v (int start) (int end) nil))) + +(defn- tv-ensure-editable [edit node] + (if (identical? edit (.-edit node)) + node + (VectorNode. edit (aclone (.-arr node))))) + +(defn- tv-editable-root [node] + (VectorNode. (js-obj) (aclone (.-arr node)))) + +(defn- tv-editable-tail [tl] + (let [ret (make-array 32)] + (array-copy tl 0 ret 0 (alength tl)) + ret)) + +(defn- tv-push-tail [tv level parent tail-node] + (let [ret (tv-ensure-editable (.. tv -root -edit) parent) + subidx (bit-and (bit-shift-right-zero-fill (dec (.-cnt tv)) level) 0x01f)] + (pv-aset ret subidx + (if (== level 5) + tail-node + (let [child (pv-aget ret subidx)] + (if-not (nil? child) + (tv-push-tail tv (- level 5) child tail-node) + (new-path (.. tv -root -edit) (- level 5) tail-node))))) + ret)) + +(defn- tv-pop-tail [tv level node] + (let [node (tv-ensure-editable (.. tv -root -edit) node) + subidx (bit-and (bit-shift-right-zero-fill (- (.-cnt tv) 2) level) 0x01f)] + (cond + (> level 5) (let [new-child (tv-pop-tail + tv (- level 5) (pv-aget node subidx))] + (if (and (nil? new-child) (zero? subidx)) + nil + (do (pv-aset node subidx new-child) + node))) + (zero? subidx) nil + :else (do (pv-aset node subidx nil) + node)))) + +(defn- unchecked-editable-array-for [tv i] + ;; invariant: i is a valid index of tv. + (if (>= i (tail-off tv)) + (.-tail tv) + (let [root (.-root tv)] + (loop [node root + level (.-shift tv)] + (if (pos? level) + (recur (tv-ensure-editable + (.-edit root) + (pv-aget node + (bit-and (bit-shift-right-zero-fill i level) + 0x01f))) + (- level 5)) + (.-arr node)))))) + +(deftype TransientVector [^:mutable cnt + ^:mutable shift + ^:mutable root + ^:mutable tail] + ITransientCollection + (-conj! [tcoll o] + (if ^boolean (.-edit root) + (if (< (- cnt (tail-off tcoll)) 32) + (do (aset tail (bit-and cnt 0x01f) o) + (set! cnt (inc cnt)) + tcoll) + (let [tail-node (VectorNode. (.-edit root) tail) + new-tail (make-array 32)] + (aset new-tail 0 o) + (set! tail new-tail) + (if (> (bit-shift-right-zero-fill cnt 5) + (bit-shift-left 1 shift)) + (let [new-root-array (make-array 32) + new-shift (+ shift 5)] + (aset new-root-array 0 root) + (aset new-root-array 1 (new-path (.-edit root) shift tail-node)) + (set! root (VectorNode. (.-edit root) new-root-array)) + (set! shift new-shift) + (set! cnt (inc cnt)) + tcoll) + (let [new-root (tv-push-tail tcoll shift root tail-node)] + (set! root new-root) + (set! cnt (inc cnt)) + tcoll)))) + (throw (js/Error. "conj! after persistent!")))) + + (-persistent! [tcoll] + (if ^boolean (.-edit root) + (do (set! (.-edit root) nil) + (let [len (- cnt (tail-off tcoll)) + trimmed-tail (make-array len)] + (array-copy tail 0 trimmed-tail 0 len) + (PersistentVector. nil cnt shift root trimmed-tail nil))) + (throw (js/Error. "persistent! called twice")))) + + ITransientAssociative + (-assoc! [tcoll key val] + (if (number? key) + (-assoc-n! tcoll key val) + (throw (js/Error. "TransientVector's key for assoc! must be a number.")))) + + ITransientVector + (-assoc-n! [tcoll n val] + (if ^boolean (.-edit root) + (cond + (and (<= 0 n) (< n cnt)) + (if (<= (tail-off tcoll) n) + (do (aset tail (bit-and n 0x01f) val) + tcoll) + (let [new-root + ((fn go [level node] + (let [node (tv-ensure-editable (.-edit root) node)] + (if (zero? level) + (do (pv-aset node (bit-and n 0x01f) val) + node) + (let [subidx (bit-and (bit-shift-right-zero-fill n level) + 0x01f)] + (pv-aset node subidx + (go (- level 5) (pv-aget node subidx))) + node)))) + shift root)] + (set! root new-root) + tcoll)) + (== n cnt) (-conj! tcoll val) + :else + (throw + (js/Error. + (str "Index " n " out of bounds for TransientVector of length" cnt)))) + (throw (js/Error. "assoc! after persistent!")))) + + (-pop! [tcoll] + (if ^boolean (.-edit root) + (cond + (zero? cnt) (throw (js/Error. "Can't pop empty vector")) + (== 1 cnt) (do (set! cnt 0) tcoll) + (pos? (bit-and (dec cnt) 0x01f)) (do (set! cnt (dec cnt)) tcoll) + :else + (let [new-tail (unchecked-editable-array-for tcoll (- cnt 2)) + new-root (let [nr (tv-pop-tail tcoll shift root)] + (if-not (nil? nr) + nr + (VectorNode. (.-edit root) (make-array 32))))] + (if (and (< 5 shift) (nil? (pv-aget new-root 1))) + (let [new-root (tv-ensure-editable (.-edit root) (pv-aget new-root 0))] + (set! root new-root) + (set! shift (- shift 5)) + (set! cnt (dec cnt)) + (set! tail new-tail) + tcoll) + (do (set! root new-root) + (set! cnt (dec cnt)) + (set! tail new-tail) + tcoll)))) + (throw (js/Error. "pop! after persistent!")))) + + ICounted + (-count [coll] + (if ^boolean (.-edit root) + cnt + (throw (js/Error. "count after persistent!")))) + + IIndexed + (-nth [coll n] + (if ^boolean (.-edit root) + (aget (array-for coll n) (bit-and n 0x01f)) + (throw (js/Error. "nth after persistent!")))) + + (-nth [coll n not-found] + (if (and (<= 0 n) (< n cnt)) + (-nth coll n) + not-found)) + + ILookup + (-lookup [coll k] (-lookup coll k nil)) + + (-lookup [coll k not-found] (if (number? k) + (-nth coll k not-found) + not-found)) + + IFn + (-invoke [coll k] + (-lookup coll k)) + + (-invoke [coll k not-found] + (-lookup coll k not-found))) + +;;; PersistentQueue ;;; + +(deftype PersistentQueueIter [^:mutable fseq riter] + Object + (hasNext [_] + (or (and (some? fseq) (seq fseq)) (and (some? riter) (.hasNext riter)))) + (next [_] + (cond + (some? fseq) + (let [ret (first fseq)] + (set! fseq (next fseq)) + ret) + (and (some? riter) ^boolean (.hasNext riter)) + (.next riter) + :else (throw (js/Error. "No such element")))) + (remove [_] (js/Error. "Unsupported operation"))) + +(deftype PersistentQueueSeq [meta front rear ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentQueueSeq. new-meta front rear __hash))) + + IMeta + (-meta [coll] meta) + + ISeq + (-first [coll] (first front)) + (-rest [coll] + (if-let [f1 (next front)] + (PersistentQueueSeq. meta f1 rear nil) + (if (nil? rear) + (-empty coll) + (PersistentQueueSeq. meta rear nil nil)))) + + INext + (-next [coll] + (if-let [f1 (next front)] + (PersistentQueueSeq. meta f1 rear nil) + (when (some? rear) + (PersistentQueueSeq. meta rear nil nil)))) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY List) meta)) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + ISeqable + (-seq [coll] coll)) + +(es6-iterable PersistentQueueSeq) + +(deftype PersistentQueue [meta count front rear ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + ICloneable + (-clone [coll] (PersistentQueue. meta count front rear __hash)) + + IIterable + (-iterator [coll] + (PersistentQueueIter. front (-iterator rear))) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentQueue. new-meta count front rear __hash))) + + IMeta + (-meta [coll] meta) + + ISeq + (-first [coll] (first front)) + (-rest [coll] (rest (seq coll))) + + IStack + (-peek [coll] (first front)) + (-pop [coll] + (if front + (if-let [f1 (next front)] + (PersistentQueue. meta (dec count) f1 rear nil) + (PersistentQueue. meta (dec count) (seq rear) [] nil)) + coll)) + + ICollection + (-conj [coll o] + (if front + (PersistentQueue. meta (inc count) front (conj (or rear []) o) nil) + (PersistentQueue. meta (inc count) (conj front o) [] nil))) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY PersistentQueue) meta)) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + ISeqable + (-seq [coll] + (let [rear (seq rear)] + (if (or front rear) + (PersistentQueueSeq. nil front (seq rear) nil)))) + + ICounted + (-count [coll] count)) + +(set! (.-EMPTY PersistentQueue) (PersistentQueue. nil 0 nil [] empty-ordered-hash)) + +(es6-iterable PersistentQueue) + +(deftype NeverEquiv [] + Object + (equiv [this other] + (-equiv this other)) + IEquiv + (-equiv [o other] false)) + +(def ^:private never-equiv (NeverEquiv.)) + +(defn equiv-map + "Test map equivalence. Returns true if x equals y, otherwise returns false." + [x y] + (boolean + (when (and (map? y) (not (record? y))) + ; assume all maps are counted + (when (== (count x) (count y)) + (if (satisfies? IKVReduce x) + (reduce-kv + (fn [_ k v] + (if (= (get y k never-equiv) v) + true + (reduced false))) + true x) + (every? + (fn [xkv] + (= (get y (first xkv) never-equiv) (second xkv))) + x)))))) + + +(defn- scan-array [incr k array] + (let [len (alength array)] + (loop [i 0] + (when (< i len) + (if (identical? k (aget array i)) + i + (recur (+ i incr))))))) + +; The keys field is an array of all keys of this map, in no particular +; order. Any string, keyword, or symbol key is used as a property name +; to store the value in strobj. If a key is assoc'ed when that same +; key already exists in strobj, the old value is overwritten. If a +; non-string key is assoc'ed, return a HashMap object instead. + +(defn- obj-map-compare-keys [a b] + (let [a (hash a) + b (hash b)] + (cond + (< a b) -1 + (> a b) 1 + :else 0))) + +(defn- obj-map->hash-map [m k v] + (let [ks (.-keys m) + len (alength ks) + so (.-strobj m) + mm (meta m)] + (loop [i 0 + out (transient (.-EMPTY PersistentHashMap))] + (if (< i len) + (let [k (aget ks i)] + (recur (inc i) (assoc! out k (gobject/get so k)))) + (-with-meta (persistent! (assoc! out k v)) mm))))) + +;;; ObjMap - DEPRECATED + +(defn- obj-clone [obj ks] + (let [new-obj (js-obj) + l (alength ks)] + (loop [i 0] + (when (< i l) + (let [k (aget ks i)] + (gobject/set new-obj k (gobject/get obj k)) + (recur (inc i))))) + new-obj)) + +(deftype ObjMap [meta keys strobj update-count ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (ObjMap. new-meta keys strobj update-count __hash))) + + IMeta + (-meta [coll] meta) + + ICollection + (-conj [coll entry] + (if (vector? entry) + (-assoc coll (-nth entry 0) (-nth entry 1)) + (reduce -conj + coll + entry))) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY ObjMap) meta)) + + IEquiv + (-equiv [coll other] (equiv-map coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-unordered-coll __hash)) + + ISeqable + (-seq [coll] + (when (pos? (alength keys)) + (map #(vector % (unchecked-get strobj %)) + (.sort keys obj-map-compare-keys)))) + + ICounted + (-count [coll] (alength keys)) + + ILookup + (-lookup [coll k] (-lookup coll k nil)) + (-lookup [coll k not-found] + (if (and ^boolean (goog/isString k) + (not (nil? (scan-array 1 k keys)))) + (unchecked-get strobj k) + not-found)) + + IAssociative + (-assoc [coll k v] + (if ^boolean (goog/isString k) + (if (or (> update-count (.-HASHMAP_THRESHOLD ObjMap)) + (>= (alength keys) (.-HASHMAP_THRESHOLD ObjMap))) + (obj-map->hash-map coll k v) + (if-not (nil? (scan-array 1 k keys)) + (let [new-strobj (obj-clone strobj keys)] + (gobject/set new-strobj k v) + (ObjMap. meta keys new-strobj (inc update-count) nil)) ; overwrite + (let [new-strobj (obj-clone strobj keys) ; append + new-keys (aclone keys)] + (gobject/set new-strobj k v) + (.push new-keys k) + (ObjMap. meta new-keys new-strobj (inc update-count) nil)))) + ;; non-string key. game over. + (obj-map->hash-map coll k v))) + (-contains-key? [coll k] + (if (and ^boolean (goog/isString k) + (not (nil? (scan-array 1 k keys)))) + true + false)) + + IFind + (-find [coll k] + (when (and ^boolean (goog/isString k) + (not (nil? (scan-array 1 k keys)))) + (MapEntry. k (unchecked-get strobj k) nil))) + + IKVReduce + (-kv-reduce [coll f init] + (let [len (alength keys)] + (loop [keys (.sort keys obj-map-compare-keys) + init init] + (if (seq keys) + (let [k (first keys) + init (f init k (unchecked-get strobj k))] + (if (reduced? init) + @init + (recur (rest keys) init))) + init)))) + + IMap + (-dissoc [coll k] + (if (and ^boolean (goog/isString k) + (not (nil? (scan-array 1 k keys)))) + (let [new-keys (aclone keys) + new-strobj (obj-clone strobj keys)] + (.splice new-keys (scan-array 1 k new-keys) 1) + (js-delete new-strobj k) + (ObjMap. meta new-keys new-strobj (inc update-count) nil)) + coll)) ; key not found, return coll unchanged + + IFn + (-invoke [coll k] + (-lookup coll k)) + (-invoke [coll k not-found] + (-lookup coll k not-found)) + + IEditableCollection + (-as-transient [coll] + (transient (into (hash-map) coll)))) + +(set! (.-EMPTY ObjMap) (ObjMap. nil (array) (js-obj) 0 empty-unordered-hash)) + +(set! (.-HASHMAP_THRESHOLD ObjMap) 8) + +(set! (.-fromObject ObjMap) (fn [ks obj] (ObjMap. nil ks obj 0 nil))) + +;; Record Iterator +(deftype RecordIter [^:mutable i record base-count fields ext-map-iter] + Object + (hasNext [_] + (or (< i base-count) (.hasNext ext-map-iter))) + (next [_] + (if (< i base-count) + (let [k (nth fields i)] + (set! i (inc i)) + (MapEntry. k (-lookup record k) nil)) + (.next ext-map-iter))) + (remove [_] (js/Error. "Unsupported operation"))) + +;; EXPERIMENTAL: subject to change +(deftype ES6EntriesIterator [^:mutable s] + Object + (next [_] + (if-not (nil? s) + (let [[k v] (first s)] + (set! s (next s)) + #js {:value #js [k v] :done false}) + #js {:value nil :done true}))) + +(defn es6-entries-iterator [coll] + (ES6EntriesIterator. (seq coll))) + +;; EXPERIMENTAL: subject to change +(deftype ES6SetEntriesIterator [^:mutable s] + Object + (next [_] + (if-not (nil? s) + (let [x (first s)] + (set! s (next s)) + #js {:value #js [x x] :done false}) + #js {:value nil :done true}))) + +(defn es6-set-entries-iterator [coll] + (ES6SetEntriesIterator. (seq coll))) + +;;; PersistentArrayMap + +(defn- array-index-of-nil? [arr] + (let [len (alength arr)] + (loop [i 0] + (cond + (<= len i) -1 + (nil? (aget arr i)) i + :else (recur (+ i 2)))))) + +(defn- array-index-of-keyword? [arr k] + (let [len (alength arr) + kstr (.-fqn k)] + (loop [i 0] + (cond + (<= len i) -1 + (and (keyword? (aget arr i)) + (identical? kstr (.-fqn (aget arr i)))) i + :else (recur (+ i 2)))))) + +(defn- array-index-of-symbol? [arr k] + (let [len (alength arr) + kstr (.-str k)] + (loop [i 0] + (cond + (<= len i) -1 + (and (symbol? (aget arr i)) + (identical? kstr (.-str (aget arr i)))) i + :else (recur (+ i 2)))))) + +(defn- array-index-of-identical? [arr k] + (let [len (alength arr)] + (loop [i 0] + (cond + (<= len i) -1 + (identical? k (aget arr i)) i + :else (recur (+ i 2)))))) + +(defn- array-index-of-equiv? [arr k] + (let [len (alength arr)] + (loop [i 0] + (cond + (<= len i) -1 + (= k (aget arr i)) i + :else (recur (+ i 2)))))) + +(defn array-index-of [arr k] + (cond + (keyword? k) (array-index-of-keyword? arr k) + + (or ^boolean (goog/isString k) (number? k)) + (array-index-of-identical? arr k) + + (symbol? k) (array-index-of-symbol? arr k) + + (nil? k) + (array-index-of-nil? arr) + + :else (array-index-of-equiv? arr k))) + +(defn- array-map-index-of [m k] + (array-index-of (.-arr m) k)) + +(defn- array-extend-kv [arr k v] + (let [l (alength arr) + narr (make-array (+ l 2))] + (loop [i 0] + (when (< i l) + (aset narr i (aget arr i)) + (recur (inc i)))) + (aset narr l k) + (aset narr (inc l) v) + narr)) + +(defn- array-map-extend-kv [m k v] + (array-extend-kv (.-arr m) k v)) + +(declare TransientArrayMap) + +(deftype MapEntry [key val ^:mutable __hash] + Object + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IMapEntry + (-key [node] key) + (-val [node] val) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IMeta + (-meta [node] nil) + + IWithMeta + (-with-meta [node meta] + (with-meta [key val] meta)) + + IStack + (-peek [node] val) + + (-pop [node] [key]) + + ICollection + (-conj [node o] [key val o]) + + IEmptyableCollection + (-empty [node] nil) + + ISequential + ISeqable + (-seq [node] (IndexedSeq. #js [key val] 0 nil)) + + IReversible + (-rseq [node] (IndexedSeq. #js [val key] 0 nil)) + + ICounted + (-count [node] 2) + + IIndexed + (-nth [node n] + (cond (== n 0) key + (== n 1) val + :else (throw (js/Error. "Index out of bounds")))) + + (-nth [node n not-found] + (cond (== n 0) key + (== n 1) val + :else not-found)) + + ILookup + (-lookup [node k] (-nth node k nil)) + (-lookup [node k not-found] (-nth node k not-found)) + + IAssociative + (-assoc [node k v] + (assoc [key val] k v)) + (-contains-key? [node k] + (or (== k 0) (== k 1))) + + IFind + (-find [node k] + (case k + 0 (MapEntry. 0 key nil) + 1 (MapEntry. 1 val nil) + nil)) + + IVector + (-assoc-n [node n v] + (-assoc-n [key val] n v)) + + IReduce + (-reduce [node f] + (ci-reduce node f)) + + (-reduce [node f start] + (ci-reduce node f start)) + + IFn + (-invoke [node k] + (-nth node k)) + + (-invoke [node k not-found] + (-nth node k not-found))) + +(defn map-entry? + "Returns true if x satisfies IMapEntry" + [x] + (implements? IMapEntry x)) + +(deftype PersistentArrayMapSeq [arr i _meta] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IMeta + (-meta [coll] _meta) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta _meta) + coll + (PersistentArrayMapSeq. arr i new-meta))) + + ICounted + (-count [coll] + (/ (- (alength arr) i) 2)) + + ISeqable + (-seq [coll] coll) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + ICollection + (-conj [coll o] + (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + IHash + (-hash [coll] (hash-ordered-coll coll)) + + ISeq + (-first [coll] + (MapEntry. (aget arr i) (aget arr (inc i)) nil)) + + (-rest [coll] + (if (< i (- (alength arr) 2)) + (PersistentArrayMapSeq. arr (+ i 2) nil) + ())) + + INext + (-next [coll] + (when (< i (- (alength arr) 2)) + (PersistentArrayMapSeq. arr (+ i 2) nil))) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(es6-iterable PersistentArrayMapSeq) + +(defn persistent-array-map-seq [arr i _meta] + (when (<= i (- (alength arr) 2)) + (PersistentArrayMapSeq. arr i _meta))) + +(declare keys vals) + +(deftype PersistentArrayMapIterator [arr ^:mutable i cnt] + Object + (hasNext [_] + (< i cnt)) + (next [_] + (let [ret (MapEntry. (aget arr i) (aget arr (inc i)) nil)] + (set! i (+ i 2)) + ret))) + +(deftype PersistentArrayMap [meta cnt arr ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + + ;; EXPERIMENTAL: subject to change + (keys [coll] + (es6-iterator (keys coll))) + (entries [coll] + (es6-entries-iterator (seq coll))) + (values [coll] + (es6-iterator (vals coll))) + (has [coll k] + (contains? coll k)) + (get [coll k not-found] + (-lookup coll k not-found)) + (forEach [coll f] + (doseq [[k v] coll] + (f v k))) + + ICloneable + (-clone [_] (PersistentArrayMap. meta cnt arr __hash)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentArrayMap. new-meta cnt arr __hash))) + + IMeta + (-meta [coll] meta) + + ICollection + (-conj [coll entry] + (if (vector? entry) + (-assoc coll (-nth entry 0) (-nth entry 1)) + (loop [ret coll es (seq entry)] + (if (nil? es) + ret + (let [e (first es)] + (if (vector? e) + (recur (-assoc ret (-nth e 0) (-nth e 1)) + (next es)) + (throw (js/Error. "conj on a map takes map entries or seqables of map entries")))))))) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY PersistentArrayMap) meta)) + + IEquiv + (-equiv [coll other] + (if (and (map? other) (not (record? other))) + (let [alen (alength arr) + ^not-native other other] + (if (== cnt (-count other)) + (loop [i 0] + (if (< i alen) + (let [v (-lookup other (aget arr i) lookup-sentinel)] + (if-not (identical? v lookup-sentinel) + (if (= (aget arr (inc i)) v) + (recur (+ i 2)) + false) + false)) + true)) + false)) + false)) + + IHash + (-hash [coll] (caching-hash coll hash-unordered-coll __hash)) + + IIterable + (-iterator [this] + (PersistentArrayMapIterator. arr 0 (* cnt 2))) + + ISeqable + (-seq [coll] + (persistent-array-map-seq arr 0 nil)) + + ICounted + (-count [coll] cnt) + + ILookup + (-lookup [coll k] + (-lookup coll k nil)) + + (-lookup [coll k not-found] + (let [idx (array-map-index-of coll k)] + (if (== idx -1) + not-found + (aget arr (inc idx))))) + + IAssociative + (-assoc [coll k v] + (let [idx (array-map-index-of coll k)] + (cond + (== idx -1) + (if (< cnt (.-HASHMAP-THRESHOLD PersistentArrayMap)) + (let [arr (array-map-extend-kv coll k v)] + (PersistentArrayMap. meta (inc cnt) arr nil)) + (-> (into (.-EMPTY PersistentHashMap) coll) + (-assoc k v) + (-with-meta meta))) + + (identical? v (aget arr (inc idx))) + coll + + :else + (let [arr (doto (aclone arr) + (aset (inc idx) v))] + (PersistentArrayMap. meta cnt arr nil))))) + + (-contains-key? [coll k] + (not (== (array-map-index-of coll k) -1))) + + IFind + (-find [coll k] + (let [idx (array-map-index-of coll k)] + (when-not (== idx -1) + (MapEntry. (aget arr idx) (aget arr (inc idx)) nil)))) + + IMap + (-dissoc [coll k] + (let [idx (array-map-index-of coll k)] + (if (>= idx 0) + (let [len (alength arr) + new-len (- len 2)] + (if (zero? new-len) + (-empty coll) + (let [new-arr (make-array new-len)] + (loop [s 0 d 0] + (cond + (>= s len) (PersistentArrayMap. meta (dec cnt) new-arr nil) + (= k (aget arr s)) (recur (+ s 2) d) + :else (do (aset new-arr d (aget arr s)) + (aset new-arr (inc d) (aget arr (inc s))) + (recur (+ s 2) (+ d 2)))))))) + coll))) + + IKVReduce + (-kv-reduce [coll f init] + (let [len (alength arr)] + (loop [i 0 init init] + (if (< i len) + (let [init (f init (aget arr i) (aget arr (inc i)))] + (if (reduced? init) + @init + (recur (+ i 2) init))) + init)))) + + IReduce + (-reduce [coll f] + (iter-reduce coll f)) + (-reduce [coll f start] + (iter-reduce coll f start)) + + IFn + (-invoke [coll k] + (-lookup coll k)) + + (-invoke [coll k not-found] + (-lookup coll k not-found)) + + IEditableCollection + (-as-transient [coll] + (TransientArrayMap. (js-obj) (alength arr) (aclone arr)))) + +(set! (.-EMPTY PersistentArrayMap) (PersistentArrayMap. nil 0 (array) empty-unordered-hash)) + +(set! (.-HASHMAP-THRESHOLD PersistentArrayMap) 8) + +(set! (.-fromArray PersistentArrayMap) + (fn [arr ^boolean no-clone ^boolean no-check] + (as-> (if no-clone arr (aclone arr)) arr + (if no-check + arr + (let [ret (array)] + (loop [i 0] + (when (< i (alength arr)) + (let [k (aget arr i) + v (aget arr (inc i)) + idx (array-index-of ret k)] + (when (== idx -1) + (.push ret k) + (.push ret v))) + (recur (+ i 2)))) + ret)) + (let [cnt (/ (alength arr) 2)] + (PersistentArrayMap. nil cnt arr nil))))) + +(set! (.-createWithCheck PersistentArrayMap) + (fn [arr] + (let [ret (array)] + (loop [i 0] + (when (< i (alength arr)) + (let [k (aget arr i) + v (aget arr (inc i)) + idx (array-index-of ret k)] + (if (== idx -1) + (doto ret (.push k) (.push v)) + (throw (js/Error. (str "Duplicate key: " k))))) + (recur (+ i 2)))) + (let [cnt (/ (alength arr) 2)] + (PersistentArrayMap. nil cnt arr nil))))) + +(set! (.-createAsIfByAssoc PersistentArrayMap) + (fn [arr] + (let [ret (array)] + (loop [i 0] + (when (< i (alength arr)) + (let [k (aget arr i) + v (aget arr (inc i)) + idx (array-index-of ret k)] + (if (== idx -1) + (doto ret (.push k) (.push v)) + (aset ret (inc idx) v))) + (recur (+ i 2)))) + (PersistentArrayMap. nil (/ (alength ret) 2) ret nil)))) + +(es6-iterable PersistentArrayMap) + +(declare array->transient-hash-map) + +(deftype TransientArrayMap [^:mutable editable? + ^:mutable len + arr] + ICounted + (-count [tcoll] + (if editable? + (quot len 2) + (throw (js/Error. "count after persistent!")))) + + ILookup + (-lookup [tcoll k] + (-lookup tcoll k nil)) + + (-lookup [tcoll k not-found] + (if editable? + (let [idx (array-map-index-of tcoll k)] + (if (== idx -1) + not-found + (aget arr (inc idx)))) + (throw (js/Error. "lookup after persistent!")))) + + ITransientCollection + (-conj! [tcoll o] + (if editable? + (cond + (map-entry? o) + (-assoc! tcoll (key o) (val o)) + + (vector? o) + (-assoc! tcoll (o 0) (o 1)) + + :else + (loop [es (seq o) tcoll tcoll] + (if-let [e (first es)] + (recur (next es) + (-assoc! tcoll (key e) (val e))) + tcoll))) + (throw (js/Error. "conj! after persistent!")))) + + (-persistent! [tcoll] + (if editable? + (do (set! editable? false) + (PersistentArrayMap. nil (quot len 2) arr nil)) + (throw (js/Error. "persistent! called twice")))) + + ITransientAssociative + (-assoc! [tcoll key val] + (if editable? + (let [idx (array-map-index-of tcoll key)] + (if (== idx -1) + (if (<= (+ len 2) (* 2 (.-HASHMAP-THRESHOLD PersistentArrayMap))) + (do (set! len (+ len 2)) + (.push arr key) + (.push arr val) + tcoll) + (assoc! (array->transient-hash-map len arr) key val)) + (if (identical? val (aget arr (inc idx))) + tcoll + (do (aset arr (inc idx) val) + tcoll)))) + (throw (js/Error. "assoc! after persistent!")))) + + ITransientMap + (-dissoc! [tcoll key] + (if editable? + (let [idx (array-map-index-of tcoll key)] + (when (>= idx 0) + (aset arr idx (aget arr (- len 2))) + (aset arr (inc idx) (aget arr (dec len))) + (doto arr .pop .pop) + (set! len (- len 2))) + tcoll) + (throw (js/Error. "dissoc! after persistent!")))) + + IFn + (-invoke [tcoll key] + (-lookup tcoll key nil)) + (-invoke [tcoll key not-found] + (-lookup tcoll key not-found))) + +(declare TransientHashMap) + +(defn- array->transient-hash-map [len arr] + (loop [out (transient (.-EMPTY PersistentHashMap)) + i 0] + (if (< i len) + (recur (assoc! out (aget arr i) (aget arr (inc i))) (+ i 2)) + out))) + +;;; PersistentHashMap + +(deftype Box [^:mutable val]) + +(declare create-inode-seq create-array-node-seq reset! create-node atom deref) + +(defn key-test [key other] + (cond + (identical? key other) true + (keyword-identical? key other) true + :else (= key other))) + +(defn- mask [hash shift] + (bit-and (bit-shift-right-zero-fill hash shift) 0x01f)) + +(defn- clone-and-set + ([arr i a] + (doto (aclone arr) + (aset i a))) + ([arr i a j b] + (doto (aclone arr) + (aset i a) + (aset j b)))) + +(defn- remove-pair [arr i] + (let [new-arr (make-array (- (alength arr) 2))] + (array-copy arr 0 new-arr 0 (* 2 i)) + (array-copy arr (* 2 (inc i)) new-arr (* 2 i) (- (alength new-arr) (* 2 i))) + new-arr)) + +(defn- bitmap-indexed-node-index [bitmap bit] + (bit-count (bit-and bitmap (dec bit)))) + +(defn- bitpos [hash shift] + (bit-shift-left 1 (mask hash shift))) + +(defn- edit-and-set + ([inode edit i a] + (let [editable (.ensure-editable inode edit)] + (aset (.-arr editable) i a) + editable)) + ([inode edit i a j b] + (let [editable (.ensure-editable inode edit)] + (aset (.-arr editable) i a) + (aset (.-arr editable) j b) + editable))) + +(defn- inode-kv-reduce [arr f init] + (let [len (alength arr)] + (loop [i 0 init init] + (if (< i len) + (let [init (let [k (aget arr i)] + (if-not (nil? k) + (f init k (aget arr (inc i))) + (let [node (aget arr (inc i))] + (if-not (nil? node) + (.kv-reduce node f init) + init))))] + (if (reduced? init) + init + (recur (+ i 2) init))) + init)))) + +(declare ArrayNode) + + (deftype NodeIterator [arr ^:mutable i ^:mutable next-entry ^:mutable next-iter] + Object + (advance [this] + (let [len (alength arr)] + (loop [] + (if (< i len) + (let [key (aget arr i) + node-or-val (aget arr (inc i)) + ^boolean found + (cond (some? key) + (set! next-entry (MapEntry. key node-or-val nil)) + (some? node-or-val) + (let [new-iter (-iterator node-or-val)] + (if ^boolean (.hasNext new-iter) + (set! next-iter new-iter) + false)) + :else false)] + (set! i (+ i 2)) + (if found true (recur))) + false)))) + (hasNext [this] + (or (some? next-entry) (some? next-iter) (.advance this))) + (next [this] + (cond + (some? next-entry) + (let [ret next-entry] + (set! next-entry nil) + ret) + (some? next-iter) + (let [ret (.next next-iter)] + (when-not ^boolean (.hasNext next-iter) + (set! next-iter nil)) + ret) + ^boolean (.advance this) + (.next this) + :else (throw (js/Error. "No such element")))) + (remove [_] (js/Error. "Unsupported operation"))) + +(deftype BitmapIndexedNode [edit ^:mutable bitmap ^:mutable arr] + Object + (inode-assoc [inode shift hash key val added-leaf?] + (let [bit (bitpos hash shift) + idx (bitmap-indexed-node-index bitmap bit)] + (if (zero? (bit-and bitmap bit)) + (let [n (bit-count bitmap)] + (if (>= n 16) + (let [nodes (make-array 32) + jdx (mask hash shift)] + (aset nodes jdx (.inode-assoc (.-EMPTY BitmapIndexedNode) (+ shift 5) hash key val added-leaf?)) + (loop [i 0 j 0] + (if (< i 32) + (if (zero? (bit-and (bit-shift-right-zero-fill bitmap i) 1)) + (recur (inc i) j) + (do (aset nodes i + (if-not (nil? (aget arr j)) + (.inode-assoc (.-EMPTY BitmapIndexedNode) + (+ shift 5) (cljs.core/hash (aget arr j)) (aget arr j) (aget arr (inc j)) added-leaf?) + (aget arr (inc j)))) + (recur (inc i) (+ j 2)))))) + (ArrayNode. nil (inc n) nodes)) + (let [new-arr (make-array (* 2 (inc n)))] + (array-copy arr 0 new-arr 0 (* 2 idx)) + (aset new-arr (* 2 idx) key) + (aset new-arr (inc (* 2 idx)) val) + (array-copy arr (* 2 idx) new-arr (* 2 (inc idx)) (* 2 (- n idx))) + (set! (.-val added-leaf?) true) + (BitmapIndexedNode. nil (bit-or bitmap bit) new-arr)))) + (let [key-or-nil (aget arr (* 2 idx)) + val-or-node (aget arr (inc (* 2 idx)))] + (cond (nil? key-or-nil) + (let [n (.inode-assoc val-or-node (+ shift 5) hash key val added-leaf?)] + (if (identical? n val-or-node) + inode + (BitmapIndexedNode. nil bitmap (clone-and-set arr (inc (* 2 idx)) n)))) + + (key-test key key-or-nil) + (if (identical? val val-or-node) + inode + (BitmapIndexedNode. nil bitmap (clone-and-set arr (inc (* 2 idx)) val))) + + :else + (do (set! (.-val added-leaf?) true) + (BitmapIndexedNode. nil bitmap + (clone-and-set arr (* 2 idx) nil (inc (* 2 idx)) + (create-node (+ shift 5) key-or-nil val-or-node hash key val))))))))) + + (inode-without [inode shift hash key] + (let [bit (bitpos hash shift)] + (if (zero? (bit-and bitmap bit)) + inode + (let [idx (bitmap-indexed-node-index bitmap bit) + key-or-nil (aget arr (* 2 idx)) + val-or-node (aget arr (inc (* 2 idx)))] + (cond (nil? key-or-nil) + (let [n (.inode-without val-or-node (+ shift 5) hash key)] + (cond (identical? n val-or-node) inode + (not (nil? n)) (BitmapIndexedNode. nil bitmap (clone-and-set arr (inc (* 2 idx)) n)) + (== bitmap bit) nil + :else (BitmapIndexedNode. nil (bit-xor bitmap bit) (remove-pair arr idx)))) + (key-test key key-or-nil) + (BitmapIndexedNode. nil (bit-xor bitmap bit) (remove-pair arr idx)) + :else inode))))) + + (inode-lookup [inode shift hash key not-found] + (let [bit (bitpos hash shift)] + (if (zero? (bit-and bitmap bit)) + not-found + (let [idx (bitmap-indexed-node-index bitmap bit) + key-or-nil (aget arr (* 2 idx)) + val-or-node (aget arr (inc (* 2 idx)))] + (cond (nil? key-or-nil) (.inode-lookup val-or-node (+ shift 5) hash key not-found) + (key-test key key-or-nil) val-or-node + :else not-found))))) + + (inode-find [inode shift hash key not-found] + (let [bit (bitpos hash shift)] + (if (zero? (bit-and bitmap bit)) + not-found + (let [idx (bitmap-indexed-node-index bitmap bit) + key-or-nil (aget arr (* 2 idx)) + val-or-node (aget arr (inc (* 2 idx)))] + (cond (nil? key-or-nil) (.inode-find val-or-node (+ shift 5) hash key not-found) + (key-test key key-or-nil) (MapEntry. key-or-nil val-or-node nil) + :else not-found))))) + + (inode-seq [inode] + (create-inode-seq arr)) + + (ensure-editable [inode e] + (if (identical? e edit) + inode + (let [n (bit-count bitmap) + new-arr (make-array (if (neg? n) 4 (* 2 (inc n))))] + (array-copy arr 0 new-arr 0 (* 2 n)) + (BitmapIndexedNode. e bitmap new-arr)))) + + (edit-and-remove-pair [inode e bit i] + (if (== bitmap bit) + nil + (let [editable (.ensure-editable inode e) + earr (.-arr editable) + len (alength earr)] + (set! (.-bitmap editable) (bit-xor bit (.-bitmap editable))) + (array-copy earr (* 2 (inc i)) + earr (* 2 i) + (- len (* 2 (inc i)))) + (aset earr (- len 2) nil) + (aset earr (dec len) nil) + editable))) + + (inode-assoc! [inode edit shift hash key val added-leaf?] + (let [bit (bitpos hash shift) + idx (bitmap-indexed-node-index bitmap bit)] + (if (zero? (bit-and bitmap bit)) + (let [n (bit-count bitmap)] + (cond + (< (* 2 n) (alength arr)) + (let [editable (.ensure-editable inode edit) + earr (.-arr editable)] + (set! (.-val added-leaf?) true) + (array-copy-downward earr (* 2 idx) + earr (* 2 (inc idx)) + (* 2 (- n idx))) + (aset earr (* 2 idx) key) + (aset earr (inc (* 2 idx)) val) + (set! (.-bitmap editable) (bit-or (.-bitmap editable) bit)) + editable) + + (>= n 16) + (let [nodes (make-array 32) + jdx (mask hash shift)] + (aset nodes jdx (.inode-assoc! (.-EMPTY BitmapIndexedNode) edit (+ shift 5) hash key val added-leaf?)) + (loop [i 0 j 0] + (if (< i 32) + (if (zero? (bit-and (bit-shift-right-zero-fill bitmap i) 1)) + (recur (inc i) j) + (do (aset nodes i + (if-not (nil? (aget arr j)) + (.inode-assoc! (.-EMPTY BitmapIndexedNode) + edit (+ shift 5) (cljs.core/hash (aget arr j)) (aget arr j) (aget arr (inc j)) added-leaf?) + (aget arr (inc j)))) + (recur (inc i) (+ j 2)))))) + (ArrayNode. edit (inc n) nodes)) + + :else + (let [new-arr (make-array (* 2 (+ n 4)))] + (array-copy arr 0 new-arr 0 (* 2 idx)) + (aset new-arr (* 2 idx) key) + (aset new-arr (inc (* 2 idx)) val) + (array-copy arr (* 2 idx) new-arr (* 2 (inc idx)) (* 2 (- n idx))) + (set! (.-val added-leaf?) true) + (let [editable (.ensure-editable inode edit)] + (set! (.-arr editable) new-arr) + (set! (.-bitmap editable) (bit-or (.-bitmap editable) bit)) + editable)))) + (let [key-or-nil (aget arr (* 2 idx)) + val-or-node (aget arr (inc (* 2 idx)))] + (cond (nil? key-or-nil) + (let [n (.inode-assoc! val-or-node edit (+ shift 5) hash key val added-leaf?)] + (if (identical? n val-or-node) + inode + (edit-and-set inode edit (inc (* 2 idx)) n))) + + (key-test key key-or-nil) + (if (identical? val val-or-node) + inode + (edit-and-set inode edit (inc (* 2 idx)) val)) + + :else + (do (set! (.-val added-leaf?) true) + (edit-and-set inode edit (* 2 idx) nil (inc (* 2 idx)) + (create-node edit (+ shift 5) key-or-nil val-or-node hash key val)))))))) + + (inode-without! [inode edit shift hash key removed-leaf?] + (let [bit (bitpos hash shift)] + (if (zero? (bit-and bitmap bit)) + inode + (let [idx (bitmap-indexed-node-index bitmap bit) + key-or-nil (aget arr (* 2 idx)) + val-or-node (aget arr (inc (* 2 idx)))] + (cond (nil? key-or-nil) + (let [n (.inode-without! val-or-node edit (+ shift 5) hash key removed-leaf?)] + (cond (identical? n val-or-node) inode + (not (nil? n)) (edit-and-set inode edit (inc (* 2 idx)) n) + (== bitmap bit) nil + :else (.edit-and-remove-pair inode edit bit idx))) + (key-test key key-or-nil) + (do (set! (.-val removed-leaf?) true) + (.edit-and-remove-pair inode edit bit idx)) + :else inode))))) + + (kv-reduce [inode f init] + (inode-kv-reduce arr f init)) + + IIterable + (-iterator [coll] + (NodeIterator. arr 0 nil nil))) + +(set! (.-EMPTY BitmapIndexedNode) (BitmapIndexedNode. nil 0 (make-array 0))) + +(defn- pack-array-node [array-node edit idx] + (let [arr (.-arr array-node) + len (alength arr) + new-arr (make-array (* 2 (dec (.-cnt array-node))))] + (loop [i 0 j 1 bitmap 0] + (if (< i len) + (if (and (not (== i idx)) + (not (nil? (aget arr i)))) + (do (aset new-arr j (aget arr i)) + (recur (inc i) (+ j 2) (bit-or bitmap (bit-shift-left 1 i)))) + (recur (inc i) j bitmap)) + (BitmapIndexedNode. edit bitmap new-arr))))) + +(deftype ArrayNodeIterator [arr ^:mutable i ^:mutable next-iter] + Object + (hasNext [this] + (let [len (alength arr)] + (loop [] + (if-not (and (some? next-iter) ^boolean (.hasNext next-iter)) + (if (< i len) + (let [node (aget arr i)] + (set! i (inc i)) + (when (some? node) + (set! next-iter (-iterator node))) + (recur)) + false) + true)))) + (next [this] + (if ^boolean (.hasNext this) + (.next next-iter) + (throw (js/Error. "No such element")))) + (remove [_] (js/Error. "Unsupported operation"))) + +(deftype ArrayNode [edit ^:mutable cnt ^:mutable arr] + Object + (inode-assoc [inode shift hash key val added-leaf?] + (let [idx (mask hash shift) + node (aget arr idx)] + (if (nil? node) + (ArrayNode. nil (inc cnt) (clone-and-set arr idx (.inode-assoc (.-EMPTY BitmapIndexedNode) (+ shift 5) hash key val added-leaf?))) + (let [n (.inode-assoc node (+ shift 5) hash key val added-leaf?)] + (if (identical? n node) + inode + (ArrayNode. nil cnt (clone-and-set arr idx n))))))) + + (inode-without [inode shift hash key] + (let [idx (mask hash shift) + node (aget arr idx)] + (if-not (nil? node) + (let [n (.inode-without node (+ shift 5) hash key)] + (cond + (identical? n node) + inode + + (nil? n) + (if (<= cnt 8) + (pack-array-node inode nil idx) + (ArrayNode. nil (dec cnt) (clone-and-set arr idx n))) + + :else + (ArrayNode. nil cnt (clone-and-set arr idx n)))) + inode))) + + (inode-lookup [inode shift hash key not-found] + (let [idx (mask hash shift) + node (aget arr idx)] + (if-not (nil? node) + (.inode-lookup node (+ shift 5) hash key not-found) + not-found))) + + (inode-find [inode shift hash key not-found] + (let [idx (mask hash shift) + node (aget arr idx)] + (if-not (nil? node) + (.inode-find node (+ shift 5) hash key not-found) + not-found))) + + (inode-seq [inode] + (create-array-node-seq arr)) + + (ensure-editable [inode e] + (if (identical? e edit) + inode + (ArrayNode. e cnt (aclone arr)))) + + (inode-assoc! [inode edit shift hash key val added-leaf?] + (let [idx (mask hash shift) + node (aget arr idx)] + (if (nil? node) + (let [editable (edit-and-set inode edit idx (.inode-assoc! (.-EMPTY BitmapIndexedNode) edit (+ shift 5) hash key val added-leaf?))] + (set! (.-cnt editable) (inc (.-cnt editable))) + editable) + (let [n (.inode-assoc! node edit (+ shift 5) hash key val added-leaf?)] + (if (identical? n node) + inode + (edit-and-set inode edit idx n)))))) + + (inode-without! [inode edit shift hash key removed-leaf?] + (let [idx (mask hash shift) + node (aget arr idx)] + (if (nil? node) + inode + (let [n (.inode-without! node edit (+ shift 5) hash key removed-leaf?)] + (cond + (identical? n node) + inode + + (nil? n) + (if (<= cnt 8) + (pack-array-node inode edit idx) + (let [editable (edit-and-set inode edit idx n)] + (set! (.-cnt editable) (dec (.-cnt editable))) + editable)) + + :else + (edit-and-set inode edit idx n)))))) + + (kv-reduce [inode f init] + (let [len (alength arr)] ; actually 32 + (loop [i 0 init init] + (if (< i len) + (let [node (aget arr i)] + (if-not (nil? node) + (let [init (.kv-reduce node f init)] + (if (reduced? init) + init + (recur (inc i) init))) + (recur (inc i) init))) + init)))) + + IIterable + (-iterator [coll] + (ArrayNodeIterator. arr 0 nil))) + +(defn- hash-collision-node-find-index [arr cnt key] + (let [lim (* 2 cnt)] + (loop [i 0] + (if (< i lim) + (if (key-test key (aget arr i)) + i + (recur (+ i 2))) + -1)))) + +(deftype HashCollisionNode [edit + ^:mutable collision-hash + ^:mutable cnt + ^:mutable arr] + Object + (inode-assoc [inode shift hash key val added-leaf?] + (if (== hash collision-hash) + (let [idx (hash-collision-node-find-index arr cnt key)] + (if (== idx -1) + (let [len (* 2 cnt) + new-arr (make-array (+ len 2))] + (array-copy arr 0 new-arr 0 len) + (aset new-arr len key) + (aset new-arr (inc len) val) + (set! (.-val added-leaf?) true) + (HashCollisionNode. nil collision-hash (inc cnt) new-arr)) + (if (= (aget arr (inc idx)) val) + inode + (HashCollisionNode. nil collision-hash cnt (clone-and-set arr (inc idx) val))))) + (.inode-assoc (BitmapIndexedNode. nil (bitpos collision-hash shift) (array nil inode)) + shift hash key val added-leaf?))) + + (inode-without [inode shift hash key] + (let [idx (hash-collision-node-find-index arr cnt key)] + (cond (== idx -1) inode + (== cnt 1) nil + :else (HashCollisionNode. nil collision-hash (dec cnt) (remove-pair arr (quot idx 2)))))) + + (inode-lookup [inode shift hash key not-found] + (let [idx (hash-collision-node-find-index arr cnt key)] + (cond (< idx 0) not-found + (key-test key (aget arr idx)) (aget arr (inc idx)) + :else not-found))) + + (inode-find [inode shift hash key not-found] + (let [idx (hash-collision-node-find-index arr cnt key)] + (cond (< idx 0) not-found + (key-test key (aget arr idx)) (MapEntry. (aget arr idx) (aget arr (inc idx)) nil) + :else not-found))) + + (inode-seq [inode] + (create-inode-seq arr)) + + (ensure-editable [inode e] + (if (identical? e edit) + inode + (let [new-arr (make-array (* 2 (inc cnt)))] + (array-copy arr 0 new-arr 0 (* 2 cnt)) + (HashCollisionNode. e collision-hash cnt new-arr)))) + + (ensure-editable-array [inode e count array] + (if (identical? e edit) + (do (set! arr array) + (set! cnt count) + inode) + (HashCollisionNode. edit collision-hash count array))) + + (inode-assoc! [inode edit shift hash key val added-leaf?] + (if (== hash collision-hash) + (let [idx (hash-collision-node-find-index arr cnt key)] + (if (== idx -1) + (if (> (alength arr) (* 2 cnt)) + (let [editable (edit-and-set inode edit (* 2 cnt) key (inc (* 2 cnt)) val)] + (set! (.-val added-leaf?) true) + (set! (.-cnt editable) (inc (.-cnt editable))) + editable) + (let [len (alength arr) + new-arr (make-array (+ len 2))] + (array-copy arr 0 new-arr 0 len) + (aset new-arr len key) + (aset new-arr (inc len) val) + (set! (.-val added-leaf?) true) + (.ensure-editable-array inode edit (inc cnt) new-arr))) + (if (identical? (aget arr (inc idx)) val) + inode + (edit-and-set inode edit (inc idx) val)))) + (.inode-assoc! (BitmapIndexedNode. edit (bitpos collision-hash shift) (array nil inode nil nil)) + edit shift hash key val added-leaf?))) + + (inode-without! [inode edit shift hash key removed-leaf?] + (let [idx (hash-collision-node-find-index arr cnt key)] + (if (== idx -1) + inode + (do (set! (.-val removed-leaf?) true) + (if (== cnt 1) + nil + (let [editable (.ensure-editable inode edit) + earr (.-arr editable)] + (aset earr idx (aget earr (- (* 2 cnt) 2))) + (aset earr (inc idx) (aget earr (dec (* 2 cnt)))) + (aset earr (dec (* 2 cnt)) nil) + (aset earr (- (* 2 cnt) 2) nil) + (set! (.-cnt editable) (dec (.-cnt editable))) + editable)))))) + + (kv-reduce [inode f init] + (inode-kv-reduce arr f init)) + + IIterable + (-iterator [coll] + (NodeIterator. arr 0 nil nil))) + +(defn- create-node + ([shift key1 val1 key2hash key2 val2] + (let [key1hash (hash key1)] + (if (== key1hash key2hash) + (HashCollisionNode. nil key1hash 2 (array key1 val1 key2 val2)) + (let [added-leaf? (Box. false)] + (-> (.-EMPTY BitmapIndexedNode) + (.inode-assoc shift key1hash key1 val1 added-leaf?) + (.inode-assoc shift key2hash key2 val2 added-leaf?)))))) + ([edit shift key1 val1 key2hash key2 val2] + (let [key1hash (hash key1)] + (if (== key1hash key2hash) + (HashCollisionNode. nil key1hash 2 (array key1 val1 key2 val2)) + (let [added-leaf? (Box. false)] + (-> (.-EMPTY BitmapIndexedNode) + (.inode-assoc! edit shift key1hash key1 val1 added-leaf?) + (.inode-assoc! edit shift key2hash key2 val2 added-leaf?))))))) + +(deftype NodeSeq [meta nodes i s ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IMeta + (-meta [coll] meta) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (NodeSeq. new-meta nodes i s __hash))) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + ISequential + ISeq + (-first [coll] + (if (nil? s) + (MapEntry. (aget nodes i) (aget nodes (inc i)) nil) + (first s))) + + (-rest [coll] + (let [ret (if (nil? s) + (create-inode-seq nodes (+ i 2) nil) + (create-inode-seq nodes i (next s)))] + (if-not (nil? ret) ret ()))) + + INext + (-next [coll] + (if (nil? s) + (create-inode-seq nodes (+ i 2) nil) + (create-inode-seq nodes i (next s)))) + + ISeqable + (-seq [this] this) + + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(es6-iterable NodeSeq) + +(defn- create-inode-seq + ([nodes] + (create-inode-seq nodes 0 nil)) + ([nodes i s] + (if (nil? s) + (let [len (alength nodes)] + (loop [j i] + (if (< j len) + (if-not (nil? (aget nodes j)) + (NodeSeq. nil nodes j nil nil) + (if-let [node (aget nodes (inc j))] + (if-let [node-seq (.inode-seq node)] + (NodeSeq. nil nodes (+ j 2) node-seq nil) + (recur (+ j 2))) + (recur (+ j 2))))))) + (NodeSeq. nil nodes i s nil)))) + +(deftype ArrayNodeSeq [meta nodes i s ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IMeta + (-meta [coll] meta) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (ArrayNodeSeq. new-meta nodes i s __hash))) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + ISequential + ISeq + (-first [coll] (first s)) + (-rest [coll] + (let [ret (create-array-node-seq nodes i (next s))] + (if-not (nil? ret) ret ()))) + + INext + (-next [coll] + (create-array-node-seq nodes i (next s))) + + ISeqable + (-seq [this] this) + + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(es6-iterable ArrayNodeSeq) + +(defn- create-array-node-seq + ([nodes] (create-array-node-seq nodes 0 nil)) + ([nodes i s] + (if (nil? s) + (let [len (alength nodes)] + (loop [j i] + (if (< j len) + (if-let [nj (aget nodes j)] + (if-let [ns (.inode-seq nj)] + (ArrayNodeSeq. nil nodes (inc j) ns nil) + (recur (inc j))) + (recur (inc j)))))) + (ArrayNodeSeq. nil nodes i s nil)))) + +(deftype HashMapIter [nil-val root-iter ^:mutable seen] + Object + (hasNext [_] + (or (not ^boolean seen) ^boolean (.hasNext root-iter))) + (next [_] + (if-not ^boolean seen + (do + (set! seen true) + (MapEntry. nil nil-val nil)) + (.next root-iter))) + (remove [_] (js/Error. "Unsupported operation"))) + +(deftype PersistentHashMap [meta cnt root ^boolean has-nil? nil-val ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + + ;; EXPERIMENTAL: subject to change + (keys [coll] + (es6-iterator (keys coll))) + (entries [coll] + (es6-entries-iterator (seq coll))) + (values [coll] + (es6-iterator (vals coll))) + (has [coll k] + (contains? coll k)) + (get [coll k not-found] + (-lookup coll k not-found)) + (forEach [coll f] + (doseq [[k v] coll] + (f v k))) + + ICloneable + (-clone [_] (PersistentHashMap. meta cnt root has-nil? nil-val __hash)) + + IIterable + (-iterator [coll] + (let [root-iter (if ^boolean root (-iterator root) (nil-iter))] + (if has-nil? + (HashMapIter. nil-val root-iter false) + root-iter))) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentHashMap. new-meta cnt root has-nil? nil-val __hash))) + + IMeta + (-meta [coll] meta) + + ICollection + (-conj [coll entry] + (if (vector? entry) + (-assoc coll (-nth entry 0) (-nth entry 1)) + (loop [ret coll es (seq entry)] + (if (nil? es) + ret + (let [e (first es)] + (if (vector? e) + (recur (-assoc ret (-nth e 0) (-nth e 1)) + (next es)) + (throw (js/Error. "conj on a map takes map entries or seqables of map entries")))))))) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY PersistentHashMap) meta)) + + IEquiv + (-equiv [coll other] (equiv-map coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-unordered-coll __hash)) + + ISeqable + (-seq [coll] + (when (pos? cnt) + (let [s (if-not (nil? root) (.inode-seq root))] + (if has-nil? + (cons (MapEntry. nil nil-val nil) s) + s)))) + + ICounted + (-count [coll] cnt) + + ILookup + (-lookup [coll k] + (-lookup coll k nil)) + + (-lookup [coll k not-found] + (cond (nil? k) (if has-nil? + nil-val + not-found) + (nil? root) not-found + :else (.inode-lookup root 0 (hash k) k not-found))) + + IAssociative + (-assoc [coll k v] + (if (nil? k) + (if (and has-nil? (identical? v nil-val)) + coll + (PersistentHashMap. meta (if has-nil? cnt (inc cnt)) root true v nil)) + (let [added-leaf? (Box. false) + new-root (-> (if (nil? root) + (.-EMPTY BitmapIndexedNode) + root) + (.inode-assoc 0 (hash k) k v added-leaf?))] + (if (identical? new-root root) + coll + (PersistentHashMap. meta (if ^boolean (.-val added-leaf?) (inc cnt) cnt) new-root has-nil? nil-val nil))))) + + (-contains-key? [coll k] + (cond (nil? k) has-nil? + (nil? root) false + :else (not (identical? (.inode-lookup root 0 (hash k) k lookup-sentinel) + lookup-sentinel)))) + + IFind + (-find [coll k] + (cond + (nil? k) (when has-nil? (MapEntry. nil nil-val nil)) + (nil? root) nil + :else (.inode-find root 0 (hash k) k nil))) + + IMap + (-dissoc [coll k] + (cond (nil? k) (if has-nil? + (PersistentHashMap. meta (dec cnt) root false nil nil) + coll) + (nil? root) coll + :else + (let [new-root (.inode-without root 0 (hash k) k)] + (if (identical? new-root root) + coll + (PersistentHashMap. meta (dec cnt) new-root has-nil? nil-val nil))))) + + IKVReduce + (-kv-reduce [coll f init] + (let [init (if has-nil? (f init nil nil-val) init)] + (cond + (reduced? init) @init + (not (nil? root)) (unreduced (.kv-reduce root f init)) + :else init))) + + IFn + (-invoke [coll k] + (-lookup coll k)) + + (-invoke [coll k not-found] + (-lookup coll k not-found)) + + IEditableCollection + (-as-transient [coll] + (TransientHashMap. (js-obj) root cnt has-nil? nil-val))) + +(set! (.-EMPTY PersistentHashMap) (PersistentHashMap. nil 0 nil false nil empty-unordered-hash)) + +(set! (.-fromArray PersistentHashMap) + (fn [arr ^boolean no-clone] + (let [arr (if no-clone arr (aclone arr)) + len (alength arr)] + (loop [i 0 ret (transient (.-EMPTY PersistentHashMap))] + (if (< i len) + (recur (+ i 2) + (-assoc! ret (aget arr i) (aget arr (inc i)))) + (-persistent! ret)))))) + +(set! (.-fromArrays PersistentHashMap) + (fn [ks vs] + (let [len (alength ks)] + (loop [i 0 ^not-native out (transient (.-EMPTY PersistentHashMap))] + (if (< i len) + (recur (inc i) (-assoc! out (aget ks i) (aget vs i))) + (persistent! out)))))) + +(set! (.-createWithCheck PersistentHashMap) + (fn [arr] + (let [len (alength arr) + ret (transient (.-EMPTY PersistentHashMap))] + (loop [i 0] + (when (< i len) + (-assoc! ret (aget arr i) (aget arr (inc i))) + (if (not= (-count ret) (inc (/ i 2))) + (throw (js/Error. (str "Duplicate key: " (aget arr i)))) + (recur (+ i 2))))) + (-persistent! ret)))) + +(es6-iterable PersistentHashMap) + +(deftype TransientHashMap [^:mutable ^boolean edit + ^:mutable root + ^:mutable count + ^:mutable ^boolean has-nil? + ^:mutable nil-val] + Object + (conj! [tcoll o] + (if edit + (cond + (map-entry? o) + (.assoc! tcoll (key o) (val o)) + + (vector? o) + (.assoc! tcoll (o 0) (o 1)) + + :else + (loop [es (seq o) tcoll tcoll] + (if-let [e (first es)] + (recur (next es) + (.assoc! tcoll (key e) (val e))) + tcoll))) + (throw (js/Error. "conj! after persistent")))) + + (assoc! [tcoll k v] + (if edit + (if (nil? k) + (do (if (identical? nil-val v) + nil + (set! nil-val v)) + (if has-nil? + nil + (do (set! count (inc count)) + (set! has-nil? true))) + tcoll) + (let [added-leaf? (Box. false) + node (-> (if (nil? root) + (.-EMPTY BitmapIndexedNode) + root) + (.inode-assoc! edit 0 (hash k) k v added-leaf?))] + (if (identical? node root) + nil + (set! root node)) + (if ^boolean (.-val added-leaf?) + (set! count (inc count))) + tcoll)) + (throw (js/Error. "assoc! after persistent!")))) + + (without! [tcoll k] + (if edit + (if (nil? k) + (if has-nil? + (do (set! has-nil? false) + (set! nil-val nil) + (set! count (dec count)) + tcoll) + tcoll) + (if (nil? root) + tcoll + (let [removed-leaf? (Box. false) + node (.inode-without! root edit 0 (hash k) k removed-leaf?)] + (if (identical? node root) + nil + (set! root node)) + (if ^boolean (.-val removed-leaf?) + (set! count (dec count))) + tcoll))) + (throw (js/Error. "dissoc! after persistent!")))) + + (persistent! [tcoll] + (if edit + (do (set! edit nil) + (PersistentHashMap. nil count root has-nil? nil-val nil)) + (throw (js/Error. "persistent! called twice")))) + + ICounted + (-count [coll] + (if edit + count + (throw (js/Error. "count after persistent!")))) + + ILookup + (-lookup [tcoll k] + (if (nil? k) + (if has-nil? + nil-val) + (if (nil? root) + nil + (.inode-lookup root 0 (hash k) k)))) + + (-lookup [tcoll k not-found] + (if (nil? k) + (if has-nil? + nil-val + not-found) + (if (nil? root) + not-found + (.inode-lookup root 0 (hash k) k not-found)))) + + ITransientCollection + (-conj! [tcoll val] (.conj! tcoll val)) + + (-persistent! [tcoll] (.persistent! tcoll)) + + ITransientAssociative + (-assoc! [tcoll key val] (.assoc! tcoll key val)) + + ITransientMap + (-dissoc! [tcoll key] (.without! tcoll key)) + + IFn + (-invoke [tcoll key] + (-lookup tcoll key)) + (-invoke [tcoll key not-found] + (-lookup tcoll key not-found))) + +;;; PersistentTreeMap + +(defn- tree-map-seq-push [node stack ^boolean ascending?] + (loop [t node stack stack] + (if-not (nil? t) + (recur (if ascending? (.-left t) (.-right t)) + (conj stack t)) + stack))) + +(deftype PersistentTreeMapSeq [meta stack ^boolean ascending? cnt ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + ISeqable + (-seq [this] this) + + ISequential + ISeq + (-first [this] (peek stack)) + (-rest [this] + (let [t (first stack) + next-stack (tree-map-seq-push (if ascending? (.-right t) (.-left t)) + (next stack) + ascending?)] + (if-not (nil? next-stack) + (PersistentTreeMapSeq. nil next-stack ascending? (dec cnt) nil) + ()))) + INext + (-next [this] + (let [t (first stack) + next-stack (tree-map-seq-push (if ascending? (.-right t) (.-left t)) + (next stack) + ascending?)] + (when-not (nil? next-stack) + (PersistentTreeMapSeq. nil next-stack ascending? (dec cnt) nil)))) + + ICounted + (-count [coll] + (if (neg? cnt) + (inc (count (next coll))) + cnt)) + + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + ICollection + (-conj [coll o] (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + IMeta + (-meta [coll] meta) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentTreeMapSeq. new-meta stack ascending? cnt __hash))) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(es6-iterable PersistentTreeMapSeq) + +(defn- create-tree-map-seq [tree ascending? cnt] + (PersistentTreeMapSeq. nil (tree-map-seq-push tree nil ascending?) ascending? cnt nil)) + +(declare RedNode BlackNode) + +(defn- balance-left [key val ins right] + (if (instance? RedNode ins) + (cond + (instance? RedNode (.-left ins)) + (RedNode. (.-key ins) (.-val ins) + (.blacken (.-left ins)) + (BlackNode. key val (.-right ins) right nil) + nil) + + (instance? RedNode (.-right ins)) + (RedNode. (.. ins -right -key) (.. ins -right -val) + (BlackNode. (.-key ins) (.-val ins) + (.-left ins) + (.. ins -right -left) + nil) + (BlackNode. key val + (.. ins -right -right) + right + nil) + nil) + + :else + (BlackNode. key val ins right nil)) + (BlackNode. key val ins right nil))) + +(defn- balance-right [key val left ins] + (if (instance? RedNode ins) + (cond + (instance? RedNode (.-right ins)) + (RedNode. (.-key ins) (.-val ins) + (BlackNode. key val left (.-left ins) nil) + (.blacken (.-right ins)) + nil) + + (instance? RedNode (.-left ins)) + (RedNode. (.. ins -left -key) (.. ins -left -val) + (BlackNode. key val left (.. ins -left -left) nil) + (BlackNode. (.-key ins) (.-val ins) + (.. ins -left -right) + (.-right ins) + nil) + nil) + + :else + (BlackNode. key val left ins nil)) + (BlackNode. key val left ins nil))) + +(defn- balance-left-del [key val del right] + (cond + (instance? RedNode del) + (RedNode. key val (.blacken del) right nil) + + (instance? BlackNode right) + (balance-right key val del (.redden right)) + + (and (instance? RedNode right) (instance? BlackNode (.-left right))) + (RedNode. (.. right -left -key) (.. right -left -val) + (BlackNode. key val del (.. right -left -left) nil) + (balance-right (.-key right) (.-val right) + (.. right -left -right) + (.redden (.-right right))) + nil) + + :else + (throw (js/Error. "red-black tree invariant violation")))) + +(defn- balance-right-del [key val left del] + (cond + (instance? RedNode del) + (RedNode. key val left (.blacken del) nil) + + (instance? BlackNode left) + (balance-left key val (.redden left) del) + + (and (instance? RedNode left) (instance? BlackNode (.-right left))) + (RedNode. (.. left -right -key) (.. left -right -val) + (balance-left (.-key left) (.-val left) + (.redden (.-left left)) + (.. left -right -left)) + (BlackNode. key val (.. left -right -right) del nil) + nil) + + :else + (throw (js/Error. "red-black tree invariant violation")))) + +(defn- tree-map-kv-reduce [node f init] + (let [init (if-not (nil? (.-left node)) + (tree-map-kv-reduce (.-left node) f init) + init)] + (if (reduced? init) + init + (let [init (f init (.-key node) (.-val node))] + (if (reduced? init) + init + (if-not (nil? (.-right node)) + (tree-map-kv-reduce (.-right node) f init) + init)))))) + +(deftype BlackNode [key val left right ^:mutable __hash] + Object + (add-left [node ins] + (.balance-left ins node)) + + (add-right [node ins] + (.balance-right ins node)) + + (remove-left [node del] + (balance-left-del key val del right)) + + (remove-right [node del] + (balance-right-del key val left del)) + + (blacken [node] node) + + (redden [node] (RedNode. key val left right nil)) + + (balance-left [node parent] + (BlackNode. (.-key parent) (.-val parent) node (.-right parent) nil)) + + (balance-right [node parent] + (BlackNode. (.-key parent) (.-val parent) (.-left parent) node nil)) + + (replace [node key val left right] + (BlackNode. key val left right nil)) + + (kv-reduce [node f init] + (tree-map-kv-reduce node f init)) + + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IMapEntry + (-key [node] key) + (-val [node] val) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IMeta + (-meta [node] nil) + + IWithMeta + (-with-meta [node meta] + (-with-meta [key val] meta)) + + IStack + (-peek [node] val) + + (-pop [node] [key]) + + ICollection + (-conj [node o] [key val o]) + + IEmptyableCollection + (-empty [node] nil) + + ISequential + ISeqable + (-seq [node] (IndexedSeq. #js [key val] 0 nil)) + + IReversible + (-rseq [node] (IndexedSeq. #js [val key] 0 nil)) + + ICounted + (-count [node] 2) + + IIndexed + (-nth [node n] + (cond (== n 0) key + (== n 1) val + :else (throw (js/Error. "Index out of bounds")))) + + (-nth [node n not-found] + (cond (== n 0) key + (== n 1) val + :else not-found)) + + ILookup + (-lookup [node k] (-nth node k nil)) + (-lookup [node k not-found] (-nth node k not-found)) + + IAssociative + (-assoc [node k v] + (assoc [key val] k v)) + (-contains-key? [node k] + (or (== k 0) (== k 1))) + + IFind + (-find [node k] + (case k + 0 (MapEntry. 0 key nil) + 1 (MapEntry. 1 val nil) + nil)) + + IVector + (-assoc-n [node n v] + (-assoc-n [key val] n v)) + + IReduce + (-reduce [node f] + (ci-reduce node f)) + + (-reduce [node f start] + (ci-reduce node f start)) + + IFn + (-invoke [node k] + (-nth node k)) + + (-invoke [node k not-found] + (-nth node k not-found))) + +(es6-iterable BlackNode) + +(deftype RedNode [key val left right ^:mutable __hash] + Object + (add-left [node ins] + (RedNode. key val ins right nil)) + + (add-right [node ins] + (RedNode. key val left ins nil)) + + (remove-left [node del] + (RedNode. key val del right nil)) + + (remove-right [node del] + (RedNode. key val left del nil)) + + (blacken [node] + (BlackNode. key val left right nil)) + + (redden [node] + (throw (js/Error. "red-black tree invariant violation"))) + + (balance-left [node parent] + (cond + (instance? RedNode left) + (RedNode. key val + (.blacken left) + (BlackNode. (.-key parent) (.-val parent) right (.-right parent) nil) + nil) + + (instance? RedNode right) + (RedNode. (.-key right) (.-val right) + (BlackNode. key val left (.-left right) nil) + (BlackNode. (.-key parent) (.-val parent) + (.-right right) + (.-right parent) + nil) + nil) + + :else + (BlackNode. (.-key parent) (.-val parent) node (.-right parent) nil))) + + (balance-right [node parent] + (cond + (instance? RedNode right) + (RedNode. key val + (BlackNode. (.-key parent) (.-val parent) + (.-left parent) + left + nil) + (.blacken right) + nil) + + (instance? RedNode left) + (RedNode. (.-key left) (.-val left) + (BlackNode. (.-key parent) (.-val parent) + (.-left parent) + (.-left left) + nil) + (BlackNode. key val (.-right left) right nil) + nil) + + :else + (BlackNode. (.-key parent) (.-val parent) (.-left parent) node nil))) + + (replace [node key val left right] + (RedNode. key val left right nil)) + + (kv-reduce [node f init] + (tree-map-kv-reduce node f init)) + + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IMapEntry + (-key [node] key) + (-val [node] val) + + IHash + (-hash [coll] (caching-hash coll hash-ordered-coll __hash)) + + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + IMeta + (-meta [node] nil) + + IWithMeta + (-with-meta [node meta] + (-with-meta [key val] meta)) + + IStack + (-peek [node] val) + + (-pop [node] [key]) + + ICollection + (-conj [node o] [key val o]) + + IEmptyableCollection + (-empty [node] nil) + + ISequential + ISeqable + (-seq [node] (IndexedSeq. #js [key val] 0 nil)) + + IReversible + (-rseq [node] (IndexedSeq. #js [val key] 0 nil)) + + ICounted + (-count [node] 2) + + IIndexed + (-nth [node n] + (cond (== n 0) key + (== n 1) val + :else (throw (js/Error. "Index out of bounds")))) + + (-nth [node n not-found] + (cond (== n 0) key + (== n 1) val + :else not-found)) + + ILookup + (-lookup [node k] (-nth node k nil)) + (-lookup [node k not-found] (-nth node k not-found)) + + IAssociative + (-assoc [node k v] + (assoc [key val] k v)) + (-contains-key? [node k] + (or (== k 0) (== k 1))) + + IFind + (-find [node k] + (case k + 0 (MapEntry. 0 key nil) + 1 (MapEntry. 1 val nil) + nil)) + + IVector + (-assoc-n [node n v] + (-assoc-n [key val] n v)) + + IReduce + (-reduce [node f] + (ci-reduce node f)) + + (-reduce [node f start] + (ci-reduce node f start)) + + IFn + (-invoke [node k] + (-nth node k)) + + (-invoke [node k not-found] + (-nth node k not-found))) + +(es6-iterable RedNode) + +(defn- tree-map-add [comp tree k v found] + (if (nil? tree) + (RedNode. k v nil nil nil) + (let [c (comp k (.-key tree))] + (cond + (zero? c) + (do (aset found 0 tree) + nil) + + (neg? c) + (let [ins (tree-map-add comp (.-left tree) k v found)] + (if-not (nil? ins) + (.add-left tree ins))) + + :else + (let [ins (tree-map-add comp (.-right tree) k v found)] + (if-not (nil? ins) + (.add-right tree ins))))))) + +(defn- tree-map-append [left right] + (cond + (nil? left) + right + + (nil? right) + left + + (instance? RedNode left) + (if (instance? RedNode right) + (let [app (tree-map-append (.-right left) (.-left right))] + (if (instance? RedNode app) + (RedNode. (.-key app) (.-val app) + (RedNode. (.-key left) (.-val left) + (.-left left) + (.-left app) + nil) + (RedNode. (.-key right) (.-val right) + (.-right app) + (.-right right) + nil) + nil) + (RedNode. (.-key left) (.-val left) + (.-left left) + (RedNode. (.-key right) (.-val right) app (.-right right) nil) + nil))) + (RedNode. (.-key left) (.-val left) + (.-left left) + (tree-map-append (.-right left) right) + nil)) + + (instance? RedNode right) + (RedNode. (.-key right) (.-val right) + (tree-map-append left (.-left right)) + (.-right right) + nil) + + :else + (let [app (tree-map-append (.-right left) (.-left right))] + (if (instance? RedNode app) + (RedNode. (.-key app) (.-val app) + (BlackNode. (.-key left) (.-val left) + (.-left left) + (.-left app) + nil) + (BlackNode. (.-key right) (.-val right) + (.-right app) + (.-right right) + nil) + nil) + (balance-left-del (.-key left) (.-val left) + (.-left left) + (BlackNode. (.-key right) (.-val right) + app + (.-right right) + nil)))))) + +(defn- tree-map-remove [comp tree k found] + (if-not (nil? tree) + (let [c (comp k (.-key tree))] + (cond + (zero? c) + (do (aset found 0 tree) + (tree-map-append (.-left tree) (.-right tree))) + + (neg? c) + (let [del (tree-map-remove comp (.-left tree) k found)] + (if (or (not (nil? del)) (not (nil? (aget found 0)))) + (if (instance? BlackNode (.-left tree)) + (balance-left-del (.-key tree) (.-val tree) del (.-right tree)) + (RedNode. (.-key tree) (.-val tree) del (.-right tree) nil)))) + + :else + (let [del (tree-map-remove comp (.-right tree) k found)] + (if (or (not (nil? del)) (not (nil? (aget found 0)))) + (if (instance? BlackNode (.-right tree)) + (balance-right-del (.-key tree) (.-val tree) (.-left tree) del) + (RedNode. (.-key tree) (.-val tree) (.-left tree) del nil)))))))) + +(defn- tree-map-replace [comp tree k v] + (let [tk (.-key tree) + c (comp k tk)] + (cond (zero? c) (.replace tree tk v (.-left tree) (.-right tree)) + (neg? c) (.replace tree tk (.-val tree) (tree-map-replace comp (.-left tree) k v) (.-right tree)) + :else (.replace tree tk (.-val tree) (.-left tree) (tree-map-replace comp (.-right tree) k v))))) + +(declare key) + +(deftype PersistentTreeMap [comp tree cnt meta ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + + ;; EXPERIMENTAL: subject to change + (keys [coll] + (es6-iterator (keys coll))) + (entries [coll] + (es6-entries-iterator (seq coll))) + (values [coll] + (es6-iterator (vals coll))) + (has [coll k] + (contains? coll k)) + (get [coll k not-found] + (-lookup coll k not-found)) + (forEach [coll f] + (doseq [[k v] coll] + (f v k))) + + (entry-at [coll k] + (loop [t tree] + (if-not (nil? t) + (let [c (comp k (.-key t))] + (cond (zero? c) t + (neg? c) (recur (.-left t)) + :else (recur (.-right t))))))) + + ICloneable + (-clone [_] (PersistentTreeMap. comp tree cnt meta __hash)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentTreeMap. comp tree cnt new-meta __hash))) + + IMeta + (-meta [coll] meta) + + ICollection + (-conj [coll entry] + (if (vector? entry) + (-assoc coll (-nth entry 0) (-nth entry 1)) + (loop [ret coll es (seq entry)] + (if (nil? es) + ret + (let [e (first es)] + (if (vector? e) + (recur (-assoc ret (-nth e 0) (-nth e 1)) + (next es)) + (throw (js/Error. "conj on a map takes map entries or seqables of map entries")))))))) + + IEmptyableCollection + (-empty [coll] (PersistentTreeMap. comp nil 0 meta 0)) + + IEquiv + (-equiv [coll other] (equiv-map coll other)) + + IHash + (-hash [coll] (caching-hash coll hash-unordered-coll __hash)) + + ICounted + (-count [coll] cnt) + + IKVReduce + (-kv-reduce [coll f init] + (if-not (nil? tree) + (unreduced (tree-map-kv-reduce tree f init)) + init)) + + IFn + (-invoke [coll k] + (-lookup coll k)) + + (-invoke [coll k not-found] + (-lookup coll k not-found)) + + ISeqable + (-seq [coll] + (if (pos? cnt) + (create-tree-map-seq tree true cnt))) + + IReversible + (-rseq [coll] + (if (pos? cnt) + (create-tree-map-seq tree false cnt))) + + ILookup + (-lookup [coll k] + (-lookup coll k nil)) + + (-lookup [coll k not-found] + (let [n (.entry-at coll k)] + (if-not (nil? n) + (.-val n) + not-found))) + + IAssociative + (-assoc [coll k v] + (let [found (array nil) + t (tree-map-add comp tree k v found)] + (if (nil? t) + (let [found-node (nth found 0)] + (if (= v (.-val found-node)) + coll + (PersistentTreeMap. comp (tree-map-replace comp tree k v) cnt meta nil))) + (PersistentTreeMap. comp (.blacken t) (inc cnt) meta nil)))) + + (-contains-key? [coll k] + (not (nil? (.entry-at coll k)))) + + IFind + (-find [coll k] + (.entry-at coll k)) + + IMap + (-dissoc [coll k] + (let [found (array nil) + t (tree-map-remove comp tree k found)] + (if (nil? t) + (if (nil? (nth found 0)) + coll + (PersistentTreeMap. comp nil 0 meta nil)) + (PersistentTreeMap. comp (.blacken t) (dec cnt) meta nil)))) + + ISorted + (-sorted-seq [coll ascending?] + (if (pos? cnt) + (create-tree-map-seq tree ascending? cnt))) + + (-sorted-seq-from [coll k ascending?] + (if (pos? cnt) + (loop [stack nil t tree] + (if-not (nil? t) + (let [c (comp k (.-key t))] + (cond + (zero? c) (PersistentTreeMapSeq. nil (conj stack t) ascending? -1 nil) + ascending? (if (neg? c) + (recur (conj stack t) (.-left t)) + (recur stack (.-right t))) + :else (if (pos? c) + (recur (conj stack t) (.-right t)) + (recur stack (.-left t))))) + (when-not (nil? stack) + (PersistentTreeMapSeq. nil stack ascending? -1 nil)))))) + + (-entry-key [coll entry] (key entry)) + + (-comparator [coll] comp)) + +(set! (.-EMPTY PersistentTreeMap) (PersistentTreeMap. compare nil 0 nil empty-unordered-hash)) + +(es6-iterable PersistentTreeMap) + +(defn hash-map + "keyval => key val + Returns a new hash map with supplied mappings." + [& keyvals] + (loop [in (seq keyvals), out (transient (.-EMPTY PersistentHashMap))] + (if in + (recur (nnext in) (assoc! out (first in) (second in))) + (persistent! out)))) + +(defn array-map + "keyval => key val + Returns a new array map with supplied mappings." + [& keyvals] + (let [arr (if (and (instance? IndexedSeq keyvals) (zero? (.-i keyvals))) + (.-arr keyvals) + (into-array keyvals))] + (.createAsIfByAssoc PersistentArrayMap arr))) + +(defn obj-map + "keyval => key val + Returns a new object map with supplied mappings." + [& keyvals] + (let [ks (array) + obj (js-obj)] + (loop [kvs (seq keyvals)] + (if kvs + (do (.push ks (first kvs)) + (gobject/set obj (first kvs) (second kvs)) + (recur (nnext kvs))) + (.fromObject ObjMap ks obj))))) + +(defn sorted-map + "keyval => key val + Returns a new sorted map with supplied mappings." + ([& keyvals] + (loop [in (seq keyvals) out (.-EMPTY PersistentTreeMap)] + (if in + (recur (nnext in) (assoc out (first in) (second in))) + out)))) + +(defn sorted-map-by + "keyval => key val + Returns a new sorted map with supplied mappings, using the supplied comparator." + ([comparator & keyvals] + (loop [in (seq keyvals) + out (PersistentTreeMap. (fn->comparator comparator) nil 0 nil 0)] + (if in + (recur (nnext in) (assoc out (first in) (second in))) + out)))) + +(deftype KeySeq [^not-native mseq _meta] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IMeta + (-meta [coll] _meta) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta _meta) + coll + (KeySeq. mseq new-meta))) + + ISeqable + (-seq [coll] coll) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + ICollection + (-conj [coll o] + (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + IHash + (-hash [coll] (hash-ordered-coll coll)) + + ISeq + (-first [coll] + (let [^not-native me (-first mseq)] + (-key me))) + + (-rest [coll] + (let [nseq (if (satisfies? INext mseq) + (-next mseq) + (next mseq))] + (if-not (nil? nseq) + (KeySeq. nseq nil) + ()))) + + INext + (-next [coll] + (let [nseq (if (satisfies? INext mseq) + (-next mseq) + (next mseq))] + (when-not (nil? nseq) + (KeySeq. nseq nil)))) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(es6-iterable KeySeq) + +(defn keys + "Returns a sequence of the map's keys, in the same order as (seq map)." + [map] + (when-let [mseq (seq map)] + (KeySeq. mseq nil))) + +(defn key + "Returns the key of the map entry." + [map-entry] + (-key map-entry)) + +(deftype ValSeq [^not-native mseq _meta] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + IMeta + (-meta [coll] _meta) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta _meta) + coll + (ValSeq. mseq new-meta))) + + ISeqable + (-seq [coll] coll) + + ISequential + IEquiv + (-equiv [coll other] (equiv-sequential coll other)) + + ICollection + (-conj [coll o] + (cons o coll)) + + IEmptyableCollection + (-empty [coll] (.-EMPTY List)) + + IHash + (-hash [coll] (hash-ordered-coll coll)) + + ISeq + (-first [coll] + (let [^not-native me (-first mseq)] + (-val me))) + + (-rest [coll] + (let [nseq (if (satisfies? INext mseq) + (-next mseq) + (next mseq))] + (if-not (nil? nseq) + (ValSeq. nseq nil) + ()))) + + INext + (-next [coll] + (let [nseq (if (satisfies? INext mseq) + (-next mseq) + (next mseq))] + (when-not (nil? nseq) + (ValSeq. nseq nil)))) + + IReduce + (-reduce [coll f] (seq-reduce f coll)) + (-reduce [coll f start] (seq-reduce f start coll))) + +(es6-iterable ValSeq) + +(defn vals + "Returns a sequence of the map's values, in the same order as (seq map)." + [map] + (when-let [mseq (seq map)] + (ValSeq. mseq nil))) + +(defn val + "Returns the value in the map entry." + [map-entry] + (-val map-entry)) + +(defn merge + "Returns a map that consists of the rest of the maps conj-ed onto + the first. If a key occurs in more than one map, the mapping from + the latter (left-to-right) will be the mapping in the result." + [& maps] + (when (some identity maps) + (reduce #(conj (or %1 {}) %2) maps))) + +(defn merge-with + "Returns a map that consists of the rest of the maps conj-ed onto + the first. If a key occurs in more than one map, the mapping(s) + from the latter (left-to-right) will be combined with the mapping in + the result by calling (f val-in-result val-in-latter)." + [f & maps] + (when (some identity maps) + (let [merge-entry (fn [m e] + (let [k (key e) v (val e)] + (if (contains? m k) + (assoc m k (f (get m k) v)) + (assoc m k v)))) + merge2 (fn [m1 m2] + (reduce merge-entry (or m1 {}) (seq m2)))] + (reduce merge2 maps)))) + +(defn select-keys + "Returns a map containing only those entries in map whose key is in keys" + [map keyseq] + (loop [ret {} keys (seq keyseq)] + (if keys + (let [key (first keys) + entry (get map key ::not-found)] + (recur + (if (not= entry ::not-found) + (assoc ret key entry) + ret) + (next keys))) + (-with-meta ret (meta map))))) + +;;; PersistentHashSet + +(declare TransientHashSet) + +(deftype HashSetIter [iter] + Object + (hasNext [_] + (.hasNext iter)) + (next [_] + (if ^boolean (.hasNext iter) + (.-key (.next iter)) + (throw (js/Error. "No such element")))) + (remove [_] (js/Error. "Unsupported operation"))) + +(deftype PersistentHashSet [meta hash-map ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + + ;; EXPERIMENTAL: subject to change + (keys [coll] + (es6-iterator (seq coll))) + (entries [coll] + (es6-set-entries-iterator (seq coll))) + (values [coll] + (es6-iterator (seq coll))) + (has [coll k] + (contains? coll k)) + (forEach [coll f] + (doseq [[k v] coll] + (f v k))) + + ICloneable + (-clone [_] (PersistentHashSet. meta hash-map __hash)) + + IIterable + (-iterator [coll] + (HashSetIter. (-iterator hash-map))) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentHashSet. new-meta hash-map __hash))) + + IMeta + (-meta [coll] meta) + + ICollection + (-conj [coll o] + (PersistentHashSet. meta (assoc hash-map o nil) nil)) + + IEmptyableCollection + (-empty [coll] (-with-meta (.-EMPTY PersistentHashSet) meta)) + + IEquiv + (-equiv [coll other] + (and + (set? other) + (== (count coll) (count other)) + ^boolean + (try + (reduce-kv + #(or (contains? other %2) (reduced false)) + true hash-map) + (catch js/Error ex + false)))) + + IHash + (-hash [coll] (caching-hash coll hash-unordered-coll __hash)) + + ISeqable + (-seq [coll] (keys hash-map)) + + ICounted + (-count [coll] (-count hash-map)) + + ILookup + (-lookup [coll v] + (-lookup coll v nil)) + (-lookup [coll v not-found] + (if-let [entry (-find hash-map v)] + (key entry) + not-found)) + + ISet + (-disjoin [coll v] + (PersistentHashSet. meta (-dissoc hash-map v) nil)) + + IFn + (-invoke [coll k] + (-lookup coll k)) + (-invoke [coll k not-found] + (-lookup coll k not-found)) + + IEditableCollection + (-as-transient [coll] (TransientHashSet. (-as-transient hash-map)))) + +(set! (.-EMPTY PersistentHashSet) + (PersistentHashSet. nil (.-EMPTY PersistentArrayMap) empty-unordered-hash)) + +(set! (.-fromArray PersistentHashSet) + (fn [items ^boolean no-clone] + (let [len (alength items)] + (if (<= len (.-HASHMAP-THRESHOLD PersistentArrayMap)) + (let [arr (if no-clone items (aclone items))] + (loop [i 0 + out (transient (.-EMPTY PersistentArrayMap))] + (if (< i len) + (recur (inc i) (-assoc! out (aget items i) nil)) + (PersistentHashSet. nil (-persistent! out) nil)))) + (loop [i 0 + out (transient (.-EMPTY PersistentHashSet))] + (if (< i len) + (recur (inc i) (-conj! out (aget items i))) + (-persistent! out))))))) + +(set! (.-createWithCheck PersistentHashSet) + (fn [items] + (let [len (alength items) + t (-as-transient (.-EMPTY PersistentHashSet))] + (dotimes [i len] + (-conj! t (aget items i)) + (when-not (= (count t) (inc i)) + (throw (js/Error. (str "Duplicate key: " (aget items i)))))) + (-persistent! t)))) + +(set! (.-createAsIfByAssoc PersistentHashSet) + (fn [items] + (let [len (alength items) + t (-as-transient (.-EMPTY PersistentHashSet))] + (dotimes [i len] (-conj! t (aget items i))) + (-persistent! t)))) + +(es6-iterable PersistentHashSet) + +(deftype TransientHashSet [^:mutable transient-map] + ITransientCollection + (-conj! [tcoll o] + (set! transient-map (assoc! transient-map o nil)) + tcoll) + + (-persistent! [tcoll] + (PersistentHashSet. nil (persistent! transient-map) nil)) + + ITransientSet + (-disjoin! [tcoll v] + (set! transient-map (dissoc! transient-map v)) + tcoll) + + ICounted + (-count [tcoll] (count transient-map)) + + ILookup + (-lookup [tcoll v] + (-lookup tcoll v nil)) + + (-lookup [tcoll v not-found] + (if (identical? (-lookup transient-map v lookup-sentinel) lookup-sentinel) + not-found + v)) + + IFn + (-invoke [tcoll k] + (if (identical? (-lookup transient-map k lookup-sentinel) lookup-sentinel) + nil + k)) + + (-invoke [tcoll k not-found] + (if (identical? (-lookup transient-map k lookup-sentinel) lookup-sentinel) + not-found + k))) + +(deftype PersistentTreeSet [meta tree-map ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + + ;; EXPERIMENTAL: subject to change + (keys [coll] + (es6-iterator (seq coll))) + (entries [coll] + (es6-set-entries-iterator (seq coll))) + (values [coll] + (es6-iterator (seq coll))) + (has [coll k] + (contains? coll k)) + (forEach [coll f] + (doseq [[k v] coll] + (f v k))) + + ICloneable + (-clone [_] (PersistentTreeSet. meta tree-map __hash)) + + IWithMeta + (-with-meta [coll new-meta] + (if (identical? new-meta meta) + coll + (PersistentTreeSet. new-meta tree-map __hash))) + + IMeta + (-meta [coll] meta) + + ICollection + (-conj [coll o] + (PersistentTreeSet. meta (assoc tree-map o nil) nil)) + + IEmptyableCollection + (-empty [coll] (PersistentTreeSet. meta (-empty tree-map) 0)) + + IEquiv + (-equiv [coll other] + (and + (set? other) + (== (count coll) (count other)) + ^boolean + (try + (reduce-kv + #(or (contains? other %2) (reduced false)) + true tree-map) + (catch js/Error ex + false)))) + + IHash + (-hash [coll] (caching-hash coll hash-unordered-coll __hash)) + + ISeqable + (-seq [coll] (keys tree-map)) + + ISorted + (-sorted-seq [coll ascending?] + (map key (-sorted-seq tree-map ascending?))) + + (-sorted-seq-from [coll k ascending?] + (map key (-sorted-seq-from tree-map k ascending?))) + + (-entry-key [coll entry] entry) + + (-comparator [coll] (-comparator tree-map)) + + IReversible + (-rseq [coll] + (if (pos? (count tree-map)) + (map key (rseq tree-map)))) + + ICounted + (-count [coll] (count tree-map)) + + ILookup + (-lookup [coll v] + (-lookup coll v nil)) + (-lookup [coll v not-found] + (let [n (.entry-at tree-map v)] + (if-not (nil? n) + (.-key n) + not-found))) + + ISet + (-disjoin [coll v] + (PersistentTreeSet. meta (dissoc tree-map v) nil)) + + IFn + (-invoke [coll k] + (-lookup coll k)) + (-invoke [coll k not-found] + (-lookup coll k not-found))) + +(set! (.-EMPTY PersistentTreeSet) + (PersistentTreeSet. nil (.-EMPTY PersistentTreeMap) empty-unordered-hash)) + +(es6-iterable PersistentTreeSet) + +(defn set-from-indexed-seq [iseq] + (let [arr (.-arr iseq) + ret (areduce arr i ^not-native res (-as-transient #{}) + (-conj! res (aget arr i)))] + (-persistent! ^not-native ret))) + +(defn set + "Returns a set of the distinct elements of coll." + [coll] + (if (set? coll) + (with-meta coll nil) + (let [in (seq coll)] + (cond + (nil? in) #{} + + (and (instance? IndexedSeq in) (zero? (.-i in))) + (.createAsIfByAssoc PersistentHashSet (.-arr in)) + + :else + (loop [^not-native in in + ^not-native out (-as-transient #{})] + (if-not (nil? in) + (recur (next in) (-conj! out (-first in))) + (persistent! out))))))) + +(defn hash-set + "Returns a new hash set with supplied keys. Any equal keys are + handled as if by repeated uses of conj." + ([] #{}) + ([& keys] (set keys))) + +(defn sorted-set + "Returns a new sorted set with supplied keys." + ([& keys] + (reduce -conj (.-EMPTY PersistentTreeSet) keys))) + +(defn sorted-set-by + "Returns a new sorted set with supplied keys, using the supplied comparator." + ([comparator & keys] + (reduce -conj + (PersistentTreeSet. nil (sorted-map-by comparator) 0) + keys))) + +(defn replace + "Given a map of replacement pairs and a vector/collection, returns a + vector/seq with any elements = a key in smap replaced with the + corresponding val in smap. Returns a transducer when no collection + is provided." + ([smap] + (map #(if-let [e (find smap %)] (val e) %))) + ([smap coll] + (if (vector? coll) + (let [n (count coll)] + (reduce (fn [v i] + (if-let [e (find smap (nth v i))] + (assoc v i (second e)) + v)) + coll (take n (iterate inc 0)))) + (map #(if-let [e (find smap %)] (second e) %) coll)))) + +(defn distinct + "Returns a lazy sequence of the elements of coll with duplicates removed. + Returns a stateful transducer when no collection is provided." + ([] + (fn [rf] + (let [seen (volatile! #{})] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (if (contains? @seen input) + result + (do (vswap! seen conj input) + (rf result input)))))))) + ([coll] + (let [step (fn step [xs seen] + (lazy-seq + ((fn [[f :as xs] seen] + (when-let [s (seq xs)] + (if (contains? seen f) + (recur (rest s) seen) + (cons f (step (rest s) (conj seen f)))))) + xs seen)))] + (step coll #{})))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defn butlast + "Return a seq of all but the last item in coll, in linear time" + [s] + (loop [ret [] s s] + (if (next s) + (recur (conj ret (first s)) (next s)) + (seq ret)))) + +(defn name + "Returns the name String of a string, symbol or keyword." + [x] + (if (implements? INamed x) + (-name x) + (if (string? x) + x + (throw (js/Error. (str "Doesn't support name: " x)))))) + +(defn zipmap + "Returns a map with the keys mapped to the corresponding vals." + [keys vals] + (loop [map (transient {}) + ks (seq keys) + vs (seq vals)] + (if (and ks vs) + (recur (assoc! map (first ks) (first vs)) + (next ks) + (next vs)) + (persistent! map)))) + +(defn max-key + "Returns the x for which (k x), a number, is greatest. + + If there are multiple such xs, the last one is returned." + ([k x] x) + ([k x y] (if (> (k x) (k y)) x y)) + ([k x y & more] + (reduce #(max-key k %1 %2) (max-key k x y) more))) + +(defn min-key + "Returns the x for which (k x), a number, is least. + + If there are multiple such xs, the last one is returned." + ([k x] x) + ([k x y] (if (< (k x) (k y)) x y)) + ([k x y & more] + (reduce #(min-key k %1 %2) (min-key k x y) more))) + +(deftype ArrayList [^:mutable arr] + Object + (add [_ x] (.push arr x)) + (size [_] (alength arr)) + (clear [_] (set! arr (array))) + (isEmpty [_] (zero? (alength arr))) + (toArray [_] arr)) + +(defn array-list [] + (ArrayList. (array))) + +(defn partition-all + "Returns a lazy sequence of lists like partition, but may include + partitions with fewer than n items at the end. Returns a stateful + transducer when no collection is provided." + ([n] + (fn [rf] + (let [a (array-list)] + (fn + ([] (rf)) + ([result] + (let [result (if (.isEmpty a) + result + (let [v (vec (.toArray a))] + ;;clear first! + (.clear a) + (unreduced (rf result v))))] + (rf result))) + ([result input] + (.add a input) + (if (== n (.size a)) + (let [v (vec (.toArray a))] + (.clear a) + (rf result v)) + result)))))) + ([n coll] + (partition-all n n coll)) + ([n step coll] + (lazy-seq + (when-let [s (seq coll)] + (cons (take n s) (partition-all n step (drop step s))))))) + +(defn take-while + "Returns a lazy sequence of successive items from coll while + (pred item) returns logical true. pred must be free of side-effects. + Returns a transducer when no collection is provided." + ([pred] + (fn [rf] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (if (pred input) + (rf result input) + (reduced result)))))) + ([pred coll] + (lazy-seq + (when-let [s (seq coll)] + (when (pred (first s)) + (cons (first s) (take-while pred (rest s)))))))) + +(defn mk-bound-fn + [sc test key] + (fn [e] + (let [comp (-comparator sc)] + (test (comp (-entry-key sc e) key) 0)))) + +(defn subseq + "sc must be a sorted collection, test(s) one of <, <=, > or + >=. Returns a seq of those entries with keys ek for + which (test (.. sc comparator (compare ek key)) 0) is true" + ([sc test key] + (let [include (mk-bound-fn sc test key)] + (if (#{> >=} test) + (when-let [[e :as s] (-sorted-seq-from sc key true)] + (if (include e) s (next s))) + (take-while include (-sorted-seq sc true))))) + ([sc start-test start-key end-test end-key] + (when-let [[e :as s] (-sorted-seq-from sc start-key true)] + (take-while (mk-bound-fn sc end-test end-key) + (if ((mk-bound-fn sc start-test start-key) e) s (next s)))))) + +(defn rsubseq + "sc must be a sorted collection, test(s) one of <, <=, > or + >=. Returns a reverse seq of those entries with keys ek for + which (test (.. sc comparator (compare ek key)) 0) is true" + ([sc test key] + (let [include (mk-bound-fn sc test key)] + (if (#{< <=} test) + (when-let [[e :as s] (-sorted-seq-from sc key false)] + (if (include e) s (next s))) + (take-while include (-sorted-seq sc false))))) + ([sc start-test start-key end-test end-key] + (when-let [[e :as s] (-sorted-seq-from sc end-key false)] + (take-while (mk-bound-fn sc start-test start-key) + (if ((mk-bound-fn sc end-test end-key) e) s (next s)))))) + +(deftype RangeChunk [start step count] + ICounted + (-count [coll] count) + + ISeq + (-first [coll] start) + + IIndexed + (-nth [coll i] + (+ start (* i step))) + (-nth [coll i not-found] + (if (and (>= i 0) (< i count)) + (+ start (* i step)) + not-found)) + + IChunk + (-drop-first [coll] + (if (<= count 1) + (throw (js/Error. "-drop-first of empty chunk")) + (RangeChunk. (+ start step) step (dec count))))) + +(deftype RangeIterator [^:mutable i end step] + Object + (hasNext [_] + (if (pos? step) + (< i end) + (> i end))) + (next [_] + (let [ret i] + (set! i (+ i step)) + ret))) + +(deftype Range [meta start end step ^:mutable chunk ^:mutable chunk-next ^:mutable __hash] + Object + (toString [coll] + (pr-str* coll)) + (equiv [this other] + (-equiv this other)) + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + (forceChunk [coll] + (when (nil? chunk) + (let [count (-count coll)] + (if (> count 32) + (do + (set! chunk-next (Range. nil (+ start (* step 32)) end step nil nil nil)) + (set! chunk (RangeChunk. start step 32))) + (set! chunk (RangeChunk. start step count)))))) + + ICloneable + (-clone [_] (Range. meta start end step chunk chunk-next __hash)) + + IWithMeta + (-with-meta [rng new-meta] + (if (identical? new-meta meta) + rng + (Range. new-meta start end step chunk chunk-next __hash))) + + IMeta + (-meta [rng] meta) + + ISeqable + (-seq [rng] rng) + + ISeq + (-first [rng] start) + (-rest [rng] + (let [s (-next rng)] + (if (nil? s) + () + s))) + + IIterable + (-iterator [_] + (RangeIterator. start end step)) + + INext + (-next [rng] + (if (pos? step) + (when (< (+ start step) end) + (Range. nil (+ start step) end step nil nil nil)) + (when (> (+ start step) end) + (Range. nil (+ start step) end step nil nil nil)))) + + IChunkedSeq + (-chunked-first [rng] + (.forceChunk rng) + chunk) + (-chunked-rest [rng] + (.forceChunk rng) + (if (nil? chunk-next) + () + chunk-next)) + + IChunkedNext + (-chunked-next [rng] + (seq (-chunked-rest rng))) + + ICollection + (-conj [rng o] (cons o rng)) + + IEmptyableCollection + (-empty [rng] (.-EMPTY List)) + + ISequential + IEquiv + (-equiv [rng other] (equiv-sequential rng other)) + + IHash + (-hash [rng] (caching-hash rng hash-ordered-coll __hash)) + + ICounted + (-count [rng] + (Math/ceil (/ (- end start) step))) + + IIndexed + (-nth [rng n] + (if (and (<= 0 n) (< n (-count rng))) + (+ start (* n step)) + (if (and (<= 0 n) (> start end) (zero? step)) + start + (throw (js/Error. "Index out of bounds"))))) + (-nth [rng n not-found] + (if (and (<= 0 n) (< n (-count rng))) + (+ start (* n step)) + (if (and (<= 0 n) (> start end) (zero? step)) + start + not-found))) + + IReduce + (-reduce [rng f] (ci-reduce rng f)) + (-reduce [rng f init] + (loop [i start ret init] + (if (if (pos? step) (< i end) (> i end)) + (let [ret (f ret i)] + (if (reduced? ret) + @ret + (recur (+ i step) ret))) + ret)))) + +(es6-iterable Range) + +(defn range + "Returns a lazy seq of nums from start (inclusive) to end + (exclusive), by step, where start defaults to 0, step to 1, + and end to infinity." + ([] (range 0 (.-MAX_VALUE js/Number) 1)) + ([end] (range 0 end 1)) + ([start end] (range start end 1)) + ([start end step] + (cond + (pos? step) + (if (<= end start) + () + (Range. nil start end step nil nil nil)) + + (neg? step) + (if (>= end start) + () + (Range. nil start end step nil nil nil)) + + :else + (if (== end start) + () + (repeat start))))) + +(defn take-nth + "Returns a lazy seq of every nth item in coll. Returns a stateful + transducer when no collection is provided." + ([n] + {:pre [(number? n)]} + (fn [rf] + (let [ia (volatile! -1)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (let [i (vswap! ia inc)] + (if (zero? (rem i n)) + (rf result input) + result))))))) + ([n coll] + {:pre [(number? n)]} + (lazy-seq + (when-let [s (seq coll)] + (cons (first s) (take-nth n (drop n s))))))) + +(defn split-with + "Returns a vector of [(take-while pred coll) (drop-while pred coll)]" + [pred coll] + [(take-while pred coll) (drop-while pred coll)]) + +(defn partition-by + "Applies f to each value in coll, splitting it each time f returns a + new value. Returns a lazy seq of partitions. Returns a stateful + transducer when no collection is provided." + ([f] + (fn [rf] + (let [a (array-list) + pa (volatile! ::none)] + (fn + ([] (rf)) + ([result] + (let [result (if (.isEmpty a) + result + (let [v (vec (.toArray a))] + ;;clear first! + (.clear a) + (unreduced (rf result v))))] + (rf result))) + ([result input] + (let [pval @pa + val (f input)] + (vreset! pa val) + (if (or (keyword-identical? pval ::none) + (= val pval)) + (do + (.add a input) + result) + (let [v (vec (.toArray a))] + (.clear a) + (let [ret (rf result v)] + (when-not (reduced? ret) + (.add a input)) + ret))))))))) + ([f coll] + (lazy-seq + (when-let [s (seq coll)] + (let [fst (first s) + fv (f fst) + run (cons fst (take-while #(= fv (f %)) (next s)))] + (cons run (partition-by f (lazy-seq (drop (count run) s))))))))) + +(defn frequencies + "Returns a map from distinct items in coll to the number of times + they appear." + [coll] + (persistent! + (reduce (fn [counts x] + (assoc! counts x (inc (get counts x 0)))) + (transient {}) coll))) + +(defn reductions + "Returns a lazy seq of the intermediate values of the reduction (as + per reduce) of coll by f, starting with init." + ([f coll] + (lazy-seq + (if-let [s (seq coll)] + (reductions f (first s) (rest s)) + (list (f))))) + ([f init coll] + (if (reduced? init) + (list @init) + (cons init + (lazy-seq + (when-let [s (seq coll)] + (reductions f (f init (first s)) (rest s)))))))) + +(defn juxt + "Takes a set of functions and returns a fn that is the juxtaposition + of those fns. The returned fn takes a variable number of args, and + returns a vector containing the result of applying each fn to the + args (left-to-right). + ((juxt a b c) x) => [(a x) (b x) (c x)]" + ([f] + (fn + ([] (vector (f))) + ([x] (vector (f x))) + ([x y] (vector (f x y))) + ([x y z] (vector (f x y z))) + ([x y z & args] (vector (apply f x y z args))))) + ([f g] + (fn + ([] (vector (f) (g))) + ([x] (vector (f x) (g x))) + ([x y] (vector (f x y) (g x y))) + ([x y z] (vector (f x y z) (g x y z))) + ([x y z & args] (vector (apply f x y z args) (apply g x y z args))))) + ([f g h] + (fn + ([] (vector (f) (g) (h))) + ([x] (vector (f x) (g x) (h x))) + ([x y] (vector (f x y) (g x y) (h x y))) + ([x y z] (vector (f x y z) (g x y z) (h x y z))) + ([x y z & args] (vector (apply f x y z args) (apply g x y z args) (apply h x y z args))))) + ([f g h & fs] + (let [fs (list* f g h fs)] + (fn + ([] (reduce #(conj %1 (%2)) [] fs)) + ([x] (reduce #(conj %1 (%2 x)) [] fs)) + ([x y] (reduce #(conj %1 (%2 x y)) [] fs)) + ([x y z] (reduce #(conj %1 (%2 x y z)) [] fs)) + ([x y z & args] (reduce #(conj %1 (apply %2 x y z args)) [] fs)))))) + +(defn dorun + "When lazy sequences are produced via functions that have side + effects, any effects other than those needed to produce the first + element in the seq do not occur until the seq is consumed. dorun can + be used to force any effects. Walks through the successive nexts of + the seq, does not retain the head and returns nil." + ([coll] + (when-let [s (seq coll)] + (recur (next s)))) + ([n coll] + (when (and (seq coll) (pos? n)) + (recur (dec n) (next coll))))) + +(defn doall + "When lazy sequences are produced via functions that have side + effects, any effects other than those needed to produce the first + element in the seq do not occur until the seq is consumed. doall can + be used to force any effects. Walks through the successive nexts of + the seq, retains the head and returns it, thus causing the entire + seq to reside in memory at one time." + ([coll] + (dorun coll) + coll) + ([n coll] + (dorun n coll) + coll)) + +;;;;;;;;;;;;;;;;;;;;;;;;; Regular Expressions ;;;;;;;;;; + +(defn regexp? + "Returns true if x is a JavaScript RegExp instance." + [x] + (instance? js/RegExp x)) + +(defn re-matches + "Returns the result of (re-find re s) if re fully matches s." + [re s] + (if (string? s) + (let [matches (.exec re s)] + (when (= (first matches) s) + (if (== (count matches) 1) + (first matches) + (vec matches)))) + (throw (js/TypeError. "re-matches must match against a string.")))) + + +(defn re-find + "Returns the first regex match, if any, of s to re, using + re.exec(s). Returns a vector, containing first the matching + substring, then any capturing groups if the regular expression contains + capturing groups." + [re s] + (if (string? s) + (let [matches (.exec re s)] + (when-not (nil? matches) + (if (== (count matches) 1) + (first matches) + (vec matches)))) + (throw (js/TypeError. "re-find must match against a string.")))) + +(defn- re-seq* [re s] + (when-some [matches (.exec re s)] + (let [match-str (aget matches 0) + match-vals (if (== (.-length matches) 1) + match-str + (vec matches))] + (cons match-vals + (lazy-seq + (let [post-idx (+ (.-index matches) + (max 1 (.-length match-str)))] + (when (<= post-idx (.-length s)) + (re-seq* re (subs s post-idx))))))))) + +(defn re-seq + "Returns a lazy sequence of successive matches of re in s." + [re s] + (if (string? s) + (re-seq* re s) + (throw (js/TypeError. "re-seq must match against a string.")))) + +(defn re-pattern + "Returns an instance of RegExp which has compiled the provided string." + [s] + (if (instance? js/RegExp s) + s + (let [[prefix flags] (re-find #"^\(\?([idmsux]*)\)" s) + pattern (subs s (count prefix))] + (js/RegExp. pattern (or flags ""))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Printing ;;;;;;;;;;;;;;;; + +(defn pr-sequential-writer [writer print-one begin sep end opts coll] + (binding [*print-level* (when-not (nil? *print-level*) (dec *print-level*))] + (if (and (not (nil? *print-level*)) (neg? *print-level*)) + (-write writer "#") + (do + (-write writer begin) + (if (zero? (:print-length opts)) + (when (seq coll) + (-write writer (or (:more-marker opts) "..."))) + (do + (when (seq coll) + (print-one (first coll) writer opts)) + (loop [coll (next coll) n (dec (:print-length opts))] + (if (and coll (or (nil? n) (not (zero? n)))) + (do + (-write writer sep) + (print-one (first coll) writer opts) + (recur (next coll) (dec n))) + (when (and (seq coll) (zero? n)) + (-write writer sep) + (-write writer (or (:more-marker opts) "..."))))))) + (-write writer end))))) + +(defn write-all [writer & ss] + (doseq [s ss] + (-write writer s))) + +(defn string-print [x] + (when (nil? *print-fn*) + (throw (js/Error. "No *print-fn* fn set for evaluation environment"))) + (*print-fn* x) + nil) + +(defn flush [] ;stub + nil) + +(def ^:private char-escapes + (js-obj + "\"" "\\\"" + "\\" "\\\\" + "\b" "\\b" + "\f" "\\f" + "\n" "\\n" + "\r" "\\r" + "\t" "\\t")) + +(defn ^:private quote-string + [s] + (str \" + (.replace s (js/RegExp "[\\\\\"\b\f\n\r\t]" "g") + (fn [match] (unchecked-get char-escapes match))) + \")) + +(declare print-map) + +(defn print-meta? [opts obj] + (and (boolean (get opts :meta)) + (implements? IMeta obj) + (not (nil? (meta obj))))) + +(defn- pr-writer-impl + [obj writer opts] + (cond + (nil? obj) (-write writer "nil") + :else + (do + (when (print-meta? opts obj) + (-write writer "^") + (pr-writer (meta obj) writer opts) + (-write writer " ")) + (cond + ;; handle CLJS ctors + ^boolean (.-cljs$lang$type obj) + (.cljs$lang$ctorPrWriter obj obj writer opts) + + ; Use the new, more efficient, IPrintWithWriter interface when possible. + (satisfies? IPrintWithWriter obj) + (-pr-writer obj writer opts) + + (or (true? obj) (false? obj)) + (-write writer (str obj)) + + (number? obj) + (-write writer + (cond + ^boolean (js/isNaN obj) "##NaN" + (identical? obj js/Number.POSITIVE_INFINITY) "##Inf" + (identical? obj js/Number.NEGATIVE_INFINITY) "##-Inf" + :else (str obj))) + + (object? obj) + (do + (-write writer "#js ") + (print-map + (map (fn [k] + (MapEntry. (cond-> k (some? (re-matches #"[A-Za-z_\*\+\?!\-'][\w\*\+\?!\-']*" k)) keyword) (unchecked-get obj k) nil)) + (js-keys obj)) + pr-writer writer opts)) + + (array? obj) + (pr-sequential-writer writer pr-writer "#js [" " " "]" opts obj) + + ^boolean (goog/isString obj) + (if (:readably opts) + (-write writer (quote-string obj)) + (-write writer obj)) + + ^boolean (goog/isFunction obj) + (let [name (.-name obj) + name (if (or (nil? name) (gstring/isEmpty name)) + "Function" + name)] + (write-all writer "#object[" name + (if *print-fn-bodies* + (str " \"" (str obj) "\"") + "") + "]")) + + (instance? js/Date obj) + (let [normalize (fn [n len] + (loop [ns (str n)] + (if (< (count ns) len) + (recur (str "0" ns)) + ns)))] + (write-all writer + "#inst \"" + (str (.getUTCFullYear obj)) "-" + (normalize (inc (.getUTCMonth obj)) 2) "-" + (normalize (.getUTCDate obj) 2) "T" + (normalize (.getUTCHours obj) 2) ":" + (normalize (.getUTCMinutes obj) 2) ":" + (normalize (.getUTCSeconds obj) 2) "." + (normalize (.getUTCMilliseconds obj) 3) "-" + "00:00\"")) + + (regexp? obj) (write-all writer "#\"" (.-source obj) "\"") + + :else + (if (some-> obj .-constructor .-cljs$lang$ctorStr) + (write-all writer + "#object[" (.replace (.. obj -constructor -cljs$lang$ctorStr) + (js/RegExp. "/" "g") ".") "]") + (let [name (some-> obj .-constructor .-name) + name (if (or (nil? name) (gstring/isEmpty name)) + "Object" + name)] + (if (nil? (. obj -constructor)) + (write-all writer "#object[" name "]") + (write-all writer "#object[" name " " (str obj) "]")))))))) + +(defn- pr-writer + "Prefer this to pr-seq, because it makes the printing function + configurable, allowing efficient implementations such as appending + to a StringBuffer." + [obj writer opts] + (if-let [alt-impl (:alt-impl opts)] + (alt-impl obj writer (assoc opts :fallback-impl pr-writer-impl)) + (pr-writer-impl obj writer opts))) + +(defn pr-seq-writer [objs writer opts] + (pr-writer (first objs) writer opts) + (doseq [obj (next objs)] + (-write writer " ") + (pr-writer obj writer opts))) + +(defn- pr-sb-with-opts [objs opts] + (let [sb (StringBuffer.) + writer (StringBufferWriter. sb)] + (pr-seq-writer objs writer opts) + (-flush writer) + sb)) + +(defn pr-str-with-opts + "Prints a sequence of objects to a string, observing all the + options given in opts" + [objs opts] + (if (empty? objs) + "" + (str (pr-sb-with-opts objs opts)))) + +(defn prn-str-with-opts + "Same as pr-str-with-opts followed by (newline)" + [objs opts] + (if (empty? objs) + "\n" + (let [sb (pr-sb-with-opts objs opts)] + (.append sb \newline) + (str sb)))) + +(defn- pr-with-opts + "Prints a sequence of objects using string-print, observing all + the options given in opts" + [objs opts] + (string-print (pr-str-with-opts objs opts))) + +(defn newline + "Prints a newline using *print-fn*" + ([] (newline nil)) + ([opts] + (string-print "\n") + (when (get opts :flush-on-newline) + (flush)))) + +(defn pr-str + "pr to a string, returning it. Fundamental entrypoint to IPrintWithWriter." + [& objs] + (pr-str-with-opts objs (pr-opts))) + +(defn prn-str + "Same as pr-str followed by (newline)" + [& objs] + (prn-str-with-opts objs (pr-opts))) + +(defn pr + "Prints the object(s) using string-print. Prints the + object(s), separated by spaces if there is more than one. + By default, pr and prn print in a way that objects can be + read by the reader" + [& objs] + (pr-with-opts objs (pr-opts))) + +(def ^{:doc + "Prints the object(s) using string-print. + print and println produce output for human consumption."} + print + (fn cljs-core-print [& objs] + (pr-with-opts objs (assoc (pr-opts) :readably false)))) + +(defn print-str + "print to a string, returning it" + [& objs] + (pr-str-with-opts objs (assoc (pr-opts) :readably false))) + +(defn println + "Same as print followed by (newline)" + [& objs] + (pr-with-opts objs (assoc (pr-opts) :readably false)) + (when *print-newline* + (newline (pr-opts)))) + +(defn println-str + "println to a string, returning it" + [& objs] + (prn-str-with-opts objs (assoc (pr-opts) :readably false))) + +(defn prn + "Same as pr followed by (newline)." + [& objs] + (pr-with-opts objs (pr-opts)) + (when *print-newline* + (newline (pr-opts)))) + +(defn- strip-ns + [named] + (if (symbol? named) + (symbol nil (name named)) + (keyword nil (name named)))) + +(defn- lift-ns + "Returns [lifted-ns lifted-map] or nil if m can't be lifted." + [m] + (when *print-namespace-maps* + (loop [ns nil + [[k v :as entry] & entries] (seq m) + lm (empty m)] + (if entry + (when (or (keyword? k) (symbol? k)) + (if ns + (when (= ns (namespace k)) + (recur ns entries (assoc lm (strip-ns k) v))) + (when-let [new-ns (namespace k)] + (recur new-ns entries (assoc lm (strip-ns k) v))))) + [ns lm])))) + +(defn print-prefix-map [prefix m print-one writer opts] + (pr-sequential-writer + writer + (fn [e w opts] + (do (print-one (key e) w opts) + (-write w \space) + (print-one (val e) w opts))) + (str prefix "{") ", " "}" + opts (seq m))) + +(defn print-map [m print-one writer opts] + (let [[ns lift-map] (when (map? m) + (lift-ns m))] + (if ns + (print-prefix-map (str "#:" ns) lift-map print-one writer opts) + (print-prefix-map nil m print-one writer opts)))) + +(extend-protocol IPrintWithWriter + LazySeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + TransformerIterator + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + IndexedSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + RSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + PersistentQueue + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "#queue [" " " "]" opts (seq coll))) + + PersistentQueueSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + PersistentTreeMapSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + NodeSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + ArrayNodeSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + List + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + Cons + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + EmptyList + (-pr-writer [coll writer opts] (-write writer "()")) + + PersistentVector + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll)) + + ChunkedCons + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + ChunkedSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + Subvec + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll)) + + BlackNode + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll)) + + RedNode + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll)) + + MapEntry + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "[" " " "]" opts coll)) + + ObjMap + (-pr-writer [coll writer opts] + (print-map coll pr-writer writer opts)) + + KeySeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + ValSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + PersistentArrayMapSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + PersistentArrayMap + (-pr-writer [coll writer opts] + (print-map coll pr-writer writer opts)) + + PersistentHashMap + (-pr-writer [coll writer opts] + (print-map coll pr-writer writer opts)) + + PersistentTreeMap + (-pr-writer [coll writer opts] + (print-map coll pr-writer writer opts)) + + PersistentHashSet + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "#{" " " "}" opts coll)) + + PersistentTreeSet + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "#{" " " "}" opts coll)) + + Range + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + Cycle + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + Repeat + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + Iterate + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + ES6IteratorSeq + (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer "(" " " ")" opts coll)) + + Atom + (-pr-writer [a writer opts] + (-write writer "#object[cljs.core.Atom ") + (pr-writer {:val (.-state a)} writer opts) + (-write writer "]")) + + Volatile + (-pr-writer [a writer opts] + (-write writer "#object[cljs.core.Volatile ") + (pr-writer {:val (.-state a)} writer opts) + (-write writer "]")) + + Var + (-pr-writer [a writer opts] + (-write writer "#'") + (pr-writer (.-sym a) writer opts))) + +;; IComparable +(extend-protocol IComparable + Symbol + (-compare [x y] + (if (symbol? y) + (compare-symbols x y) + (throw (js/Error. (str "Cannot compare " x " to " y))))) + + Keyword + (-compare [x y] + (if (keyword? y) + (compare-keywords x y) + (throw (js/Error. (str "Cannot compare " x " to " y))))) + + Subvec + (-compare [x y] + (if (vector? y) + (compare-indexed x y) + (throw (js/Error. (str "Cannot compare " x " to " y))))) + + PersistentVector + (-compare [x y] + (if (vector? y) + (compare-indexed x y) + (throw (js/Error. (str "Cannot compare " x " to " y))))) + + MapEntry + (-compare [x y] + (if (vector? y) + (compare-indexed x y) + (throw (js/Error. (str "Cannot compare " x " to " y))))) + + BlackNode + (-compare [x y] + (if (vector? y) + (compare-indexed x y) + (throw (js/Error. (str "Cannot compare " x " to " y))))) + + RedNode + (-compare [x y] + (if (vector? y) + (compare-indexed x y) + (throw (js/Error. (str "Cannot compare " x " to " y)))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Reference Types ;;;;;;;;;;;;;;;; + +(defn alter-meta! + "Atomically sets the metadata for a namespace/var/ref/agent/atom to be: + + (apply f its-current-meta args) + + f must be free of side-effects" + [iref f & args] + (set! (.-meta iref) (apply f (.-meta iref) args))) + +(defn reset-meta! + "Atomically resets the metadata for an atom" + [iref m] + (set! (.-meta iref) m)) + +(defn add-watch + "Adds a watch function to an atom reference. The watch fn must be a + fn of 4 args: a key, the reference, its old-state, its + new-state. Whenever the reference's state might have been changed, + any registered watches will have their functions called. The watch + fn will be called synchronously. Note that an atom's state + may have changed again prior to the fn call, so use old/new-state + rather than derefing the reference. Keys must be unique per + reference, and can be used to remove the watch with remove-watch, + but are otherwise considered opaque by the watch mechanism. Bear in + mind that regardless of the result or action of the watch fns the + atom's value will change. Example: + + (def a (atom 0)) + (add-watch a :inc (fn [k r o n] (assert (== 0 n)))) + (swap! a inc) + ;; Assertion Error + (deref a) + ;=> 1" + [iref key f] + (-add-watch iref key f) + iref) + +(defn remove-watch + "Removes a watch (set by add-watch) from a reference" + [iref key] + (-remove-watch iref key) + iref) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; gensym ;;;;;;;;;;;;;;;; +;; Internal - do not use! +(def + ^{:jsdoc ["@type {*}"]} + gensym_counter nil) + +(defn gensym + "Returns a new symbol with a unique name. If a prefix string is + supplied, the name is prefix# where # is some unique number. If + prefix is not supplied, the prefix is 'G__'." + ([] (gensym "G__")) + ([prefix-string] + (when (nil? gensym_counter) + (set! gensym_counter (atom 0))) + (symbol (str prefix-string (swap! gensym_counter inc))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Delay ;;;;;;;;;;;;;;;;;;;; + +(deftype Delay [^:mutable f ^:mutable value] + IDeref + (-deref [_] + (when f + (set! value (f)) + (set! f nil)) + value) + + IPending + (-realized? [x] + (not f)) + + IPrintWithWriter + (-pr-writer [x writer opts] + (-write writer "#object[cljs.core.Delay ") + (pr-writer {:status (if (nil? f) :ready :pending), :val value} writer opts) + (-write writer "]"))) + +(defn delay? + "returns true if x is a Delay created with delay" + [x] (instance? Delay x)) + +(defn force + "If x is a Delay, returns the (possibly cached) value of its expression, else returns x" + [x] + (if (delay? x) + (deref x) + x)) + +(defn ^boolean realized? + "Returns true if a value has been produced for a delay or lazy sequence." + [x] + (-realized? x)) + +(defn- preserving-reduced + [rf] + #(let [ret (rf %1 %2)] + (if (reduced? ret) + (reduced ret) + ret))) + +(defn cat + "A transducer which concatenates the contents of each input, which must be a + collection, into the reduction." + {:added "1.7"} + [rf] + (let [rf1 (preserving-reduced rf)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (reduce rf1 result input))))) + +(defn halt-when + "Returns a transducer that ends transduction when pred returns true + for an input. When retf is supplied it must be a fn of 2 arguments - + it will be passed the (completed) result so far and the input that + triggered the predicate, and its return value (if it does not throw + an exception) will be the return value of the transducer. If retf + is not supplied, the input that triggered the predicate will be + returned. If the predicate never returns true the transduction is + unaffected." + {:added "1.9"} + ([pred] (halt-when pred nil)) + ([pred retf] + (fn [rf] + (fn + ([] (rf)) + ([result] + (if (and (map? result) (contains? result ::halt)) + (::halt result) + (rf result))) + ([result input] + (if (pred input) + (reduced {::halt (if retf (retf (rf result) input) input)}) + (rf result input))))))) + +(defn dedupe + "Returns a lazy sequence removing consecutive duplicates in coll. + Returns a transducer when no collection is provided." + ([] + (fn [rf] + (let [pa (volatile! ::none)] + (fn + ([] (rf)) + ([result] (rf result)) + ([result input] + (let [prior @pa] + (vreset! pa input) + (if (= prior input) + result + (rf result input)))))))) + ([coll] (sequence (dedupe) coll))) + +(declare rand) + +(defn random-sample + "Returns items from coll with random probability of prob (0.0 - + 1.0). Returns a transducer when no collection is provided." + ([prob] + (filter (fn [_] (< (rand) prob)))) + ([prob coll] + (filter (fn [_] (< (rand) prob)) coll))) + +(deftype Eduction [xform coll] + Object + (indexOf [coll x] + (-indexOf coll x 0)) + (indexOf [coll x start] + (-indexOf coll x start)) + (lastIndexOf [coll x] + (-lastIndexOf coll x (count coll))) + (lastIndexOf [coll x start] + (-lastIndexOf coll x start)) + + ISequential + + IIterable + (-iterator [_] + (.create TransformerIterator xform (iter coll))) + + ISeqable + (-seq [_] (seq (sequence xform coll))) + + IReduce + (-reduce [_ f] (transduce xform (completing f) coll)) + (-reduce [_ f init] (transduce xform (completing f) init coll)) + + IPrintWithWriter + (-pr-writer [coll writer opts] + (pr-sequential-writer writer pr-writer "(" " " ")" opts coll))) + +(es6-iterable Eduction) + +(defn eduction + "Returns a reducible/iterable application of the transducers + to the items in coll. Transducers are applied in order as if + combined with comp. Note that these applications will be + performed every time reduce/iterator is called." + {:arglists '([xform* coll])} + [& xforms] + (Eduction. (apply comp (butlast xforms)) (last xforms))) + +(defn run! + "Runs the supplied procedure (via reduce), for purposes of side + effects, on successive items in the collection. Returns nil" + [proc coll] + (reduce #(proc %2) nil coll) + nil) + +(defprotocol IEncodeJS + (-clj->js [x] "Recursively transforms clj values to JavaScript") + (-key->js [x] "Transforms map keys to valid JavaScript keys. Arbitrary keys are + encoded to their string representation via (pr-str x)")) + +(declare clj->js) + +(defn key->js + ([k] (key->js k clj->js)) + ([k primitive-fn] + (cond + (satisfies? IEncodeJS k) (-clj->js k) + (or (string? k) + (number? k) + (keyword? k) + (symbol? k)) (primitive-fn k) + :default (pr-str k)))) + +(defn clj->js + "Recursively transforms ClojureScript values to JavaScript. + sets/vectors/lists become Arrays, Keywords and Symbol become Strings, + Maps become Objects. Arbitrary keys are encoded to by `key->js`. + Options is a key-value pair, where the only valid key is + :keyword-fn, which should point to a single-argument function to be + called on keyword keys. Default to `name`." + [x & {:keys [keyword-fn] + :or {keyword-fn name} + :as options}] + (letfn [(keyfn [k] (key->js k thisfn)) + (thisfn [x] (cond + (nil? x) nil + (satisfies? IEncodeJS x) (-clj->js x) + (keyword? x) (keyword-fn x) + (symbol? x) (str x) + (map? x) (let [m (js-obj)] + (doseq [[k v] x] + (gobject/set m (keyfn k) (thisfn v))) + m) + (coll? x) (let [arr (array)] + (doseq [x (map thisfn x)] + (.push arr x)) + arr) + :else x))] + (thisfn x))) + + +(defprotocol IEncodeClojure + (-js->clj [x options] "Transforms JavaScript values to Clojure")) + +(defn js->clj + "Recursively transforms JavaScript arrays into ClojureScript + vectors, and JavaScript objects into ClojureScript maps. With + option ':keywordize-keys true' will convert object fields from + strings to keywords." + ([x] (js->clj x :keywordize-keys false)) + ([x & opts] + (let [{:keys [keywordize-keys]} opts + keyfn (if keywordize-keys keyword str) + f (fn thisfn [x] + (cond + (satisfies? IEncodeClojure x) + (-js->clj x (apply array-map opts)) + + (seq? x) + (doall (map thisfn x)) + + (map-entry? x) + (MapEntry. (thisfn (key x)) (thisfn (val x)) nil) + + (coll? x) + (into (empty x) (map thisfn) x) + + (array? x) + (persistent! + (reduce #(conj! %1 (thisfn %2)) + (transient []) x)) + + (identical? (type x) js/Object) + (persistent! + (reduce (fn [r k] (assoc! r (keyfn k) (thisfn (gobject/get x k)))) + (transient {}) (js-keys x))) + :else x))] + (f x)))) + +(defn memoize + "Returns a memoized version of a referentially transparent function. The + memoized version of the function keeps a cache of the mapping from arguments + to results and, when calls with the same arguments are repeated often, has + higher performance at the expense of higher memory use." + [f] + (let [mem (atom {})] + (fn [& args] + (let [v (get @mem args lookup-sentinel)] + (if (identical? v lookup-sentinel) + (let [ret (apply f args)] + (swap! mem assoc args ret) + ret) + v))))) + +(defn trampoline + "trampoline can be used to convert algorithms requiring mutual + recursion without stack consumption. Calls f with supplied args, if + any. If f returns a fn, calls that fn with no arguments, and + continues to repeat, until the return value is not a fn, then + returns that non-fn value. Note that if you want to return a fn as a + final value, you must wrap it in some data structure and unpack it + after trampoline returns." + ([f] + (let [ret (f)] + (if (fn? ret) + (recur ret) + ret))) + ([f & args] + (trampoline #(apply f args)))) + +(defn rand + "Returns a random floating point number between 0 (inclusive) and + n (default 1) (exclusive)." + ([] (rand 1)) + ([n] (* (Math/random) n))) + +(defn rand-int + "Returns a random integer between 0 (inclusive) and n (exclusive)." + [n] (Math/floor (* (Math/random) n))) + +(defn rand-nth + "Return a random element of the (sequential) collection. Will have + the same performance characteristics as nth for the given + collection." + [coll] + (nth coll (rand-int (count coll)))) + +(defn group-by + "Returns a map of the elements of coll keyed by the result of + f on each element. The value at each key will be a vector of the + corresponding elements, in the order they appeared in coll." + [f coll] + (persistent! + (reduce + (fn [ret x] + (let [k (f x)] + (assoc! ret k (conj (get ret k []) x)))) + (transient {}) coll))) + +(defn make-hierarchy + "Creates a hierarchy object for use with derive, isa? etc." + [] {:parents {} :descendants {} :ancestors {}}) + +(def + ^{:private true + :jsdoc ["@type {*}"]} + -global-hierarchy nil) + +(defn- get-global-hierarchy [] + (when (nil? -global-hierarchy) + (set! -global-hierarchy (atom (make-hierarchy)))) + -global-hierarchy) + +(defn- swap-global-hierarchy! [f & args] + (apply swap! (get-global-hierarchy) f args)) + +(defn ^boolean isa? + "Returns true if (= child parent), or child is directly or indirectly derived from + parent, either via a JavaScript type inheritance relationship or a + relationship established via derive. h must be a hierarchy obtained + from make-hierarchy, if not supplied defaults to the global + hierarchy" + ([child parent] (isa? @(get-global-hierarchy) child parent)) + ([h child parent] + (or (= child parent) + ;; (and (class? parent) (class? child) + ;; (. ^Class parent isAssignableFrom child)) + (contains? ((:ancestors h) child) parent) + ;;(and (class? child) (some #(contains? ((:ancestors h) %) parent) (supers child))) + (and (vector? parent) (vector? child) + (== (count parent) (count child)) + (loop [ret true i 0] + (if (or (not ret) (== i (count parent))) + ret + (recur (isa? h (child i) (parent i)) (inc i)))))))) + +(defn parents + "Returns the immediate parents of tag, either via a JavaScript type + inheritance relationship or a relationship established via derive. h + must be a hierarchy obtained from make-hierarchy, if not supplied + defaults to the global hierarchy" + ([tag] (parents @(get-global-hierarchy) tag)) + ([h tag] (not-empty (get (:parents h) tag)))) + +(defn ancestors + "Returns the immediate and indirect parents of tag, either via a JavaScript type + inheritance relationship or a relationship established via derive. h + must be a hierarchy obtained from make-hierarchy, if not supplied + defaults to the global hierarchy" + ([tag] (ancestors @(get-global-hierarchy) tag)) + ([h tag] (not-empty (get (:ancestors h) tag)))) + +(defn descendants + "Returns the immediate and indirect children of tag, through a + relationship established via derive. h must be a hierarchy obtained + from make-hierarchy, if not supplied defaults to the global + hierarchy. Note: does not work on JavaScript type inheritance + relationships." + ([tag] (descendants @(get-global-hierarchy) tag)) + ([h tag] (not-empty (get (:descendants h) tag)))) + +(defn derive + "Establishes a parent/child relationship between parent and + tag. Parent must be a namespace-qualified symbol or keyword and + child can be either a namespace-qualified symbol or keyword or a + class. h must be a hierarchy obtained from make-hierarchy, if not + supplied defaults to, and modifies, the global hierarchy." + ([tag parent] + (assert (namespace parent)) + ;; (assert (or (class? tag) (and (instance? cljs.core.Named tag) (namespace tag)))) + (swap-global-hierarchy! derive tag parent) nil) + ([h tag parent] + (assert (not= tag parent)) + ;; (assert (or (class? tag) (instance? clojure.lang.Named tag))) + ;; (assert (instance? clojure.lang.INamed tag)) + ;; (assert (instance? clojure.lang.INamed parent)) + (let [tp (:parents h) + td (:descendants h) + ta (:ancestors h) + tf (fn [m source sources target targets] + (reduce (fn [ret k] + (assoc ret k + (reduce conj (get targets k #{}) (cons target (targets target))))) + m (cons source (sources source))))] + (or + (when-not (contains? (tp tag) parent) + (when (contains? (ta tag) parent) + (throw (js/Error. (str tag "already has" parent "as ancestor")))) + (when (contains? (ta parent) tag) + (throw (js/Error. (str "Cyclic derivation:" parent "has" tag "as ancestor")))) + {:parents (assoc (:parents h) tag (conj (get tp tag #{}) parent)) + :ancestors (tf (:ancestors h) tag td parent ta) + :descendants (tf (:descendants h) parent ta tag td)}) + h)))) + +(defn underive + "Removes a parent/child relationship between parent and + tag. h must be a hierarchy obtained from make-hierarchy, if not + supplied defaults to, and modifies, the global hierarchy." + ([tag parent] + (swap-global-hierarchy! underive tag parent) + nil) + ([h tag parent] + (let [parentMap (:parents h) + childsParents (if (parentMap tag) + (disj (parentMap tag) parent) #{}) + newParents (if (not-empty childsParents) + (assoc parentMap tag childsParents) + (dissoc parentMap tag)) + deriv-seq (flatten (map #(cons (first %) (interpose (first %) (second %))) + (seq newParents)))] + (if (contains? (parentMap tag) parent) + (reduce #(apply derive %1 %2) (make-hierarchy) + (partition 2 deriv-seq)) + h)))) + +(defn- reset-cache + [method-cache method-table cached-hierarchy hierarchy] + (swap! method-cache (fn [_] (deref method-table))) + (swap! cached-hierarchy (fn [_] (deref hierarchy)))) + +(defn- prefers* + [x y prefer-table] + (let [xprefs (@prefer-table x)] + (or + (when (and xprefs (xprefs y)) + true) + (loop [ps (parents y)] + (when (pos? (count ps)) + (when (prefers* x (first ps) prefer-table) + true) + (recur (rest ps)))) + (loop [ps (parents x)] + (when (pos? (count ps)) + (when (prefers* (first ps) y prefer-table) + true) + (recur (rest ps)))) + false))) + +(defn- dominates + [x y prefer-table hierarchy] + (or (prefers* x y prefer-table) (isa? hierarchy x y))) + +(defn- find-and-cache-best-method + [name dispatch-val hierarchy method-table prefer-table method-cache cached-hierarchy default-dispatch-val] + (let [best-entry (reduce (fn [be [k _ :as e]] + (if (isa? @hierarchy dispatch-val k) + (let [be2 (if (or (nil? be) (dominates k (first be) prefer-table @hierarchy)) + e + be)] + (when-not (dominates (first be2) k prefer-table @hierarchy) + (throw (js/Error. + (str "Multiple methods in multimethod '" name + "' match dispatch value: " dispatch-val " -> " k + " and " (first be2) ", and neither is preferred")))) + be2) + be)) + nil @method-table) + best-entry (if-let [entry (and (nil? best-entry) (@method-table default-dispatch-val))] + [default-dispatch-val entry] + best-entry)] + (when best-entry + (if (= @cached-hierarchy @hierarchy) + (do + (swap! method-cache assoc dispatch-val (second best-entry)) + (second best-entry)) + (do + (reset-cache method-cache method-table cached-hierarchy hierarchy) + (find-and-cache-best-method name dispatch-val hierarchy method-table prefer-table + method-cache cached-hierarchy default-dispatch-val)))))) + +(defprotocol IMultiFn + (-reset [mf]) + (-add-method [mf dispatch-val method]) + (-remove-method [mf dispatch-val]) + (-prefer-method [mf dispatch-val dispatch-val-y]) + (-get-method [mf dispatch-val]) + (-methods [mf]) + (-prefers [mf]) + (-default-dispatch-val [mf]) + (-dispatch-fn [mf])) + +(defn- throw-no-method-error [name dispatch-val] + (throw (js/Error. (str "No method in multimethod '" name "' for dispatch value: " dispatch-val)))) + +(deftype MultiFn [name dispatch-fn default-dispatch-val hierarchy + method-table prefer-table method-cache cached-hierarchy] + IFn + (-invoke [mf] + (let [dispatch-val (dispatch-fn) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn))) + (-invoke [mf a] + (let [dispatch-val (dispatch-fn a) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a))) + (-invoke [mf a b] + (let [dispatch-val (dispatch-fn a b) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b))) + (-invoke [mf a b c] + (let [dispatch-val (dispatch-fn a b c) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c))) + (-invoke [mf a b c d] + (let [dispatch-val (dispatch-fn a b c d) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d))) + (-invoke [mf a b c d e] + (let [dispatch-val (dispatch-fn a b c d e) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e))) + (-invoke [mf a b c d e f] + (let [dispatch-val (dispatch-fn a b c d e f) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f))) + (-invoke [mf a b c d e f g] + (let [dispatch-val (dispatch-fn a b c d e f g) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g))) + (-invoke [mf a b c d e f g h] + (let [dispatch-val (dispatch-fn a b c d e f g h) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h))) + (-invoke [mf a b c d e f g h i] + (let [dispatch-val (dispatch-fn a b c d e f g h i) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i))) + (-invoke [mf a b c d e f g h i j] + (let [dispatch-val (dispatch-fn a b c d e f g h i j) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j))) + (-invoke [mf a b c d e f g h i j k] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k))) + (-invoke [mf a b c d e f g h i j k l] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l))) + (-invoke [mf a b c d e f g h i j k l m] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l m) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l m))) + (-invoke [mf a b c d e f g h i j k l m n] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l m n) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l m n))) + (-invoke [mf a b c d e f g h i j k l m n o] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l m n o) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l m n o))) + (-invoke [mf a b c d e f g h i j k l m n o p] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l m n o p) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l m n o p))) + (-invoke [mf a b c d e f g h i j k l m n o p q] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l m n o p q) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l m n o p q))) + (-invoke [mf a b c d e f g h i j k l m n o p q r] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l m n o p q r) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l m n o p q r))) + (-invoke [mf a b c d e f g h i j k l m n o p q r s] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l m n o p q r s) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l m n o p q r s))) + (-invoke [mf a b c d e f g h i j k l m n o p q r s t] + (let [dispatch-val (dispatch-fn a b c d e f g h i j k l m n o p q r s t) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (target-fn a b c d e f g h i j k l m n o p q r s t))) + (-invoke [mf a b c d e f g h i j k l m n o p q r s t rest] + (let [dispatch-val (apply dispatch-fn a b c d e f g h i j k l m n o p q r s t rest) + target-fn (-get-method mf dispatch-val)] + (when-not target-fn + (throw-no-method-error name dispatch-val)) + (apply target-fn a b c d e f g h i j k l m n o p q r s t rest))) + + IMultiFn + (-reset [mf] + (swap! method-table (fn [mf] {})) + (swap! method-cache (fn [mf] {})) + (swap! prefer-table (fn [mf] {})) + (swap! cached-hierarchy (fn [mf] nil)) + mf) + + (-add-method [mf dispatch-val method] + (swap! method-table assoc dispatch-val method) + (reset-cache method-cache method-table cached-hierarchy hierarchy) + mf) + + (-remove-method [mf dispatch-val] + (swap! method-table dissoc dispatch-val) + (reset-cache method-cache method-table cached-hierarchy hierarchy) + mf) + + (-get-method [mf dispatch-val] + (when-not (= @cached-hierarchy @hierarchy) + (reset-cache method-cache method-table cached-hierarchy hierarchy)) + (if-let [target-fn (@method-cache dispatch-val)] + target-fn + (find-and-cache-best-method name dispatch-val hierarchy method-table + prefer-table method-cache cached-hierarchy default-dispatch-val))) + + (-prefer-method [mf dispatch-val-x dispatch-val-y] + (when (prefers* dispatch-val-x dispatch-val-y prefer-table) + (throw (js/Error. (str "Preference conflict in multimethod '" name "': " dispatch-val-y + " is already preferred to " dispatch-val-x)))) + (swap! prefer-table + (fn [old] + (assoc old dispatch-val-x + (conj (get old dispatch-val-x #{}) + dispatch-val-y)))) + (reset-cache method-cache method-table cached-hierarchy hierarchy)) + + (-methods [mf] @method-table) + (-prefers [mf] @prefer-table) + (-default-dispatch-val [mf] default-dispatch-val) + (-dispatch-fn [mf] dispatch-fn) + + INamed + (-name [this] (-name name)) + (-namespace [this] (-namespace name)) + + IHash + (-hash [this] (goog/getUid this))) + +(defn remove-all-methods + "Removes all of the methods of multimethod." + [multifn] + (-reset multifn)) + +(defn remove-method + "Removes the method of multimethod associated with dispatch-value." + [multifn dispatch-val] + (-remove-method multifn dispatch-val)) + +(defn prefer-method + "Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y + when there is a conflict" + [multifn dispatch-val-x dispatch-val-y] + (-prefer-method multifn dispatch-val-x dispatch-val-y)) + +(defn methods + "Given a multimethod, returns a map of dispatch values -> dispatch fns" + [multifn] (-methods multifn)) + +(defn get-method + "Given a multimethod and a dispatch value, returns the dispatch fn + that would apply to that value, or nil if none apply and no default" + [multifn dispatch-val] (-get-method multifn dispatch-val)) + +(defn prefers + "Given a multimethod, returns a map of preferred value -> set of other values" + [multifn] (-prefers multifn)) + +(defn default-dispatch-val + "Given a multimethod, return it's default-dispatch-val." + [multifn] (-default-dispatch-val multifn)) + +(defn dispatch-fn + "Given a multimethod, return it's dispatch-fn." + [multifn] (-dispatch-fn multifn)) + +;; UUID +(defprotocol IUUID "A marker protocol for UUIDs") + +(deftype UUID [uuid ^:mutable __hash] + IUUID + + Object + (toString [_] uuid) + (equiv [this other] + (-equiv this other)) + + IEquiv + (-equiv [_ other] + (and (instance? UUID other) (identical? uuid (.-uuid other)))) + + IPrintWithWriter + (-pr-writer [_ writer _] + (-write writer (str "#uuid \"" uuid "\""))) + + IHash + (-hash [this] + (when (nil? __hash) + (set! __hash (hash uuid))) + __hash) + + IComparable + (-compare [_ other] + (garray/defaultCompare uuid (.-uuid other)))) + +(defn uuid [s] + (assert (string? s)) + (UUID. (.toLowerCase s) nil)) + +(defn random-uuid [] + (letfn [(hex [] (.toString (rand-int 16) 16))] + (let [rhex (.toString (bit-or 0x8 (bit-and 0x3 (rand-int 16))) 16)] + (uuid + (str (hex) (hex) (hex) (hex) + (hex) (hex) (hex) (hex) "-" + (hex) (hex) (hex) (hex) "-" + "4" (hex) (hex) (hex) "-" + rhex (hex) (hex) (hex) "-" + (hex) (hex) (hex) (hex) + (hex) (hex) (hex) (hex) + (hex) (hex) (hex) (hex)))))) + +(defn uuid? + [x] (implements? IUUID x)) + +;;; ExceptionInfo + +(defn- pr-writer-ex-info [obj writer opts] + (-write writer "#error {:message ") + (pr-writer (.-message obj) writer opts) + (when (.-data obj) + (-write writer ", :data ") + (pr-writer (.-data obj) writer opts)) + (when (.-cause obj) + (-write writer ", :cause ") + (pr-writer (.-cause obj) writer opts)) + (-write writer "}")) + +(defn ^{:jsdoc ["@constructor"]} + ExceptionInfo [message data cause] + (let [e (js/Error. message)] + (this-as this + (set! (.-message this) message) + (set! (.-data this) data) + (set! (.-cause this) cause) + (do + (set! (.-name this) (.-name e)) + ;; non-standard + (set! (.-description this) (.-description e)) + (set! (.-number this) (.-number e)) + (set! (.-fileName this) (.-fileName e)) + (set! (.-lineNumber this) (.-lineNumber e)) + (set! (.-columnNumber this) (.-columnNumber e)) + (set! (.-stack this) (.-stack e))) + this))) + +(set! (.. ExceptionInfo -prototype -__proto__) js/Error.prototype) + +(extend-type ExceptionInfo + IPrintWithWriter + (-pr-writer [obj writer opts] + (pr-writer-ex-info obj writer opts))) + +(set! (.. ExceptionInfo -prototype -toString) + (fn [] + (this-as this (pr-str* this)))) + +(defn ex-info + "Create an instance of ExceptionInfo, an Error type that carries a + map of additional data." + ([msg data] (ex-info msg data nil)) + ([msg data cause] + (ExceptionInfo. msg data cause))) + +(defn ex-data + "Returns exception data (a map) if ex is an ExceptionInfo. + Otherwise returns nil." + [ex] + (when (instance? ExceptionInfo ex) + (.-data ex))) + +(defn ex-message + "Returns the message attached to the given Error / ExceptionInfo object. + For non-Errors returns nil." + [ex] + (when (instance? js/Error ex) + (.-message ex))) + +(defn ex-cause + "Returns exception cause (an Error / ExceptionInfo) if ex is an + ExceptionInfo. + Otherwise returns nil." + [ex] + (when (instance? ExceptionInfo ex) + (.-cause ex))) + +(defn comparator + "Returns an JavaScript compatible comparator based upon pred." + [pred] + (fn [x y] + (cond (pred x y) -1 (pred y x) 1 :else 0))) + +(defn ^boolean special-symbol? + "Returns true if x names a special form" + [x] + (contains? + '#{if def fn* do let* loop* letfn* throw try catch finally + recur new set! ns deftype* defrecord* . js* & quote case* var ns*} + x)) + +(defn test + "test [v] finds fn at key :test in var metadata and calls it, + presuming failure will throw exception" + [v] + (let [f (.-cljs$lang$test v)] + (if f + (do (f) :ok) + :no-test))) + + +(deftype TaggedLiteral [tag form] + Object + (toString [coll] + (pr-str* coll)) + + IEquiv + (-equiv [this other] + (and (instance? TaggedLiteral other) + (= tag (.-tag other)) + (= form (.-form other)))) + + IHash + (-hash [this] + (+ (* 31 (hash tag)) + (hash form))) + + ILookup + (-lookup [this v] + (-lookup this v nil)) + (-lookup [this v not-found] + (case v + :tag tag + :form form + not-found)) + + IPrintWithWriter + (-pr-writer [o writer opts] + (-write writer (str "#" tag " ")) + (pr-writer form writer opts))) + +(defn tagged-literal? + "Return true if the value is the data representation of a tagged literal" + [value] + (instance? TaggedLiteral value)) + +(defn tagged-literal + "Construct a data representation of a tagged literal from a + tag symbol and a form." + [tag form] + {:pre [(symbol? tag)]} + (TaggedLiteral. tag form)) + +(def + ^{:private true + :jsdoc ["@type {*}"]} + js-reserved-arr + #js ["arguments" "abstract" "await" "boolean" "break" "byte" "case" + "catch" "char" "class" "const" "continue" + "debugger" "default" "delete" "do" "double" + "else" "enum" "export" "extends" "final" + "finally" "float" "for" "function" "goto" "if" + "implements" "import" "in" "instanceof" "int" + "interface" "let" "long" "native" "new" + "package" "private" "protected" "public" + "return" "short" "static" "super" "switch" + "synchronized" "this" "throw" "throws" + "transient" "try" "typeof" "var" "void" + "volatile" "while" "with" "yield" "methods" + "null" "constructor"]) + +(def + ^{:jsdoc ["@type {null|Object}"]} + js-reserved nil) + +(defn- js-reserved? [x] + (when (nil? js-reserved) + (set! js-reserved + (reduce #(do (gobject/set %1 %2 true) %1) + #js {} js-reserved-arr))) + (.hasOwnProperty js-reserved x)) + +(defn- demunge-pattern [] + (when-not DEMUNGE_PATTERN + (set! DEMUNGE_PATTERN + (let [ks (sort (fn [a b] (- (. b -length) (. a -length))) + (js-keys DEMUNGE_MAP))] + (loop [ks ks ret ""] + (if (seq ks) + (recur + (next ks) + (str + (cond-> ret + (not (identical? ret "")) (str "|")) + (first ks))) + (str ret "|\\$")))))) + DEMUNGE_PATTERN) + +(defn- munge-str [name] + (let [sb (StringBuffer.)] + (loop [i 0] + (if (< i (. name -length)) + (let [c (.charAt name i) + sub (gobject/get CHAR_MAP c)] + (if-not (nil? sub) + (.append sb sub) + (.append sb c)) + (recur (inc i))))) + (.toString sb))) + +(defn munge [name] + (let [name' (munge-str (str name)) + name' (cond + (identical? name' "..") "_DOT__DOT_" + (js-reserved? name') (str name' "$") + :else name')] + (if (symbol? name) + (symbol name') + name'))) + +(defn- demunge-str [munged-name] + (let [r (js/RegExp. (demunge-pattern) "g") + munged-name (if (gstring/endsWith munged-name "$") + (.substring munged-name 0 (dec (. munged-name -length))) + munged-name)] + (loop [ret "" last-match-end 0] + (if-let [match (.exec r munged-name)] + (let [[x] match] + (recur + (str ret + (.substring munged-name last-match-end + (- (. r -lastIndex) (. x -length))) + (if (identical? x "$") "/" (gobject/get DEMUNGE_MAP x))) + (. r -lastIndex))) + (str ret + (.substring munged-name last-match-end (.-length munged-name))))))) + +(defn demunge [name] + ((if (symbol? name) symbol str) + (let [name' (str name)] + (if (identical? name' "_DOT__DOT_") + ".." + (demunge-str name'))))) + +(defonce ^{:jsdoc ["@type {*}"] :private true} + tapset nil) + +(defn- maybe-init-tapset [] + (when (nil? tapset) + (set! tapset (atom #{})))) + +(defn add-tap + "Adds f, a fn of one argument, to the tap set. This function will be called with + anything sent via tap>. Remember f in order to remove-tap" + [f] + (maybe-init-tapset) + (swap! tapset conj f) + nil) + +(defn remove-tap + "Remove f from the tap set." + [f] + (maybe-init-tapset) + (swap! tapset disj f) + nil) + +(defn ^boolean tap> + "Sends x to any taps. Returns the result of *exec-tap-fn*, a Boolean value." + [x] + (maybe-init-tapset) + (*exec-tap-fn* + (fn [] + (doseq [tap @tapset] + (try + (tap x) + (catch js/Error ex)))))) + +;; ----------------------------------------------------------------------------- +;; Bootstrap helpers - incompatible with advanced compilation + +(defn- ns-lookup + "Bootstrap only." + [ns-obj k] + (fn [] (gobject/get ns-obj k))) + +;; Bootstrap only +(deftype Namespace [obj name] + Object + (findInternedVar [this sym] + (let [k (munge (str sym))] + (when ^boolean (gobject/containsKey obj k) + (let [var-sym (symbol (str name) (str sym)) + var-meta {:ns this}] + (Var. (ns-lookup obj k) var-sym var-meta))))) + (getName [_] name) + (toString [_] + (str name)) + IEquiv + (-equiv [_ other] + (if (instance? Namespace other) + (= name (.-name other)) + false)) + IHash + (-hash [_] + (hash name))) + +(def + ^{:doc "Bootstrap only." :jsdoc ["@type {*}"]} + NS_CACHE nil) + +(defn- find-ns-obj* + "Bootstrap only." + [ctxt xs] + (cond + (nil? ctxt) nil + (nil? xs) ctxt + :else (recur (gobject/get ctxt (first xs)) (next xs)))) + +(defn find-ns-obj + "Bootstrap only." + [ns] + (let [munged-ns (munge (str ns)) + segs (.split munged-ns ".")] + (case *target* + "nodejs" (if ^boolean js/COMPILED + ; Under simple optimizations on nodejs, namespaces will be in module + ; rather than global scope and must be accessed by a direct call to eval. + ; The first segment may refer to an undefined variable, so its evaluation + ; may throw ReferenceError. + (find-ns-obj* + (try + (let [ctxt (js/eval (first segs))] + (when (and ctxt (object? ctxt)) + ctxt)) + (catch js/ReferenceError e + nil)) + (next segs)) + (find-ns-obj* goog/global segs)) + ("default" "webworker") (find-ns-obj* goog/global segs) + (throw (js/Error. (str "find-ns-obj not supported for target " *target*)))))) + +(defn ns-interns* + "Returns a map of the intern mappings for the namespace. + Bootstrap only." + [sym] + (let [ns-obj (find-ns-obj sym) + ns (Namespace. ns-obj sym)] + (letfn [(step [ret k] + (let [var-sym (symbol (demunge k))] + (assoc ret + var-sym (Var. #(gobject/get ns-obj k) + (symbol (str sym) (str var-sym)) {:ns ns}))))] + (reduce step {} (js-keys ns-obj))))) + +(defn create-ns + "Create a new namespace named by the symbol. Bootstrap only." + ([sym] + (create-ns sym (find-ns-obj sym))) + ([sym ns-obj] + (Namespace. ns-obj sym))) + +(defn find-ns + "Returns the namespace named by the symbol or nil if it doesn't exist. + Bootstrap only." + [ns] + (when (nil? NS_CACHE) + (set! NS_CACHE (atom {}))) + (let [the-ns (get @NS_CACHE ns)] + (if-not (nil? the-ns) + the-ns + (let [ns-obj (find-ns-obj ns)] + (when-not (nil? ns-obj) + (let [new-ns (create-ns ns ns-obj)] + (swap! NS_CACHE assoc ns new-ns) + new-ns)))))) + +(defn find-macros-ns + "Returns the macros namespace named by the symbol or nil if it doesn't exist. + Bootstrap only." + [ns] + (when (nil? NS_CACHE) + (set! NS_CACHE (atom {}))) + (let [ns-str (str ns) + ns (if (not ^boolean (gstring/contains ns-str "$macros")) + (symbol (str ns-str "$macros")) + ns) + the-ns (get @NS_CACHE ns)] + (if-not (nil? the-ns) + the-ns + (let [ns-obj (find-ns-obj ns)] + (when-not (nil? ns-obj) + (let [new-ns (create-ns ns ns-obj)] + (swap! NS_CACHE assoc ns new-ns) + new-ns)))))) + +(defn ns-name + "Returns the name of the namespace, a Namespace object. + Bootstrap only." + [ns-obj] + (.-name ns-obj)) + +(defn uri? + "Returns true x is a goog.Uri instance." + {:added "1.9"} + [x] + (instance? goog.Uri x)) + +(defn- maybe-enable-print! [] + (cond + (exists? js/console) + (enable-console-print!) + + (or (identical? *target* "nashorn") + (identical? *target* "graaljs")) + (let [system (.type js/Java "java.lang.System")] + (set! *print-newline* false) + (set-print-fn! + (fn [] + (let [xs (js-arguments) + s (.join (garray/clone xs) "")] + (.println (.-out system) s)))) + (set-print-err-fn! + (fn [] + (let [xs (js-arguments) + s (.join (garray/clone xs) "")] + (.println (.-error system) s))))))) + +(maybe-enable-print!) + +(defonce + ^{:doc "Runtime environments may provide a way to evaluate ClojureScript + forms. Whatever function *eval* is bound to will be passed any forms which + should be evaluated." :dynamic true} + *eval* + (fn [_] + (throw (js/Error. "cljs.core/*eval* not bound")))) + +(defn eval + "Evaluates the form data structure (not text!) and returns the result. + Delegates to cljs.core/*eval*. Intended for use in self-hosted ClojureScript, + which sets up an implementation of cljs.core/*eval* for that environment." + [form] + (*eval* form)) diff --git a/resources/public/js/optimized/cljs/core.js b/resources/public/js/optimized/cljs/core.js new file mode 100644 index 0000000..7682e18 --- /dev/null +++ b/resources/public/js/optimized/cljs/core.js @@ -0,0 +1,37895 @@ +// Compiled by ClojureScript 1.10.520 {:static-fns true, :optimize-constants true} +goog.provide('cljs.core'); +goog.require('goog.math.Long'); +goog.require('goog.math.Integer'); +goog.require('goog.string'); +goog.require('goog.object'); +goog.require('goog.array'); +goog.require('goog.Uri'); +goog.require('goog.string.StringBuffer'); +cljs.core._STAR_clojurescript_version_STAR_ = "1.10.520"; +cljs.core._STAR_unchecked_if_STAR_ = false; +cljs.core._STAR_unchecked_arrays_STAR_ = false; +cljs.core._STAR_warn_on_infer_STAR_ = false; +if((typeof cljs !== 'undefined') && (typeof cljs.core !== 'undefined') && (typeof cljs.core.PROTOCOL_SENTINEL !== 'undefined')){ +} else { +cljs.core.PROTOCOL_SENTINEL = ({}); +} +cljs.core.MODULE_URIS = null; +cljs.core.MODULE_INFOS = null; + +/** @define {string} */ +goog.define("cljs.core._STAR_target_STAR_","default"); +/** + * Var bound to the current namespace. Only used for bootstrapping. + * @type {*} + */ +cljs.core._STAR_ns_STAR_ = null; +/** + * @type {*} + */ +cljs.core._STAR_out_STAR_ = null; +cljs.core._STAR_assert_STAR_ = true; +if((typeof cljs !== 'undefined') && (typeof cljs.core !== 'undefined') && (typeof cljs.core._STAR_print_fn_STAR_ !== 'undefined')){ +} else { +/** + * Each runtime environment provides a different way to print output. + * Whatever function *print-fn* is bound to will be passed any + * Strings which should be printed. + */ +cljs.core._STAR_print_fn_STAR_ = null; +} +/** + * Arranges to have tap functions executed via the supplied f, a + * function of no arguments. Returns true if successful, false otherwise. + */ +cljs.core._STAR_exec_tap_fn_STAR_ = (function cljs$core$_STAR_exec_tap_fn_STAR_(f){ +var and__4120__auto__ = (typeof setTimeout !== 'undefined'); +if(and__4120__auto__){ +var and__4120__auto____$1 = setTimeout(f,(0)); +if(cljs.core.truth_(and__4120__auto____$1)){ +return true; +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +}); +if((typeof cljs !== 'undefined') && (typeof cljs.core !== 'undefined') && (typeof cljs.core._STAR_print_err_fn_STAR_ !== 'undefined')){ +} else { +/** + * Each runtime environment provides a different way to print error output. + * Whatever function *print-err-fn* is bound to will be passed any + * Strings which should be printed. + */ +cljs.core._STAR_print_err_fn_STAR_ = null; +} +/** + * Set *print-fn* to f. + */ +cljs.core.set_print_fn_BANG_ = (function cljs$core$set_print_fn_BANG_(f){ +return cljs.core._STAR_print_fn_STAR_ = f; +}); +/** + * Set *print-err-fn* to f. + */ +cljs.core.set_print_err_fn_BANG_ = (function cljs$core$set_print_err_fn_BANG_(f){ +return cljs.core._STAR_print_err_fn_STAR_ = f; +}); +/** + * When set to true, output will be flushed whenever a newline is printed. + * + * Defaults to true. + */ +cljs.core._STAR_flush_on_newline_STAR_ = true; +/** + * When set to logical false will drop newlines from printing calls. + * This is to work around the implicit newlines emitted by standard JavaScript + * console objects. + */ +cljs.core._STAR_print_newline_STAR_ = true; +/** + * When set to logical false, strings and characters will be printed with + * non-alphanumeric characters converted to the appropriate escape sequences. + * + * Defaults to true + */ +cljs.core._STAR_print_readably_STAR_ = true; +/** + * If set to logical true, when printing an object, its metadata will also + * be printed in a form that can be read back by the reader. + * + * Defaults to false. + */ +cljs.core._STAR_print_meta_STAR_ = false; +/** + * When set to logical true, objects will be printed in a way that preserves + * their type when read in later. + * + * Defaults to false. + */ +cljs.core._STAR_print_dup_STAR_ = false; +/** + * *print-namespace-maps* controls whether the printer will print + * namespace map literal syntax. + * + * Defaults to false, but the REPL binds it to true. + */ +cljs.core._STAR_print_namespace_maps_STAR_ = false; +/** + * *print-length* controls how many items of each collection the + * printer will print. If it is bound to logical false, there is no + * limit. Otherwise, it must be bound to an integer indicating the maximum + * number of items of each collection to print. If a collection contains + * more items, the printer will print items up to the limit followed by + * '...' to represent the remaining items. The root binding is nil + * indicating no limit. + * @type {null|number} + */ +cljs.core._STAR_print_length_STAR_ = null; +/** + * *print-level* controls how many levels deep the printer will + * print nested objects. If it is bound to logical false, there is no + * limit. Otherwise, it must be bound to an integer indicating the maximum + * level to print. Each argument to print is at level 0; if an argument is a + * collection, its items are at level 1; and so on. If an object is a + * collection and is at a level greater than or equal to the value bound to + * *print-level*, the printer prints '#' to represent it. The root binding + * is nil indicating no limit. + * @type {null|number} + */ +cljs.core._STAR_print_level_STAR_ = null; +/** + * *print-fns-bodies* controls whether functions print their source or + * only their names. + */ +cljs.core._STAR_print_fn_bodies_STAR_ = false; +if((typeof cljs !== 'undefined') && (typeof cljs.core !== 'undefined') && (typeof cljs.core._STAR_loaded_libs_STAR_ !== 'undefined')){ +} else { +/** + * @type {*} + */ +cljs.core._STAR_loaded_libs_STAR_ = null; +} +cljs.core.pr_opts = (function cljs$core$pr_opts(){ +return new cljs.core.PersistentArrayMap(null, 5, [cljs.core.cst$kw$flush_DASH_on_DASH_newline,cljs.core._STAR_flush_on_newline_STAR_,cljs.core.cst$kw$readably,cljs.core._STAR_print_readably_STAR_,cljs.core.cst$kw$meta,cljs.core._STAR_print_meta_STAR_,cljs.core.cst$kw$dup,cljs.core._STAR_print_dup_STAR_,cljs.core.cst$kw$print_DASH_length,cljs.core._STAR_print_length_STAR_], null); +}); +/** + * Set *print-fn* to console.log + */ +cljs.core.enable_console_print_BANG_ = (function cljs$core$enable_console_print_BANG_(){ +cljs.core._STAR_print_newline_STAR_ = false; + +cljs.core.set_print_fn_BANG_((function (){ +var xs = arguments; +return console.log.apply(console,goog.array.clone(xs)); +})); + +cljs.core.set_print_err_fn_BANG_((function (){ +var xs = arguments; +return console.error.apply(console,goog.array.clone(xs)); +})); + +return null; +}); +/** + * Internal - do not use! + */ +cljs.core.truth_ = (function cljs$core$truth_(x){ +return (x != null && x !== false); +}); +cljs.core.not_native = null; + +/** + * Tests if 2 arguments are the same object + */ +cljs.core.identical_QMARK_ = (function cljs$core$identical_QMARK_(x,y){ +return (x === y); +}); +/** + * Returns true if x is nil, false otherwise. + */ +cljs.core.nil_QMARK_ = (function cljs$core$nil_QMARK_(x){ +return (x == null); +}); +/** + * Returns true if x is a JavaScript array. + */ +cljs.core.array_QMARK_ = (function cljs$core$array_QMARK_(x){ +if((cljs.core._STAR_target_STAR_ === "nodejs")){ +return Array.isArray(x); +} else { +return (x instanceof Array); +} +}); +/** + * Returns true if x is a JavaScript number. + */ +cljs.core.number_QMARK_ = (function cljs$core$number_QMARK_(x){ +return typeof x === 'number'; +}); +/** + * Returns true if x is logical false, false otherwise. + */ +cljs.core.not = (function cljs$core$not(x){ +if((x == null)){ +return true; +} else { +if(x === false){ +return true; +} else { +return false; + +} +} +}); +/** + * Returns true if x is not nil, false otherwise. + */ +cljs.core.some_QMARK_ = (function cljs$core$some_QMARK_(x){ +return (!((x == null))); +}); +/** + * Returns true if x's constructor is Object + */ +cljs.core.object_QMARK_ = (function cljs$core$object_QMARK_(x){ +if((!((x == null)))){ +return (x.constructor === Object); +} else { +return false; +} +}); +/** + * Returns true if x is a JavaScript string. + */ +cljs.core.string_QMARK_ = (function cljs$core$string_QMARK_(x){ +return goog.isString(x); +}); +/** + * Returns true if x is a JavaScript string of length one. + */ +cljs.core.char_QMARK_ = (function cljs$core$char_QMARK_(x){ +return ((typeof x === 'string') && (((1) === x.length))); +}); +/** + * Returns true if given any argument. + */ +cljs.core.any_QMARK_ = (function cljs$core$any_QMARK_(x){ +return true; +}); +/** + * Internal - do not use! + */ +cljs.core.native_satisfies_QMARK_ = (function cljs$core$native_satisfies_QMARK_(p,x){ +var x__$1 = (((x == null))?null:x); +if((p[goog.typeOf(x__$1)])){ +return true; +} else { +if((p["_"])){ +return true; +} else { +return false; + +} +} +}); +cljs.core.is_proto_ = (function cljs$core$is_proto_(x){ +return (x.constructor.prototype === x); +}); +/** + * When compiled for a command-line target, whatever function + * *main-cli-fn* is set to will be called with the command-line + * argv as arguments + */ +cljs.core._STAR_main_cli_fn_STAR_ = null; +/** + * A sequence of the supplied command line arguments, or nil if + * none were supplied + */ +cljs.core._STAR_command_line_args_STAR_ = null; +/** + * Return x's constructor. + */ +cljs.core.type = (function cljs$core$type(x){ +if((x == null)){ +return null; +} else { +return x.constructor; +} +}); +cljs.core.missing_protocol = (function cljs$core$missing_protocol(proto,obj){ +var ty = cljs.core.type(obj); +var ty__$1 = (cljs.core.truth_((function (){var and__4120__auto__ = ty; +if(cljs.core.truth_(and__4120__auto__)){ +return ty.cljs$lang$type; +} else { +return and__4120__auto__; +} +})())?ty.cljs$lang$ctorStr:goog.typeOf(obj)); +return (new Error(["No protocol method ",proto," defined for type ",ty__$1,": ",obj].join(""))); +}); +cljs.core.type__GT_str = (function cljs$core$type__GT_str(ty){ +var temp__5733__auto__ = ty.cljs$lang$ctorStr; +if(cljs.core.truth_(temp__5733__auto__)){ +var s = temp__5733__auto__; +return s; +} else { +return cljs.core.str.cljs$core$IFn$_invoke$arity$1(ty); +} +}); +cljs.core.load_file = (function cljs$core$load_file(file){ +if(cljs.core.truth_(COMPILED)){ +return null; +} else { +return goog.nodeGlobalRequire(file); +} +}); +if((((typeof Symbol !== 'undefined')) && ((goog.typeOf(Symbol) === "function")))){ +cljs.core.ITER_SYMBOL = Symbol.iterator; +} else { +cljs.core.ITER_SYMBOL = "@@iterator"; +} +/** + * @enum {string} + */ +cljs.core.CHAR_MAP = ({"]": "_RBRACK_", "'": "_SINGLEQUOTE_", "=": "_EQ_", "\"": "_DOUBLEQUOTE_", "!": "_BANG_", "*": "_STAR_", "%": "_PERCENT_", "|": "_BAR_", "~": "_TILDE_", "/": "_SLASH_", "\\": "_BSLASH_", "-": "_", "?": "_QMARK_", "&": "_AMPERSAND_", ":": "_COLON_", "<": "_LT_", "{": "_LBRACE_", "}": "_RBRACE_", "[": "_LBRACK_", "#": "_SHARP_", "^": "_CARET_", "+": "_PLUS_", "@": "_CIRCA_", ">": "_GT_"}); +/** + * @enum {string} + */ +cljs.core.DEMUNGE_MAP = ({"_RBRACE_": "}", "_COLON_": ":", "_BANG_": "!", "_QMARK_": "?", "_BSLASH_": "\\\\", "_SLASH_": "/", "_PERCENT_": "%", "_PLUS_": "+", "_SHARP_": "#", "_LBRACE_": "{", "_BAR_": "|", "_LBRACK_": "[", "_EQ_": "=", "_": "-", "_TILDE_": "~", "_RBRACK_": "]", "_GT_": ">", "_SINGLEQUOTE_": "'", "_CIRCA_": "@", "_AMPERSAND_": "&", "_DOUBLEQUOTE_": "\\\"", "_CARET_": "^", "_LT_": "<", "_STAR_": "*"}); +cljs.core.DEMUNGE_PATTERN = null; +/** + * Returns highest resolution time offered by host in milliseconds. + */ +cljs.core.system_time = (function cljs$core$system_time(){ +if((((typeof performance !== 'undefined')) && ((!((performance.now == null)))))){ +return performance.now(); +} else { +if((((typeof process !== 'undefined')) && ((!((process.hrtime == null)))))){ +var t = process.hrtime(); +return ((((t[(0)]) * 1.0E9) + (t[(1)])) / 1000000.0); +} else { +return (new Date()).getTime(); + +} +} +}); +/** + * Construct a JavaScript array of the specified dimensions. Accepts ignored + * type argument for compatibility with Clojure. Note that there is no efficient + * way to allocate multi-dimensional arrays in JavaScript; as such, this function + * will run in polynomial time when called with 3 or more arguments. + */ +cljs.core.make_array = (function cljs$core$make_array(var_args){ +var G__2640 = arguments.length; +switch (G__2640) { +case 1: +return cljs.core.make_array.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.make_array.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2642 = arguments.length; +var i__4731__auto___2643 = (0); +while(true){ +if((i__4731__auto___2643 < len__4730__auto___2642)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2643])); + +var G__2644 = (i__4731__auto___2643 + (1)); +i__4731__auto___2643 = G__2644; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.make_array.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.make_array.cljs$core$IFn$_invoke$arity$1 = (function (size){ +return (new Array(size)); +}); + +cljs.core.make_array.cljs$core$IFn$_invoke$arity$2 = (function (type,size){ +return (new Array(size)); +}); + +cljs.core.make_array.cljs$core$IFn$_invoke$arity$variadic = (function (type,size,more_sizes){ +var dims = more_sizes; +var dimarray = (new Array(size)); +var n__4607__auto___2645 = dimarray.length; +var i_2646 = (0); +while(true){ +if((i_2646 < n__4607__auto___2645)){ +(dimarray[i_2646] = cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.make_array,null,dims)); + +var G__2647 = (i_2646 + (1)); +i_2646 = G__2647; +continue; +} else { +} +break; +} + +return dimarray; +}); + +/** @this {Function} */ +cljs.core.make_array.cljs$lang$applyTo = (function (seq2637){ +var G__2638 = cljs.core.first(seq2637); +var seq2637__$1 = cljs.core.next(seq2637); +var G__2639 = cljs.core.first(seq2637__$1); +var seq2637__$2 = cljs.core.next(seq2637__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2638,G__2639,seq2637__$2); +}); + +cljs.core.make_array.cljs$lang$maxFixedArity = (2); + +/** + * Returns a javascript array, cloned from the passed in array + */ +cljs.core.aclone = (function cljs$core$aclone(arr){ +var len = arr.length; +var new_arr = (new Array(len)); +var n__4607__auto___2648 = len; +var i_2649 = (0); +while(true){ +if((i_2649 < n__4607__auto___2648)){ +(new_arr[i_2649] = (arr[i_2649])); + +var G__2650 = (i_2649 + (1)); +i_2649 = G__2650; +continue; +} else { +} +break; +} + +return new_arr; +}); +/** + * Creates a new javascript array. + * @param {...*} var_args + */ +cljs.core.array = (function cljs$core$array(var_args){ +var a = (new Array(arguments.length)); +var i = (0); +while(true){ +if((i < a.length)){ +(a[i] = (arguments[i])); + +var G__2651 = (i + (1)); +i = G__2651; +continue; +} else { +return a; +} +break; +} +}); +cljs.core.maybe_warn = (function cljs$core$maybe_warn(e){ +if(cljs.core.truth_(cljs.core._STAR_print_err_fn_STAR_)){ +return (cljs.core._STAR_print_err_fn_STAR_.cljs$core$IFn$_invoke$arity$1 ? cljs.core._STAR_print_err_fn_STAR_.cljs$core$IFn$_invoke$arity$1(e) : cljs.core._STAR_print_err_fn_STAR_.call(null,e)); +} else { +return null; +} +}); +cljs.core.checked_aget = (function cljs$core$checked_aget(var_args){ +var G__2656 = arguments.length; +switch (G__2656) { +case 2: +return cljs.core.checked_aget.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2659 = arguments.length; +var i__4731__auto___2660 = (0); +while(true){ +if((i__4731__auto___2660 < len__4730__auto___2659)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2660])); + +var G__2661 = (i__4731__auto___2660 + (1)); +i__4731__auto___2660 = G__2661; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.checked_aget.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.checked_aget.cljs$core$IFn$_invoke$arity$2 = (function (array,idx){ +try{if(cljs.core.truth_((function (){var or__4131__auto__ = cljs.core.array_QMARK_(array); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return goog.isArrayLike(array); +} +})())){ +} else { +throw (new Error("Assert failed: (or (array? array) (goog/isArrayLike array))")); +} + +if(typeof idx === 'number'){ +} else { +throw (new Error("Assert failed: (number? idx)")); +} + +if((!((idx < (0))))){ +} else { +throw (new Error("Assert failed: (not (neg? idx))")); +} + +if((idx < array.length)){ +} else { +throw (new Error("Assert failed: (< idx (alength array))")); +} +}catch (e2657){var e_2662 = e2657; +cljs.core.maybe_warn(e_2662); +} +return (array[idx]); +}); + +cljs.core.checked_aget.cljs$core$IFn$_invoke$arity$variadic = (function (array,idx,idxs){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.checked_aget,cljs.core.checked_aget.cljs$core$IFn$_invoke$arity$2(array,idx),idxs); +}); + +/** @this {Function} */ +cljs.core.checked_aget.cljs$lang$applyTo = (function (seq2653){ +var G__2654 = cljs.core.first(seq2653); +var seq2653__$1 = cljs.core.next(seq2653); +var G__2655 = cljs.core.first(seq2653__$1); +var seq2653__$2 = cljs.core.next(seq2653__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2654,G__2655,seq2653__$2); +}); + +cljs.core.checked_aget.cljs$lang$maxFixedArity = (2); + +cljs.core.checked_aset = (function cljs$core$checked_aset(var_args){ +var G__2668 = arguments.length; +switch (G__2668) { +case 3: +return cljs.core.checked_aset.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2671 = arguments.length; +var i__4731__auto___2672 = (0); +while(true){ +if((i__4731__auto___2672 < len__4730__auto___2671)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2672])); + +var G__2673 = (i__4731__auto___2672 + (1)); +i__4731__auto___2672 = G__2673; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.checked_aset.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.checked_aset.cljs$core$IFn$_invoke$arity$3 = (function (array,idx,val){ +try{if(cljs.core.truth_((function (){var or__4131__auto__ = cljs.core.array_QMARK_(array); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return goog.isArrayLike(array); +} +})())){ +} else { +throw (new Error("Assert failed: (or (array? array) (goog/isArrayLike array))")); +} + +if(typeof idx === 'number'){ +} else { +throw (new Error("Assert failed: (number? idx)")); +} + +if((!((idx < (0))))){ +} else { +throw (new Error("Assert failed: (not (neg? idx))")); +} + +if((idx < array.length)){ +} else { +throw (new Error("Assert failed: (< idx (alength array))")); +} +}catch (e2669){var e_2674 = e2669; +cljs.core.maybe_warn(e_2674); +} +return (array[idx] = val); +}); + +cljs.core.checked_aset.cljs$core$IFn$_invoke$arity$variadic = (function (array,idx,idx2,idxv){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$4(cljs.core.checked_aset,cljs.core.checked_aget.cljs$core$IFn$_invoke$arity$2(array,idx),idx2,idxv); +}); + +/** @this {Function} */ +cljs.core.checked_aset.cljs$lang$applyTo = (function (seq2664){ +var G__2665 = cljs.core.first(seq2664); +var seq2664__$1 = cljs.core.next(seq2664); +var G__2666 = cljs.core.first(seq2664__$1); +var seq2664__$2 = cljs.core.next(seq2664__$1); +var G__2667 = cljs.core.first(seq2664__$2); +var seq2664__$3 = cljs.core.next(seq2664__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2665,G__2666,G__2667,seq2664__$3); +}); + +cljs.core.checked_aset.cljs$lang$maxFixedArity = (3); + +cljs.core.checked_aget_SINGLEQUOTE_ = (function cljs$core$checked_aget_SINGLEQUOTE_(var_args){ +var G__2679 = arguments.length; +switch (G__2679) { +case 2: +return cljs.core.checked_aget_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2681 = arguments.length; +var i__4731__auto___2682 = (0); +while(true){ +if((i__4731__auto___2682 < len__4730__auto___2681)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2682])); + +var G__2683 = (i__4731__auto___2682 + (1)); +i__4731__auto___2682 = G__2683; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.checked_aget_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.checked_aget_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$2 = (function (array,idx){ +if(cljs.core.truth_((function (){var or__4131__auto__ = cljs.core.array_QMARK_(array); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return goog.isArrayLike(array); +} +})())){ +} else { +throw (new Error("Assert failed: (or (array? array) (goog/isArrayLike array))")); +} + +if(typeof idx === 'number'){ +} else { +throw (new Error("Assert failed: (number? idx)")); +} + +if((!((idx < (0))))){ +} else { +throw (new Error("Assert failed: (not (neg? idx))")); +} + +if((idx < array.length)){ +} else { +throw (new Error("Assert failed: (< idx (alength array))")); +} + +return (array[idx]); +}); + +cljs.core.checked_aget_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$variadic = (function (array,idx,idxs){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.checked_aget_SINGLEQUOTE_,cljs.core.checked_aget_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$2(array,idx),idxs); +}); + +/** @this {Function} */ +cljs.core.checked_aget_SINGLEQUOTE_.cljs$lang$applyTo = (function (seq2676){ +var G__2677 = cljs.core.first(seq2676); +var seq2676__$1 = cljs.core.next(seq2676); +var G__2678 = cljs.core.first(seq2676__$1); +var seq2676__$2 = cljs.core.next(seq2676__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2677,G__2678,seq2676__$2); +}); + +cljs.core.checked_aget_SINGLEQUOTE_.cljs$lang$maxFixedArity = (2); + +cljs.core.checked_aset_SINGLEQUOTE_ = (function cljs$core$checked_aset_SINGLEQUOTE_(var_args){ +var G__2689 = arguments.length; +switch (G__2689) { +case 3: +return cljs.core.checked_aset_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2691 = arguments.length; +var i__4731__auto___2692 = (0); +while(true){ +if((i__4731__auto___2692 < len__4730__auto___2691)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2692])); + +var G__2693 = (i__4731__auto___2692 + (1)); +i__4731__auto___2692 = G__2693; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.checked_aset_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.checked_aset_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$3 = (function (array,idx,val){ +if(cljs.core.truth_((function (){var or__4131__auto__ = cljs.core.array_QMARK_(array); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return goog.isArrayLike(array); +} +})())){ +} else { +throw (new Error("Assert failed: (or (array? array) (goog/isArrayLike array))")); +} + +if(typeof idx === 'number'){ +} else { +throw (new Error("Assert failed: (number? idx)")); +} + +if((!((idx < (0))))){ +} else { +throw (new Error("Assert failed: (not (neg? idx))")); +} + +if((idx < array.length)){ +} else { +throw (new Error("Assert failed: (< idx (alength array))")); +} + +return (array[idx] = val); +}); + +cljs.core.checked_aset_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$variadic = (function (array,idx,idx2,idxv){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$4(cljs.core.checked_aset_SINGLEQUOTE_,cljs.core.checked_aget_SINGLEQUOTE_.cljs$core$IFn$_invoke$arity$2(array,idx),idx2,idxv); +}); + +/** @this {Function} */ +cljs.core.checked_aset_SINGLEQUOTE_.cljs$lang$applyTo = (function (seq2685){ +var G__2686 = cljs.core.first(seq2685); +var seq2685__$1 = cljs.core.next(seq2685); +var G__2687 = cljs.core.first(seq2685__$1); +var seq2685__$2 = cljs.core.next(seq2685__$1); +var G__2688 = cljs.core.first(seq2685__$2); +var seq2685__$3 = cljs.core.next(seq2685__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2686,G__2687,G__2688,seq2685__$3); +}); + +cljs.core.checked_aset_SINGLEQUOTE_.cljs$lang$maxFixedArity = (3); + +/** + * Returns the value at the index/indices. Works on JavaScript arrays. + */ +cljs.core.aget = (function cljs$core$aget(var_args){ +var G__2698 = arguments.length; +switch (G__2698) { +case 2: +return cljs.core.aget.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2700 = arguments.length; +var i__4731__auto___2701 = (0); +while(true){ +if((i__4731__auto___2701 < len__4730__auto___2700)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2701])); + +var G__2702 = (i__4731__auto___2701 + (1)); +i__4731__auto___2701 = G__2702; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.aget.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.aget.cljs$core$IFn$_invoke$arity$2 = (function (array,idx){ +return (array[idx]); +}); + +cljs.core.aget.cljs$core$IFn$_invoke$arity$variadic = (function (array,idx,idxs){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.aget,(array[idx]),idxs); +}); + +/** @this {Function} */ +cljs.core.aget.cljs$lang$applyTo = (function (seq2695){ +var G__2696 = cljs.core.first(seq2695); +var seq2695__$1 = cljs.core.next(seq2695); +var G__2697 = cljs.core.first(seq2695__$1); +var seq2695__$2 = cljs.core.next(seq2695__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2696,G__2697,seq2695__$2); +}); + +cljs.core.aget.cljs$lang$maxFixedArity = (2); + +/** + * Sets the value at the index/indices. Works on JavaScript arrays. + * Returns val. + */ +cljs.core.aset = (function cljs$core$aset(var_args){ +var G__2708 = arguments.length; +switch (G__2708) { +case 3: +return cljs.core.aset.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2710 = arguments.length; +var i__4731__auto___2711 = (0); +while(true){ +if((i__4731__auto___2711 < len__4730__auto___2710)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2711])); + +var G__2712 = (i__4731__auto___2711 + (1)); +i__4731__auto___2711 = G__2712; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.aset.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.aset.cljs$core$IFn$_invoke$arity$3 = (function (array,idx,val){ +return (array[idx] = val); +}); + +cljs.core.aset.cljs$core$IFn$_invoke$arity$variadic = (function (array,idx,idx2,idxv){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$4(cljs.core.aset,(array[idx]),idx2,idxv); +}); + +/** @this {Function} */ +cljs.core.aset.cljs$lang$applyTo = (function (seq2704){ +var G__2705 = cljs.core.first(seq2704); +var seq2704__$1 = cljs.core.next(seq2704); +var G__2706 = cljs.core.first(seq2704__$1); +var seq2704__$2 = cljs.core.next(seq2704__$1); +var G__2707 = cljs.core.first(seq2704__$2); +var seq2704__$3 = cljs.core.next(seq2704__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2705,G__2706,G__2707,seq2704__$3); +}); + +cljs.core.aset.cljs$lang$maxFixedArity = (3); + +/** + * Returns the length of the array. Works on arrays of all types. + */ +cljs.core.alength = (function cljs$core$alength(array){ +return array.length; +}); +/** + * Returns an array with components set to the values in aseq. Optional type + * argument accepted for compatibility with Clojure. + */ +cljs.core.into_array = (function cljs$core$into_array(var_args){ +var G__2714 = arguments.length; +switch (G__2714) { +case 1: +return cljs.core.into_array.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.into_array.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.into_array.cljs$core$IFn$_invoke$arity$1 = (function (aseq){ +return cljs.core.into_array.cljs$core$IFn$_invoke$arity$2(null,aseq); +}); + +cljs.core.into_array.cljs$core$IFn$_invoke$arity$2 = (function (type,aseq){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (a,x){ +a.push(x); + +return a; +}),[],aseq); +}); + +cljs.core.into_array.cljs$lang$maxFixedArity = 2; + +/** + * Invoke JavaScript object method via string. Needed when the + * string is not a valid unquoted property name. + */ +cljs.core.js_invoke = (function cljs$core$js_invoke(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___2719 = arguments.length; +var i__4731__auto___2720 = (0); +while(true){ +if((i__4731__auto___2720 < len__4730__auto___2719)){ +args__4736__auto__.push((arguments[i__4731__auto___2720])); + +var G__2721 = (i__4731__auto___2720 + (1)); +i__4731__auto___2720 = G__2721; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((2) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((2)),(0),null)):null); +return cljs.core.js_invoke.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4737__auto__); +}); + +cljs.core.js_invoke.cljs$core$IFn$_invoke$arity$variadic = (function (obj,s,args){ +return (obj[s]).apply(obj,cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(args)); +}); + +cljs.core.js_invoke.cljs$lang$maxFixedArity = (2); + +/** @this {Function} */ +cljs.core.js_invoke.cljs$lang$applyTo = (function (seq2716){ +var G__2717 = cljs.core.first(seq2716); +var seq2716__$1 = cljs.core.next(seq2716); +var G__2718 = cljs.core.first(seq2716__$1); +var seq2716__$2 = cljs.core.next(seq2716__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2717,G__2718,seq2716__$2); +}); + + +/** + * Marker protocol + * @interface + */ +cljs.core.Fn = function(){}; + + +/** + * Protocol for adding the ability to invoke an object as a function. + * For example, a vector can also be used to look up a value: + * ([1 2 3 4] 1) => 2 + * @interface + */ +cljs.core.IFn = function(){}; + +cljs.core._invoke = (function cljs$core$_invoke(var_args){ +var G__2723 = arguments.length; +switch (G__2723) { +case 1: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +case 6: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$6((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)])); + +break; +case 7: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$7((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)])); + +break; +case 8: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$8((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)])); + +break; +case 9: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$9((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)])); + +break; +case 10: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$10((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)])); + +break; +case 11: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$11((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)])); + +break; +case 12: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$12((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)])); + +break; +case 13: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$13((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)])); + +break; +case 14: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$14((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)])); + +break; +case 15: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$15((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)]),(arguments[(14)])); + +break; +case 16: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$16((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)]),(arguments[(14)]),(arguments[(15)])); + +break; +case 17: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$17((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)]),(arguments[(14)]),(arguments[(15)]),(arguments[(16)])); + +break; +case 18: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$18((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)]),(arguments[(14)]),(arguments[(15)]),(arguments[(16)]),(arguments[(17)])); + +break; +case 19: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$19((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)]),(arguments[(14)]),(arguments[(15)]),(arguments[(16)]),(arguments[(17)]),(arguments[(18)])); + +break; +case 20: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$20((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)]),(arguments[(14)]),(arguments[(15)]),(arguments[(16)]),(arguments[(17)]),(arguments[(18)]),(arguments[(19)])); + +break; +case 21: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$21((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)]),(arguments[(14)]),(arguments[(15)]),(arguments[(16)]),(arguments[(17)]),(arguments[(18)]),(arguments[(19)]),(arguments[(20)])); + +break; +case 22: +return cljs.core._invoke.cljs$core$IFn$_invoke$arity$22((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)]),(arguments[(7)]),(arguments[(8)]),(arguments[(9)]),(arguments[(10)]),(arguments[(11)]),(arguments[(12)]),(arguments[(13)]),(arguments[(14)]),(arguments[(15)]),(arguments[(16)]),(arguments[(17)]),(arguments[(18)]),(arguments[(19)]),(arguments[(20)]),(arguments[(21)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$1 = (function (this$){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$1 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$1(this$); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(this$) : m__4434__auto__.call(null,this$)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(this$) : m__4431__auto__.call(null,this$)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$2 = (function (this$,a){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$2 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$2(this$,a); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(this$,a) : m__4434__auto__.call(null,this$,a)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(this$,a) : m__4431__auto__.call(null,this$,a)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$3 = (function (this$,a,b){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$3 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$3(this$,a,b); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(this$,a,b) : m__4434__auto__.call(null,this$,a,b)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(this$,a,b) : m__4431__auto__.call(null,this$,a,b)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$4 = (function (this$,a,b,c){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$4 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$4(this$,a,b,c); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$4 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$4(this$,a,b,c) : m__4434__auto__.call(null,this$,a,b,c)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$4 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$4(this$,a,b,c) : m__4431__auto__.call(null,this$,a,b,c)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$5 = (function (this$,a,b,c,d){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$5 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$5(this$,a,b,c,d); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$5 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$5(this$,a,b,c,d) : m__4434__auto__.call(null,this$,a,b,c,d)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$5 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$5(this$,a,b,c,d) : m__4431__auto__.call(null,this$,a,b,c,d)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$6 = (function (this$,a,b,c,d,e){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$6 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$6(this$,a,b,c,d,e); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$6 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$6(this$,a,b,c,d,e) : m__4434__auto__.call(null,this$,a,b,c,d,e)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$6 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$6(this$,a,b,c,d,e) : m__4431__auto__.call(null,this$,a,b,c,d,e)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$7 = (function (this$,a,b,c,d,e,f){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$7 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$7(this$,a,b,c,d,e,f); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$7 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$7(this$,a,b,c,d,e,f) : m__4434__auto__.call(null,this$,a,b,c,d,e,f)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$7 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$7(this$,a,b,c,d,e,f) : m__4431__auto__.call(null,this$,a,b,c,d,e,f)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$8 = (function (this$,a,b,c,d,e,f,g){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$8 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$8(this$,a,b,c,d,e,f,g); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$8 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$8(this$,a,b,c,d,e,f,g) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$8 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$8(this$,a,b,c,d,e,f,g) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$9 = (function (this$,a,b,c,d,e,f,g,h){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$9 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$9(this$,a,b,c,d,e,f,g,h); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$9 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$9(this$,a,b,c,d,e,f,g,h) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$9 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$9(this$,a,b,c,d,e,f,g,h) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$10 = (function (this$,a,b,c,d,e,f,g,h,i){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$10 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$10(this$,a,b,c,d,e,f,g,h,i); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$10 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$10(this$,a,b,c,d,e,f,g,h,i) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$10 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$10(this$,a,b,c,d,e,f,g,h,i) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$11 = (function (this$,a,b,c,d,e,f,g,h,i,j){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$11 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$11(this$,a,b,c,d,e,f,g,h,i,j); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$11 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$11(this$,a,b,c,d,e,f,g,h,i,j) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$11 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$11(this$,a,b,c,d,e,f,g,h,i,j) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$12 = (function (this$,a,b,c,d,e,f,g,h,i,j,k){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$12 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$12(this$,a,b,c,d,e,f,g,h,i,j,k); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$12 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$12(this$,a,b,c,d,e,f,g,h,i,j,k) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$12 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$12(this$,a,b,c,d,e,f,g,h,i,j,k) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$13 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$13 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$13(this$,a,b,c,d,e,f,g,h,i,j,k,l); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$13 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$13(this$,a,b,c,d,e,f,g,h,i,j,k,l) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$13 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$13(this$,a,b,c,d,e,f,g,h,i,j,k,l) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$14 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$14 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$14(this$,a,b,c,d,e,f,g,h,i,j,k,l,m); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$14 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$14(this$,a,b,c,d,e,f,g,h,i,j,k,l,m) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$14 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$14(this$,a,b,c,d,e,f,g,h,i,j,k,l,m) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$15 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$15 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$15(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$15 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$15(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$15 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$15(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$16 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$16 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$16(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$16 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$16(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$16 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$16(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$17 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$17 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$17(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$17 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$17(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$17 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$17(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$18 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$18 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$18(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$18 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$18(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$18 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$18(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$19 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$19 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$19(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$19 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$19(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$19 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$19(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$20 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$20 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$20(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$20 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$20(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$20 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$20(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$21 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$21 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$21(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$21 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$21(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$21 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$21(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$core$IFn$_invoke$arity$22 = (function (this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IFn$_invoke$arity$22 == null)))))){ +return this$.cljs$core$IFn$_invoke$arity$22(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._invoke[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$22 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$22(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest) : m__4434__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest)); +} else { +var m__4431__auto__ = (cljs.core._invoke["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$22 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$22(this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest) : m__4431__auto__.call(null,this$,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest)); +} else { +throw cljs.core.missing_protocol("IFn.-invoke",this$); +} +} +} +}); + +cljs.core._invoke.cljs$lang$maxFixedArity = 22; + + + +/** + * Protocol for cloning a value. + * @interface + */ +cljs.core.ICloneable = function(){}; + +/** + * Creates a clone of value. + */ +cljs.core._clone = (function cljs$core$_clone(value){ +if((((!((value == null)))) && ((!((value.cljs$core$ICloneable$_clone$arity$1 == null)))))){ +return value.cljs$core$ICloneable$_clone$arity$1(value); +} else { +var x__4433__auto__ = (((value == null))?null:value); +var m__4434__auto__ = (cljs.core._clone[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(value) : m__4434__auto__.call(null,value)); +} else { +var m__4431__auto__ = (cljs.core._clone["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(value) : m__4431__auto__.call(null,value)); +} else { +throw cljs.core.missing_protocol("ICloneable.-clone",value); +} +} +} +}); + + +/** + * Protocol for adding the ability to count a collection in constant time. + * @interface + */ +cljs.core.ICounted = function(){}; + +/** + * Calculates the count of coll in constant time. Used by cljs.core/count. + */ +cljs.core._count = (function cljs$core$_count(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ICounted$_count$arity$1 == null)))))){ +return coll.cljs$core$ICounted$_count$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._count[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._count["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("ICounted.-count",coll); +} +} +} +}); + + +/** + * Protocol for creating an empty collection. + * @interface + */ +cljs.core.IEmptyableCollection = function(){}; + +/** + * Returns an empty collection of the same category as coll. Used + * by cljs.core/empty. + */ +cljs.core._empty = (function cljs$core$_empty(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IEmptyableCollection$_empty$arity$1 == null)))))){ +return coll.cljs$core$IEmptyableCollection$_empty$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._empty[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._empty["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IEmptyableCollection.-empty",coll); +} +} +} +}); + + +/** + * Protocol for adding to a collection. + * @interface + */ +cljs.core.ICollection = function(){}; + +/** + * Returns a new collection of coll with o added to it. The new item + * should be added to the most efficient place, e.g. + * (conj [1 2 3 4] 5) => [1 2 3 4 5] + * (conj '(2 3 4 5) 1) => '(1 2 3 4 5) + */ +cljs.core._conj = (function cljs$core$_conj(coll,o){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ICollection$_conj$arity$2 == null)))))){ +return coll.cljs$core$ICollection$_conj$arity$2(coll,o); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._conj[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,o) : m__4434__auto__.call(null,coll,o)); +} else { +var m__4431__auto__ = (cljs.core._conj["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,o) : m__4431__auto__.call(null,coll,o)); +} else { +throw cljs.core.missing_protocol("ICollection.-conj",coll); +} +} +} +}); + + +/** + * Protocol for collections to provide indexed-based access to their items. + * @interface + */ +cljs.core.IIndexed = function(){}; + +/** + * Returns the value at the index n in the collection coll. + * Returns not-found if index n is out of bounds and not-found is supplied. + */ +cljs.core._nth = (function cljs$core$_nth(var_args){ +var G__2726 = arguments.length; +switch (G__2726) { +case 2: +return cljs.core._nth.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core._nth.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core._nth.cljs$core$IFn$_invoke$arity$2 = (function (coll,n){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IIndexed$_nth$arity$2 == null)))))){ +return coll.cljs$core$IIndexed$_nth$arity$2(coll,n); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._nth[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,n) : m__4434__auto__.call(null,coll,n)); +} else { +var m__4431__auto__ = (cljs.core._nth["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,n) : m__4431__auto__.call(null,coll,n)); +} else { +throw cljs.core.missing_protocol("IIndexed.-nth",coll); +} +} +} +}); + +cljs.core._nth.cljs$core$IFn$_invoke$arity$3 = (function (coll,n,not_found){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IIndexed$_nth$arity$3 == null)))))){ +return coll.cljs$core$IIndexed$_nth$arity$3(coll,n,not_found); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._nth[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(coll,n,not_found) : m__4434__auto__.call(null,coll,n,not_found)); +} else { +var m__4431__auto__ = (cljs.core._nth["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(coll,n,not_found) : m__4431__auto__.call(null,coll,n,not_found)); +} else { +throw cljs.core.missing_protocol("IIndexed.-nth",coll); +} +} +} +}); + +cljs.core._nth.cljs$lang$maxFixedArity = 3; + + + +/** + * Marker protocol indicating an array sequence. + * @interface + */ +cljs.core.ASeq = function(){}; + + +/** + * Protocol for collections to provide access to their items as sequences. + * @interface + */ +cljs.core.ISeq = function(){}; + +/** + * Returns the first item in the collection coll. Used by cljs.core/first. + */ +cljs.core._first = (function cljs$core$_first(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ISeq$_first$arity$1 == null)))))){ +return coll.cljs$core$ISeq$_first$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._first[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._first["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("ISeq.-first",coll); +} +} +} +}); + +/** + * Returns a new collection of coll without the first item. It should + * always return a seq, e.g. + * (rest []) => () + * (rest nil) => () + */ +cljs.core._rest = (function cljs$core$_rest(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ISeq$_rest$arity$1 == null)))))){ +return coll.cljs$core$ISeq$_rest$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._rest[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._rest["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("ISeq.-rest",coll); +} +} +} +}); + + +/** + * Protocol for accessing the next items of a collection. + * @interface + */ +cljs.core.INext = function(){}; + +/** + * Returns a new collection of coll without the first item. In contrast to + * rest, it should return nil if there are no more items, e.g. + * (next []) => nil + * (next nil) => nil + */ +cljs.core._next = (function cljs$core$_next(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$INext$_next$arity$1 == null)))))){ +return coll.cljs$core$INext$_next$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._next[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._next["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("INext.-next",coll); +} +} +} +}); + + +/** + * Protocol for looking up a value in a data structure. + * @interface + */ +cljs.core.ILookup = function(){}; + +/** + * Use k to look up a value in o. If not-found is supplied and k is not + * a valid value that can be used for look up, not-found is returned. + */ +cljs.core._lookup = (function cljs$core$_lookup(var_args){ +var G__2729 = arguments.length; +switch (G__2729) { +case 2: +return cljs.core._lookup.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core._lookup.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core._lookup.cljs$core$IFn$_invoke$arity$2 = (function (o,k){ +if((((!((o == null)))) && ((!((o.cljs$core$ILookup$_lookup$arity$2 == null)))))){ +return o.cljs$core$ILookup$_lookup$arity$2(o,k); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._lookup[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(o,k) : m__4434__auto__.call(null,o,k)); +} else { +var m__4431__auto__ = (cljs.core._lookup["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(o,k) : m__4431__auto__.call(null,o,k)); +} else { +throw cljs.core.missing_protocol("ILookup.-lookup",o); +} +} +} +}); + +cljs.core._lookup.cljs$core$IFn$_invoke$arity$3 = (function (o,k,not_found){ +if((((!((o == null)))) && ((!((o.cljs$core$ILookup$_lookup$arity$3 == null)))))){ +return o.cljs$core$ILookup$_lookup$arity$3(o,k,not_found); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._lookup[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(o,k,not_found) : m__4434__auto__.call(null,o,k,not_found)); +} else { +var m__4431__auto__ = (cljs.core._lookup["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(o,k,not_found) : m__4431__auto__.call(null,o,k,not_found)); +} else { +throw cljs.core.missing_protocol("ILookup.-lookup",o); +} +} +} +}); + +cljs.core._lookup.cljs$lang$maxFixedArity = 3; + + + +/** + * Protocol for adding associativity to collections. + * @interface + */ +cljs.core.IAssociative = function(){}; + +/** + * Returns true if k is a key in coll. + */ +cljs.core._contains_key_QMARK_ = (function cljs$core$_contains_key_QMARK_(coll,k){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 == null)))))){ +return coll.cljs$core$IAssociative$_contains_key_QMARK_$arity$2(coll,k); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._contains_key_QMARK_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,k) : m__4434__auto__.call(null,coll,k)); +} else { +var m__4431__auto__ = (cljs.core._contains_key_QMARK_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,k) : m__4431__auto__.call(null,coll,k)); +} else { +throw cljs.core.missing_protocol("IAssociative.-contains-key?",coll); +} +} +} +}); + +/** + * Returns a new collection of coll with a mapping from key k to + * value v added to it. + */ +cljs.core._assoc = (function cljs$core$_assoc(coll,k,v){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IAssociative$_assoc$arity$3 == null)))))){ +return coll.cljs$core$IAssociative$_assoc$arity$3(coll,k,v); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._assoc[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(coll,k,v) : m__4434__auto__.call(null,coll,k,v)); +} else { +var m__4431__auto__ = (cljs.core._assoc["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(coll,k,v) : m__4431__auto__.call(null,coll,k,v)); +} else { +throw cljs.core.missing_protocol("IAssociative.-assoc",coll); +} +} +} +}); + + +/** + * Protocol for implementing entry finding in collections. + * @interface + */ +cljs.core.IFind = function(){}; + +/** + * Returns the map entry for key, or nil if key not present. + */ +cljs.core._find = (function cljs$core$_find(coll,k){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IFind$_find$arity$2 == null)))))){ +return coll.cljs$core$IFind$_find$arity$2(coll,k); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._find[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,k) : m__4434__auto__.call(null,coll,k)); +} else { +var m__4431__auto__ = (cljs.core._find["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,k) : m__4431__auto__.call(null,coll,k)); +} else { +throw cljs.core.missing_protocol("IFind.-find",coll); +} +} +} +}); + + +/** + * Protocol for adding mapping functionality to collections. + * @interface + */ +cljs.core.IMap = function(){}; + +/** + * Returns a new collection of coll without the mapping for key k. + */ +cljs.core._dissoc = (function cljs$core$_dissoc(coll,k){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IMap$_dissoc$arity$2 == null)))))){ +return coll.cljs$core$IMap$_dissoc$arity$2(coll,k); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._dissoc[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,k) : m__4434__auto__.call(null,coll,k)); +} else { +var m__4431__auto__ = (cljs.core._dissoc["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,k) : m__4431__auto__.call(null,coll,k)); +} else { +throw cljs.core.missing_protocol("IMap.-dissoc",coll); +} +} +} +}); + + +/** + * Protocol for examining a map entry. + * @interface + */ +cljs.core.IMapEntry = function(){}; + +/** + * Returns the key of the map entry. + */ +cljs.core._key = (function cljs$core$_key(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IMapEntry$_key$arity$1 == null)))))){ +return coll.cljs$core$IMapEntry$_key$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._key[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._key["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IMapEntry.-key",coll); +} +} +} +}); + +/** + * Returns the value of the map entry. + */ +cljs.core._val = (function cljs$core$_val(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IMapEntry$_val$arity$1 == null)))))){ +return coll.cljs$core$IMapEntry$_val$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._val[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._val["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IMapEntry.-val",coll); +} +} +} +}); + + +/** + * Protocol for adding set functionality to a collection. + * @interface + */ +cljs.core.ISet = function(){}; + +/** + * Returns a new collection of coll that does not contain v. + */ +cljs.core._disjoin = (function cljs$core$_disjoin(coll,v){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ISet$_disjoin$arity$2 == null)))))){ +return coll.cljs$core$ISet$_disjoin$arity$2(coll,v); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._disjoin[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,v) : m__4434__auto__.call(null,coll,v)); +} else { +var m__4431__auto__ = (cljs.core._disjoin["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,v) : m__4431__auto__.call(null,coll,v)); +} else { +throw cljs.core.missing_protocol("ISet.-disjoin",coll); +} +} +} +}); + + +/** + * Protocol for collections to provide access to their items as stacks. The top + * of the stack should be accessed in the most efficient way for the different + * data structures. + * @interface + */ +cljs.core.IStack = function(){}; + +/** + * Returns the item from the top of the stack. Is used by cljs.core/peek. + */ +cljs.core._peek = (function cljs$core$_peek(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IStack$_peek$arity$1 == null)))))){ +return coll.cljs$core$IStack$_peek$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._peek[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._peek["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IStack.-peek",coll); +} +} +} +}); + +/** + * Returns a new stack without the item on top of the stack. Is used + * by cljs.core/pop. + */ +cljs.core._pop = (function cljs$core$_pop(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IStack$_pop$arity$1 == null)))))){ +return coll.cljs$core$IStack$_pop$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._pop[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._pop["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IStack.-pop",coll); +} +} +} +}); + + +/** + * Protocol for adding vector functionality to collections. + * @interface + */ +cljs.core.IVector = function(){}; + +/** + * Returns a new vector with value val added at position n. + */ +cljs.core._assoc_n = (function cljs$core$_assoc_n(coll,n,val){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IVector$_assoc_n$arity$3 == null)))))){ +return coll.cljs$core$IVector$_assoc_n$arity$3(coll,n,val); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._assoc_n[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(coll,n,val) : m__4434__auto__.call(null,coll,n,val)); +} else { +var m__4431__auto__ = (cljs.core._assoc_n["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(coll,n,val) : m__4431__auto__.call(null,coll,n,val)); +} else { +throw cljs.core.missing_protocol("IVector.-assoc-n",coll); +} +} +} +}); + + +/** + * Protocol for adding dereference functionality to a reference. + * @interface + */ +cljs.core.IDeref = function(){}; + +/** + * Returns the value of the reference o. + */ +cljs.core._deref = (function cljs$core$_deref(o){ +if((((!((o == null)))) && ((!((o.cljs$core$IDeref$_deref$arity$1 == null)))))){ +return o.cljs$core$IDeref$_deref$arity$1(o); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._deref[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(o) : m__4434__auto__.call(null,o)); +} else { +var m__4431__auto__ = (cljs.core._deref["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(o) : m__4431__auto__.call(null,o)); +} else { +throw cljs.core.missing_protocol("IDeref.-deref",o); +} +} +} +}); + + +/** + * @interface + */ +cljs.core.IDerefWithTimeout = function(){}; + +cljs.core._deref_with_timeout = (function cljs$core$_deref_with_timeout(o,msec,timeout_val){ +if((((!((o == null)))) && ((!((o.cljs$core$IDerefWithTimeout$_deref_with_timeout$arity$3 == null)))))){ +return o.cljs$core$IDerefWithTimeout$_deref_with_timeout$arity$3(o,msec,timeout_val); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._deref_with_timeout[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(o,msec,timeout_val) : m__4434__auto__.call(null,o,msec,timeout_val)); +} else { +var m__4431__auto__ = (cljs.core._deref_with_timeout["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(o,msec,timeout_val) : m__4431__auto__.call(null,o,msec,timeout_val)); +} else { +throw cljs.core.missing_protocol("IDerefWithTimeout.-deref-with-timeout",o); +} +} +} +}); + + +/** + * Protocol for accessing the metadata of an object. + * @interface + */ +cljs.core.IMeta = function(){}; + +/** + * Returns the metadata of object o. + */ +cljs.core._meta = (function cljs$core$_meta(o){ +if((((!((o == null)))) && ((!((o.cljs$core$IMeta$_meta$arity$1 == null)))))){ +return o.cljs$core$IMeta$_meta$arity$1(o); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._meta[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(o) : m__4434__auto__.call(null,o)); +} else { +var m__4431__auto__ = (cljs.core._meta["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(o) : m__4431__auto__.call(null,o)); +} else { +throw cljs.core.missing_protocol("IMeta.-meta",o); +} +} +} +}); + + +/** + * Protocol for adding metadata to an object. + * @interface + */ +cljs.core.IWithMeta = function(){}; + +/** + * Returns a new object with value of o and metadata meta added to it. + */ +cljs.core._with_meta = (function cljs$core$_with_meta(o,meta){ +if((((!((o == null)))) && ((!((o.cljs$core$IWithMeta$_with_meta$arity$2 == null)))))){ +return o.cljs$core$IWithMeta$_with_meta$arity$2(o,meta); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._with_meta[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(o,meta) : m__4434__auto__.call(null,o,meta)); +} else { +var m__4431__auto__ = (cljs.core._with_meta["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(o,meta) : m__4431__auto__.call(null,o,meta)); +} else { +throw cljs.core.missing_protocol("IWithMeta.-with-meta",o); +} +} +} +}); + + +/** + * Protocol for seq types that can reduce themselves. + * Called by cljs.core/reduce. + * @interface + */ +cljs.core.IReduce = function(){}; + +/** + * f should be a function of 2 arguments. If start is not supplied, + * returns the result of applying f to the first 2 items in coll, then + * applying f to that result and the 3rd item, etc. + */ +cljs.core._reduce = (function cljs$core$_reduce(var_args){ +var G__2732 = arguments.length; +switch (G__2732) { +case 2: +return cljs.core._reduce.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core._reduce.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core._reduce.cljs$core$IFn$_invoke$arity$2 = (function (coll,f){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IReduce$_reduce$arity$2 == null)))))){ +return coll.cljs$core$IReduce$_reduce$arity$2(coll,f); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._reduce[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,f) : m__4434__auto__.call(null,coll,f)); +} else { +var m__4431__auto__ = (cljs.core._reduce["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,f) : m__4431__auto__.call(null,coll,f)); +} else { +throw cljs.core.missing_protocol("IReduce.-reduce",coll); +} +} +} +}); + +cljs.core._reduce.cljs$core$IFn$_invoke$arity$3 = (function (coll,f,start){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IReduce$_reduce$arity$3 == null)))))){ +return coll.cljs$core$IReduce$_reduce$arity$3(coll,f,start); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._reduce[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(coll,f,start) : m__4434__auto__.call(null,coll,f,start)); +} else { +var m__4431__auto__ = (cljs.core._reduce["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(coll,f,start) : m__4431__auto__.call(null,coll,f,start)); +} else { +throw cljs.core.missing_protocol("IReduce.-reduce",coll); +} +} +} +}); + +cljs.core._reduce.cljs$lang$maxFixedArity = 3; + + + +/** + * Protocol for associative types that can reduce themselves + * via a function of key and val. Called by cljs.core/reduce-kv. + * @interface + */ +cljs.core.IKVReduce = function(){}; + +/** + * Reduces an associative collection and returns the result. f should be + * a function that takes three arguments. + */ +cljs.core._kv_reduce = (function cljs$core$_kv_reduce(coll,f,init){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IKVReduce$_kv_reduce$arity$3 == null)))))){ +return coll.cljs$core$IKVReduce$_kv_reduce$arity$3(coll,f,init); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._kv_reduce[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(coll,f,init) : m__4434__auto__.call(null,coll,f,init)); +} else { +var m__4431__auto__ = (cljs.core._kv_reduce["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(coll,f,init) : m__4431__auto__.call(null,coll,f,init)); +} else { +throw cljs.core.missing_protocol("IKVReduce.-kv-reduce",coll); +} +} +} +}); + + +/** + * Protocol for adding value comparison functionality to a type. + * @interface + */ +cljs.core.IEquiv = function(){}; + +/** + * Returns true if o and other are equal, false otherwise. + */ +cljs.core._equiv = (function cljs$core$_equiv(o,other){ +if((((!((o == null)))) && ((!((o.cljs$core$IEquiv$_equiv$arity$2 == null)))))){ +return o.cljs$core$IEquiv$_equiv$arity$2(o,other); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._equiv[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(o,other) : m__4434__auto__.call(null,o,other)); +} else { +var m__4431__auto__ = (cljs.core._equiv["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(o,other) : m__4431__auto__.call(null,o,other)); +} else { +throw cljs.core.missing_protocol("IEquiv.-equiv",o); +} +} +} +}); + + +/** + * Protocol for adding hashing functionality to a type. + * @interface + */ +cljs.core.IHash = function(){}; + +/** + * Returns the hash code of o. + */ +cljs.core._hash = (function cljs$core$_hash(o){ +if((((!((o == null)))) && ((!((o.cljs$core$IHash$_hash$arity$1 == null)))))){ +return o.cljs$core$IHash$_hash$arity$1(o); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._hash[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(o) : m__4434__auto__.call(null,o)); +} else { +var m__4431__auto__ = (cljs.core._hash["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(o) : m__4431__auto__.call(null,o)); +} else { +throw cljs.core.missing_protocol("IHash.-hash",o); +} +} +} +}); + + +/** + * Protocol for adding the ability to a type to be transformed into a sequence. + * @interface + */ +cljs.core.ISeqable = function(){}; + +/** + * Returns a seq of o, or nil if o is empty. + */ +cljs.core._seq = (function cljs$core$_seq(o){ +if((((!((o == null)))) && ((!((o.cljs$core$ISeqable$_seq$arity$1 == null)))))){ +return o.cljs$core$ISeqable$_seq$arity$1(o); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._seq[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(o) : m__4434__auto__.call(null,o)); +} else { +var m__4431__auto__ = (cljs.core._seq["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(o) : m__4431__auto__.call(null,o)); +} else { +throw cljs.core.missing_protocol("ISeqable.-seq",o); +} +} +} +}); + + +/** + * Marker interface indicating a persistent collection of sequential items + * @interface + */ +cljs.core.ISequential = function(){}; + + +/** + * Marker interface indicating a persistent list + * @interface + */ +cljs.core.IList = function(){}; + + +/** + * Marker interface indicating a record object + * @interface + */ +cljs.core.IRecord = function(){}; + + +/** + * Protocol for reversing a seq. + * @interface + */ +cljs.core.IReversible = function(){}; + +/** + * Returns a seq of the items in coll in reversed order. + */ +cljs.core._rseq = (function cljs$core$_rseq(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IReversible$_rseq$arity$1 == null)))))){ +return coll.cljs$core$IReversible$_rseq$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._rseq[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._rseq["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IReversible.-rseq",coll); +} +} +} +}); + + +/** + * Protocol for a collection which can represent their items + * in a sorted manner. + * @interface + */ +cljs.core.ISorted = function(){}; + +/** + * Returns a sorted seq from coll in either ascending or descending order. + */ +cljs.core._sorted_seq = (function cljs$core$_sorted_seq(coll,ascending_QMARK_){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ISorted$_sorted_seq$arity$2 == null)))))){ +return coll.cljs$core$ISorted$_sorted_seq$arity$2(coll,ascending_QMARK_); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._sorted_seq[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,ascending_QMARK_) : m__4434__auto__.call(null,coll,ascending_QMARK_)); +} else { +var m__4431__auto__ = (cljs.core._sorted_seq["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,ascending_QMARK_) : m__4431__auto__.call(null,coll,ascending_QMARK_)); +} else { +throw cljs.core.missing_protocol("ISorted.-sorted-seq",coll); +} +} +} +}); + +/** + * Returns a sorted seq from coll in either ascending or descending order. + * If ascending is true, the result should contain all items which are > or >= + * than k. If ascending is false, the result should contain all items which + * are < or <= than k, e.g. + * (-sorted-seq-from (sorted-set 1 2 3 4 5) 3 true) => (3 4 5) + * (-sorted-seq-from (sorted-set 1 2 3 4 5) 3 false) => (3 2 1) + */ +cljs.core._sorted_seq_from = (function cljs$core$_sorted_seq_from(coll,k,ascending_QMARK_){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ISorted$_sorted_seq_from$arity$3 == null)))))){ +return coll.cljs$core$ISorted$_sorted_seq_from$arity$3(coll,k,ascending_QMARK_); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._sorted_seq_from[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(coll,k,ascending_QMARK_) : m__4434__auto__.call(null,coll,k,ascending_QMARK_)); +} else { +var m__4431__auto__ = (cljs.core._sorted_seq_from["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(coll,k,ascending_QMARK_) : m__4431__auto__.call(null,coll,k,ascending_QMARK_)); +} else { +throw cljs.core.missing_protocol("ISorted.-sorted-seq-from",coll); +} +} +} +}); + +/** + * Returns the key for entry. + */ +cljs.core._entry_key = (function cljs$core$_entry_key(coll,entry){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ISorted$_entry_key$arity$2 == null)))))){ +return coll.cljs$core$ISorted$_entry_key$arity$2(coll,entry); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._entry_key[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(coll,entry) : m__4434__auto__.call(null,coll,entry)); +} else { +var m__4431__auto__ = (cljs.core._entry_key["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(coll,entry) : m__4431__auto__.call(null,coll,entry)); +} else { +throw cljs.core.missing_protocol("ISorted.-entry-key",coll); +} +} +} +}); + +/** + * Returns the comparator for coll. + */ +cljs.core._comparator = (function cljs$core$_comparator(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$ISorted$_comparator$arity$1 == null)))))){ +return coll.cljs$core$ISorted$_comparator$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._comparator[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._comparator["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("ISorted.-comparator",coll); +} +} +} +}); + + +/** + * Protocol for writing. Currently only implemented by StringBufferWriter. + * @interface + */ +cljs.core.IWriter = function(){}; + +/** + * Writes s with writer and returns the result. + */ +cljs.core._write = (function cljs$core$_write(writer,s){ +if((((!((writer == null)))) && ((!((writer.cljs$core$IWriter$_write$arity$2 == null)))))){ +return writer.cljs$core$IWriter$_write$arity$2(writer,s); +} else { +var x__4433__auto__ = (((writer == null))?null:writer); +var m__4434__auto__ = (cljs.core._write[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(writer,s) : m__4434__auto__.call(null,writer,s)); +} else { +var m__4431__auto__ = (cljs.core._write["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(writer,s) : m__4431__auto__.call(null,writer,s)); +} else { +throw cljs.core.missing_protocol("IWriter.-write",writer); +} +} +} +}); + +/** + * Flush writer. + */ +cljs.core._flush = (function cljs$core$_flush(writer){ +if((((!((writer == null)))) && ((!((writer.cljs$core$IWriter$_flush$arity$1 == null)))))){ +return writer.cljs$core$IWriter$_flush$arity$1(writer); +} else { +var x__4433__auto__ = (((writer == null))?null:writer); +var m__4434__auto__ = (cljs.core._flush[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(writer) : m__4434__auto__.call(null,writer)); +} else { +var m__4431__auto__ = (cljs.core._flush["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(writer) : m__4431__auto__.call(null,writer)); +} else { +throw cljs.core.missing_protocol("IWriter.-flush",writer); +} +} +} +}); + + +/** + * The old IPrintable protocol's implementation consisted of building a giant + * list of strings to concatenate. This involved lots of concat calls, + * intermediate vectors, and lazy-seqs, and was very slow in some older JS + * engines. IPrintWithWriter implements printing via the IWriter protocol, so it + * be implemented efficiently in terms of e.g. a StringBuffer append. + * @interface + */ +cljs.core.IPrintWithWriter = function(){}; + +cljs.core._pr_writer = (function cljs$core$_pr_writer(o,writer,opts){ +if((((!((o == null)))) && ((!((o.cljs$core$IPrintWithWriter$_pr_writer$arity$3 == null)))))){ +return o.cljs$core$IPrintWithWriter$_pr_writer$arity$3(o,writer,opts); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._pr_writer[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(o,writer,opts) : m__4434__auto__.call(null,o,writer,opts)); +} else { +var m__4431__auto__ = (cljs.core._pr_writer["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(o,writer,opts) : m__4431__auto__.call(null,o,writer,opts)); +} else { +throw cljs.core.missing_protocol("IPrintWithWriter.-pr-writer",o); +} +} +} +}); + + +/** + * Protocol for types which can have a deferred realization. Currently only + * implemented by Delay and LazySeq. + * @interface + */ +cljs.core.IPending = function(){}; + +/** + * Returns true if a value for x has been produced, false otherwise. + */ +cljs.core._realized_QMARK_ = (function cljs$core$_realized_QMARK_(x){ +if((((!((x == null)))) && ((!((x.cljs$core$IPending$_realized_QMARK_$arity$1 == null)))))){ +return x.cljs$core$IPending$_realized_QMARK_$arity$1(x); +} else { +var x__4433__auto__ = (((x == null))?null:x); +var m__4434__auto__ = (cljs.core._realized_QMARK_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4434__auto__.call(null,x)); +} else { +var m__4431__auto__ = (cljs.core._realized_QMARK_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4431__auto__.call(null,x)); +} else { +throw cljs.core.missing_protocol("IPending.-realized?",x); +} +} +} +}); + + +/** + * Protocol for types that can be watched. Currently only implemented by Atom. + * @interface + */ +cljs.core.IWatchable = function(){}; + +/** + * Calls all watchers with this, oldval and newval. + */ +cljs.core._notify_watches = (function cljs$core$_notify_watches(this$,oldval,newval){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IWatchable$_notify_watches$arity$3 == null)))))){ +return this$.cljs$core$IWatchable$_notify_watches$arity$3(this$,oldval,newval); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._notify_watches[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(this$,oldval,newval) : m__4434__auto__.call(null,this$,oldval,newval)); +} else { +var m__4431__auto__ = (cljs.core._notify_watches["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(this$,oldval,newval) : m__4431__auto__.call(null,this$,oldval,newval)); +} else { +throw cljs.core.missing_protocol("IWatchable.-notify-watches",this$); +} +} +} +}); + +/** + * Adds a watcher function f to this. Keys must be unique per reference, + * and can be used to remove the watch with -remove-watch. + */ +cljs.core._add_watch = (function cljs$core$_add_watch(this$,key,f){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IWatchable$_add_watch$arity$3 == null)))))){ +return this$.cljs$core$IWatchable$_add_watch$arity$3(this$,key,f); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._add_watch[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(this$,key,f) : m__4434__auto__.call(null,this$,key,f)); +} else { +var m__4431__auto__ = (cljs.core._add_watch["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(this$,key,f) : m__4431__auto__.call(null,this$,key,f)); +} else { +throw cljs.core.missing_protocol("IWatchable.-add-watch",this$); +} +} +} +}); + +/** + * Removes watcher that corresponds to key from this. + */ +cljs.core._remove_watch = (function cljs$core$_remove_watch(this$,key){ +if((((!((this$ == null)))) && ((!((this$.cljs$core$IWatchable$_remove_watch$arity$2 == null)))))){ +return this$.cljs$core$IWatchable$_remove_watch$arity$2(this$,key); +} else { +var x__4433__auto__ = (((this$ == null))?null:this$); +var m__4434__auto__ = (cljs.core._remove_watch[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(this$,key) : m__4434__auto__.call(null,this$,key)); +} else { +var m__4431__auto__ = (cljs.core._remove_watch["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(this$,key) : m__4431__auto__.call(null,this$,key)); +} else { +throw cljs.core.missing_protocol("IWatchable.-remove-watch",this$); +} +} +} +}); + + +/** + * Protocol for collections which can transformed to transients. + * @interface + */ +cljs.core.IEditableCollection = function(){}; + +/** + * Returns a new, transient version of the collection, in constant time. + */ +cljs.core._as_transient = (function cljs$core$_as_transient(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IEditableCollection$_as_transient$arity$1 == null)))))){ +return coll.cljs$core$IEditableCollection$_as_transient$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._as_transient[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._as_transient["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IEditableCollection.-as-transient",coll); +} +} +} +}); + + +/** + * Protocol for adding basic functionality to transient collections. + * @interface + */ +cljs.core.ITransientCollection = function(){}; + +/** + * Adds value val to tcoll and returns tcoll. + */ +cljs.core._conj_BANG_ = (function cljs$core$_conj_BANG_(tcoll,val){ +if((((!((tcoll == null)))) && ((!((tcoll.cljs$core$ITransientCollection$_conj_BANG_$arity$2 == null)))))){ +return tcoll.cljs$core$ITransientCollection$_conj_BANG_$arity$2(tcoll,val); +} else { +var x__4433__auto__ = (((tcoll == null))?null:tcoll); +var m__4434__auto__ = (cljs.core._conj_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(tcoll,val) : m__4434__auto__.call(null,tcoll,val)); +} else { +var m__4431__auto__ = (cljs.core._conj_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(tcoll,val) : m__4431__auto__.call(null,tcoll,val)); +} else { +throw cljs.core.missing_protocol("ITransientCollection.-conj!",tcoll); +} +} +} +}); + +/** + * Creates a persistent data structure from tcoll and returns it. + */ +cljs.core._persistent_BANG_ = (function cljs$core$_persistent_BANG_(tcoll){ +if((((!((tcoll == null)))) && ((!((tcoll.cljs$core$ITransientCollection$_persistent_BANG_$arity$1 == null)))))){ +return tcoll.cljs$core$ITransientCollection$_persistent_BANG_$arity$1(tcoll); +} else { +var x__4433__auto__ = (((tcoll == null))?null:tcoll); +var m__4434__auto__ = (cljs.core._persistent_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(tcoll) : m__4434__auto__.call(null,tcoll)); +} else { +var m__4431__auto__ = (cljs.core._persistent_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(tcoll) : m__4431__auto__.call(null,tcoll)); +} else { +throw cljs.core.missing_protocol("ITransientCollection.-persistent!",tcoll); +} +} +} +}); + + +/** + * Protocol for adding associativity to transient collections. + * @interface + */ +cljs.core.ITransientAssociative = function(){}; + +/** + * Returns a new transient collection of tcoll with a mapping from key to + * val added to it. + */ +cljs.core._assoc_BANG_ = (function cljs$core$_assoc_BANG_(tcoll,key,val){ +if((((!((tcoll == null)))) && ((!((tcoll.cljs$core$ITransientAssociative$_assoc_BANG_$arity$3 == null)))))){ +return tcoll.cljs$core$ITransientAssociative$_assoc_BANG_$arity$3(tcoll,key,val); +} else { +var x__4433__auto__ = (((tcoll == null))?null:tcoll); +var m__4434__auto__ = (cljs.core._assoc_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(tcoll,key,val) : m__4434__auto__.call(null,tcoll,key,val)); +} else { +var m__4431__auto__ = (cljs.core._assoc_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(tcoll,key,val) : m__4431__auto__.call(null,tcoll,key,val)); +} else { +throw cljs.core.missing_protocol("ITransientAssociative.-assoc!",tcoll); +} +} +} +}); + + +/** + * Protocol for adding mapping functionality to transient collections. + * @interface + */ +cljs.core.ITransientMap = function(){}; + +/** + * Returns a new transient collection of tcoll without the mapping for key. + */ +cljs.core._dissoc_BANG_ = (function cljs$core$_dissoc_BANG_(tcoll,key){ +if((((!((tcoll == null)))) && ((!((tcoll.cljs$core$ITransientMap$_dissoc_BANG_$arity$2 == null)))))){ +return tcoll.cljs$core$ITransientMap$_dissoc_BANG_$arity$2(tcoll,key); +} else { +var x__4433__auto__ = (((tcoll == null))?null:tcoll); +var m__4434__auto__ = (cljs.core._dissoc_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(tcoll,key) : m__4434__auto__.call(null,tcoll,key)); +} else { +var m__4431__auto__ = (cljs.core._dissoc_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(tcoll,key) : m__4431__auto__.call(null,tcoll,key)); +} else { +throw cljs.core.missing_protocol("ITransientMap.-dissoc!",tcoll); +} +} +} +}); + + +/** + * Protocol for adding vector functionality to transient collections. + * @interface + */ +cljs.core.ITransientVector = function(){}; + +/** + * Returns tcoll with value val added at position n. + */ +cljs.core._assoc_n_BANG_ = (function cljs$core$_assoc_n_BANG_(tcoll,n,val){ +if((((!((tcoll == null)))) && ((!((tcoll.cljs$core$ITransientVector$_assoc_n_BANG_$arity$3 == null)))))){ +return tcoll.cljs$core$ITransientVector$_assoc_n_BANG_$arity$3(tcoll,n,val); +} else { +var x__4433__auto__ = (((tcoll == null))?null:tcoll); +var m__4434__auto__ = (cljs.core._assoc_n_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(tcoll,n,val) : m__4434__auto__.call(null,tcoll,n,val)); +} else { +var m__4431__auto__ = (cljs.core._assoc_n_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(tcoll,n,val) : m__4431__auto__.call(null,tcoll,n,val)); +} else { +throw cljs.core.missing_protocol("ITransientVector.-assoc-n!",tcoll); +} +} +} +}); + +/** + * Returns tcoll with the last item removed from it. + */ +cljs.core._pop_BANG_ = (function cljs$core$_pop_BANG_(tcoll){ +if((((!((tcoll == null)))) && ((!((tcoll.cljs$core$ITransientVector$_pop_BANG_$arity$1 == null)))))){ +return tcoll.cljs$core$ITransientVector$_pop_BANG_$arity$1(tcoll); +} else { +var x__4433__auto__ = (((tcoll == null))?null:tcoll); +var m__4434__auto__ = (cljs.core._pop_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(tcoll) : m__4434__auto__.call(null,tcoll)); +} else { +var m__4431__auto__ = (cljs.core._pop_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(tcoll) : m__4431__auto__.call(null,tcoll)); +} else { +throw cljs.core.missing_protocol("ITransientVector.-pop!",tcoll); +} +} +} +}); + + +/** + * Protocol for adding set functionality to a transient collection. + * @interface + */ +cljs.core.ITransientSet = function(){}; + +/** + * Returns tcoll without v. + */ +cljs.core._disjoin_BANG_ = (function cljs$core$_disjoin_BANG_(tcoll,v){ +if((((!((tcoll == null)))) && ((!((tcoll.cljs$core$ITransientSet$_disjoin_BANG_$arity$2 == null)))))){ +return tcoll.cljs$core$ITransientSet$_disjoin_BANG_$arity$2(tcoll,v); +} else { +var x__4433__auto__ = (((tcoll == null))?null:tcoll); +var m__4434__auto__ = (cljs.core._disjoin_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(tcoll,v) : m__4434__auto__.call(null,tcoll,v)); +} else { +var m__4431__auto__ = (cljs.core._disjoin_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(tcoll,v) : m__4431__auto__.call(null,tcoll,v)); +} else { +throw cljs.core.missing_protocol("ITransientSet.-disjoin!",tcoll); +} +} +} +}); + + +/** + * Protocol for values that can be compared. + * @interface + */ +cljs.core.IComparable = function(){}; + +/** + * Returns a negative number, zero, or a positive number when x is logically + * 'less than', 'equal to', or 'greater than' y. + */ +cljs.core._compare = (function cljs$core$_compare(x,y){ +if((((!((x == null)))) && ((!((x.cljs$core$IComparable$_compare$arity$2 == null)))))){ +return x.cljs$core$IComparable$_compare$arity$2(x,y); +} else { +var x__4433__auto__ = (((x == null))?null:x); +var m__4434__auto__ = (cljs.core._compare[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(x,y) : m__4434__auto__.call(null,x,y)); +} else { +var m__4431__auto__ = (cljs.core._compare["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(x,y) : m__4431__auto__.call(null,x,y)); +} else { +throw cljs.core.missing_protocol("IComparable.-compare",x); +} +} +} +}); + + +/** + * Protocol for accessing the items of a chunk. + * @interface + */ +cljs.core.IChunk = function(){}; + +/** + * Return a new chunk of coll with the first item removed. + */ +cljs.core._drop_first = (function cljs$core$_drop_first(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IChunk$_drop_first$arity$1 == null)))))){ +return coll.cljs$core$IChunk$_drop_first$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._drop_first[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._drop_first["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IChunk.-drop-first",coll); +} +} +} +}); + + +/** + * Protocol for accessing a collection as sequential chunks. + * @interface + */ +cljs.core.IChunkedSeq = function(){}; + +/** + * Returns the first chunk in coll. + */ +cljs.core._chunked_first = (function cljs$core$_chunked_first(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IChunkedSeq$_chunked_first$arity$1 == null)))))){ +return coll.cljs$core$IChunkedSeq$_chunked_first$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._chunked_first[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._chunked_first["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IChunkedSeq.-chunked-first",coll); +} +} +} +}); + +/** + * Return a new collection of coll with the first chunk removed. + */ +cljs.core._chunked_rest = (function cljs$core$_chunked_rest(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IChunkedSeq$_chunked_rest$arity$1 == null)))))){ +return coll.cljs$core$IChunkedSeq$_chunked_rest$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._chunked_rest[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._chunked_rest["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IChunkedSeq.-chunked-rest",coll); +} +} +} +}); + + +/** + * Protocol for accessing the chunks of a collection. + * @interface + */ +cljs.core.IChunkedNext = function(){}; + +/** + * Returns a new collection of coll without the first chunk. + */ +cljs.core._chunked_next = (function cljs$core$_chunked_next(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IChunkedNext$_chunked_next$arity$1 == null)))))){ +return coll.cljs$core$IChunkedNext$_chunked_next$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._chunked_next[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._chunked_next["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IChunkedNext.-chunked-next",coll); +} +} +} +}); + + +/** + * Protocol for adding a name. + * @interface + */ +cljs.core.INamed = function(){}; + +/** + * Returns the name String of x. + */ +cljs.core._name = (function cljs$core$_name(x){ +if((((!((x == null)))) && ((!((x.cljs$core$INamed$_name$arity$1 == null)))))){ +return x.cljs$core$INamed$_name$arity$1(x); +} else { +var x__4433__auto__ = (((x == null))?null:x); +var m__4434__auto__ = (cljs.core._name[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4434__auto__.call(null,x)); +} else { +var m__4431__auto__ = (cljs.core._name["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4431__auto__.call(null,x)); +} else { +throw cljs.core.missing_protocol("INamed.-name",x); +} +} +} +}); + +/** + * Returns the namespace String of x. + */ +cljs.core._namespace = (function cljs$core$_namespace(x){ +if((((!((x == null)))) && ((!((x.cljs$core$INamed$_namespace$arity$1 == null)))))){ +return x.cljs$core$INamed$_namespace$arity$1(x); +} else { +var x__4433__auto__ = (((x == null))?null:x); +var m__4434__auto__ = (cljs.core._namespace[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4434__auto__.call(null,x)); +} else { +var m__4431__auto__ = (cljs.core._namespace["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4431__auto__.call(null,x)); +} else { +throw cljs.core.missing_protocol("INamed.-namespace",x); +} +} +} +}); + + +/** + * Marker protocol indicating an atom. + * @interface + */ +cljs.core.IAtom = function(){}; + + +/** + * Protocol for adding resetting functionality. + * @interface + */ +cljs.core.IReset = function(){}; + +/** + * Sets the value of o to new-value. + */ +cljs.core._reset_BANG_ = (function cljs$core$_reset_BANG_(o,new_value){ +if((((!((o == null)))) && ((!((o.cljs$core$IReset$_reset_BANG_$arity$2 == null)))))){ +return o.cljs$core$IReset$_reset_BANG_$arity$2(o,new_value); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._reset_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(o,new_value) : m__4434__auto__.call(null,o,new_value)); +} else { +var m__4431__auto__ = (cljs.core._reset_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(o,new_value) : m__4431__auto__.call(null,o,new_value)); +} else { +throw cljs.core.missing_protocol("IReset.-reset!",o); +} +} +} +}); + + +/** + * Protocol for adding swapping functionality. + * @interface + */ +cljs.core.ISwap = function(){}; + +/** + * Swaps the value of o to be (apply f current-value-of-atom args). + */ +cljs.core._swap_BANG_ = (function cljs$core$_swap_BANG_(var_args){ +var G__2735 = arguments.length; +switch (G__2735) { +case 2: +return cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$2 = (function (o,f){ +if((((!((o == null)))) && ((!((o.cljs$core$ISwap$_swap_BANG_$arity$2 == null)))))){ +return o.cljs$core$ISwap$_swap_BANG_$arity$2(o,f); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._swap_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(o,f) : m__4434__auto__.call(null,o,f)); +} else { +var m__4431__auto__ = (cljs.core._swap_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(o,f) : m__4431__auto__.call(null,o,f)); +} else { +throw cljs.core.missing_protocol("ISwap.-swap!",o); +} +} +} +}); + +cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$3 = (function (o,f,a){ +if((((!((o == null)))) && ((!((o.cljs$core$ISwap$_swap_BANG_$arity$3 == null)))))){ +return o.cljs$core$ISwap$_swap_BANG_$arity$3(o,f,a); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._swap_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(o,f,a) : m__4434__auto__.call(null,o,f,a)); +} else { +var m__4431__auto__ = (cljs.core._swap_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(o,f,a) : m__4431__auto__.call(null,o,f,a)); +} else { +throw cljs.core.missing_protocol("ISwap.-swap!",o); +} +} +} +}); + +cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$4 = (function (o,f,a,b){ +if((((!((o == null)))) && ((!((o.cljs$core$ISwap$_swap_BANG_$arity$4 == null)))))){ +return o.cljs$core$ISwap$_swap_BANG_$arity$4(o,f,a,b); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._swap_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$4 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$4(o,f,a,b) : m__4434__auto__.call(null,o,f,a,b)); +} else { +var m__4431__auto__ = (cljs.core._swap_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$4 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$4(o,f,a,b) : m__4431__auto__.call(null,o,f,a,b)); +} else { +throw cljs.core.missing_protocol("ISwap.-swap!",o); +} +} +} +}); + +cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$5 = (function (o,f,a,b,xs){ +if((((!((o == null)))) && ((!((o.cljs$core$ISwap$_swap_BANG_$arity$5 == null)))))){ +return o.cljs$core$ISwap$_swap_BANG_$arity$5(o,f,a,b,xs); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._swap_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$5 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$5(o,f,a,b,xs) : m__4434__auto__.call(null,o,f,a,b,xs)); +} else { +var m__4431__auto__ = (cljs.core._swap_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$5 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$5(o,f,a,b,xs) : m__4431__auto__.call(null,o,f,a,b,xs)); +} else { +throw cljs.core.missing_protocol("ISwap.-swap!",o); +} +} +} +}); + +cljs.core._swap_BANG_.cljs$lang$maxFixedArity = 5; + + + +/** + * Protocol for adding volatile functionality. + * @interface + */ +cljs.core.IVolatile = function(){}; + +/** + * Sets the value of volatile o to new-value without regard for the + * current value. Returns new-value. + */ +cljs.core._vreset_BANG_ = (function cljs$core$_vreset_BANG_(o,new_value){ +if((((!((o == null)))) && ((!((o.cljs$core$IVolatile$_vreset_BANG_$arity$2 == null)))))){ +return o.cljs$core$IVolatile$_vreset_BANG_$arity$2(o,new_value); +} else { +var x__4433__auto__ = (((o == null))?null:o); +var m__4434__auto__ = (cljs.core._vreset_BANG_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(o,new_value) : m__4434__auto__.call(null,o,new_value)); +} else { +var m__4431__auto__ = (cljs.core._vreset_BANG_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(o,new_value) : m__4431__auto__.call(null,o,new_value)); +} else { +throw cljs.core.missing_protocol("IVolatile.-vreset!",o); +} +} +} +}); + + +/** + * Protocol for iterating over a collection. + * @interface + */ +cljs.core.IIterable = function(){}; + +/** + * Returns an iterator for coll. + */ +cljs.core._iterator = (function cljs$core$_iterator(coll){ +if((((!((coll == null)))) && ((!((coll.cljs$core$IIterable$_iterator$arity$1 == null)))))){ +return coll.cljs$core$IIterable$_iterator$arity$1(coll); +} else { +var x__4433__auto__ = (((coll == null))?null:coll); +var m__4434__auto__ = (cljs.core._iterator[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4434__auto__.call(null,coll)); +} else { +var m__4431__auto__ = (cljs.core._iterator["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(coll) : m__4431__auto__.call(null,coll)); +} else { +throw cljs.core.missing_protocol("IIterable.-iterator",coll); +} +} +} +}); + + +/** +* @constructor + * @implements {cljs.core.IWriter} +*/ +cljs.core.StringBufferWriter = (function (sb){ +this.sb = sb; +this.cljs$lang$protocol_mask$partition0$ = 1073741824; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.StringBufferWriter.prototype.cljs$core$IWriter$_write$arity$2 = (function (_,s){ +var self__ = this; +var ___$1 = this; +return self__.sb.append(s); +}); + +cljs.core.StringBufferWriter.prototype.cljs$core$IWriter$_flush$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return null; +}); + +cljs.core.StringBufferWriter.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$sb], null); +}); + +cljs.core.StringBufferWriter.cljs$lang$type = true; + +cljs.core.StringBufferWriter.cljs$lang$ctorStr = "cljs.core/StringBufferWriter"; + +cljs.core.StringBufferWriter.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/StringBufferWriter"); +}); + +/** + * Positional factory function for cljs.core/StringBufferWriter. + */ +cljs.core.__GT_StringBufferWriter = (function cljs$core$__GT_StringBufferWriter(sb){ +return (new cljs.core.StringBufferWriter(sb)); +}); + +/** + * Support so that collections can implement toString without + * loading all the printing machinery. + */ +cljs.core.pr_str_STAR_ = (function cljs$core$pr_str_STAR_(obj){ +var sb = (new goog.string.StringBuffer()); +var writer = (new cljs.core.StringBufferWriter(sb)); +obj.cljs$core$IPrintWithWriter$_pr_writer$arity$3(null,writer,cljs.core.pr_opts()); + +writer.cljs$core$IWriter$_flush$arity$1(null); + +return cljs.core.str.cljs$core$IFn$_invoke$arity$1(sb); +}); +cljs.core.int_rotate_left = (function cljs$core$int_rotate_left(x,n){ +return ((x << n) | (x >>> (- n))); +}); +if((((typeof Math !== 'undefined') && (typeof Math.imul !== 'undefined')) && ((!((Math.imul((4294967295),(5)) === (0))))))){ +cljs.core.imul = (function cljs$core$imul(a,b){ +return Math.imul(a,b); +}); +} else { +cljs.core.imul = (function cljs$core$imul(a,b){ +var ah = ((a >>> (16)) & (65535)); +var al = (a & (65535)); +var bh = ((b >>> (16)) & (65535)); +var bl = (b & (65535)); +return (((al * bl) + ((((ah * bl) + (al * bh)) << (16)) >>> (0))) | (0)); +}); +} +cljs.core.m3_seed = (0); +cljs.core.m3_C1 = ((3432918353) | (0)); +cljs.core.m3_C2 = ((461845907) | (0)); +cljs.core.m3_mix_K1 = (function cljs$core$m3_mix_K1(k1){ +return cljs.core.imul(cljs.core.int_rotate_left(cljs.core.imul((k1 | (0)),cljs.core.m3_C1),(15)),cljs.core.m3_C2); +}); +cljs.core.m3_mix_H1 = (function cljs$core$m3_mix_H1(h1,k1){ +return ((cljs.core.imul(cljs.core.int_rotate_left(((h1 | (0)) ^ (k1 | (0))),(13)),(5)) + ((3864292196) | (0))) | (0)); +}); +cljs.core.m3_fmix = (function cljs$core$m3_fmix(h1,len){ +var h1__$1 = (h1 | (0)); +var h1__$2 = (h1__$1 ^ len); +var h1__$3 = (h1__$2 ^ (h1__$2 >>> (16))); +var h1__$4 = cljs.core.imul(h1__$3,((2246822507) | (0))); +var h1__$5 = (h1__$4 ^ (h1__$4 >>> (13))); +var h1__$6 = cljs.core.imul(h1__$5,((3266489909) | (0))); +return (h1__$6 ^ (h1__$6 >>> (16))); +}); +cljs.core.m3_hash_int = (function cljs$core$m3_hash_int(in$){ +if((in$ === (0))){ +return in$; +} else { +var k1 = cljs.core.m3_mix_K1(in$); +var h1 = cljs.core.m3_mix_H1(cljs.core.m3_seed,k1); +return cljs.core.m3_fmix(h1,(4)); +} +}); +cljs.core.m3_hash_unencoded_chars = (function cljs$core$m3_hash_unencoded_chars(in$){ +var h1 = (function (){var i = (1); +var h1 = cljs.core.m3_seed; +while(true){ +if((i < in$.length)){ +var G__2737 = (i + (2)); +var G__2738 = cljs.core.m3_mix_H1(h1,cljs.core.m3_mix_K1((in$.charCodeAt((i - (1))) | (in$.charCodeAt(i) << (16))))); +i = G__2737; +h1 = G__2738; +continue; +} else { +return h1; +} +break; +} +})(); +var h1__$1 = ((((in$.length & (1)) === (1)))?(h1 ^ cljs.core.m3_mix_K1(in$.charCodeAt((in$.length - (1))))):h1); +return cljs.core.m3_fmix(h1__$1,cljs.core.imul((2),in$.length)); +}); + + + +cljs.core.string_hash_cache = ({}); +cljs.core.string_hash_cache_count = (0); +cljs.core.hash_string_STAR_ = (function cljs$core$hash_string_STAR_(s){ +if((!((s == null)))){ +var len = s.length; +if((len > (0))){ +var i = (0); +var hash = (0); +while(true){ +if((i < len)){ +var G__2741 = (i + (1)); +var G__2742 = (cljs.core.imul((31),hash) + s.charCodeAt(i)); +i = G__2741; +hash = G__2742; +continue; +} else { +return hash; +} +break; +} +} else { +return (0); +} +} else { +return (0); +} +}); +cljs.core.add_to_string_hash_cache = (function cljs$core$add_to_string_hash_cache(k){ +var h = cljs.core.hash_string_STAR_(k); +goog.object.set(cljs.core.string_hash_cache,k,h); + +cljs.core.string_hash_cache_count = (cljs.core.string_hash_cache_count + (1)); + +return h; +}); +cljs.core.hash_string = (function cljs$core$hash_string(k){ +if((cljs.core.string_hash_cache_count > (255))){ +cljs.core.string_hash_cache = ({}); + +cljs.core.string_hash_cache_count = (0); +} else { +} + +if((k == null)){ +return (0); +} else { +var h = (cljs.core.string_hash_cache[k]); +if(typeof h === 'number'){ +return h; +} else { +return cljs.core.add_to_string_hash_cache(k); +} +} +}); +/** + * Returns the hash code of its argument. Note this is the hash code + * consistent with =. + */ +cljs.core.hash = (function cljs$core$hash(o){ +if((((!((o == null))))?(((((o.cljs$lang$protocol_mask$partition0$ & (4194304))) || ((cljs.core.PROTOCOL_SENTINEL === o.cljs$core$IHash$))))?true:false):false)){ +return (cljs.core._hash(o) ^ (0)); +} else { +if(typeof o === 'number'){ +if(cljs.core.truth_(isFinite(o))){ +return (Math.floor(o) % (2147483647)); +} else { +var G__2746 = o; +switch (G__2746) { +case Infinity: +return (2146435072); + +break; +case -Infinity: +return (-1048576); + +break; +default: +return (2146959360); + +} +} +} else { +if(o === true){ +return (1231); +} else { +if(o === false){ +return (1237); +} else { +if(typeof o === 'string'){ +return cljs.core.m3_hash_int(cljs.core.hash_string(o)); +} else { +if((o instanceof Date)){ +return (o.valueOf() ^ (0)); +} else { +if((o == null)){ +return (0); +} else { +return (cljs.core._hash(o) ^ (0)); + +} +} +} +} +} +} +} +}); +cljs.core.hash_combine = (function cljs$core$hash_combine(seed,hash){ +return (seed ^ (((hash + (2654435769)) + (seed << (6))) + (seed >> (2)))); +}); +/** + * Evaluates x and tests if it is an instance of the type + * c. Returns true or false + */ +cljs.core.instance_QMARK_ = (function cljs$core$instance_QMARK_(c,x){ +return (x instanceof c); +}); +/** + * Return true if x is a Symbol + */ +cljs.core.symbol_QMARK_ = (function cljs$core$symbol_QMARK_(x){ +return (x instanceof cljs.core.Symbol); +}); +cljs.core.hash_symbol = (function cljs$core$hash_symbol(sym){ +return cljs.core.hash_combine(cljs.core.m3_hash_unencoded_chars(sym.name),cljs.core.hash_string(sym.ns)); +}); +cljs.core.compare_symbols = (function cljs$core$compare_symbols(a,b){ +if((a.str === b.str)){ +return (0); +} else { +if(cljs.core.truth_((function (){var and__4120__auto__ = cljs.core.not(a.ns); +if(and__4120__auto__){ +return b.ns; +} else { +return and__4120__auto__; +} +})())){ +return (-1); +} else { +if(cljs.core.truth_(a.ns)){ +if(cljs.core.not(b.ns)){ +return (1); +} else { +var nsc = (function (){var G__2748 = a.ns; +var G__2749 = b.ns; +return goog.array.defaultCompare(G__2748,G__2749); +})(); +if(((0) === nsc)){ +var G__2750 = a.name; +var G__2751 = b.name; +return goog.array.defaultCompare(G__2750,G__2751); +} else { +return nsc; +} +} +} else { +var G__2752 = a.name; +var G__2753 = b.name; +return goog.array.defaultCompare(G__2752,G__2753); + +} +} +} +}); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.INamed} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IPrintWithWriter} + * @implements {cljs.core.IWithMeta} +*/ +cljs.core.Symbol = (function (ns,name,str,_hash,_meta){ +this.ns = ns; +this.name = name; +this.str = str; +this._hash = _hash; +this._meta = _meta; +this.cljs$lang$protocol_mask$partition0$ = 2154168321; +this.cljs$lang$protocol_mask$partition1$ = 4096; +}); +cljs.core.Symbol.prototype.toString = (function (){ +var self__ = this; +var _ = this; +return self__.str; +}); + +cljs.core.Symbol.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.Symbol.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (_,other){ +var self__ = this; +var ___$1 = this; +if((other instanceof cljs.core.Symbol)){ +return (self__.str === other.str); +} else { +return false; +} +}); + +cljs.core.Symbol.prototype.call = (function() { +var G__2755 = null; +var G__2755__2 = (function (self__,coll){ +var self__ = this; +var self____$1 = this; +var sym = self____$1; +return cljs.core.get.cljs$core$IFn$_invoke$arity$2(coll,sym); +}); +var G__2755__3 = (function (self__,coll,not_found){ +var self__ = this; +var self____$1 = this; +var sym = self____$1; +return cljs.core.get.cljs$core$IFn$_invoke$arity$3(coll,sym,not_found); +}); +G__2755 = function(self__,coll,not_found){ +switch(arguments.length){ +case 2: +return G__2755__2.call(this,self__,coll); +case 3: +return G__2755__3.call(this,self__,coll,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__2755.cljs$core$IFn$_invoke$arity$2 = G__2755__2; +G__2755.cljs$core$IFn$_invoke$arity$3 = G__2755__3; +return G__2755; +})() +; + +cljs.core.Symbol.prototype.apply = (function (self__,args2754){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args2754))); +}); + +cljs.core.Symbol.prototype.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +var self__ = this; +var sym = this; +return cljs.core.get.cljs$core$IFn$_invoke$arity$2(coll,sym); +}); + +cljs.core.Symbol.prototype.cljs$core$IFn$_invoke$arity$2 = (function (coll,not_found){ +var self__ = this; +var sym = this; +return cljs.core.get.cljs$core$IFn$_invoke$arity$3(coll,sym,not_found); +}); + +cljs.core.Symbol.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__._meta; +}); + +cljs.core.Symbol.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_,new_meta){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.Symbol(self__.ns,self__.name,self__.str,self__._hash,new_meta)); +}); + +cljs.core.Symbol.prototype.cljs$core$IHash$_hash$arity$1 = (function (sym){ +var self__ = this; +var sym__$1 = this; +var h__4243__auto__ = self__._hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_symbol(sym__$1); +self__._hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.Symbol.prototype.cljs$core$INamed$_name$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.name; +}); + +cljs.core.Symbol.prototype.cljs$core$INamed$_namespace$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.ns; +}); + +cljs.core.Symbol.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (o,writer,_){ +var self__ = this; +var o__$1 = this; +return cljs.core._write(writer,self__.str); +}); + +cljs.core.Symbol.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$ns,cljs.core.cst$sym$name,cljs.core.cst$sym$str,cljs.core.with_meta(cljs.core.cst$sym$_hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.cst$sym$_meta], null); +}); + +cljs.core.Symbol.cljs$lang$type = true; + +cljs.core.Symbol.cljs$lang$ctorStr = "cljs.core/Symbol"; + +cljs.core.Symbol.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Symbol"); +}); + +/** + * Positional factory function for cljs.core/Symbol. + */ +cljs.core.__GT_Symbol = (function cljs$core$__GT_Symbol(ns,name,str,_hash,_meta){ +return (new cljs.core.Symbol(ns,name,str,_hash,_meta)); +}); + +/** + * Returns true if v is of type cljs.core.Var + */ +cljs.core.var_QMARK_ = (function cljs$core$var_QMARK_(v){ +return (v instanceof cljs.core.Var); +}); +/** + * Returns a Symbol with the given namespace and name. Arity-1 works + * on strings, keywords, and vars. + */ +cljs.core.symbol = (function cljs$core$symbol(var_args){ +var G__2757 = arguments.length; +switch (G__2757) { +case 1: +return cljs.core.symbol.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.symbol.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.symbol.cljs$core$IFn$_invoke$arity$1 = (function (name){ +while(true){ +if((name instanceof cljs.core.Symbol)){ +return name; +} else { +if(typeof name === 'string'){ +var idx = name.indexOf("/"); +if((idx < (1))){ +return cljs.core.symbol.cljs$core$IFn$_invoke$arity$2(null,name); +} else { +return cljs.core.symbol.cljs$core$IFn$_invoke$arity$2(name.substring((0),idx),name.substring((idx + (1)),name.length)); +} +} else { +if(cljs.core.var_QMARK_(name)){ +return name.sym; +} else { +if((name instanceof cljs.core.Keyword)){ +var G__2759 = name.fqn; +name = G__2759; +continue; +} else { +throw (new Error("no conversion to symbol")); + +} +} +} +} +break; +} +}); + +cljs.core.symbol.cljs$core$IFn$_invoke$arity$2 = (function (ns,name){ +var sym_str = (((!((ns == null))))?[cljs.core.str.cljs$core$IFn$_invoke$arity$1(ns),"/",cljs.core.str.cljs$core$IFn$_invoke$arity$1(name)].join(''):name); +return (new cljs.core.Symbol(ns,name,sym_str,null,null)); +}); + +cljs.core.symbol.cljs$lang$maxFixedArity = 2; + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.Fn} + * @implements {cljs.core.IDeref} + * @implements {cljs.core.IWithMeta} +*/ +cljs.core.Var = (function (val,sym,_meta){ +this.val = val; +this.sym = sym; +this._meta = _meta; +this.cljs$lang$protocol_mask$partition0$ = 6717441; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.Var.prototype.isMacro = (function (){ +var self__ = this; +var _ = this; +return (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)).cljs$lang$macro; +}); + +cljs.core.Var.prototype.toString = (function (){ +var self__ = this; +var _ = this; +return ["#'",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.sym)].join(''); +}); + +cljs.core.Var.prototype.cljs$core$IDeref$_deref$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +}); + +cljs.core.Var.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__._meta; +}); + +cljs.core.Var.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_,new_meta){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.Var(self__.val,self__.sym,new_meta)); +}); + +cljs.core.Var.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (this$,other){ +var self__ = this; +var this$__$1 = this; +if((other instanceof cljs.core.Var)){ +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(this$__$1.sym,other.sym); +} else { +return false; +} +}); + +cljs.core.Var.prototype.cljs$core$IHash$_hash$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return cljs.core.hash_symbol(self__.sym); +}); + +cljs.core.Var.prototype.cljs$core$Fn$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Var.prototype.call = (function() { +var G__2803 = null; +var G__2803__1 = (function (self__){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2761 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2761.cljs$core$IFn$_invoke$arity$0 ? fexpr__2761.cljs$core$IFn$_invoke$arity$0() : fexpr__2761.call(null)); +}); +var G__2803__2 = (function (self__,a){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2762 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2762.cljs$core$IFn$_invoke$arity$1 ? fexpr__2762.cljs$core$IFn$_invoke$arity$1(a) : fexpr__2762.call(null,a)); +}); +var G__2803__3 = (function (self__,a,b){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2763 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2763.cljs$core$IFn$_invoke$arity$2 ? fexpr__2763.cljs$core$IFn$_invoke$arity$2(a,b) : fexpr__2763.call(null,a,b)); +}); +var G__2803__4 = (function (self__,a,b,c){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2764 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2764.cljs$core$IFn$_invoke$arity$3 ? fexpr__2764.cljs$core$IFn$_invoke$arity$3(a,b,c) : fexpr__2764.call(null,a,b,c)); +}); +var G__2803__5 = (function (self__,a,b,c,d){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2765 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2765.cljs$core$IFn$_invoke$arity$4 ? fexpr__2765.cljs$core$IFn$_invoke$arity$4(a,b,c,d) : fexpr__2765.call(null,a,b,c,d)); +}); +var G__2803__6 = (function (self__,a,b,c,d,e){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2766 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2766.cljs$core$IFn$_invoke$arity$5 ? fexpr__2766.cljs$core$IFn$_invoke$arity$5(a,b,c,d,e) : fexpr__2766.call(null,a,b,c,d,e)); +}); +var G__2803__7 = (function (self__,a,b,c,d,e,f){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2767 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2767.cljs$core$IFn$_invoke$arity$6 ? fexpr__2767.cljs$core$IFn$_invoke$arity$6(a,b,c,d,e,f) : fexpr__2767.call(null,a,b,c,d,e,f)); +}); +var G__2803__8 = (function (self__,a,b,c,d,e,f,g){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2768 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2768.cljs$core$IFn$_invoke$arity$7 ? fexpr__2768.cljs$core$IFn$_invoke$arity$7(a,b,c,d,e,f,g) : fexpr__2768.call(null,a,b,c,d,e,f,g)); +}); +var G__2803__9 = (function (self__,a,b,c,d,e,f,g,h){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2769 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2769.cljs$core$IFn$_invoke$arity$8 ? fexpr__2769.cljs$core$IFn$_invoke$arity$8(a,b,c,d,e,f,g,h) : fexpr__2769.call(null,a,b,c,d,e,f,g,h)); +}); +var G__2803__10 = (function (self__,a,b,c,d,e,f,g,h,i){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2770 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2770.cljs$core$IFn$_invoke$arity$9 ? fexpr__2770.cljs$core$IFn$_invoke$arity$9(a,b,c,d,e,f,g,h,i) : fexpr__2770.call(null,a,b,c,d,e,f,g,h,i)); +}); +var G__2803__11 = (function (self__,a,b,c,d,e,f,g,h,i,j){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2771 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2771.cljs$core$IFn$_invoke$arity$10 ? fexpr__2771.cljs$core$IFn$_invoke$arity$10(a,b,c,d,e,f,g,h,i,j) : fexpr__2771.call(null,a,b,c,d,e,f,g,h,i,j)); +}); +var G__2803__12 = (function (self__,a,b,c,d,e,f,g,h,i,j,k){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2772 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2772.cljs$core$IFn$_invoke$arity$11 ? fexpr__2772.cljs$core$IFn$_invoke$arity$11(a,b,c,d,e,f,g,h,i,j,k) : fexpr__2772.call(null,a,b,c,d,e,f,g,h,i,j,k)); +}); +var G__2803__13 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2773 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2773.cljs$core$IFn$_invoke$arity$12 ? fexpr__2773.cljs$core$IFn$_invoke$arity$12(a,b,c,d,e,f,g,h,i,j,k,l) : fexpr__2773.call(null,a,b,c,d,e,f,g,h,i,j,k,l)); +}); +var G__2803__14 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2774 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2774.cljs$core$IFn$_invoke$arity$13 ? fexpr__2774.cljs$core$IFn$_invoke$arity$13(a,b,c,d,e,f,g,h,i,j,k,l,m) : fexpr__2774.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m)); +}); +var G__2803__15 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2775 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2775.cljs$core$IFn$_invoke$arity$14 ? fexpr__2775.cljs$core$IFn$_invoke$arity$14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) : fexpr__2775.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +}); +var G__2803__16 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2776 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2776.cljs$core$IFn$_invoke$arity$15 ? fexpr__2776.cljs$core$IFn$_invoke$arity$15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : fexpr__2776.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +}); +var G__2803__17 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2777 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2777.cljs$core$IFn$_invoke$arity$16 ? fexpr__2777.cljs$core$IFn$_invoke$arity$16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : fexpr__2777.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +}); +var G__2803__18 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2778 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2778.cljs$core$IFn$_invoke$arity$17 ? fexpr__2778.cljs$core$IFn$_invoke$arity$17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : fexpr__2778.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +}); +var G__2803__19 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2779 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2779.cljs$core$IFn$_invoke$arity$18 ? fexpr__2779.cljs$core$IFn$_invoke$arity$18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : fexpr__2779.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +}); +var G__2803__20 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2780 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2780.cljs$core$IFn$_invoke$arity$19 ? fexpr__2780.cljs$core$IFn$_invoke$arity$19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : fexpr__2780.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +}); +var G__2803__21 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +var fexpr__2781 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2781.cljs$core$IFn$_invoke$arity$20 ? fexpr__2781.cljs$core$IFn$_invoke$arity$20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : fexpr__2781.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +}); +var G__2803__22 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic((self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)),a,b,c,d,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest], 0)); +}); +G__2803 = function(self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +switch(arguments.length){ +case 1: +return G__2803__1.call(this,self__); +case 2: +return G__2803__2.call(this,self__,a); +case 3: +return G__2803__3.call(this,self__,a,b); +case 4: +return G__2803__4.call(this,self__,a,b,c); +case 5: +return G__2803__5.call(this,self__,a,b,c,d); +case 6: +return G__2803__6.call(this,self__,a,b,c,d,e); +case 7: +return G__2803__7.call(this,self__,a,b,c,d,e,f); +case 8: +return G__2803__8.call(this,self__,a,b,c,d,e,f,g); +case 9: +return G__2803__9.call(this,self__,a,b,c,d,e,f,g,h); +case 10: +return G__2803__10.call(this,self__,a,b,c,d,e,f,g,h,i); +case 11: +return G__2803__11.call(this,self__,a,b,c,d,e,f,g,h,i,j); +case 12: +return G__2803__12.call(this,self__,a,b,c,d,e,f,g,h,i,j,k); +case 13: +return G__2803__13.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l); +case 14: +return G__2803__14.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m); +case 15: +return G__2803__15.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n); +case 16: +return G__2803__16.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o); +case 17: +return G__2803__17.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); +case 18: +return G__2803__18.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q); +case 19: +return G__2803__19.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r); +case 20: +return G__2803__20.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s); +case 21: +return G__2803__21.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t); +case 22: +return G__2803__22.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__2803.cljs$core$IFn$_invoke$arity$1 = G__2803__1; +G__2803.cljs$core$IFn$_invoke$arity$2 = G__2803__2; +G__2803.cljs$core$IFn$_invoke$arity$3 = G__2803__3; +G__2803.cljs$core$IFn$_invoke$arity$4 = G__2803__4; +G__2803.cljs$core$IFn$_invoke$arity$5 = G__2803__5; +G__2803.cljs$core$IFn$_invoke$arity$6 = G__2803__6; +G__2803.cljs$core$IFn$_invoke$arity$7 = G__2803__7; +G__2803.cljs$core$IFn$_invoke$arity$8 = G__2803__8; +G__2803.cljs$core$IFn$_invoke$arity$9 = G__2803__9; +G__2803.cljs$core$IFn$_invoke$arity$10 = G__2803__10; +G__2803.cljs$core$IFn$_invoke$arity$11 = G__2803__11; +G__2803.cljs$core$IFn$_invoke$arity$12 = G__2803__12; +G__2803.cljs$core$IFn$_invoke$arity$13 = G__2803__13; +G__2803.cljs$core$IFn$_invoke$arity$14 = G__2803__14; +G__2803.cljs$core$IFn$_invoke$arity$15 = G__2803__15; +G__2803.cljs$core$IFn$_invoke$arity$16 = G__2803__16; +G__2803.cljs$core$IFn$_invoke$arity$17 = G__2803__17; +G__2803.cljs$core$IFn$_invoke$arity$18 = G__2803__18; +G__2803.cljs$core$IFn$_invoke$arity$19 = G__2803__19; +G__2803.cljs$core$IFn$_invoke$arity$20 = G__2803__20; +G__2803.cljs$core$IFn$_invoke$arity$21 = G__2803__21; +G__2803.cljs$core$IFn$_invoke$arity$22 = G__2803__22; +return G__2803; +})() +; + +cljs.core.Var.prototype.apply = (function (self__,args2760){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args2760))); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$0 = (function (){ +var self__ = this; +var _ = this; +var fexpr__2782 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2782.cljs$core$IFn$_invoke$arity$0 ? fexpr__2782.cljs$core$IFn$_invoke$arity$0() : fexpr__2782.call(null)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$1 = (function (a){ +var self__ = this; +var _ = this; +var fexpr__2783 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2783.cljs$core$IFn$_invoke$arity$1 ? fexpr__2783.cljs$core$IFn$_invoke$arity$1(a) : fexpr__2783.call(null,a)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$2 = (function (a,b){ +var self__ = this; +var _ = this; +var fexpr__2784 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2784.cljs$core$IFn$_invoke$arity$2 ? fexpr__2784.cljs$core$IFn$_invoke$arity$2(a,b) : fexpr__2784.call(null,a,b)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$3 = (function (a,b,c){ +var self__ = this; +var _ = this; +var fexpr__2785 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2785.cljs$core$IFn$_invoke$arity$3 ? fexpr__2785.cljs$core$IFn$_invoke$arity$3(a,b,c) : fexpr__2785.call(null,a,b,c)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$4 = (function (a,b,c,d){ +var self__ = this; +var _ = this; +var fexpr__2786 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2786.cljs$core$IFn$_invoke$arity$4 ? fexpr__2786.cljs$core$IFn$_invoke$arity$4(a,b,c,d) : fexpr__2786.call(null,a,b,c,d)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$5 = (function (a,b,c,d,e){ +var self__ = this; +var _ = this; +var fexpr__2787 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2787.cljs$core$IFn$_invoke$arity$5 ? fexpr__2787.cljs$core$IFn$_invoke$arity$5(a,b,c,d,e) : fexpr__2787.call(null,a,b,c,d,e)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$6 = (function (a,b,c,d,e,f){ +var self__ = this; +var _ = this; +var fexpr__2788 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2788.cljs$core$IFn$_invoke$arity$6 ? fexpr__2788.cljs$core$IFn$_invoke$arity$6(a,b,c,d,e,f) : fexpr__2788.call(null,a,b,c,d,e,f)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$7 = (function (a,b,c,d,e,f,g){ +var self__ = this; +var _ = this; +var fexpr__2789 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2789.cljs$core$IFn$_invoke$arity$7 ? fexpr__2789.cljs$core$IFn$_invoke$arity$7(a,b,c,d,e,f,g) : fexpr__2789.call(null,a,b,c,d,e,f,g)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$8 = (function (a,b,c,d,e,f,g,h){ +var self__ = this; +var _ = this; +var fexpr__2790 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2790.cljs$core$IFn$_invoke$arity$8 ? fexpr__2790.cljs$core$IFn$_invoke$arity$8(a,b,c,d,e,f,g,h) : fexpr__2790.call(null,a,b,c,d,e,f,g,h)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$9 = (function (a,b,c,d,e,f,g,h,i){ +var self__ = this; +var _ = this; +var fexpr__2791 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2791.cljs$core$IFn$_invoke$arity$9 ? fexpr__2791.cljs$core$IFn$_invoke$arity$9(a,b,c,d,e,f,g,h,i) : fexpr__2791.call(null,a,b,c,d,e,f,g,h,i)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$10 = (function (a,b,c,d,e,f,g,h,i,j){ +var self__ = this; +var _ = this; +var fexpr__2792 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2792.cljs$core$IFn$_invoke$arity$10 ? fexpr__2792.cljs$core$IFn$_invoke$arity$10(a,b,c,d,e,f,g,h,i,j) : fexpr__2792.call(null,a,b,c,d,e,f,g,h,i,j)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$11 = (function (a,b,c,d,e,f,g,h,i,j,k){ +var self__ = this; +var _ = this; +var fexpr__2793 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2793.cljs$core$IFn$_invoke$arity$11 ? fexpr__2793.cljs$core$IFn$_invoke$arity$11(a,b,c,d,e,f,g,h,i,j,k) : fexpr__2793.call(null,a,b,c,d,e,f,g,h,i,j,k)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$12 = (function (a,b,c,d,e,f,g,h,i,j,k,l){ +var self__ = this; +var _ = this; +var fexpr__2794 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2794.cljs$core$IFn$_invoke$arity$12 ? fexpr__2794.cljs$core$IFn$_invoke$arity$12(a,b,c,d,e,f,g,h,i,j,k,l) : fexpr__2794.call(null,a,b,c,d,e,f,g,h,i,j,k,l)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$13 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m){ +var self__ = this; +var _ = this; +var fexpr__2795 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2795.cljs$core$IFn$_invoke$arity$13 ? fexpr__2795.cljs$core$IFn$_invoke$arity$13(a,b,c,d,e,f,g,h,i,j,k,l,m) : fexpr__2795.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$14 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n){ +var self__ = this; +var _ = this; +var fexpr__2796 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2796.cljs$core$IFn$_invoke$arity$14 ? fexpr__2796.cljs$core$IFn$_invoke$arity$14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) : fexpr__2796.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$15 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){ +var self__ = this; +var _ = this; +var fexpr__2797 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2797.cljs$core$IFn$_invoke$arity$15 ? fexpr__2797.cljs$core$IFn$_invoke$arity$15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : fexpr__2797.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$16 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){ +var self__ = this; +var _ = this; +var fexpr__2798 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2798.cljs$core$IFn$_invoke$arity$16 ? fexpr__2798.cljs$core$IFn$_invoke$arity$16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : fexpr__2798.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$17 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){ +var self__ = this; +var _ = this; +var fexpr__2799 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2799.cljs$core$IFn$_invoke$arity$17 ? fexpr__2799.cljs$core$IFn$_invoke$arity$17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : fexpr__2799.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$18 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r){ +var self__ = this; +var _ = this; +var fexpr__2800 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2800.cljs$core$IFn$_invoke$arity$18 ? fexpr__2800.cljs$core$IFn$_invoke$arity$18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : fexpr__2800.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$19 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){ +var self__ = this; +var _ = this; +var fexpr__2801 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2801.cljs$core$IFn$_invoke$arity$19 ? fexpr__2801.cljs$core$IFn$_invoke$arity$19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : fexpr__2801.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$20 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t){ +var self__ = this; +var _ = this; +var fexpr__2802 = (self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)); +return (fexpr__2802.cljs$core$IFn$_invoke$arity$20 ? fexpr__2802.cljs$core$IFn$_invoke$arity$20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : fexpr__2802.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +}); + +cljs.core.Var.prototype.cljs$core$IFn$_invoke$arity$21 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +var self__ = this; +var _ = this; +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic((self__.val.cljs$core$IFn$_invoke$arity$0 ? self__.val.cljs$core$IFn$_invoke$arity$0() : self__.val.call(null)),a,b,c,d,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest], 0)); +}); + +cljs.core.Var.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$val,cljs.core.cst$sym$sym,cljs.core.cst$sym$_meta], null); +}); + +cljs.core.Var.cljs$lang$type = true; + +cljs.core.Var.cljs$lang$ctorStr = "cljs.core/Var"; + +cljs.core.Var.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Var"); +}); + +/** + * Positional factory function for cljs.core/Var. + */ +cljs.core.__GT_Var = (function cljs$core$__GT_Var(val,sym,_meta){ +return (new cljs.core.Var(val,sym,_meta)); +}); + + + +/** + * Return true if x implements IIterable protocol. + */ +cljs.core.iterable_QMARK_ = (function cljs$core$iterable_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition1$ & (131072))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IIterable$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition1$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IIterable,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IIterable,x); +} +}); +/** + * Clone the supplied value which must implement ICloneable. + */ +cljs.core.clone = (function cljs$core$clone(value){ +return cljs.core._clone(value); +}); +/** + * Return true if x implements ICloneable protocol. + */ +cljs.core.cloneable_QMARK_ = (function cljs$core$cloneable_QMARK_(value){ +if((!((value == null)))){ +if((((value.cljs$lang$protocol_mask$partition1$ & (8192))) || ((cljs.core.PROTOCOL_SENTINEL === value.cljs$core$ICloneable$)))){ +return true; +} else { +if((!value.cljs$lang$protocol_mask$partition1$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.ICloneable,value); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.ICloneable,value); +} +}); +/** + * Returns a seq on the collection. If the collection is + * empty, returns nil. (seq nil) returns nil. seq also works on + * Strings. + */ +cljs.core.seq = (function cljs$core$seq(coll){ +if((coll == null)){ +return null; +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (8388608))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISeqable$))))?true:false):false)){ +return cljs.core._seq(coll); +} else { +if(cljs.core.array_QMARK_(coll)){ +if((coll.length === (0))){ +return null; +} else { +return (new cljs.core.IndexedSeq(coll,(0),null)); +} +} else { +if(typeof coll === 'string'){ +if((coll.length === (0))){ +return null; +} else { +return (new cljs.core.IndexedSeq(coll,(0),null)); +} +} else { +if(cljs.core.native_satisfies_QMARK_(cljs.core.ISeqable,coll)){ +return cljs.core._seq(coll); +} else { +throw (new Error([cljs.core.str.cljs$core$IFn$_invoke$arity$1(coll)," is not ISeqable"].join(''))); + +} +} +} +} +} +}); +/** + * Returns the first item in the collection. Calls seq on its + * argument. If coll is nil, returns nil. + */ +cljs.core.first = (function cljs$core$first(coll){ +if((coll == null)){ +return null; +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISeq$))))?true:false):false)){ +return cljs.core._first(coll); +} else { +var s = cljs.core.seq(coll); +if((s == null)){ +return null; +} else { +return cljs.core._first(s); +} +} +} +}); +/** + * Returns a possibly empty seq of the items after the first. Calls seq on its + * argument. + */ +cljs.core.rest = (function cljs$core$rest(coll){ +if((!((coll == null)))){ +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISeq$))))?true:false):false)){ +return cljs.core._rest(coll); +} else { +var s = cljs.core.seq(coll); +if(s){ +return s.cljs$core$ISeq$_rest$arity$1(null); +} else { +return cljs.core.List.EMPTY; +} +} +} else { +return cljs.core.List.EMPTY; +} +}); +/** + * Returns a seq of the items after the first. Calls seq on its + * argument. If there are no more items, returns nil + */ +cljs.core.next = (function cljs$core$next(coll){ +if((coll == null)){ +return null; +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (128))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$INext$))))?true:false):false)){ +return cljs.core._next(coll); +} else { +return cljs.core.seq(cljs.core.rest(coll)); +} +} +}); +/** + * Equality. Returns true if x equals y, false if not. Compares + * numbers and collections in a type-independent manner. Clojure's immutable data + * structures define -equiv (and thus =) as a value, not an identity, + * comparison. + */ +cljs.core._EQ_ = (function cljs$core$_EQ_(var_args){ +var G__2814 = arguments.length; +switch (G__2814) { +case 1: +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2816 = arguments.length; +var i__4731__auto___2817 = (0); +while(true){ +if((i__4731__auto___2817 < len__4730__auto___2816)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2817])); + +var G__2818 = (i__4731__auto___2817 + (1)); +i__4731__auto___2817 = G__2818; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._EQ_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return true; +}); + +cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +if((x == null)){ +return (y == null); +} else { +return (((x === y)) || (cljs.core._equiv(x,y))); +} +}); + +cljs.core._EQ_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +while(true){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(x,y)){ +if(cljs.core.next(more)){ +var G__2819 = y; +var G__2820 = cljs.core.first(more); +var G__2821 = cljs.core.next(more); +x = G__2819; +y = G__2820; +more = G__2821; +continue; +} else { +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(y,cljs.core.first(more)); +} +} else { +return false; +} +break; +} +}); + +/** @this {Function} */ +cljs.core._EQ_.cljs$lang$applyTo = (function (seq2811){ +var G__2812 = cljs.core.first(seq2811); +var seq2811__$1 = cljs.core.next(seq2811); +var G__2813 = cljs.core.first(seq2811__$1); +var seq2811__$2 = cljs.core.next(seq2811__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2812,G__2813,seq2811__$2); +}); + +cljs.core._EQ_.cljs$lang$maxFixedArity = (2); + + +/** +* @constructor +*/ +cljs.core.ES6Iterator = (function (s){ +this.s = s; +}); +cljs.core.ES6Iterator.prototype.next = (function (){ +var self__ = this; +var _ = this; +if((!((self__.s == null)))){ +var x = cljs.core.first(self__.s); +self__.s = cljs.core.next(self__.s); + +return ({"value": x, "done": false}); +} else { +return ({"value": null, "done": true}); +} +}); + +cljs.core.ES6Iterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$s,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ES6Iterator.cljs$lang$type = true; + +cljs.core.ES6Iterator.cljs$lang$ctorStr = "cljs.core/ES6Iterator"; + +cljs.core.ES6Iterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ES6Iterator"); +}); + +/** + * Positional factory function for cljs.core/ES6Iterator. + */ +cljs.core.__GT_ES6Iterator = (function cljs$core$__GT_ES6Iterator(s){ +return (new cljs.core.ES6Iterator(s)); +}); + +/** + * EXPERIMENTAL: Return a ES2015 compatible iterator for coll. + */ +cljs.core.es6_iterator = (function cljs$core$es6_iterator(coll){ +return (new cljs.core.ES6Iterator(cljs.core.seq(coll))); +}); + +/** +* @constructor + * @implements {cljs.core.ISeq} + * @implements {cljs.core.ISeqable} +*/ +cljs.core.ES6IteratorSeq = (function (value,iter,_rest){ +this.value = value; +this.iter = iter; +this._rest = _rest; +this.cljs$lang$protocol_mask$partition0$ = 8388672; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.ES6IteratorSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return this$__$1; +}); + +cljs.core.ES6IteratorSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.value; +}); + +cljs.core.ES6IteratorSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +if((self__._rest == null)){ +self__._rest = cljs.core.es6_iterator_seq(self__.iter); +} else { +} + +return self__._rest; +}); + +cljs.core.ES6IteratorSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$value,cljs.core.cst$sym$iter,cljs.core.with_meta(cljs.core.cst$sym$_rest,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ES6IteratorSeq.cljs$lang$type = true; + +cljs.core.ES6IteratorSeq.cljs$lang$ctorStr = "cljs.core/ES6IteratorSeq"; + +cljs.core.ES6IteratorSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ES6IteratorSeq"); +}); + +/** + * Positional factory function for cljs.core/ES6IteratorSeq. + */ +cljs.core.__GT_ES6IteratorSeq = (function cljs$core$__GT_ES6IteratorSeq(value,iter,_rest){ +return (new cljs.core.ES6IteratorSeq(value,iter,_rest)); +}); + +/** + * EXPERIMENTAL: Given an ES2015 compatible iterator return a seq. + */ +cljs.core.es6_iterator_seq = (function cljs$core$es6_iterator_seq(iter){ +var v = iter.next(); +if(cljs.core.truth_(v.done)){ +return cljs.core.List.EMPTY; +} else { +return (new cljs.core.ES6IteratorSeq(v.value,iter,null)); +} +}); +/** + * Mix final collection hash for ordered or unordered collections. + * hash-basis is the combined collection hash, count is the number + * of elements included in the basis. Note this is the hash code + * consistent with =, different from .hashCode. + * See http://clojure.org/data_structures#hash for full algorithms. + */ +cljs.core.mix_collection_hash = (function cljs$core$mix_collection_hash(hash_basis,count){ +var h1 = cljs.core.m3_seed; +var k1 = cljs.core.m3_mix_K1(hash_basis); +var h1__$1 = cljs.core.m3_mix_H1(h1,k1); +return cljs.core.m3_fmix(h1__$1,count); +}); +/** + * Returns the hash code, consistent with =, for an external ordered + * collection implementing Iterable. + * See http://clojure.org/data_structures#hash for full algorithms. + */ +cljs.core.hash_ordered_coll = (function cljs$core$hash_ordered_coll(coll){ +var n = (0); +var hash_code = (1); +var coll__$1 = cljs.core.seq(coll); +while(true){ +if((!((coll__$1 == null)))){ +var G__2822 = (n + (1)); +var G__2823 = ((cljs.core.imul((31),hash_code) + cljs.core.hash(cljs.core.first(coll__$1))) | (0)); +var G__2824 = cljs.core.next(coll__$1); +n = G__2822; +hash_code = G__2823; +coll__$1 = G__2824; +continue; +} else { +return cljs.core.mix_collection_hash(hash_code,n); +} +break; +} +}); +cljs.core.empty_ordered_hash = cljs.core.mix_collection_hash((1),(0)); +/** + * Returns the hash code, consistent with =, for an external unordered + * collection implementing Iterable. For maps, the iterator should + * return map entries whose hash is computed as + * (hash-ordered-coll [k v]). + * See http://clojure.org/data_structures#hash for full algorithms. + */ +cljs.core.hash_unordered_coll = (function cljs$core$hash_unordered_coll(coll){ +var n = (0); +var hash_code = (0); +var coll__$1 = cljs.core.seq(coll); +while(true){ +if((!((coll__$1 == null)))){ +var G__2825 = (n + (1)); +var G__2826 = ((hash_code + cljs.core.hash(cljs.core.first(coll__$1))) | (0)); +var G__2827 = cljs.core.next(coll__$1); +n = G__2825; +hash_code = G__2826; +coll__$1 = G__2827; +continue; +} else { +return cljs.core.mix_collection_hash(hash_code,n); +} +break; +} +}); +cljs.core.empty_unordered_hash = cljs.core.mix_collection_hash((0),(0)); + + +goog.object.set(cljs.core.ICounted,"null",true); + +var G__2828_2831 = cljs.core._count; +var G__2829_2832 = "null"; +var G__2830_2833 = ((function (G__2828_2831,G__2829_2832){ +return (function (_){ +return (0); +});})(G__2828_2831,G__2829_2832)) +; +goog.object.set(G__2828_2831,G__2829_2832,G__2830_2833); +Date.prototype.cljs$core$IEquiv$ = cljs.core.PROTOCOL_SENTINEL; + +Date.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (o,other){ +var o__$1 = this; +return (((other instanceof Date)) && ((o__$1.valueOf() === other.valueOf()))); +}); + +Date.prototype.cljs$core$IComparable$ = cljs.core.PROTOCOL_SENTINEL; + +Date.prototype.cljs$core$IComparable$_compare$arity$2 = (function (this$,other){ +var this$__$1 = this; +if((other instanceof Date)){ +var G__2834 = this$__$1.valueOf(); +var G__2835 = other.valueOf(); +return goog.array.defaultCompare(G__2834,G__2835); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(this$__$1)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(other)].join(''))); +} +}); + +/** + * @interface + */ +cljs.core.Inst = function(){}; + +cljs.core.inst_ms_STAR_ = (function cljs$core$inst_ms_STAR_(inst){ +if((((!((inst == null)))) && ((!((inst.cljs$core$Inst$inst_ms_STAR_$arity$1 == null)))))){ +return inst.cljs$core$Inst$inst_ms_STAR_$arity$1(inst); +} else { +var x__4433__auto__ = (((inst == null))?null:inst); +var m__4434__auto__ = (cljs.core.inst_ms_STAR_[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(inst) : m__4434__auto__.call(null,inst)); +} else { +var m__4431__auto__ = (cljs.core.inst_ms_STAR_["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(inst) : m__4431__auto__.call(null,inst)); +} else { +throw cljs.core.missing_protocol("Inst.inst-ms*",inst); +} +} +} +}); + +Date.prototype.cljs$core$Inst$ = cljs.core.PROTOCOL_SENTINEL; + +Date.prototype.cljs$core$Inst$inst_ms_STAR_$arity$1 = (function (inst){ +var inst__$1 = this; +return inst__$1.getTime(); +}); +/** + * Return the number of milliseconds since January 1, 1970, 00:00:00 GMT + */ +cljs.core.inst_ms = (function cljs$core$inst_ms(inst){ +return cljs.core.inst_ms_STAR_(inst); +}); +/** + * Return true if x satisfies Inst + */ +cljs.core.inst_QMARK_ = (function cljs$core$inst_QMARK_(x){ +if((!((x == null)))){ +if(((false) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$Inst$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.Inst,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.Inst,x); +} +}); +goog.object.set(cljs.core.IEquiv,"number",true); + +var G__2837_2840 = cljs.core._equiv; +var G__2838_2841 = "number"; +var G__2839_2842 = ((function (G__2837_2840,G__2838_2841){ +return (function (x,o){ +return (x === o); +});})(G__2837_2840,G__2838_2841)) +; +goog.object.set(G__2837_2840,G__2838_2841,G__2839_2842); +goog.object.set(cljs.core.Fn,"function",true); + +goog.object.set(cljs.core.IMeta,"function",true); + +var G__2843_2846 = cljs.core._meta; +var G__2844_2847 = "function"; +var G__2845_2848 = ((function (G__2843_2846,G__2844_2847){ +return (function (_){ +return null; +});})(G__2843_2846,G__2844_2847)) +; +goog.object.set(G__2843_2846,G__2844_2847,G__2845_2848); +goog.object.set(cljs.core.IHash,"_",true); + +var G__2849_2852 = cljs.core._hash; +var G__2850_2853 = "_"; +var G__2851_2854 = ((function (G__2849_2852,G__2850_2853){ +return (function (o){ +return goog.getUid(o); +});})(G__2849_2852,G__2850_2853)) +; +goog.object.set(G__2849_2852,G__2850_2853,G__2851_2854); +/** + * Returns a number one greater than num. + */ +cljs.core.inc = (function cljs$core$inc(x){ +return (x + (1)); +}); + +/** +* @constructor + * @implements {cljs.core.IDeref} +*/ +cljs.core.Reduced = (function (val){ +this.val = val; +this.cljs$lang$protocol_mask$partition0$ = 32768; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.Reduced.prototype.cljs$core$IDeref$_deref$arity$1 = (function (o){ +var self__ = this; +var o__$1 = this; +return self__.val; +}); + +cljs.core.Reduced.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$val], null); +}); + +cljs.core.Reduced.cljs$lang$type = true; + +cljs.core.Reduced.cljs$lang$ctorStr = "cljs.core/Reduced"; + +cljs.core.Reduced.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Reduced"); +}); + +/** + * Positional factory function for cljs.core/Reduced. + */ +cljs.core.__GT_Reduced = (function cljs$core$__GT_Reduced(val){ +return (new cljs.core.Reduced(val)); +}); + +/** + * Wraps x in a way such that a reduce will terminate with the value x + */ +cljs.core.reduced = (function cljs$core$reduced(x){ +return (new cljs.core.Reduced(x)); +}); +/** + * Returns true if x is the result of a call to reduced + */ +cljs.core.reduced_QMARK_ = (function cljs$core$reduced_QMARK_(r){ +return (r instanceof cljs.core.Reduced); +}); +/** + * If x is already reduced?, returns it, else returns (reduced x) + */ +cljs.core.ensure_reduced = (function cljs$core$ensure_reduced(x){ +if(cljs.core.reduced_QMARK_(x)){ +return x; +} else { +return cljs.core.reduced(x); +} +}); +/** + * If x is reduced?, returns (deref x), else returns x + */ +cljs.core.unreduced = (function cljs$core$unreduced(x){ +if(cljs.core.reduced_QMARK_(x)){ +return cljs.core.deref(x); +} else { +return x; +} +}); +/** + * Also reader macro: @var/@atom/@delay. Returns the + * most-recently-committed value of ref. When applied to a var + * or atom, returns its current state. When applied to a delay, forces + * it if not already forced. See also - realized?. + */ +cljs.core.deref = (function cljs$core$deref(o){ +return cljs.core._deref(o); +}); +/** + * Accepts any collection which satisfies the ICount and IIndexed protocols and + * reduces them without incurring seq initialization + */ +cljs.core.ci_reduce = (function cljs$core$ci_reduce(var_args){ +var G__2856 = arguments.length; +switch (G__2856) { +case 2: +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$2 = (function (cicoll,f){ +var cnt = cljs.core._count(cicoll); +if((cnt === (0))){ +return (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); +} else { +var val = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(cicoll,(0)); +var n = (1); +while(true){ +if((n < cnt)){ +var nval = (function (){var G__2857 = val; +var G__2858 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(cicoll,n); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__2857,G__2858) : f.call(null,G__2857,G__2858)); +})(); +if(cljs.core.reduced_QMARK_(nval)){ +return cljs.core.deref(nval); +} else { +var G__2864 = nval; +var G__2865 = (n + (1)); +val = G__2864; +n = G__2865; +continue; +} +} else { +return val; +} +break; +} +} +}); + +cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$3 = (function (cicoll,f,val){ +var cnt = cljs.core._count(cicoll); +var val__$1 = val; +var n = (0); +while(true){ +if((n < cnt)){ +var nval = (function (){var G__2859 = val__$1; +var G__2860 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(cicoll,n); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__2859,G__2860) : f.call(null,G__2859,G__2860)); +})(); +if(cljs.core.reduced_QMARK_(nval)){ +return cljs.core.deref(nval); +} else { +var G__2866 = nval; +var G__2867 = (n + (1)); +val__$1 = G__2866; +n = G__2867; +continue; +} +} else { +return val__$1; +} +break; +} +}); + +cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$4 = (function (cicoll,f,val,idx){ +var cnt = cljs.core._count(cicoll); +var val__$1 = val; +var n = idx; +while(true){ +if((n < cnt)){ +var nval = (function (){var G__2861 = val__$1; +var G__2862 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(cicoll,n); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__2861,G__2862) : f.call(null,G__2861,G__2862)); +})(); +if(cljs.core.reduced_QMARK_(nval)){ +return cljs.core.deref(nval); +} else { +var G__2868 = nval; +var G__2869 = (n + (1)); +val__$1 = G__2868; +n = G__2869; +continue; +} +} else { +return val__$1; +} +break; +} +}); + +cljs.core.ci_reduce.cljs$lang$maxFixedArity = 4; + +cljs.core.array_reduce = (function cljs$core$array_reduce(var_args){ +var G__2871 = arguments.length; +switch (G__2871) { +case 2: +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$2 = (function (arr,f){ +var cnt = arr.length; +if((arr.length === (0))){ +return (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); +} else { +var val = (arr[(0)]); +var n = (1); +while(true){ +if((n < cnt)){ +var nval = (function (){var G__2872 = val; +var G__2873 = (arr[n]); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__2872,G__2873) : f.call(null,G__2872,G__2873)); +})(); +if(cljs.core.reduced_QMARK_(nval)){ +return cljs.core.deref(nval); +} else { +var G__2879 = nval; +var G__2880 = (n + (1)); +val = G__2879; +n = G__2880; +continue; +} +} else { +return val; +} +break; +} +} +}); + +cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$3 = (function (arr,f,val){ +var cnt = arr.length; +var val__$1 = val; +var n = (0); +while(true){ +if((n < cnt)){ +var nval = (function (){var G__2874 = val__$1; +var G__2875 = (arr[n]); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__2874,G__2875) : f.call(null,G__2874,G__2875)); +})(); +if(cljs.core.reduced_QMARK_(nval)){ +return cljs.core.deref(nval); +} else { +var G__2881 = nval; +var G__2882 = (n + (1)); +val__$1 = G__2881; +n = G__2882; +continue; +} +} else { +return val__$1; +} +break; +} +}); + +cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$4 = (function (arr,f,val,idx){ +var cnt = arr.length; +var val__$1 = val; +var n = idx; +while(true){ +if((n < cnt)){ +var nval = (function (){var G__2876 = val__$1; +var G__2877 = (arr[n]); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__2876,G__2877) : f.call(null,G__2876,G__2877)); +})(); +if(cljs.core.reduced_QMARK_(nval)){ +return cljs.core.deref(nval); +} else { +var G__2883 = nval; +var G__2884 = (n + (1)); +val__$1 = G__2883; +n = G__2884; +continue; +} +} else { +return val__$1; +} +break; +} +}); + +cljs.core.array_reduce.cljs$lang$maxFixedArity = 4; + + + + + + + +/** + * Returns true if coll implements count in constant time + */ +cljs.core.counted_QMARK_ = (function cljs$core$counted_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (2))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$ICounted$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.ICounted,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.ICounted,x); +} +}); +/** + * Returns true if coll implements nth in constant time + */ +cljs.core.indexed_QMARK_ = (function cljs$core$indexed_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (16))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IIndexed$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IIndexed,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IIndexed,x); +} +}); +cljs.core._indexOf = (function cljs$core$_indexOf(var_args){ +var G__2888 = arguments.length; +switch (G__2888) { +case 2: +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core._indexOf.cljs$core$IFn$_invoke$arity$2 = (function (coll,x){ +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); + +cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3 = (function (coll,x,start){ +var len = cljs.core.count(coll); +if((start >= len)){ +return (-1); +} else { +var idx = (((start > (0)))?start:(((start < (0)))?(function (){var x__4219__auto__ = (0); +var y__4220__auto__ = (start + len); +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +})():start +)); +while(true){ +if((idx < len)){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.nth.cljs$core$IFn$_invoke$arity$2(coll,idx),x)){ +return idx; +} else { +var G__2890 = (idx + (1)); +idx = G__2890; +continue; +} +} else { +return (-1); +} +break; +} +} +}); + +cljs.core._indexOf.cljs$lang$maxFixedArity = 3; + +cljs.core._lastIndexOf = (function cljs$core$_lastIndexOf(var_args){ +var G__2892 = arguments.length; +switch (G__2892) { +case 2: +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$2 = (function (coll,x){ +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); + +cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3 = (function (coll,x,start){ +var len = cljs.core.count(coll); +if((len === (0))){ +return (-1); +} else { +var idx = (((start > (0)))?(function (){var x__4222__auto__ = (len - (1)); +var y__4223__auto__ = start; +return ((x__4222__auto__ < y__4223__auto__) ? x__4222__auto__ : y__4223__auto__); +})():(((start < (0)))?(len + start):start +)); +while(true){ +if((idx >= (0))){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.nth.cljs$core$IFn$_invoke$arity$2(coll,idx),x)){ +return idx; +} else { +var G__2894 = (idx - (1)); +idx = G__2894; +continue; +} +} else { +return (-1); +} +break; +} +} +}); + +cljs.core._lastIndexOf.cljs$lang$maxFixedArity = 3; + + +/** +* @constructor +*/ +cljs.core.IndexedSeqIterator = (function (arr,i){ +this.arr = arr; +this.i = i; +}); +cljs.core.IndexedSeqIterator.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +return (self__.i < self__.arr.length); +}); + +cljs.core.IndexedSeqIterator.prototype.next = (function (){ +var self__ = this; +var _ = this; +var ret = (self__.arr[self__.i]); +self__.i = (self__.i + (1)); + +return ret; +}); + +cljs.core.IndexedSeqIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$arr,cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.IndexedSeqIterator.cljs$lang$type = true; + +cljs.core.IndexedSeqIterator.cljs$lang$ctorStr = "cljs.core/IndexedSeqIterator"; + +cljs.core.IndexedSeqIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/IndexedSeqIterator"); +}); + +/** + * Positional factory function for cljs.core/IndexedSeqIterator. + */ +cljs.core.__GT_IndexedSeqIterator = (function cljs$core$__GT_IndexedSeqIterator(arr,i){ +return (new cljs.core.IndexedSeqIterator(arr,i)); +}); + + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.IReversible} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ASeq} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.IndexedSeq = (function (arr,i,meta){ +this.arr = arr; +this.i = i; +this.meta = meta; +this.cljs$lang$protocol_mask$partition0$ = 166592766; +this.cljs$lang$protocol_mask$partition1$ = 139264; +}); +cljs.core.IndexedSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.IndexedSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.IndexedSeq.prototype.indexOf = (function() { +var G__2895 = null; +var G__2895__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__2895__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__2895 = function(x,start){ +switch(arguments.length){ +case 1: +return G__2895__1.call(this,x); +case 2: +return G__2895__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__2895.cljs$core$IFn$_invoke$arity$1 = G__2895__1; +G__2895.cljs$core$IFn$_invoke$arity$2 = G__2895__2; +return G__2895; +})() +; + +cljs.core.IndexedSeq.prototype.lastIndexOf = (function() { +var G__2896 = null; +var G__2896__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__2896__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__2896 = function(x,start){ +switch(arguments.length){ +case 1: +return G__2896__1.call(this,x); +case 2: +return G__2896__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__2896.cljs$core$IFn$_invoke$arity$1 = G__2896__1; +G__2896.cljs$core$IFn$_invoke$arity$2 = G__2896__2; +return G__2896; +})() +; + +cljs.core.IndexedSeq.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (coll,n){ +var self__ = this; +var coll__$1 = this; +var i__$1 = (n + self__.i); +if(((((0) <= i__$1)) && ((i__$1 < self__.arr.length)))){ +return (self__.arr[i__$1]); +} else { +throw (new Error("Index out of bounds")); +} +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (coll,n,not_found){ +var self__ = this; +var coll__$1 = this; +var i__$1 = (n + self__.i); +if(((((0) <= i__$1)) && ((i__$1 < self__.arr.length)))){ +return (self__.arr[i__$1]); +} else { +return not_found; +} +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.IndexedSeqIterator(self__.arr,self__.i)); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.IndexedSeq.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.IndexedSeq(self__.arr,self__.i,self__.meta)); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$INext$_next$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +if(((self__.i + (1)) < self__.arr.length)){ +return (new cljs.core.IndexedSeq(self__.arr,(self__.i + (1)),null)); +} else { +return null; +} +}); + +cljs.core.IndexedSeq.prototype.cljs$core$ICounted$_count$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +var x__4219__auto__ = (0); +var y__4220__auto__ = (self__.arr.length - self__.i); +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IReversible$_rseq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var c = coll__$1.cljs$core$ICounted$_count$arity$1(null); +if((c > (0))){ +return (new cljs.core.RSeq(coll__$1,(c - (1)),null)); +} else { +return null; +} +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.hash_ordered_coll(coll__$1); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$4(self__.arr,f,(self__.arr[self__.i]),(self__.i + (1))); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$4(self__.arr,f,start,self__.i); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (self__.arr[self__.i]); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +if(((self__.i + (1)) < self__.arr.length)){ +return (new cljs.core.IndexedSeq(self__.arr,(self__.i + (1)),null)); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.IndexedSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +if((self__.i < self__.arr.length)){ +return this$__$1; +} else { +return null; +} +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.IndexedSeq(self__.arr,self__.i,new_meta)); +} +}); + +cljs.core.IndexedSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.IndexedSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$arr,cljs.core.cst$sym$i,cljs.core.cst$sym$meta], null); +}); + +cljs.core.IndexedSeq.cljs$lang$type = true; + +cljs.core.IndexedSeq.cljs$lang$ctorStr = "cljs.core/IndexedSeq"; + +cljs.core.IndexedSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/IndexedSeq"); +}); + +/** + * Positional factory function for cljs.core/IndexedSeq. + */ +cljs.core.__GT_IndexedSeq = (function cljs$core$__GT_IndexedSeq(arr,i,meta){ +return (new cljs.core.IndexedSeq(arr,i,meta)); +}); + +var G__2897_2900 = cljs.core.IndexedSeq.prototype; +var G__2898_2901 = cljs.core.ITER_SYMBOL; +var G__2899_2902 = ((function (G__2897_2900,G__2898_2901){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__2897_2900,G__2898_2901)) +; +goog.object.set(G__2897_2900,G__2898_2901,G__2899_2902); +/** + * Create seq from a primitive JavaScript Array-like. + */ +cljs.core.prim_seq = (function cljs$core$prim_seq(var_args){ +var G__2904 = arguments.length; +switch (G__2904) { +case 1: +return cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$1 = (function (prim){ +return cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(prim,(0)); +}); + +cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2 = (function (prim,i){ +if((i < prim.length)){ +return (new cljs.core.IndexedSeq(prim,i,null)); +} else { +return null; +} +}); + +cljs.core.prim_seq.cljs$lang$maxFixedArity = 2; + +/** + * Create a seq from a JavaScript array. + */ +cljs.core.array_seq = (function cljs$core$array_seq(var_args){ +var G__2907 = arguments.length; +switch (G__2907) { +case 1: +return cljs.core.array_seq.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.array_seq.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.array_seq.cljs$core$IFn$_invoke$arity$1 = (function (array){ +return cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(array,(0)); +}); + +cljs.core.array_seq.cljs$core$IFn$_invoke$arity$2 = (function (array,i){ +return cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(array,i); +}); + +cljs.core.array_seq.cljs$lang$maxFixedArity = 2; + + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.RSeq = (function (ci,i,meta){ +this.ci = ci; +this.i = i; +this.meta = meta; +this.cljs$lang$protocol_mask$partition0$ = 32374990; +this.cljs$lang$protocol_mask$partition1$ = 8192; +}); +cljs.core.RSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.RSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.RSeq.prototype.indexOf = (function() { +var G__2909 = null; +var G__2909__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__2909__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__2909 = function(x,start){ +switch(arguments.length){ +case 1: +return G__2909__1.call(this,x); +case 2: +return G__2909__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__2909.cljs$core$IFn$_invoke$arity$1 = G__2909__1; +G__2909.cljs$core$IFn$_invoke$arity$2 = G__2909__2; +return G__2909; +})() +; + +cljs.core.RSeq.prototype.lastIndexOf = (function() { +var G__2910 = null; +var G__2910__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__2910__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__2910 = function(x,start){ +switch(arguments.length){ +case 1: +return G__2910__1.call(this,x); +case 2: +return G__2910__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__2910.cljs$core$IFn$_invoke$arity$1 = G__2910__1; +G__2910.cljs$core$IFn$_invoke$arity$2 = G__2910__2; +return G__2910; +})() +; + +cljs.core.RSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.RSeq.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.RSeq(self__.ci,self__.i,self__.meta)); +}); + +cljs.core.RSeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.i > (0))){ +return (new cljs.core.RSeq(self__.ci,(self__.i - (1)),null)); +} else { +return null; +} +}); + +cljs.core.RSeq.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (self__.i + (1)); +}); + +cljs.core.RSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.hash_ordered_coll(coll__$1); +}); + +cljs.core.RSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.RSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.RSeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (col,f){ +var self__ = this; +var col__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,col__$1); +}); + +cljs.core.RSeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (col,f,start){ +var self__ = this; +var col__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,col__$1); +}); + +cljs.core.RSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._nth.cljs$core$IFn$_invoke$arity$2(self__.ci,self__.i); +}); + +cljs.core.RSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.i > (0))){ +return (new cljs.core.RSeq(self__.ci,(self__.i - (1)),null)); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.RSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.RSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.RSeq(self__.ci,self__.i,new_meta)); +} +}); + +cljs.core.RSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.RSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$ci,cljs.core.cst$sym$i,cljs.core.cst$sym$meta], null); +}); + +cljs.core.RSeq.cljs$lang$type = true; + +cljs.core.RSeq.cljs$lang$ctorStr = "cljs.core/RSeq"; + +cljs.core.RSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/RSeq"); +}); + +/** + * Positional factory function for cljs.core/RSeq. + */ +cljs.core.__GT_RSeq = (function cljs$core$__GT_RSeq(ci,i,meta){ +return (new cljs.core.RSeq(ci,i,meta)); +}); + +var G__2911_2914 = cljs.core.RSeq.prototype; +var G__2912_2915 = cljs.core.ITER_SYMBOL; +var G__2913_2916 = ((function (G__2911_2914,G__2912_2915){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__2911_2914,G__2912_2915)) +; +goog.object.set(G__2911_2914,G__2912_2915,G__2913_2916); +/** + * Same as (first (next x)) + */ +cljs.core.second = (function cljs$core$second(coll){ +return cljs.core.first(cljs.core.next(coll)); +}); +/** + * Same as (first (first x)) + */ +cljs.core.ffirst = (function cljs$core$ffirst(coll){ +return cljs.core.first(cljs.core.first(coll)); +}); +/** + * Same as (next (first x)) + */ +cljs.core.nfirst = (function cljs$core$nfirst(coll){ +return cljs.core.next(cljs.core.first(coll)); +}); +/** + * Same as (first (next x)) + */ +cljs.core.fnext = (function cljs$core$fnext(coll){ +return cljs.core.first(cljs.core.next(coll)); +}); +/** + * Same as (next (next x)) + */ +cljs.core.nnext = (function cljs$core$nnext(coll){ +return cljs.core.next(cljs.core.next(coll)); +}); +/** + * Return the last item in coll, in linear time + */ +cljs.core.last = (function cljs$core$last(s){ +while(true){ +var sn = cljs.core.next(s); +if((!((sn == null)))){ +var G__2917 = sn; +s = G__2917; +continue; +} else { +return cljs.core.first(s); +} +break; +} +}); +goog.object.set(cljs.core.IEquiv,"_",true); + +var G__2918_2921 = cljs.core._equiv; +var G__2919_2922 = "_"; +var G__2920_2923 = ((function (G__2918_2921,G__2919_2922){ +return (function (x,o){ +return (x === o); +});})(G__2918_2921,G__2919_2922)) +; +goog.object.set(G__2918_2921,G__2919_2922,G__2920_2923); +/** + * conj[oin]. Returns a new collection with the xs + * 'added'. (conj nil item) returns (item). The 'addition' may + * happen at different 'places' depending on the concrete type. + */ +cljs.core.conj = (function cljs$core$conj(var_args){ +var G__2928 = arguments.length; +switch (G__2928) { +case 0: +return cljs.core.conj.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.conj.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2930 = arguments.length; +var i__4731__auto___2931 = (0); +while(true){ +if((i__4731__auto___2931 < len__4730__auto___2930)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2931])); + +var G__2932 = (i__4731__auto___2931 + (1)); +i__4731__auto___2931 = G__2932; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.conj.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.conj.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.PersistentVector.EMPTY; +}); + +cljs.core.conj.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +return coll; +}); + +cljs.core.conj.cljs$core$IFn$_invoke$arity$2 = (function (coll,x){ +if((!((coll == null)))){ +return cljs.core._conj(coll,x); +} else { +return (new cljs.core.List(null,x,null,(1),null)); +} +}); + +cljs.core.conj.cljs$core$IFn$_invoke$arity$variadic = (function (coll,x,xs){ +while(true){ +if(cljs.core.truth_(xs)){ +var G__2933 = cljs.core.conj.cljs$core$IFn$_invoke$arity$2(coll,x); +var G__2934 = cljs.core.first(xs); +var G__2935 = cljs.core.next(xs); +coll = G__2933; +x = G__2934; +xs = G__2935; +continue; +} else { +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(coll,x); +} +break; +} +}); + +/** @this {Function} */ +cljs.core.conj.cljs$lang$applyTo = (function (seq2925){ +var G__2926 = cljs.core.first(seq2925); +var seq2925__$1 = cljs.core.next(seq2925); +var G__2927 = cljs.core.first(seq2925__$1); +var seq2925__$2 = cljs.core.next(seq2925__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2926,G__2927,seq2925__$2); +}); + +cljs.core.conj.cljs$lang$maxFixedArity = (2); + +/** + * Returns an empty collection of the same category as coll, or nil + */ +cljs.core.empty = (function cljs$core$empty(coll){ +if((coll == null)){ +return null; +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (4))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$IEmptyableCollection$))))?true:false):false)){ +return cljs.core._empty(coll); +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (4))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$IEmptyableCollection$))))?true:(((!coll.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_(cljs.core.IEmptyableCollection,coll):false)):cljs.core.native_satisfies_QMARK_(cljs.core.IEmptyableCollection,coll))){ +return cljs.core._empty(coll); +} else { +return null; + +} +} +} +}); +cljs.core.accumulating_seq_count = (function cljs$core$accumulating_seq_count(coll){ +var s = cljs.core.seq(coll); +var acc = (0); +while(true){ +if(cljs.core.counted_QMARK_(s)){ +return (acc + cljs.core._count(s)); +} else { +var G__2938 = cljs.core.next(s); +var G__2939 = (acc + (1)); +s = G__2938; +acc = G__2939; +continue; +} +break; +} +}); +/** + * Returns the number of items in the collection. (count nil) returns + * 0. Also works on strings, arrays, and Maps + */ +cljs.core.count = (function cljs$core$count(coll){ +if((!((coll == null)))){ +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (2))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ICounted$))))?true:false):false)){ +return cljs.core._count(coll); +} else { +if(cljs.core.array_QMARK_(coll)){ +return coll.length; +} else { +if(typeof coll === 'string'){ +return coll.length; +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (8388608))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISeqable$))))?true:false):false)){ +return cljs.core.accumulating_seq_count(coll); +} else { +return cljs.core._count(coll); + +} +} +} +} +} else { +return (0); +} +}); +cljs.core.linear_traversal_nth = (function cljs$core$linear_traversal_nth(var_args){ +var G__2943 = arguments.length; +switch (G__2943) { +case 2: +return cljs.core.linear_traversal_nth.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.linear_traversal_nth.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.linear_traversal_nth.cljs$core$IFn$_invoke$arity$2 = (function (coll,n){ +while(true){ +if((coll == null)){ +throw (new Error("Index out of bounds")); +} else { +if((n === (0))){ +if(cljs.core.seq(coll)){ +return cljs.core.first(coll); +} else { +throw (new Error("Index out of bounds")); +} +} else { +if(cljs.core.indexed_QMARK_(coll)){ +return cljs.core._nth.cljs$core$IFn$_invoke$arity$2(coll,n); +} else { +if(cljs.core.seq(coll)){ +var G__2945 = cljs.core.next(coll); +var G__2946 = (n - (1)); +coll = G__2945; +n = G__2946; +continue; +} else { +throw (new Error("Index out of bounds")); + +} +} +} +} +break; +} +}); + +cljs.core.linear_traversal_nth.cljs$core$IFn$_invoke$arity$3 = (function (coll,n,not_found){ +while(true){ +if((coll == null)){ +return not_found; +} else { +if((n === (0))){ +if(cljs.core.seq(coll)){ +return cljs.core.first(coll); +} else { +return not_found; +} +} else { +if(cljs.core.indexed_QMARK_(coll)){ +return cljs.core._nth.cljs$core$IFn$_invoke$arity$3(coll,n,not_found); +} else { +if(cljs.core.seq(coll)){ +var G__2947 = cljs.core.next(coll); +var G__2948 = (n - (1)); +var G__2949 = not_found; +coll = G__2947; +n = G__2948; +not_found = G__2949; +continue; +} else { +return not_found; + +} +} +} +} +break; +} +}); + +cljs.core.linear_traversal_nth.cljs$lang$maxFixedArity = 3; + +/** + * Returns the value at the index. get returns nil if index out of + * bounds, nth throws an exception unless not-found is supplied. nth + * also works for strings, arrays, regex Matchers and Lists, and, + * in O(n) time, for sequences. + */ +cljs.core.nth = (function cljs$core$nth(var_args){ +var G__2951 = arguments.length; +switch (G__2951) { +case 2: +return cljs.core.nth.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.nth.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.nth.cljs$core$IFn$_invoke$arity$2 = (function (coll,n){ +if((!(typeof n === 'number'))){ +throw (new Error("Index argument to nth must be a number")); +} else { +if((coll == null)){ +return coll; +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (16))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$IIndexed$))))?true:false):false)){ +return cljs.core._nth.cljs$core$IFn$_invoke$arity$2(coll,n); +} else { +if(cljs.core.array_QMARK_(coll)){ +if(((((-1) < n)) && ((n < coll.length)))){ +return (coll[(n | (0))]); +} else { +throw (new Error("Index out of bounds")); +} +} else { +if(typeof coll === 'string'){ +if(((((-1) < n)) && ((n < coll.length)))){ +return coll.charAt((n | (0))); +} else { +throw (new Error("Index out of bounds")); +} +} else { +if((function (){var or__4131__auto__ = (((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISeq$))))?true:false):false); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +if((!((coll == null)))){ +if((((coll.cljs$lang$protocol_mask$partition0$ & (16777216))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISequential$)))){ +return true; +} else { +return false; +} +} else { +return false; +} +} +})()){ +if((n < (0))){ +throw (new Error("Index out of bounds")); +} else { +return cljs.core.linear_traversal_nth.cljs$core$IFn$_invoke$arity$2(coll,n); +} +} else { +if(cljs.core.native_satisfies_QMARK_(cljs.core.IIndexed,coll)){ +return cljs.core._nth.cljs$core$IFn$_invoke$arity$2(coll,n); +} else { +throw (new Error(["nth not supported on this type ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.type__GT_str(cljs.core.type(coll)))].join(''))); + +} +} +} +} +} +} +} +}); + +cljs.core.nth.cljs$core$IFn$_invoke$arity$3 = (function (coll,n,not_found){ +if((!(typeof n === 'number'))){ +throw (new Error("Index argument to nth must be a number.")); +} else { +if((coll == null)){ +return not_found; +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (16))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$IIndexed$))))?true:false):false)){ +return cljs.core._nth.cljs$core$IFn$_invoke$arity$3(coll,n,not_found); +} else { +if(cljs.core.array_QMARK_(coll)){ +if(((((-1) < n)) && ((n < coll.length)))){ +return (coll[(n | (0))]); +} else { +return not_found; +} +} else { +if(typeof coll === 'string'){ +if(((((-1) < n)) && ((n < coll.length)))){ +return coll.charAt((n | (0))); +} else { +return not_found; +} +} else { +if((function (){var or__4131__auto__ = (((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISeq$))))?true:false):false); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +if((!((coll == null)))){ +if((((coll.cljs$lang$protocol_mask$partition0$ & (16777216))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISequential$)))){ +return true; +} else { +return false; +} +} else { +return false; +} +} +})()){ +if((n < (0))){ +return not_found; +} else { +return cljs.core.linear_traversal_nth.cljs$core$IFn$_invoke$arity$3(coll,n,not_found); +} +} else { +if(cljs.core.native_satisfies_QMARK_(cljs.core.IIndexed,coll)){ +return cljs.core._nth.cljs$core$IFn$_invoke$arity$3(coll,n,not_found); +} else { +throw (new Error(["nth not supported on this type ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.type__GT_str(cljs.core.type(coll)))].join(''))); + +} +} +} +} +} +} +} +}); + +cljs.core.nth.cljs$lang$maxFixedArity = 3; + +/** + * Returns the nth rest of coll, coll when n is 0. + */ +cljs.core.nthrest = (function cljs$core$nthrest(coll,n){ +var n__$1 = n; +var xs = coll; +while(true){ +var temp__5733__auto__ = (((n__$1 > (0))) && (cljs.core.seq(xs))); +if(temp__5733__auto__){ +var xs__$1 = temp__5733__auto__; +var G__2961 = (n__$1 - (1)); +var G__2962 = cljs.core.rest(xs__$1); +n__$1 = G__2961; +xs = G__2962; +continue; +} else { +return xs; +} +break; +} +}); +/** + * Returns the value mapped to key, not-found or nil if key not present. + */ +cljs.core.get = (function cljs$core$get(var_args){ +var G__2964 = arguments.length; +switch (G__2964) { +case 2: +return cljs.core.get.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.get.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.get.cljs$core$IFn$_invoke$arity$2 = (function (o,k){ +if((o == null)){ +return null; +} else { +if((((!((o == null))))?(((((o.cljs$lang$protocol_mask$partition0$ & (256))) || ((cljs.core.PROTOCOL_SENTINEL === o.cljs$core$ILookup$))))?true:false):false)){ +return cljs.core._lookup.cljs$core$IFn$_invoke$arity$2(o,k); +} else { +if(cljs.core.array_QMARK_(o)){ +if((((!((k == null)))) && ((k < o.length)))){ +return (o[(k | (0))]); +} else { +return null; +} +} else { +if(typeof o === 'string'){ +if((((!((k == null)))) && ((k < o.length)))){ +return o.charAt((k | (0))); +} else { +return null; +} +} else { +if(cljs.core.native_satisfies_QMARK_(cljs.core.ILookup,o)){ +return cljs.core._lookup.cljs$core$IFn$_invoke$arity$2(o,k); +} else { +return null; + +} +} +} +} +} +}); + +cljs.core.get.cljs$core$IFn$_invoke$arity$3 = (function (o,k,not_found){ +if((!((o == null)))){ +if((((!((o == null))))?(((((o.cljs$lang$protocol_mask$partition0$ & (256))) || ((cljs.core.PROTOCOL_SENTINEL === o.cljs$core$ILookup$))))?true:false):false)){ +return cljs.core._lookup.cljs$core$IFn$_invoke$arity$3(o,k,not_found); +} else { +if(cljs.core.array_QMARK_(o)){ +if((((!((k == null)))) && (((((-1) < k)) && ((k < o.length)))))){ +return (o[(k | (0))]); +} else { +return not_found; +} +} else { +if(typeof o === 'string'){ +if((((!((k == null)))) && (((((-1) < k)) && ((k < o.length)))))){ +return o.charAt((k | (0))); +} else { +return not_found; +} +} else { +if(cljs.core.native_satisfies_QMARK_(cljs.core.ILookup,o)){ +return cljs.core._lookup.cljs$core$IFn$_invoke$arity$3(o,k,not_found); +} else { +return not_found; + +} +} +} +} +} else { +return not_found; +} +}); + +cljs.core.get.cljs$lang$maxFixedArity = 3; + + + +/** + * assoc[iate]. When applied to a map, returns a new map of the + * same (hashed/sorted) type, that contains the mapping of key(s) to + * val(s). When applied to a vector, returns a new vector that + * contains val at index. + */ +cljs.core.assoc = (function cljs$core$assoc(var_args){ +var G__2973 = arguments.length; +switch (G__2973) { +case 3: +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2975 = arguments.length; +var i__4731__auto___2976 = (0); +while(true){ +if((i__4731__auto___2976 < len__4730__auto___2975)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2976])); + +var G__2977 = (i__4731__auto___2976 + (1)); +i__4731__auto___2976 = G__2977; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.assoc.cljs$core$IFn$_invoke$arity$3 = (function (coll,k,v){ +if((!((coll == null)))){ +return cljs.core._assoc(coll,k,v); +} else { +return cljs.core.PersistentArrayMap.createAsIfByAssoc([k,v]); +} +}); + +cljs.core.assoc.cljs$core$IFn$_invoke$arity$variadic = (function (coll,k,v,kvs){ +while(true){ +var ret = cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(coll,k,v); +if(cljs.core.truth_(kvs)){ +var G__2978 = ret; +var G__2979 = cljs.core.first(kvs); +var G__2980 = cljs.core.second(kvs); +var G__2981 = cljs.core.nnext(kvs); +coll = G__2978; +k = G__2979; +v = G__2980; +kvs = G__2981; +continue; +} else { +return ret; +} +break; +} +}); + +/** @this {Function} */ +cljs.core.assoc.cljs$lang$applyTo = (function (seq2969){ +var G__2970 = cljs.core.first(seq2969); +var seq2969__$1 = cljs.core.next(seq2969); +var G__2971 = cljs.core.first(seq2969__$1); +var seq2969__$2 = cljs.core.next(seq2969__$1); +var G__2972 = cljs.core.first(seq2969__$2); +var seq2969__$3 = cljs.core.next(seq2969__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2970,G__2971,G__2972,seq2969__$3); +}); + +cljs.core.assoc.cljs$lang$maxFixedArity = (3); + +/** + * dissoc[iate]. Returns a new map of the same (hashed/sorted) type, + * that does not contain a mapping for key(s). + */ +cljs.core.dissoc = (function cljs$core$dissoc(var_args){ +var G__2986 = arguments.length; +switch (G__2986) { +case 1: +return cljs.core.dissoc.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.dissoc.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___2988 = arguments.length; +var i__4731__auto___2989 = (0); +while(true){ +if((i__4731__auto___2989 < len__4730__auto___2988)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___2989])); + +var G__2990 = (i__4731__auto___2989 + (1)); +i__4731__auto___2989 = G__2990; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.dissoc.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.dissoc.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +return coll; +}); + +cljs.core.dissoc.cljs$core$IFn$_invoke$arity$2 = (function (coll,k){ +if((coll == null)){ +return null; +} else { +return cljs.core._dissoc(coll,k); +} +}); + +cljs.core.dissoc.cljs$core$IFn$_invoke$arity$variadic = (function (coll,k,ks){ +while(true){ +if((coll == null)){ +return null; +} else { +var ret = cljs.core.dissoc.cljs$core$IFn$_invoke$arity$2(coll,k); +if(cljs.core.truth_(ks)){ +var G__2991 = ret; +var G__2992 = cljs.core.first(ks); +var G__2993 = cljs.core.next(ks); +coll = G__2991; +k = G__2992; +ks = G__2993; +continue; +} else { +return ret; +} +} +break; +} +}); + +/** @this {Function} */ +cljs.core.dissoc.cljs$lang$applyTo = (function (seq2983){ +var G__2984 = cljs.core.first(seq2983); +var seq2983__$1 = cljs.core.next(seq2983); +var G__2985 = cljs.core.first(seq2983__$1); +var seq2983__$2 = cljs.core.next(seq2983__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__2984,G__2985,seq2983__$2); +}); + +cljs.core.dissoc.cljs$lang$maxFixedArity = (2); + +/** + * Return true if f is a JavaScript function or satisfies the Fn protocol. + */ +cljs.core.fn_QMARK_ = (function cljs$core$fn_QMARK_(f){ +var or__4131__auto__ = goog.isFunction(f); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +if((!((f == null)))){ +if(((false) || ((cljs.core.PROTOCOL_SENTINEL === f.cljs$core$Fn$)))){ +return true; +} else { +if((!f.cljs$lang$protocol_mask$partition$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.Fn,f); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.Fn,f); +} +} +}); + +/** +* @constructor + * @implements {cljs.core.IFn} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.Fn} + * @implements {cljs.core.IWithMeta} +*/ +cljs.core.MetaFn = (function (afn,meta){ +this.afn = afn; +this.meta = meta; +this.cljs$lang$protocol_mask$partition0$ = 393217; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.MetaFn.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.meta; +}); + +cljs.core.MetaFn.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_,new_meta){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.MetaFn(self__.afn,new_meta)); +}); + +cljs.core.MetaFn.prototype.cljs$core$Fn$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.MetaFn.prototype.call = (function() { +var G__2997 = null; +var G__2997__1 = (function (self__){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$0 ? self__.afn.cljs$core$IFn$_invoke$arity$0() : self__.afn.call(null)); +}); +var G__2997__2 = (function (self__,a){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$1 ? self__.afn.cljs$core$IFn$_invoke$arity$1(a) : self__.afn.call(null,a)); +}); +var G__2997__3 = (function (self__,a,b){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$2 ? self__.afn.cljs$core$IFn$_invoke$arity$2(a,b) : self__.afn.call(null,a,b)); +}); +var G__2997__4 = (function (self__,a,b,c){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$3 ? self__.afn.cljs$core$IFn$_invoke$arity$3(a,b,c) : self__.afn.call(null,a,b,c)); +}); +var G__2997__5 = (function (self__,a,b,c,d){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$4 ? self__.afn.cljs$core$IFn$_invoke$arity$4(a,b,c,d) : self__.afn.call(null,a,b,c,d)); +}); +var G__2997__6 = (function (self__,a,b,c,d,e){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$5 ? self__.afn.cljs$core$IFn$_invoke$arity$5(a,b,c,d,e) : self__.afn.call(null,a,b,c,d,e)); +}); +var G__2997__7 = (function (self__,a,b,c,d,e,f){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$6 ? self__.afn.cljs$core$IFn$_invoke$arity$6(a,b,c,d,e,f) : self__.afn.call(null,a,b,c,d,e,f)); +}); +var G__2997__8 = (function (self__,a,b,c,d,e,f,g){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$7 ? self__.afn.cljs$core$IFn$_invoke$arity$7(a,b,c,d,e,f,g) : self__.afn.call(null,a,b,c,d,e,f,g)); +}); +var G__2997__9 = (function (self__,a,b,c,d,e,f,g,h){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$8 ? self__.afn.cljs$core$IFn$_invoke$arity$8(a,b,c,d,e,f,g,h) : self__.afn.call(null,a,b,c,d,e,f,g,h)); +}); +var G__2997__10 = (function (self__,a,b,c,d,e,f,g,h,i){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$9 ? self__.afn.cljs$core$IFn$_invoke$arity$9(a,b,c,d,e,f,g,h,i) : self__.afn.call(null,a,b,c,d,e,f,g,h,i)); +}); +var G__2997__11 = (function (self__,a,b,c,d,e,f,g,h,i,j){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$10 ? self__.afn.cljs$core$IFn$_invoke$arity$10(a,b,c,d,e,f,g,h,i,j) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j)); +}); +var G__2997__12 = (function (self__,a,b,c,d,e,f,g,h,i,j,k){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$11 ? self__.afn.cljs$core$IFn$_invoke$arity$11(a,b,c,d,e,f,g,h,i,j,k) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k)); +}); +var G__2997__13 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$12 ? self__.afn.cljs$core$IFn$_invoke$arity$12(a,b,c,d,e,f,g,h,i,j,k,l) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l)); +}); +var G__2997__14 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$13 ? self__.afn.cljs$core$IFn$_invoke$arity$13(a,b,c,d,e,f,g,h,i,j,k,l,m) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m)); +}); +var G__2997__15 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$14 ? self__.afn.cljs$core$IFn$_invoke$arity$14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +}); +var G__2997__16 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$15 ? self__.afn.cljs$core$IFn$_invoke$arity$15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +}); +var G__2997__17 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$16 ? self__.afn.cljs$core$IFn$_invoke$arity$16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +}); +var G__2997__18 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$17 ? self__.afn.cljs$core$IFn$_invoke$arity$17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +}); +var G__2997__19 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$18 ? self__.afn.cljs$core$IFn$_invoke$arity$18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +}); +var G__2997__20 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$19 ? self__.afn.cljs$core$IFn$_invoke$arity$19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +}); +var G__2997__21 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return (self__.afn.cljs$core$IFn$_invoke$arity$20 ? self__.afn.cljs$core$IFn$_invoke$arity$20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +}); +var G__2997__22 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +var self__ = this; +var self____$1 = this; +var _ = self____$1; +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(self__.afn,a,b,c,d,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest], 0)); +}); +G__2997 = function(self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +switch(arguments.length){ +case 1: +return G__2997__1.call(this,self__); +case 2: +return G__2997__2.call(this,self__,a); +case 3: +return G__2997__3.call(this,self__,a,b); +case 4: +return G__2997__4.call(this,self__,a,b,c); +case 5: +return G__2997__5.call(this,self__,a,b,c,d); +case 6: +return G__2997__6.call(this,self__,a,b,c,d,e); +case 7: +return G__2997__7.call(this,self__,a,b,c,d,e,f); +case 8: +return G__2997__8.call(this,self__,a,b,c,d,e,f,g); +case 9: +return G__2997__9.call(this,self__,a,b,c,d,e,f,g,h); +case 10: +return G__2997__10.call(this,self__,a,b,c,d,e,f,g,h,i); +case 11: +return G__2997__11.call(this,self__,a,b,c,d,e,f,g,h,i,j); +case 12: +return G__2997__12.call(this,self__,a,b,c,d,e,f,g,h,i,j,k); +case 13: +return G__2997__13.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l); +case 14: +return G__2997__14.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m); +case 15: +return G__2997__15.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n); +case 16: +return G__2997__16.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o); +case 17: +return G__2997__17.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); +case 18: +return G__2997__18.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q); +case 19: +return G__2997__19.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r); +case 20: +return G__2997__20.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s); +case 21: +return G__2997__21.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t); +case 22: +return G__2997__22.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__2997.cljs$core$IFn$_invoke$arity$1 = G__2997__1; +G__2997.cljs$core$IFn$_invoke$arity$2 = G__2997__2; +G__2997.cljs$core$IFn$_invoke$arity$3 = G__2997__3; +G__2997.cljs$core$IFn$_invoke$arity$4 = G__2997__4; +G__2997.cljs$core$IFn$_invoke$arity$5 = G__2997__5; +G__2997.cljs$core$IFn$_invoke$arity$6 = G__2997__6; +G__2997.cljs$core$IFn$_invoke$arity$7 = G__2997__7; +G__2997.cljs$core$IFn$_invoke$arity$8 = G__2997__8; +G__2997.cljs$core$IFn$_invoke$arity$9 = G__2997__9; +G__2997.cljs$core$IFn$_invoke$arity$10 = G__2997__10; +G__2997.cljs$core$IFn$_invoke$arity$11 = G__2997__11; +G__2997.cljs$core$IFn$_invoke$arity$12 = G__2997__12; +G__2997.cljs$core$IFn$_invoke$arity$13 = G__2997__13; +G__2997.cljs$core$IFn$_invoke$arity$14 = G__2997__14; +G__2997.cljs$core$IFn$_invoke$arity$15 = G__2997__15; +G__2997.cljs$core$IFn$_invoke$arity$16 = G__2997__16; +G__2997.cljs$core$IFn$_invoke$arity$17 = G__2997__17; +G__2997.cljs$core$IFn$_invoke$arity$18 = G__2997__18; +G__2997.cljs$core$IFn$_invoke$arity$19 = G__2997__19; +G__2997.cljs$core$IFn$_invoke$arity$20 = G__2997__20; +G__2997.cljs$core$IFn$_invoke$arity$21 = G__2997__21; +G__2997.cljs$core$IFn$_invoke$arity$22 = G__2997__22; +return G__2997; +})() +; + +cljs.core.MetaFn.prototype.apply = (function (self__,args2996){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args2996))); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$0 = (function (){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$0 ? self__.afn.cljs$core$IFn$_invoke$arity$0() : self__.afn.call(null)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$1 = (function (a){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$1 ? self__.afn.cljs$core$IFn$_invoke$arity$1(a) : self__.afn.call(null,a)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$2 = (function (a,b){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$2 ? self__.afn.cljs$core$IFn$_invoke$arity$2(a,b) : self__.afn.call(null,a,b)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$3 = (function (a,b,c){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$3 ? self__.afn.cljs$core$IFn$_invoke$arity$3(a,b,c) : self__.afn.call(null,a,b,c)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$4 = (function (a,b,c,d){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$4 ? self__.afn.cljs$core$IFn$_invoke$arity$4(a,b,c,d) : self__.afn.call(null,a,b,c,d)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$5 = (function (a,b,c,d,e){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$5 ? self__.afn.cljs$core$IFn$_invoke$arity$5(a,b,c,d,e) : self__.afn.call(null,a,b,c,d,e)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$6 = (function (a,b,c,d,e,f){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$6 ? self__.afn.cljs$core$IFn$_invoke$arity$6(a,b,c,d,e,f) : self__.afn.call(null,a,b,c,d,e,f)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$7 = (function (a,b,c,d,e,f,g){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$7 ? self__.afn.cljs$core$IFn$_invoke$arity$7(a,b,c,d,e,f,g) : self__.afn.call(null,a,b,c,d,e,f,g)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$8 = (function (a,b,c,d,e,f,g,h){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$8 ? self__.afn.cljs$core$IFn$_invoke$arity$8(a,b,c,d,e,f,g,h) : self__.afn.call(null,a,b,c,d,e,f,g,h)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$9 = (function (a,b,c,d,e,f,g,h,i){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$9 ? self__.afn.cljs$core$IFn$_invoke$arity$9(a,b,c,d,e,f,g,h,i) : self__.afn.call(null,a,b,c,d,e,f,g,h,i)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$10 = (function (a,b,c,d,e,f,g,h,i,j){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$10 ? self__.afn.cljs$core$IFn$_invoke$arity$10(a,b,c,d,e,f,g,h,i,j) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$11 = (function (a,b,c,d,e,f,g,h,i,j,k){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$11 ? self__.afn.cljs$core$IFn$_invoke$arity$11(a,b,c,d,e,f,g,h,i,j,k) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$12 = (function (a,b,c,d,e,f,g,h,i,j,k,l){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$12 ? self__.afn.cljs$core$IFn$_invoke$arity$12(a,b,c,d,e,f,g,h,i,j,k,l) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$13 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$13 ? self__.afn.cljs$core$IFn$_invoke$arity$13(a,b,c,d,e,f,g,h,i,j,k,l,m) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$14 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$14 ? self__.afn.cljs$core$IFn$_invoke$arity$14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$15 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$15 ? self__.afn.cljs$core$IFn$_invoke$arity$15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$16 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$16 ? self__.afn.cljs$core$IFn$_invoke$arity$16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$17 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$17 ? self__.afn.cljs$core$IFn$_invoke$arity$17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$18 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$18 ? self__.afn.cljs$core$IFn$_invoke$arity$18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$19 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$19 ? self__.afn.cljs$core$IFn$_invoke$arity$19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$20 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t){ +var self__ = this; +var _ = this; +return (self__.afn.cljs$core$IFn$_invoke$arity$20 ? self__.afn.cljs$core$IFn$_invoke$arity$20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : self__.afn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +}); + +cljs.core.MetaFn.prototype.cljs$core$IFn$_invoke$arity$21 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +var self__ = this; +var _ = this; +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(self__.afn,a,b,c,d,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest], 0)); +}); + +cljs.core.MetaFn.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$afn,cljs.core.cst$sym$meta], null); +}); + +cljs.core.MetaFn.cljs$lang$type = true; + +cljs.core.MetaFn.cljs$lang$ctorStr = "cljs.core/MetaFn"; + +cljs.core.MetaFn.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/MetaFn"); +}); + +/** + * Positional factory function for cljs.core/MetaFn. + */ +cljs.core.__GT_MetaFn = (function cljs$core$__GT_MetaFn(afn,meta){ +return (new cljs.core.MetaFn(afn,meta)); +}); + +/** + * Returns an object of the same type and value as obj, with + * map m as its metadata. + */ +cljs.core.with_meta = (function cljs$core$with_meta(o,meta){ +if(goog.isFunction(o)){ +return (new cljs.core.MetaFn(o,meta)); +} else { +if((o == null)){ +return null; +} else { +return cljs.core._with_meta(o,meta); +} +} +}); +/** + * Returns the metadata of obj, returns nil if there is no metadata. + */ +cljs.core.meta = (function cljs$core$meta(o){ +if((function (){var and__4120__auto__ = (!((o == null))); +if(and__4120__auto__){ +if((!((o == null)))){ +if((((o.cljs$lang$protocol_mask$partition0$ & (131072))) || ((cljs.core.PROTOCOL_SENTINEL === o.cljs$core$IMeta$)))){ +return true; +} else { +if((!o.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IMeta,o); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IMeta,o); +} +} else { +return and__4120__auto__; +} +})()){ +return cljs.core._meta(o); +} else { +return null; +} +}); +/** + * For a list or queue, same as first, for a vector, same as, but much + * more efficient than, last. If the collection is empty, returns nil. + */ +cljs.core.peek = (function cljs$core$peek(coll){ +if((coll == null)){ +return null; +} else { +return cljs.core._peek(coll); +} +}); +/** + * For a list or queue, returns a new list/queue without the first + * item, for a vector, returns a new vector without the last item. + * Note - not the same as next/butlast. + */ +cljs.core.pop = (function cljs$core$pop(coll){ +if((coll == null)){ +return null; +} else { +return cljs.core._pop(coll); +} +}); +/** + * disj[oin]. Returns a new set of the same (hashed/sorted) type, that + * does not contain key(s). + */ +cljs.core.disj = (function cljs$core$disj(var_args){ +var G__3004 = arguments.length; +switch (G__3004) { +case 1: +return cljs.core.disj.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.disj.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3006 = arguments.length; +var i__4731__auto___3007 = (0); +while(true){ +if((i__4731__auto___3007 < len__4730__auto___3006)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3007])); + +var G__3008 = (i__4731__auto___3007 + (1)); +i__4731__auto___3007 = G__3008; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.disj.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.disj.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +return coll; +}); + +cljs.core.disj.cljs$core$IFn$_invoke$arity$2 = (function (coll,k){ +if((coll == null)){ +return null; +} else { +return cljs.core._disjoin(coll,k); +} +}); + +cljs.core.disj.cljs$core$IFn$_invoke$arity$variadic = (function (coll,k,ks){ +while(true){ +if((coll == null)){ +return null; +} else { +var ret = cljs.core.disj.cljs$core$IFn$_invoke$arity$2(coll,k); +if(cljs.core.truth_(ks)){ +var G__3009 = ret; +var G__3010 = cljs.core.first(ks); +var G__3011 = cljs.core.next(ks); +coll = G__3009; +k = G__3010; +ks = G__3011; +continue; +} else { +return ret; +} +} +break; +} +}); + +/** @this {Function} */ +cljs.core.disj.cljs$lang$applyTo = (function (seq3001){ +var G__3002 = cljs.core.first(seq3001); +var seq3001__$1 = cljs.core.next(seq3001); +var G__3003 = cljs.core.first(seq3001__$1); +var seq3001__$2 = cljs.core.next(seq3001__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3002,G__3003,seq3001__$2); +}); + +cljs.core.disj.cljs$lang$maxFixedArity = (2); + +/** + * Returns true if coll has no items - same as (not (seq coll)). + * Please use the idiom (seq x) rather than (not (empty? x)) + */ +cljs.core.empty_QMARK_ = (function cljs$core$empty_QMARK_(coll){ +return (((coll == null)) || (cljs.core.not(cljs.core.seq(coll)))); +}); +/** + * Returns true if x satisfies ICollection + */ +cljs.core.coll_QMARK_ = (function cljs$core$coll_QMARK_(x){ +if((x == null)){ +return false; +} else { +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (8))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$ICollection$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.ICollection,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.ICollection,x); +} +} +}); +/** + * Returns true if x satisfies ISet + */ +cljs.core.set_QMARK_ = (function cljs$core$set_QMARK_(x){ +if((x == null)){ +return false; +} else { +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (4096))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$ISet$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.ISet,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.ISet,x); +} +} +}); +/** + * Returns true if coll implements IAssociative + */ +cljs.core.associative_QMARK_ = (function cljs$core$associative_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (512))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IAssociative$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IAssociative,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IAssociative,x); +} +}); +/** + * Returns true if coll implements IFind + */ +cljs.core.ifind_QMARK_ = (function cljs$core$ifind_QMARK_(x){ +if((!((x == null)))){ +if(((false) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IFind$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IFind,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IFind,x); +} +}); +/** + * Returns true if coll satisfies ISequential + */ +cljs.core.sequential_QMARK_ = (function cljs$core$sequential_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (16777216))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$ISequential$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.ISequential,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.ISequential,x); +} +}); +/** + * Returns true if coll satisfies ISorted + */ +cljs.core.sorted_QMARK_ = (function cljs$core$sorted_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (268435456))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$ISorted$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.ISorted,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.ISorted,x); +} +}); +/** + * Returns true if coll satisfies IReduce + */ +cljs.core.reduceable_QMARK_ = (function cljs$core$reduceable_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (524288))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IReduce$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IReduce,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IReduce,x); +} +}); +/** + * Return true if x satisfies IMap + */ +cljs.core.map_QMARK_ = (function cljs$core$map_QMARK_(x){ +if((x == null)){ +return false; +} else { +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (1024))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IMap$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IMap,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IMap,x); +} +} +}); +/** + * Return true if x satisfies IRecord + */ +cljs.core.record_QMARK_ = (function cljs$core$record_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (67108864))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IRecord$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IRecord,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IRecord,x); +} +}); +/** + * Return true if x satisfies IVector + */ +cljs.core.vector_QMARK_ = (function cljs$core$vector_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (16384))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IVector$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IVector,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IVector,x); +} +}); + +/** + * Return true if x is satisfies IChunkedSeq. + */ +cljs.core.chunked_seq_QMARK_ = (function cljs$core$chunked_seq_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition1$ & (512))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IChunkedSeq$)))){ +return true; +} else { +return false; +} +} else { +return false; +} +}); +/** + * Create JavaSript object from an even number arguments representing + * interleaved keys and values. + */ +cljs.core.js_obj = (function cljs$core$js_obj(var_args){ +var G__3025 = arguments.length; +switch (G__3025) { +case 0: +return cljs.core.js_obj.cljs$core$IFn$_invoke$arity$0(); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3029 = arguments.length; +var i__4731__auto___3030 = (0); +while(true){ +if((i__4731__auto___3030 < len__4730__auto___3029)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3030])); + +var G__3031 = (i__4731__auto___3030 + (1)); +i__4731__auto___3030 = G__3031; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((0)),(0),null)); +return cljs.core.js_obj.cljs$core$IFn$_invoke$arity$variadic(argseq__4752__auto__); + +} +}); + +cljs.core.js_obj.cljs$core$IFn$_invoke$arity$0 = (function (){ +return ({}); +}); + +cljs.core.js_obj.cljs$core$IFn$_invoke$arity$variadic = (function (keyvals){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(goog.object.create,keyvals); +}); + +/** @this {Function} */ +cljs.core.js_obj.cljs$lang$applyTo = (function (seq3024){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq3024)); +}); + +cljs.core.js_obj.cljs$lang$maxFixedArity = (0); + +/** + * Return the JavaScript keys for an object. + */ +cljs.core.js_keys = (function cljs$core$js_keys(obj){ +return goog.object.getKeys(obj); +}); +/** + * Delete a property from a JavaScript object. + * Returns true upon success, false otherwise. + */ +cljs.core.js_delete = (function cljs$core$js_delete(obj,key){ +return delete obj[key]; +}); +cljs.core.array_copy = (function cljs$core$array_copy(from,i,to,j,len){ +var i__$1 = i; +var j__$1 = j; +var len__$1 = len; +while(true){ +if((len__$1 === (0))){ +return to; +} else { +(to[j__$1] = (from[i__$1])); + +var G__3032 = (i__$1 + (1)); +var G__3033 = (j__$1 + (1)); +var G__3034 = (len__$1 - (1)); +i__$1 = G__3032; +j__$1 = G__3033; +len__$1 = G__3034; +continue; +} +break; +} +}); +cljs.core.array_copy_downward = (function cljs$core$array_copy_downward(from,i,to,j,len){ +var i__$1 = (i + (len - (1))); +var j__$1 = (j + (len - (1))); +var len__$1 = len; +while(true){ +if((len__$1 === (0))){ +return to; +} else { +(to[j__$1] = (from[i__$1])); + +var G__3035 = (i__$1 - (1)); +var G__3036 = (j__$1 - (1)); +var G__3037 = (len__$1 - (1)); +i__$1 = G__3035; +j__$1 = G__3036; +len__$1 = G__3037; +continue; +} +break; +} +}); +cljs.core.lookup_sentinel = ({}); +/** + * Returns true if x is the value false, false otherwise. + */ +cljs.core.false_QMARK_ = (function cljs$core$false_QMARK_(x){ +return x === false; +}); +/** + * Returns true if x is the value true, false otherwise. + */ +cljs.core.true_QMARK_ = (function cljs$core$true_QMARK_(x){ +return x === true; +}); +/** + * Return true if x is a Boolean + */ +cljs.core.boolean_QMARK_ = (function cljs$core$boolean_QMARK_(x){ +return ((x === true) || (x === false)); +}); +/** + * Returns true if x identical to the JavaScript undefined value. + */ +cljs.core.undefined_QMARK_ = (function cljs$core$undefined_QMARK_(x){ +return (void 0 === x); +}); +/** + * Return true if s satisfies ISeq + */ +cljs.core.seq_QMARK_ = (function cljs$core$seq_QMARK_(s){ +if((s == null)){ +return false; +} else { +if((!((s == null)))){ +if((((s.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === s.cljs$core$ISeq$)))){ +return true; +} else { +if((!s.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.ISeq,s); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.ISeq,s); +} +} +}); +/** + * Return true if the seq function is supported for s + */ +cljs.core.seqable_QMARK_ = (function cljs$core$seqable_QMARK_(s){ +var or__4131__auto__ = (s == null); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (((!((s == null))))?(((((s.cljs$lang$protocol_mask$partition0$ & (8388608))) || ((cljs.core.PROTOCOL_SENTINEL === s.cljs$core$ISeqable$))))?true:(((!s.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_(cljs.core.ISeqable,s):false)):cljs.core.native_satisfies_QMARK_(cljs.core.ISeqable,s)); +if(or__4131__auto____$1){ +return or__4131__auto____$1; +} else { +return ((cljs.core.array_QMARK_(s)) || (typeof s === 'string')); +} +} +}); +/** + * Coerce to boolean + */ +cljs.core.boolean$ = (function cljs$core$boolean(x){ +if((x == null)){ +return false; +} else { +if(x === false){ +return false; +} else { +return true; + +} +} +}); +/** + * Returns true if f returns true for fn? or satisfies IFn. + */ +cljs.core.ifn_QMARK_ = (function cljs$core$ifn_QMARK_(f){ +var or__4131__auto__ = cljs.core.fn_QMARK_(f); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +if((!((f == null)))){ +if((((f.cljs$lang$protocol_mask$partition0$ & (1))) || ((cljs.core.PROTOCOL_SENTINEL === f.cljs$core$IFn$)))){ +return true; +} else { +if((!f.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IFn,f); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IFn,f); +} +} +}); +/** + * Returns true if n is a JavaScript number with no decimal part. + */ +cljs.core.integer_QMARK_ = (function cljs$core$integer_QMARK_(n){ +return ((typeof n === 'number') && ((!(isNaN(n)))) && ((!((n === Infinity)))) && ((parseFloat(n) === parseInt(n,(10))))); +}); +/** + * Return true if x satisfies integer? or is an instance of goog.math.Integer + * or goog.math.Long. + */ +cljs.core.int_QMARK_ = (function cljs$core$int_QMARK_(x){ +return ((cljs.core.integer_QMARK_(x)) || ((x instanceof goog.math.Integer)) || ((x instanceof goog.math.Long))); +}); +/** + * Return true if x satisfies int? and is positive. + */ +cljs.core.pos_int_QMARK_ = (function cljs$core$pos_int_QMARK_(x){ +if(cljs.core.integer_QMARK_(x)){ +return (x > (0)); +} else { +if((x instanceof goog.math.Integer)){ +return ((cljs.core.not(x.isNegative())) && (cljs.core.not(x.isZero()))); +} else { +if((x instanceof goog.math.Long)){ +return ((cljs.core.not(x.isNegative())) && (cljs.core.not(x.isZero()))); +} else { +return false; + +} +} +} +}); +/** + * Return true if x satisfies int? and is negative. + */ +cljs.core.neg_int_QMARK_ = (function cljs$core$neg_int_QMARK_(x){ +if(cljs.core.integer_QMARK_(x)){ +return (x < (0)); +} else { +if((x instanceof goog.math.Integer)){ +return x.isNegative(); +} else { +if((x instanceof goog.math.Long)){ +return x.isNegative(); +} else { +return false; + +} +} +} +}); +/** + * Return true if x satisfies int? and is a natural integer value. + */ +cljs.core.nat_int_QMARK_ = (function cljs$core$nat_int_QMARK_(x){ +if(cljs.core.integer_QMARK_(x)){ +return (!((x < (0)))); +} else { +if((x instanceof goog.math.Integer)){ +return cljs.core.not(x.isNegative()); +} else { +if((x instanceof goog.math.Long)){ +return cljs.core.not(x.isNegative()); +} else { +return false; + +} +} +} +}); +/** + * Returns true for JavaScript numbers, false otherwise. + */ +cljs.core.float_QMARK_ = (function cljs$core$float_QMARK_(x){ +return typeof x === 'number'; +}); +/** + * Returns true for JavaScript numbers, false otherwise. + */ +cljs.core.double_QMARK_ = (function cljs$core$double_QMARK_(x){ +return typeof x === 'number'; +}); +/** + * Returns true for Infinity and -Infinity values. + */ +cljs.core.infinite_QMARK_ = (function cljs$core$infinite_QMARK_(x){ +return (((x === Number.POSITIVE_INFINITY)) || ((x === Number.NEGATIVE_INFINITY))); +}); +/** + * Returns true if key is present in the given collection, otherwise + * returns false. Note that for numerically indexed collections like + * vectors and arrays, this tests if the numeric key is within the + * range of indexes. 'contains?' operates constant or logarithmic time; + * it will not perform a linear search for a value. See also 'some'. + */ +cljs.core.contains_QMARK_ = (function cljs$core$contains_QMARK_(coll,v){ +if((cljs.core.get.cljs$core$IFn$_invoke$arity$3(coll,v,cljs.core.lookup_sentinel) === cljs.core.lookup_sentinel)){ +return false; +} else { +return true; +} +}); +/** + * Returns the map entry for key, or nil if key not present. + */ +cljs.core.find = (function cljs$core$find(coll,k){ +if(cljs.core.ifind_QMARK_(coll)){ +return cljs.core._find(coll,k); +} else { +if((((!((coll == null)))) && (cljs.core.associative_QMARK_(coll)) && (cljs.core.contains_QMARK_(coll,k)))){ +return (new cljs.core.MapEntry(k,cljs.core.get.cljs$core$IFn$_invoke$arity$2(coll,k),null)); +} else { +return null; +} +} +}); +/** + * Returns true if no two of the arguments are = + */ +cljs.core.distinct_QMARK_ = (function cljs$core$distinct_QMARK_(var_args){ +var G__3050 = arguments.length; +switch (G__3050) { +case 1: +return cljs.core.distinct_QMARK_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.distinct_QMARK_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3052 = arguments.length; +var i__4731__auto___3053 = (0); +while(true){ +if((i__4731__auto___3053 < len__4730__auto___3052)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3053])); + +var G__3054 = (i__4731__auto___3053 + (1)); +i__4731__auto___3053 = G__3054; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.distinct_QMARK_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.distinct_QMARK_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return true; +}); + +cljs.core.distinct_QMARK_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (!(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(x,y))); +}); + +cljs.core.distinct_QMARK_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +if((!(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(x,y)))){ +var s = cljs.core.PersistentHashSet.createAsIfByAssoc([x,y]); +var xs = more; +while(true){ +var x__$1 = cljs.core.first(xs); +var etc = cljs.core.next(xs); +if(cljs.core.truth_(xs)){ +if(cljs.core.contains_QMARK_(s,x__$1)){ +return false; +} else { +var G__3055 = cljs.core.conj.cljs$core$IFn$_invoke$arity$2(s,x__$1); +var G__3056 = etc; +s = G__3055; +xs = G__3056; +continue; +} +} else { +return true; +} +break; +} +} else { +return false; +} +}); + +/** @this {Function} */ +cljs.core.distinct_QMARK_.cljs$lang$applyTo = (function (seq3047){ +var G__3048 = cljs.core.first(seq3047); +var seq3047__$1 = cljs.core.next(seq3047); +var G__3049 = cljs.core.first(seq3047__$1); +var seq3047__$2 = cljs.core.next(seq3047__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3048,G__3049,seq3047__$2); +}); + +cljs.core.distinct_QMARK_.cljs$lang$maxFixedArity = (2); + +/** + * Comparator. Returns a negative number, zero, or a positive number + * when x is logically 'less than', 'equal to', or 'greater than' + * y. Uses IComparable if available and google.array.defaultCompare for objects + * of the same type and special-cases nil to be less than any other object. + */ +cljs.core.compare = (function cljs$core$compare(x,y){ +if((x === y)){ +return (0); +} else { +if((x == null)){ +return (-1); +} else { +if((y == null)){ +return (1); +} else { +if(typeof x === 'number'){ +if(typeof y === 'number'){ +return goog.array.defaultCompare(x,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} +} else { +if((((!((x == null))))?(((((x.cljs$lang$protocol_mask$partition1$ & (2048))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IComparable$))))?true:(((!x.cljs$lang$protocol_mask$partition1$))?cljs.core.native_satisfies_QMARK_(cljs.core.IComparable,x):false)):cljs.core.native_satisfies_QMARK_(cljs.core.IComparable,x))){ +return cljs.core._compare(x,y); +} else { +if(((((typeof x === 'string') || (cljs.core.array_QMARK_(x)) || (x === true) || (x === false))) && ((cljs.core.type(x) === cljs.core.type(y))))){ +return goog.array.defaultCompare(x,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} + +} +} +} +} +} +}); +/** + * Compare indexed collection. + */ +cljs.core.compare_indexed = (function cljs$core$compare_indexed(var_args){ +var G__3059 = arguments.length; +switch (G__3059) { +case 2: +return cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 4: +return cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$2 = (function (xs,ys){ +var xl = cljs.core.count(xs); +var yl = cljs.core.count(ys); +if((xl < yl)){ +return (-1); +} else { +if((xl > yl)){ +return (1); +} else { +if((xl === (0))){ +return (0); +} else { +return cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$4(xs,ys,xl,(0)); + +} +} +} +}); + +cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$4 = (function (xs,ys,len,n){ +while(true){ +var d = cljs.core.compare(cljs.core.nth.cljs$core$IFn$_invoke$arity$2(xs,n),cljs.core.nth.cljs$core$IFn$_invoke$arity$2(ys,n)); +if((((d === (0))) && (((n + (1)) < len)))){ +var G__3061 = xs; +var G__3062 = ys; +var G__3063 = len; +var G__3064 = (n + (1)); +xs = G__3061; +ys = G__3062; +len = G__3063; +n = G__3064; +continue; +} else { +return d; +} +break; +} +}); + +cljs.core.compare_indexed.cljs$lang$maxFixedArity = 4; + +/** + * Given a fn that might be boolean valued or a comparator, + * return a fn that is a comparator. + */ +cljs.core.fn__GT_comparator = (function cljs$core$fn__GT_comparator(f){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(f,cljs.core.compare)){ +return cljs.core.compare; +} else { +return (function (x,y){ +var r = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(x,y) : f.call(null,x,y)); +if(typeof r === 'number'){ +return r; +} else { +if(cljs.core.truth_(r)){ +return (-1); +} else { +if(cljs.core.truth_((f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(y,x) : f.call(null,y,x)))){ +return (1); +} else { +return (0); +} +} +} +}); +} +}); +/** + * Returns a sorted sequence of the items in coll. Comp can be + * boolean-valued comparison function, or a -/0/+ valued comparator. + * Comp defaults to compare. + */ +cljs.core.sort = (function cljs$core$sort(var_args){ +var G__3066 = arguments.length; +switch (G__3066) { +case 1: +return cljs.core.sort.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.sort.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.sort.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +return cljs.core.sort.cljs$core$IFn$_invoke$arity$2(cljs.core.compare,coll); +}); + +cljs.core.sort.cljs$core$IFn$_invoke$arity$2 = (function (comp,coll){ +if(cljs.core.seq(coll)){ +var a = cljs.core.to_array(coll); +var G__3067_3070 = a; +var G__3068_3071 = cljs.core.fn__GT_comparator(comp); +goog.array.stableSort(G__3067_3070,G__3068_3071); + +return cljs.core.seq(a); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.sort.cljs$lang$maxFixedArity = 2; + +/** + * Returns a sorted sequence of the items in coll, where the sort + * order is determined by comparing (keyfn item). Comp can be + * boolean-valued comparison function, or a -/0/+ valued comparator. + * Comp defaults to compare. + */ +cljs.core.sort_by = (function cljs$core$sort_by(var_args){ +var G__3073 = arguments.length; +switch (G__3073) { +case 2: +return cljs.core.sort_by.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.sort_by.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.sort_by.cljs$core$IFn$_invoke$arity$2 = (function (keyfn,coll){ +return cljs.core.sort_by.cljs$core$IFn$_invoke$arity$3(keyfn,cljs.core.compare,coll); +}); + +cljs.core.sort_by.cljs$core$IFn$_invoke$arity$3 = (function (keyfn,comp,coll){ +return cljs.core.sort.cljs$core$IFn$_invoke$arity$2((function (x,y){ +var G__3075 = (keyfn.cljs$core$IFn$_invoke$arity$1 ? keyfn.cljs$core$IFn$_invoke$arity$1(x) : keyfn.call(null,x)); +var G__3076 = (keyfn.cljs$core$IFn$_invoke$arity$1 ? keyfn.cljs$core$IFn$_invoke$arity$1(y) : keyfn.call(null,y)); +var fexpr__3074 = cljs.core.fn__GT_comparator(comp); +return (fexpr__3074.cljs$core$IFn$_invoke$arity$2 ? fexpr__3074.cljs$core$IFn$_invoke$arity$2(G__3075,G__3076) : fexpr__3074.call(null,G__3075,G__3076)); +}),coll); +}); + +cljs.core.sort_by.cljs$lang$maxFixedArity = 3; + +cljs.core.seq_reduce = (function cljs$core$seq_reduce(var_args){ +var G__3079 = arguments.length; +switch (G__3079) { +case 2: +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +var temp__5733__auto__ = cljs.core.seq(coll); +if(temp__5733__auto__){ +var s = temp__5733__auto__; +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(f,cljs.core.first(s),cljs.core.next(s)); +} else { +return (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); +} +}); + +cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3 = (function (f,val,coll){ +var val__$1 = val; +var coll__$1 = cljs.core.seq(coll); +while(true){ +if(coll__$1){ +var nval = (function (){var G__3080 = val__$1; +var G__3081 = cljs.core.first(coll__$1); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3080,G__3081) : f.call(null,G__3080,G__3081)); +})(); +if(cljs.core.reduced_QMARK_(nval)){ +return cljs.core.deref(nval); +} else { +var G__3083 = nval; +var G__3084 = cljs.core.next(coll__$1); +val__$1 = G__3083; +coll__$1 = G__3084; +continue; +} +} else { +return val__$1; +} +break; +} +}); + +cljs.core.seq_reduce.cljs$lang$maxFixedArity = 3; + +/** + * Return a random permutation of coll + */ +cljs.core.shuffle = (function cljs$core$shuffle(coll){ +var a = cljs.core.to_array(coll); +goog.array.shuffle(a); + +return cljs.core.vec(a); +}); +cljs.core.iter_reduce = (function cljs$core$iter_reduce(var_args){ +var G__3086 = arguments.length; +switch (G__3086) { +case 2: +return cljs.core.iter_reduce.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.iter_reduce.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.iter_reduce.cljs$core$IFn$_invoke$arity$2 = (function (coll,f){ +var iter = cljs.core._iterator(coll); +if(cljs.core.truth_(iter.hasNext())){ +var init = iter.next(); +var acc = init; +while(true){ +if(iter.hasNext()){ +var nacc = (function (){var G__3087 = acc; +var G__3088 = iter.next(); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3087,G__3088) : f.call(null,G__3087,G__3088)); +})(); +if(cljs.core.reduced_QMARK_(nacc)){ +return cljs.core.deref(nacc); +} else { +var G__3092 = nacc; +acc = G__3092; +continue; +} +} else { +return acc; +} +break; +} +} else { +return (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); +} +}); + +cljs.core.iter_reduce.cljs$core$IFn$_invoke$arity$3 = (function (coll,f,init){ +var iter = cljs.core._iterator(coll); +var acc = init; +while(true){ +if(iter.hasNext()){ +var nacc = (function (){var G__3089 = acc; +var G__3090 = iter.next(); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3089,G__3090) : f.call(null,G__3089,G__3090)); +})(); +if(cljs.core.reduced_QMARK_(nacc)){ +return cljs.core.deref(nacc); +} else { +var G__3093 = nacc; +acc = G__3093; +continue; +} +} else { +return acc; +} +break; +} +}); + +cljs.core.iter_reduce.cljs$lang$maxFixedArity = 3; + +/** + * f should be a function of 2 arguments. If val is not supplied, + * returns the result of applying f to the first 2 items in coll, then + * applying f to that result and the 3rd item, etc. If coll contains no + * items, f must accept no arguments as well, and reduce returns the + * result of calling f with no arguments. If coll has only 1 item, it + * is returned and f is not called. If val is supplied, returns the + * result of applying f to val and the first item in coll, then + * applying f to that result and the 2nd item, etc. If coll contains no + * items, returns val and f is not called. + */ +cljs.core.reduce = (function cljs$core$reduce(var_args){ +var G__3095 = arguments.length; +switch (G__3095) { +case 2: +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.reduce.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (524288))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$IReduce$))))?true:false):false)){ +return cljs.core._reduce.cljs$core$IFn$_invoke$arity$2(coll,f); +} else { +if(cljs.core.array_QMARK_(coll)){ +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$2(coll,f); +} else { +if(typeof coll === 'string'){ +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$2(coll,f); +} else { +if(cljs.core.native_satisfies_QMARK_(cljs.core.IReduce,coll)){ +return cljs.core._reduce.cljs$core$IFn$_invoke$arity$2(coll,f); +} else { +if(cljs.core.iterable_QMARK_(coll)){ +return cljs.core.iter_reduce.cljs$core$IFn$_invoke$arity$2(coll,f); +} else { +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll); + +} +} +} +} +} +}); + +cljs.core.reduce.cljs$core$IFn$_invoke$arity$3 = (function (f,val,coll){ +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (524288))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$IReduce$))))?true:false):false)){ +return cljs.core._reduce.cljs$core$IFn$_invoke$arity$3(coll,f,val); +} else { +if(cljs.core.array_QMARK_(coll)){ +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$3(coll,f,val); +} else { +if(typeof coll === 'string'){ +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$3(coll,f,val); +} else { +if(cljs.core.native_satisfies_QMARK_(cljs.core.IReduce,coll)){ +return cljs.core._reduce.cljs$core$IFn$_invoke$arity$3(coll,f,val); +} else { +if(cljs.core.iterable_QMARK_(coll)){ +return cljs.core.iter_reduce.cljs$core$IFn$_invoke$arity$3(coll,f,val); +} else { +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,val,coll); + +} +} +} +} +} +}); + +cljs.core.reduce.cljs$lang$maxFixedArity = 3; + +/** + * Reduces an associative collection. f should be a function of 3 + * arguments. Returns the result of applying f to init, the first key + * and the first value in coll, then applying f to that result and the + * 2nd key and value, etc. If coll contains no entries, returns init + * and f is not called. Note that reduce-kv is supported on vectors, + * where the keys will be the ordinals. + */ +cljs.core.reduce_kv = (function cljs$core$reduce_kv(f,init,coll){ +if((!((coll == null)))){ +return cljs.core._kv_reduce(coll,f,init); +} else { +return init; +} +}); +/** + * Returns its argument. + */ +cljs.core.identity = (function cljs$core$identity(x){ +return x; +}); +/** + * Takes a reducing function f of 2 args and returns a fn suitable for + * transduce by adding an arity-1 signature that calls cf (default - + * identity) on the result argument. + */ +cljs.core.completing = (function cljs$core$completing(var_args){ +var G__3100 = arguments.length; +switch (G__3100) { +case 1: +return cljs.core.completing.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.completing.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.completing.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return cljs.core.completing.cljs$core$IFn$_invoke$arity$2(f,cljs.core.identity); +}); + +cljs.core.completing.cljs$core$IFn$_invoke$arity$2 = (function (f,cf){ +return (function() { +var G__3102 = null; +var G__3102__0 = (function (){ +return (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); +}); +var G__3102__1 = (function (x){ +return (cf.cljs$core$IFn$_invoke$arity$1 ? cf.cljs$core$IFn$_invoke$arity$1(x) : cf.call(null,x)); +}); +var G__3102__2 = (function (x,y){ +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(x,y) : f.call(null,x,y)); +}); +G__3102 = function(x,y){ +switch(arguments.length){ +case 0: +return G__3102__0.call(this); +case 1: +return G__3102__1.call(this,x); +case 2: +return G__3102__2.call(this,x,y); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3102.cljs$core$IFn$_invoke$arity$0 = G__3102__0; +G__3102.cljs$core$IFn$_invoke$arity$1 = G__3102__1; +G__3102.cljs$core$IFn$_invoke$arity$2 = G__3102__2; +return G__3102; +})() +}); + +cljs.core.completing.cljs$lang$maxFixedArity = 2; + +/** + * reduce with a transformation of f (xf). If init is not + * supplied, (f) will be called to produce it. f should be a reducing + * step function that accepts both 1 and 2 arguments, if it accepts + * only 2 you can add the arity-1 with 'completing'. Returns the result + * of applying (the transformed) xf to init and the first item in coll, + * then applying xf to that result and the 2nd item, etc. If coll + * contains no items, returns init and f is not called. Note that + * certain transforms may inject or skip items. + */ +cljs.core.transduce = (function cljs$core$transduce(var_args){ +var G__3104 = arguments.length; +switch (G__3104) { +case 3: +return cljs.core.transduce.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.transduce.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.transduce.cljs$core$IFn$_invoke$arity$3 = (function (xform,f,coll){ +return cljs.core.transduce.cljs$core$IFn$_invoke$arity$4(xform,f,(f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)),coll); +}); + +cljs.core.transduce.cljs$core$IFn$_invoke$arity$4 = (function (xform,f,init,coll){ +var f__$1 = (xform.cljs$core$IFn$_invoke$arity$1 ? xform.cljs$core$IFn$_invoke$arity$1(f) : xform.call(null,f)); +var ret = cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(f__$1,init,coll); +return (f__$1.cljs$core$IFn$_invoke$arity$1 ? f__$1.cljs$core$IFn$_invoke$arity$1(ret) : f__$1.call(null,ret)); +}); + +cljs.core.transduce.cljs$lang$maxFixedArity = 4; + +/** + * Returns the sum of nums. (+) returns 0. + */ +cljs.core._PLUS_ = (function cljs$core$_PLUS_(var_args){ +var G__3110 = arguments.length; +switch (G__3110) { +case 0: +return cljs.core._PLUS_.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core._PLUS_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._PLUS_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3112 = arguments.length; +var i__4731__auto___3113 = (0); +while(true){ +if((i__4731__auto___3113 < len__4730__auto___3112)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3113])); + +var G__3114 = (i__4731__auto___3113 + (1)); +i__4731__auto___3113 = G__3114; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._PLUS_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._PLUS_.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (0); +}); + +cljs.core._PLUS_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return x; +}); + +cljs.core._PLUS_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x + y); +}); + +cljs.core._PLUS_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._PLUS_,(x + y),more); +}); + +/** @this {Function} */ +cljs.core._PLUS_.cljs$lang$applyTo = (function (seq3107){ +var G__3108 = cljs.core.first(seq3107); +var seq3107__$1 = cljs.core.next(seq3107); +var G__3109 = cljs.core.first(seq3107__$1); +var seq3107__$2 = cljs.core.next(seq3107__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3108,G__3109,seq3107__$2); +}); + +cljs.core._PLUS_.cljs$lang$maxFixedArity = (2); + +/** + * If no ys are supplied, returns the negation of x, else subtracts + * the ys from x and returns the result. + */ +cljs.core._ = (function cljs$core$_(var_args){ +var G__3119 = arguments.length; +switch (G__3119) { +case 1: +return cljs.core._.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3121 = arguments.length; +var i__4731__auto___3122 = (0); +while(true){ +if((i__4731__auto___3122 < len__4730__auto___3121)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3122])); + +var G__3123 = (i__4731__auto___3122 + (1)); +i__4731__auto___3122 = G__3123; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return (- x); +}); + +cljs.core._.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x - y); +}); + +cljs.core._.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._,(x - y),more); +}); + +/** @this {Function} */ +cljs.core._.cljs$lang$applyTo = (function (seq3116){ +var G__3117 = cljs.core.first(seq3116); +var seq3116__$1 = cljs.core.next(seq3116); +var G__3118 = cljs.core.first(seq3116__$1); +var seq3116__$2 = cljs.core.next(seq3116__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3117,G__3118,seq3116__$2); +}); + +cljs.core._.cljs$lang$maxFixedArity = (2); + +/** + * Returns the product of nums. (*) returns 1. + */ +cljs.core._STAR_ = (function cljs$core$_STAR_(var_args){ +var G__3128 = arguments.length; +switch (G__3128) { +case 0: +return cljs.core._STAR_.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core._STAR_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._STAR_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3130 = arguments.length; +var i__4731__auto___3131 = (0); +while(true){ +if((i__4731__auto___3131 < len__4730__auto___3130)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3131])); + +var G__3132 = (i__4731__auto___3131 + (1)); +i__4731__auto___3131 = G__3132; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._STAR_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._STAR_.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (1); +}); + +cljs.core._STAR_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return x; +}); + +cljs.core._STAR_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x * y); +}); + +cljs.core._STAR_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._STAR_,(x * y),more); +}); + +/** @this {Function} */ +cljs.core._STAR_.cljs$lang$applyTo = (function (seq3125){ +var G__3126 = cljs.core.first(seq3125); +var seq3125__$1 = cljs.core.next(seq3125); +var G__3127 = cljs.core.first(seq3125__$1); +var seq3125__$2 = cljs.core.next(seq3125__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3126,G__3127,seq3125__$2); +}); + +cljs.core._STAR_.cljs$lang$maxFixedArity = (2); + +/** + * If no denominators are supplied, returns 1/numerator, + * else returns numerator divided by all of the denominators. + */ +cljs.core._SLASH_ = (function cljs$core$_SLASH_(var_args){ +var G__3137 = arguments.length; +switch (G__3137) { +case 1: +return cljs.core._SLASH_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._SLASH_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3139 = arguments.length; +var i__4731__auto___3140 = (0); +while(true){ +if((i__4731__auto___3140 < len__4730__auto___3139)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3140])); + +var G__3141 = (i__4731__auto___3140 + (1)); +i__4731__auto___3140 = G__3141; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._SLASH_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._SLASH_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return ((1) / x); +}); + +cljs.core._SLASH_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x / y); +}); + +cljs.core._SLASH_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._SLASH_,(x / y),more); +}); + +/** @this {Function} */ +cljs.core._SLASH_.cljs$lang$applyTo = (function (seq3134){ +var G__3135 = cljs.core.first(seq3134); +var seq3134__$1 = cljs.core.next(seq3134); +var G__3136 = cljs.core.first(seq3134__$1); +var seq3134__$2 = cljs.core.next(seq3134__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3135,G__3136,seq3134__$2); +}); + +cljs.core._SLASH_.cljs$lang$maxFixedArity = (2); + +/** + * Returns non-nil if nums are in monotonically increasing order, + * otherwise false. + */ +cljs.core._LT_ = (function cljs$core$_LT_(var_args){ +var G__3146 = arguments.length; +switch (G__3146) { +case 1: +return cljs.core._LT_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._LT_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3148 = arguments.length; +var i__4731__auto___3149 = (0); +while(true){ +if((i__4731__auto___3149 < len__4730__auto___3148)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3149])); + +var G__3150 = (i__4731__auto___3149 + (1)); +i__4731__auto___3149 = G__3150; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._LT_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._LT_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return true; +}); + +cljs.core._LT_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x < y); +}); + +cljs.core._LT_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +while(true){ +if((x < y)){ +if(cljs.core.next(more)){ +var G__3151 = y; +var G__3152 = cljs.core.first(more); +var G__3153 = cljs.core.next(more); +x = G__3151; +y = G__3152; +more = G__3153; +continue; +} else { +return (y < cljs.core.first(more)); +} +} else { +return false; +} +break; +} +}); + +/** @this {Function} */ +cljs.core._LT_.cljs$lang$applyTo = (function (seq3143){ +var G__3144 = cljs.core.first(seq3143); +var seq3143__$1 = cljs.core.next(seq3143); +var G__3145 = cljs.core.first(seq3143__$1); +var seq3143__$2 = cljs.core.next(seq3143__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3144,G__3145,seq3143__$2); +}); + +cljs.core._LT_.cljs$lang$maxFixedArity = (2); + +/** + * Returns non-nil if nums are in monotonically non-decreasing order, + * otherwise false. + */ +cljs.core._LT__EQ_ = (function cljs$core$_LT__EQ_(var_args){ +var G__3158 = arguments.length; +switch (G__3158) { +case 1: +return cljs.core._LT__EQ_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._LT__EQ_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3160 = arguments.length; +var i__4731__auto___3161 = (0); +while(true){ +if((i__4731__auto___3161 < len__4730__auto___3160)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3161])); + +var G__3162 = (i__4731__auto___3161 + (1)); +i__4731__auto___3161 = G__3162; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._LT__EQ_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._LT__EQ_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return true; +}); + +cljs.core._LT__EQ_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x <= y); +}); + +cljs.core._LT__EQ_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +while(true){ +if((x <= y)){ +if(cljs.core.next(more)){ +var G__3163 = y; +var G__3164 = cljs.core.first(more); +var G__3165 = cljs.core.next(more); +x = G__3163; +y = G__3164; +more = G__3165; +continue; +} else { +return (y <= cljs.core.first(more)); +} +} else { +return false; +} +break; +} +}); + +/** @this {Function} */ +cljs.core._LT__EQ_.cljs$lang$applyTo = (function (seq3155){ +var G__3156 = cljs.core.first(seq3155); +var seq3155__$1 = cljs.core.next(seq3155); +var G__3157 = cljs.core.first(seq3155__$1); +var seq3155__$2 = cljs.core.next(seq3155__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3156,G__3157,seq3155__$2); +}); + +cljs.core._LT__EQ_.cljs$lang$maxFixedArity = (2); + +/** + * Returns non-nil if nums are in monotonically decreasing order, + * otherwise false. + */ +cljs.core._GT_ = (function cljs$core$_GT_(var_args){ +var G__3170 = arguments.length; +switch (G__3170) { +case 1: +return cljs.core._GT_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._GT_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3172 = arguments.length; +var i__4731__auto___3173 = (0); +while(true){ +if((i__4731__auto___3173 < len__4730__auto___3172)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3173])); + +var G__3174 = (i__4731__auto___3173 + (1)); +i__4731__auto___3173 = G__3174; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._GT_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._GT_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return true; +}); + +cljs.core._GT_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x > y); +}); + +cljs.core._GT_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +while(true){ +if((x > y)){ +if(cljs.core.next(more)){ +var G__3175 = y; +var G__3176 = cljs.core.first(more); +var G__3177 = cljs.core.next(more); +x = G__3175; +y = G__3176; +more = G__3177; +continue; +} else { +return (y > cljs.core.first(more)); +} +} else { +return false; +} +break; +} +}); + +/** @this {Function} */ +cljs.core._GT_.cljs$lang$applyTo = (function (seq3167){ +var G__3168 = cljs.core.first(seq3167); +var seq3167__$1 = cljs.core.next(seq3167); +var G__3169 = cljs.core.first(seq3167__$1); +var seq3167__$2 = cljs.core.next(seq3167__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3168,G__3169,seq3167__$2); +}); + +cljs.core._GT_.cljs$lang$maxFixedArity = (2); + +/** + * Returns non-nil if nums are in monotonically non-increasing order, + * otherwise false. + */ +cljs.core._GT__EQ_ = (function cljs$core$_GT__EQ_(var_args){ +var G__3182 = arguments.length; +switch (G__3182) { +case 1: +return cljs.core._GT__EQ_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._GT__EQ_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3184 = arguments.length; +var i__4731__auto___3185 = (0); +while(true){ +if((i__4731__auto___3185 < len__4730__auto___3184)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3185])); + +var G__3186 = (i__4731__auto___3185 + (1)); +i__4731__auto___3185 = G__3186; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._GT__EQ_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._GT__EQ_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return true; +}); + +cljs.core._GT__EQ_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x >= y); +}); + +cljs.core._GT__EQ_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +while(true){ +if((x >= y)){ +if(cljs.core.next(more)){ +var G__3187 = y; +var G__3188 = cljs.core.first(more); +var G__3189 = cljs.core.next(more); +x = G__3187; +y = G__3188; +more = G__3189; +continue; +} else { +return (y >= cljs.core.first(more)); +} +} else { +return false; +} +break; +} +}); + +/** @this {Function} */ +cljs.core._GT__EQ_.cljs$lang$applyTo = (function (seq3179){ +var G__3180 = cljs.core.first(seq3179); +var seq3179__$1 = cljs.core.next(seq3179); +var G__3181 = cljs.core.first(seq3179__$1); +var seq3179__$2 = cljs.core.next(seq3179__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3180,G__3181,seq3179__$2); +}); + +cljs.core._GT__EQ_.cljs$lang$maxFixedArity = (2); + +/** + * Returns a number one less than num. + */ +cljs.core.dec = (function cljs$core$dec(x){ +return (x - (1)); +}); +/** + * Returns the greatest of the nums. + */ +cljs.core.max = (function cljs$core$max(var_args){ +var G__3194 = arguments.length; +switch (G__3194) { +case 1: +return cljs.core.max.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.max.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3196 = arguments.length; +var i__4731__auto___3197 = (0); +while(true){ +if((i__4731__auto___3197 < len__4730__auto___3196)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3197])); + +var G__3198 = (i__4731__auto___3197 + (1)); +i__4731__auto___3197 = G__3198; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.max.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.max.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return x; +}); + +cljs.core.max.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +var x__4219__auto__ = x; +var y__4220__auto__ = y; +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +}); + +cljs.core.max.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.max,(function (){var x__4219__auto__ = x; +var y__4220__auto__ = y; +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +})(),more); +}); + +/** @this {Function} */ +cljs.core.max.cljs$lang$applyTo = (function (seq3191){ +var G__3192 = cljs.core.first(seq3191); +var seq3191__$1 = cljs.core.next(seq3191); +var G__3193 = cljs.core.first(seq3191__$1); +var seq3191__$2 = cljs.core.next(seq3191__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3192,G__3193,seq3191__$2); +}); + +cljs.core.max.cljs$lang$maxFixedArity = (2); + +/** + * Returns the least of the nums. + */ +cljs.core.min = (function cljs$core$min(var_args){ +var G__3203 = arguments.length; +switch (G__3203) { +case 1: +return cljs.core.min.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.min.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3205 = arguments.length; +var i__4731__auto___3206 = (0); +while(true){ +if((i__4731__auto___3206 < len__4730__auto___3205)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3206])); + +var G__3207 = (i__4731__auto___3206 + (1)); +i__4731__auto___3206 = G__3207; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.min.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.min.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return x; +}); + +cljs.core.min.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +var x__4222__auto__ = x; +var y__4223__auto__ = y; +return ((x__4222__auto__ < y__4223__auto__) ? x__4222__auto__ : y__4223__auto__); +}); + +cljs.core.min.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.min,(function (){var x__4222__auto__ = x; +var y__4223__auto__ = y; +return ((x__4222__auto__ < y__4223__auto__) ? x__4222__auto__ : y__4223__auto__); +})(),more); +}); + +/** @this {Function} */ +cljs.core.min.cljs$lang$applyTo = (function (seq3200){ +var G__3201 = cljs.core.first(seq3200); +var seq3200__$1 = cljs.core.next(seq3200); +var G__3202 = cljs.core.first(seq3200__$1); +var seq3200__$2 = cljs.core.next(seq3200__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3201,G__3202,seq3200__$2); +}); + +cljs.core.min.cljs$lang$maxFixedArity = (2); + +cljs.core.byte$ = (function cljs$core$byte(x){ +return x; +}); +/** + * Coerce to char + */ +cljs.core.char$ = (function cljs$core$char(x){ +if(typeof x === 'number'){ +return String.fromCharCode(x); +} else { +if(((typeof x === 'string') && ((x.length === (1))))){ +return x; +} else { +throw (new Error("Argument to char must be a character or number")); + +} +} +}); +cljs.core.short$ = (function cljs$core$short(x){ +return x; +}); +cljs.core.float$ = (function cljs$core$float(x){ +return x; +}); +cljs.core.double$ = (function cljs$core$double(x){ +return x; +}); +cljs.core.unchecked_byte = (function cljs$core$unchecked_byte(x){ +return x; +}); +cljs.core.unchecked_char = (function cljs$core$unchecked_char(x){ +return x; +}); +cljs.core.unchecked_short = (function cljs$core$unchecked_short(x){ +return x; +}); +cljs.core.unchecked_float = (function cljs$core$unchecked_float(x){ +return x; +}); +cljs.core.unchecked_double = (function cljs$core$unchecked_double(x){ +return x; +}); +/** + * Returns the sum of nums. (+) returns 0. + */ +cljs.core.unchecked_add = (function cljs$core$unchecked_add(var_args){ +var G__3212 = arguments.length; +switch (G__3212) { +case 0: +return cljs.core.unchecked_add.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.unchecked_add.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.unchecked_add.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3214 = arguments.length; +var i__4731__auto___3215 = (0); +while(true){ +if((i__4731__auto___3215 < len__4730__auto___3214)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3215])); + +var G__3216 = (i__4731__auto___3215 + (1)); +i__4731__auto___3215 = G__3216; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.unchecked_add.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.unchecked_add.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (0); +}); + +cljs.core.unchecked_add.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return x; +}); + +cljs.core.unchecked_add.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x + y); +}); + +cljs.core.unchecked_add.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.unchecked_add,(x + y),more); +}); + +/** @this {Function} */ +cljs.core.unchecked_add.cljs$lang$applyTo = (function (seq3209){ +var G__3210 = cljs.core.first(seq3209); +var seq3209__$1 = cljs.core.next(seq3209); +var G__3211 = cljs.core.first(seq3209__$1); +var seq3209__$2 = cljs.core.next(seq3209__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3210,G__3211,seq3209__$2); +}); + +cljs.core.unchecked_add.cljs$lang$maxFixedArity = (2); + +/** + * Returns the sum of nums. (+) returns 0. + */ +cljs.core.unchecked_add_int = (function cljs$core$unchecked_add_int(var_args){ +var G__3221 = arguments.length; +switch (G__3221) { +case 0: +return cljs.core.unchecked_add_int.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.unchecked_add_int.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.unchecked_add_int.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3223 = arguments.length; +var i__4731__auto___3224 = (0); +while(true){ +if((i__4731__auto___3224 < len__4730__auto___3223)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3224])); + +var G__3225 = (i__4731__auto___3224 + (1)); +i__4731__auto___3224 = G__3225; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.unchecked_add_int.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.unchecked_add_int.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (0); +}); + +cljs.core.unchecked_add_int.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return x; +}); + +cljs.core.unchecked_add_int.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x + y); +}); + +cljs.core.unchecked_add_int.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.unchecked_add_int,(x + y),more); +}); + +/** @this {Function} */ +cljs.core.unchecked_add_int.cljs$lang$applyTo = (function (seq3218){ +var G__3219 = cljs.core.first(seq3218); +var seq3218__$1 = cljs.core.next(seq3218); +var G__3220 = cljs.core.first(seq3218__$1); +var seq3218__$2 = cljs.core.next(seq3218__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3219,G__3220,seq3218__$2); +}); + +cljs.core.unchecked_add_int.cljs$lang$maxFixedArity = (2); + +/** + * Returns a number one less than x, an int. + */ +cljs.core.unchecked_dec = (function cljs$core$unchecked_dec(x){ +return (x - (1)); +}); +/** + * Returns a number one less than x, an int. + */ +cljs.core.unchecked_dec_int = (function cljs$core$unchecked_dec_int(x){ +return (x - (1)); +}); +/** + * If no denominators are supplied, returns 1/numerator, + * else returns numerator divided by all of the denominators. + */ +cljs.core.unchecked_divide_int = (function cljs$core$unchecked_divide_int(var_args){ +var G__3230 = arguments.length; +switch (G__3230) { +case 1: +return cljs.core.unchecked_divide_int.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.unchecked_divide_int.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3232 = arguments.length; +var i__4731__auto___3233 = (0); +while(true){ +if((i__4731__auto___3233 < len__4730__auto___3232)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3233])); + +var G__3234 = (i__4731__auto___3233 + (1)); +i__4731__auto___3233 = G__3234; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.unchecked_divide_int.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.unchecked_divide_int.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return ((1) / x); +}); + +cljs.core.unchecked_divide_int.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x / y); +}); + +cljs.core.unchecked_divide_int.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.unchecked_divide_int,(x / y),more); +}); + +/** @this {Function} */ +cljs.core.unchecked_divide_int.cljs$lang$applyTo = (function (seq3227){ +var G__3228 = cljs.core.first(seq3227); +var seq3227__$1 = cljs.core.next(seq3227); +var G__3229 = cljs.core.first(seq3227__$1); +var seq3227__$2 = cljs.core.next(seq3227__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3228,G__3229,seq3227__$2); +}); + +cljs.core.unchecked_divide_int.cljs$lang$maxFixedArity = (2); + +cljs.core.unchecked_inc = (function cljs$core$unchecked_inc(x){ +return (x + (1)); +}); +cljs.core.unchecked_inc_int = (function cljs$core$unchecked_inc_int(x){ +return (x + (1)); +}); +/** + * Returns the product of nums. (*) returns 1. + */ +cljs.core.unchecked_multiply = (function cljs$core$unchecked_multiply(var_args){ +var G__3239 = arguments.length; +switch (G__3239) { +case 0: +return cljs.core.unchecked_multiply.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.unchecked_multiply.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.unchecked_multiply.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3241 = arguments.length; +var i__4731__auto___3242 = (0); +while(true){ +if((i__4731__auto___3242 < len__4730__auto___3241)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3242])); + +var G__3243 = (i__4731__auto___3242 + (1)); +i__4731__auto___3242 = G__3243; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.unchecked_multiply.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.unchecked_multiply.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (1); +}); + +cljs.core.unchecked_multiply.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return x; +}); + +cljs.core.unchecked_multiply.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x * y); +}); + +cljs.core.unchecked_multiply.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.unchecked_multiply,(x * y),more); +}); + +/** @this {Function} */ +cljs.core.unchecked_multiply.cljs$lang$applyTo = (function (seq3236){ +var G__3237 = cljs.core.first(seq3236); +var seq3236__$1 = cljs.core.next(seq3236); +var G__3238 = cljs.core.first(seq3236__$1); +var seq3236__$2 = cljs.core.next(seq3236__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3237,G__3238,seq3236__$2); +}); + +cljs.core.unchecked_multiply.cljs$lang$maxFixedArity = (2); + +/** + * Returns the product of nums. (*) returns 1. + */ +cljs.core.unchecked_multiply_int = (function cljs$core$unchecked_multiply_int(var_args){ +var G__3248 = arguments.length; +switch (G__3248) { +case 0: +return cljs.core.unchecked_multiply_int.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.unchecked_multiply_int.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.unchecked_multiply_int.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3250 = arguments.length; +var i__4731__auto___3251 = (0); +while(true){ +if((i__4731__auto___3251 < len__4730__auto___3250)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3251])); + +var G__3252 = (i__4731__auto___3251 + (1)); +i__4731__auto___3251 = G__3252; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.unchecked_multiply_int.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.unchecked_multiply_int.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (1); +}); + +cljs.core.unchecked_multiply_int.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return x; +}); + +cljs.core.unchecked_multiply_int.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x * y); +}); + +cljs.core.unchecked_multiply_int.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.unchecked_multiply_int,(x * y),more); +}); + +/** @this {Function} */ +cljs.core.unchecked_multiply_int.cljs$lang$applyTo = (function (seq3245){ +var G__3246 = cljs.core.first(seq3245); +var seq3245__$1 = cljs.core.next(seq3245); +var G__3247 = cljs.core.first(seq3245__$1); +var seq3245__$2 = cljs.core.next(seq3245__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3246,G__3247,seq3245__$2); +}); + +cljs.core.unchecked_multiply_int.cljs$lang$maxFixedArity = (2); + +cljs.core.unchecked_negate = (function cljs$core$unchecked_negate(x){ +return (- x); +}); +cljs.core.unchecked_negate_int = (function cljs$core$unchecked_negate_int(x){ +return (- x); +}); +cljs.core.unchecked_remainder_int = (function cljs$core$unchecked_remainder_int(x,n){ +return cljs.core.mod(x,n); +}); +/** + * If no ys are supplied, returns the negation of x, else subtracts + * the ys from x and returns the result. + */ +cljs.core.unchecked_subtract = (function cljs$core$unchecked_subtract(var_args){ +var G__3257 = arguments.length; +switch (G__3257) { +case 1: +return cljs.core.unchecked_subtract.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.unchecked_subtract.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3259 = arguments.length; +var i__4731__auto___3260 = (0); +while(true){ +if((i__4731__auto___3260 < len__4730__auto___3259)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3260])); + +var G__3261 = (i__4731__auto___3260 + (1)); +i__4731__auto___3260 = G__3261; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.unchecked_subtract.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.unchecked_subtract.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return (- x); +}); + +cljs.core.unchecked_subtract.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x - y); +}); + +cljs.core.unchecked_subtract.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.unchecked_subtract,(x - y),more); +}); + +/** @this {Function} */ +cljs.core.unchecked_subtract.cljs$lang$applyTo = (function (seq3254){ +var G__3255 = cljs.core.first(seq3254); +var seq3254__$1 = cljs.core.next(seq3254); +var G__3256 = cljs.core.first(seq3254__$1); +var seq3254__$2 = cljs.core.next(seq3254__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3255,G__3256,seq3254__$2); +}); + +cljs.core.unchecked_subtract.cljs$lang$maxFixedArity = (2); + +/** + * If no ys are supplied, returns the negation of x, else subtracts + * the ys from x and returns the result. + */ +cljs.core.unchecked_subtract_int = (function cljs$core$unchecked_subtract_int(var_args){ +var G__3266 = arguments.length; +switch (G__3266) { +case 1: +return cljs.core.unchecked_subtract_int.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.unchecked_subtract_int.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3268 = arguments.length; +var i__4731__auto___3269 = (0); +while(true){ +if((i__4731__auto___3269 < len__4730__auto___3268)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3269])); + +var G__3270 = (i__4731__auto___3269 + (1)); +i__4731__auto___3269 = G__3270; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.unchecked_subtract_int.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.unchecked_subtract_int.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return (- x); +}); + +cljs.core.unchecked_subtract_int.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x - y); +}); + +cljs.core.unchecked_subtract_int.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.unchecked_subtract_int,(x - y),more); +}); + +/** @this {Function} */ +cljs.core.unchecked_subtract_int.cljs$lang$applyTo = (function (seq3263){ +var G__3264 = cljs.core.first(seq3263); +var seq3263__$1 = cljs.core.next(seq3263); +var G__3265 = cljs.core.first(seq3263__$1); +var seq3263__$2 = cljs.core.next(seq3263__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3264,G__3265,seq3263__$2); +}); + +cljs.core.unchecked_subtract_int.cljs$lang$maxFixedArity = (2); + +cljs.core.fix = (function cljs$core$fix(q){ +if((q >= (0))){ +return Math.floor(q); +} else { +return Math.ceil(q); +} +}); +/** + * Coerce to int by stripping decimal places. + */ +cljs.core.int$ = (function cljs$core$int(x){ +return (x | (0)); +}); +/** + * Coerce to int by stripping decimal places. + */ +cljs.core.unchecked_int = (function cljs$core$unchecked_int(x){ +return cljs.core.fix(x); +}); +/** + * Coerce to long by stripping decimal places. Identical to `int'. + */ +cljs.core.long$ = (function cljs$core$long(x){ +return cljs.core.fix(x); +}); +/** + * Coerce to long by stripping decimal places. Identical to `int'. + */ +cljs.core.unchecked_long = (function cljs$core$unchecked_long(x){ +return cljs.core.fix(x); +}); +cljs.core.booleans = (function cljs$core$booleans(x){ +return x; +}); +cljs.core.bytes = (function cljs$core$bytes(x){ +return x; +}); +cljs.core.chars = (function cljs$core$chars(x){ +return x; +}); +cljs.core.shorts = (function cljs$core$shorts(x){ +return x; +}); +cljs.core.ints = (function cljs$core$ints(x){ +return x; +}); +cljs.core.floats = (function cljs$core$floats(x){ +return x; +}); +cljs.core.doubles = (function cljs$core$doubles(x){ +return x; +}); +cljs.core.longs = (function cljs$core$longs(x){ +return x; +}); +/** + * Modulus of num and div with original javascript behavior. i.e. bug for negative numbers + */ +cljs.core.js_mod = (function cljs$core$js_mod(n,d){ +return (n % d); +}); +/** + * Modulus of num and div. Truncates toward negative infinity. + */ +cljs.core.mod = (function cljs$core$mod(n,d){ +return (((n % d) + d) % d); +}); +/** + * quot[ient] of dividing numerator by denominator. + */ +cljs.core.quot = (function cljs$core$quot(n,d){ +var rem = (n % d); +return cljs.core.fix(((n - rem) / d)); +}); +/** + * remainder of dividing numerator by denominator. + */ +cljs.core.rem = (function cljs$core$rem(n,d){ +var q = cljs.core.quot(n,d); +return (n - (d * q)); +}); +/** + * Bitwise exclusive or + */ +cljs.core.bit_xor = (function cljs$core$bit_xor(var_args){ +var G__3275 = arguments.length; +switch (G__3275) { +case 2: +return cljs.core.bit_xor.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3277 = arguments.length; +var i__4731__auto___3278 = (0); +while(true){ +if((i__4731__auto___3278 < len__4730__auto___3277)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3278])); + +var G__3279 = (i__4731__auto___3278 + (1)); +i__4731__auto___3278 = G__3279; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.bit_xor.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.bit_xor.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x ^ y); +}); + +cljs.core.bit_xor.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.bit_xor,(x ^ y),more); +}); + +/** @this {Function} */ +cljs.core.bit_xor.cljs$lang$applyTo = (function (seq3272){ +var G__3273 = cljs.core.first(seq3272); +var seq3272__$1 = cljs.core.next(seq3272); +var G__3274 = cljs.core.first(seq3272__$1); +var seq3272__$2 = cljs.core.next(seq3272__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3273,G__3274,seq3272__$2); +}); + +cljs.core.bit_xor.cljs$lang$maxFixedArity = (2); + +/** + * Bitwise and + */ +cljs.core.bit_and = (function cljs$core$bit_and(var_args){ +var G__3284 = arguments.length; +switch (G__3284) { +case 2: +return cljs.core.bit_and.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3286 = arguments.length; +var i__4731__auto___3287 = (0); +while(true){ +if((i__4731__auto___3287 < len__4730__auto___3286)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3287])); + +var G__3288 = (i__4731__auto___3287 + (1)); +i__4731__auto___3287 = G__3288; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.bit_and.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.bit_and.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x & y); +}); + +cljs.core.bit_and.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.bit_and,(x & y),more); +}); + +/** @this {Function} */ +cljs.core.bit_and.cljs$lang$applyTo = (function (seq3281){ +var G__3282 = cljs.core.first(seq3281); +var seq3281__$1 = cljs.core.next(seq3281); +var G__3283 = cljs.core.first(seq3281__$1); +var seq3281__$2 = cljs.core.next(seq3281__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3282,G__3283,seq3281__$2); +}); + +cljs.core.bit_and.cljs$lang$maxFixedArity = (2); + +/** + * Bitwise or + */ +cljs.core.bit_or = (function cljs$core$bit_or(var_args){ +var G__3293 = arguments.length; +switch (G__3293) { +case 2: +return cljs.core.bit_or.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3295 = arguments.length; +var i__4731__auto___3296 = (0); +while(true){ +if((i__4731__auto___3296 < len__4730__auto___3295)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3296])); + +var G__3297 = (i__4731__auto___3296 + (1)); +i__4731__auto___3296 = G__3297; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.bit_or.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.bit_or.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x | y); +}); + +cljs.core.bit_or.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.bit_or,(x | y),more); +}); + +/** @this {Function} */ +cljs.core.bit_or.cljs$lang$applyTo = (function (seq3290){ +var G__3291 = cljs.core.first(seq3290); +var seq3290__$1 = cljs.core.next(seq3290); +var G__3292 = cljs.core.first(seq3290__$1); +var seq3290__$2 = cljs.core.next(seq3290__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3291,G__3292,seq3290__$2); +}); + +cljs.core.bit_or.cljs$lang$maxFixedArity = (2); + +/** + * Bitwise and with complement + */ +cljs.core.bit_and_not = (function cljs$core$bit_and_not(var_args){ +var G__3302 = arguments.length; +switch (G__3302) { +case 2: +return cljs.core.bit_and_not.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3304 = arguments.length; +var i__4731__auto___3305 = (0); +while(true){ +if((i__4731__auto___3305 < len__4730__auto___3304)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3305])); + +var G__3306 = (i__4731__auto___3305 + (1)); +i__4731__auto___3305 = G__3306; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.bit_and_not.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.bit_and_not.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (x & ~y); +}); + +cljs.core.bit_and_not.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.bit_and_not,(x & ~y),more); +}); + +/** @this {Function} */ +cljs.core.bit_and_not.cljs$lang$applyTo = (function (seq3299){ +var G__3300 = cljs.core.first(seq3299); +var seq3299__$1 = cljs.core.next(seq3299); +var G__3301 = cljs.core.first(seq3299__$1); +var seq3299__$2 = cljs.core.next(seq3299__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3300,G__3301,seq3299__$2); +}); + +cljs.core.bit_and_not.cljs$lang$maxFixedArity = (2); + +/** + * Clear bit at index n + */ +cljs.core.bit_clear = (function cljs$core$bit_clear(x,n){ +return (x & ~(1 << n)); +}); +/** + * Flip bit at index n + */ +cljs.core.bit_flip = (function cljs$core$bit_flip(x,n){ +return (x ^ (1 << n)); +}); +/** + * Bitwise complement + */ +cljs.core.bit_not = (function cljs$core$bit_not(x){ +return (~ x); +}); +/** + * Set bit at index n + */ +cljs.core.bit_set = (function cljs$core$bit_set(x,n){ +return (x | (1 << n)); +}); +/** + * Test bit at index n + */ +cljs.core.bit_test = (function cljs$core$bit_test(x,n){ +return ((x & (1 << n)) != 0); +}); +/** + * Bitwise shift left + */ +cljs.core.bit_shift_left = (function cljs$core$bit_shift_left(x,n){ +return (x << n); +}); +/** + * Bitwise shift right + */ +cljs.core.bit_shift_right = (function cljs$core$bit_shift_right(x,n){ +return (x >> n); +}); +/** + * DEPRECATED: Bitwise shift right with zero fill + */ +cljs.core.bit_shift_right_zero_fill = (function cljs$core$bit_shift_right_zero_fill(x,n){ +return (x >>> n); +}); +/** + * Bitwise shift right with zero fill + */ +cljs.core.unsigned_bit_shift_right = (function cljs$core$unsigned_bit_shift_right(x,n){ +return (x >>> n); +}); +/** + * Counts the number of bits set in n + */ +cljs.core.bit_count = (function cljs$core$bit_count(v){ +var v__$1 = (v - ((v >> (1)) & (1431655765))); +var v__$2 = ((v__$1 & (858993459)) + ((v__$1 >> (2)) & (858993459))); +return ((((v__$2 + (v__$2 >> (4))) & (252645135)) * (16843009)) >> (24)); +}); +/** + * Returns non-nil if nums all have the equivalent + * value, otherwise false. Behavior on non nums is + * undefined. + */ +cljs.core._EQ__EQ_ = (function cljs$core$_EQ__EQ_(var_args){ +var G__3311 = arguments.length; +switch (G__3311) { +case 1: +return cljs.core._EQ__EQ_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core._EQ__EQ_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3313 = arguments.length; +var i__4731__auto___3314 = (0); +while(true){ +if((i__4731__auto___3314 < len__4730__auto___3313)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3314])); + +var G__3315 = (i__4731__auto___3314 + (1)); +i__4731__auto___3314 = G__3315; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core._EQ__EQ_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core._EQ__EQ_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return true; +}); + +cljs.core._EQ__EQ_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return cljs.core._equiv(x,y); +}); + +cljs.core._EQ__EQ_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +while(true){ +if((x === y)){ +if(cljs.core.next(more)){ +var G__3316 = y; +var G__3317 = cljs.core.first(more); +var G__3318 = cljs.core.next(more); +x = G__3316; +y = G__3317; +more = G__3318; +continue; +} else { +return (y === cljs.core.first(more)); +} +} else { +return false; +} +break; +} +}); + +/** @this {Function} */ +cljs.core._EQ__EQ_.cljs$lang$applyTo = (function (seq3308){ +var G__3309 = cljs.core.first(seq3308); +var seq3308__$1 = cljs.core.next(seq3308); +var G__3310 = cljs.core.first(seq3308__$1); +var seq3308__$2 = cljs.core.next(seq3308__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3309,G__3310,seq3308__$2); +}); + +cljs.core._EQ__EQ_.cljs$lang$maxFixedArity = (2); + +/** + * Returns true if num is greater than zero, else false + */ +cljs.core.pos_QMARK_ = (function cljs$core$pos_QMARK_(x){ +return (x > (0)); +}); +/** + * Returns true if num is zero, else false + */ +cljs.core.zero_QMARK_ = (function cljs$core$zero_QMARK_(x){ +return (x === (0)); +}); +/** + * Returns true if num is less than zero, else false + */ +cljs.core.neg_QMARK_ = (function cljs$core$neg_QMARK_(x){ +return (x < (0)); +}); +/** + * Returns the nth next of coll, (seq coll) when n is 0. + */ +cljs.core.nthnext = (function cljs$core$nthnext(coll,n){ +var n__$1 = n; +var xs = cljs.core.seq(coll); +while(true){ +if(((xs) && ((n__$1 > (0))))){ +var G__3319 = (n__$1 - (1)); +var G__3320 = cljs.core.next(xs); +n__$1 = G__3319; +xs = G__3320; +continue; +} else { +return xs; +} +break; +} +}); +/** + * With no args, returns the empty string. With one arg x, returns + * x.toString(). (str nil) returns the empty string. With more than + * one arg, returns the concatenation of the str values of the args. + */ +cljs.core.str = (function cljs$core$str(var_args){ +var G__3324 = arguments.length; +switch (G__3324) { +case 0: +return cljs.core.str.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.str.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3326 = arguments.length; +var i__4731__auto___3327 = (0); +while(true){ +if((i__4731__auto___3327 < len__4730__auto___3326)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3327])); + +var G__3328 = (i__4731__auto___3327 + (1)); +i__4731__auto___3327 = G__3328; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((1)),(0),null)); +return cljs.core.str.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4752__auto__); + +} +}); + +cljs.core.str.cljs$core$IFn$_invoke$arity$0 = (function (){ +return ""; +}); + +cljs.core.str.cljs$core$IFn$_invoke$arity$1 = (function (x){ +if((x == null)){ +return ""; +} else { +return [x].join(""); +} +}); + +cljs.core.str.cljs$core$IFn$_invoke$arity$variadic = (function (x,ys){ +var sb = (new goog.string.StringBuffer(cljs.core.str.cljs$core$IFn$_invoke$arity$1(x))); +var more = ys; +while(true){ +if(cljs.core.truth_(more)){ +var G__3329 = sb.append(cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.first(more))); +var G__3330 = cljs.core.next(more); +sb = G__3329; +more = G__3330; +continue; +} else { +return sb.toString(); +} +break; +} +}); + +/** @this {Function} */ +cljs.core.str.cljs$lang$applyTo = (function (seq3322){ +var G__3323 = cljs.core.first(seq3322); +var seq3322__$1 = cljs.core.next(seq3322); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3323,seq3322__$1); +}); + +cljs.core.str.cljs$lang$maxFixedArity = (1); + +/** + * Returns the substring of s beginning at start inclusive, and ending + * at end (defaults to length of string), exclusive. + */ +cljs.core.subs = (function cljs$core$subs(var_args){ +var G__3332 = arguments.length; +switch (G__3332) { +case 2: +return cljs.core.subs.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.subs.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.subs.cljs$core$IFn$_invoke$arity$2 = (function (s,start){ +return s.substring(start); +}); + +cljs.core.subs.cljs$core$IFn$_invoke$arity$3 = (function (s,start,end){ +return s.substring(start,end); +}); + +cljs.core.subs.cljs$lang$maxFixedArity = 3; + + +/** + * Assumes x is sequential. Returns true if x equals y, otherwise + * returns false. + */ +cljs.core.equiv_sequential = (function cljs$core$equiv_sequential(x,y){ +return cljs.core.boolean$(((cljs.core.sequential_QMARK_(y))?((((cljs.core.counted_QMARK_(x)) && (cljs.core.counted_QMARK_(y)) && ((!((cljs.core.count(x) === cljs.core.count(y)))))))?false:(function (){var xs = cljs.core.seq(x); +var ys = cljs.core.seq(y); +while(true){ +if((xs == null)){ +return (ys == null); +} else { +if((ys == null)){ +return false; +} else { +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.first(xs),cljs.core.first(ys))){ +var G__3334 = cljs.core.next(xs); +var G__3335 = cljs.core.next(ys); +xs = G__3334; +ys = G__3335; +continue; +} else { +return false; + +} +} +} +break; +} +})()):null)); +}); +cljs.core.hash_coll = (function cljs$core$hash_coll(coll){ +if(cljs.core.seq(coll)){ +var res = cljs.core.hash(cljs.core.first(coll)); +var s = cljs.core.next(coll); +while(true){ +if((s == null)){ +return res; +} else { +var G__3336 = cljs.core.hash_combine(res,cljs.core.hash(cljs.core.first(s))); +var G__3337 = cljs.core.next(s); +res = G__3336; +s = G__3337; +continue; +} +break; +} +} else { +return (0); +} +}); + +cljs.core.hash_imap = (function cljs$core$hash_imap(m){ +var h = (0); +var s = cljs.core.seq(m); +while(true){ +if(s){ +var e = cljs.core.first(s); +var G__3338 = ((h + (cljs.core.hash(cljs.core.key(e)) ^ cljs.core.hash(cljs.core.val(e)))) % (4503599627370496)); +var G__3339 = cljs.core.next(s); +h = G__3338; +s = G__3339; +continue; +} else { +return h; +} +break; +} +}); +cljs.core.hash_iset = (function cljs$core$hash_iset(s){ +var h = (0); +var s__$1 = cljs.core.seq(s); +while(true){ +if(s__$1){ +var e = cljs.core.first(s__$1); +var G__3340 = ((h + cljs.core.hash(e)) % (4503599627370496)); +var G__3341 = cljs.core.next(s__$1); +h = G__3340; +s__$1 = G__3341; +continue; +} else { +return h; +} +break; +} +}); + + +/** + * Takes a JavaScript object and a map of names to functions and + * attaches said functions as methods on the object. Any references to + * JavaScript's implicit this (via the this-as macro) will resolve to the + * object that the function is attached. + */ +cljs.core.extend_object_BANG_ = (function cljs$core$extend_object_BANG_(obj,fn_map){ +var seq__3342_3358 = cljs.core.seq(fn_map); +var chunk__3343_3359 = null; +var count__3344_3360 = (0); +var i__3345_3361 = (0); +while(true){ +if((i__3345_3361 < count__3344_3360)){ +var vec__3352_3362 = chunk__3343_3359.cljs$core$IIndexed$_nth$arity$2(null,i__3345_3361); +var key_name_3363 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__3352_3362,(0),null); +var f_3364 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__3352_3362,(1),null); +var str_name_3365 = cljs.core.name(key_name_3363); +goog.object.set(obj,str_name_3365,f_3364); + + +var G__3366 = seq__3342_3358; +var G__3367 = chunk__3343_3359; +var G__3368 = count__3344_3360; +var G__3369 = (i__3345_3361 + (1)); +seq__3342_3358 = G__3366; +chunk__3343_3359 = G__3367; +count__3344_3360 = G__3368; +i__3345_3361 = G__3369; +continue; +} else { +var temp__5735__auto___3370 = cljs.core.seq(seq__3342_3358); +if(temp__5735__auto___3370){ +var seq__3342_3371__$1 = temp__5735__auto___3370; +if(cljs.core.chunked_seq_QMARK_(seq__3342_3371__$1)){ +var c__4550__auto___3372 = cljs.core.chunk_first(seq__3342_3371__$1); +var G__3373 = cljs.core.chunk_rest(seq__3342_3371__$1); +var G__3374 = c__4550__auto___3372; +var G__3375 = cljs.core.count(c__4550__auto___3372); +var G__3376 = (0); +seq__3342_3358 = G__3373; +chunk__3343_3359 = G__3374; +count__3344_3360 = G__3375; +i__3345_3361 = G__3376; +continue; +} else { +var vec__3355_3377 = cljs.core.first(seq__3342_3371__$1); +var key_name_3378 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__3355_3377,(0),null); +var f_3379 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__3355_3377,(1),null); +var str_name_3380 = cljs.core.name(key_name_3378); +goog.object.set(obj,str_name_3380,f_3379); + + +var G__3381 = cljs.core.next(seq__3342_3371__$1); +var G__3382 = null; +var G__3383 = (0); +var G__3384 = (0); +seq__3342_3358 = G__3381; +chunk__3343_3359 = G__3382; +count__3344_3360 = G__3383; +i__3345_3361 = G__3384; +continue; +} +} else { +} +} +break; +} + +return obj; +}); + +/** +* @constructor + * @implements {cljs.core.IList} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ASeq} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IStack} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.List = (function (meta,first,rest,count,__hash){ +this.meta = meta; +this.first = first; +this.rest = rest; +this.count = count; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 65937646; +this.cljs$lang$protocol_mask$partition1$ = 8192; +}); +cljs.core.List.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.List.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.List.prototype.indexOf = (function() { +var G__3385 = null; +var G__3385__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__3385__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3385 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3385__1.call(this,x); +case 2: +return G__3385__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3385.cljs$core$IFn$_invoke$arity$1 = G__3385__1; +G__3385.cljs$core$IFn$_invoke$arity$2 = G__3385__2; +return G__3385; +})() +; + +cljs.core.List.prototype.lastIndexOf = (function() { +var G__3386 = null; +var G__3386__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,self__.count); +}); +var G__3386__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3386 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3386__1.call(this,x); +case 2: +return G__3386__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3386.cljs$core$IFn$_invoke$arity$1 = G__3386__1; +G__3386.cljs$core$IFn$_invoke$arity$2 = G__3386__2; +return G__3386; +})() +; + +cljs.core.List.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.List.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.List(self__.meta,self__.first,self__.rest,self__.count,self__.__hash)); +}); + +cljs.core.List.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.count === (1))){ +return null; +} else { +return self__.rest; +} +}); + +cljs.core.List.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.count; +}); + +cljs.core.List.prototype.cljs$core$IStack$_peek$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.first; +}); + +cljs.core.List.prototype.cljs$core$IStack$_pop$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ISeq$_rest$arity$1(null); +}); + +cljs.core.List.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.List.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.List.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.List.EMPTY,self__.meta); +}); + +cljs.core.List.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.List.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.List.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.first; +}); + +cljs.core.List.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.count === (1))){ +return cljs.core.List.EMPTY; +} else { +return self__.rest; +} +}); + +cljs.core.List.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.List.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.List(new_meta,self__.first,self__.rest,self__.count,self__.__hash)); +} +}); + +cljs.core.List.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.List(self__.meta,o,coll__$1,(self__.count + (1)),null)); +}); + +cljs.core.List.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$first,cljs.core.cst$sym$rest,cljs.core.cst$sym$count,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.List.cljs$lang$type = true; + +cljs.core.List.cljs$lang$ctorStr = "cljs.core/List"; + +cljs.core.List.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/List"); +}); + +/** + * Positional factory function for cljs.core/List. + */ +cljs.core.__GT_List = (function cljs$core$__GT_List(meta,first,rest,count,__hash){ +return (new cljs.core.List(meta,first,rest,count,__hash)); +}); + +/** + * Returns true if x implements IList + */ +cljs.core.list_QMARK_ = (function cljs$core$list_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (33554432))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IList$)))){ +return true; +} else { +if((!x.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IList,x); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IList,x); +} +}); +var G__3388_3391 = cljs.core.List.prototype; +var G__3389_3392 = cljs.core.ITER_SYMBOL; +var G__3390_3393 = ((function (G__3388_3391,G__3389_3392){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__3388_3391,G__3389_3392)) +; +goog.object.set(G__3388_3391,G__3389_3392,G__3390_3393); + +/** +* @constructor + * @implements {cljs.core.IList} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IStack} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.EmptyList = (function (meta){ +this.meta = meta; +this.cljs$lang$protocol_mask$partition0$ = 65937614; +this.cljs$lang$protocol_mask$partition1$ = 8192; +}); +cljs.core.EmptyList.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.EmptyList.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.EmptyList.prototype.indexOf = (function() { +var G__3394 = null; +var G__3394__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__3394__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3394 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3394__1.call(this,x); +case 2: +return G__3394__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3394.cljs$core$IFn$_invoke$arity$1 = G__3394__1; +G__3394.cljs$core$IFn$_invoke$arity$2 = G__3394__2; +return G__3394; +})() +; + +cljs.core.EmptyList.prototype.lastIndexOf = (function() { +var G__3395 = null; +var G__3395__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__3395__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3395 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3395__1.call(this,x); +case 2: +return G__3395__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3395.cljs$core$IFn$_invoke$arity$1 = G__3395__1; +G__3395.cljs$core$IFn$_invoke$arity$2 = G__3395__2; +return G__3395; +})() +; + +cljs.core.EmptyList.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.EmptyList.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.EmptyList(self__.meta)); +}); + +cljs.core.EmptyList.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return null; +}); + +cljs.core.EmptyList.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (0); +}); + +cljs.core.EmptyList.prototype.cljs$core$IStack$_peek$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return null; +}); + +cljs.core.EmptyList.prototype.cljs$core$IStack$_pop$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +throw (new Error("Can't pop empty list")); +}); + +cljs.core.EmptyList.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.empty_ordered_hash; +}); + +cljs.core.EmptyList.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +if(((cljs.core.list_QMARK_(other)) || (cljs.core.sequential_QMARK_(other)))){ +return (cljs.core.seq(other) == null); +} else { +return false; +} +}); + +cljs.core.EmptyList.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.EmptyList.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.EmptyList.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.EmptyList.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return null; +}); + +cljs.core.EmptyList.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.EmptyList.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return null; +}); + +cljs.core.EmptyList.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.EmptyList(new_meta)); +} +}); + +cljs.core.EmptyList.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.List(self__.meta,o,null,(1),null)); +}); + +cljs.core.EmptyList.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta], null); +}); + +cljs.core.EmptyList.cljs$lang$type = true; + +cljs.core.EmptyList.cljs$lang$ctorStr = "cljs.core/EmptyList"; + +cljs.core.EmptyList.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/EmptyList"); +}); + +/** + * Positional factory function for cljs.core/EmptyList. + */ +cljs.core.__GT_EmptyList = (function cljs$core$__GT_EmptyList(meta){ +return (new cljs.core.EmptyList(meta)); +}); + +cljs.core.List.EMPTY = (new cljs.core.EmptyList(null)); +var G__3396_3399 = cljs.core.EmptyList.prototype; +var G__3397_3400 = cljs.core.ITER_SYMBOL; +var G__3398_3401 = ((function (G__3396_3399,G__3397_3400){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__3396_3399,G__3397_3400)) +; +goog.object.set(G__3396_3399,G__3397_3400,G__3398_3401); +/** + * Returns true if coll satisfies? IReversible. + */ +cljs.core.reversible_QMARK_ = (function cljs$core$reversible_QMARK_(coll){ +if((!((coll == null)))){ +if((((coll.cljs$lang$protocol_mask$partition0$ & (134217728))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$IReversible$)))){ +return true; +} else { +if((!coll.cljs$lang$protocol_mask$partition0$)){ +return cljs.core.native_satisfies_QMARK_(cljs.core.IReversible,coll); +} else { +return false; +} +} +} else { +return cljs.core.native_satisfies_QMARK_(cljs.core.IReversible,coll); +} +}); +/** + * Returns, in constant time, a seq of the items in rev (which + * can be a vector or sorted-map), in reverse order. If rev is empty returns nil + */ +cljs.core.rseq = (function cljs$core$rseq(rev){ +return cljs.core._rseq(rev); +}); +/** + * Returns a seq of the items in coll in reverse order. Not lazy. + */ +cljs.core.reverse = (function cljs$core$reverse(coll){ +if(cljs.core.reversible_QMARK_(coll)){ +var or__4131__auto__ = cljs.core.rseq(coll); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return cljs.core.List.EMPTY; +} +} else { +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.conj,cljs.core.List.EMPTY,coll); +} +}); +/** + * Creates a new list containing the items. + */ +cljs.core.list = (function cljs$core$list(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___3404 = arguments.length; +var i__4731__auto___3405 = (0); +while(true){ +if((i__4731__auto___3405 < len__4730__auto___3404)){ +args__4736__auto__.push((arguments[i__4731__auto___3405])); + +var G__3406 = (i__4731__auto___3405 + (1)); +i__4731__auto___3405 = G__3406; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.list.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.list.cljs$core$IFn$_invoke$arity$variadic = (function (xs){ +var arr = (((((xs instanceof cljs.core.IndexedSeq)) && ((xs.i === (0)))))?xs.arr:(function (){var arr = []; +var xs__$1 = xs; +while(true){ +if((!((xs__$1 == null)))){ +arr.push(cljs.core._first(xs__$1)); + +var G__3407 = cljs.core._next(xs__$1); +xs__$1 = G__3407; +continue; +} else { +return arr; +} +break; +} +})()); +var i = arr.length; +var r = cljs.core.List.EMPTY; +while(true){ +if((i > (0))){ +var G__3408 = (i - (1)); +var G__3409 = cljs.core._conj(r,(arr[(i - (1))])); +i = G__3408; +r = G__3409; +continue; +} else { +return r; +} +break; +} +}); + +cljs.core.list.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.list.cljs$lang$applyTo = (function (seq3403){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq3403)); +}); + + +/** +* @constructor + * @implements {cljs.core.IList} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ASeq} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.Cons = (function (meta,first,rest,__hash){ +this.meta = meta; +this.first = first; +this.rest = rest; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 65929452; +this.cljs$lang$protocol_mask$partition1$ = 8192; +}); +cljs.core.Cons.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.Cons.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.Cons.prototype.indexOf = (function() { +var G__3410 = null; +var G__3410__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__3410__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3410 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3410__1.call(this,x); +case 2: +return G__3410__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3410.cljs$core$IFn$_invoke$arity$1 = G__3410__1; +G__3410.cljs$core$IFn$_invoke$arity$2 = G__3410__2; +return G__3410; +})() +; + +cljs.core.Cons.prototype.lastIndexOf = (function() { +var G__3411 = null; +var G__3411__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__3411__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3411 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3411__1.call(this,x); +case 2: +return G__3411__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3411.cljs$core$IFn$_invoke$arity$1 = G__3411__1; +G__3411.cljs$core$IFn$_invoke$arity$2 = G__3411__2; +return G__3411; +})() +; + +cljs.core.Cons.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.Cons.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.Cons(self__.meta,self__.first,self__.rest,self__.__hash)); +}); + +cljs.core.Cons.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.rest == null)){ +return null; +} else { +return cljs.core.seq(self__.rest); +} +}); + +cljs.core.Cons.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.Cons.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.Cons.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.Cons.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.Cons.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.Cons.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.first; +}); + +cljs.core.Cons.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.rest == null)){ +return cljs.core.List.EMPTY; +} else { +return self__.rest; +} +}); + +cljs.core.Cons.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.Cons.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.Cons(new_meta,self__.first,self__.rest,self__.__hash)); +} +}); + +cljs.core.Cons.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.Cons(null,o,coll__$1,null)); +}); + +cljs.core.Cons.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$first,cljs.core.cst$sym$rest,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Cons.cljs$lang$type = true; + +cljs.core.Cons.cljs$lang$ctorStr = "cljs.core/Cons"; + +cljs.core.Cons.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Cons"); +}); + +/** + * Positional factory function for cljs.core/Cons. + */ +cljs.core.__GT_Cons = (function cljs$core$__GT_Cons(meta,first,rest,__hash){ +return (new cljs.core.Cons(meta,first,rest,__hash)); +}); + +var G__3412_3415 = cljs.core.Cons.prototype; +var G__3413_3416 = cljs.core.ITER_SYMBOL; +var G__3414_3417 = ((function (G__3412_3415,G__3413_3416){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__3412_3415,G__3413_3416)) +; +goog.object.set(G__3412_3415,G__3413_3416,G__3414_3417); +/** + * Returns a new seq where x is the first element and coll is the rest. + */ +cljs.core.cons = (function cljs$core$cons(x,coll){ +if((coll == null)){ +return (new cljs.core.List(null,x,null,(1),null)); +} else { +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$ISeq$))))?true:false):false)){ +return (new cljs.core.Cons(null,x,coll,null)); +} else { +return (new cljs.core.Cons(null,x,cljs.core.seq(coll),null)); + +} +} +}); +cljs.core.hash_keyword = (function cljs$core$hash_keyword(k){ +return ((cljs.core.hash_symbol(k) + (2654435769)) | (0)); +}); +cljs.core.compare_keywords = (function cljs$core$compare_keywords(a,b){ +if((a.fqn === b.fqn)){ +return (0); +} else { +if(cljs.core.truth_((function (){var and__4120__auto__ = cljs.core.not(a.ns); +if(and__4120__auto__){ +return b.ns; +} else { +return and__4120__auto__; +} +})())){ +return (-1); +} else { +if(cljs.core.truth_(a.ns)){ +if(cljs.core.not(b.ns)){ +return (1); +} else { +var nsc = (function (){var G__3419 = a.ns; +var G__3420 = b.ns; +return goog.array.defaultCompare(G__3419,G__3420); +})(); +if(((0) === nsc)){ +var G__3421 = a.name; +var G__3422 = b.name; +return goog.array.defaultCompare(G__3421,G__3422); +} else { +return nsc; +} +} +} else { +var G__3423 = a.name; +var G__3424 = b.name; +return goog.array.defaultCompare(G__3423,G__3424); + +} +} +} +}); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.INamed} + * @implements {cljs.core.IPrintWithWriter} +*/ +cljs.core.Keyword = (function (ns,name,fqn,_hash){ +this.ns = ns; +this.name = name; +this.fqn = fqn; +this._hash = _hash; +this.cljs$lang$protocol_mask$partition0$ = 2153775105; +this.cljs$lang$protocol_mask$partition1$ = 4096; +}); +cljs.core.Keyword.prototype.toString = (function (){ +var self__ = this; +var _ = this; +return [":",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.fqn)].join(''); +}); + +cljs.core.Keyword.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.Keyword.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (_,other){ +var self__ = this; +var ___$1 = this; +if((other instanceof cljs.core.Keyword)){ +return (self__.fqn === other.fqn); +} else { +return false; +} +}); + +cljs.core.Keyword.prototype.call = (function() { +var G__3426 = null; +var G__3426__2 = (function (self__,coll){ +var self__ = this; +var self____$1 = this; +var kw = self____$1; +return cljs.core.get.cljs$core$IFn$_invoke$arity$2(coll,kw); +}); +var G__3426__3 = (function (self__,coll,not_found){ +var self__ = this; +var self____$1 = this; +var kw = self____$1; +return cljs.core.get.cljs$core$IFn$_invoke$arity$3(coll,kw,not_found); +}); +G__3426 = function(self__,coll,not_found){ +switch(arguments.length){ +case 2: +return G__3426__2.call(this,self__,coll); +case 3: +return G__3426__3.call(this,self__,coll,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__3426.cljs$core$IFn$_invoke$arity$2 = G__3426__2; +G__3426.cljs$core$IFn$_invoke$arity$3 = G__3426__3; +return G__3426; +})() +; + +cljs.core.Keyword.prototype.apply = (function (self__,args3425){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args3425))); +}); + +cljs.core.Keyword.prototype.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +var self__ = this; +var kw = this; +return cljs.core.get.cljs$core$IFn$_invoke$arity$2(coll,kw); +}); + +cljs.core.Keyword.prototype.cljs$core$IFn$_invoke$arity$2 = (function (coll,not_found){ +var self__ = this; +var kw = this; +return cljs.core.get.cljs$core$IFn$_invoke$arity$3(coll,kw,not_found); +}); + +cljs.core.Keyword.prototype.cljs$core$IHash$_hash$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +var h__4243__auto__ = self__._hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_keyword(this$__$1); +self__._hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.Keyword.prototype.cljs$core$INamed$_name$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.name; +}); + +cljs.core.Keyword.prototype.cljs$core$INamed$_namespace$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.ns; +}); + +cljs.core.Keyword.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (o,writer,_){ +var self__ = this; +var o__$1 = this; +return cljs.core._write(writer,[":",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.fqn)].join('')); +}); + +cljs.core.Keyword.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$ns,cljs.core.cst$sym$name,cljs.core.cst$sym$fqn,cljs.core.with_meta(cljs.core.cst$sym$_hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Keyword.cljs$lang$type = true; + +cljs.core.Keyword.cljs$lang$ctorStr = "cljs.core/Keyword"; + +cljs.core.Keyword.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Keyword"); +}); + +/** + * Positional factory function for cljs.core/Keyword. + */ +cljs.core.__GT_Keyword = (function cljs$core$__GT_Keyword(ns,name,fqn,_hash){ +return (new cljs.core.Keyword(ns,name,fqn,_hash)); +}); + +/** + * Return true if x is a Keyword + */ +cljs.core.keyword_QMARK_ = (function cljs$core$keyword_QMARK_(x){ +return (x instanceof cljs.core.Keyword); +}); +/** + * Efficient test to determine that two keywords are identical. + */ +cljs.core.keyword_identical_QMARK_ = (function cljs$core$keyword_identical_QMARK_(x,y){ +if((x === y)){ +return true; +} else { +if((((x instanceof cljs.core.Keyword)) && ((y instanceof cljs.core.Keyword)))){ +return (x.fqn === y.fqn); +} else { +return false; +} +} +}); +/** + * Efficient test to determine that two symbols are identical. + */ +cljs.core.symbol_identical_QMARK_ = (function cljs$core$symbol_identical_QMARK_(x,y){ +if((x === y)){ +return true; +} else { +if((((x instanceof cljs.core.Symbol)) && ((y instanceof cljs.core.Symbol)))){ +return (x.str === y.str); +} else { +return false; +} +} +}); +/** + * Returns the namespace String of a symbol or keyword, or nil if not present. + */ +cljs.core.namespace = (function cljs$core$namespace(x){ +if((((!((x == null))))?(((((x.cljs$lang$protocol_mask$partition1$ & (4096))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$INamed$))))?true:false):false)){ +return cljs.core._namespace(x); +} else { +throw (new Error(["Doesn't support namespace: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x)].join(''))); +} +}); +/** + * Return true if x is a symbol or keyword + */ +cljs.core.ident_QMARK_ = (function cljs$core$ident_QMARK_(x){ +return (((x instanceof cljs.core.Keyword)) || ((x instanceof cljs.core.Symbol))); +}); +/** + * Return true if x is a symbol or keyword without a namespace + */ +cljs.core.simple_ident_QMARK_ = (function cljs$core$simple_ident_QMARK_(x){ +return ((cljs.core.ident_QMARK_(x)) && ((cljs.core.namespace(x) == null))); +}); +/** + * Return true if x is a symbol or keyword with a namespace + */ +cljs.core.qualified_ident_QMARK_ = (function cljs$core$qualified_ident_QMARK_(x){ +return cljs.core.boolean$((function (){var and__4120__auto__ = cljs.core.ident_QMARK_(x); +if(and__4120__auto__){ +var and__4120__auto____$1 = cljs.core.namespace(x); +if(cljs.core.truth_(and__4120__auto____$1)){ +return true; +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +/** + * Return true if x is a symbol without a namespace + */ +cljs.core.simple_symbol_QMARK_ = (function cljs$core$simple_symbol_QMARK_(x){ +return (((x instanceof cljs.core.Symbol)) && ((cljs.core.namespace(x) == null))); +}); +/** + * Return true if x is a symbol with a namespace + */ +cljs.core.qualified_symbol_QMARK_ = (function cljs$core$qualified_symbol_QMARK_(x){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (x instanceof cljs.core.Symbol); +if(and__4120__auto__){ +var and__4120__auto____$1 = cljs.core.namespace(x); +if(cljs.core.truth_(and__4120__auto____$1)){ +return true; +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +/** + * Return true if x is a keyword without a namespace + */ +cljs.core.simple_keyword_QMARK_ = (function cljs$core$simple_keyword_QMARK_(x){ +return (((x instanceof cljs.core.Keyword)) && ((cljs.core.namespace(x) == null))); +}); +/** + * Return true if x is a keyword with a namespace + */ +cljs.core.qualified_keyword_QMARK_ = (function cljs$core$qualified_keyword_QMARK_(x){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (x instanceof cljs.core.Keyword); +if(and__4120__auto__){ +var and__4120__auto____$1 = cljs.core.namespace(x); +if(cljs.core.truth_(and__4120__auto____$1)){ +return true; +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +/** + * Returns a Keyword with the given namespace and name. Do not use : + * in the keyword strings, it will be added automatically. + */ +cljs.core.keyword = (function cljs$core$keyword(var_args){ +var G__3429 = arguments.length; +switch (G__3429) { +case 1: +return cljs.core.keyword.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.keyword.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.keyword.cljs$core$IFn$_invoke$arity$1 = (function (name){ +if((name instanceof cljs.core.Keyword)){ +return name; +} else { +if((name instanceof cljs.core.Symbol)){ +return (new cljs.core.Keyword(cljs.core.namespace(name),cljs.core.name(name),name.str,null)); +} else { +if(typeof name === 'string'){ +var parts = name.split("/"); +if((parts.length === (2))){ +return (new cljs.core.Keyword((parts[(0)]),(parts[(1)]),name,null)); +} else { +return (new cljs.core.Keyword(null,(parts[(0)]),name,null)); +} +} else { +return null; +} +} +} +}); + +cljs.core.keyword.cljs$core$IFn$_invoke$arity$2 = (function (ns,name){ +var ns__$1 = (((ns instanceof cljs.core.Keyword))?cljs.core.name(ns):(((ns instanceof cljs.core.Symbol))?cljs.core.name(ns):ns +)); +var name__$1 = (((name instanceof cljs.core.Keyword))?cljs.core.name(name):(((name instanceof cljs.core.Symbol))?cljs.core.name(name):name +)); +return (new cljs.core.Keyword(ns__$1,name__$1,[(cljs.core.truth_(ns__$1)?[cljs.core.str.cljs$core$IFn$_invoke$arity$1(ns__$1),"/"].join(''):null),cljs.core.str.cljs$core$IFn$_invoke$arity$1(name__$1)].join(''),null)); +}); + +cljs.core.keyword.cljs$lang$maxFixedArity = 2; + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IPending} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.LazySeq = (function (meta,fn,s,__hash){ +this.meta = meta; +this.fn = fn; +this.s = s; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 32374988; +this.cljs$lang$protocol_mask$partition1$ = 1; +}); +cljs.core.LazySeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.LazySeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.LazySeq.prototype.sval = (function (){ +var self__ = this; +var coll = this; +if((self__.fn == null)){ +return self__.s; +} else { +self__.s = (self__.fn.cljs$core$IFn$_invoke$arity$0 ? self__.fn.cljs$core$IFn$_invoke$arity$0() : self__.fn.call(null)); + +self__.fn = null; + +return self__.s; +} +}); + +cljs.core.LazySeq.prototype.indexOf = (function() { +var G__3431 = null; +var G__3431__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__3431__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3431 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3431__1.call(this,x); +case 2: +return G__3431__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3431.cljs$core$IFn$_invoke$arity$1 = G__3431__1; +G__3431.cljs$core$IFn$_invoke$arity$2 = G__3431__2; +return G__3431; +})() +; + +cljs.core.LazySeq.prototype.lastIndexOf = (function() { +var G__3432 = null; +var G__3432__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__3432__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3432 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3432__1.call(this,x); +case 2: +return G__3432__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3432.cljs$core$IFn$_invoke$arity$1 = G__3432__1; +G__3432.cljs$core$IFn$_invoke$arity$2 = G__3432__2; +return G__3432; +})() +; + +cljs.core.LazySeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.LazySeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +coll__$1.cljs$core$ISeqable$_seq$arity$1(null); + +if((self__.s == null)){ +return null; +} else { +return cljs.core.next(self__.s); +} +}); + +cljs.core.LazySeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.LazySeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.LazySeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.List.EMPTY,self__.meta); +}); + +cljs.core.LazySeq.prototype.cljs$core$IPending$_realized_QMARK_$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.not(self__.fn); +}); + +cljs.core.LazySeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.LazySeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.LazySeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +coll__$1.cljs$core$ISeqable$_seq$arity$1(null); + +if((self__.s == null)){ +return null; +} else { +return cljs.core.first(self__.s); +} +}); + +cljs.core.LazySeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +coll__$1.cljs$core$ISeqable$_seq$arity$1(null); + +if((!((self__.s == null)))){ +return cljs.core.rest(self__.s); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.LazySeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +coll__$1.sval(); + +if((self__.s == null)){ +return null; +} else { +var ls = self__.s; +while(true){ +if((ls instanceof cljs.core.LazySeq)){ +var G__3433 = ls.sval(); +ls = G__3433; +continue; +} else { +self__.s = ls; + +return cljs.core.seq(self__.s); +} +break; +} +} +}); + +cljs.core.LazySeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.LazySeq(new_meta,((function (coll__$1){ +return (function (){ +return coll__$1.cljs$core$ISeqable$_seq$arity$1(null); +});})(coll__$1)) +,null,self__.__hash)); +} +}); + +cljs.core.LazySeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.LazySeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.with_meta(cljs.core.cst$sym$fn,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$s,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.LazySeq.cljs$lang$type = true; + +cljs.core.LazySeq.cljs$lang$ctorStr = "cljs.core/LazySeq"; + +cljs.core.LazySeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/LazySeq"); +}); + +/** + * Positional factory function for cljs.core/LazySeq. + */ +cljs.core.__GT_LazySeq = (function cljs$core$__GT_LazySeq(meta,fn,s,__hash){ +return (new cljs.core.LazySeq(meta,fn,s,__hash)); +}); + +var G__3434_3437 = cljs.core.LazySeq.prototype; +var G__3435_3438 = cljs.core.ITER_SYMBOL; +var G__3436_3439 = ((function (G__3434_3437,G__3435_3438){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__3434_3437,G__3435_3438)) +; +goog.object.set(G__3434_3437,G__3435_3438,G__3436_3439); + +/** +* @constructor + * @implements {cljs.core.ICounted} +*/ +cljs.core.ChunkBuffer = (function (buf,end){ +this.buf = buf; +this.end = end; +this.cljs$lang$protocol_mask$partition0$ = 2; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.ChunkBuffer.prototype.add = (function (o){ +var self__ = this; +var _ = this; +(self__.buf[self__.end] = o); + +return self__.end = (self__.end + (1)); +}); + +cljs.core.ChunkBuffer.prototype.chunk = (function (){ +var self__ = this; +var _ = this; +var ret = (new cljs.core.ArrayChunk(self__.buf,(0),self__.end)); +self__.buf = null; + +return ret; +}); + +cljs.core.ChunkBuffer.prototype.cljs$core$ICounted$_count$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.end; +}); + +cljs.core.ChunkBuffer.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$buf,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$end,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ChunkBuffer.cljs$lang$type = true; + +cljs.core.ChunkBuffer.cljs$lang$ctorStr = "cljs.core/ChunkBuffer"; + +cljs.core.ChunkBuffer.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ChunkBuffer"); +}); + +/** + * Positional factory function for cljs.core/ChunkBuffer. + */ +cljs.core.__GT_ChunkBuffer = (function cljs$core$__GT_ChunkBuffer(buf,end){ +return (new cljs.core.ChunkBuffer(buf,end)); +}); + +cljs.core.chunk_buffer = (function cljs$core$chunk_buffer(capacity){ +return (new cljs.core.ChunkBuffer((new Array(capacity)),(0))); +}); + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.IChunk} + * @implements {cljs.core.IReduce} +*/ +cljs.core.ArrayChunk = (function (arr,off,end){ +this.arr = arr; +this.off = off; +this.end = end; +this.cljs$lang$protocol_mask$partition0$ = 524306; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.ArrayChunk.prototype.cljs$core$ICounted$_count$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (self__.end - self__.off); +}); + +cljs.core.ArrayChunk.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (coll,i){ +var self__ = this; +var coll__$1 = this; +return (self__.arr[(self__.off + i)]); +}); + +cljs.core.ArrayChunk.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (coll,i,not_found){ +var self__ = this; +var coll__$1 = this; +if((((i >= (0))) && ((i < (self__.end - self__.off))))){ +return (self__.arr[(self__.off + i)]); +} else { +return not_found; +} +}); + +cljs.core.ArrayChunk.prototype.cljs$core$IChunk$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ArrayChunk.prototype.cljs$core$IChunk$_drop_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.off === self__.end)){ +throw (new Error("-drop-first of empty chunk")); +} else { +return (new cljs.core.ArrayChunk(self__.arr,(self__.off + (1)),self__.end)); +} +}); + +cljs.core.ArrayChunk.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$4(self__.arr,f,(self__.arr[self__.off]),(self__.off + (1))); +}); + +cljs.core.ArrayChunk.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.array_reduce.cljs$core$IFn$_invoke$arity$4(self__.arr,f,start,self__.off); +}); + +cljs.core.ArrayChunk.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$arr,cljs.core.cst$sym$off,cljs.core.cst$sym$end], null); +}); + +cljs.core.ArrayChunk.cljs$lang$type = true; + +cljs.core.ArrayChunk.cljs$lang$ctorStr = "cljs.core/ArrayChunk"; + +cljs.core.ArrayChunk.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ArrayChunk"); +}); + +/** + * Positional factory function for cljs.core/ArrayChunk. + */ +cljs.core.__GT_ArrayChunk = (function cljs$core$__GT_ArrayChunk(arr,off,end){ +return (new cljs.core.ArrayChunk(arr,off,end)); +}); + +cljs.core.array_chunk = (function cljs$core$array_chunk(var_args){ +var G__3441 = arguments.length; +switch (G__3441) { +case 1: +return cljs.core.array_chunk.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.array_chunk.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.array_chunk.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.array_chunk.cljs$core$IFn$_invoke$arity$1 = (function (arr){ +return (new cljs.core.ArrayChunk(arr,(0),arr.length)); +}); + +cljs.core.array_chunk.cljs$core$IFn$_invoke$arity$2 = (function (arr,off){ +return (new cljs.core.ArrayChunk(arr,off,arr.length)); +}); + +cljs.core.array_chunk.cljs$core$IFn$_invoke$arity$3 = (function (arr,off,end){ +return (new cljs.core.ArrayChunk(arr,off,end)); +}); + +cljs.core.array_chunk.cljs$lang$maxFixedArity = 3; + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ASeq} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IChunkedNext} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IChunkedSeq} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} +*/ +cljs.core.ChunkedCons = (function (chunk,more,meta,__hash){ +this.chunk = chunk; +this.more = more; +this.meta = meta; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 31850732; +this.cljs$lang$protocol_mask$partition1$ = 1536; +}); +cljs.core.ChunkedCons.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.ChunkedCons.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.ChunkedCons.prototype.indexOf = (function() { +var G__3443 = null; +var G__3443__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__3443__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3443 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3443__1.call(this,x); +case 2: +return G__3443__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3443.cljs$core$IFn$_invoke$arity$1 = G__3443__1; +G__3443.cljs$core$IFn$_invoke$arity$2 = G__3443__2; +return G__3443; +})() +; + +cljs.core.ChunkedCons.prototype.lastIndexOf = (function() { +var G__3444 = null; +var G__3444__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__3444__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__3444 = function(x,start){ +switch(arguments.length){ +case 1: +return G__3444__1.call(this,x); +case 2: +return G__3444__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3444.cljs$core$IFn$_invoke$arity$1 = G__3444__1; +G__3444.cljs$core$IFn$_invoke$arity$2 = G__3444__2; +return G__3444; +})() +; + +cljs.core.ChunkedCons.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.ChunkedCons.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((cljs.core._count(self__.chunk) > (1))){ +return (new cljs.core.ChunkedCons(cljs.core._drop_first(self__.chunk),self__.more,null,null)); +} else { +if((self__.more == null)){ +return null; +} else { +return cljs.core._seq(self__.more); +} +} +}); + +cljs.core.ChunkedCons.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.ChunkedCons.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.ChunkedCons.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.ChunkedCons.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._nth.cljs$core$IFn$_invoke$arity$2(self__.chunk,(0)); +}); + +cljs.core.ChunkedCons.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((cljs.core._count(self__.chunk) > (1))){ +return (new cljs.core.ChunkedCons(cljs.core._drop_first(self__.chunk),self__.more,null,null)); +} else { +if((self__.more == null)){ +return cljs.core.List.EMPTY; +} else { +return self__.more; +} +} +}); + +cljs.core.ChunkedCons.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.ChunkedCons.prototype.cljs$core$IChunkedSeq$_chunked_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.chunk; +}); + +cljs.core.ChunkedCons.prototype.cljs$core$IChunkedSeq$_chunked_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.more == null)){ +return cljs.core.List.EMPTY; +} else { +return self__.more; +} +}); + +cljs.core.ChunkedCons.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.ChunkedCons(self__.chunk,self__.more,new_meta,self__.__hash)); +} +}); + +cljs.core.ChunkedCons.prototype.cljs$core$ICollection$_conj$arity$2 = (function (this$,o){ +var self__ = this; +var this$__$1 = this; +return cljs.core.cons(o,this$__$1); +}); + +cljs.core.ChunkedCons.prototype.cljs$core$IChunkedNext$_chunked_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.more == null)){ +return null; +} else { +return self__.more; +} +}); + +cljs.core.ChunkedCons.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$chunk,cljs.core.cst$sym$more,cljs.core.cst$sym$meta,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ChunkedCons.cljs$lang$type = true; + +cljs.core.ChunkedCons.cljs$lang$ctorStr = "cljs.core/ChunkedCons"; + +cljs.core.ChunkedCons.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ChunkedCons"); +}); + +/** + * Positional factory function for cljs.core/ChunkedCons. + */ +cljs.core.__GT_ChunkedCons = (function cljs$core$__GT_ChunkedCons(chunk,more,meta,__hash){ +return (new cljs.core.ChunkedCons(chunk,more,meta,__hash)); +}); + +var G__3445_3448 = cljs.core.ChunkedCons.prototype; +var G__3446_3449 = cljs.core.ITER_SYMBOL; +var G__3447_3450 = ((function (G__3445_3448,G__3446_3449){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__3445_3448,G__3446_3449)) +; +goog.object.set(G__3445_3448,G__3446_3449,G__3447_3450); +cljs.core.chunk_cons = (function cljs$core$chunk_cons(chunk,rest){ +if((cljs.core._count(chunk) === (0))){ +return rest; +} else { +return (new cljs.core.ChunkedCons(chunk,rest,null,null)); +} +}); +cljs.core.chunk_append = (function cljs$core$chunk_append(b,x){ +return b.add(x); +}); +cljs.core.chunk = (function cljs$core$chunk(b){ +return b.chunk(); +}); +cljs.core.chunk_first = (function cljs$core$chunk_first(s){ +return cljs.core._chunked_first(s); +}); +cljs.core.chunk_rest = (function cljs$core$chunk_rest(s){ +return cljs.core._chunked_rest(s); +}); +cljs.core.chunk_next = (function cljs$core$chunk_next(s){ +if((((!((s == null))))?(((((s.cljs$lang$protocol_mask$partition1$ & (1024))) || ((cljs.core.PROTOCOL_SENTINEL === s.cljs$core$IChunkedNext$))))?true:false):false)){ +return cljs.core._chunked_next(s); +} else { +return cljs.core.seq(cljs.core._chunked_rest(s)); +} +}); +/** + * Returns an array containing the contents of coll. + */ +cljs.core.to_array = (function cljs$core$to_array(coll){ +var ary = []; +var s = cljs.core.seq(coll); +while(true){ +if((!((s == null)))){ +ary.push(cljs.core.first(s)); + +var G__3452 = cljs.core.next(s); +s = G__3452; +continue; +} else { +return ary; +} +break; +} +}); +/** + * Returns a (potentially-ragged) 2-dimensional array + * containing the contents of coll. + */ +cljs.core.to_array_2d = (function cljs$core$to_array_2d(coll){ +var ret = (new Array(cljs.core.count(coll))); +var i_3453 = (0); +var xs_3454 = cljs.core.seq(coll); +while(true){ +if((xs_3454 == null)){ +} else { +(ret[i_3453] = cljs.core.to_array(cljs.core.first(xs_3454))); + +var G__3455 = (i_3453 + (1)); +var G__3456 = cljs.core.next(xs_3454); +i_3453 = G__3455; +xs_3454 = G__3456; +continue; +} +break; +} + +return ret; +}); +/** + * Creates an array of ints. Does not coerce array, provided for compatibility + * with Clojure. + */ +cljs.core.int_array = (function cljs$core$int_array(var_args){ +var G__3458 = arguments.length; +switch (G__3458) { +case 1: +return cljs.core.int_array.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.int_array.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.int_array.cljs$core$IFn$_invoke$arity$1 = (function (size_or_seq){ +if(typeof size_or_seq === 'number'){ +return cljs.core.int_array.cljs$core$IFn$_invoke$arity$2(size_or_seq,null); +} else { +return cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(size_or_seq); +} +}); + +cljs.core.int_array.cljs$core$IFn$_invoke$arity$2 = (function (size,init_val_or_seq){ +var a = (new Array(size)); +if(cljs.core.seq_QMARK_(init_val_or_seq)){ +var s = cljs.core.seq(init_val_or_seq); +var i = (0); +var s__$1 = s; +while(true){ +if(((s__$1) && ((i < size)))){ +(a[i] = cljs.core.first(s__$1)); + +var G__3460 = (i + (1)); +var G__3461 = cljs.core.next(s__$1); +i = G__3460; +s__$1 = G__3461; +continue; +} else { +return a; +} +break; +} +} else { +var n__4607__auto___3462 = size; +var i_3463 = (0); +while(true){ +if((i_3463 < n__4607__auto___3462)){ +(a[i_3463] = init_val_or_seq); + +var G__3464 = (i_3463 + (1)); +i_3463 = G__3464; +continue; +} else { +} +break; +} + +return a; +} +}); + +cljs.core.int_array.cljs$lang$maxFixedArity = 2; + +/** + * Creates an array of longs. Does not coerce array, provided for compatibility + * with Clojure. + */ +cljs.core.long_array = (function cljs$core$long_array(var_args){ +var G__3466 = arguments.length; +switch (G__3466) { +case 1: +return cljs.core.long_array.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.long_array.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.long_array.cljs$core$IFn$_invoke$arity$1 = (function (size_or_seq){ +if(typeof size_or_seq === 'number'){ +return cljs.core.long_array.cljs$core$IFn$_invoke$arity$2(size_or_seq,null); +} else { +return cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(size_or_seq); +} +}); + +cljs.core.long_array.cljs$core$IFn$_invoke$arity$2 = (function (size,init_val_or_seq){ +var a = (new Array(size)); +if(cljs.core.seq_QMARK_(init_val_or_seq)){ +var s = cljs.core.seq(init_val_or_seq); +var i = (0); +var s__$1 = s; +while(true){ +if(((s__$1) && ((i < size)))){ +(a[i] = cljs.core.first(s__$1)); + +var G__3468 = (i + (1)); +var G__3469 = cljs.core.next(s__$1); +i = G__3468; +s__$1 = G__3469; +continue; +} else { +return a; +} +break; +} +} else { +var n__4607__auto___3470 = size; +var i_3471 = (0); +while(true){ +if((i_3471 < n__4607__auto___3470)){ +(a[i_3471] = init_val_or_seq); + +var G__3472 = (i_3471 + (1)); +i_3471 = G__3472; +continue; +} else { +} +break; +} + +return a; +} +}); + +cljs.core.long_array.cljs$lang$maxFixedArity = 2; + +/** + * Creates an array of doubles. Does not coerce array, provided for compatibility + * with Clojure. + */ +cljs.core.double_array = (function cljs$core$double_array(var_args){ +var G__3474 = arguments.length; +switch (G__3474) { +case 1: +return cljs.core.double_array.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.double_array.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.double_array.cljs$core$IFn$_invoke$arity$1 = (function (size_or_seq){ +if(typeof size_or_seq === 'number'){ +return cljs.core.double_array.cljs$core$IFn$_invoke$arity$2(size_or_seq,null); +} else { +return cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(size_or_seq); +} +}); + +cljs.core.double_array.cljs$core$IFn$_invoke$arity$2 = (function (size,init_val_or_seq){ +var a = (new Array(size)); +if(cljs.core.seq_QMARK_(init_val_or_seq)){ +var s = cljs.core.seq(init_val_or_seq); +var i = (0); +var s__$1 = s; +while(true){ +if(((s__$1) && ((i < size)))){ +(a[i] = cljs.core.first(s__$1)); + +var G__3476 = (i + (1)); +var G__3477 = cljs.core.next(s__$1); +i = G__3476; +s__$1 = G__3477; +continue; +} else { +return a; +} +break; +} +} else { +var n__4607__auto___3478 = size; +var i_3479 = (0); +while(true){ +if((i_3479 < n__4607__auto___3478)){ +(a[i_3479] = init_val_or_seq); + +var G__3480 = (i_3479 + (1)); +i_3479 = G__3480; +continue; +} else { +} +break; +} + +return a; +} +}); + +cljs.core.double_array.cljs$lang$maxFixedArity = 2; + +/** + * Creates an array of objects. Does not coerce array, provided for compatibility + * with Clojure. + */ +cljs.core.object_array = (function cljs$core$object_array(var_args){ +var G__3482 = arguments.length; +switch (G__3482) { +case 1: +return cljs.core.object_array.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.object_array.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.object_array.cljs$core$IFn$_invoke$arity$1 = (function (size_or_seq){ +if(typeof size_or_seq === 'number'){ +return cljs.core.object_array.cljs$core$IFn$_invoke$arity$2(size_or_seq,null); +} else { +return cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(size_or_seq); +} +}); + +cljs.core.object_array.cljs$core$IFn$_invoke$arity$2 = (function (size,init_val_or_seq){ +var a = (new Array(size)); +if(cljs.core.seq_QMARK_(init_val_or_seq)){ +var s = cljs.core.seq(init_val_or_seq); +var i = (0); +var s__$1 = s; +while(true){ +if(((s__$1) && ((i < size)))){ +(a[i] = cljs.core.first(s__$1)); + +var G__3484 = (i + (1)); +var G__3485 = cljs.core.next(s__$1); +i = G__3484; +s__$1 = G__3485; +continue; +} else { +return a; +} +break; +} +} else { +var n__4607__auto___3486 = size; +var i_3487 = (0); +while(true){ +if((i_3487 < n__4607__auto___3486)){ +(a[i_3487] = init_val_or_seq); + +var G__3488 = (i_3487 + (1)); +i_3487 = G__3488; +continue; +} else { +} +break; +} + +return a; +} +}); + +cljs.core.object_array.cljs$lang$maxFixedArity = 2; + +/** + * If coll is counted? returns its count, else will count at most the first n + * elements of coll using its seq + */ +cljs.core.bounded_count = (function cljs$core$bounded_count(n,coll){ +if(cljs.core.counted_QMARK_(coll)){ +return cljs.core.count(coll); +} else { +var i = (0); +var s = cljs.core.seq(coll); +while(true){ +if((((!((s == null)))) && ((i < n)))){ +var G__3489 = (i + (1)); +var G__3490 = cljs.core.next(s); +i = G__3489; +s = G__3490; +continue; +} else { +return i; +} +break; +} +} +}); +cljs.core.spread = (function cljs$core$spread(arglist){ +if((arglist == null)){ +return null; +} else { +var n = cljs.core.next(arglist); +if((n == null)){ +return cljs.core.seq(cljs.core.first(arglist)); +} else { +return cljs.core.cons(cljs.core.first(arglist),(cljs.core.spread.cljs$core$IFn$_invoke$arity$1 ? cljs.core.spread.cljs$core$IFn$_invoke$arity$1(n) : cljs.core.spread.call(null,n))); +} +} +}); +/** + * Returns a lazy seq representing the concatenation of the elements in the supplied colls. + */ +cljs.core.concat = (function cljs$core$concat(var_args){ +var G__3495 = arguments.length; +switch (G__3495) { +case 0: +return cljs.core.concat.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.concat.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.concat.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3497 = arguments.length; +var i__4731__auto___3498 = (0); +while(true){ +if((i__4731__auto___3498 < len__4730__auto___3497)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3498])); + +var G__3499 = (i__4731__auto___3498 + (1)); +i__4731__auto___3498 = G__3499; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.concat.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.concat.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (new cljs.core.LazySeq(null,(function (){ +return null; +}),null,null)); +}); + +cljs.core.concat.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return (new cljs.core.LazySeq(null,(function (){ +return x; +}),null,null)); +}); + +cljs.core.concat.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (new cljs.core.LazySeq(null,(function (){ +var s = cljs.core.seq(x); +if(s){ +if(cljs.core.chunked_seq_QMARK_(s)){ +return cljs.core.chunk_cons(cljs.core.chunk_first(s),cljs.core.concat.cljs$core$IFn$_invoke$arity$2(cljs.core.chunk_rest(s),y)); +} else { +return cljs.core.cons(cljs.core.first(s),cljs.core.concat.cljs$core$IFn$_invoke$arity$2(cljs.core.rest(s),y)); +} +} else { +return y; +} +}),null,null)); +}); + +cljs.core.concat.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,zs){ +var cat = (function cljs$core$cat(xys,zs__$1){ +return (new cljs.core.LazySeq(null,(function (){ +var xys__$1 = cljs.core.seq(xys); +if(xys__$1){ +if(cljs.core.chunked_seq_QMARK_(xys__$1)){ +return cljs.core.chunk_cons(cljs.core.chunk_first(xys__$1),cljs$core$cat(cljs.core.chunk_rest(xys__$1),zs__$1)); +} else { +return cljs.core.cons(cljs.core.first(xys__$1),cljs$core$cat(cljs.core.rest(xys__$1),zs__$1)); +} +} else { +if(cljs.core.truth_(zs__$1)){ +return cljs$core$cat(cljs.core.first(zs__$1),cljs.core.next(zs__$1)); +} else { +return null; +} +} +}),null,null)); +}); +return cat(cljs.core.concat.cljs$core$IFn$_invoke$arity$2(x,y),zs); +}); + +/** @this {Function} */ +cljs.core.concat.cljs$lang$applyTo = (function (seq3492){ +var G__3493 = cljs.core.first(seq3492); +var seq3492__$1 = cljs.core.next(seq3492); +var G__3494 = cljs.core.first(seq3492__$1); +var seq3492__$2 = cljs.core.next(seq3492__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3493,G__3494,seq3492__$2); +}); + +cljs.core.concat.cljs$lang$maxFixedArity = (2); + +/** + * Creates a new list containing the items prepended to the rest, the + * last of which will be treated as a sequence. + */ +cljs.core.list_STAR_ = (function cljs$core$list_STAR_(var_args){ +var G__3506 = arguments.length; +switch (G__3506) { +case 1: +return cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3508 = arguments.length; +var i__4731__auto___3509 = (0); +while(true){ +if((i__4731__auto___3509 < len__4730__auto___3508)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3509])); + +var G__3510 = (i__4731__auto___3509 + (1)); +i__4731__auto___3509 = G__3510; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((4)),(0),null)); +return cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),argseq__4752__auto__); + +} +}); + +cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$1 = (function (args){ +return cljs.core.seq(args); +}); + +cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$2 = (function (a,args){ +return cljs.core.cons(a,args); +}); + +cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$3 = (function (a,b,args){ +return cljs.core.cons(a,cljs.core.cons(b,args)); +}); + +cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$4 = (function (a,b,c,args){ +return cljs.core.cons(a,cljs.core.cons(b,cljs.core.cons(c,args))); +}); + +cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$variadic = (function (a,b,c,d,more){ +return cljs.core.cons(a,cljs.core.cons(b,cljs.core.cons(c,cljs.core.cons(d,cljs.core.spread(more))))); +}); + +/** @this {Function} */ +cljs.core.list_STAR_.cljs$lang$applyTo = (function (seq3501){ +var G__3502 = cljs.core.first(seq3501); +var seq3501__$1 = cljs.core.next(seq3501); +var G__3503 = cljs.core.first(seq3501__$1); +var seq3501__$2 = cljs.core.next(seq3501__$1); +var G__3504 = cljs.core.first(seq3501__$2); +var seq3501__$3 = cljs.core.next(seq3501__$2); +var G__3505 = cljs.core.first(seq3501__$3); +var seq3501__$4 = cljs.core.next(seq3501__$3); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3502,G__3503,G__3504,G__3505,seq3501__$4); +}); + +cljs.core.list_STAR_.cljs$lang$maxFixedArity = (4); + +/** + * Returns a new, transient version of the collection, in constant time. + */ +cljs.core.transient$ = (function cljs$core$transient(coll){ +return cljs.core._as_transient(coll); +}); +/** + * Returns a new, persistent version of the transient collection, in + * constant time. The transient collection cannot be used after this + * call, any such use will throw an exception. + */ +cljs.core.persistent_BANG_ = (function cljs$core$persistent_BANG_(tcoll){ +return cljs.core._persistent_BANG_(tcoll); +}); +/** + * Adds val to the transient collection, and return tcoll. The 'addition' + * may happen at different 'places' depending on the concrete type. + */ +cljs.core.conj_BANG_ = (function cljs$core$conj_BANG_(var_args){ +var G__3515 = arguments.length; +switch (G__3515) { +case 0: +return cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3517 = arguments.length; +var i__4731__auto___3518 = (0); +while(true){ +if((i__4731__auto___3518 < len__4730__auto___3517)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3518])); + +var G__3519 = (i__4731__auto___3518 + (1)); +i__4731__auto___3518 = G__3519; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.transient$(cljs.core.PersistentVector.EMPTY); +}); + +cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$1 = (function (tcoll){ +return tcoll; +}); + +cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$2 = (function (tcoll,val){ +return cljs.core._conj_BANG_(tcoll,val); +}); + +cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (tcoll,val,vals){ +while(true){ +var ntcoll = cljs.core._conj_BANG_(tcoll,val); +if(cljs.core.truth_(vals)){ +var G__3520 = ntcoll; +var G__3521 = cljs.core.first(vals); +var G__3522 = cljs.core.next(vals); +tcoll = G__3520; +val = G__3521; +vals = G__3522; +continue; +} else { +return ntcoll; +} +break; +} +}); + +/** @this {Function} */ +cljs.core.conj_BANG_.cljs$lang$applyTo = (function (seq3512){ +var G__3513 = cljs.core.first(seq3512); +var seq3512__$1 = cljs.core.next(seq3512); +var G__3514 = cljs.core.first(seq3512__$1); +var seq3512__$2 = cljs.core.next(seq3512__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3513,G__3514,seq3512__$2); +}); + +cljs.core.conj_BANG_.cljs$lang$maxFixedArity = (2); + +/** + * When applied to a transient map, adds mapping of key(s) to + * val(s). When applied to a transient vector, sets the val at index. + * Note - index must be <= (count vector). Returns coll. + */ +cljs.core.assoc_BANG_ = (function cljs$core$assoc_BANG_(var_args){ +var G__3528 = arguments.length; +switch (G__3528) { +case 3: +return cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3530 = arguments.length; +var i__4731__auto___3531 = (0); +while(true){ +if((i__4731__auto___3531 < len__4730__auto___3530)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3531])); + +var G__3532 = (i__4731__auto___3531 + (1)); +i__4731__auto___3531 = G__3532; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3 = (function (tcoll,key,val){ +return cljs.core._assoc_BANG_(tcoll,key,val); +}); + +cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (tcoll,key,val,kvs){ +while(true){ +var ntcoll = cljs.core._assoc_BANG_(tcoll,key,val); +if(cljs.core.truth_(kvs)){ +var G__3533 = ntcoll; +var G__3534 = cljs.core.first(kvs); +var G__3535 = cljs.core.second(kvs); +var G__3536 = cljs.core.nnext(kvs); +tcoll = G__3533; +key = G__3534; +val = G__3535; +kvs = G__3536; +continue; +} else { +return ntcoll; +} +break; +} +}); + +/** @this {Function} */ +cljs.core.assoc_BANG_.cljs$lang$applyTo = (function (seq3524){ +var G__3525 = cljs.core.first(seq3524); +var seq3524__$1 = cljs.core.next(seq3524); +var G__3526 = cljs.core.first(seq3524__$1); +var seq3524__$2 = cljs.core.next(seq3524__$1); +var G__3527 = cljs.core.first(seq3524__$2); +var seq3524__$3 = cljs.core.next(seq3524__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3525,G__3526,G__3527,seq3524__$3); +}); + +cljs.core.assoc_BANG_.cljs$lang$maxFixedArity = (3); + +/** + * Returns a transient map that doesn't contain a mapping for key(s). + */ +cljs.core.dissoc_BANG_ = (function cljs$core$dissoc_BANG_(var_args){ +var G__3541 = arguments.length; +switch (G__3541) { +case 2: +return cljs.core.dissoc_BANG_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3543 = arguments.length; +var i__4731__auto___3544 = (0); +while(true){ +if((i__4731__auto___3544 < len__4730__auto___3543)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3544])); + +var G__3545 = (i__4731__auto___3544 + (1)); +i__4731__auto___3544 = G__3545; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.dissoc_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.dissoc_BANG_.cljs$core$IFn$_invoke$arity$2 = (function (tcoll,key){ +return cljs.core._dissoc_BANG_(tcoll,key); +}); + +cljs.core.dissoc_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (tcoll,key,ks){ +while(true){ +var ntcoll = cljs.core._dissoc_BANG_(tcoll,key); +if(cljs.core.truth_(ks)){ +var G__3546 = ntcoll; +var G__3547 = cljs.core.first(ks); +var G__3548 = cljs.core.next(ks); +tcoll = G__3546; +key = G__3547; +ks = G__3548; +continue; +} else { +return ntcoll; +} +break; +} +}); + +/** @this {Function} */ +cljs.core.dissoc_BANG_.cljs$lang$applyTo = (function (seq3538){ +var G__3539 = cljs.core.first(seq3538); +var seq3538__$1 = cljs.core.next(seq3538); +var G__3540 = cljs.core.first(seq3538__$1); +var seq3538__$2 = cljs.core.next(seq3538__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3539,G__3540,seq3538__$2); +}); + +cljs.core.dissoc_BANG_.cljs$lang$maxFixedArity = (2); + +/** + * Removes the last item from a transient vector. If + * the collection is empty, throws an exception. Returns tcoll + */ +cljs.core.pop_BANG_ = (function cljs$core$pop_BANG_(tcoll){ +return cljs.core._pop_BANG_(tcoll); +}); +/** + * disj[oin]. Returns a transient set of the same (hashed/sorted) type, that + * does not contain key(s). + */ +cljs.core.disj_BANG_ = (function cljs$core$disj_BANG_(var_args){ +var G__3553 = arguments.length; +switch (G__3553) { +case 2: +return cljs.core.disj_BANG_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3555 = arguments.length; +var i__4731__auto___3556 = (0); +while(true){ +if((i__4731__auto___3556 < len__4730__auto___3555)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3556])); + +var G__3557 = (i__4731__auto___3556 + (1)); +i__4731__auto___3556 = G__3557; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.disj_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.disj_BANG_.cljs$core$IFn$_invoke$arity$2 = (function (tcoll,val){ +return cljs.core._disjoin_BANG_(tcoll,val); +}); + +cljs.core.disj_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (tcoll,val,vals){ +while(true){ +var ntcoll = cljs.core._disjoin_BANG_(tcoll,val); +if(cljs.core.truth_(vals)){ +var G__3558 = ntcoll; +var G__3559 = cljs.core.first(vals); +var G__3560 = cljs.core.next(vals); +tcoll = G__3558; +val = G__3559; +vals = G__3560; +continue; +} else { +return ntcoll; +} +break; +} +}); + +/** @this {Function} */ +cljs.core.disj_BANG_.cljs$lang$applyTo = (function (seq3550){ +var G__3551 = cljs.core.first(seq3550); +var seq3550__$1 = cljs.core.next(seq3550); +var G__3552 = cljs.core.first(seq3550__$1); +var seq3550__$2 = cljs.core.next(seq3550__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3551,G__3552,seq3550__$2); +}); + +cljs.core.disj_BANG_.cljs$lang$maxFixedArity = (2); + + +cljs.core.apply_to = (function cljs$core$apply_to(f,argc,args){ +var args__$1 = cljs.core.seq(args); +if((argc === (0))){ +return (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); +} else { +var a254 = cljs.core._first(args__$1); +var args__$2 = cljs.core._rest(args__$1); +if((argc === (1))){ +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(a254) : f.call(null,a254)); +} else { +var b255 = cljs.core._first(args__$2); +var args__$3 = cljs.core._rest(args__$2); +if((argc === (2))){ +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(a254,b255) : f.call(null,a254,b255)); +} else { +var c256 = cljs.core._first(args__$3); +var args__$4 = cljs.core._rest(args__$3); +if((argc === (3))){ +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(a254,b255,c256) : f.call(null,a254,b255,c256)); +} else { +var d257 = cljs.core._first(args__$4); +var args__$5 = cljs.core._rest(args__$4); +if((argc === (4))){ +return (f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(a254,b255,c256,d257) : f.call(null,a254,b255,c256,d257)); +} else { +var e258 = cljs.core._first(args__$5); +var args__$6 = cljs.core._rest(args__$5); +if((argc === (5))){ +return (f.cljs$core$IFn$_invoke$arity$5 ? f.cljs$core$IFn$_invoke$arity$5(a254,b255,c256,d257,e258) : f.call(null,a254,b255,c256,d257,e258)); +} else { +var f259 = cljs.core._first(args__$6); +var args__$7 = cljs.core._rest(args__$6); +if((argc === (6))){ +return (f.cljs$core$IFn$_invoke$arity$6 ? f.cljs$core$IFn$_invoke$arity$6(a254,b255,c256,d257,e258,f259) : f.call(null,a254,b255,c256,d257,e258,f259)); +} else { +var g260 = cljs.core._first(args__$7); +var args__$8 = cljs.core._rest(args__$7); +if((argc === (7))){ +return (f.cljs$core$IFn$_invoke$arity$7 ? f.cljs$core$IFn$_invoke$arity$7(a254,b255,c256,d257,e258,f259,g260) : f.call(null,a254,b255,c256,d257,e258,f259,g260)); +} else { +var h261 = cljs.core._first(args__$8); +var args__$9 = cljs.core._rest(args__$8); +if((argc === (8))){ +return (f.cljs$core$IFn$_invoke$arity$8 ? f.cljs$core$IFn$_invoke$arity$8(a254,b255,c256,d257,e258,f259,g260,h261) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261)); +} else { +var i262 = cljs.core._first(args__$9); +var args__$10 = cljs.core._rest(args__$9); +if((argc === (9))){ +return (f.cljs$core$IFn$_invoke$arity$9 ? f.cljs$core$IFn$_invoke$arity$9(a254,b255,c256,d257,e258,f259,g260,h261,i262) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262)); +} else { +var j263 = cljs.core._first(args__$10); +var args__$11 = cljs.core._rest(args__$10); +if((argc === (10))){ +return (f.cljs$core$IFn$_invoke$arity$10 ? f.cljs$core$IFn$_invoke$arity$10(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263)); +} else { +var k264 = cljs.core._first(args__$11); +var args__$12 = cljs.core._rest(args__$11); +if((argc === (11))){ +return (f.cljs$core$IFn$_invoke$arity$11 ? f.cljs$core$IFn$_invoke$arity$11(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264)); +} else { +var l265 = cljs.core._first(args__$12); +var args__$13 = cljs.core._rest(args__$12); +if((argc === (12))){ +return (f.cljs$core$IFn$_invoke$arity$12 ? f.cljs$core$IFn$_invoke$arity$12(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265)); +} else { +var m266 = cljs.core._first(args__$13); +var args__$14 = cljs.core._rest(args__$13); +if((argc === (13))){ +return (f.cljs$core$IFn$_invoke$arity$13 ? f.cljs$core$IFn$_invoke$arity$13(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266)); +} else { +var n267 = cljs.core._first(args__$14); +var args__$15 = cljs.core._rest(args__$14); +if((argc === (14))){ +return (f.cljs$core$IFn$_invoke$arity$14 ? f.cljs$core$IFn$_invoke$arity$14(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267)); +} else { +var o268 = cljs.core._first(args__$15); +var args__$16 = cljs.core._rest(args__$15); +if((argc === (15))){ +return (f.cljs$core$IFn$_invoke$arity$15 ? f.cljs$core$IFn$_invoke$arity$15(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268)); +} else { +var p269 = cljs.core._first(args__$16); +var args__$17 = cljs.core._rest(args__$16); +if((argc === (16))){ +return (f.cljs$core$IFn$_invoke$arity$16 ? f.cljs$core$IFn$_invoke$arity$16(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269)); +} else { +var q270 = cljs.core._first(args__$17); +var args__$18 = cljs.core._rest(args__$17); +if((argc === (17))){ +return (f.cljs$core$IFn$_invoke$arity$17 ? f.cljs$core$IFn$_invoke$arity$17(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269,q270) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269,q270)); +} else { +var r271 = cljs.core._first(args__$18); +var args__$19 = cljs.core._rest(args__$18); +if((argc === (18))){ +return (f.cljs$core$IFn$_invoke$arity$18 ? f.cljs$core$IFn$_invoke$arity$18(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269,q270,r271) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269,q270,r271)); +} else { +var s272 = cljs.core._first(args__$19); +var args__$20 = cljs.core._rest(args__$19); +if((argc === (19))){ +return (f.cljs$core$IFn$_invoke$arity$19 ? f.cljs$core$IFn$_invoke$arity$19(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269,q270,r271,s272) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269,q270,r271,s272)); +} else { +var t273 = cljs.core._first(args__$20); +var args__$21 = cljs.core._rest(args__$20); +if((argc === (20))){ +return (f.cljs$core$IFn$_invoke$arity$20 ? f.cljs$core$IFn$_invoke$arity$20(a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269,q270,r271,s272,t273) : f.call(null,a254,b255,c256,d257,e258,f259,g260,h261,i262,j263,k264,l265,m266,n267,o268,p269,q270,r271,s272,t273)); +} else { +throw (new Error("Only up to 20 arguments supported on functions")); +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +}); + +/** + * Internal. DO NOT USE! Next without the nil? check. + */ +cljs.core.next_STAR_ = (function cljs$core$next_STAR_(coll){ +if((((!((coll == null))))?(((((coll.cljs$lang$protocol_mask$partition0$ & (128))) || ((cljs.core.PROTOCOL_SENTINEL === coll.cljs$core$INext$))))?true:false):false)){ +return coll.cljs$core$INext$_next$arity$1(null); +} else { +return cljs.core.seq(cljs.core.rest(coll)); +} +}); +/** + * Internal. DO NOT USE! + * Assumes args was already called with seq beforehand! + */ +cljs.core.apply_to_simple = (function cljs$core$apply_to_simple(var_args){ +var G__3563 = arguments.length; +switch (G__3563) { +case 2: +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +case 6: +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$6((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$2 = (function (f,args){ +if((args == null)){ +if(f.cljs$core$IFn$_invoke$arity$0){ +return f.cljs$core$IFn$_invoke$arity$0(); +} else { +return f.call(f); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$3(f,cljs.core._first(args),cljs.core.next_STAR_(args)); +} +}); + +cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$3 = (function (f,a0,args){ +if((args == null)){ +if(f.cljs$core$IFn$_invoke$arity$1){ +return f.cljs$core$IFn$_invoke$arity$1(a0); +} else { +return f.call(f,a0); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$4(f,a0,cljs.core._first(args),cljs.core.next_STAR_(args)); +} +}); + +cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$4 = (function (f,a0,a1,args){ +if((args == null)){ +if(f.cljs$core$IFn$_invoke$arity$2){ +return f.cljs$core$IFn$_invoke$arity$2(a0,a1); +} else { +return f.call(f,a0,a1); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$5(f,a0,a1,cljs.core._first(args),cljs.core.next_STAR_(args)); +} +}); + +cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$5 = (function (f,a0,a1,a2,args){ +if((args == null)){ +if(f.cljs$core$IFn$_invoke$arity$3){ +return f.cljs$core$IFn$_invoke$arity$3(a0,a1,a2); +} else { +return f.call(f,a0,a1,a2); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$6(f,a0,a1,a2,cljs.core._first(args),cljs.core.next_STAR_(args)); +} +}); + +cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$6 = (function (f,a0,a1,a2,a3,args){ +if((args == null)){ +if(f.cljs$core$IFn$_invoke$arity$4){ +return f.cljs$core$IFn$_invoke$arity$4(a0,a1,a2,a3); +} else { +return f.call(f,a0,a1,a2,a3); +} +} else { +var a4 = cljs.core._first(args); +var next_4 = cljs.core.next(args); +if((next_4 == null)){ +if(f.cljs$core$IFn$_invoke$arity$5){ +return f.cljs$core$IFn$_invoke$arity$5(a0,a1,a2,a3,a4); +} else { +return f.call(f,a0,a1,a2,a3,a4); +} +} else { +var a5 = cljs.core._first(next_4); +var next_5 = cljs.core.next(next_4); +if((next_5 == null)){ +if(f.cljs$core$IFn$_invoke$arity$6){ +return f.cljs$core$IFn$_invoke$arity$6(a0,a1,a2,a3,a4,a5); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5); +} +} else { +var a6 = cljs.core._first(next_5); +var next_6 = cljs.core.next(next_5); +if((next_6 == null)){ +if(f.cljs$core$IFn$_invoke$arity$7){ +return f.cljs$core$IFn$_invoke$arity$7(a0,a1,a2,a3,a4,a5,a6); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6); +} +} else { +var a7 = cljs.core._first(next_6); +var next_7 = cljs.core.next(next_6); +if((next_7 == null)){ +if(f.cljs$core$IFn$_invoke$arity$8){ +return f.cljs$core$IFn$_invoke$arity$8(a0,a1,a2,a3,a4,a5,a6,a7); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7); +} +} else { +var a8 = cljs.core._first(next_7); +var next_8 = cljs.core.next(next_7); +if((next_8 == null)){ +if(f.cljs$core$IFn$_invoke$arity$9){ +return f.cljs$core$IFn$_invoke$arity$9(a0,a1,a2,a3,a4,a5,a6,a7,a8); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8); +} +} else { +var a9 = cljs.core._first(next_8); +var next_9 = cljs.core.next(next_8); +if((next_9 == null)){ +if(f.cljs$core$IFn$_invoke$arity$10){ +return f.cljs$core$IFn$_invoke$arity$10(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9); +} +} else { +var a10 = cljs.core._first(next_9); +var next_10 = cljs.core.next(next_9); +if((next_10 == null)){ +if(f.cljs$core$IFn$_invoke$arity$11){ +return f.cljs$core$IFn$_invoke$arity$11(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10); +} +} else { +var a11 = cljs.core._first(next_10); +var next_11 = cljs.core.next(next_10); +if((next_11 == null)){ +if(f.cljs$core$IFn$_invoke$arity$12){ +return f.cljs$core$IFn$_invoke$arity$12(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11); +} +} else { +var a12 = cljs.core._first(next_11); +var next_12 = cljs.core.next(next_11); +if((next_12 == null)){ +if(f.cljs$core$IFn$_invoke$arity$13){ +return f.cljs$core$IFn$_invoke$arity$13(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12); +} +} else { +var a13 = cljs.core._first(next_12); +var next_13 = cljs.core.next(next_12); +if((next_13 == null)){ +if(f.cljs$core$IFn$_invoke$arity$14){ +return f.cljs$core$IFn$_invoke$arity$14(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13); +} +} else { +var a14 = cljs.core._first(next_13); +var next_14 = cljs.core.next(next_13); +if((next_14 == null)){ +if(f.cljs$core$IFn$_invoke$arity$15){ +return f.cljs$core$IFn$_invoke$arity$15(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14); +} +} else { +var a15 = cljs.core._first(next_14); +var next_15 = cljs.core.next(next_14); +if((next_15 == null)){ +if(f.cljs$core$IFn$_invoke$arity$16){ +return f.cljs$core$IFn$_invoke$arity$16(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15); +} +} else { +var a16 = cljs.core._first(next_15); +var next_16 = cljs.core.next(next_15); +if((next_16 == null)){ +if(f.cljs$core$IFn$_invoke$arity$17){ +return f.cljs$core$IFn$_invoke$arity$17(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16); +} +} else { +var a17 = cljs.core._first(next_16); +var next_17 = cljs.core.next(next_16); +if((next_17 == null)){ +if(f.cljs$core$IFn$_invoke$arity$18){ +return f.cljs$core$IFn$_invoke$arity$18(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17); +} +} else { +var a18 = cljs.core._first(next_17); +var next_18 = cljs.core.next(next_17); +if((next_18 == null)){ +if(f.cljs$core$IFn$_invoke$arity$19){ +return f.cljs$core$IFn$_invoke$arity$19(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18); +} +} else { +var a19 = cljs.core._first(next_18); +var next_19 = cljs.core.next(next_18); +if((next_19 == null)){ +if(f.cljs$core$IFn$_invoke$arity$20){ +return f.cljs$core$IFn$_invoke$arity$20(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19); +} else { +return f.call(f,a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19); +} +} else { +var arr__4655__auto__ = [a0,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16,a17,a18,a19]; +var s__4656__auto___3565 = next_19; +while(true){ +if(s__4656__auto___3565){ +arr__4655__auto__.push(cljs.core._first(s__4656__auto___3565)); + +var G__3566 = cljs.core.next(s__4656__auto___3565); +s__4656__auto___3565 = G__3566; +continue; +} else { +} +break; +} + +return f.apply(f,arr__4655__auto__); +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +}); + +cljs.core.apply_to_simple.cljs$lang$maxFixedArity = 6; + +/** + * Applies fn f to the argument list formed by prepending intervening arguments to args. + */ +cljs.core.apply = (function cljs$core$apply(var_args){ +var G__3574 = arguments.length; +switch (G__3574) { +case 2: +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.apply.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.apply.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core.apply.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3576 = arguments.length; +var i__4731__auto___3577 = (0); +while(true){ +if((i__4731__auto___3577 < len__4730__auto___3576)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3577])); + +var G__3578 = (i__4731__auto___3577 + (1)); +i__4731__auto___3577 = G__3578; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((5)),(0),null)); +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),argseq__4752__auto__); + +} +}); + +cljs.core.apply.cljs$core$IFn$_invoke$arity$2 = (function (f,args){ +if(f.cljs$lang$applyTo){ +var fixed_arity = f.cljs$lang$maxFixedArity; +var bc = cljs.core.bounded_count((fixed_arity + (1)),args); +if((bc <= fixed_arity)){ +return cljs.core.apply_to(f,bc,args); +} else { +return f.cljs$lang$applyTo(args); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$2(f,cljs.core.seq(args)); +} +}); + +cljs.core.apply.cljs$core$IFn$_invoke$arity$3 = (function (f,x,args){ +if(f.cljs$lang$applyTo){ +var arglist = cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$2(x,args); +var fixed_arity = f.cljs$lang$maxFixedArity; +var bc = (cljs.core.bounded_count(fixed_arity,args) + (1)); +if((bc <= fixed_arity)){ +return cljs.core.apply_to(f,bc,arglist); +} else { +return f.cljs$lang$applyTo(arglist); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$3(f,x,cljs.core.seq(args)); +} +}); + +cljs.core.apply.cljs$core$IFn$_invoke$arity$4 = (function (f,x,y,args){ +if(f.cljs$lang$applyTo){ +var arglist = cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$3(x,y,args); +var fixed_arity = f.cljs$lang$maxFixedArity; +var bc = ((2) + cljs.core.bounded_count((fixed_arity - (1)),args)); +if((bc <= fixed_arity)){ +return cljs.core.apply_to(f,bc,arglist); +} else { +return f.cljs$lang$applyTo(arglist); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$4(f,x,y,cljs.core.seq(args)); +} +}); + +cljs.core.apply.cljs$core$IFn$_invoke$arity$5 = (function (f,x,y,z,args){ +if(f.cljs$lang$applyTo){ +var arglist = cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$4(x,y,z,args); +var fixed_arity = f.cljs$lang$maxFixedArity; +var bc = ((3) + cljs.core.bounded_count((fixed_arity - (2)),args)); +if((bc <= fixed_arity)){ +return cljs.core.apply_to(f,bc,arglist); +} else { +return f.cljs$lang$applyTo(arglist); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$5(f,x,y,z,cljs.core.seq(args)); +} +}); + +cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic = (function (f,a,b,c,d,args){ +if(f.cljs$lang$applyTo){ +var spread_args = cljs.core.spread(args); +var arglist = cljs.core.cons(a,cljs.core.cons(b,cljs.core.cons(c,cljs.core.cons(d,spread_args)))); +var fixed_arity = f.cljs$lang$maxFixedArity; +var bc = ((4) + cljs.core.bounded_count((fixed_arity - (3)),spread_args)); +if((bc <= fixed_arity)){ +return cljs.core.apply_to(f,bc,arglist); +} else { +return f.cljs$lang$applyTo(arglist); +} +} else { +return cljs.core.apply_to_simple.cljs$core$IFn$_invoke$arity$6(f,a,b,c,d,cljs.core.spread(args)); +} +}); + +/** @this {Function} */ +cljs.core.apply.cljs$lang$applyTo = (function (seq3568){ +var G__3569 = cljs.core.first(seq3568); +var seq3568__$1 = cljs.core.next(seq3568); +var G__3570 = cljs.core.first(seq3568__$1); +var seq3568__$2 = cljs.core.next(seq3568__$1); +var G__3571 = cljs.core.first(seq3568__$2); +var seq3568__$3 = cljs.core.next(seq3568__$2); +var G__3572 = cljs.core.first(seq3568__$3); +var seq3568__$4 = cljs.core.next(seq3568__$3); +var G__3573 = cljs.core.first(seq3568__$4); +var seq3568__$5 = cljs.core.next(seq3568__$4); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3569,G__3570,G__3571,G__3572,G__3573,seq3568__$5); +}); + +cljs.core.apply.cljs$lang$maxFixedArity = (5); + +/** + * Returns an object of the same type and value as obj, with + * (apply f (meta obj) args) as its metadata. + */ +cljs.core.vary_meta = (function cljs$core$vary_meta(var_args){ +var G__3587 = arguments.length; +switch (G__3587) { +case 2: +return cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +case 6: +return cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$6((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3604 = arguments.length; +var i__4731__auto___3605 = (0); +while(true){ +if((i__4731__auto___3605 < len__4730__auto___3604)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3605])); + +var G__3606 = (i__4731__auto___3605 + (1)); +i__4731__auto___3605 = G__3606; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((6)),(0),null)); +return cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),argseq__4752__auto__); + +} +}); + +cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$2 = (function (obj,f){ +return cljs.core.with_meta(obj,(function (){var G__3588 = cljs.core.meta(obj); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3588) : f.call(null,G__3588)); +})()); +}); + +cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$3 = (function (obj,f,a){ +return cljs.core.with_meta(obj,(function (){var G__3589 = cljs.core.meta(obj); +var G__3590 = a; +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3589,G__3590) : f.call(null,G__3589,G__3590)); +})()); +}); + +cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$4 = (function (obj,f,a,b){ +return cljs.core.with_meta(obj,(function (){var G__3591 = cljs.core.meta(obj); +var G__3592 = a; +var G__3593 = b; +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__3591,G__3592,G__3593) : f.call(null,G__3591,G__3592,G__3593)); +})()); +}); + +cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$5 = (function (obj,f,a,b,c){ +return cljs.core.with_meta(obj,(function (){var G__3594 = cljs.core.meta(obj); +var G__3595 = a; +var G__3596 = b; +var G__3597 = c; +return (f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(G__3594,G__3595,G__3596,G__3597) : f.call(null,G__3594,G__3595,G__3596,G__3597)); +})()); +}); + +cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$6 = (function (obj,f,a,b,c,d){ +return cljs.core.with_meta(obj,(function (){var G__3598 = cljs.core.meta(obj); +var G__3599 = a; +var G__3600 = b; +var G__3601 = c; +var G__3602 = d; +return (f.cljs$core$IFn$_invoke$arity$5 ? f.cljs$core$IFn$_invoke$arity$5(G__3598,G__3599,G__3600,G__3601,G__3602) : f.call(null,G__3598,G__3599,G__3600,G__3601,G__3602)); +})()); +}); + +cljs.core.vary_meta.cljs$core$IFn$_invoke$arity$variadic = (function (obj,f,a,b,c,d,args){ +return cljs.core.with_meta(obj,cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(f,cljs.core.meta(obj),a,b,c,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([d,args], 0))); +}); + +/** @this {Function} */ +cljs.core.vary_meta.cljs$lang$applyTo = (function (seq3580){ +var G__3581 = cljs.core.first(seq3580); +var seq3580__$1 = cljs.core.next(seq3580); +var G__3582 = cljs.core.first(seq3580__$1); +var seq3580__$2 = cljs.core.next(seq3580__$1); +var G__3583 = cljs.core.first(seq3580__$2); +var seq3580__$3 = cljs.core.next(seq3580__$2); +var G__3584 = cljs.core.first(seq3580__$3); +var seq3580__$4 = cljs.core.next(seq3580__$3); +var G__3585 = cljs.core.first(seq3580__$4); +var seq3580__$5 = cljs.core.next(seq3580__$4); +var G__3586 = cljs.core.first(seq3580__$5); +var seq3580__$6 = cljs.core.next(seq3580__$5); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3581,G__3582,G__3583,G__3584,G__3585,G__3586,seq3580__$6); +}); + +cljs.core.vary_meta.cljs$lang$maxFixedArity = (6); + +/** + * Same as (not (= obj1 obj2)) + */ +cljs.core.not_EQ_ = (function cljs$core$not_EQ_(var_args){ +var G__3611 = arguments.length; +switch (G__3611) { +case 1: +return cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3613 = arguments.length; +var i__4731__auto___3614 = (0); +while(true){ +if((i__4731__auto___3614 < len__4730__auto___3613)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3614])); + +var G__3615 = (i__4731__auto___3614 + (1)); +i__4731__auto___3614 = G__3615; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return false; +}); + +cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2 = (function (x,y){ +return (!(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(x,y))); +}); + +cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$variadic = (function (x,y,more){ +return cljs.core.not(cljs.core.apply.cljs$core$IFn$_invoke$arity$4(cljs.core._EQ_,x,y,more)); +}); + +/** @this {Function} */ +cljs.core.not_EQ_.cljs$lang$applyTo = (function (seq3608){ +var G__3609 = cljs.core.first(seq3608); +var seq3608__$1 = cljs.core.next(seq3608); +var G__3610 = cljs.core.first(seq3608__$1); +var seq3608__$2 = cljs.core.next(seq3608__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3609,G__3610,seq3608__$2); +}); + +cljs.core.not_EQ_.cljs$lang$maxFixedArity = (2); + +/** + * If coll is empty, returns nil, else coll + */ +cljs.core.not_empty = (function cljs$core$not_empty(coll){ +if(cljs.core.seq(coll)){ +return coll; +} else { +return null; +} +}); +cljs.core.nil_iter = (function cljs$core$nil_iter(){ +if((typeof cljs !== 'undefined') && (typeof cljs.core !== 'undefined') && (typeof cljs.core.t_cljs$core3616 !== 'undefined')){ +} else { + +/** +* @constructor + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IWithMeta} +*/ +cljs.core.t_cljs$core3616 = (function (meta3617){ +this.meta3617 = meta3617; +this.cljs$lang$protocol_mask$partition0$ = 393216; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.t_cljs$core3616.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (_3618,meta3617__$1){ +var self__ = this; +var _3618__$1 = this; +return (new cljs.core.t_cljs$core3616(meta3617__$1)); +}); + +cljs.core.t_cljs$core3616.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_3618){ +var self__ = this; +var _3618__$1 = this; +return self__.meta3617; +}); + +cljs.core.t_cljs$core3616.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +return false; +}); + +cljs.core.t_cljs$core3616.prototype.next = (function (){ +var self__ = this; +var _ = this; +return (new Error("No such element")); +}); + +cljs.core.t_cljs$core3616.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.t_cljs$core3616.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta3617], null); +}); + +cljs.core.t_cljs$core3616.cljs$lang$type = true; + +cljs.core.t_cljs$core3616.cljs$lang$ctorStr = "cljs.core/t_cljs$core3616"; + +cljs.core.t_cljs$core3616.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/t_cljs$core3616"); +}); + +/** + * Positional factory function for cljs.core/t_cljs$core3616. + */ +cljs.core.__GT_t_cljs$core3616 = (function cljs$core$nil_iter_$___GT_t_cljs$core3616(meta3617){ +return (new cljs.core.t_cljs$core3616(meta3617)); +}); + +} + +return (new cljs.core.t_cljs$core3616(cljs.core.PersistentArrayMap.EMPTY)); +}); + +/** +* @constructor +*/ +cljs.core.StringIter = (function (s,i){ +this.s = s; +this.i = i; +}); +cljs.core.StringIter.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +return (self__.i < self__.s.length); +}); + +cljs.core.StringIter.prototype.next = (function (){ +var self__ = this; +var _ = this; +var ret = self__.s.charAt(self__.i); +self__.i = (self__.i + (1)); + +return ret; +}); + +cljs.core.StringIter.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.StringIter.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$s,cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.StringIter.cljs$lang$type = true; + +cljs.core.StringIter.cljs$lang$ctorStr = "cljs.core/StringIter"; + +cljs.core.StringIter.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/StringIter"); +}); + +/** + * Positional factory function for cljs.core/StringIter. + */ +cljs.core.__GT_StringIter = (function cljs$core$__GT_StringIter(s,i){ +return (new cljs.core.StringIter(s,i)); +}); + +cljs.core.string_iter = (function cljs$core$string_iter(x){ +return (new cljs.core.StringIter(x,(0))); +}); + +/** +* @constructor +*/ +cljs.core.ArrayIter = (function (arr,i){ +this.arr = arr; +this.i = i; +}); +cljs.core.ArrayIter.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +return (self__.i < self__.arr.length); +}); + +cljs.core.ArrayIter.prototype.next = (function (){ +var self__ = this; +var _ = this; +var ret = (self__.arr[self__.i]); +self__.i = (self__.i + (1)); + +return ret; +}); + +cljs.core.ArrayIter.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.ArrayIter.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$arr,cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ArrayIter.cljs$lang$type = true; + +cljs.core.ArrayIter.cljs$lang$ctorStr = "cljs.core/ArrayIter"; + +cljs.core.ArrayIter.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ArrayIter"); +}); + +/** + * Positional factory function for cljs.core/ArrayIter. + */ +cljs.core.__GT_ArrayIter = (function cljs$core$__GT_ArrayIter(arr,i){ +return (new cljs.core.ArrayIter(arr,i)); +}); + +cljs.core.array_iter = (function cljs$core$array_iter(x){ +return (new cljs.core.ArrayIter(x,(0))); +}); +cljs.core.INIT = ({}); +cljs.core.START = ({}); + +/** +* @constructor +*/ +cljs.core.SeqIter = (function (_seq,_next){ +this._seq = _seq; +this._next = _next; +}); +cljs.core.SeqIter.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +if((self__._seq === cljs.core.INIT)){ +self__._seq = cljs.core.START; + +self__._next = cljs.core.seq(self__._next); +} else { +if((self__._seq === self__._next)){ +self__._next = cljs.core.next(self__._seq); +} else { +} +} + +return (!((self__._next == null))); +}); + +cljs.core.SeqIter.prototype.next = (function (){ +var self__ = this; +var this$ = this; +if((!(this$.hasNext()))){ +throw (new Error("No such element")); +} else { +self__._seq = self__._next; + +return cljs.core.first(self__._next); +} +}); + +cljs.core.SeqIter.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.SeqIter.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$_seq,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$_next,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.SeqIter.cljs$lang$type = true; + +cljs.core.SeqIter.cljs$lang$ctorStr = "cljs.core/SeqIter"; + +cljs.core.SeqIter.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/SeqIter"); +}); + +/** + * Positional factory function for cljs.core/SeqIter. + */ +cljs.core.__GT_SeqIter = (function cljs$core$__GT_SeqIter(_seq,_next){ +return (new cljs.core.SeqIter(_seq,_next)); +}); + +cljs.core.seq_iter = (function cljs$core$seq_iter(coll){ +return (new cljs.core.SeqIter(cljs.core.INIT,coll)); +}); +cljs.core.iter = (function cljs$core$iter(coll){ +if(cljs.core.iterable_QMARK_(coll)){ +return cljs.core._iterator(coll); +} else { +if((coll == null)){ +return cljs.core.nil_iter(); +} else { +if(typeof coll === 'string'){ +return cljs.core.string_iter(coll); +} else { +if(cljs.core.array_QMARK_(coll)){ +return cljs.core.array_iter(coll); +} else { +if(cljs.core.seqable_QMARK_(coll)){ +return cljs.core.seq_iter(coll); +} else { +throw (new Error(["Cannot create iterator from ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(coll)].join(''))); + +} +} +} +} +} +}); + +/** +* @constructor +*/ +cljs.core.Many = (function (vals){ +this.vals = vals; +}); +cljs.core.Many.prototype.add = (function (o){ +var self__ = this; +var this$ = this; +self__.vals.push(o); + +return this$; +}); + +cljs.core.Many.prototype.remove = (function (){ +var self__ = this; +var this$ = this; +return self__.vals.shift(); +}); + +cljs.core.Many.prototype.isEmpty = (function (){ +var self__ = this; +var this$ = this; +return (self__.vals.length === (0)); +}); + +cljs.core.Many.prototype.toString = (function (){ +var self__ = this; +var this$ = this; +return ["Many: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.vals)].join(''); +}); + +cljs.core.Many.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$vals], null); +}); + +cljs.core.Many.cljs$lang$type = true; + +cljs.core.Many.cljs$lang$ctorStr = "cljs.core/Many"; + +cljs.core.Many.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Many"); +}); + +/** + * Positional factory function for cljs.core/Many. + */ +cljs.core.__GT_Many = (function cljs$core$__GT_Many(vals){ +return (new cljs.core.Many(vals)); +}); + +cljs.core.NONE = ({}); + +/** +* @constructor +*/ +cljs.core.Single = (function (val){ +this.val = val; +}); +cljs.core.Single.prototype.add = (function (o){ +var self__ = this; +var this$ = this; +if((self__.val === cljs.core.NONE)){ +self__.val = o; + +return this$; +} else { +return (new cljs.core.Many([self__.val,o])); +} +}); + +cljs.core.Single.prototype.remove = (function (){ +var self__ = this; +var this$ = this; +if((self__.val === cljs.core.NONE)){ +throw (new Error("Removing object from empty buffer")); +} else { +var ret = self__.val; +self__.val = cljs.core.NONE; + +return ret; +} +}); + +cljs.core.Single.prototype.isEmpty = (function (){ +var self__ = this; +var this$ = this; +return (self__.val === cljs.core.NONE); +}); + +cljs.core.Single.prototype.toString = (function (){ +var self__ = this; +var this$ = this; +return ["Single: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.val)].join(''); +}); + +cljs.core.Single.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$val,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Single.cljs$lang$type = true; + +cljs.core.Single.cljs$lang$ctorStr = "cljs.core/Single"; + +cljs.core.Single.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Single"); +}); + +/** + * Positional factory function for cljs.core/Single. + */ +cljs.core.__GT_Single = (function cljs$core$__GT_Single(val){ +return (new cljs.core.Single(val)); +}); + + +/** +* @constructor +*/ +cljs.core.Empty = (function (){ +}); +cljs.core.Empty.prototype.add = (function (o){ +var self__ = this; +var this$ = this; +return (new cljs.core.Single(o)); +}); + +cljs.core.Empty.prototype.remove = (function (){ +var self__ = this; +var this$ = this; +throw (new Error("Removing object from empty buffer")); +}); + +cljs.core.Empty.prototype.isEmpty = (function (){ +var self__ = this; +var this$ = this; +return true; +}); + +cljs.core.Empty.prototype.toString = (function (){ +var self__ = this; +var this$ = this; +return "Empty"; +}); + +cljs.core.Empty.getBasis = (function (){ +return cljs.core.PersistentVector.EMPTY; +}); + +cljs.core.Empty.cljs$lang$type = true; + +cljs.core.Empty.cljs$lang$ctorStr = "cljs.core/Empty"; + +cljs.core.Empty.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Empty"); +}); + +/** + * Positional factory function for cljs.core/Empty. + */ +cljs.core.__GT_Empty = (function cljs$core$__GT_Empty(){ +return (new cljs.core.Empty()); +}); + +cljs.core.EMPTY = (new cljs.core.Empty()); + +/** +* @constructor +*/ +cljs.core.MultiIterator = (function (iters){ +this.iters = iters; +}); +cljs.core.MultiIterator.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +var iters__$1 = cljs.core.seq(self__.iters); +while(true){ +if((!((iters__$1 == null)))){ +var iter = cljs.core.first(iters__$1); +if((!(iter.hasNext()))){ +return false; +} else { +var G__3619 = cljs.core.next(iters__$1); +iters__$1 = G__3619; +continue; +} +} else { +return true; +} +break; +} +}); + +cljs.core.MultiIterator.prototype.next = (function (){ +var self__ = this; +var _ = this; +var nexts = []; +var n__4607__auto___3620 = self__.iters.length; +var i_3621 = (0); +while(true){ +if((i_3621 < n__4607__auto___3620)){ +(nexts[i_3621] = (self__.iters[i_3621]).next()); + +var G__3622 = (i_3621 + (1)); +i_3621 = G__3622; +continue; +} else { +} +break; +} + +return cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(nexts,(0)); +}); + +cljs.core.MultiIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$iters], null); +}); + +cljs.core.MultiIterator.cljs$lang$type = true; + +cljs.core.MultiIterator.cljs$lang$ctorStr = "cljs.core/MultiIterator"; + +cljs.core.MultiIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/MultiIterator"); +}); + +/** + * Positional factory function for cljs.core/MultiIterator. + */ +cljs.core.__GT_MultiIterator = (function cljs$core$__GT_MultiIterator(iters){ +return (new cljs.core.MultiIterator(iters)); +}); + +cljs.core.chunkIteratorSeq = (function cljs$core$chunkIteratorSeq(iter){ +return (new cljs.core.LazySeq(null,(function (){ +if(iter.hasNext()){ +var arr = []; +var n = (0); +while(true){ +if(cljs.core.truth_((function (){var and__4120__auto__ = iter.hasNext(); +if(cljs.core.truth_(and__4120__auto__)){ +return (n < (32)); +} else { +return and__4120__auto__; +} +})())){ +(arr[n] = iter.next()); + +var G__3623 = (n + (1)); +n = G__3623; +continue; +} else { +return cljs.core.chunk_cons(cljs.core.array_chunk.cljs$core$IFn$_invoke$arity$3(arr,(0),n),(cljs.core.chunkIteratorSeq.cljs$core$IFn$_invoke$arity$1 ? cljs.core.chunkIteratorSeq.cljs$core$IFn$_invoke$arity$1(iter) : cljs.core.chunkIteratorSeq.call(null,iter))); +} +break; +} +} else { +return null; +} +}),null,null)); +}); + +/** +* @constructor +*/ +cljs.core.TransformerIterator = (function (buffer,_next,completed,xf,sourceIter,multi){ +this.buffer = buffer; +this._next = _next; +this.completed = completed; +this.xf = xf; +this.sourceIter = sourceIter; +this.multi = multi; +}); +cljs.core.TransformerIterator.prototype.step = (function (){ +var self__ = this; +var this$ = this; +if((!((self__._next === cljs.core.NONE)))){ +return true; +} else { +while(true){ +if((self__._next === cljs.core.NONE)){ +if(self__.buffer.isEmpty()){ +if(self__.completed){ +return false; +} else { +if(self__.sourceIter.hasNext()){ +var iter = ((self__.multi)?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(self__.xf,cljs.core.cons(null,self__.sourceIter.next())):(function (){var G__3624 = null; +var G__3625 = self__.sourceIter.next(); +return (self__.xf.cljs$core$IFn$_invoke$arity$2 ? self__.xf.cljs$core$IFn$_invoke$arity$2(G__3624,G__3625) : self__.xf.call(null,G__3624,G__3625)); +})()); +if(cljs.core.reduced_QMARK_(iter)){ +(self__.xf.cljs$core$IFn$_invoke$arity$1 ? self__.xf.cljs$core$IFn$_invoke$arity$1(null) : self__.xf.call(null,null)); + +self__.completed = true; +} else { +} + +continue; +} else { +(self__.xf.cljs$core$IFn$_invoke$arity$1 ? self__.xf.cljs$core$IFn$_invoke$arity$1(null) : self__.xf.call(null,null)); + +self__.completed = true; + +continue; +} +} +} else { +self__._next = self__.buffer.remove(); + +continue; +} +} else { +return true; +} +break; +} +} +}); + +cljs.core.TransformerIterator.prototype.hasNext = (function (){ +var self__ = this; +var this$ = this; +return this$.step(); +}); + +cljs.core.TransformerIterator.prototype.next = (function (){ +var self__ = this; +var this$ = this; +if(this$.hasNext()){ +var ret = self__._next; +self__._next = cljs.core.NONE; + +return ret; +} else { +throw (new Error("No such element")); +} +}); + +cljs.core.TransformerIterator.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.TransformerIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 6, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$buffer,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$_next,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$completed,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$xf,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.cst$sym$sourceIter,cljs.core.cst$sym$multi], null); +}); + +cljs.core.TransformerIterator.cljs$lang$type = true; + +cljs.core.TransformerIterator.cljs$lang$ctorStr = "cljs.core/TransformerIterator"; + +cljs.core.TransformerIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/TransformerIterator"); +}); + +/** + * Positional factory function for cljs.core/TransformerIterator. + */ +cljs.core.__GT_TransformerIterator = (function cljs$core$__GT_TransformerIterator(buffer,_next,completed,xf,sourceIter,multi){ +return (new cljs.core.TransformerIterator(buffer,_next,completed,xf,sourceIter,multi)); +}); + +var G__3626_3629 = cljs.core.TransformerIterator.prototype; +var G__3627_3630 = cljs.core.ITER_SYMBOL; +var G__3628_3631 = ((function (G__3626_3629,G__3627_3630){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__3626_3629,G__3627_3630)) +; +goog.object.set(G__3626_3629,G__3627_3630,G__3628_3631); +cljs.core.transformer_iterator = (function cljs$core$transformer_iterator(xform,sourceIter,multi){ +var iterator = (new cljs.core.TransformerIterator(cljs.core.EMPTY,cljs.core.NONE,false,null,sourceIter,multi)); +iterator.xf = (function (){var G__3632 = ((function (iterator){ +return (function() { +var G__3633 = null; +var G__3633__0 = (function (){ +return null; +}); +var G__3633__1 = (function (acc){ +return acc; +}); +var G__3633__2 = (function (acc,o){ +iterator.buffer = iterator.buffer.add(o); + +return acc; +}); +G__3633 = function(acc,o){ +switch(arguments.length){ +case 0: +return G__3633__0.call(this); +case 1: +return G__3633__1.call(this,acc); +case 2: +return G__3633__2.call(this,acc,o); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3633.cljs$core$IFn$_invoke$arity$0 = G__3633__0; +G__3633.cljs$core$IFn$_invoke$arity$1 = G__3633__1; +G__3633.cljs$core$IFn$_invoke$arity$2 = G__3633__2; +return G__3633; +})() +;})(iterator)) +; +return (xform.cljs$core$IFn$_invoke$arity$1 ? xform.cljs$core$IFn$_invoke$arity$1(G__3632) : xform.call(null,G__3632)); +})(); + +return iterator; +}); +cljs.core.TransformerIterator.create = (function (xform,source){ +return cljs.core.transformer_iterator(xform,source,false); +}); +cljs.core.TransformerIterator.createMulti = (function (xform,sources){ +return cljs.core.transformer_iterator(xform,(new cljs.core.MultiIterator(cljs.core.to_array(sources))),true); +}); +/** + * Coerces coll to a (possibly empty) sequence, if it is not already + * one. Will not force a lazy seq. (sequence nil) yields (), When a + * transducer is supplied, returns a lazy sequence of applications of + * the transform to the items in coll(s), i.e. to the set of first + * items of each coll, followed by the set of second + * items in each coll, until any one of the colls is exhausted. Any + * remaining items in other colls are ignored. The transform should accept + * number-of-colls arguments + */ +cljs.core.sequence = (function cljs$core$sequence(var_args){ +var G__3638 = arguments.length; +switch (G__3638) { +case 1: +return cljs.core.sequence.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.sequence.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3640 = arguments.length; +var i__4731__auto___3641 = (0); +while(true){ +if((i__4731__auto___3641 < len__4730__auto___3640)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3641])); + +var G__3642 = (i__4731__auto___3641 + (1)); +i__4731__auto___3641 = G__3642; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.sequence.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.sequence.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +if(cljs.core.seq_QMARK_(coll)){ +return coll; +} else { +var or__4131__auto__ = cljs.core.seq(coll); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return cljs.core.List.EMPTY; +} +} +}); + +cljs.core.sequence.cljs$core$IFn$_invoke$arity$2 = (function (xform,coll){ +var or__4131__auto__ = cljs.core.chunkIteratorSeq(cljs.core.TransformerIterator.create(xform,cljs.core.iter(coll))); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.sequence.cljs$core$IFn$_invoke$arity$variadic = (function (xform,coll,colls){ +var or__4131__auto__ = cljs.core.chunkIteratorSeq(cljs.core.TransformerIterator.createMulti(xform,cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.iter,cljs.core.cons(coll,colls)))); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.List.EMPTY; +} +}); + +/** @this {Function} */ +cljs.core.sequence.cljs$lang$applyTo = (function (seq3635){ +var G__3636 = cljs.core.first(seq3635); +var seq3635__$1 = cljs.core.next(seq3635); +var G__3637 = cljs.core.first(seq3635__$1); +var seq3635__$2 = cljs.core.next(seq3635__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3636,G__3637,seq3635__$2); +}); + +cljs.core.sequence.cljs$lang$maxFixedArity = (2); + +/** + * Returns true if (pred x) is logical true for every x in coll, else + * false. + */ +cljs.core.every_QMARK_ = (function cljs$core$every_QMARK_(pred,coll){ +while(true){ +if((cljs.core.seq(coll) == null)){ +return true; +} else { +if(cljs.core.truth_((function (){var G__3643 = cljs.core.first(coll); +return (pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(G__3643) : pred.call(null,G__3643)); +})())){ +var G__3644 = pred; +var G__3645 = cljs.core.next(coll); +pred = G__3644; +coll = G__3645; +continue; +} else { +return false; + +} +} +break; +} +}); +/** + * Returns false if (pred x) is logical true for every x in + * coll, else true. + */ +cljs.core.not_every_QMARK_ = (function cljs$core$not_every_QMARK_(pred,coll){ +return (!(cljs.core.every_QMARK_(pred,coll))); +}); +/** + * Returns the first logical true value of (pred x) for any x in coll, + * else nil. One common idiom is to use a set as pred, for example + * this will return :fred if :fred is in the sequence, otherwise nil: + * (some #{:fred} coll) + */ +cljs.core.some = (function cljs$core$some(pred,coll){ +while(true){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +var or__4131__auto__ = (function (){var G__3647 = cljs.core.first(s); +return (pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(G__3647) : pred.call(null,G__3647)); +})(); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var G__3648 = pred; +var G__3649 = cljs.core.next(s); +pred = G__3648; +coll = G__3649; +continue; +} +} else { +return null; +} +break; +} +}); +/** + * Returns false if (pred x) is logical true for any x in coll, + * else true. + */ +cljs.core.not_any_QMARK_ = (function cljs$core$not_any_QMARK_(pred,coll){ +return cljs.core.not(cljs.core.some(pred,coll)); +}); +/** + * Returns true if n is even, throws an exception if n is not an integer + */ +cljs.core.even_QMARK_ = (function cljs$core$even_QMARK_(n){ +if(cljs.core.integer_QMARK_(n)){ +return ((n & (1)) === (0)); +} else { +throw (new Error(["Argument must be an integer: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(n)].join(''))); +} +}); +/** + * Returns true if n is odd, throws an exception if n is not an integer + */ +cljs.core.odd_QMARK_ = (function cljs$core$odd_QMARK_(n){ +return (!(cljs.core.even_QMARK_(n))); +}); +/** + * Takes a fn f and returns a fn that takes the same arguments as f, + * has the same effects, if any, and returns the opposite truth value. + */ +cljs.core.complement = (function cljs$core$complement(f){ +return (function() { +var G__3650 = null; +var G__3650__0 = (function (){ +return cljs.core.not((f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null))); +}); +var G__3650__1 = (function (x){ +return cljs.core.not((f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(x) : f.call(null,x))); +}); +var G__3650__2 = (function (x,y){ +return cljs.core.not((f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(x,y) : f.call(null,x,y))); +}); +var G__3650__3 = (function() { +var G__3651__delegate = function (x,y,zs){ +return cljs.core.not(cljs.core.apply.cljs$core$IFn$_invoke$arity$4(f,x,y,zs)); +}; +var G__3651 = function (x,y,var_args){ +var zs = null; +if (arguments.length > 2) { +var G__3652__i = 0, G__3652__a = new Array(arguments.length - 2); +while (G__3652__i < G__3652__a.length) {G__3652__a[G__3652__i] = arguments[G__3652__i + 2]; ++G__3652__i;} + zs = new cljs.core.IndexedSeq(G__3652__a,0,null); +} +return G__3651__delegate.call(this,x,y,zs);}; +G__3651.cljs$lang$maxFixedArity = 2; +G__3651.cljs$lang$applyTo = (function (arglist__3653){ +var x = cljs.core.first(arglist__3653); +arglist__3653 = cljs.core.next(arglist__3653); +var y = cljs.core.first(arglist__3653); +var zs = cljs.core.rest(arglist__3653); +return G__3651__delegate(x,y,zs); +}); +G__3651.cljs$core$IFn$_invoke$arity$variadic = G__3651__delegate; +return G__3651; +})() +; +G__3650 = function(x,y,var_args){ +var zs = var_args; +switch(arguments.length){ +case 0: +return G__3650__0.call(this); +case 1: +return G__3650__1.call(this,x); +case 2: +return G__3650__2.call(this,x,y); +default: +var G__3654 = null; +if (arguments.length > 2) { +var G__3655__i = 0, G__3655__a = new Array(arguments.length - 2); +while (G__3655__i < G__3655__a.length) {G__3655__a[G__3655__i] = arguments[G__3655__i + 2]; ++G__3655__i;} +G__3654 = new cljs.core.IndexedSeq(G__3655__a,0,null); +} +return G__3650__3.cljs$core$IFn$_invoke$arity$variadic(x,y, G__3654); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3650.cljs$lang$maxFixedArity = 2; +G__3650.cljs$lang$applyTo = G__3650__3.cljs$lang$applyTo; +G__3650.cljs$core$IFn$_invoke$arity$0 = G__3650__0; +G__3650.cljs$core$IFn$_invoke$arity$1 = G__3650__1; +G__3650.cljs$core$IFn$_invoke$arity$2 = G__3650__2; +G__3650.cljs$core$IFn$_invoke$arity$variadic = G__3650__3.cljs$core$IFn$_invoke$arity$variadic; +return G__3650; +})() +}); +/** + * Returns a function that takes any number of arguments and returns x. + */ +cljs.core.constantly = (function cljs$core$constantly(x){ +return (function() { +var G__3656__delegate = function (args){ +return x; +}; +var G__3656 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__3657__i = 0, G__3657__a = new Array(arguments.length - 0); +while (G__3657__i < G__3657__a.length) {G__3657__a[G__3657__i] = arguments[G__3657__i + 0]; ++G__3657__i;} + args = new cljs.core.IndexedSeq(G__3657__a,0,null); +} +return G__3656__delegate.call(this,args);}; +G__3656.cljs$lang$maxFixedArity = 0; +G__3656.cljs$lang$applyTo = (function (arglist__3658){ +var args = cljs.core.seq(arglist__3658); +return G__3656__delegate(args); +}); +G__3656.cljs$core$IFn$_invoke$arity$variadic = G__3656__delegate; +return G__3656; +})() +; +}); +/** + * Takes a set of functions and returns a fn that is the composition + * of those fns. The returned fn takes a variable number of args, + * applies the rightmost of fns to the args, the next + * fn (right-to-left) to the result, etc. + */ +cljs.core.comp = (function cljs$core$comp(var_args){ +var G__3664 = arguments.length; +switch (G__3664) { +case 0: +return cljs.core.comp.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.comp.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.comp.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.comp.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3682 = arguments.length; +var i__4731__auto___3683 = (0); +while(true){ +if((i__4731__auto___3683 < len__4730__auto___3682)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3683])); + +var G__3684 = (i__4731__auto___3683 + (1)); +i__4731__auto___3683 = G__3684; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.comp.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.comp.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.identity; +}); + +cljs.core.comp.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return f; +}); + +cljs.core.comp.cljs$core$IFn$_invoke$arity$2 = (function (f,g){ +return (function() { +var G__3685 = null; +var G__3685__0 = (function (){ +var G__3665 = (g.cljs$core$IFn$_invoke$arity$0 ? g.cljs$core$IFn$_invoke$arity$0() : g.call(null)); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3665) : f.call(null,G__3665)); +}); +var G__3685__1 = (function (x){ +var G__3666 = (g.cljs$core$IFn$_invoke$arity$1 ? g.cljs$core$IFn$_invoke$arity$1(x) : g.call(null,x)); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3666) : f.call(null,G__3666)); +}); +var G__3685__2 = (function (x,y){ +var G__3667 = (g.cljs$core$IFn$_invoke$arity$2 ? g.cljs$core$IFn$_invoke$arity$2(x,y) : g.call(null,x,y)); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3667) : f.call(null,G__3667)); +}); +var G__3685__3 = (function (x,y,z){ +var G__3668 = (g.cljs$core$IFn$_invoke$arity$3 ? g.cljs$core$IFn$_invoke$arity$3(x,y,z) : g.call(null,x,y,z)); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3668) : f.call(null,G__3668)); +}); +var G__3685__4 = (function() { +var G__3686__delegate = function (x,y,z,args){ +var G__3669 = cljs.core.apply.cljs$core$IFn$_invoke$arity$5(g,x,y,z,args); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3669) : f.call(null,G__3669)); +}; +var G__3686 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3687__i = 0, G__3687__a = new Array(arguments.length - 3); +while (G__3687__i < G__3687__a.length) {G__3687__a[G__3687__i] = arguments[G__3687__i + 3]; ++G__3687__i;} + args = new cljs.core.IndexedSeq(G__3687__a,0,null); +} +return G__3686__delegate.call(this,x,y,z,args);}; +G__3686.cljs$lang$maxFixedArity = 3; +G__3686.cljs$lang$applyTo = (function (arglist__3688){ +var x = cljs.core.first(arglist__3688); +arglist__3688 = cljs.core.next(arglist__3688); +var y = cljs.core.first(arglist__3688); +arglist__3688 = cljs.core.next(arglist__3688); +var z = cljs.core.first(arglist__3688); +var args = cljs.core.rest(arglist__3688); +return G__3686__delegate(x,y,z,args); +}); +G__3686.cljs$core$IFn$_invoke$arity$variadic = G__3686__delegate; +return G__3686; +})() +; +G__3685 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__3685__0.call(this); +case 1: +return G__3685__1.call(this,x); +case 2: +return G__3685__2.call(this,x,y); +case 3: +return G__3685__3.call(this,x,y,z); +default: +var G__3689 = null; +if (arguments.length > 3) { +var G__3690__i = 0, G__3690__a = new Array(arguments.length - 3); +while (G__3690__i < G__3690__a.length) {G__3690__a[G__3690__i] = arguments[G__3690__i + 3]; ++G__3690__i;} +G__3689 = new cljs.core.IndexedSeq(G__3690__a,0,null); +} +return G__3685__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3689); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3685.cljs$lang$maxFixedArity = 3; +G__3685.cljs$lang$applyTo = G__3685__4.cljs$lang$applyTo; +G__3685.cljs$core$IFn$_invoke$arity$0 = G__3685__0; +G__3685.cljs$core$IFn$_invoke$arity$1 = G__3685__1; +G__3685.cljs$core$IFn$_invoke$arity$2 = G__3685__2; +G__3685.cljs$core$IFn$_invoke$arity$3 = G__3685__3; +G__3685.cljs$core$IFn$_invoke$arity$variadic = G__3685__4.cljs$core$IFn$_invoke$arity$variadic; +return G__3685; +})() +}); + +cljs.core.comp.cljs$core$IFn$_invoke$arity$3 = (function (f,g,h){ +return (function() { +var G__3691 = null; +var G__3691__0 = (function (){ +var G__3670 = (function (){var G__3671 = (h.cljs$core$IFn$_invoke$arity$0 ? h.cljs$core$IFn$_invoke$arity$0() : h.call(null)); +return (g.cljs$core$IFn$_invoke$arity$1 ? g.cljs$core$IFn$_invoke$arity$1(G__3671) : g.call(null,G__3671)); +})(); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3670) : f.call(null,G__3670)); +}); +var G__3691__1 = (function (x){ +var G__3672 = (function (){var G__3673 = (h.cljs$core$IFn$_invoke$arity$1 ? h.cljs$core$IFn$_invoke$arity$1(x) : h.call(null,x)); +return (g.cljs$core$IFn$_invoke$arity$1 ? g.cljs$core$IFn$_invoke$arity$1(G__3673) : g.call(null,G__3673)); +})(); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3672) : f.call(null,G__3672)); +}); +var G__3691__2 = (function (x,y){ +var G__3674 = (function (){var G__3675 = (h.cljs$core$IFn$_invoke$arity$2 ? h.cljs$core$IFn$_invoke$arity$2(x,y) : h.call(null,x,y)); +return (g.cljs$core$IFn$_invoke$arity$1 ? g.cljs$core$IFn$_invoke$arity$1(G__3675) : g.call(null,G__3675)); +})(); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3674) : f.call(null,G__3674)); +}); +var G__3691__3 = (function (x,y,z){ +var G__3676 = (function (){var G__3677 = (h.cljs$core$IFn$_invoke$arity$3 ? h.cljs$core$IFn$_invoke$arity$3(x,y,z) : h.call(null,x,y,z)); +return (g.cljs$core$IFn$_invoke$arity$1 ? g.cljs$core$IFn$_invoke$arity$1(G__3677) : g.call(null,G__3677)); +})(); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3676) : f.call(null,G__3676)); +}); +var G__3691__4 = (function() { +var G__3692__delegate = function (x,y,z,args){ +var G__3678 = (function (){var G__3679 = cljs.core.apply.cljs$core$IFn$_invoke$arity$5(h,x,y,z,args); +return (g.cljs$core$IFn$_invoke$arity$1 ? g.cljs$core$IFn$_invoke$arity$1(G__3679) : g.call(null,G__3679)); +})(); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3678) : f.call(null,G__3678)); +}; +var G__3692 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3693__i = 0, G__3693__a = new Array(arguments.length - 3); +while (G__3693__i < G__3693__a.length) {G__3693__a[G__3693__i] = arguments[G__3693__i + 3]; ++G__3693__i;} + args = new cljs.core.IndexedSeq(G__3693__a,0,null); +} +return G__3692__delegate.call(this,x,y,z,args);}; +G__3692.cljs$lang$maxFixedArity = 3; +G__3692.cljs$lang$applyTo = (function (arglist__3694){ +var x = cljs.core.first(arglist__3694); +arglist__3694 = cljs.core.next(arglist__3694); +var y = cljs.core.first(arglist__3694); +arglist__3694 = cljs.core.next(arglist__3694); +var z = cljs.core.first(arglist__3694); +var args = cljs.core.rest(arglist__3694); +return G__3692__delegate(x,y,z,args); +}); +G__3692.cljs$core$IFn$_invoke$arity$variadic = G__3692__delegate; +return G__3692; +})() +; +G__3691 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__3691__0.call(this); +case 1: +return G__3691__1.call(this,x); +case 2: +return G__3691__2.call(this,x,y); +case 3: +return G__3691__3.call(this,x,y,z); +default: +var G__3695 = null; +if (arguments.length > 3) { +var G__3696__i = 0, G__3696__a = new Array(arguments.length - 3); +while (G__3696__i < G__3696__a.length) {G__3696__a[G__3696__i] = arguments[G__3696__i + 3]; ++G__3696__i;} +G__3695 = new cljs.core.IndexedSeq(G__3696__a,0,null); +} +return G__3691__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3695); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3691.cljs$lang$maxFixedArity = 3; +G__3691.cljs$lang$applyTo = G__3691__4.cljs$lang$applyTo; +G__3691.cljs$core$IFn$_invoke$arity$0 = G__3691__0; +G__3691.cljs$core$IFn$_invoke$arity$1 = G__3691__1; +G__3691.cljs$core$IFn$_invoke$arity$2 = G__3691__2; +G__3691.cljs$core$IFn$_invoke$arity$3 = G__3691__3; +G__3691.cljs$core$IFn$_invoke$arity$variadic = G__3691__4.cljs$core$IFn$_invoke$arity$variadic; +return G__3691; +})() +}); + +cljs.core.comp.cljs$core$IFn$_invoke$arity$variadic = (function (f1,f2,f3,fs){ +var fs__$1 = cljs.core.reverse(cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$4(f1,f2,f3,fs)); +return ((function (fs__$1){ +return (function() { +var G__3697__delegate = function (args){ +var ret = cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.first(fs__$1),args); +var fs__$2 = cljs.core.next(fs__$1); +while(true){ +if(fs__$2){ +var G__3698 = (function (){var fexpr__3680 = cljs.core.first(fs__$2); +return (fexpr__3680.cljs$core$IFn$_invoke$arity$1 ? fexpr__3680.cljs$core$IFn$_invoke$arity$1(ret) : fexpr__3680.call(null,ret)); +})(); +var G__3699 = cljs.core.next(fs__$2); +ret = G__3698; +fs__$2 = G__3699; +continue; +} else { +return ret; +} +break; +} +}; +var G__3697 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__3700__i = 0, G__3700__a = new Array(arguments.length - 0); +while (G__3700__i < G__3700__a.length) {G__3700__a[G__3700__i] = arguments[G__3700__i + 0]; ++G__3700__i;} + args = new cljs.core.IndexedSeq(G__3700__a,0,null); +} +return G__3697__delegate.call(this,args);}; +G__3697.cljs$lang$maxFixedArity = 0; +G__3697.cljs$lang$applyTo = (function (arglist__3701){ +var args = cljs.core.seq(arglist__3701); +return G__3697__delegate(args); +}); +G__3697.cljs$core$IFn$_invoke$arity$variadic = G__3697__delegate; +return G__3697; +})() +; +;})(fs__$1)) +}); + +/** @this {Function} */ +cljs.core.comp.cljs$lang$applyTo = (function (seq3660){ +var G__3661 = cljs.core.first(seq3660); +var seq3660__$1 = cljs.core.next(seq3660); +var G__3662 = cljs.core.first(seq3660__$1); +var seq3660__$2 = cljs.core.next(seq3660__$1); +var G__3663 = cljs.core.first(seq3660__$2); +var seq3660__$3 = cljs.core.next(seq3660__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3661,G__3662,G__3663,seq3660__$3); +}); + +cljs.core.comp.cljs$lang$maxFixedArity = (3); + +/** + * Takes a function f and fewer than the normal arguments to f, and + * returns a fn that takes a variable number of additional args. When + * called, the returned function calls f with args + additional args. + */ +cljs.core.partial = (function cljs$core$partial(var_args){ +var G__3708 = arguments.length; +switch (G__3708) { +case 1: +return cljs.core.partial.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.partial.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.partial.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.partial.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3710 = arguments.length; +var i__4731__auto___3711 = (0); +while(true){ +if((i__4731__auto___3711 < len__4730__auto___3710)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3711])); + +var G__3712 = (i__4731__auto___3711 + (1)); +i__4731__auto___3711 = G__3712; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((4)),(0),null)); +return cljs.core.partial.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),argseq__4752__auto__); + +} +}); + +cljs.core.partial.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return f; +}); + +cljs.core.partial.cljs$core$IFn$_invoke$arity$2 = (function (f,arg1){ +return (function() { +var G__3713 = null; +var G__3713__0 = (function (){ +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(arg1) : f.call(null,arg1)); +}); +var G__3713__1 = (function (x){ +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(arg1,x) : f.call(null,arg1,x)); +}); +var G__3713__2 = (function (x,y){ +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(arg1,x,y) : f.call(null,arg1,x,y)); +}); +var G__3713__3 = (function (x,y,z){ +return (f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(arg1,x,y,z) : f.call(null,arg1,x,y,z)); +}); +var G__3713__4 = (function() { +var G__3714__delegate = function (x,y,z,args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(f,arg1,x,y,z,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([args], 0)); +}; +var G__3714 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3715__i = 0, G__3715__a = new Array(arguments.length - 3); +while (G__3715__i < G__3715__a.length) {G__3715__a[G__3715__i] = arguments[G__3715__i + 3]; ++G__3715__i;} + args = new cljs.core.IndexedSeq(G__3715__a,0,null); +} +return G__3714__delegate.call(this,x,y,z,args);}; +G__3714.cljs$lang$maxFixedArity = 3; +G__3714.cljs$lang$applyTo = (function (arglist__3716){ +var x = cljs.core.first(arglist__3716); +arglist__3716 = cljs.core.next(arglist__3716); +var y = cljs.core.first(arglist__3716); +arglist__3716 = cljs.core.next(arglist__3716); +var z = cljs.core.first(arglist__3716); +var args = cljs.core.rest(arglist__3716); +return G__3714__delegate(x,y,z,args); +}); +G__3714.cljs$core$IFn$_invoke$arity$variadic = G__3714__delegate; +return G__3714; +})() +; +G__3713 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__3713__0.call(this); +case 1: +return G__3713__1.call(this,x); +case 2: +return G__3713__2.call(this,x,y); +case 3: +return G__3713__3.call(this,x,y,z); +default: +var G__3717 = null; +if (arguments.length > 3) { +var G__3718__i = 0, G__3718__a = new Array(arguments.length - 3); +while (G__3718__i < G__3718__a.length) {G__3718__a[G__3718__i] = arguments[G__3718__i + 3]; ++G__3718__i;} +G__3717 = new cljs.core.IndexedSeq(G__3718__a,0,null); +} +return G__3713__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3717); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3713.cljs$lang$maxFixedArity = 3; +G__3713.cljs$lang$applyTo = G__3713__4.cljs$lang$applyTo; +G__3713.cljs$core$IFn$_invoke$arity$0 = G__3713__0; +G__3713.cljs$core$IFn$_invoke$arity$1 = G__3713__1; +G__3713.cljs$core$IFn$_invoke$arity$2 = G__3713__2; +G__3713.cljs$core$IFn$_invoke$arity$3 = G__3713__3; +G__3713.cljs$core$IFn$_invoke$arity$variadic = G__3713__4.cljs$core$IFn$_invoke$arity$variadic; +return G__3713; +})() +}); + +cljs.core.partial.cljs$core$IFn$_invoke$arity$3 = (function (f,arg1,arg2){ +return (function() { +var G__3719 = null; +var G__3719__0 = (function (){ +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(arg1,arg2) : f.call(null,arg1,arg2)); +}); +var G__3719__1 = (function (x){ +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(arg1,arg2,x) : f.call(null,arg1,arg2,x)); +}); +var G__3719__2 = (function (x,y){ +return (f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(arg1,arg2,x,y) : f.call(null,arg1,arg2,x,y)); +}); +var G__3719__3 = (function (x,y,z){ +return (f.cljs$core$IFn$_invoke$arity$5 ? f.cljs$core$IFn$_invoke$arity$5(arg1,arg2,x,y,z) : f.call(null,arg1,arg2,x,y,z)); +}); +var G__3719__4 = (function() { +var G__3720__delegate = function (x,y,z,args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(f,arg1,arg2,x,y,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([z,args], 0)); +}; +var G__3720 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3721__i = 0, G__3721__a = new Array(arguments.length - 3); +while (G__3721__i < G__3721__a.length) {G__3721__a[G__3721__i] = arguments[G__3721__i + 3]; ++G__3721__i;} + args = new cljs.core.IndexedSeq(G__3721__a,0,null); +} +return G__3720__delegate.call(this,x,y,z,args);}; +G__3720.cljs$lang$maxFixedArity = 3; +G__3720.cljs$lang$applyTo = (function (arglist__3722){ +var x = cljs.core.first(arglist__3722); +arglist__3722 = cljs.core.next(arglist__3722); +var y = cljs.core.first(arglist__3722); +arglist__3722 = cljs.core.next(arglist__3722); +var z = cljs.core.first(arglist__3722); +var args = cljs.core.rest(arglist__3722); +return G__3720__delegate(x,y,z,args); +}); +G__3720.cljs$core$IFn$_invoke$arity$variadic = G__3720__delegate; +return G__3720; +})() +; +G__3719 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__3719__0.call(this); +case 1: +return G__3719__1.call(this,x); +case 2: +return G__3719__2.call(this,x,y); +case 3: +return G__3719__3.call(this,x,y,z); +default: +var G__3723 = null; +if (arguments.length > 3) { +var G__3724__i = 0, G__3724__a = new Array(arguments.length - 3); +while (G__3724__i < G__3724__a.length) {G__3724__a[G__3724__i] = arguments[G__3724__i + 3]; ++G__3724__i;} +G__3723 = new cljs.core.IndexedSeq(G__3724__a,0,null); +} +return G__3719__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3723); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3719.cljs$lang$maxFixedArity = 3; +G__3719.cljs$lang$applyTo = G__3719__4.cljs$lang$applyTo; +G__3719.cljs$core$IFn$_invoke$arity$0 = G__3719__0; +G__3719.cljs$core$IFn$_invoke$arity$1 = G__3719__1; +G__3719.cljs$core$IFn$_invoke$arity$2 = G__3719__2; +G__3719.cljs$core$IFn$_invoke$arity$3 = G__3719__3; +G__3719.cljs$core$IFn$_invoke$arity$variadic = G__3719__4.cljs$core$IFn$_invoke$arity$variadic; +return G__3719; +})() +}); + +cljs.core.partial.cljs$core$IFn$_invoke$arity$4 = (function (f,arg1,arg2,arg3){ +return (function() { +var G__3725 = null; +var G__3725__0 = (function (){ +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(arg1,arg2,arg3) : f.call(null,arg1,arg2,arg3)); +}); +var G__3725__1 = (function (x){ +return (f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(arg1,arg2,arg3,x) : f.call(null,arg1,arg2,arg3,x)); +}); +var G__3725__2 = (function (x,y){ +return (f.cljs$core$IFn$_invoke$arity$5 ? f.cljs$core$IFn$_invoke$arity$5(arg1,arg2,arg3,x,y) : f.call(null,arg1,arg2,arg3,x,y)); +}); +var G__3725__3 = (function (x,y,z){ +return (f.cljs$core$IFn$_invoke$arity$6 ? f.cljs$core$IFn$_invoke$arity$6(arg1,arg2,arg3,x,y,z) : f.call(null,arg1,arg2,arg3,x,y,z)); +}); +var G__3725__4 = (function() { +var G__3726__delegate = function (x,y,z,args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(f,arg1,arg2,arg3,x,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([y,z,args], 0)); +}; +var G__3726 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3727__i = 0, G__3727__a = new Array(arguments.length - 3); +while (G__3727__i < G__3727__a.length) {G__3727__a[G__3727__i] = arguments[G__3727__i + 3]; ++G__3727__i;} + args = new cljs.core.IndexedSeq(G__3727__a,0,null); +} +return G__3726__delegate.call(this,x,y,z,args);}; +G__3726.cljs$lang$maxFixedArity = 3; +G__3726.cljs$lang$applyTo = (function (arglist__3728){ +var x = cljs.core.first(arglist__3728); +arglist__3728 = cljs.core.next(arglist__3728); +var y = cljs.core.first(arglist__3728); +arglist__3728 = cljs.core.next(arglist__3728); +var z = cljs.core.first(arglist__3728); +var args = cljs.core.rest(arglist__3728); +return G__3726__delegate(x,y,z,args); +}); +G__3726.cljs$core$IFn$_invoke$arity$variadic = G__3726__delegate; +return G__3726; +})() +; +G__3725 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__3725__0.call(this); +case 1: +return G__3725__1.call(this,x); +case 2: +return G__3725__2.call(this,x,y); +case 3: +return G__3725__3.call(this,x,y,z); +default: +var G__3729 = null; +if (arguments.length > 3) { +var G__3730__i = 0, G__3730__a = new Array(arguments.length - 3); +while (G__3730__i < G__3730__a.length) {G__3730__a[G__3730__i] = arguments[G__3730__i + 3]; ++G__3730__i;} +G__3729 = new cljs.core.IndexedSeq(G__3730__a,0,null); +} +return G__3725__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3729); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3725.cljs$lang$maxFixedArity = 3; +G__3725.cljs$lang$applyTo = G__3725__4.cljs$lang$applyTo; +G__3725.cljs$core$IFn$_invoke$arity$0 = G__3725__0; +G__3725.cljs$core$IFn$_invoke$arity$1 = G__3725__1; +G__3725.cljs$core$IFn$_invoke$arity$2 = G__3725__2; +G__3725.cljs$core$IFn$_invoke$arity$3 = G__3725__3; +G__3725.cljs$core$IFn$_invoke$arity$variadic = G__3725__4.cljs$core$IFn$_invoke$arity$variadic; +return G__3725; +})() +}); + +cljs.core.partial.cljs$core$IFn$_invoke$arity$variadic = (function (f,arg1,arg2,arg3,more){ +return (function() { +var G__3731__delegate = function (args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,arg1,arg2,arg3,cljs.core.concat.cljs$core$IFn$_invoke$arity$2(more,args)); +}; +var G__3731 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__3732__i = 0, G__3732__a = new Array(arguments.length - 0); +while (G__3732__i < G__3732__a.length) {G__3732__a[G__3732__i] = arguments[G__3732__i + 0]; ++G__3732__i;} + args = new cljs.core.IndexedSeq(G__3732__a,0,null); +} +return G__3731__delegate.call(this,args);}; +G__3731.cljs$lang$maxFixedArity = 0; +G__3731.cljs$lang$applyTo = (function (arglist__3733){ +var args = cljs.core.seq(arglist__3733); +return G__3731__delegate(args); +}); +G__3731.cljs$core$IFn$_invoke$arity$variadic = G__3731__delegate; +return G__3731; +})() +; +}); + +/** @this {Function} */ +cljs.core.partial.cljs$lang$applyTo = (function (seq3703){ +var G__3704 = cljs.core.first(seq3703); +var seq3703__$1 = cljs.core.next(seq3703); +var G__3705 = cljs.core.first(seq3703__$1); +var seq3703__$2 = cljs.core.next(seq3703__$1); +var G__3706 = cljs.core.first(seq3703__$2); +var seq3703__$3 = cljs.core.next(seq3703__$2); +var G__3707 = cljs.core.first(seq3703__$3); +var seq3703__$4 = cljs.core.next(seq3703__$3); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3704,G__3705,G__3706,G__3707,seq3703__$4); +}); + +cljs.core.partial.cljs$lang$maxFixedArity = (4); + +/** + * Takes a function f, and returns a function that calls f, replacing + * a nil first argument to f with the supplied value x. Higher arity + * versions can replace arguments in the second and third + * positions (y, z). Note that the function f can take any number of + * arguments, not just the one(s) being nil-patched. + */ +cljs.core.fnil = (function cljs$core$fnil(var_args){ +var G__3735 = arguments.length; +switch (G__3735) { +case 2: +return cljs.core.fnil.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.fnil.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.fnil.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.fnil.cljs$core$IFn$_invoke$arity$2 = (function (f,x){ +return (function() { +var G__3753 = null; +var G__3753__1 = (function (a){ +var G__3736 = (((a == null))?x:a); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3736) : f.call(null,G__3736)); +}); +var G__3753__2 = (function (a,b){ +var G__3737 = (((a == null))?x:a); +var G__3738 = b; +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3737,G__3738) : f.call(null,G__3737,G__3738)); +}); +var G__3753__3 = (function (a,b,c){ +var G__3739 = (((a == null))?x:a); +var G__3740 = b; +var G__3741 = c; +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__3739,G__3740,G__3741) : f.call(null,G__3739,G__3740,G__3741)); +}); +var G__3753__4 = (function() { +var G__3754__delegate = function (a,b,c,ds){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,(((a == null))?x:a),b,c,ds); +}; +var G__3754 = function (a,b,c,var_args){ +var ds = null; +if (arguments.length > 3) { +var G__3755__i = 0, G__3755__a = new Array(arguments.length - 3); +while (G__3755__i < G__3755__a.length) {G__3755__a[G__3755__i] = arguments[G__3755__i + 3]; ++G__3755__i;} + ds = new cljs.core.IndexedSeq(G__3755__a,0,null); +} +return G__3754__delegate.call(this,a,b,c,ds);}; +G__3754.cljs$lang$maxFixedArity = 3; +G__3754.cljs$lang$applyTo = (function (arglist__3756){ +var a = cljs.core.first(arglist__3756); +arglist__3756 = cljs.core.next(arglist__3756); +var b = cljs.core.first(arglist__3756); +arglist__3756 = cljs.core.next(arglist__3756); +var c = cljs.core.first(arglist__3756); +var ds = cljs.core.rest(arglist__3756); +return G__3754__delegate(a,b,c,ds); +}); +G__3754.cljs$core$IFn$_invoke$arity$variadic = G__3754__delegate; +return G__3754; +})() +; +G__3753 = function(a,b,c,var_args){ +var ds = var_args; +switch(arguments.length){ +case 1: +return G__3753__1.call(this,a); +case 2: +return G__3753__2.call(this,a,b); +case 3: +return G__3753__3.call(this,a,b,c); +default: +var G__3757 = null; +if (arguments.length > 3) { +var G__3758__i = 0, G__3758__a = new Array(arguments.length - 3); +while (G__3758__i < G__3758__a.length) {G__3758__a[G__3758__i] = arguments[G__3758__i + 3]; ++G__3758__i;} +G__3757 = new cljs.core.IndexedSeq(G__3758__a,0,null); +} +return G__3753__4.cljs$core$IFn$_invoke$arity$variadic(a,b,c, G__3757); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3753.cljs$lang$maxFixedArity = 3; +G__3753.cljs$lang$applyTo = G__3753__4.cljs$lang$applyTo; +G__3753.cljs$core$IFn$_invoke$arity$1 = G__3753__1; +G__3753.cljs$core$IFn$_invoke$arity$2 = G__3753__2; +G__3753.cljs$core$IFn$_invoke$arity$3 = G__3753__3; +G__3753.cljs$core$IFn$_invoke$arity$variadic = G__3753__4.cljs$core$IFn$_invoke$arity$variadic; +return G__3753; +})() +}); + +cljs.core.fnil.cljs$core$IFn$_invoke$arity$3 = (function (f,x,y){ +return (function() { +var G__3759 = null; +var G__3759__2 = (function (a,b){ +var G__3742 = (((a == null))?x:a); +var G__3743 = (((b == null))?y:b); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3742,G__3743) : f.call(null,G__3742,G__3743)); +}); +var G__3759__3 = (function (a,b,c){ +var G__3744 = (((a == null))?x:a); +var G__3745 = (((b == null))?y:b); +var G__3746 = c; +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__3744,G__3745,G__3746) : f.call(null,G__3744,G__3745,G__3746)); +}); +var G__3759__4 = (function() { +var G__3760__delegate = function (a,b,c,ds){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,(((a == null))?x:a),(((b == null))?y:b),c,ds); +}; +var G__3760 = function (a,b,c,var_args){ +var ds = null; +if (arguments.length > 3) { +var G__3761__i = 0, G__3761__a = new Array(arguments.length - 3); +while (G__3761__i < G__3761__a.length) {G__3761__a[G__3761__i] = arguments[G__3761__i + 3]; ++G__3761__i;} + ds = new cljs.core.IndexedSeq(G__3761__a,0,null); +} +return G__3760__delegate.call(this,a,b,c,ds);}; +G__3760.cljs$lang$maxFixedArity = 3; +G__3760.cljs$lang$applyTo = (function (arglist__3762){ +var a = cljs.core.first(arglist__3762); +arglist__3762 = cljs.core.next(arglist__3762); +var b = cljs.core.first(arglist__3762); +arglist__3762 = cljs.core.next(arglist__3762); +var c = cljs.core.first(arglist__3762); +var ds = cljs.core.rest(arglist__3762); +return G__3760__delegate(a,b,c,ds); +}); +G__3760.cljs$core$IFn$_invoke$arity$variadic = G__3760__delegate; +return G__3760; +})() +; +G__3759 = function(a,b,c,var_args){ +var ds = var_args; +switch(arguments.length){ +case 2: +return G__3759__2.call(this,a,b); +case 3: +return G__3759__3.call(this,a,b,c); +default: +var G__3763 = null; +if (arguments.length > 3) { +var G__3764__i = 0, G__3764__a = new Array(arguments.length - 3); +while (G__3764__i < G__3764__a.length) {G__3764__a[G__3764__i] = arguments[G__3764__i + 3]; ++G__3764__i;} +G__3763 = new cljs.core.IndexedSeq(G__3764__a,0,null); +} +return G__3759__4.cljs$core$IFn$_invoke$arity$variadic(a,b,c, G__3763); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3759.cljs$lang$maxFixedArity = 3; +G__3759.cljs$lang$applyTo = G__3759__4.cljs$lang$applyTo; +G__3759.cljs$core$IFn$_invoke$arity$2 = G__3759__2; +G__3759.cljs$core$IFn$_invoke$arity$3 = G__3759__3; +G__3759.cljs$core$IFn$_invoke$arity$variadic = G__3759__4.cljs$core$IFn$_invoke$arity$variadic; +return G__3759; +})() +}); + +cljs.core.fnil.cljs$core$IFn$_invoke$arity$4 = (function (f,x,y,z){ +return (function() { +var G__3765 = null; +var G__3765__2 = (function (a,b){ +var G__3747 = (((a == null))?x:a); +var G__3748 = (((b == null))?y:b); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3747,G__3748) : f.call(null,G__3747,G__3748)); +}); +var G__3765__3 = (function (a,b,c){ +var G__3749 = (((a == null))?x:a); +var G__3750 = (((b == null))?y:b); +var G__3751 = (((c == null))?z:c); +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__3749,G__3750,G__3751) : f.call(null,G__3749,G__3750,G__3751)); +}); +var G__3765__4 = (function() { +var G__3766__delegate = function (a,b,c,ds){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,(((a == null))?x:a),(((b == null))?y:b),(((c == null))?z:c),ds); +}; +var G__3766 = function (a,b,c,var_args){ +var ds = null; +if (arguments.length > 3) { +var G__3767__i = 0, G__3767__a = new Array(arguments.length - 3); +while (G__3767__i < G__3767__a.length) {G__3767__a[G__3767__i] = arguments[G__3767__i + 3]; ++G__3767__i;} + ds = new cljs.core.IndexedSeq(G__3767__a,0,null); +} +return G__3766__delegate.call(this,a,b,c,ds);}; +G__3766.cljs$lang$maxFixedArity = 3; +G__3766.cljs$lang$applyTo = (function (arglist__3768){ +var a = cljs.core.first(arglist__3768); +arglist__3768 = cljs.core.next(arglist__3768); +var b = cljs.core.first(arglist__3768); +arglist__3768 = cljs.core.next(arglist__3768); +var c = cljs.core.first(arglist__3768); +var ds = cljs.core.rest(arglist__3768); +return G__3766__delegate(a,b,c,ds); +}); +G__3766.cljs$core$IFn$_invoke$arity$variadic = G__3766__delegate; +return G__3766; +})() +; +G__3765 = function(a,b,c,var_args){ +var ds = var_args; +switch(arguments.length){ +case 2: +return G__3765__2.call(this,a,b); +case 3: +return G__3765__3.call(this,a,b,c); +default: +var G__3769 = null; +if (arguments.length > 3) { +var G__3770__i = 0, G__3770__a = new Array(arguments.length - 3); +while (G__3770__i < G__3770__a.length) {G__3770__a[G__3770__i] = arguments[G__3770__i + 3]; ++G__3770__i;} +G__3769 = new cljs.core.IndexedSeq(G__3770__a,0,null); +} +return G__3765__4.cljs$core$IFn$_invoke$arity$variadic(a,b,c, G__3769); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3765.cljs$lang$maxFixedArity = 3; +G__3765.cljs$lang$applyTo = G__3765__4.cljs$lang$applyTo; +G__3765.cljs$core$IFn$_invoke$arity$2 = G__3765__2; +G__3765.cljs$core$IFn$_invoke$arity$3 = G__3765__3; +G__3765.cljs$core$IFn$_invoke$arity$variadic = G__3765__4.cljs$core$IFn$_invoke$arity$variadic; +return G__3765; +})() +}); + +cljs.core.fnil.cljs$lang$maxFixedArity = 4; + +/** + * Returns a lazy sequence consisting of the result of applying f to 0 + * and the first item of coll, followed by applying f to 1 and the second + * item in coll, etc, until coll is exhausted. Thus function f should + * accept 2 arguments, index and item. Returns a stateful transducer when + * no collection is provided. + */ +cljs.core.map_indexed = (function cljs$core$map_indexed(var_args){ +var G__3772 = arguments.length; +switch (G__3772) { +case 1: +return cljs.core.map_indexed.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.map_indexed.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.map_indexed.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return (function (rf){ +var i = cljs.core.volatile_BANG_((-1)); +return ((function (i){ +return (function() { +var G__3786 = null; +var G__3786__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__3786__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__3786__2 = (function (result,input){ +var G__3773 = result; +var G__3774 = (function (){var G__3775 = i.cljs$core$IVolatile$_vreset_BANG_$arity$2(null,(i.cljs$core$IDeref$_deref$arity$1(null) + (1))); +var G__3776 = input; +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3775,G__3776) : f.call(null,G__3775,G__3776)); +})(); +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(G__3773,G__3774) : rf.call(null,G__3773,G__3774)); +}); +G__3786 = function(result,input){ +switch(arguments.length){ +case 0: +return G__3786__0.call(this); +case 1: +return G__3786__1.call(this,result); +case 2: +return G__3786__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3786.cljs$core$IFn$_invoke$arity$0 = G__3786__0; +G__3786.cljs$core$IFn$_invoke$arity$1 = G__3786__1; +G__3786.cljs$core$IFn$_invoke$arity$2 = G__3786__2; +return G__3786; +})() +;})(i)) +}); +}); + +cljs.core.map_indexed.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +var mapi = (function cljs$core$mapi(idx,coll__$1){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll__$1); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(s)){ +var c = cljs.core.chunk_first(s); +var size = cljs.core.count(c); +var b = cljs.core.chunk_buffer(size); +var n__4607__auto___3787 = size; +var i_3788 = (0); +while(true){ +if((i_3788 < n__4607__auto___3787)){ +cljs.core.chunk_append(b,(function (){var G__3781 = (idx + i_3788); +var G__3782 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(c,i_3788); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3781,G__3782) : f.call(null,G__3781,G__3782)); +})()); + +var G__3789 = (i_3788 + (1)); +i_3788 = G__3789; +continue; +} else { +} +break; +} + +return cljs.core.chunk_cons(cljs.core.chunk(b),cljs$core$mapi((idx + size),cljs.core.chunk_rest(s))); +} else { +return cljs.core.cons((function (){var G__3783 = idx; +var G__3784 = cljs.core.first(s); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3783,G__3784) : f.call(null,G__3783,G__3784)); +})(),cljs$core$mapi((idx + (1)),cljs.core.rest(s))); +} +} else { +return null; +} +}),null,null)); +}); +return mapi((0),coll); +}); + +cljs.core.map_indexed.cljs$lang$maxFixedArity = 2; + +/** + * Returns a lazy sequence of the non-nil results of (f item). Note, + * this means false return values will be included. f must be free of + * side-effects. Returns a transducer when no collection is provided. + */ +cljs.core.keep = (function cljs$core$keep(var_args){ +var G__3791 = arguments.length; +switch (G__3791) { +case 1: +return cljs.core.keep.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.keep.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.keep.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return (function (rf){ +return (function() { +var G__3795 = null; +var G__3795__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__3795__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__3795__2 = (function (result,input){ +var v = (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(input) : f.call(null,input)); +if((v == null)){ +return result; +} else { +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,v) : rf.call(null,result,v)); +} +}); +G__3795 = function(result,input){ +switch(arguments.length){ +case 0: +return G__3795__0.call(this); +case 1: +return G__3795__1.call(this,result); +case 2: +return G__3795__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3795.cljs$core$IFn$_invoke$arity$0 = G__3795__0; +G__3795.cljs$core$IFn$_invoke$arity$1 = G__3795__1; +G__3795.cljs$core$IFn$_invoke$arity$2 = G__3795__2; +return G__3795; +})() +}); +}); + +cljs.core.keep.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(s)){ +var c = cljs.core.chunk_first(s); +var size = cljs.core.count(c); +var b = cljs.core.chunk_buffer(size); +var n__4607__auto___3796 = size; +var i_3797 = (0); +while(true){ +if((i_3797 < n__4607__auto___3796)){ +var x_3798 = (function (){var G__3792 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(c,i_3797); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3792) : f.call(null,G__3792)); +})(); +if((x_3798 == null)){ +} else { +cljs.core.chunk_append(b,x_3798); +} + +var G__3799 = (i_3797 + (1)); +i_3797 = G__3799; +continue; +} else { +} +break; +} + +return cljs.core.chunk_cons(cljs.core.chunk(b),cljs.core.keep.cljs$core$IFn$_invoke$arity$2(f,cljs.core.chunk_rest(s))); +} else { +var x = (function (){var G__3793 = cljs.core.first(s); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3793) : f.call(null,G__3793)); +})(); +if((x == null)){ +return cljs.core.keep.cljs$core$IFn$_invoke$arity$2(f,cljs.core.rest(s)); +} else { +return cljs.core.cons(x,cljs.core.keep.cljs$core$IFn$_invoke$arity$2(f,cljs.core.rest(s))); +} +} +} else { +return null; +} +}),null,null)); +}); + +cljs.core.keep.cljs$lang$maxFixedArity = 2; + + +/** +* @constructor + * @implements {cljs.core.IWatchable} + * @implements {cljs.core.IAtom} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IDeref} +*/ +cljs.core.Atom = (function (state,meta,validator,watches){ +this.state = state; +this.meta = meta; +this.validator = validator; +this.watches = watches; +this.cljs$lang$protocol_mask$partition1$ = 16386; +this.cljs$lang$protocol_mask$partition0$ = 6455296; +}); +cljs.core.Atom.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.Atom.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (o,other){ +var self__ = this; +var o__$1 = this; +return (o__$1 === other); +}); + +cljs.core.Atom.prototype.cljs$core$IDeref$_deref$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.state; +}); + +cljs.core.Atom.prototype.cljs$core$IMeta$_meta$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.meta; +}); + +cljs.core.Atom.prototype.cljs$core$IWatchable$_notify_watches$arity$3 = (function (this$,oldval,newval){ +var self__ = this; +var this$__$1 = this; +var seq__3800 = cljs.core.seq(self__.watches); +var chunk__3801 = null; +var count__3802 = (0); +var i__3803 = (0); +while(true){ +if((i__3803 < count__3802)){ +var vec__3810 = chunk__3801.cljs$core$IIndexed$_nth$arity$2(null,i__3803); +var key = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__3810,(0),null); +var f = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__3810,(1),null); +(f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(key,this$__$1,oldval,newval) : f.call(null,key,this$__$1,oldval,newval)); + + +var G__3816 = seq__3800; +var G__3817 = chunk__3801; +var G__3818 = count__3802; +var G__3819 = (i__3803 + (1)); +seq__3800 = G__3816; +chunk__3801 = G__3817; +count__3802 = G__3818; +i__3803 = G__3819; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__3800); +if(temp__5735__auto__){ +var seq__3800__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__3800__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__3800__$1); +var G__3820 = cljs.core.chunk_rest(seq__3800__$1); +var G__3821 = c__4550__auto__; +var G__3822 = cljs.core.count(c__4550__auto__); +var G__3823 = (0); +seq__3800 = G__3820; +chunk__3801 = G__3821; +count__3802 = G__3822; +i__3803 = G__3823; +continue; +} else { +var vec__3813 = cljs.core.first(seq__3800__$1); +var key = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__3813,(0),null); +var f = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__3813,(1),null); +(f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(key,this$__$1,oldval,newval) : f.call(null,key,this$__$1,oldval,newval)); + + +var G__3824 = cljs.core.next(seq__3800__$1); +var G__3825 = null; +var G__3826 = (0); +var G__3827 = (0); +seq__3800 = G__3824; +chunk__3801 = G__3825; +count__3802 = G__3826; +i__3803 = G__3827; +continue; +} +} else { +return null; +} +} +break; +} +}); + +cljs.core.Atom.prototype.cljs$core$IWatchable$_add_watch$arity$3 = (function (this$,key,f){ +var self__ = this; +var this$__$1 = this; +this$__$1.watches = cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(self__.watches,key,f); + +return this$__$1; +}); + +cljs.core.Atom.prototype.cljs$core$IWatchable$_remove_watch$arity$2 = (function (this$,key){ +var self__ = this; +var this$__$1 = this; +return this$__$1.watches = cljs.core.dissoc.cljs$core$IFn$_invoke$arity$2(self__.watches,key); +}); + +cljs.core.Atom.prototype.cljs$core$IHash$_hash$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return goog.getUid(this$__$1); +}); + +cljs.core.Atom.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$state,cljs.core.cst$sym$meta,cljs.core.cst$sym$validator,cljs.core.cst$sym$watches], null); +}); + +cljs.core.Atom.cljs$lang$type = true; + +cljs.core.Atom.cljs$lang$ctorStr = "cljs.core/Atom"; + +cljs.core.Atom.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Atom"); +}); + +/** + * Positional factory function for cljs.core/Atom. + */ +cljs.core.__GT_Atom = (function cljs$core$__GT_Atom(state,meta,validator,watches){ +return (new cljs.core.Atom(state,meta,validator,watches)); +}); + +/** + * Creates and returns an Atom with an initial value of x and zero or + * more options (in any order): + * + * :meta metadata-map + * + * :validator validate-fn + * + * If metadata-map is supplied, it will become the metadata on the + * atom. validate-fn must be nil or a side-effect-free fn of one + * argument, which will be passed the intended new state on any state + * change. If the new state is unacceptable, the validate-fn should + * return false or throw an Error. If either of these error conditions + * occur, then the value of the atom will not change. + */ +cljs.core.atom = (function cljs$core$atom(var_args){ +var G__3831 = arguments.length; +switch (G__3831) { +case 1: +return cljs.core.atom.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3836 = arguments.length; +var i__4731__auto___3837 = (0); +while(true){ +if((i__4731__auto___3837 < len__4730__auto___3836)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3837])); + +var G__3838 = (i__4731__auto___3837 + (1)); +i__4731__auto___3837 = G__3838; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((1)),(0),null)); +return cljs.core.atom.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4752__auto__); + +} +}); + +cljs.core.atom.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return (new cljs.core.Atom(x,null,null,null)); +}); + +cljs.core.atom.cljs$core$IFn$_invoke$arity$variadic = (function (x,p__3832){ +var map__3833 = p__3832; +var map__3833__$1 = (((((!((map__3833 == null))))?(((((map__3833.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__3833.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__3833):map__3833); +var meta = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__3833__$1,cljs.core.cst$kw$meta); +var validator = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__3833__$1,cljs.core.cst$kw$validator); +return (new cljs.core.Atom(x,meta,validator,null)); +}); + +/** @this {Function} */ +cljs.core.atom.cljs$lang$applyTo = (function (seq3829){ +var G__3830 = cljs.core.first(seq3829); +var seq3829__$1 = cljs.core.next(seq3829); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3830,seq3829__$1); +}); + +cljs.core.atom.cljs$lang$maxFixedArity = (1); + +/** + * Sets the value of atom to newval without regard for the + * current value. Returns new-value. + */ +cljs.core.reset_BANG_ = (function cljs$core$reset_BANG_(a,new_value){ +if((a instanceof cljs.core.Atom)){ +var validate = a.validator; +if((validate == null)){ +} else { +if(cljs.core.truth_((validate.cljs$core$IFn$_invoke$arity$1 ? validate.cljs$core$IFn$_invoke$arity$1(new_value) : validate.call(null,new_value)))){ +} else { +throw (new Error("Validator rejected reference state")); +} +} + +var old_value = a.state; +a.state = new_value; + +if((a.watches == null)){ +} else { +a.cljs$core$IWatchable$_notify_watches$arity$3(null,old_value,new_value); +} + +return new_value; +} else { +return cljs.core._reset_BANG_(a,new_value); +} +}); +/** + * Sets the value of atom to newval. Returns [old new], the value of the + * atom before and after the reset. + */ +cljs.core.reset_vals_BANG_ = (function cljs$core$reset_vals_BANG_(a,new_value){ +var validate = a.validator; +if((validate == null)){ +} else { +if(cljs.core.truth_((validate.cljs$core$IFn$_invoke$arity$1 ? validate.cljs$core$IFn$_invoke$arity$1(new_value) : validate.call(null,new_value)))){ +} else { +throw (new Error("Validator rejected reference state")); +} +} + +var old_value = a.state; +a.state = new_value; + +if((a.watches == null)){ +} else { +cljs.core._notify_watches(a,old_value,new_value); +} + +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [old_value,new_value], null); +}); +/** + * Atomically swaps the value of atom to be: + * (apply f current-value-of-atom args). Note that f may be called + * multiple times, and thus should be free of side effects. Returns + * the value that was swapped in. + */ +cljs.core.swap_BANG_ = (function cljs$core$swap_BANG_(var_args){ +var G__3845 = arguments.length; +switch (G__3845) { +case 2: +return cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3853 = arguments.length; +var i__4731__auto___3854 = (0); +while(true){ +if((i__4731__auto___3854 < len__4730__auto___3853)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3854])); + +var G__3855 = (i__4731__auto___3854 + (1)); +i__4731__auto___3854 = G__3855; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((4)),(0),null)); +return cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),argseq__4752__auto__); + +} +}); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2 = (function (a,f){ +if((a instanceof cljs.core.Atom)){ +return cljs.core.reset_BANG_(a,(function (){var G__3846 = a.state; +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3846) : f.call(null,G__3846)); +})()); +} else { +return cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$2(a,f); +} +}); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3 = (function (a,f,x){ +if((a instanceof cljs.core.Atom)){ +return cljs.core.reset_BANG_(a,(function (){var G__3847 = a.state; +var G__3848 = x; +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3847,G__3848) : f.call(null,G__3847,G__3848)); +})()); +} else { +return cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$3(a,f,x); +} +}); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4 = (function (a,f,x,y){ +if((a instanceof cljs.core.Atom)){ +return cljs.core.reset_BANG_(a,(function (){var G__3849 = a.state; +var G__3850 = x; +var G__3851 = y; +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__3849,G__3850,G__3851) : f.call(null,G__3849,G__3850,G__3851)); +})()); +} else { +return cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$4(a,f,x,y); +} +}); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (a,f,x,y,more){ +if((a instanceof cljs.core.Atom)){ +return cljs.core.reset_BANG_(a,cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,a.state,x,y,more)); +} else { +return cljs.core._swap_BANG_.cljs$core$IFn$_invoke$arity$5(a,f,x,y,more); +} +}); + +/** @this {Function} */ +cljs.core.swap_BANG_.cljs$lang$applyTo = (function (seq3840){ +var G__3841 = cljs.core.first(seq3840); +var seq3840__$1 = cljs.core.next(seq3840); +var G__3842 = cljs.core.first(seq3840__$1); +var seq3840__$2 = cljs.core.next(seq3840__$1); +var G__3843 = cljs.core.first(seq3840__$2); +var seq3840__$3 = cljs.core.next(seq3840__$2); +var G__3844 = cljs.core.first(seq3840__$3); +var seq3840__$4 = cljs.core.next(seq3840__$3); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3841,G__3842,G__3843,G__3844,seq3840__$4); +}); + +cljs.core.swap_BANG_.cljs$lang$maxFixedArity = (4); + +/** + * Atomically swaps the value of atom to be: + * (apply f current-value-of-atom args). Note that f may be called + * multiple times, and thus should be free of side effects. + * Returns [old new], the value of the atom before and after the swap. + */ +cljs.core.swap_vals_BANG_ = (function cljs$core$swap_vals_BANG_(var_args){ +var G__3862 = arguments.length; +switch (G__3862) { +case 2: +return cljs.core.swap_vals_BANG_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.swap_vals_BANG_.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.swap_vals_BANG_.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3870 = arguments.length; +var i__4731__auto___3871 = (0); +while(true){ +if((i__4731__auto___3871 < len__4730__auto___3870)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3871])); + +var G__3872 = (i__4731__auto___3871 + (1)); +i__4731__auto___3871 = G__3872; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((4)),(0),null)); +return cljs.core.swap_vals_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),argseq__4752__auto__); + +} +}); + +cljs.core.swap_vals_BANG_.cljs$core$IFn$_invoke$arity$2 = (function (a,f){ +return cljs.core.reset_vals_BANG_(a,(function (){var G__3863 = a.state; +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3863) : f.call(null,G__3863)); +})()); +}); + +cljs.core.swap_vals_BANG_.cljs$core$IFn$_invoke$arity$3 = (function (a,f,x){ +return cljs.core.reset_vals_BANG_(a,(function (){var G__3864 = a.state; +var G__3865 = x; +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3864,G__3865) : f.call(null,G__3864,G__3865)); +})()); +}); + +cljs.core.swap_vals_BANG_.cljs$core$IFn$_invoke$arity$4 = (function (a,f,x,y){ +return cljs.core.reset_vals_BANG_(a,(function (){var G__3866 = a.state; +var G__3867 = x; +var G__3868 = y; +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__3866,G__3867,G__3868) : f.call(null,G__3866,G__3867,G__3868)); +})()); +}); + +cljs.core.swap_vals_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (a,f,x,y,more){ +return cljs.core.reset_vals_BANG_(a,cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,a.state,x,y,more)); +}); + +/** @this {Function} */ +cljs.core.swap_vals_BANG_.cljs$lang$applyTo = (function (seq3857){ +var G__3858 = cljs.core.first(seq3857); +var seq3857__$1 = cljs.core.next(seq3857); +var G__3859 = cljs.core.first(seq3857__$1); +var seq3857__$2 = cljs.core.next(seq3857__$1); +var G__3860 = cljs.core.first(seq3857__$2); +var seq3857__$3 = cljs.core.next(seq3857__$2); +var G__3861 = cljs.core.first(seq3857__$3); +var seq3857__$4 = cljs.core.next(seq3857__$3); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3858,G__3859,G__3860,G__3861,seq3857__$4); +}); + +cljs.core.swap_vals_BANG_.cljs$lang$maxFixedArity = (4); + +/** + * Atomically sets the value of atom to newval if and only if the + * current value of the atom is equal to oldval. Returns true if + * set happened, else false. + */ +cljs.core.compare_and_set_BANG_ = (function cljs$core$compare_and_set_BANG_(a,oldval,newval){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(a.cljs$core$IDeref$_deref$arity$1(null),oldval)){ +cljs.core.reset_BANG_(a,newval); + +return true; +} else { +return false; +} +}); +/** + * Sets the validator-fn for an atom. validator-fn must be nil or a + * side-effect-free fn of one argument, which will be passed the intended + * new state on any state change. If the new state is unacceptable, the + * validator-fn should return false or throw an Error. If the current state + * is not acceptable to the new validator, an Error will be thrown and the + * validator will not be changed. + */ +cljs.core.set_validator_BANG_ = (function cljs$core$set_validator_BANG_(iref,val){ +if((((!((val == null)))) && (cljs.core.not((function (){var G__3874 = cljs.core._deref(iref); +return (val.cljs$core$IFn$_invoke$arity$1 ? val.cljs$core$IFn$_invoke$arity$1(G__3874) : val.call(null,G__3874)); +})())))){ +throw (new Error("Validator rejected reference state")); +} else { +} + +return iref.validator = val; +}); +/** + * Gets the validator-fn for a var/ref/agent/atom. + */ +cljs.core.get_validator = (function cljs$core$get_validator(iref){ +return iref.validator; +}); + +/** +* @constructor + * @implements {cljs.core.IVolatile} + * @implements {cljs.core.IDeref} +*/ +cljs.core.Volatile = (function (state){ +this.state = state; +this.cljs$lang$protocol_mask$partition0$ = 32768; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.Volatile.prototype.cljs$core$IVolatile$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Volatile.prototype.cljs$core$IVolatile$_vreset_BANG_$arity$2 = (function (_,new_state){ +var self__ = this; +var ___$1 = this; +return self__.state = new_state; +}); + +cljs.core.Volatile.prototype.cljs$core$IDeref$_deref$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return self__.state; +}); + +cljs.core.Volatile.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$state,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Volatile.cljs$lang$type = true; + +cljs.core.Volatile.cljs$lang$ctorStr = "cljs.core/Volatile"; + +cljs.core.Volatile.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Volatile"); +}); + +/** + * Positional factory function for cljs.core/Volatile. + */ +cljs.core.__GT_Volatile = (function cljs$core$__GT_Volatile(state){ +return (new cljs.core.Volatile(state)); +}); + +/** + * Creates and returns a Volatile with an initial value of val. + */ +cljs.core.volatile_BANG_ = (function cljs$core$volatile_BANG_(val){ +return (new cljs.core.Volatile(val)); +}); +/** + * Returns true if x is a volatile. + */ +cljs.core.volatile_QMARK_ = (function cljs$core$volatile_QMARK_(x){ +return (x instanceof cljs.core.Volatile); +}); +/** + * Sets the value of volatile to newval without regard for the + * current value. Returns newval. + */ +cljs.core.vreset_BANG_ = (function cljs$core$vreset_BANG_(vol,newval){ +return cljs.core._vreset_BANG_(vol,newval); +}); +/** + * Returns a lazy sequence of the non-nil results of (f index item). Note, + * this means false return values will be included. f must be free of + * side-effects. Returns a stateful transducer when no collection is + * provided. + */ +cljs.core.keep_indexed = (function cljs$core$keep_indexed(var_args){ +var G__3876 = arguments.length; +switch (G__3876) { +case 1: +return cljs.core.keep_indexed.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.keep_indexed.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.keep_indexed.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return (function (rf){ +var ia = cljs.core.volatile_BANG_((-1)); +return ((function (ia){ +return (function() { +var G__3886 = null; +var G__3886__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__3886__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__3886__2 = (function (result,input){ +var i = ia.cljs$core$IVolatile$_vreset_BANG_$arity$2(null,(ia.cljs$core$IDeref$_deref$arity$1(null) + (1))); +var v = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(i,input) : f.call(null,i,input)); +if((v == null)){ +return result; +} else { +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,v) : rf.call(null,result,v)); +} +}); +G__3886 = function(result,input){ +switch(arguments.length){ +case 0: +return G__3886__0.call(this); +case 1: +return G__3886__1.call(this,result); +case 2: +return G__3886__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3886.cljs$core$IFn$_invoke$arity$0 = G__3886__0; +G__3886.cljs$core$IFn$_invoke$arity$1 = G__3886__1; +G__3886.cljs$core$IFn$_invoke$arity$2 = G__3886__2; +return G__3886; +})() +;})(ia)) +}); +}); + +cljs.core.keep_indexed.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +var keepi = (function cljs$core$keepi(idx,coll__$1){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll__$1); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(s)){ +var c = cljs.core.chunk_first(s); +var size = cljs.core.count(c); +var b = cljs.core.chunk_buffer(size); +var n__4607__auto___3887 = size; +var i_3888 = (0); +while(true){ +if((i_3888 < n__4607__auto___3887)){ +var x_3889 = (function (){var G__3881 = (idx + i_3888); +var G__3882 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(c,i_3888); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3881,G__3882) : f.call(null,G__3881,G__3882)); +})(); +if((x_3889 == null)){ +} else { +cljs.core.chunk_append(b,x_3889); +} + +var G__3890 = (i_3888 + (1)); +i_3888 = G__3890; +continue; +} else { +} +break; +} + +return cljs.core.chunk_cons(cljs.core.chunk(b),cljs$core$keepi((idx + size),cljs.core.chunk_rest(s))); +} else { +var x = (function (){var G__3883 = idx; +var G__3884 = cljs.core.first(s); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3883,G__3884) : f.call(null,G__3883,G__3884)); +})(); +if((x == null)){ +return cljs$core$keepi((idx + (1)),cljs.core.rest(s)); +} else { +return cljs.core.cons(x,cljs$core$keepi((idx + (1)),cljs.core.rest(s))); +} +} +} else { +return null; +} +}),null,null)); +}); +return keepi((0),coll); +}); + +cljs.core.keep_indexed.cljs$lang$maxFixedArity = 2; + +/** + * Takes a set of predicates and returns a function f that returns true if all of its + * composing predicates return a logical true value against all of its arguments, else it returns + * false. Note that f is short-circuiting in that it will stop execution on the first + * argument that triggers a logical false result against the original predicates. + */ +cljs.core.every_pred = (function cljs$core$every_pred(var_args){ +var G__3902 = arguments.length; +switch (G__3902) { +case 1: +return cljs.core.every_pred.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.every_pred.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.every_pred.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3904 = arguments.length; +var i__4731__auto___3905 = (0); +while(true){ +if((i__4731__auto___3905 < len__4730__auto___3904)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3905])); + +var G__3906 = (i__4731__auto___3905 + (1)); +i__4731__auto___3905 = G__3906; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.every_pred.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.every_pred.cljs$core$IFn$_invoke$arity$1 = (function (p){ +return (function() { +var cljs$core$ep1 = null; +var cljs$core$ep1__0 = (function (){ +return true; +}); +var cljs$core$ep1__1 = (function (x){ +return cljs.core.boolean$((p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(x) : p.call(null,x))); +}); +var cljs$core$ep1__2 = (function (x,y){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(x) : p.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +return (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(y) : p.call(null,y)); +} else { +return and__4120__auto__; +} +})()); +}); +var cljs$core$ep1__3 = (function (x,y,z){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(x) : p.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +var and__4120__auto____$1 = (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(y) : p.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$1)){ +return (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(z) : p.call(null,z)); +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +var cljs$core$ep1__4 = (function() { +var G__3907__delegate = function (x,y,z,args){ +return cljs.core.boolean$((function (){var and__4120__auto__ = cljs$core$ep1.cljs$core$IFn$_invoke$arity$3(x,y,z); +if(cljs.core.truth_(and__4120__auto__)){ +return cljs.core.every_QMARK_(p,args); +} else { +return and__4120__auto__; +} +})()); +}; +var G__3907 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3908__i = 0, G__3908__a = new Array(arguments.length - 3); +while (G__3908__i < G__3908__a.length) {G__3908__a[G__3908__i] = arguments[G__3908__i + 3]; ++G__3908__i;} + args = new cljs.core.IndexedSeq(G__3908__a,0,null); +} +return G__3907__delegate.call(this,x,y,z,args);}; +G__3907.cljs$lang$maxFixedArity = 3; +G__3907.cljs$lang$applyTo = (function (arglist__3909){ +var x = cljs.core.first(arglist__3909); +arglist__3909 = cljs.core.next(arglist__3909); +var y = cljs.core.first(arglist__3909); +arglist__3909 = cljs.core.next(arglist__3909); +var z = cljs.core.first(arglist__3909); +var args = cljs.core.rest(arglist__3909); +return G__3907__delegate(x,y,z,args); +}); +G__3907.cljs$core$IFn$_invoke$arity$variadic = G__3907__delegate; +return G__3907; +})() +; +cljs$core$ep1 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return cljs$core$ep1__0.call(this); +case 1: +return cljs$core$ep1__1.call(this,x); +case 2: +return cljs$core$ep1__2.call(this,x,y); +case 3: +return cljs$core$ep1__3.call(this,x,y,z); +default: +var G__3910 = null; +if (arguments.length > 3) { +var G__3911__i = 0, G__3911__a = new Array(arguments.length - 3); +while (G__3911__i < G__3911__a.length) {G__3911__a[G__3911__i] = arguments[G__3911__i + 3]; ++G__3911__i;} +G__3910 = new cljs.core.IndexedSeq(G__3911__a,0,null); +} +return cljs$core$ep1__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3910); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +cljs$core$ep1.cljs$lang$maxFixedArity = 3; +cljs$core$ep1.cljs$lang$applyTo = cljs$core$ep1__4.cljs$lang$applyTo; +cljs$core$ep1.cljs$core$IFn$_invoke$arity$0 = cljs$core$ep1__0; +cljs$core$ep1.cljs$core$IFn$_invoke$arity$1 = cljs$core$ep1__1; +cljs$core$ep1.cljs$core$IFn$_invoke$arity$2 = cljs$core$ep1__2; +cljs$core$ep1.cljs$core$IFn$_invoke$arity$3 = cljs$core$ep1__3; +cljs$core$ep1.cljs$core$IFn$_invoke$arity$variadic = cljs$core$ep1__4.cljs$core$IFn$_invoke$arity$variadic; +return cljs$core$ep1; +})() +}); + +cljs.core.every_pred.cljs$core$IFn$_invoke$arity$2 = (function (p1,p2){ +return (function() { +var cljs$core$ep2 = null; +var cljs$core$ep2__0 = (function (){ +return true; +}); +var cljs$core$ep2__1 = (function (x){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +return (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +} else { +return and__4120__auto__; +} +})()); +}); +var cljs$core$ep2__2 = (function (x,y){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +var and__4120__auto____$1 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(y) : p1.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$1)){ +var and__4120__auto____$2 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(and__4120__auto____$2)){ +return (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(y) : p2.call(null,y)); +} else { +return and__4120__auto____$2; +} +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +var cljs$core$ep2__3 = (function (x,y,z){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +var and__4120__auto____$1 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(y) : p1.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$1)){ +var and__4120__auto____$2 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(z) : p1.call(null,z)); +if(cljs.core.truth_(and__4120__auto____$2)){ +var and__4120__auto____$3 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(and__4120__auto____$3)){ +var and__4120__auto____$4 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(y) : p2.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$4)){ +return (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(z) : p2.call(null,z)); +} else { +return and__4120__auto____$4; +} +} else { +return and__4120__auto____$3; +} +} else { +return and__4120__auto____$2; +} +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +var cljs$core$ep2__4 = (function() { +var G__3912__delegate = function (x,y,z,args){ +return cljs.core.boolean$((function (){var and__4120__auto__ = cljs$core$ep2.cljs$core$IFn$_invoke$arity$3(x,y,z); +if(cljs.core.truth_(and__4120__auto__)){ +return cljs.core.every_QMARK_(((function (and__4120__auto__){ +return (function (p1__3891_SHARP_){ +var and__4120__auto____$1 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(p1__3891_SHARP_) : p1.call(null,p1__3891_SHARP_)); +if(cljs.core.truth_(and__4120__auto____$1)){ +return (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(p1__3891_SHARP_) : p2.call(null,p1__3891_SHARP_)); +} else { +return and__4120__auto____$1; +} +});})(and__4120__auto__)) +,args); +} else { +return and__4120__auto__; +} +})()); +}; +var G__3912 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3913__i = 0, G__3913__a = new Array(arguments.length - 3); +while (G__3913__i < G__3913__a.length) {G__3913__a[G__3913__i] = arguments[G__3913__i + 3]; ++G__3913__i;} + args = new cljs.core.IndexedSeq(G__3913__a,0,null); +} +return G__3912__delegate.call(this,x,y,z,args);}; +G__3912.cljs$lang$maxFixedArity = 3; +G__3912.cljs$lang$applyTo = (function (arglist__3914){ +var x = cljs.core.first(arglist__3914); +arglist__3914 = cljs.core.next(arglist__3914); +var y = cljs.core.first(arglist__3914); +arglist__3914 = cljs.core.next(arglist__3914); +var z = cljs.core.first(arglist__3914); +var args = cljs.core.rest(arglist__3914); +return G__3912__delegate(x,y,z,args); +}); +G__3912.cljs$core$IFn$_invoke$arity$variadic = G__3912__delegate; +return G__3912; +})() +; +cljs$core$ep2 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return cljs$core$ep2__0.call(this); +case 1: +return cljs$core$ep2__1.call(this,x); +case 2: +return cljs$core$ep2__2.call(this,x,y); +case 3: +return cljs$core$ep2__3.call(this,x,y,z); +default: +var G__3915 = null; +if (arguments.length > 3) { +var G__3916__i = 0, G__3916__a = new Array(arguments.length - 3); +while (G__3916__i < G__3916__a.length) {G__3916__a[G__3916__i] = arguments[G__3916__i + 3]; ++G__3916__i;} +G__3915 = new cljs.core.IndexedSeq(G__3916__a,0,null); +} +return cljs$core$ep2__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3915); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +cljs$core$ep2.cljs$lang$maxFixedArity = 3; +cljs$core$ep2.cljs$lang$applyTo = cljs$core$ep2__4.cljs$lang$applyTo; +cljs$core$ep2.cljs$core$IFn$_invoke$arity$0 = cljs$core$ep2__0; +cljs$core$ep2.cljs$core$IFn$_invoke$arity$1 = cljs$core$ep2__1; +cljs$core$ep2.cljs$core$IFn$_invoke$arity$2 = cljs$core$ep2__2; +cljs$core$ep2.cljs$core$IFn$_invoke$arity$3 = cljs$core$ep2__3; +cljs$core$ep2.cljs$core$IFn$_invoke$arity$variadic = cljs$core$ep2__4.cljs$core$IFn$_invoke$arity$variadic; +return cljs$core$ep2; +})() +}); + +cljs.core.every_pred.cljs$core$IFn$_invoke$arity$3 = (function (p1,p2,p3){ +return (function() { +var cljs$core$ep3 = null; +var cljs$core$ep3__0 = (function (){ +return true; +}); +var cljs$core$ep3__1 = (function (x){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +var and__4120__auto____$1 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(and__4120__auto____$1)){ +return (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(x) : p3.call(null,x)); +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +var cljs$core$ep3__2 = (function (x,y){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +var and__4120__auto____$1 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(and__4120__auto____$1)){ +var and__4120__auto____$2 = (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(x) : p3.call(null,x)); +if(cljs.core.truth_(and__4120__auto____$2)){ +var and__4120__auto____$3 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(y) : p1.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$3)){ +var and__4120__auto____$4 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(y) : p2.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$4)){ +return (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(y) : p3.call(null,y)); +} else { +return and__4120__auto____$4; +} +} else { +return and__4120__auto____$3; +} +} else { +return and__4120__auto____$2; +} +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +var cljs$core$ep3__3 = (function (x,y,z){ +return cljs.core.boolean$((function (){var and__4120__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +var and__4120__auto____$1 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(and__4120__auto____$1)){ +var and__4120__auto____$2 = (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(x) : p3.call(null,x)); +if(cljs.core.truth_(and__4120__auto____$2)){ +var and__4120__auto____$3 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(y) : p1.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$3)){ +var and__4120__auto____$4 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(y) : p2.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$4)){ +var and__4120__auto____$5 = (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(y) : p3.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$5)){ +var and__4120__auto____$6 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(z) : p1.call(null,z)); +if(cljs.core.truth_(and__4120__auto____$6)){ +var and__4120__auto____$7 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(z) : p2.call(null,z)); +if(cljs.core.truth_(and__4120__auto____$7)){ +return (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(z) : p3.call(null,z)); +} else { +return and__4120__auto____$7; +} +} else { +return and__4120__auto____$6; +} +} else { +return and__4120__auto____$5; +} +} else { +return and__4120__auto____$4; +} +} else { +return and__4120__auto____$3; +} +} else { +return and__4120__auto____$2; +} +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +})()); +}); +var cljs$core$ep3__4 = (function() { +var G__3917__delegate = function (x,y,z,args){ +return cljs.core.boolean$((function (){var and__4120__auto__ = cljs$core$ep3.cljs$core$IFn$_invoke$arity$3(x,y,z); +if(cljs.core.truth_(and__4120__auto__)){ +return cljs.core.every_QMARK_(((function (and__4120__auto__){ +return (function (p1__3892_SHARP_){ +var and__4120__auto____$1 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(p1__3892_SHARP_) : p1.call(null,p1__3892_SHARP_)); +if(cljs.core.truth_(and__4120__auto____$1)){ +var and__4120__auto____$2 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(p1__3892_SHARP_) : p2.call(null,p1__3892_SHARP_)); +if(cljs.core.truth_(and__4120__auto____$2)){ +return (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(p1__3892_SHARP_) : p3.call(null,p1__3892_SHARP_)); +} else { +return and__4120__auto____$2; +} +} else { +return and__4120__auto____$1; +} +});})(and__4120__auto__)) +,args); +} else { +return and__4120__auto__; +} +})()); +}; +var G__3917 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3918__i = 0, G__3918__a = new Array(arguments.length - 3); +while (G__3918__i < G__3918__a.length) {G__3918__a[G__3918__i] = arguments[G__3918__i + 3]; ++G__3918__i;} + args = new cljs.core.IndexedSeq(G__3918__a,0,null); +} +return G__3917__delegate.call(this,x,y,z,args);}; +G__3917.cljs$lang$maxFixedArity = 3; +G__3917.cljs$lang$applyTo = (function (arglist__3919){ +var x = cljs.core.first(arglist__3919); +arglist__3919 = cljs.core.next(arglist__3919); +var y = cljs.core.first(arglist__3919); +arglist__3919 = cljs.core.next(arglist__3919); +var z = cljs.core.first(arglist__3919); +var args = cljs.core.rest(arglist__3919); +return G__3917__delegate(x,y,z,args); +}); +G__3917.cljs$core$IFn$_invoke$arity$variadic = G__3917__delegate; +return G__3917; +})() +; +cljs$core$ep3 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return cljs$core$ep3__0.call(this); +case 1: +return cljs$core$ep3__1.call(this,x); +case 2: +return cljs$core$ep3__2.call(this,x,y); +case 3: +return cljs$core$ep3__3.call(this,x,y,z); +default: +var G__3920 = null; +if (arguments.length > 3) { +var G__3921__i = 0, G__3921__a = new Array(arguments.length - 3); +while (G__3921__i < G__3921__a.length) {G__3921__a[G__3921__i] = arguments[G__3921__i + 3]; ++G__3921__i;} +G__3920 = new cljs.core.IndexedSeq(G__3921__a,0,null); +} +return cljs$core$ep3__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3920); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +cljs$core$ep3.cljs$lang$maxFixedArity = 3; +cljs$core$ep3.cljs$lang$applyTo = cljs$core$ep3__4.cljs$lang$applyTo; +cljs$core$ep3.cljs$core$IFn$_invoke$arity$0 = cljs$core$ep3__0; +cljs$core$ep3.cljs$core$IFn$_invoke$arity$1 = cljs$core$ep3__1; +cljs$core$ep3.cljs$core$IFn$_invoke$arity$2 = cljs$core$ep3__2; +cljs$core$ep3.cljs$core$IFn$_invoke$arity$3 = cljs$core$ep3__3; +cljs$core$ep3.cljs$core$IFn$_invoke$arity$variadic = cljs$core$ep3__4.cljs$core$IFn$_invoke$arity$variadic; +return cljs$core$ep3; +})() +}); + +cljs.core.every_pred.cljs$core$IFn$_invoke$arity$variadic = (function (p1,p2,p3,ps){ +var ps__$1 = cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$4(p1,p2,p3,ps); +return ((function (ps__$1){ +return (function() { +var cljs$core$epn = null; +var cljs$core$epn__0 = (function (){ +return true; +}); +var cljs$core$epn__1 = (function (x){ +return cljs.core.every_QMARK_(((function (ps__$1){ +return (function (p1__3893_SHARP_){ +return (p1__3893_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3893_SHARP_.cljs$core$IFn$_invoke$arity$1(x) : p1__3893_SHARP_.call(null,x)); +});})(ps__$1)) +,ps__$1); +}); +var cljs$core$epn__2 = (function (x,y){ +return cljs.core.every_QMARK_(((function (ps__$1){ +return (function (p1__3894_SHARP_){ +var and__4120__auto__ = (p1__3894_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3894_SHARP_.cljs$core$IFn$_invoke$arity$1(x) : p1__3894_SHARP_.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +return (p1__3894_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3894_SHARP_.cljs$core$IFn$_invoke$arity$1(y) : p1__3894_SHARP_.call(null,y)); +} else { +return and__4120__auto__; +} +});})(ps__$1)) +,ps__$1); +}); +var cljs$core$epn__3 = (function (x,y,z){ +return cljs.core.every_QMARK_(((function (ps__$1){ +return (function (p1__3895_SHARP_){ +var and__4120__auto__ = (p1__3895_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3895_SHARP_.cljs$core$IFn$_invoke$arity$1(x) : p1__3895_SHARP_.call(null,x)); +if(cljs.core.truth_(and__4120__auto__)){ +var and__4120__auto____$1 = (p1__3895_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3895_SHARP_.cljs$core$IFn$_invoke$arity$1(y) : p1__3895_SHARP_.call(null,y)); +if(cljs.core.truth_(and__4120__auto____$1)){ +return (p1__3895_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3895_SHARP_.cljs$core$IFn$_invoke$arity$1(z) : p1__3895_SHARP_.call(null,z)); +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +});})(ps__$1)) +,ps__$1); +}); +var cljs$core$epn__4 = (function() { +var G__3922__delegate = function (x,y,z,args){ +return cljs.core.boolean$((function (){var and__4120__auto__ = cljs$core$epn.cljs$core$IFn$_invoke$arity$3(x,y,z); +if(cljs.core.truth_(and__4120__auto__)){ +return cljs.core.every_QMARK_(((function (and__4120__auto__,ps__$1){ +return (function (p1__3896_SHARP_){ +return cljs.core.every_QMARK_(p1__3896_SHARP_,args); +});})(and__4120__auto__,ps__$1)) +,ps__$1); +} else { +return and__4120__auto__; +} +})()); +}; +var G__3922 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3923__i = 0, G__3923__a = new Array(arguments.length - 3); +while (G__3923__i < G__3923__a.length) {G__3923__a[G__3923__i] = arguments[G__3923__i + 3]; ++G__3923__i;} + args = new cljs.core.IndexedSeq(G__3923__a,0,null); +} +return G__3922__delegate.call(this,x,y,z,args);}; +G__3922.cljs$lang$maxFixedArity = 3; +G__3922.cljs$lang$applyTo = (function (arglist__3924){ +var x = cljs.core.first(arglist__3924); +arglist__3924 = cljs.core.next(arglist__3924); +var y = cljs.core.first(arglist__3924); +arglist__3924 = cljs.core.next(arglist__3924); +var z = cljs.core.first(arglist__3924); +var args = cljs.core.rest(arglist__3924); +return G__3922__delegate(x,y,z,args); +}); +G__3922.cljs$core$IFn$_invoke$arity$variadic = G__3922__delegate; +return G__3922; +})() +; +cljs$core$epn = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return cljs$core$epn__0.call(this); +case 1: +return cljs$core$epn__1.call(this,x); +case 2: +return cljs$core$epn__2.call(this,x,y); +case 3: +return cljs$core$epn__3.call(this,x,y,z); +default: +var G__3925 = null; +if (arguments.length > 3) { +var G__3926__i = 0, G__3926__a = new Array(arguments.length - 3); +while (G__3926__i < G__3926__a.length) {G__3926__a[G__3926__i] = arguments[G__3926__i + 3]; ++G__3926__i;} +G__3925 = new cljs.core.IndexedSeq(G__3926__a,0,null); +} +return cljs$core$epn__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3925); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +cljs$core$epn.cljs$lang$maxFixedArity = 3; +cljs$core$epn.cljs$lang$applyTo = cljs$core$epn__4.cljs$lang$applyTo; +cljs$core$epn.cljs$core$IFn$_invoke$arity$0 = cljs$core$epn__0; +cljs$core$epn.cljs$core$IFn$_invoke$arity$1 = cljs$core$epn__1; +cljs$core$epn.cljs$core$IFn$_invoke$arity$2 = cljs$core$epn__2; +cljs$core$epn.cljs$core$IFn$_invoke$arity$3 = cljs$core$epn__3; +cljs$core$epn.cljs$core$IFn$_invoke$arity$variadic = cljs$core$epn__4.cljs$core$IFn$_invoke$arity$variadic; +return cljs$core$epn; +})() +;})(ps__$1)) +}); + +/** @this {Function} */ +cljs.core.every_pred.cljs$lang$applyTo = (function (seq3898){ +var G__3899 = cljs.core.first(seq3898); +var seq3898__$1 = cljs.core.next(seq3898); +var G__3900 = cljs.core.first(seq3898__$1); +var seq3898__$2 = cljs.core.next(seq3898__$1); +var G__3901 = cljs.core.first(seq3898__$2); +var seq3898__$3 = cljs.core.next(seq3898__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3899,G__3900,G__3901,seq3898__$3); +}); + +cljs.core.every_pred.cljs$lang$maxFixedArity = (3); + +/** + * Takes a set of predicates and returns a function f that returns the first logical true value + * returned by one of its composing predicates against any of its arguments, else it returns + * logical false. Note that f is short-circuiting in that it will stop execution on the first + * argument that triggers a logical true result against the original predicates. + */ +cljs.core.some_fn = (function cljs$core$some_fn(var_args){ +var G__3938 = arguments.length; +switch (G__3938) { +case 1: +return cljs.core.some_fn.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.some_fn.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.some_fn.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3940 = arguments.length; +var i__4731__auto___3941 = (0); +while(true){ +if((i__4731__auto___3941 < len__4730__auto___3940)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3941])); + +var G__3942 = (i__4731__auto___3941 + (1)); +i__4731__auto___3941 = G__3942; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.some_fn.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.some_fn.cljs$core$IFn$_invoke$arity$1 = (function (p){ +return (function() { +var cljs$core$sp1 = null; +var cljs$core$sp1__0 = (function (){ +return null; +}); +var cljs$core$sp1__1 = (function (x){ +return (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(x) : p.call(null,x)); +}); +var cljs$core$sp1__2 = (function (x,y){ +var or__4131__auto__ = (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(x) : p.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(y) : p.call(null,y)); +} +}); +var cljs$core$sp1__3 = (function (x,y,z){ +var or__4131__auto__ = (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(x) : p.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(y) : p.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +return (p.cljs$core$IFn$_invoke$arity$1 ? p.cljs$core$IFn$_invoke$arity$1(z) : p.call(null,z)); +} +} +}); +var cljs$core$sp1__4 = (function() { +var G__3943__delegate = function (x,y,z,args){ +var or__4131__auto__ = cljs$core$sp1.cljs$core$IFn$_invoke$arity$3(x,y,z); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.some(p,args); +} +}; +var G__3943 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3944__i = 0, G__3944__a = new Array(arguments.length - 3); +while (G__3944__i < G__3944__a.length) {G__3944__a[G__3944__i] = arguments[G__3944__i + 3]; ++G__3944__i;} + args = new cljs.core.IndexedSeq(G__3944__a,0,null); +} +return G__3943__delegate.call(this,x,y,z,args);}; +G__3943.cljs$lang$maxFixedArity = 3; +G__3943.cljs$lang$applyTo = (function (arglist__3945){ +var x = cljs.core.first(arglist__3945); +arglist__3945 = cljs.core.next(arglist__3945); +var y = cljs.core.first(arglist__3945); +arglist__3945 = cljs.core.next(arglist__3945); +var z = cljs.core.first(arglist__3945); +var args = cljs.core.rest(arglist__3945); +return G__3943__delegate(x,y,z,args); +}); +G__3943.cljs$core$IFn$_invoke$arity$variadic = G__3943__delegate; +return G__3943; +})() +; +cljs$core$sp1 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return cljs$core$sp1__0.call(this); +case 1: +return cljs$core$sp1__1.call(this,x); +case 2: +return cljs$core$sp1__2.call(this,x,y); +case 3: +return cljs$core$sp1__3.call(this,x,y,z); +default: +var G__3946 = null; +if (arguments.length > 3) { +var G__3947__i = 0, G__3947__a = new Array(arguments.length - 3); +while (G__3947__i < G__3947__a.length) {G__3947__a[G__3947__i] = arguments[G__3947__i + 3]; ++G__3947__i;} +G__3946 = new cljs.core.IndexedSeq(G__3947__a,0,null); +} +return cljs$core$sp1__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3946); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +cljs$core$sp1.cljs$lang$maxFixedArity = 3; +cljs$core$sp1.cljs$lang$applyTo = cljs$core$sp1__4.cljs$lang$applyTo; +cljs$core$sp1.cljs$core$IFn$_invoke$arity$0 = cljs$core$sp1__0; +cljs$core$sp1.cljs$core$IFn$_invoke$arity$1 = cljs$core$sp1__1; +cljs$core$sp1.cljs$core$IFn$_invoke$arity$2 = cljs$core$sp1__2; +cljs$core$sp1.cljs$core$IFn$_invoke$arity$3 = cljs$core$sp1__3; +cljs$core$sp1.cljs$core$IFn$_invoke$arity$variadic = cljs$core$sp1__4.cljs$core$IFn$_invoke$arity$variadic; +return cljs$core$sp1; +})() +}); + +cljs.core.some_fn.cljs$core$IFn$_invoke$arity$2 = (function (p1,p2){ +return (function() { +var cljs$core$sp2 = null; +var cljs$core$sp2__0 = (function (){ +return null; +}); +var cljs$core$sp2__1 = (function (x){ +var or__4131__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +} +}); +var cljs$core$sp2__2 = (function (x,y){ +var or__4131__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(y) : p1.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +var or__4131__auto____$2 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(or__4131__auto____$2)){ +return or__4131__auto____$2; +} else { +return (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(y) : p2.call(null,y)); +} +} +} +}); +var cljs$core$sp2__3 = (function (x,y,z){ +var or__4131__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(y) : p1.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +var or__4131__auto____$2 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(z) : p1.call(null,z)); +if(cljs.core.truth_(or__4131__auto____$2)){ +return or__4131__auto____$2; +} else { +var or__4131__auto____$3 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(or__4131__auto____$3)){ +return or__4131__auto____$3; +} else { +var or__4131__auto____$4 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(y) : p2.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$4)){ +return or__4131__auto____$4; +} else { +return (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(z) : p2.call(null,z)); +} +} +} +} +} +}); +var cljs$core$sp2__4 = (function() { +var G__3948__delegate = function (x,y,z,args){ +var or__4131__auto__ = cljs$core$sp2.cljs$core$IFn$_invoke$arity$3(x,y,z); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.some(((function (or__4131__auto__){ +return (function (p1__3927_SHARP_){ +var or__4131__auto____$1 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(p1__3927_SHARP_) : p1.call(null,p1__3927_SHARP_)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +return (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(p1__3927_SHARP_) : p2.call(null,p1__3927_SHARP_)); +} +});})(or__4131__auto__)) +,args); +} +}; +var G__3948 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3949__i = 0, G__3949__a = new Array(arguments.length - 3); +while (G__3949__i < G__3949__a.length) {G__3949__a[G__3949__i] = arguments[G__3949__i + 3]; ++G__3949__i;} + args = new cljs.core.IndexedSeq(G__3949__a,0,null); +} +return G__3948__delegate.call(this,x,y,z,args);}; +G__3948.cljs$lang$maxFixedArity = 3; +G__3948.cljs$lang$applyTo = (function (arglist__3950){ +var x = cljs.core.first(arglist__3950); +arglist__3950 = cljs.core.next(arglist__3950); +var y = cljs.core.first(arglist__3950); +arglist__3950 = cljs.core.next(arglist__3950); +var z = cljs.core.first(arglist__3950); +var args = cljs.core.rest(arglist__3950); +return G__3948__delegate(x,y,z,args); +}); +G__3948.cljs$core$IFn$_invoke$arity$variadic = G__3948__delegate; +return G__3948; +})() +; +cljs$core$sp2 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return cljs$core$sp2__0.call(this); +case 1: +return cljs$core$sp2__1.call(this,x); +case 2: +return cljs$core$sp2__2.call(this,x,y); +case 3: +return cljs$core$sp2__3.call(this,x,y,z); +default: +var G__3951 = null; +if (arguments.length > 3) { +var G__3952__i = 0, G__3952__a = new Array(arguments.length - 3); +while (G__3952__i < G__3952__a.length) {G__3952__a[G__3952__i] = arguments[G__3952__i + 3]; ++G__3952__i;} +G__3951 = new cljs.core.IndexedSeq(G__3952__a,0,null); +} +return cljs$core$sp2__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3951); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +cljs$core$sp2.cljs$lang$maxFixedArity = 3; +cljs$core$sp2.cljs$lang$applyTo = cljs$core$sp2__4.cljs$lang$applyTo; +cljs$core$sp2.cljs$core$IFn$_invoke$arity$0 = cljs$core$sp2__0; +cljs$core$sp2.cljs$core$IFn$_invoke$arity$1 = cljs$core$sp2__1; +cljs$core$sp2.cljs$core$IFn$_invoke$arity$2 = cljs$core$sp2__2; +cljs$core$sp2.cljs$core$IFn$_invoke$arity$3 = cljs$core$sp2__3; +cljs$core$sp2.cljs$core$IFn$_invoke$arity$variadic = cljs$core$sp2__4.cljs$core$IFn$_invoke$arity$variadic; +return cljs$core$sp2; +})() +}); + +cljs.core.some_fn.cljs$core$IFn$_invoke$arity$3 = (function (p1,p2,p3){ +return (function() { +var cljs$core$sp3 = null; +var cljs$core$sp3__0 = (function (){ +return null; +}); +var cljs$core$sp3__1 = (function (x){ +var or__4131__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +return (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(x) : p3.call(null,x)); +} +} +}); +var cljs$core$sp3__2 = (function (x,y){ +var or__4131__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +var or__4131__auto____$2 = (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(x) : p3.call(null,x)); +if(cljs.core.truth_(or__4131__auto____$2)){ +return or__4131__auto____$2; +} else { +var or__4131__auto____$3 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(y) : p1.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$3)){ +return or__4131__auto____$3; +} else { +var or__4131__auto____$4 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(y) : p2.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$4)){ +return or__4131__auto____$4; +} else { +return (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(y) : p3.call(null,y)); +} +} +} +} +} +}); +var cljs$core$sp3__3 = (function (x,y,z){ +var or__4131__auto__ = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(x) : p1.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(x) : p2.call(null,x)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +var or__4131__auto____$2 = (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(x) : p3.call(null,x)); +if(cljs.core.truth_(or__4131__auto____$2)){ +return or__4131__auto____$2; +} else { +var or__4131__auto____$3 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(y) : p1.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$3)){ +return or__4131__auto____$3; +} else { +var or__4131__auto____$4 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(y) : p2.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$4)){ +return or__4131__auto____$4; +} else { +var or__4131__auto____$5 = (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(y) : p3.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$5)){ +return or__4131__auto____$5; +} else { +var or__4131__auto____$6 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(z) : p1.call(null,z)); +if(cljs.core.truth_(or__4131__auto____$6)){ +return or__4131__auto____$6; +} else { +var or__4131__auto____$7 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(z) : p2.call(null,z)); +if(cljs.core.truth_(or__4131__auto____$7)){ +return or__4131__auto____$7; +} else { +return (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(z) : p3.call(null,z)); +} +} +} +} +} +} +} +} +}); +var cljs$core$sp3__4 = (function() { +var G__3953__delegate = function (x,y,z,args){ +var or__4131__auto__ = cljs$core$sp3.cljs$core$IFn$_invoke$arity$3(x,y,z); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.some(((function (or__4131__auto__){ +return (function (p1__3928_SHARP_){ +var or__4131__auto____$1 = (p1.cljs$core$IFn$_invoke$arity$1 ? p1.cljs$core$IFn$_invoke$arity$1(p1__3928_SHARP_) : p1.call(null,p1__3928_SHARP_)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +var or__4131__auto____$2 = (p2.cljs$core$IFn$_invoke$arity$1 ? p2.cljs$core$IFn$_invoke$arity$1(p1__3928_SHARP_) : p2.call(null,p1__3928_SHARP_)); +if(cljs.core.truth_(or__4131__auto____$2)){ +return or__4131__auto____$2; +} else { +return (p3.cljs$core$IFn$_invoke$arity$1 ? p3.cljs$core$IFn$_invoke$arity$1(p1__3928_SHARP_) : p3.call(null,p1__3928_SHARP_)); +} +} +});})(or__4131__auto__)) +,args); +} +}; +var G__3953 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3954__i = 0, G__3954__a = new Array(arguments.length - 3); +while (G__3954__i < G__3954__a.length) {G__3954__a[G__3954__i] = arguments[G__3954__i + 3]; ++G__3954__i;} + args = new cljs.core.IndexedSeq(G__3954__a,0,null); +} +return G__3953__delegate.call(this,x,y,z,args);}; +G__3953.cljs$lang$maxFixedArity = 3; +G__3953.cljs$lang$applyTo = (function (arglist__3955){ +var x = cljs.core.first(arglist__3955); +arglist__3955 = cljs.core.next(arglist__3955); +var y = cljs.core.first(arglist__3955); +arglist__3955 = cljs.core.next(arglist__3955); +var z = cljs.core.first(arglist__3955); +var args = cljs.core.rest(arglist__3955); +return G__3953__delegate(x,y,z,args); +}); +G__3953.cljs$core$IFn$_invoke$arity$variadic = G__3953__delegate; +return G__3953; +})() +; +cljs$core$sp3 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return cljs$core$sp3__0.call(this); +case 1: +return cljs$core$sp3__1.call(this,x); +case 2: +return cljs$core$sp3__2.call(this,x,y); +case 3: +return cljs$core$sp3__3.call(this,x,y,z); +default: +var G__3956 = null; +if (arguments.length > 3) { +var G__3957__i = 0, G__3957__a = new Array(arguments.length - 3); +while (G__3957__i < G__3957__a.length) {G__3957__a[G__3957__i] = arguments[G__3957__i + 3]; ++G__3957__i;} +G__3956 = new cljs.core.IndexedSeq(G__3957__a,0,null); +} +return cljs$core$sp3__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3956); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +cljs$core$sp3.cljs$lang$maxFixedArity = 3; +cljs$core$sp3.cljs$lang$applyTo = cljs$core$sp3__4.cljs$lang$applyTo; +cljs$core$sp3.cljs$core$IFn$_invoke$arity$0 = cljs$core$sp3__0; +cljs$core$sp3.cljs$core$IFn$_invoke$arity$1 = cljs$core$sp3__1; +cljs$core$sp3.cljs$core$IFn$_invoke$arity$2 = cljs$core$sp3__2; +cljs$core$sp3.cljs$core$IFn$_invoke$arity$3 = cljs$core$sp3__3; +cljs$core$sp3.cljs$core$IFn$_invoke$arity$variadic = cljs$core$sp3__4.cljs$core$IFn$_invoke$arity$variadic; +return cljs$core$sp3; +})() +}); + +cljs.core.some_fn.cljs$core$IFn$_invoke$arity$variadic = (function (p1,p2,p3,ps){ +var ps__$1 = cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$4(p1,p2,p3,ps); +return ((function (ps__$1){ +return (function() { +var cljs$core$spn = null; +var cljs$core$spn__0 = (function (){ +return null; +}); +var cljs$core$spn__1 = (function (x){ +return cljs.core.some(((function (ps__$1){ +return (function (p1__3929_SHARP_){ +return (p1__3929_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3929_SHARP_.cljs$core$IFn$_invoke$arity$1(x) : p1__3929_SHARP_.call(null,x)); +});})(ps__$1)) +,ps__$1); +}); +var cljs$core$spn__2 = (function (x,y){ +return cljs.core.some(((function (ps__$1){ +return (function (p1__3930_SHARP_){ +var or__4131__auto__ = (p1__3930_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3930_SHARP_.cljs$core$IFn$_invoke$arity$1(x) : p1__3930_SHARP_.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return (p1__3930_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3930_SHARP_.cljs$core$IFn$_invoke$arity$1(y) : p1__3930_SHARP_.call(null,y)); +} +});})(ps__$1)) +,ps__$1); +}); +var cljs$core$spn__3 = (function (x,y,z){ +return cljs.core.some(((function (ps__$1){ +return (function (p1__3931_SHARP_){ +var or__4131__auto__ = (p1__3931_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3931_SHARP_.cljs$core$IFn$_invoke$arity$1(x) : p1__3931_SHARP_.call(null,x)); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (p1__3931_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3931_SHARP_.cljs$core$IFn$_invoke$arity$1(y) : p1__3931_SHARP_.call(null,y)); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +return (p1__3931_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p1__3931_SHARP_.cljs$core$IFn$_invoke$arity$1(z) : p1__3931_SHARP_.call(null,z)); +} +} +});})(ps__$1)) +,ps__$1); +}); +var cljs$core$spn__4 = (function() { +var G__3958__delegate = function (x,y,z,args){ +var or__4131__auto__ = cljs$core$spn.cljs$core$IFn$_invoke$arity$3(x,y,z); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.some(((function (or__4131__auto__,ps__$1){ +return (function (p1__3932_SHARP_){ +return cljs.core.some(p1__3932_SHARP_,args); +});})(or__4131__auto__,ps__$1)) +,ps__$1); +} +}; +var G__3958 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__3959__i = 0, G__3959__a = new Array(arguments.length - 3); +while (G__3959__i < G__3959__a.length) {G__3959__a[G__3959__i] = arguments[G__3959__i + 3]; ++G__3959__i;} + args = new cljs.core.IndexedSeq(G__3959__a,0,null); +} +return G__3958__delegate.call(this,x,y,z,args);}; +G__3958.cljs$lang$maxFixedArity = 3; +G__3958.cljs$lang$applyTo = (function (arglist__3960){ +var x = cljs.core.first(arglist__3960); +arglist__3960 = cljs.core.next(arglist__3960); +var y = cljs.core.first(arglist__3960); +arglist__3960 = cljs.core.next(arglist__3960); +var z = cljs.core.first(arglist__3960); +var args = cljs.core.rest(arglist__3960); +return G__3958__delegate(x,y,z,args); +}); +G__3958.cljs$core$IFn$_invoke$arity$variadic = G__3958__delegate; +return G__3958; +})() +; +cljs$core$spn = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return cljs$core$spn__0.call(this); +case 1: +return cljs$core$spn__1.call(this,x); +case 2: +return cljs$core$spn__2.call(this,x,y); +case 3: +return cljs$core$spn__3.call(this,x,y,z); +default: +var G__3961 = null; +if (arguments.length > 3) { +var G__3962__i = 0, G__3962__a = new Array(arguments.length - 3); +while (G__3962__i < G__3962__a.length) {G__3962__a[G__3962__i] = arguments[G__3962__i + 3]; ++G__3962__i;} +G__3961 = new cljs.core.IndexedSeq(G__3962__a,0,null); +} +return cljs$core$spn__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__3961); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +cljs$core$spn.cljs$lang$maxFixedArity = 3; +cljs$core$spn.cljs$lang$applyTo = cljs$core$spn__4.cljs$lang$applyTo; +cljs$core$spn.cljs$core$IFn$_invoke$arity$0 = cljs$core$spn__0; +cljs$core$spn.cljs$core$IFn$_invoke$arity$1 = cljs$core$spn__1; +cljs$core$spn.cljs$core$IFn$_invoke$arity$2 = cljs$core$spn__2; +cljs$core$spn.cljs$core$IFn$_invoke$arity$3 = cljs$core$spn__3; +cljs$core$spn.cljs$core$IFn$_invoke$arity$variadic = cljs$core$spn__4.cljs$core$IFn$_invoke$arity$variadic; +return cljs$core$spn; +})() +;})(ps__$1)) +}); + +/** @this {Function} */ +cljs.core.some_fn.cljs$lang$applyTo = (function (seq3934){ +var G__3935 = cljs.core.first(seq3934); +var seq3934__$1 = cljs.core.next(seq3934); +var G__3936 = cljs.core.first(seq3934__$1); +var seq3934__$2 = cljs.core.next(seq3934__$1); +var G__3937 = cljs.core.first(seq3934__$2); +var seq3934__$3 = cljs.core.next(seq3934__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3935,G__3936,G__3937,seq3934__$3); +}); + +cljs.core.some_fn.cljs$lang$maxFixedArity = (3); + +/** + * Returns a lazy sequence consisting of the result of applying f to + * the set of first items of each coll, followed by applying f to the + * set of second items in each coll, until any one of the colls is + * exhausted. Any remaining items in other colls are ignored. Function + * f should accept number-of-colls arguments. Returns a transducer when + * no collection is provided. + */ +cljs.core.map = (function cljs$core$map(var_args){ +var G__3970 = arguments.length; +switch (G__3970) { +case 1: +return cljs.core.map.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.map.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.map.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.map.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___3983 = arguments.length; +var i__4731__auto___3984 = (0); +while(true){ +if((i__4731__auto___3984 < len__4730__auto___3983)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___3984])); + +var G__3985 = (i__4731__auto___3984 + (1)); +i__4731__auto___3984 = G__3985; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((4)),(0),null)); +return cljs.core.map.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),argseq__4752__auto__); + +} +}); + +cljs.core.map.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return (function (rf){ +return (function() { +var G__3986 = null; +var G__3986__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__3986__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__3986__2 = (function (result,input){ +var G__3971 = result; +var G__3972 = (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(input) : f.call(null,input)); +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(G__3971,G__3972) : rf.call(null,G__3971,G__3972)); +}); +var G__3986__3 = (function() { +var G__3987__delegate = function (result,input,inputs){ +var G__3973 = result; +var G__3974 = cljs.core.apply.cljs$core$IFn$_invoke$arity$3(f,input,inputs); +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(G__3973,G__3974) : rf.call(null,G__3973,G__3974)); +}; +var G__3987 = function (result,input,var_args){ +var inputs = null; +if (arguments.length > 2) { +var G__3988__i = 0, G__3988__a = new Array(arguments.length - 2); +while (G__3988__i < G__3988__a.length) {G__3988__a[G__3988__i] = arguments[G__3988__i + 2]; ++G__3988__i;} + inputs = new cljs.core.IndexedSeq(G__3988__a,0,null); +} +return G__3987__delegate.call(this,result,input,inputs);}; +G__3987.cljs$lang$maxFixedArity = 2; +G__3987.cljs$lang$applyTo = (function (arglist__3989){ +var result = cljs.core.first(arglist__3989); +arglist__3989 = cljs.core.next(arglist__3989); +var input = cljs.core.first(arglist__3989); +var inputs = cljs.core.rest(arglist__3989); +return G__3987__delegate(result,input,inputs); +}); +G__3987.cljs$core$IFn$_invoke$arity$variadic = G__3987__delegate; +return G__3987; +})() +; +G__3986 = function(result,input,var_args){ +var inputs = var_args; +switch(arguments.length){ +case 0: +return G__3986__0.call(this); +case 1: +return G__3986__1.call(this,result); +case 2: +return G__3986__2.call(this,result,input); +default: +var G__3990 = null; +if (arguments.length > 2) { +var G__3991__i = 0, G__3991__a = new Array(arguments.length - 2); +while (G__3991__i < G__3991__a.length) {G__3991__a[G__3991__i] = arguments[G__3991__i + 2]; ++G__3991__i;} +G__3990 = new cljs.core.IndexedSeq(G__3991__a,0,null); +} +return G__3986__3.cljs$core$IFn$_invoke$arity$variadic(result,input, G__3990); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3986.cljs$lang$maxFixedArity = 2; +G__3986.cljs$lang$applyTo = G__3986__3.cljs$lang$applyTo; +G__3986.cljs$core$IFn$_invoke$arity$0 = G__3986__0; +G__3986.cljs$core$IFn$_invoke$arity$1 = G__3986__1; +G__3986.cljs$core$IFn$_invoke$arity$2 = G__3986__2; +G__3986.cljs$core$IFn$_invoke$arity$variadic = G__3986__3.cljs$core$IFn$_invoke$arity$variadic; +return G__3986; +})() +}); +}); + +cljs.core.map.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(s)){ +var c = cljs.core.chunk_first(s); +var size = cljs.core.count(c); +var b = cljs.core.chunk_buffer(size); +var n__4607__auto___3992 = size; +var i_3993 = (0); +while(true){ +if((i_3993 < n__4607__auto___3992)){ +cljs.core.chunk_append(b,(function (){var G__3975 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(c,i_3993); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3975) : f.call(null,G__3975)); +})()); + +var G__3994 = (i_3993 + (1)); +i_3993 = G__3994; +continue; +} else { +} +break; +} + +return cljs.core.chunk_cons(cljs.core.chunk(b),cljs.core.map.cljs$core$IFn$_invoke$arity$2(f,cljs.core.chunk_rest(s))); +} else { +return cljs.core.cons((function (){var G__3976 = cljs.core.first(s); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__3976) : f.call(null,G__3976)); +})(),cljs.core.map.cljs$core$IFn$_invoke$arity$2(f,cljs.core.rest(s))); +} +} else { +return null; +} +}),null,null)); +}); + +cljs.core.map.cljs$core$IFn$_invoke$arity$3 = (function (f,c1,c2){ +return (new cljs.core.LazySeq(null,(function (){ +var s1 = cljs.core.seq(c1); +var s2 = cljs.core.seq(c2); +if(((s1) && (s2))){ +return cljs.core.cons((function (){var G__3977 = cljs.core.first(s1); +var G__3978 = cljs.core.first(s2); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__3977,G__3978) : f.call(null,G__3977,G__3978)); +})(),cljs.core.map.cljs$core$IFn$_invoke$arity$3(f,cljs.core.rest(s1),cljs.core.rest(s2))); +} else { +return null; +} +}),null,null)); +}); + +cljs.core.map.cljs$core$IFn$_invoke$arity$4 = (function (f,c1,c2,c3){ +return (new cljs.core.LazySeq(null,(function (){ +var s1 = cljs.core.seq(c1); +var s2 = cljs.core.seq(c2); +var s3 = cljs.core.seq(c3); +if(((s1) && (s2) && (s3))){ +return cljs.core.cons((function (){var G__3979 = cljs.core.first(s1); +var G__3980 = cljs.core.first(s2); +var G__3981 = cljs.core.first(s3); +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__3979,G__3980,G__3981) : f.call(null,G__3979,G__3980,G__3981)); +})(),cljs.core.map.cljs$core$IFn$_invoke$arity$4(f,cljs.core.rest(s1),cljs.core.rest(s2),cljs.core.rest(s3))); +} else { +return null; +} +}),null,null)); +}); + +cljs.core.map.cljs$core$IFn$_invoke$arity$variadic = (function (f,c1,c2,c3,colls){ +var step = (function cljs$core$step(cs){ +return (new cljs.core.LazySeq(null,(function (){ +var ss = cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.seq,cs); +if(cljs.core.every_QMARK_(cljs.core.identity,ss)){ +return cljs.core.cons(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.first,ss),cljs$core$step(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.rest,ss))); +} else { +return null; +} +}),null,null)); +}); +return cljs.core.map.cljs$core$IFn$_invoke$arity$2(((function (step){ +return (function (p1__3963_SHARP_){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(f,p1__3963_SHARP_); +});})(step)) +,step(cljs.core.conj.cljs$core$IFn$_invoke$arity$variadic(colls,c3,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([c2,c1], 0)))); +}); + +/** @this {Function} */ +cljs.core.map.cljs$lang$applyTo = (function (seq3965){ +var G__3966 = cljs.core.first(seq3965); +var seq3965__$1 = cljs.core.next(seq3965); +var G__3967 = cljs.core.first(seq3965__$1); +var seq3965__$2 = cljs.core.next(seq3965__$1); +var G__3968 = cljs.core.first(seq3965__$2); +var seq3965__$3 = cljs.core.next(seq3965__$2); +var G__3969 = cljs.core.first(seq3965__$3); +var seq3965__$4 = cljs.core.next(seq3965__$3); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__3966,G__3967,G__3968,G__3969,seq3965__$4); +}); + +cljs.core.map.cljs$lang$maxFixedArity = (4); + +/** + * Returns a lazy sequence of the first n items in coll, or all items if + * there are fewer than n. Returns a stateful transducer when + * no collection is provided. + */ +cljs.core.take = (function cljs$core$take(var_args){ +var G__3996 = arguments.length; +switch (G__3996) { +case 1: +return cljs.core.take.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.take.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.take.cljs$core$IFn$_invoke$arity$1 = (function (n){ +if(typeof n === 'number'){ +} else { +throw (new Error("Assert failed: (number? n)")); +} + +return (function (rf){ +var na = cljs.core.volatile_BANG_(n); +return ((function (na){ +return (function() { +var G__3998 = null; +var G__3998__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__3998__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__3998__2 = (function (result,input){ +var n__$1 = cljs.core.deref(na); +var nn = na.cljs$core$IVolatile$_vreset_BANG_$arity$2(null,(na.cljs$core$IDeref$_deref$arity$1(null) - (1))); +var result__$1 = (((n__$1 > (0)))?(rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)):result); +if((!((nn > (0))))){ +return cljs.core.ensure_reduced(result__$1); +} else { +return result__$1; +} +}); +G__3998 = function(result,input){ +switch(arguments.length){ +case 0: +return G__3998__0.call(this); +case 1: +return G__3998__1.call(this,result); +case 2: +return G__3998__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__3998.cljs$core$IFn$_invoke$arity$0 = G__3998__0; +G__3998.cljs$core$IFn$_invoke$arity$1 = G__3998__1; +G__3998.cljs$core$IFn$_invoke$arity$2 = G__3998__2; +return G__3998; +})() +;})(na)) +}); +}); + +cljs.core.take.cljs$core$IFn$_invoke$arity$2 = (function (n,coll){ +if(typeof n === 'number'){ +} else { +throw (new Error("Assert failed: (number? n)")); +} + +return (new cljs.core.LazySeq(null,(function (){ +if((n > (0))){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +return cljs.core.cons(cljs.core.first(s),cljs.core.take.cljs$core$IFn$_invoke$arity$2((n - (1)),cljs.core.rest(s))); +} else { +return null; +} +} else { +return null; +} +}),null,null)); +}); + +cljs.core.take.cljs$lang$maxFixedArity = 2; + +/** + * Returns a lazy sequence of all but the first n items in coll. + * Returns a stateful transducer when no collection is provided. + */ +cljs.core.drop = (function cljs$core$drop(var_args){ +var G__4000 = arguments.length; +switch (G__4000) { +case 1: +return cljs.core.drop.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.drop.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.drop.cljs$core$IFn$_invoke$arity$1 = (function (n){ +if(typeof n === 'number'){ +} else { +throw (new Error("Assert failed: (number? n)")); +} + +return (function (rf){ +var na = cljs.core.volatile_BANG_(n); +return ((function (na){ +return (function() { +var G__4002 = null; +var G__4002__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4002__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__4002__2 = (function (result,input){ +var n__$1 = cljs.core.deref(na); +na.cljs$core$IVolatile$_vreset_BANG_$arity$2(null,(na.cljs$core$IDeref$_deref$arity$1(null) - (1))); + +if((n__$1 > (0))){ +return result; +} else { +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} +}); +G__4002 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4002__0.call(this); +case 1: +return G__4002__1.call(this,result); +case 2: +return G__4002__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4002.cljs$core$IFn$_invoke$arity$0 = G__4002__0; +G__4002.cljs$core$IFn$_invoke$arity$1 = G__4002__1; +G__4002.cljs$core$IFn$_invoke$arity$2 = G__4002__2; +return G__4002; +})() +;})(na)) +}); +}); + +cljs.core.drop.cljs$core$IFn$_invoke$arity$2 = (function (n,coll){ +if(typeof n === 'number'){ +} else { +throw (new Error("Assert failed: (number? n)")); +} + +var step = (function (n__$1,coll__$1){ +while(true){ +var s = cljs.core.seq(coll__$1); +if((((n__$1 > (0))) && (s))){ +var G__4003 = (n__$1 - (1)); +var G__4004 = cljs.core.rest(s); +n__$1 = G__4003; +coll__$1 = G__4004; +continue; +} else { +return s; +} +break; +} +}); +return (new cljs.core.LazySeq(null,((function (step){ +return (function (){ +return step(n,coll); +});})(step)) +,null,null)); +}); + +cljs.core.drop.cljs$lang$maxFixedArity = 2; + +/** + * Return a lazy sequence of all but the last n (default 1) items in coll + */ +cljs.core.drop_last = (function cljs$core$drop_last(var_args){ +var G__4006 = arguments.length; +switch (G__4006) { +case 1: +return cljs.core.drop_last.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.drop_last.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.drop_last.cljs$core$IFn$_invoke$arity$1 = (function (s){ +return cljs.core.drop_last.cljs$core$IFn$_invoke$arity$2((1),s); +}); + +cljs.core.drop_last.cljs$core$IFn$_invoke$arity$2 = (function (n,s){ +return cljs.core.map.cljs$core$IFn$_invoke$arity$3((function (x,_){ +return x; +}),s,cljs.core.drop.cljs$core$IFn$_invoke$arity$2(n,s)); +}); + +cljs.core.drop_last.cljs$lang$maxFixedArity = 2; + +/** + * Returns a seq of the last n items in coll. Depending on the type + * of coll may be no better than linear time. For vectors, see also subvec. + */ +cljs.core.take_last = (function cljs$core$take_last(n,coll){ +var s = cljs.core.seq(coll); +var lead = cljs.core.seq(cljs.core.drop.cljs$core$IFn$_invoke$arity$2(n,coll)); +while(true){ +if(lead){ +var G__4008 = cljs.core.next(s); +var G__4009 = cljs.core.next(lead); +s = G__4008; +lead = G__4009; +continue; +} else { +return s; +} +break; +} +}); +/** + * Returns a lazy sequence of the items in coll starting from the + * first item for which (pred item) returns logical false. Returns a + * stateful transducer when no collection is provided. + */ +cljs.core.drop_while = (function cljs$core$drop_while(var_args){ +var G__4011 = arguments.length; +switch (G__4011) { +case 1: +return cljs.core.drop_while.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.drop_while.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.drop_while.cljs$core$IFn$_invoke$arity$1 = (function (pred){ +return (function (rf){ +var da = cljs.core.volatile_BANG_(true); +return ((function (da){ +return (function() { +var G__4015 = null; +var G__4015__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4015__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__4015__2 = (function (result,input){ +var drop_QMARK_ = cljs.core.deref(da); +if(cljs.core.truth_((function (){var and__4120__auto__ = drop_QMARK_; +if(cljs.core.truth_(and__4120__auto__)){ +return (pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(input) : pred.call(null,input)); +} else { +return and__4120__auto__; +} +})())){ +return result; +} else { +cljs.core.vreset_BANG_(da,null); + +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} +}); +G__4015 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4015__0.call(this); +case 1: +return G__4015__1.call(this,result); +case 2: +return G__4015__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4015.cljs$core$IFn$_invoke$arity$0 = G__4015__0; +G__4015.cljs$core$IFn$_invoke$arity$1 = G__4015__1; +G__4015.cljs$core$IFn$_invoke$arity$2 = G__4015__2; +return G__4015; +})() +;})(da)) +}); +}); + +cljs.core.drop_while.cljs$core$IFn$_invoke$arity$2 = (function (pred,coll){ +var step = (function (pred__$1,coll__$1){ +while(true){ +var s = cljs.core.seq(coll__$1); +if(cljs.core.truth_((function (){var and__4120__auto__ = s; +if(and__4120__auto__){ +var G__4013 = cljs.core.first(s); +return (pred__$1.cljs$core$IFn$_invoke$arity$1 ? pred__$1.cljs$core$IFn$_invoke$arity$1(G__4013) : pred__$1.call(null,G__4013)); +} else { +return and__4120__auto__; +} +})())){ +var G__4016 = pred__$1; +var G__4017 = cljs.core.rest(s); +pred__$1 = G__4016; +coll__$1 = G__4017; +continue; +} else { +return s; +} +break; +} +}); +return (new cljs.core.LazySeq(null,((function (step){ +return (function (){ +return step(pred,coll); +});})(step)) +,null,null)); +}); + +cljs.core.drop_while.cljs$lang$maxFixedArity = 2; + + +/** +* @constructor + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IPending} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.Cycle = (function (meta,all,prev,current,_next){ +this.meta = meta; +this.all = all; +this.prev = prev; +this.current = current; +this._next = _next; +this.cljs$lang$protocol_mask$partition0$ = 26083532; +this.cljs$lang$protocol_mask$partition1$ = 1; +}); +cljs.core.Cycle.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.Cycle.prototype.currentval = (function (){ +var self__ = this; +var coll = this; +if(self__.current){ +} else { +var temp__5733__auto___4024 = cljs.core.next(self__.prev); +if(temp__5733__auto___4024){ +var c_4025 = temp__5733__auto___4024; +self__.current = c_4025; +} else { +self__.current = self__.all; +} +} + +return self__.current; +}); + +cljs.core.Cycle.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.Cycle.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ISeq$_rest$arity$1(null); +}); + +cljs.core.Cycle.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.Cycle.prototype.cljs$core$IPending$_realized_QMARK_$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (!((self__.current == null))); +}); + +cljs.core.Cycle.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +var s = coll__$1.currentval(); +var ret = cljs.core.first(s); +while(true){ +var s__$1 = (function (){var or__4131__auto__ = cljs.core.next(s); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return self__.all; +} +})(); +var ret__$1 = (function (){var G__4020 = ret; +var G__4021 = cljs.core.first(s__$1); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__4020,G__4021) : f.call(null,G__4020,G__4021)); +})(); +if(cljs.core.reduced_QMARK_(ret__$1)){ +return cljs.core.deref(ret__$1); +} else { +var G__4026 = s__$1; +var G__4027 = ret__$1; +s = G__4026; +ret = G__4027; +continue; +} +break; +} +}); + +cljs.core.Cycle.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +var s = coll__$1.currentval(); +var ret = start; +while(true){ +var ret__$1 = (function (){var G__4022 = ret; +var G__4023 = cljs.core.first(s); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__4022,G__4023) : f.call(null,G__4022,G__4023)); +})(); +if(cljs.core.reduced_QMARK_(ret__$1)){ +return cljs.core.deref(ret__$1); +} else { +var G__4028 = (function (){var or__4131__auto__ = cljs.core.next(s); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return self__.all; +} +})(); +var G__4029 = ret__$1; +s = G__4028; +ret = G__4029; +continue; +} +break; +} +}); + +cljs.core.Cycle.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.first(coll__$1.currentval()); +}); + +cljs.core.Cycle.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__._next == null)){ +self__._next = (new cljs.core.Cycle(null,self__.all,coll__$1.currentval(),null,null)); +} else { +} + +return self__._next; +}); + +cljs.core.Cycle.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.Cycle.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.Cycle(new_meta,self__.all,self__.prev,self__.current,self__._next)); +} +}); + +cljs.core.Cycle.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.Cycle.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$all,cljs.core.cst$sym$prev,cljs.core.with_meta(cljs.core.cst$sym$current,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$_next,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Cycle.cljs$lang$type = true; + +cljs.core.Cycle.cljs$lang$ctorStr = "cljs.core/Cycle"; + +cljs.core.Cycle.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Cycle"); +}); + +/** + * Positional factory function for cljs.core/Cycle. + */ +cljs.core.__GT_Cycle = (function cljs$core$__GT_Cycle(meta,all,prev,current,_next){ +return (new cljs.core.Cycle(meta,all,prev,current,_next)); +}); + +/** + * Returns a lazy (infinite!) sequence of repetitions of the items in coll. + */ +cljs.core.cycle = (function cljs$core$cycle(coll){ +var temp__5733__auto__ = cljs.core.seq(coll); +if(temp__5733__auto__){ +var vals = temp__5733__auto__; +return (new cljs.core.Cycle(null,vals,null,vals,null)); +} else { +return cljs.core.List.EMPTY; +} +}); +/** + * Returns a vector of [(take n coll) (drop n coll)] + */ +cljs.core.split_at = (function cljs$core$split_at(n,coll){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.take.cljs$core$IFn$_invoke$arity$2(n,coll),cljs.core.drop.cljs$core$IFn$_invoke$arity$2(n,coll)], null); +}); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IPending} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.Repeat = (function (meta,count,val,next,__hash){ +this.meta = meta; +this.count = count; +this.val = val; +this.next = next; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 32374988; +this.cljs$lang$protocol_mask$partition1$ = 1; +}); +cljs.core.Repeat.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.Repeat.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.Repeat.prototype.indexOf = (function() { +var G__4030 = null; +var G__4030__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4030__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4030 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4030__1.call(this,x); +case 2: +return G__4030__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4030.cljs$core$IFn$_invoke$arity$1 = G__4030__1; +G__4030.cljs$core$IFn$_invoke$arity$2 = G__4030__2; +return G__4030; +})() +; + +cljs.core.Repeat.prototype.lastIndexOf = (function() { +var G__4031 = null; +var G__4031__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,self__.count); +}); +var G__4031__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4031 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4031__1.call(this,x); +case 2: +return G__4031__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4031.cljs$core$IFn$_invoke$arity$1 = G__4031__1; +G__4031.cljs$core$IFn$_invoke$arity$2 = G__4031__2; +return G__4031; +})() +; + +cljs.core.Repeat.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.Repeat.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.next == null)){ +if((self__.count > (1))){ +self__.next = (new cljs.core.Repeat(null,(self__.count - (1)),self__.val,null,null)); + +return self__.next; +} else { +if(((-1) === self__.count)){ +return coll__$1; +} else { +return null; +} +} +} else { +return self__.next; +} +}); + +cljs.core.Repeat.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.Repeat.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.Repeat.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.Repeat.prototype.cljs$core$IPending$_realized_QMARK_$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return false; +}); + +cljs.core.Repeat.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +if((self__.count === (-1))){ +var ret = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(self__.val,self__.val) : f.call(null,self__.val,self__.val)); +while(true){ +if(cljs.core.reduced_QMARK_(ret)){ +return cljs.core.deref(ret); +} else { +var G__4032 = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(ret,self__.val) : f.call(null,ret,self__.val)); +ret = G__4032; +continue; +} +break; +} +} else { +var i = (1); +var ret = self__.val; +while(true){ +if((i < self__.count)){ +var ret__$1 = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(ret,self__.val) : f.call(null,ret,self__.val)); +if(cljs.core.reduced_QMARK_(ret__$1)){ +return cljs.core.deref(ret__$1); +} else { +var G__4033 = (i + (1)); +var G__4034 = ret__$1; +i = G__4033; +ret = G__4034; +continue; +} +} else { +return ret; +} +break; +} +} +}); + +cljs.core.Repeat.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +if((self__.count === (-1))){ +var ret = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(start,self__.val) : f.call(null,start,self__.val)); +while(true){ +if(cljs.core.reduced_QMARK_(ret)){ +return cljs.core.deref(ret); +} else { +var G__4035 = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(ret,self__.val) : f.call(null,ret,self__.val)); +ret = G__4035; +continue; +} +break; +} +} else { +var i = (0); +var ret = start; +while(true){ +if((i < self__.count)){ +var ret__$1 = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(ret,self__.val) : f.call(null,ret,self__.val)); +if(cljs.core.reduced_QMARK_(ret__$1)){ +return cljs.core.deref(ret__$1); +} else { +var G__4036 = (i + (1)); +var G__4037 = ret__$1; +i = G__4036; +ret = G__4037; +continue; +} +} else { +return ret; +} +break; +} +} +}); + +cljs.core.Repeat.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.val; +}); + +cljs.core.Repeat.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.next == null)){ +if((self__.count > (1))){ +self__.next = (new cljs.core.Repeat(null,(self__.count - (1)),self__.val,null,null)); + +return self__.next; +} else { +if(((-1) === self__.count)){ +return coll__$1; +} else { +return cljs.core.List.EMPTY; +} +} +} else { +return self__.next; +} +}); + +cljs.core.Repeat.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.Repeat.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.Repeat(new_meta,self__.count,self__.val,self__.next,null)); +} +}); + +cljs.core.Repeat.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.Repeat.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$count,cljs.core.cst$sym$val,cljs.core.with_meta(cljs.core.cst$sym$next,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Repeat.cljs$lang$type = true; + +cljs.core.Repeat.cljs$lang$ctorStr = "cljs.core/Repeat"; + +cljs.core.Repeat.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Repeat"); +}); + +/** + * Positional factory function for cljs.core/Repeat. + */ +cljs.core.__GT_Repeat = (function cljs$core$__GT_Repeat(meta,count,val,next,__hash){ +return (new cljs.core.Repeat(meta,count,val,next,__hash)); +}); + +/** + * Returns a lazy (infinite!, or length n if supplied) sequence of xs. + */ +cljs.core.repeat = (function cljs$core$repeat(var_args){ +var G__4039 = arguments.length; +switch (G__4039) { +case 1: +return cljs.core.repeat.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.repeat.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.repeat.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return (new cljs.core.Repeat(null,(-1),x,null,null)); +}); + +cljs.core.repeat.cljs$core$IFn$_invoke$arity$2 = (function (n,x){ +if((n > (0))){ +return (new cljs.core.Repeat(null,n,x,null,null)); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.repeat.cljs$lang$maxFixedArity = 2; + +/** + * DEPRECATED: Use 'repeat' instead. + * Returns a lazy seq of n xs. + */ +cljs.core.replicate = (function cljs$core$replicate(n,x){ +return cljs.core.take.cljs$core$IFn$_invoke$arity$2(n,cljs.core.repeat.cljs$core$IFn$_invoke$arity$1(x)); +}); +/** + * Takes a function of no args, presumably with side effects, and + * returns an infinite (or length n if supplied) lazy sequence of calls + * to it + */ +cljs.core.repeatedly = (function cljs$core$repeatedly(var_args){ +var G__4042 = arguments.length; +switch (G__4042) { +case 1: +return cljs.core.repeatedly.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.repeatedly.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.repeatedly.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return (new cljs.core.LazySeq(null,(function (){ +return cljs.core.cons((f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)),cljs.core.repeatedly.cljs$core$IFn$_invoke$arity$1(f)); +}),null,null)); +}); + +cljs.core.repeatedly.cljs$core$IFn$_invoke$arity$2 = (function (n,f){ +return cljs.core.take.cljs$core$IFn$_invoke$arity$2(n,cljs.core.repeatedly.cljs$core$IFn$_invoke$arity$1(f)); +}); + +cljs.core.repeatedly.cljs$lang$maxFixedArity = 2; + +cljs.core.UNREALIZED_SEED = ({}); + +/** +* @constructor + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IPending} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.Iterate = (function (meta,f,prev_seed,seed,next){ +this.meta = meta; +this.f = f; +this.prev_seed = prev_seed; +this.seed = seed; +this.next = next; +this.cljs$lang$protocol_mask$partition0$ = 26083532; +this.cljs$lang$protocol_mask$partition1$ = 1; +}); +cljs.core.Iterate.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.Iterate.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.Iterate.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ISeq$_rest$arity$1(null); +}); + +cljs.core.Iterate.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.Iterate.prototype.cljs$core$IPending$_realized_QMARK_$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (!((self__.seed === cljs.core.UNREALIZED_SEED))); +}); + +cljs.core.Iterate.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,rf){ +var self__ = this; +var coll__$1 = this; +var first = coll__$1.cljs$core$ISeq$_first$arity$1(null); +var v = (self__.f.cljs$core$IFn$_invoke$arity$1 ? self__.f.cljs$core$IFn$_invoke$arity$1(first) : self__.f.call(null,first)); +var ret = (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(first,v) : rf.call(null,first,v)); +var v__$1 = v; +while(true){ +if(cljs.core.reduced_QMARK_(ret)){ +return cljs.core.deref(ret); +} else { +var v__$2 = (self__.f.cljs$core$IFn$_invoke$arity$1 ? self__.f.cljs$core$IFn$_invoke$arity$1(v__$1) : self__.f.call(null,v__$1)); +var G__4044 = (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(ret,v__$2) : rf.call(null,ret,v__$2)); +var G__4045 = v__$2; +ret = G__4044; +v__$1 = G__4045; +continue; +} +break; +} +}); + +cljs.core.Iterate.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,rf,start){ +var self__ = this; +var coll__$1 = this; +var v = coll__$1.cljs$core$ISeq$_first$arity$1(null); +var ret = (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(start,v) : rf.call(null,start,v)); +var v__$1 = v; +while(true){ +if(cljs.core.reduced_QMARK_(ret)){ +return cljs.core.deref(ret); +} else { +var v__$2 = (self__.f.cljs$core$IFn$_invoke$arity$1 ? self__.f.cljs$core$IFn$_invoke$arity$1(v__$1) : self__.f.call(null,v__$1)); +var G__4046 = (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(ret,v__$2) : rf.call(null,ret,v__$2)); +var G__4047 = v__$2; +ret = G__4046; +v__$1 = G__4047; +continue; +} +break; +} +}); + +cljs.core.Iterate.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((cljs.core.UNREALIZED_SEED === self__.seed)){ +self__.seed = (self__.f.cljs$core$IFn$_invoke$arity$1 ? self__.f.cljs$core$IFn$_invoke$arity$1(self__.prev_seed) : self__.f.call(null,self__.prev_seed)); +} else { +} + +return self__.seed; +}); + +cljs.core.Iterate.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.next == null)){ +self__.next = (new cljs.core.Iterate(null,self__.f,coll__$1.cljs$core$ISeq$_first$arity$1(null),cljs.core.UNREALIZED_SEED,null)); +} else { +} + +return self__.next; +}); + +cljs.core.Iterate.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.Iterate.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.Iterate(new_meta,self__.f,self__.prev_seed,self__.seed,self__.next)); +} +}); + +cljs.core.Iterate.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.Iterate.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$f,cljs.core.cst$sym$prev_DASH_seed,cljs.core.with_meta(cljs.core.cst$sym$seed,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$next,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Iterate.cljs$lang$type = true; + +cljs.core.Iterate.cljs$lang$ctorStr = "cljs.core/Iterate"; + +cljs.core.Iterate.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Iterate"); +}); + +/** + * Positional factory function for cljs.core/Iterate. + */ +cljs.core.__GT_Iterate = (function cljs$core$__GT_Iterate(meta,f,prev_seed,seed,next){ +return (new cljs.core.Iterate(meta,f,prev_seed,seed,next)); +}); + +/** + * Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects + */ +cljs.core.iterate = (function cljs$core$iterate(f,x){ +return (new cljs.core.Iterate(null,f,null,x,null)); +}); +/** + * Returns a lazy seq of the first item in each coll, then the second etc. + */ +cljs.core.interleave = (function cljs$core$interleave(var_args){ +var G__4052 = arguments.length; +switch (G__4052) { +case 0: +return cljs.core.interleave.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.interleave.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.interleave.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4054 = arguments.length; +var i__4731__auto___4055 = (0); +while(true){ +if((i__4731__auto___4055 < len__4730__auto___4054)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___4055])); + +var G__4056 = (i__4731__auto___4055 + (1)); +i__4731__auto___4055 = G__4056; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((2)),(0),null)); +return cljs.core.interleave.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4752__auto__); + +} +}); + +cljs.core.interleave.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.List.EMPTY; +}); + +cljs.core.interleave.cljs$core$IFn$_invoke$arity$1 = (function (c1){ +return (new cljs.core.LazySeq(null,(function (){ +return c1; +}),null,null)); +}); + +cljs.core.interleave.cljs$core$IFn$_invoke$arity$2 = (function (c1,c2){ +return (new cljs.core.LazySeq(null,(function (){ +var s1 = cljs.core.seq(c1); +var s2 = cljs.core.seq(c2); +if(((s1) && (s2))){ +return cljs.core.cons(cljs.core.first(s1),cljs.core.cons(cljs.core.first(s2),cljs.core.interleave.cljs$core$IFn$_invoke$arity$2(cljs.core.rest(s1),cljs.core.rest(s2)))); +} else { +return null; +} +}),null,null)); +}); + +cljs.core.interleave.cljs$core$IFn$_invoke$arity$variadic = (function (c1,c2,colls){ +return (new cljs.core.LazySeq(null,(function (){ +var ss = cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.seq,cljs.core.conj.cljs$core$IFn$_invoke$arity$variadic(colls,c2,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([c1], 0))); +if(cljs.core.every_QMARK_(cljs.core.identity,ss)){ +return cljs.core.concat.cljs$core$IFn$_invoke$arity$2(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.first,ss),cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.interleave,cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.rest,ss))); +} else { +return null; +} +}),null,null)); +}); + +/** @this {Function} */ +cljs.core.interleave.cljs$lang$applyTo = (function (seq4049){ +var G__4050 = cljs.core.first(seq4049); +var seq4049__$1 = cljs.core.next(seq4049); +var G__4051 = cljs.core.first(seq4049__$1); +var seq4049__$2 = cljs.core.next(seq4049__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4050,G__4051,seq4049__$2); +}); + +cljs.core.interleave.cljs$lang$maxFixedArity = (2); + +/** + * Returns a lazy seq of the elements of coll separated by sep. + * Returns a stateful transducer when no collection is provided. + */ +cljs.core.interpose = (function cljs$core$interpose(var_args){ +var G__4058 = arguments.length; +switch (G__4058) { +case 1: +return cljs.core.interpose.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.interpose.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.interpose.cljs$core$IFn$_invoke$arity$1 = (function (sep){ +return (function (rf){ +var started = cljs.core.volatile_BANG_(false); +return ((function (started){ +return (function() { +var G__4060 = null; +var G__4060__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4060__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__4060__2 = (function (result,input){ +if(cljs.core.truth_(cljs.core.deref(started))){ +var sepr = (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,sep) : rf.call(null,result,sep)); +if(cljs.core.reduced_QMARK_(sepr)){ +return sepr; +} else { +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(sepr,input) : rf.call(null,sepr,input)); +} +} else { +cljs.core.vreset_BANG_(started,true); + +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} +}); +G__4060 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4060__0.call(this); +case 1: +return G__4060__1.call(this,result); +case 2: +return G__4060__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4060.cljs$core$IFn$_invoke$arity$0 = G__4060__0; +G__4060.cljs$core$IFn$_invoke$arity$1 = G__4060__1; +G__4060.cljs$core$IFn$_invoke$arity$2 = G__4060__2; +return G__4060; +})() +;})(started)) +}); +}); + +cljs.core.interpose.cljs$core$IFn$_invoke$arity$2 = (function (sep,coll){ +return cljs.core.drop.cljs$core$IFn$_invoke$arity$2((1),cljs.core.interleave.cljs$core$IFn$_invoke$arity$2(cljs.core.repeat.cljs$core$IFn$_invoke$arity$1(sep),coll)); +}); + +cljs.core.interpose.cljs$lang$maxFixedArity = 2; + +/** + * Take a collection of collections, and return a lazy seq + * of items from the inner collection + */ +cljs.core.flatten1 = (function cljs$core$flatten1(colls){ +var cat = (function cljs$core$flatten1_$_cat(coll,colls__$1){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5733__auto__ = cljs.core.seq(coll); +if(temp__5733__auto__){ +var coll__$1 = temp__5733__auto__; +return cljs.core.cons(cljs.core.first(coll__$1),cljs$core$flatten1_$_cat(cljs.core.rest(coll__$1),colls__$1)); +} else { +if(cljs.core.seq(colls__$1)){ +return cljs$core$flatten1_$_cat(cljs.core.first(colls__$1),cljs.core.rest(colls__$1)); +} else { +return null; +} +} +}),null,null)); +}); +return cat(null,colls); +}); +/** + * Returns the result of applying concat to the result of applying map + * to f and colls. Thus function f should return a collection. Returns + * a transducer when no collections are provided + */ +cljs.core.mapcat = (function cljs$core$mapcat(var_args){ +var G__4064 = arguments.length; +switch (G__4064) { +case 1: +return cljs.core.mapcat.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4066 = arguments.length; +var i__4731__auto___4067 = (0); +while(true){ +if((i__4731__auto___4067 < len__4730__auto___4066)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___4067])); + +var G__4068 = (i__4731__auto___4067 + (1)); +i__4731__auto___4067 = G__4068; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((1)),(0),null)); +return cljs.core.mapcat.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4752__auto__); + +} +}); + +cljs.core.mapcat.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return cljs.core.comp.cljs$core$IFn$_invoke$arity$2(cljs.core.map.cljs$core$IFn$_invoke$arity$1(f),cljs.core.cat); +}); + +cljs.core.mapcat.cljs$core$IFn$_invoke$arity$variadic = (function (f,colls){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.concat,cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.map,f,colls)); +}); + +/** @this {Function} */ +cljs.core.mapcat.cljs$lang$applyTo = (function (seq4062){ +var G__4063 = cljs.core.first(seq4062); +var seq4062__$1 = cljs.core.next(seq4062); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4063,seq4062__$1); +}); + +cljs.core.mapcat.cljs$lang$maxFixedArity = (1); + +/** + * Returns a lazy sequence of the items in coll for which + * (pred item) returns logical true. pred must be free of side-effects. + * Returns a transducer when no collection is provided. + */ +cljs.core.filter = (function cljs$core$filter(var_args){ +var G__4070 = arguments.length; +switch (G__4070) { +case 1: +return cljs.core.filter.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.filter.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.filter.cljs$core$IFn$_invoke$arity$1 = (function (pred){ +return (function (rf){ +return (function() { +var G__4073 = null; +var G__4073__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4073__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__4073__2 = (function (result,input){ +if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(input) : pred.call(null,input)))){ +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} else { +return result; +} +}); +G__4073 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4073__0.call(this); +case 1: +return G__4073__1.call(this,result); +case 2: +return G__4073__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4073.cljs$core$IFn$_invoke$arity$0 = G__4073__0; +G__4073.cljs$core$IFn$_invoke$arity$1 = G__4073__1; +G__4073.cljs$core$IFn$_invoke$arity$2 = G__4073__2; +return G__4073; +})() +}); +}); + +cljs.core.filter.cljs$core$IFn$_invoke$arity$2 = (function (pred,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(s)){ +var c = cljs.core.chunk_first(s); +var size = cljs.core.count(c); +var b = cljs.core.chunk_buffer(size); +var n__4607__auto___4074 = size; +var i_4075 = (0); +while(true){ +if((i_4075 < n__4607__auto___4074)){ +if(cljs.core.truth_((function (){var G__4071 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(c,i_4075); +return (pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(G__4071) : pred.call(null,G__4071)); +})())){ +cljs.core.chunk_append(b,cljs.core._nth.cljs$core$IFn$_invoke$arity$2(c,i_4075)); +} else { +} + +var G__4076 = (i_4075 + (1)); +i_4075 = G__4076; +continue; +} else { +} +break; +} + +return cljs.core.chunk_cons(cljs.core.chunk(b),cljs.core.filter.cljs$core$IFn$_invoke$arity$2(pred,cljs.core.chunk_rest(s))); +} else { +var f = cljs.core.first(s); +var r = cljs.core.rest(s); +if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(f) : pred.call(null,f)))){ +return cljs.core.cons(f,cljs.core.filter.cljs$core$IFn$_invoke$arity$2(pred,r)); +} else { +return cljs.core.filter.cljs$core$IFn$_invoke$arity$2(pred,r); +} +} +} else { +return null; +} +}),null,null)); +}); + +cljs.core.filter.cljs$lang$maxFixedArity = 2; + +/** + * Returns a lazy sequence of the items in coll for which + * (pred item) returns logical false. pred must be free of side-effects. + * Returns a transducer when no collection is provided. + */ +cljs.core.remove = (function cljs$core$remove(var_args){ +var G__4078 = arguments.length; +switch (G__4078) { +case 1: +return cljs.core.remove.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.remove.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.remove.cljs$core$IFn$_invoke$arity$1 = (function (pred){ +return cljs.core.filter.cljs$core$IFn$_invoke$arity$1(cljs.core.complement(pred)); +}); + +cljs.core.remove.cljs$core$IFn$_invoke$arity$2 = (function (pred,coll){ +return cljs.core.filter.cljs$core$IFn$_invoke$arity$2(cljs.core.complement(pred),coll); +}); + +cljs.core.remove.cljs$lang$maxFixedArity = 2; + +/** + * Returns a lazy sequence of the nodes in a tree, via a depth-first walk. + * branch? must be a fn of one arg that returns true if passed a node + * that can have children (but may not). children must be a fn of one + * arg that returns a sequence of the children. Will only be called on + * nodes for which branch? returns true. Root is the root node of the + * tree. + */ +cljs.core.tree_seq = (function cljs$core$tree_seq(branch_QMARK_,children,root){ +var walk = (function cljs$core$tree_seq_$_walk(node){ +return (new cljs.core.LazySeq(null,(function (){ +return cljs.core.cons(node,(cljs.core.truth_((branch_QMARK_.cljs$core$IFn$_invoke$arity$1 ? branch_QMARK_.cljs$core$IFn$_invoke$arity$1(node) : branch_QMARK_.call(null,node)))?cljs.core.mapcat.cljs$core$IFn$_invoke$arity$variadic(cljs$core$tree_seq_$_walk,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([(children.cljs$core$IFn$_invoke$arity$1 ? children.cljs$core$IFn$_invoke$arity$1(node) : children.call(null,node))], 0)):null)); +}),null,null)); +}); +return walk(root); +}); +/** + * Takes any nested combination of sequential things (lists, vectors, + * etc.) and returns their contents as a single, flat sequence. + * (flatten nil) returns nil. + */ +cljs.core.flatten = (function cljs$core$flatten(x){ +return cljs.core.filter.cljs$core$IFn$_invoke$arity$2((function (p1__4080_SHARP_){ +return (!(cljs.core.sequential_QMARK_(p1__4080_SHARP_))); +}),cljs.core.rest(cljs.core.tree_seq(cljs.core.sequential_QMARK_,cljs.core.seq,x))); +}); +/** + * Returns a new coll consisting of to-coll with all of the items of + * from-coll conjoined. A transducer may be supplied. + */ +cljs.core.into = (function cljs$core$into(var_args){ +var G__4082 = arguments.length; +switch (G__4082) { +case 0: +return cljs.core.into.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.into.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.into.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.into.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.into.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.PersistentVector.EMPTY; +}); + +cljs.core.into.cljs$core$IFn$_invoke$arity$1 = (function (to){ +return to; +}); + +cljs.core.into.cljs$core$IFn$_invoke$arity$2 = (function (to,from){ +if((!((to == null)))){ +if((((!((to == null))))?(((((to.cljs$lang$protocol_mask$partition1$ & (4))) || ((cljs.core.PROTOCOL_SENTINEL === to.cljs$core$IEditableCollection$))))?true:false):false)){ +return cljs.core._with_meta(cljs.core.persistent_BANG_(cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._conj_BANG_,cljs.core.transient$(to),from)),cljs.core.meta(to)); +} else { +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._conj,to,from); +} +} else { +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.conj,cljs.core.List.EMPTY,from); +} +}); + +cljs.core.into.cljs$core$IFn$_invoke$arity$3 = (function (to,xform,from){ +if((((!((to == null))))?(((((to.cljs$lang$protocol_mask$partition1$ & (4))) || ((cljs.core.PROTOCOL_SENTINEL === to.cljs$core$IEditableCollection$))))?true:false):false)){ +return cljs.core._with_meta(cljs.core.persistent_BANG_(cljs.core.transduce.cljs$core$IFn$_invoke$arity$4(xform,cljs.core.conj_BANG_,cljs.core.transient$(to),from)),cljs.core.meta(to)); +} else { +return cljs.core.transduce.cljs$core$IFn$_invoke$arity$4(xform,cljs.core.conj,to,from); +} +}); + +cljs.core.into.cljs$lang$maxFixedArity = 3; + +/** + * Returns a vector consisting of the result of applying f to the + * set of first items of each coll, followed by applying f to the set + * of second items in each coll, until any one of the colls is + * exhausted. Any remaining items in other colls are ignored. Function + * f should accept number-of-colls arguments. + */ +cljs.core.mapv = (function cljs$core$mapv(var_args){ +var G__4092 = arguments.length; +switch (G__4092) { +case 2: +return cljs.core.mapv.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.mapv.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.mapv.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4094 = arguments.length; +var i__4731__auto___4095 = (0); +while(true){ +if((i__4731__auto___4095 < len__4730__auto___4094)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___4095])); + +var G__4096 = (i__4731__auto___4095 + (1)); +i__4731__auto___4095 = G__4096; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((4)),(0),null)); +return cljs.core.mapv.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),argseq__4752__auto__); + +} +}); + +cljs.core.mapv.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +return cljs.core.persistent_BANG_(cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (v,o){ +return cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$2(v,(f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(o) : f.call(null,o))); +}),cljs.core.transient$(cljs.core.PersistentVector.EMPTY),coll)); +}); + +cljs.core.mapv.cljs$core$IFn$_invoke$arity$3 = (function (f,c1,c2){ +return cljs.core.into.cljs$core$IFn$_invoke$arity$2(cljs.core.PersistentVector.EMPTY,cljs.core.map.cljs$core$IFn$_invoke$arity$3(f,c1,c2)); +}); + +cljs.core.mapv.cljs$core$IFn$_invoke$arity$4 = (function (f,c1,c2,c3){ +return cljs.core.into.cljs$core$IFn$_invoke$arity$2(cljs.core.PersistentVector.EMPTY,cljs.core.map.cljs$core$IFn$_invoke$arity$4(f,c1,c2,c3)); +}); + +cljs.core.mapv.cljs$core$IFn$_invoke$arity$variadic = (function (f,c1,c2,c3,colls){ +return cljs.core.into.cljs$core$IFn$_invoke$arity$2(cljs.core.PersistentVector.EMPTY,cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(cljs.core.map,f,c1,c2,c3,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([colls], 0))); +}); + +/** @this {Function} */ +cljs.core.mapv.cljs$lang$applyTo = (function (seq4087){ +var G__4088 = cljs.core.first(seq4087); +var seq4087__$1 = cljs.core.next(seq4087); +var G__4089 = cljs.core.first(seq4087__$1); +var seq4087__$2 = cljs.core.next(seq4087__$1); +var G__4090 = cljs.core.first(seq4087__$2); +var seq4087__$3 = cljs.core.next(seq4087__$2); +var G__4091 = cljs.core.first(seq4087__$3); +var seq4087__$4 = cljs.core.next(seq4087__$3); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4088,G__4089,G__4090,G__4091,seq4087__$4); +}); + +cljs.core.mapv.cljs$lang$maxFixedArity = (4); + +/** + * Returns a vector of the items in coll for which + * (pred item) returns logical true. pred must be free of side-effects. + */ +cljs.core.filterv = (function cljs$core$filterv(pred,coll){ +return cljs.core.persistent_BANG_(cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (v,o){ +if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(o) : pred.call(null,o)))){ +return cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$2(v,o); +} else { +return v; +} +}),cljs.core.transient$(cljs.core.PersistentVector.EMPTY),coll)); +}); +/** + * Returns a lazy sequence of lists of n items each, at offsets step + * apart. If step is not supplied, defaults to n, i.e. the partitions + * do not overlap. If a pad collection is supplied, use its elements as + * necessary to complete last partition up to n items. In case there are + * not enough padding elements, return a partition with less than n items. + */ +cljs.core.partition = (function cljs$core$partition(var_args){ +var G__4098 = arguments.length; +switch (G__4098) { +case 2: +return cljs.core.partition.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.partition.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.partition.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.partition.cljs$core$IFn$_invoke$arity$2 = (function (n,coll){ +return cljs.core.partition.cljs$core$IFn$_invoke$arity$3(n,n,coll); +}); + +cljs.core.partition.cljs$core$IFn$_invoke$arity$3 = (function (n,step,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +var p = cljs.core.take.cljs$core$IFn$_invoke$arity$2(n,s); +if((n === cljs.core.count(p))){ +return cljs.core.cons(p,cljs.core.partition.cljs$core$IFn$_invoke$arity$3(n,step,cljs.core.drop.cljs$core$IFn$_invoke$arity$2(step,s))); +} else { +return null; +} +} else { +return null; +} +}),null,null)); +}); + +cljs.core.partition.cljs$core$IFn$_invoke$arity$4 = (function (n,step,pad,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +var p = cljs.core.take.cljs$core$IFn$_invoke$arity$2(n,s); +if((n === cljs.core.count(p))){ +return cljs.core.cons(p,cljs.core.partition.cljs$core$IFn$_invoke$arity$4(n,step,pad,cljs.core.drop.cljs$core$IFn$_invoke$arity$2(step,s))); +} else { +return (new cljs.core.List(null,cljs.core.take.cljs$core$IFn$_invoke$arity$2(n,cljs.core.concat.cljs$core$IFn$_invoke$arity$2(p,pad)),null,(1),null)); +} +} else { +return null; +} +}),null,null)); +}); + +cljs.core.partition.cljs$lang$maxFixedArity = 4; + +/** + * Returns the value in a nested associative structure, + * where ks is a sequence of keys. Returns nil if the key is not present, + * or the not-found value if supplied. + */ +cljs.core.get_in = (function cljs$core$get_in(var_args){ +var G__4101 = arguments.length; +switch (G__4101) { +case 2: +return cljs.core.get_in.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.get_in.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.get_in.cljs$core$IFn$_invoke$arity$2 = (function (m,ks){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.get,m,ks); +}); + +cljs.core.get_in.cljs$core$IFn$_invoke$arity$3 = (function (m,ks,not_found){ +var sentinel = cljs.core.lookup_sentinel; +var m__$1 = m; +var ks__$1 = cljs.core.seq(ks); +while(true){ +if((!((ks__$1 == null)))){ +var m__$2 = cljs.core.get.cljs$core$IFn$_invoke$arity$3(m__$1,cljs.core.first(ks__$1),sentinel); +if((sentinel === m__$2)){ +return not_found; +} else { +var G__4103 = sentinel; +var G__4104 = m__$2; +var G__4105 = cljs.core.next(ks__$1); +sentinel = G__4103; +m__$1 = G__4104; +ks__$1 = G__4105; +continue; +} +} else { +return m__$1; +} +break; +} +}); + +cljs.core.get_in.cljs$lang$maxFixedArity = 3; + +/** + * Associates a value in a nested associative structure, where ks is a + * sequence of keys and v is the new value and returns a new nested structure. + * If any levels do not exist, hash-maps will be created. + */ +cljs.core.assoc_in = (function cljs$core$assoc_in(m,p__4106,v){ +var vec__4107 = p__4106; +var seq__4108 = cljs.core.seq(vec__4107); +var first__4109 = cljs.core.first(seq__4108); +var seq__4108__$1 = cljs.core.next(seq__4108); +var k = first__4109; +var ks = seq__4108__$1; +if(ks){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4110 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +var G__4111 = ks; +var G__4112 = v; +return (cljs.core.assoc_in.cljs$core$IFn$_invoke$arity$3 ? cljs.core.assoc_in.cljs$core$IFn$_invoke$arity$3(G__4110,G__4111,G__4112) : cljs.core.assoc_in.call(null,G__4110,G__4111,G__4112)); +})()); +} else { +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,v); +} +}); +/** + * 'Updates' a value in a nested associative structure, where ks is a + * sequence of keys and f is a function that will take the old value + * and any supplied args and return the new value, and returns a new + * nested structure. If any levels do not exist, hash-maps will be + * created. + */ +cljs.core.update_in = (function cljs$core$update_in(var_args){ +var G__4121 = arguments.length; +switch (G__4121) { +case 3: +return cljs.core.update_in.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.update_in.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core.update_in.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +case 6: +return cljs.core.update_in.cljs$core$IFn$_invoke$arity$6((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4153 = arguments.length; +var i__4731__auto___4154 = (0); +while(true){ +if((i__4731__auto___4154 < len__4730__auto___4153)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___4154])); + +var G__4155 = (i__4731__auto___4154 + (1)); +i__4731__auto___4154 = G__4155; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((6)),(0),null)); +return cljs.core.update_in.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),argseq__4752__auto__); + +} +}); + +cljs.core.update_in.cljs$core$IFn$_invoke$arity$3 = (function (m,p__4122,f){ +var vec__4123 = p__4122; +var seq__4124 = cljs.core.seq(vec__4123); +var first__4125 = cljs.core.first(seq__4124); +var seq__4124__$1 = cljs.core.next(seq__4124); +var k = first__4125; +var ks = seq__4124__$1; +if(ks){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,cljs.core.update_in.cljs$core$IFn$_invoke$arity$3(cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k),ks,f)); +} else { +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4126 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__4126) : f.call(null,G__4126)); +})()); +} +}); + +cljs.core.update_in.cljs$core$IFn$_invoke$arity$4 = (function (m,p__4127,f,a){ +var vec__4128 = p__4127; +var seq__4129 = cljs.core.seq(vec__4128); +var first__4130 = cljs.core.first(seq__4129); +var seq__4129__$1 = cljs.core.next(seq__4129); +var k = first__4130; +var ks = seq__4129__$1; +if(ks){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,cljs.core.update_in.cljs$core$IFn$_invoke$arity$4(cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k),ks,f,a)); +} else { +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4131 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +var G__4132 = a; +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__4131,G__4132) : f.call(null,G__4131,G__4132)); +})()); +} +}); + +cljs.core.update_in.cljs$core$IFn$_invoke$arity$5 = (function (m,p__4133,f,a,b){ +var vec__4134 = p__4133; +var seq__4135 = cljs.core.seq(vec__4134); +var first__4136 = cljs.core.first(seq__4135); +var seq__4135__$1 = cljs.core.next(seq__4135); +var k = first__4136; +var ks = seq__4135__$1; +if(ks){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,cljs.core.update_in.cljs$core$IFn$_invoke$arity$5(cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k),ks,f,a,b)); +} else { +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4137 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +var G__4138 = a; +var G__4139 = b; +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__4137,G__4138,G__4139) : f.call(null,G__4137,G__4138,G__4139)); +})()); +} +}); + +cljs.core.update_in.cljs$core$IFn$_invoke$arity$6 = (function (m,p__4140,f,a,b,c){ +var vec__4141 = p__4140; +var seq__4142 = cljs.core.seq(vec__4141); +var first__4143 = cljs.core.first(seq__4142); +var seq__4142__$1 = cljs.core.next(seq__4142); +var k = first__4143; +var ks = seq__4142__$1; +if(ks){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,cljs.core.update_in.cljs$core$IFn$_invoke$arity$6(cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k),ks,f,a,b,c)); +} else { +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4144 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +var G__4145 = a; +var G__4146 = b; +var G__4147 = c; +return (f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(G__4144,G__4145,G__4146,G__4147) : f.call(null,G__4144,G__4145,G__4146,G__4147)); +})()); +} +}); + +cljs.core.update_in.cljs$core$IFn$_invoke$arity$variadic = (function (m,p__4148,f,a,b,c,args){ +var vec__4149 = p__4148; +var seq__4150 = cljs.core.seq(vec__4149); +var first__4151 = cljs.core.first(seq__4150); +var seq__4150__$1 = cljs.core.next(seq__4150); +var k = first__4151; +var ks = seq__4150__$1; +if(ks){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(cljs.core.update_in,cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k),ks,f,a,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([b,c,args], 0))); +} else { +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(f,cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k),a,b,c,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([args], 0))); +} +}); + +/** @this {Function} */ +cljs.core.update_in.cljs$lang$applyTo = (function (seq4114){ +var G__4115 = cljs.core.first(seq4114); +var seq4114__$1 = cljs.core.next(seq4114); +var G__4116 = cljs.core.first(seq4114__$1); +var seq4114__$2 = cljs.core.next(seq4114__$1); +var G__4117 = cljs.core.first(seq4114__$2); +var seq4114__$3 = cljs.core.next(seq4114__$2); +var G__4118 = cljs.core.first(seq4114__$3); +var seq4114__$4 = cljs.core.next(seq4114__$3); +var G__4119 = cljs.core.first(seq4114__$4); +var seq4114__$5 = cljs.core.next(seq4114__$4); +var G__4120 = cljs.core.first(seq4114__$5); +var seq4114__$6 = cljs.core.next(seq4114__$5); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4115,G__4116,G__4117,G__4118,G__4119,G__4120,seq4114__$6); +}); + +cljs.core.update_in.cljs$lang$maxFixedArity = (6); + +/** + * 'Updates' a value in an associative structure, where k is a + * key and f is a function that will take the old value + * and any supplied args and return the new value, and returns a new + * structure. If the key does not exist, nil is passed as the old value. + */ +cljs.core.update = (function cljs$core$update(var_args){ +var G__4164 = arguments.length; +switch (G__4164) { +case 3: +return cljs.core.update.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.update.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core.update.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +case 6: +return cljs.core.update.cljs$core$IFn$_invoke$arity$6((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4176 = arguments.length; +var i__4731__auto___4177 = (0); +while(true){ +if((i__4731__auto___4177 < len__4730__auto___4176)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___4177])); + +var G__4178 = (i__4731__auto___4177 + (1)); +i__4731__auto___4177 = G__4178; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((6)),(0),null)); +return cljs.core.update.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),argseq__4752__auto__); + +} +}); + +cljs.core.update.cljs$core$IFn$_invoke$arity$3 = (function (m,k,f){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4165 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__4165) : f.call(null,G__4165)); +})()); +}); + +cljs.core.update.cljs$core$IFn$_invoke$arity$4 = (function (m,k,f,x){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4166 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +var G__4167 = x; +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__4166,G__4167) : f.call(null,G__4166,G__4167)); +})()); +}); + +cljs.core.update.cljs$core$IFn$_invoke$arity$5 = (function (m,k,f,x,y){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4168 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +var G__4169 = x; +var G__4170 = y; +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__4168,G__4169,G__4170) : f.call(null,G__4168,G__4169,G__4170)); +})()); +}); + +cljs.core.update.cljs$core$IFn$_invoke$arity$6 = (function (m,k,f,x,y,z){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4171 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +var G__4172 = x; +var G__4173 = y; +var G__4174 = z; +return (f.cljs$core$IFn$_invoke$arity$4 ? f.cljs$core$IFn$_invoke$arity$4(G__4171,G__4172,G__4173,G__4174) : f.call(null,G__4171,G__4172,G__4173,G__4174)); +})()); +}); + +cljs.core.update.cljs$core$IFn$_invoke$arity$variadic = (function (m,k,f,x,y,z,more){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(f,cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k),x,y,z,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([more], 0))); +}); + +/** @this {Function} */ +cljs.core.update.cljs$lang$applyTo = (function (seq4157){ +var G__4158 = cljs.core.first(seq4157); +var seq4157__$1 = cljs.core.next(seq4157); +var G__4159 = cljs.core.first(seq4157__$1); +var seq4157__$2 = cljs.core.next(seq4157__$1); +var G__4160 = cljs.core.first(seq4157__$2); +var seq4157__$3 = cljs.core.next(seq4157__$2); +var G__4161 = cljs.core.first(seq4157__$3); +var seq4157__$4 = cljs.core.next(seq4157__$3); +var G__4162 = cljs.core.first(seq4157__$4); +var seq4157__$5 = cljs.core.next(seq4157__$4); +var G__4163 = cljs.core.first(seq4157__$5); +var seq4157__$6 = cljs.core.next(seq4157__$5); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4158,G__4159,G__4160,G__4161,G__4162,G__4163,seq4157__$6); +}); + +cljs.core.update.cljs$lang$maxFixedArity = (6); + + +/** +* @constructor +*/ +cljs.core.VectorNode = (function (edit,arr){ +this.edit = edit; +this.arr = arr; +}); + +cljs.core.VectorNode.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$edit,cljs.core.cst$sym$arr], null); +}); + +cljs.core.VectorNode.cljs$lang$type = true; + +cljs.core.VectorNode.cljs$lang$ctorStr = "cljs.core/VectorNode"; + +cljs.core.VectorNode.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/VectorNode"); +}); + +/** + * Positional factory function for cljs.core/VectorNode. + */ +cljs.core.__GT_VectorNode = (function cljs$core$__GT_VectorNode(edit,arr){ +return (new cljs.core.VectorNode(edit,arr)); +}); + +cljs.core.pv_fresh_node = (function cljs$core$pv_fresh_node(edit){ +return (new cljs.core.VectorNode(edit,[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])); +}); +cljs.core.pv_aget = (function cljs$core$pv_aget(node,idx){ +return (node.arr[idx]); +}); +cljs.core.pv_aset = (function cljs$core$pv_aset(node,idx,val){ +return (node.arr[idx] = val); +}); +cljs.core.pv_clone_node = (function cljs$core$pv_clone_node(node){ +return (new cljs.core.VectorNode(node.edit,cljs.core.aclone(node.arr))); +}); +cljs.core.tail_off = (function cljs$core$tail_off(pv){ +var cnt = pv.cnt; +if((cnt < (32))){ +return (0); +} else { +return (((cnt - (1)) >>> (5)) << (5)); +} +}); +cljs.core.new_path = (function cljs$core$new_path(edit,level,node){ +var ll = level; +var ret = node; +while(true){ +if((ll === (0))){ +return ret; +} else { +var embed = ret; +var r = cljs.core.pv_fresh_node(edit); +var _ = cljs.core.pv_aset(r,(0),embed); +var G__4179 = (ll - (5)); +var G__4180 = r; +ll = G__4179; +ret = G__4180; +continue; +} +break; +} +}); +cljs.core.push_tail = (function cljs$core$push_tail(pv,level,parent,tailnode){ +var ret = cljs.core.pv_clone_node(parent); +var subidx = (((pv.cnt - (1)) >>> level) & (31)); +if(((5) === level)){ +cljs.core.pv_aset(ret,subidx,tailnode); + +return ret; +} else { +var child = cljs.core.pv_aget(parent,subidx); +if((!((child == null)))){ +var node_to_insert = (function (){var G__4181 = pv; +var G__4182 = (level - (5)); +var G__4183 = child; +var G__4184 = tailnode; +return (cljs.core.push_tail.cljs$core$IFn$_invoke$arity$4 ? cljs.core.push_tail.cljs$core$IFn$_invoke$arity$4(G__4181,G__4182,G__4183,G__4184) : cljs.core.push_tail.call(null,G__4181,G__4182,G__4183,G__4184)); +})(); +cljs.core.pv_aset(ret,subidx,node_to_insert); + +return ret; +} else { +var node_to_insert = cljs.core.new_path(null,(level - (5)),tailnode); +cljs.core.pv_aset(ret,subidx,node_to_insert); + +return ret; +} +} +}); +cljs.core.vector_index_out_of_bounds = (function cljs$core$vector_index_out_of_bounds(i,cnt){ +throw (new Error(["No item ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(i)," in vector of length ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cnt)].join(''))); +}); +cljs.core.first_array_for_longvec = (function cljs$core$first_array_for_longvec(pv){ +var node = pv.root; +var level = pv.shift; +while(true){ +if((level > (0))){ +var G__4185 = cljs.core.pv_aget(node,(0)); +var G__4186 = (level - (5)); +node = G__4185; +level = G__4186; +continue; +} else { +return node.arr; +} +break; +} +}); +cljs.core.unchecked_array_for = (function cljs$core$unchecked_array_for(pv,i){ +if((i >= cljs.core.tail_off(pv))){ +return pv.tail; +} else { +var node = pv.root; +var level = pv.shift; +while(true){ +if((level > (0))){ +var G__4187 = cljs.core.pv_aget(node,((i >>> level) & (31))); +var G__4188 = (level - (5)); +node = G__4187; +level = G__4188; +continue; +} else { +return node.arr; +} +break; +} +} +}); +cljs.core.array_for = (function cljs$core$array_for(pv,i){ +if(((((0) <= i)) && ((i < pv.cnt)))){ +return cljs.core.unchecked_array_for(pv,i); +} else { +return cljs.core.vector_index_out_of_bounds(i,pv.cnt); +} +}); +cljs.core.do_assoc = (function cljs$core$do_assoc(pv,level,node,i,val){ +var ret = cljs.core.pv_clone_node(node); +if((level === (0))){ +cljs.core.pv_aset(ret,(i & (31)),val); + +return ret; +} else { +var subidx = ((i >>> level) & (31)); +cljs.core.pv_aset(ret,subidx,(function (){var G__4189 = pv; +var G__4190 = (level - (5)); +var G__4191 = cljs.core.pv_aget(node,subidx); +var G__4192 = i; +var G__4193 = val; +return (cljs.core.do_assoc.cljs$core$IFn$_invoke$arity$5 ? cljs.core.do_assoc.cljs$core$IFn$_invoke$arity$5(G__4189,G__4190,G__4191,G__4192,G__4193) : cljs.core.do_assoc.call(null,G__4189,G__4190,G__4191,G__4192,G__4193)); +})()); + +return ret; +} +}); +cljs.core.pop_tail = (function cljs$core$pop_tail(pv,level,node){ +var subidx = (((pv.cnt - (2)) >>> level) & (31)); +if((level > (5))){ +var new_child = (function (){var G__4194 = pv; +var G__4195 = (level - (5)); +var G__4196 = cljs.core.pv_aget(node,subidx); +return (cljs.core.pop_tail.cljs$core$IFn$_invoke$arity$3 ? cljs.core.pop_tail.cljs$core$IFn$_invoke$arity$3(G__4194,G__4195,G__4196) : cljs.core.pop_tail.call(null,G__4194,G__4195,G__4196)); +})(); +if((((new_child == null)) && ((subidx === (0))))){ +return null; +} else { +var ret = cljs.core.pv_clone_node(node); +cljs.core.pv_aset(ret,subidx,new_child); + +return ret; +} +} else { +if((subidx === (0))){ +return null; +} else { +var ret = cljs.core.pv_clone_node(node); +cljs.core.pv_aset(ret,subidx,null); + +return ret; + +} +} +}); + +/** +* @constructor +*/ +cljs.core.RangedIterator = (function (i,base,arr,v,start,end){ +this.i = i; +this.base = base; +this.arr = arr; +this.v = v; +this.start = start; +this.end = end; +}); +cljs.core.RangedIterator.prototype.hasNext = (function (){ +var self__ = this; +var this$ = this; +return (self__.i < self__.end); +}); + +cljs.core.RangedIterator.prototype.next = (function (){ +var self__ = this; +var this$ = this; +if(((self__.i - self__.base) === (32))){ +self__.arr = cljs.core.unchecked_array_for(self__.v,self__.i); + +self__.base = (self__.base + (32)); +} else { +} + +var ret = (self__.arr[(self__.i & (31))]); +self__.i = (self__.i + (1)); + +return ret; +}); + +cljs.core.RangedIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 6, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$base,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$arr,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.cst$sym$v,cljs.core.cst$sym$start,cljs.core.cst$sym$end], null); +}); + +cljs.core.RangedIterator.cljs$lang$type = true; + +cljs.core.RangedIterator.cljs$lang$ctorStr = "cljs.core/RangedIterator"; + +cljs.core.RangedIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/RangedIterator"); +}); + +/** + * Positional factory function for cljs.core/RangedIterator. + */ +cljs.core.__GT_RangedIterator = (function cljs$core$__GT_RangedIterator(i,base,arr,v,start,end){ +return (new cljs.core.RangedIterator(i,base,arr,v,start,end)); +}); + +cljs.core.ranged_iterator = (function cljs$core$ranged_iterator(v,start,end){ +var i = start; +return (new cljs.core.RangedIterator(i,(i - (i % (32))),(((start < cljs.core.count(v)))?cljs.core.unchecked_array_for(v,i):null),v,start,end)); +}); +cljs.core.pv_reduce = (function cljs$core$pv_reduce(var_args){ +var G__4198 = arguments.length; +switch (G__4198) { +case 4: +return cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$4 = (function (pv,f,start,end){ +if((start < end)){ +return cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$5(pv,f,cljs.core.nth.cljs$core$IFn$_invoke$arity$2(pv,start),(start + (1)),end); +} else { +return (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); +} +}); + +cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$5 = (function (pv,f,init,start,end){ +var acc = init; +var i = start; +var arr = cljs.core.unchecked_array_for(pv,start); +while(true){ +if((i < end)){ +var j = (i & (31)); +var arr__$1 = (((j === (0)))?cljs.core.unchecked_array_for(pv,i):arr); +var nacc = (function (){var G__4199 = acc; +var G__4200 = (arr__$1[j]); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__4199,G__4200) : f.call(null,G__4199,G__4200)); +})(); +if(cljs.core.reduced_QMARK_(nacc)){ +return cljs.core.deref(nacc); +} else { +var G__4202 = nacc; +var G__4203 = (i + (1)); +var G__4204 = arr__$1; +acc = G__4202; +i = G__4203; +arr = G__4204; +continue; +} +} else { +return acc; +} +break; +} +}); + +cljs.core.pv_reduce.cljs$lang$maxFixedArity = 5; + + + + + + + + +/** + * Marker protocol + * @interface + */ +cljs.core.APersistentVector = function(){}; + + +/** +* @constructor + * @implements {cljs.core.APersistentVector} + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.IVector} + * @implements {cljs.core.IReversible} + * @implements {cljs.core.IKVReduce} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEditableCollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IStack} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.ILookup} + * @implements {cljs.core.IReduce} +*/ +cljs.core.PersistentVector = (function (meta,cnt,shift,root,tail,__hash){ +this.meta = meta; +this.cnt = cnt; +this.shift = shift; +this.root = root; +this.tail = tail; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 167666463; +this.cljs$lang$protocol_mask$partition1$ = 139268; +}); +cljs.core.PersistentVector.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentVector.prototype.cljs$core$IFind$_find$arity$2 = (function (coll,n){ +var self__ = this; +var coll__$1 = this; +if(((((0) <= n)) && ((n < self__.cnt)))){ +return (new cljs.core.MapEntry(n,(cljs.core.unchecked_array_for(coll__$1,n)[(n & (31))]),null)); +} else { +return null; +} +}); + +cljs.core.PersistentVector.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentVector.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentVector.prototype.indexOf = (function() { +var G__4211 = null; +var G__4211__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4211__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4211 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4211__1.call(this,x); +case 2: +return G__4211__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4211.cljs$core$IFn$_invoke$arity$1 = G__4211__1; +G__4211.cljs$core$IFn$_invoke$arity$2 = G__4211__2; +return G__4211; +})() +; + +cljs.core.PersistentVector.prototype.lastIndexOf = (function() { +var G__4212 = null; +var G__4212__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4212__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4212 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4212__1.call(this,x); +case 2: +return G__4212__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4212.cljs$core$IFn$_invoke$arity$1 = G__4212__1; +G__4212.cljs$core$IFn$_invoke$arity$2 = G__4212__2; +return G__4212; +})() +; + +cljs.core.PersistentVector.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,k,null); +}); + +cljs.core.PersistentVector.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,k,not_found){ +var self__ = this; +var coll__$1 = this; +if(typeof k === 'number'){ +return coll__$1.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +} else { +return not_found; +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IKVReduce$_kv_reduce$arity$3 = (function (v,f,init){ +var self__ = this; +var v__$1 = this; +var i = (0); +var init__$1 = init; +while(true){ +if((i < self__.cnt)){ +var arr = cljs.core.unchecked_array_for(v__$1,i); +var len = arr.length; +var init__$2 = (function (){var j = (0); +var init__$2 = init__$1; +while(true){ +if((j < len)){ +var init__$3 = (function (){var G__4206 = init__$2; +var G__4207 = (j + i); +var G__4208 = (arr[j]); +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__4206,G__4207,G__4208) : f.call(null,G__4206,G__4207,G__4208)); +})(); +if(cljs.core.reduced_QMARK_(init__$3)){ +return init__$3; +} else { +var G__4213 = (j + (1)); +var G__4214 = init__$3; +j = G__4213; +init__$2 = G__4214; +continue; +} +} else { +return init__$2; +} +break; +} +})(); +if(cljs.core.reduced_QMARK_(init__$2)){ +return cljs.core.deref(init__$2); +} else { +var G__4215 = (i + len); +var G__4216 = init__$2; +i = G__4215; +init__$1 = G__4216; +continue; +} +} else { +return init__$1; +} +break; +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$APersistentVector$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentVector.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (coll,n){ +var self__ = this; +var coll__$1 = this; +return (cljs.core.array_for(coll__$1,n)[(n & (31))]); +}); + +cljs.core.PersistentVector.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (coll,n,not_found){ +var self__ = this; +var coll__$1 = this; +if(((((0) <= n)) && ((n < self__.cnt)))){ +return (cljs.core.unchecked_array_for(coll__$1,n)[(n & (31))]); +} else { +return not_found; +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IVector$_assoc_n$arity$3 = (function (coll,n,val){ +var self__ = this; +var coll__$1 = this; +if(((((0) <= n)) && ((n < self__.cnt)))){ +if((cljs.core.tail_off(coll__$1) <= n)){ +var new_tail = cljs.core.aclone(self__.tail); +(new_tail[(n & (31))] = val); + +return (new cljs.core.PersistentVector(self__.meta,self__.cnt,self__.shift,self__.root,new_tail,null)); +} else { +return (new cljs.core.PersistentVector(self__.meta,self__.cnt,self__.shift,cljs.core.do_assoc(coll__$1,self__.shift,self__.root,n,val),self__.tail,null)); +} +} else { +if((n === self__.cnt)){ +return coll__$1.cljs$core$ICollection$_conj$arity$2(null,val); +} else { +throw (new Error(["Index ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(n)," out of bounds [0,",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.cnt),"]"].join(''))); + +} +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return cljs.core.ranged_iterator(this$__$1,(0),self__.cnt); +}); + +cljs.core.PersistentVector.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentVector.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.PersistentVector(self__.meta,self__.cnt,self__.shift,self__.root,self__.tail,self__.__hash)); +}); + +cljs.core.PersistentVector.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.cnt; +}); + +cljs.core.PersistentVector.prototype.cljs$core$IStack$_peek$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt > (0))){ +return coll__$1.cljs$core$IIndexed$_nth$arity$2(null,(self__.cnt - (1))); +} else { +return null; +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IStack$_pop$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt === (0))){ +throw (new Error("Can't pop empty vector")); +} else { +if(((1) === self__.cnt)){ +return cljs.core._with_meta(cljs.core.PersistentVector.EMPTY,self__.meta); +} else { +if(((1) < (self__.cnt - cljs.core.tail_off(coll__$1)))){ +return (new cljs.core.PersistentVector(self__.meta,(self__.cnt - (1)),self__.shift,self__.root,self__.tail.slice((0),(-1)),null)); +} else { +var new_tail = cljs.core.unchecked_array_for(coll__$1,(self__.cnt - (2))); +var nr = cljs.core.pop_tail(coll__$1,self__.shift,self__.root); +var new_root = (((nr == null))?cljs.core.PersistentVector.EMPTY_NODE:nr); +var cnt_1 = (self__.cnt - (1)); +if(((((5) < self__.shift)) && ((cljs.core.pv_aget(new_root,(1)) == null)))){ +return (new cljs.core.PersistentVector(self__.meta,cnt_1,(self__.shift - (5)),cljs.core.pv_aget(new_root,(0)),new_tail,null)); +} else { +return (new cljs.core.PersistentVector(self__.meta,cnt_1,self__.shift,new_root,new_tail,null)); +} + +} +} +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IReversible$_rseq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt > (0))){ +return (new cljs.core.RSeq(coll__$1,(self__.cnt - (1)),null)); +} else { +return null; +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +if((other instanceof cljs.core.PersistentVector)){ +if((self__.cnt === cljs.core.count(other))){ +var me_iter = coll__$1.cljs$core$IIterable$_iterator$arity$1(null); +var you_iter = other.cljs$core$IIterable$_iterator$arity$1(null); +while(true){ +if(me_iter.hasNext()){ +var x = me_iter.next(); +var y = you_iter.next(); +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(x,y)){ +continue; +} else { +return false; +} +} else { +return true; +} +break; +} +} else { +return false; +} +} else { +return cljs.core.equiv_sequential(coll__$1,other); +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IEditableCollection$_as_transient$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.TransientVector(self__.cnt,self__.shift,cljs.core.tv_editable_root(self__.root),cljs.core.tv_editable_tail(self__.tail))); +}); + +cljs.core.PersistentVector.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.PersistentVector.EMPTY,self__.meta); +}); + +cljs.core.PersistentVector.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (v,f){ +var self__ = this; +var v__$1 = this; +return cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$4(v__$1,f,(0),self__.cnt); +}); + +cljs.core.PersistentVector.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (v,f,init){ +var self__ = this; +var v__$1 = this; +var i = (0); +var init__$1 = init; +while(true){ +if((i < self__.cnt)){ +var arr = cljs.core.unchecked_array_for(v__$1,i); +var len = arr.length; +var init__$2 = (function (){var j = (0); +var init__$2 = init__$1; +while(true){ +if((j < len)){ +var init__$3 = (function (){var G__4209 = init__$2; +var G__4210 = (arr[j]); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__4209,G__4210) : f.call(null,G__4209,G__4210)); +})(); +if(cljs.core.reduced_QMARK_(init__$3)){ +return init__$3; +} else { +var G__4217 = (j + (1)); +var G__4218 = init__$3; +j = G__4217; +init__$2 = G__4218; +continue; +} +} else { +return init__$2; +} +break; +} +})(); +if(cljs.core.reduced_QMARK_(init__$2)){ +return cljs.core.deref(init__$2); +} else { +var G__4219 = (i + len); +var G__4220 = init__$2; +i = G__4219; +init__$1 = G__4220; +continue; +} +} else { +return init__$1; +} +break; +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (coll,k,v){ +var self__ = this; +var coll__$1 = this; +if(typeof k === 'number'){ +return coll__$1.cljs$core$IVector$_assoc_n$arity$3(null,k,v); +} else { +throw (new Error("Vector's key for assoc must be a number.")); +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +if(cljs.core.integer_QMARK_(k)){ +return ((((0) <= k)) && ((k < self__.cnt))); +} else { +return false; +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt === (0))){ +return null; +} else { +if((self__.cnt <= (32))){ +return (new cljs.core.IndexedSeq(self__.tail,(0),null)); +} else { +return cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$4(coll__$1,cljs.core.first_array_for_longvec(coll__$1),(0),(0)); + +} +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentVector(new_meta,self__.cnt,self__.shift,self__.root,self__.tail,self__.__hash)); +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +if(((self__.cnt - cljs.core.tail_off(coll__$1)) < (32))){ +var len = self__.tail.length; +var new_tail = (new Array((len + (1)))); +var n__4607__auto___4221 = len; +var i_4222 = (0); +while(true){ +if((i_4222 < n__4607__auto___4221)){ +(new_tail[i_4222] = (self__.tail[i_4222])); + +var G__4223 = (i_4222 + (1)); +i_4222 = G__4223; +continue; +} else { +} +break; +} + +(new_tail[len] = o); + +return (new cljs.core.PersistentVector(self__.meta,(self__.cnt + (1)),self__.shift,self__.root,new_tail,null)); +} else { +var root_overflow_QMARK_ = ((self__.cnt >>> (5)) > ((1) << self__.shift)); +var new_shift = ((root_overflow_QMARK_)?(self__.shift + (5)):self__.shift); +var new_root = ((root_overflow_QMARK_)?(function (){var n_r = cljs.core.pv_fresh_node(null); +cljs.core.pv_aset(n_r,(0),self__.root); + +cljs.core.pv_aset(n_r,(1),cljs.core.new_path(null,self__.shift,(new cljs.core.VectorNode(null,self__.tail)))); + +return n_r; +})():cljs.core.push_tail(coll__$1,self__.shift,self__.root,(new cljs.core.VectorNode(null,self__.tail)))); +return (new cljs.core.PersistentVector(self__.meta,(self__.cnt + (1)),new_shift,new_root,[o],null)); +} +}); + +cljs.core.PersistentVector.prototype.call = (function() { +var G__4224 = null; +var G__4224__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$IIndexed$_nth$arity$2(null,k); +}); +var G__4224__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); +G__4224 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4224__2.call(this,self__,k); +case 3: +return G__4224__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4224.cljs$core$IFn$_invoke$arity$2 = G__4224__2; +G__4224.cljs$core$IFn$_invoke$arity$3 = G__4224__3; +return G__4224; +})() +; + +cljs.core.PersistentVector.prototype.apply = (function (self__,args4205){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4205))); +}); + +cljs.core.PersistentVector.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$IIndexed$_nth$arity$2(null,k); +}); + +cljs.core.PersistentVector.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); + +cljs.core.PersistentVector.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 6, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$cnt,cljs.core.cst$sym$shift,cljs.core.cst$sym$root,cljs.core.cst$sym$tail,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentVector.cljs$lang$type = true; + +cljs.core.PersistentVector.cljs$lang$ctorStr = "cljs.core/PersistentVector"; + +cljs.core.PersistentVector.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentVector"); +}); + +/** + * Positional factory function for cljs.core/PersistentVector. + */ +cljs.core.__GT_PersistentVector = (function cljs$core$__GT_PersistentVector(meta,cnt,shift,root,tail,__hash){ +return (new cljs.core.PersistentVector(meta,cnt,shift,root,tail,__hash)); +}); + +cljs.core.PersistentVector.EMPTY_NODE = (new cljs.core.VectorNode(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])); +cljs.core.PersistentVector.EMPTY = (new cljs.core.PersistentVector(null,(0),(5),cljs.core.PersistentVector.EMPTY_NODE,[],cljs.core.empty_ordered_hash)); +cljs.core.PersistentVector.fromArray = (function (xs,no_clone){ +var l = xs.length; +var xs__$1 = ((no_clone)?xs:cljs.core.aclone(xs)); +if((l < (32))){ +return (new cljs.core.PersistentVector(null,l,(5),cljs.core.PersistentVector.EMPTY_NODE,xs__$1,null)); +} else { +var node = xs__$1.slice((0),(32)); +var v = (new cljs.core.PersistentVector(null,(32),(5),cljs.core.PersistentVector.EMPTY_NODE,node,null)); +var i = (32); +var out = v.cljs$core$IEditableCollection$_as_transient$arity$1(null); +while(true){ +if((i < l)){ +var G__4225 = (i + (1)); +var G__4226 = cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$2(out,(xs__$1[i])); +i = G__4225; +out = G__4226; +continue; +} else { +return cljs.core.persistent_BANG_(out); +} +break; +} +} +}); +var G__4227_4230 = cljs.core.PersistentVector.prototype; +var G__4228_4231 = cljs.core.ITER_SYMBOL; +var G__4229_4232 = ((function (G__4227_4230,G__4228_4231){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4227_4230,G__4228_4231)) +; +goog.object.set(G__4227_4230,G__4228_4231,G__4229_4232); +/** + * Creates a new vector containing the contents of coll. JavaScript arrays + * will be aliased and should not be modified. + */ +cljs.core.vec = (function cljs$core$vec(coll){ +if(cljs.core.map_entry_QMARK_(coll)){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.key(coll),cljs.core.val(coll)], null); +} else { +if(cljs.core.vector_QMARK_(coll)){ +return cljs.core.with_meta(coll,null); +} else { +if(cljs.core.array_QMARK_(coll)){ +return cljs.core.PersistentVector.fromArray(coll,true); +} else { +return cljs.core._persistent_BANG_(cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._conj_BANG_,cljs.core._as_transient(cljs.core.PersistentVector.EMPTY),coll)); + +} +} +} +}); +/** + * Creates a new vector containing the args. + */ +cljs.core.vector = (function cljs$core$vector(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4234 = arguments.length; +var i__4731__auto___4235 = (0); +while(true){ +if((i__4731__auto___4235 < len__4730__auto___4234)){ +args__4736__auto__.push((arguments[i__4731__auto___4235])); + +var G__4236 = (i__4731__auto___4235 + (1)); +i__4731__auto___4235 = G__4236; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.vector.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.vector.cljs$core$IFn$_invoke$arity$variadic = (function (args){ +if((((args instanceof cljs.core.IndexedSeq)) && ((args.i === (0))))){ +return cljs.core.PersistentVector.fromArray(args.arr,true); +} else { +return cljs.core.vec(args); +} +}); + +cljs.core.vector.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.vector.cljs$lang$applyTo = (function (seq4233){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq4233)); +}); + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ASeq} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IChunkedNext} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IChunkedSeq} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.ChunkedSeq = (function (vec,node,i,off,meta,__hash){ +this.vec = vec; +this.node = node; +this.i = i; +this.off = off; +this.meta = meta; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 32375020; +this.cljs$lang$protocol_mask$partition1$ = 1536; +}); +cljs.core.ChunkedSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.ChunkedSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.ChunkedSeq.prototype.indexOf = (function() { +var G__4237 = null; +var G__4237__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4237__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4237 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4237__1.call(this,x); +case 2: +return G__4237__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4237.cljs$core$IFn$_invoke$arity$1 = G__4237__1; +G__4237.cljs$core$IFn$_invoke$arity$2 = G__4237__2; +return G__4237; +})() +; + +cljs.core.ChunkedSeq.prototype.lastIndexOf = (function() { +var G__4238 = null; +var G__4238__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4238__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4238 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4238__1.call(this,x); +case 2: +return G__4238__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4238.cljs$core$IFn$_invoke$arity$1 = G__4238__1; +G__4238.cljs$core$IFn$_invoke$arity$2 = G__4238__2; +return G__4238; +})() +; + +cljs.core.ChunkedSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if(((self__.off + (1)) < self__.node.length)){ +var s = cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$4(self__.vec,self__.node,self__.i,(self__.off + (1))); +if((s == null)){ +return null; +} else { +return s; +} +} else { +return coll__$1.cljs$core$IChunkedNext$_chunked_next$arity$1(null); +} +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$4(self__.vec,f,(self__.i + self__.off),cljs.core.count(self__.vec)); +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$5(self__.vec,f,start,(self__.i + self__.off),cljs.core.count(self__.vec)); +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (self__.node[self__.off]); +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if(((self__.off + (1)) < self__.node.length)){ +var s = cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$4(self__.vec,self__.node,self__.i,(self__.off + (1))); +if((s == null)){ +return cljs.core.List.EMPTY; +} else { +return s; +} +} else { +return coll__$1.cljs$core$IChunkedSeq$_chunked_rest$arity$1(null); +} +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IChunkedSeq$_chunked_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.array_chunk.cljs$core$IFn$_invoke$arity$2(self__.node,self__.off); +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IChunkedSeq$_chunked_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var end = (self__.i + self__.node.length); +if((end < cljs.core._count(self__.vec))){ +return cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$4(self__.vec,cljs.core.unchecked_array_for(self__.vec,end),end,(0)); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$5(self__.vec,self__.node,self__.i,self__.off,new_meta); +} +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IChunkedNext$_chunked_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var end = (self__.i + self__.node.length); +if((end < cljs.core._count(self__.vec))){ +return cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$4(self__.vec,cljs.core.unchecked_array_for(self__.vec,end),end,(0)); +} else { +return null; +} +}); + +cljs.core.ChunkedSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 6, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$vec,cljs.core.cst$sym$node,cljs.core.cst$sym$i,cljs.core.cst$sym$off,cljs.core.cst$sym$meta,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ChunkedSeq.cljs$lang$type = true; + +cljs.core.ChunkedSeq.cljs$lang$ctorStr = "cljs.core/ChunkedSeq"; + +cljs.core.ChunkedSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ChunkedSeq"); +}); + +/** + * Positional factory function for cljs.core/ChunkedSeq. + */ +cljs.core.__GT_ChunkedSeq = (function cljs$core$__GT_ChunkedSeq(vec,node,i,off,meta,__hash){ +return (new cljs.core.ChunkedSeq(vec,node,i,off,meta,__hash)); +}); + +var G__4239_4242 = cljs.core.ChunkedSeq.prototype; +var G__4240_4243 = cljs.core.ITER_SYMBOL; +var G__4241_4244 = ((function (G__4239_4242,G__4240_4243){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4239_4242,G__4240_4243)) +; +goog.object.set(G__4239_4242,G__4240_4243,G__4241_4244); +cljs.core.chunked_seq = (function cljs$core$chunked_seq(var_args){ +var G__4246 = arguments.length; +switch (G__4246) { +case 3: +return cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 4: +return cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 5: +return cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$3 = (function (vec,i,off){ +return (new cljs.core.ChunkedSeq(vec,cljs.core.array_for(vec,i),i,off,null,null)); +}); + +cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$4 = (function (vec,node,i,off){ +return (new cljs.core.ChunkedSeq(vec,node,i,off,null,null)); +}); + +cljs.core.chunked_seq.cljs$core$IFn$_invoke$arity$5 = (function (vec,node,i,off,meta){ +return (new cljs.core.ChunkedSeq(vec,node,i,off,meta,null)); +}); + +cljs.core.chunked_seq.cljs$lang$maxFixedArity = 5; + + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.IVector} + * @implements {cljs.core.IReversible} + * @implements {cljs.core.IKVReduce} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IStack} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.ILookup} + * @implements {cljs.core.IReduce} +*/ +cljs.core.Subvec = (function (meta,v,start,end,__hash){ +this.meta = meta; +this.v = v; +this.start = start; +this.end = end; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 167666463; +this.cljs$lang$protocol_mask$partition1$ = 139264; +}); +cljs.core.Subvec.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Subvec.prototype.cljs$core$IFind$_find$arity$2 = (function (coll,n){ +var self__ = this; +var coll__$1 = this; +if((n < (0))){ +return null; +} else { +var idx = (self__.start + n); +if((idx < self__.end)){ +return (new cljs.core.MapEntry(n,cljs.core._lookup.cljs$core$IFn$_invoke$arity$2(self__.v,idx),null)); +} else { +return null; +} +} +}); + +cljs.core.Subvec.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.Subvec.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.Subvec.prototype.indexOf = (function() { +var G__4255 = null; +var G__4255__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4255__2 = (function (x,start__$1){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start__$1); +}); +G__4255 = function(x,start__$1){ +switch(arguments.length){ +case 1: +return G__4255__1.call(this,x); +case 2: +return G__4255__2.call(this,x,start__$1); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4255.cljs$core$IFn$_invoke$arity$1 = G__4255__1; +G__4255.cljs$core$IFn$_invoke$arity$2 = G__4255__2; +return G__4255; +})() +; + +cljs.core.Subvec.prototype.lastIndexOf = (function() { +var G__4256 = null; +var G__4256__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4256__2 = (function (x,start__$1){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start__$1); +}); +G__4256 = function(x,start__$1){ +switch(arguments.length){ +case 1: +return G__4256__1.call(this,x); +case 2: +return G__4256__2.call(this,x,start__$1); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4256.cljs$core$IFn$_invoke$arity$1 = G__4256__1; +G__4256.cljs$core$IFn$_invoke$arity$2 = G__4256__2; +return G__4256; +})() +; + +cljs.core.Subvec.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,k,null); +}); + +cljs.core.Subvec.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,k,not_found){ +var self__ = this; +var coll__$1 = this; +if(typeof k === 'number'){ +return coll__$1.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +} else { +return not_found; +} +}); + +cljs.core.Subvec.prototype.cljs$core$IKVReduce$_kv_reduce$arity$3 = (function (coll,f,init){ +var self__ = this; +var coll__$1 = this; +var i = self__.start; +var j = (0); +var init__$1 = init; +while(true){ +if((i < self__.end)){ +var init__$2 = (function (){var G__4249 = init__$1; +var G__4250 = j; +var G__4251 = cljs.core._nth.cljs$core$IFn$_invoke$arity$2(self__.v,i); +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__4249,G__4250,G__4251) : f.call(null,G__4249,G__4250,G__4251)); +})(); +if(cljs.core.reduced_QMARK_(init__$2)){ +return cljs.core.deref(init__$2); +} else { +var G__4257 = (i + (1)); +var G__4258 = (j + (1)); +var G__4259 = init__$2; +i = G__4257; +j = G__4258; +init__$1 = G__4259; +continue; +} +} else { +return init__$1; +} +break; +} +}); + +cljs.core.Subvec.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (coll,n){ +var self__ = this; +var coll__$1 = this; +if((((n < (0))) || ((self__.end <= (self__.start + n))))){ +return cljs.core.vector_index_out_of_bounds(n,(self__.end - self__.start)); +} else { +return cljs.core._nth.cljs$core$IFn$_invoke$arity$2(self__.v,(self__.start + n)); +} +}); + +cljs.core.Subvec.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (coll,n,not_found){ +var self__ = this; +var coll__$1 = this; +if((((n < (0))) || ((self__.end <= (self__.start + n))))){ +return not_found; +} else { +return cljs.core._nth.cljs$core$IFn$_invoke$arity$3(self__.v,(self__.start + n),not_found); +} +}); + +cljs.core.Subvec.prototype.cljs$core$IVector$_assoc_n$arity$3 = (function (coll,n,val){ +var self__ = this; +var coll__$1 = this; +var v_pos = (self__.start + n); +if((((n < (0))) || (((self__.end + (1)) <= v_pos)))){ +throw (new Error(["Index ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(n)," out of bounds [0,",cljs.core.str.cljs$core$IFn$_invoke$arity$1(coll__$1.cljs$core$ICounted$_count$arity$1(null)),"]"].join(''))); +} else { +return cljs.core.build_subvec(self__.meta,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(self__.v,v_pos,val),self__.start,(function (){var x__4219__auto__ = self__.end; +var y__4220__auto__ = (v_pos + (1)); +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +})(),null); +} +}); + +cljs.core.Subvec.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((((!((self__.v == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === self__.v.cljs$core$APersistentVector$))))?true:false):false)){ +return cljs.core.ranged_iterator(self__.v,self__.start,self__.end); +} else { +return cljs.core.seq_iter(coll__$1); +} +}); + +cljs.core.Subvec.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.Subvec.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.Subvec(self__.meta,self__.v,self__.start,self__.end,self__.__hash)); +}); + +cljs.core.Subvec.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (self__.end - self__.start); +}); + +cljs.core.Subvec.prototype.cljs$core$IStack$_peek$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._nth.cljs$core$IFn$_invoke$arity$2(self__.v,(self__.end - (1))); +}); + +cljs.core.Subvec.prototype.cljs$core$IStack$_pop$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.start === self__.end)){ +throw (new Error("Can't pop empty vector")); +} else { +return cljs.core.build_subvec(self__.meta,self__.v,self__.start,(self__.end - (1)),null); +} +}); + +cljs.core.Subvec.prototype.cljs$core$IReversible$_rseq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((!((self__.start === self__.end)))){ +return (new cljs.core.RSeq(coll__$1,((self__.end - self__.start) - (1)),null)); +} else { +return null; +} +}); + +cljs.core.Subvec.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.Subvec.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.Subvec.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.PersistentVector.EMPTY,self__.meta); +}); + +cljs.core.Subvec.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +if((((!((self__.v == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === self__.v.cljs$core$APersistentVector$))))?true:false):false)){ +return cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$4(self__.v,f,self__.start,self__.end); +} else { +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$2(coll__$1,f); +} +}); + +cljs.core.Subvec.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,init){ +var self__ = this; +var coll__$1 = this; +if((((!((self__.v == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === self__.v.cljs$core$APersistentVector$))))?true:false):false)){ +return cljs.core.pv_reduce.cljs$core$IFn$_invoke$arity$5(self__.v,f,init,self__.start,self__.end); +} else { +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$3(coll__$1,f,init); +} +}); + +cljs.core.Subvec.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (coll,key,val){ +var self__ = this; +var coll__$1 = this; +if(typeof key === 'number'){ +return coll__$1.cljs$core$IVector$_assoc_n$arity$3(null,key,val); +} else { +throw (new Error("Subvec's key for assoc must be a number.")); +} +}); + +cljs.core.Subvec.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var subvec_seq = ((function (coll__$1){ +return (function cljs$core$subvec_seq(i){ +if((i === self__.end)){ +return null; +} else { +return cljs.core.cons(cljs.core._nth.cljs$core$IFn$_invoke$arity$2(self__.v,i),(new cljs.core.LazySeq(null,((function (coll__$1){ +return (function (){ +return cljs$core$subvec_seq((i + (1))); +});})(coll__$1)) +,null,null))); +} +});})(coll__$1)) +; +return subvec_seq(self__.start); +}); + +cljs.core.Subvec.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return cljs.core.build_subvec(new_meta,self__.v,self__.start,self__.end,self__.__hash); +} +}); + +cljs.core.Subvec.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.build_subvec(self__.meta,cljs.core._assoc_n(self__.v,self__.end,o),self__.start,(self__.end + (1)),null); +}); + +cljs.core.Subvec.prototype.call = (function() { +var G__4260 = null; +var G__4260__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$IIndexed$_nth$arity$2(null,k); +}); +var G__4260__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); +G__4260 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4260__2.call(this,self__,k); +case 3: +return G__4260__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4260.cljs$core$IFn$_invoke$arity$2 = G__4260__2; +G__4260.cljs$core$IFn$_invoke$arity$3 = G__4260__3; +return G__4260; +})() +; + +cljs.core.Subvec.prototype.apply = (function (self__,args4248){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4248))); +}); + +cljs.core.Subvec.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$IIndexed$_nth$arity$2(null,k); +}); + +cljs.core.Subvec.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); + +cljs.core.Subvec.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$v,cljs.core.cst$sym$start,cljs.core.cst$sym$end,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Subvec.cljs$lang$type = true; + +cljs.core.Subvec.cljs$lang$ctorStr = "cljs.core/Subvec"; + +cljs.core.Subvec.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Subvec"); +}); + +/** + * Positional factory function for cljs.core/Subvec. + */ +cljs.core.__GT_Subvec = (function cljs$core$__GT_Subvec(meta,v,start,end,__hash){ +return (new cljs.core.Subvec(meta,v,start,end,__hash)); +}); + +var G__4261_4264 = cljs.core.Subvec.prototype; +var G__4262_4265 = cljs.core.ITER_SYMBOL; +var G__4263_4266 = ((function (G__4261_4264,G__4262_4265){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4261_4264,G__4262_4265)) +; +goog.object.set(G__4261_4264,G__4262_4265,G__4263_4266); +cljs.core.build_subvec = (function cljs$core$build_subvec(meta,v,start,end,__hash){ +while(true){ +if((v instanceof cljs.core.Subvec)){ +var G__4267 = meta; +var G__4268 = v.v; +var G__4269 = (v.start + start); +var G__4270 = (v.start + end); +var G__4271 = __hash; +meta = G__4267; +v = G__4268; +start = G__4269; +end = G__4270; +__hash = G__4271; +continue; +} else { +if(cljs.core.vector_QMARK_(v)){ +} else { +throw (new Error("v must satisfy IVector")); +} + +var c_4272 = cljs.core.count(v); +if((((start < (0))) || ((end < (0))) || ((start > c_4272)) || ((end > c_4272)))){ +throw (new Error("Index out of bounds")); +} else { +} + +return (new cljs.core.Subvec(meta,v,start,end,__hash)); +} +break; +} +}); +/** + * Returns a persistent vector of the items in vector from + * start (inclusive) to end (exclusive). If end is not supplied, + * defaults to (count vector). This operation is O(1) and very fast, as + * the resulting vector shares structure with the original and no + * trimming is done. + */ +cljs.core.subvec = (function cljs$core$subvec(var_args){ +var G__4274 = arguments.length; +switch (G__4274) { +case 2: +return cljs.core.subvec.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.subvec.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.subvec.cljs$core$IFn$_invoke$arity$2 = (function (v,start){ +return cljs.core.subvec.cljs$core$IFn$_invoke$arity$3(v,start,cljs.core.count(v)); +}); + +cljs.core.subvec.cljs$core$IFn$_invoke$arity$3 = (function (v,start,end){ +if((((!((start == null)))) && ((!((end == null)))))){ +} else { +throw (new Error("Assert failed: (and (not (nil? start)) (not (nil? end)))")); +} + +return cljs.core.build_subvec(null,v,(start | (0)),(end | (0)),null); +}); + +cljs.core.subvec.cljs$lang$maxFixedArity = 3; + +cljs.core.tv_ensure_editable = (function cljs$core$tv_ensure_editable(edit,node){ +if((edit === node.edit)){ +return node; +} else { +return (new cljs.core.VectorNode(edit,cljs.core.aclone(node.arr))); +} +}); +cljs.core.tv_editable_root = (function cljs$core$tv_editable_root(node){ +return (new cljs.core.VectorNode(({}),cljs.core.aclone(node.arr))); +}); +cljs.core.tv_editable_tail = (function cljs$core$tv_editable_tail(tl){ +var ret = [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]; +cljs.core.array_copy(tl,(0),ret,(0),tl.length); + +return ret; +}); +cljs.core.tv_push_tail = (function cljs$core$tv_push_tail(tv,level,parent,tail_node){ +var ret = cljs.core.tv_ensure_editable(tv.root.edit,parent); +var subidx = (((tv.cnt - (1)) >>> level) & (31)); +cljs.core.pv_aset(ret,subidx,(((level === (5)))?tail_node:(function (){var child = cljs.core.pv_aget(ret,subidx); +if((!((child == null)))){ +var G__4278 = tv; +var G__4279 = (level - (5)); +var G__4280 = child; +var G__4281 = tail_node; +return (cljs.core.tv_push_tail.cljs$core$IFn$_invoke$arity$4 ? cljs.core.tv_push_tail.cljs$core$IFn$_invoke$arity$4(G__4278,G__4279,G__4280,G__4281) : cljs.core.tv_push_tail.call(null,G__4278,G__4279,G__4280,G__4281)); +} else { +return cljs.core.new_path(tv.root.edit,(level - (5)),tail_node); +} +})())); + +return ret; +}); +cljs.core.tv_pop_tail = (function cljs$core$tv_pop_tail(tv,level,node){ +var node__$1 = cljs.core.tv_ensure_editable(tv.root.edit,node); +var subidx = (((tv.cnt - (2)) >>> level) & (31)); +if((level > (5))){ +var new_child = (function (){var G__4282 = tv; +var G__4283 = (level - (5)); +var G__4284 = cljs.core.pv_aget(node__$1,subidx); +return (cljs.core.tv_pop_tail.cljs$core$IFn$_invoke$arity$3 ? cljs.core.tv_pop_tail.cljs$core$IFn$_invoke$arity$3(G__4282,G__4283,G__4284) : cljs.core.tv_pop_tail.call(null,G__4282,G__4283,G__4284)); +})(); +if((((new_child == null)) && ((subidx === (0))))){ +return null; +} else { +cljs.core.pv_aset(node__$1,subidx,new_child); + +return node__$1; +} +} else { +if((subidx === (0))){ +return null; +} else { +cljs.core.pv_aset(node__$1,subidx,null); + +return node__$1; + +} +} +}); +cljs.core.unchecked_editable_array_for = (function cljs$core$unchecked_editable_array_for(tv,i){ +if((i >= cljs.core.tail_off(tv))){ +return tv.tail; +} else { +var root = tv.root; +var node = root; +var level = tv.shift; +while(true){ +if((level > (0))){ +var G__4285 = cljs.core.tv_ensure_editable(root.edit,cljs.core.pv_aget(node,((i >>> level) & (31)))); +var G__4286 = (level - (5)); +node = G__4285; +level = G__4286; +continue; +} else { +return node.arr; +} +break; +} +} +}); + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ITransientCollection} + * @implements {cljs.core.ITransientVector} + * @implements {cljs.core.ITransientAssociative} + * @implements {cljs.core.ILookup} +*/ +cljs.core.TransientVector = (function (cnt,shift,root,tail){ +this.cnt = cnt; +this.shift = shift; +this.root = root; +this.tail = tail; +this.cljs$lang$protocol_mask$partition1$ = 88; +this.cljs$lang$protocol_mask$partition0$ = 275; +}); +cljs.core.TransientVector.prototype.cljs$core$ITransientCollection$_conj_BANG_$arity$2 = (function (tcoll,o){ +var self__ = this; +var tcoll__$1 = this; +if(self__.root.edit){ +if(((self__.cnt - cljs.core.tail_off(tcoll__$1)) < (32))){ +(self__.tail[(self__.cnt & (31))] = o); + +self__.cnt = (self__.cnt + (1)); + +return tcoll__$1; +} else { +var tail_node = (new cljs.core.VectorNode(self__.root.edit,self__.tail)); +var new_tail = [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]; +(new_tail[(0)] = o); + +self__.tail = new_tail; + +if(((self__.cnt >>> (5)) > ((1) << self__.shift))){ +var new_root_array = [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]; +var new_shift = (self__.shift + (5)); +(new_root_array[(0)] = self__.root); + +(new_root_array[(1)] = cljs.core.new_path(self__.root.edit,self__.shift,tail_node)); + +self__.root = (new cljs.core.VectorNode(self__.root.edit,new_root_array)); + +self__.shift = new_shift; + +self__.cnt = (self__.cnt + (1)); + +return tcoll__$1; +} else { +var new_root = cljs.core.tv_push_tail(tcoll__$1,self__.shift,self__.root,tail_node); +self__.root = new_root; + +self__.cnt = (self__.cnt + (1)); + +return tcoll__$1; +} +} +} else { +throw (new Error("conj! after persistent!")); +} +}); + +cljs.core.TransientVector.prototype.cljs$core$ITransientCollection$_persistent_BANG_$arity$1 = (function (tcoll){ +var self__ = this; +var tcoll__$1 = this; +if(self__.root.edit){ +self__.root.edit = null; + +var len = (self__.cnt - cljs.core.tail_off(tcoll__$1)); +var trimmed_tail = (new Array(len)); +cljs.core.array_copy(self__.tail,(0),trimmed_tail,(0),len); + +return (new cljs.core.PersistentVector(null,self__.cnt,self__.shift,self__.root,trimmed_tail,null)); +} else { +throw (new Error("persistent! called twice")); +} +}); + +cljs.core.TransientVector.prototype.cljs$core$ITransientAssociative$_assoc_BANG_$arity$3 = (function (tcoll,key,val){ +var self__ = this; +var tcoll__$1 = this; +if(typeof key === 'number'){ +return tcoll__$1.cljs$core$ITransientVector$_assoc_n_BANG_$arity$3(null,key,val); +} else { +throw (new Error("TransientVector's key for assoc! must be a number.")); +} +}); + +cljs.core.TransientVector.prototype.cljs$core$ITransientVector$_assoc_n_BANG_$arity$3 = (function (tcoll,n,val){ +var self__ = this; +var tcoll__$1 = this; +if(self__.root.edit){ +if(((((0) <= n)) && ((n < self__.cnt)))){ +if((cljs.core.tail_off(tcoll__$1) <= n)){ +(self__.tail[(n & (31))] = val); + +return tcoll__$1; +} else { +var new_root = (function (){var fexpr__4288 = ((function (tcoll__$1){ +return (function cljs$core$go(level,node){ +var node__$1 = cljs.core.tv_ensure_editable(self__.root.edit,node); +if((level === (0))){ +cljs.core.pv_aset(node__$1,(n & (31)),val); + +return node__$1; +} else { +var subidx = ((n >>> level) & (31)); +cljs.core.pv_aset(node__$1,subidx,cljs$core$go((level - (5)),cljs.core.pv_aget(node__$1,subidx))); + +return node__$1; +} +});})(tcoll__$1)) +; +return fexpr__4288(self__.shift,self__.root); +})(); +self__.root = new_root; + +return tcoll__$1; +} +} else { +if((n === self__.cnt)){ +return tcoll__$1.cljs$core$ITransientCollection$_conj_BANG_$arity$2(null,val); +} else { +throw (new Error(["Index ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(n)," out of bounds for TransientVector of length",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.cnt)].join(''))); + +} +} +} else { +throw (new Error("assoc! after persistent!")); +} +}); + +cljs.core.TransientVector.prototype.cljs$core$ITransientVector$_pop_BANG_$arity$1 = (function (tcoll){ +var self__ = this; +var tcoll__$1 = this; +if(self__.root.edit){ +if((self__.cnt === (0))){ +throw (new Error("Can't pop empty vector")); +} else { +if(((1) === self__.cnt)){ +self__.cnt = (0); + +return tcoll__$1; +} else { +if((((self__.cnt - (1)) & (31)) > (0))){ +self__.cnt = (self__.cnt - (1)); + +return tcoll__$1; +} else { +var new_tail = cljs.core.unchecked_editable_array_for(tcoll__$1,(self__.cnt - (2))); +var new_root = (function (){var nr = cljs.core.tv_pop_tail(tcoll__$1,self__.shift,self__.root); +if((!((nr == null)))){ +return nr; +} else { +return (new cljs.core.VectorNode(self__.root.edit,[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])); +} +})(); +if(((((5) < self__.shift)) && ((cljs.core.pv_aget(new_root,(1)) == null)))){ +var new_root__$1 = cljs.core.tv_ensure_editable(self__.root.edit,cljs.core.pv_aget(new_root,(0))); +self__.root = new_root__$1; + +self__.shift = (self__.shift - (5)); + +self__.cnt = (self__.cnt - (1)); + +self__.tail = new_tail; + +return tcoll__$1; +} else { +self__.root = new_root; + +self__.cnt = (self__.cnt - (1)); + +self__.tail = new_tail; + +return tcoll__$1; +} + +} +} +} +} else { +throw (new Error("pop! after persistent!")); +} +}); + +cljs.core.TransientVector.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if(self__.root.edit){ +return self__.cnt; +} else { +throw (new Error("count after persistent!")); +} +}); + +cljs.core.TransientVector.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (coll,n){ +var self__ = this; +var coll__$1 = this; +if(self__.root.edit){ +return (cljs.core.array_for(coll__$1,n)[(n & (31))]); +} else { +throw (new Error("nth after persistent!")); +} +}); + +cljs.core.TransientVector.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (coll,n,not_found){ +var self__ = this; +var coll__$1 = this; +if(((((0) <= n)) && ((n < self__.cnt)))){ +return coll__$1.cljs$core$IIndexed$_nth$arity$2(null,n); +} else { +return not_found; +} +}); + +cljs.core.TransientVector.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,k,null); +}); + +cljs.core.TransientVector.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,k,not_found){ +var self__ = this; +var coll__$1 = this; +if(typeof k === 'number'){ +return coll__$1.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +} else { +return not_found; +} +}); + +cljs.core.TransientVector.prototype.call = (function() { +var G__4289 = null; +var G__4289__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); +var G__4289__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); +G__4289 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4289__2.call(this,self__,k); +case 3: +return G__4289__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4289.cljs$core$IFn$_invoke$arity$2 = G__4289__2; +G__4289.cljs$core$IFn$_invoke$arity$3 = G__4289__3; +return G__4289; +})() +; + +cljs.core.TransientVector.prototype.apply = (function (self__,args4287){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4287))); +}); + +cljs.core.TransientVector.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); + +cljs.core.TransientVector.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.TransientVector.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$cnt,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$shift,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$root,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$tail,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.TransientVector.cljs$lang$type = true; + +cljs.core.TransientVector.cljs$lang$ctorStr = "cljs.core/TransientVector"; + +cljs.core.TransientVector.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/TransientVector"); +}); + +/** + * Positional factory function for cljs.core/TransientVector. + */ +cljs.core.__GT_TransientVector = (function cljs$core$__GT_TransientVector(cnt,shift,root,tail){ +return (new cljs.core.TransientVector(cnt,shift,root,tail)); +}); + + +/** +* @constructor +*/ +cljs.core.PersistentQueueIter = (function (fseq,riter){ +this.fseq = fseq; +this.riter = riter; +}); +cljs.core.PersistentQueueIter.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +var or__4131__auto__ = (((!((self__.fseq == null)))) && (cljs.core.seq(self__.fseq))); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +var and__4120__auto__ = (!((self__.riter == null))); +if(and__4120__auto__){ +return self__.riter.hasNext(); +} else { +return and__4120__auto__; +} +} +}); + +cljs.core.PersistentQueueIter.prototype.next = (function (){ +var self__ = this; +var _ = this; +if((!((self__.fseq == null)))){ +var ret = cljs.core.first(self__.fseq); +self__.fseq = cljs.core.next(self__.fseq); + +return ret; +} else { +if((((!((self__.riter == null)))) && (self__.riter.hasNext()))){ +return self__.riter.next(); +} else { +throw (new Error("No such element")); + +} +} +}); + +cljs.core.PersistentQueueIter.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.PersistentQueueIter.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$fseq,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.cst$sym$riter], null); +}); + +cljs.core.PersistentQueueIter.cljs$lang$type = true; + +cljs.core.PersistentQueueIter.cljs$lang$ctorStr = "cljs.core/PersistentQueueIter"; + +cljs.core.PersistentQueueIter.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentQueueIter"); +}); + +/** + * Positional factory function for cljs.core/PersistentQueueIter. + */ +cljs.core.__GT_PersistentQueueIter = (function cljs$core$__GT_PersistentQueueIter(fseq,riter){ +return (new cljs.core.PersistentQueueIter(fseq,riter)); +}); + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} +*/ +cljs.core.PersistentQueueSeq = (function (meta,front,rear,__hash){ +this.meta = meta; +this.front = front; +this.rear = rear; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 31850700; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.PersistentQueueSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentQueueSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentQueueSeq.prototype.indexOf = (function() { +var G__4290 = null; +var G__4290__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4290__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4290 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4290__1.call(this,x); +case 2: +return G__4290__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4290.cljs$core$IFn$_invoke$arity$1 = G__4290__1; +G__4290.cljs$core$IFn$_invoke$arity$2 = G__4290__2; +return G__4290; +})() +; + +cljs.core.PersistentQueueSeq.prototype.lastIndexOf = (function() { +var G__4291 = null; +var G__4291__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4291__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4291 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4291__1.call(this,x); +case 2: +return G__4291__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4291.cljs$core$IFn$_invoke$arity$1 = G__4291__1; +G__4291.cljs$core$IFn$_invoke$arity$2 = G__4291__2; +return G__4291; +})() +; + +cljs.core.PersistentQueueSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var temp__5733__auto__ = cljs.core.next(self__.front); +if(temp__5733__auto__){ +var f1 = temp__5733__auto__; +return (new cljs.core.PersistentQueueSeq(self__.meta,f1,self__.rear,null)); +} else { +if((!((self__.rear == null)))){ +return (new cljs.core.PersistentQueueSeq(self__.meta,self__.rear,null,null)); +} else { +return null; +} +} +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.List.EMPTY,self__.meta); +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.first(self__.front); +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var temp__5733__auto__ = cljs.core.next(self__.front); +if(temp__5733__auto__){ +var f1 = temp__5733__auto__; +return (new cljs.core.PersistentQueueSeq(self__.meta,f1,self__.rear,null)); +} else { +if((self__.rear == null)){ +return coll__$1.cljs$core$IEmptyableCollection$_empty$arity$1(null); +} else { +return (new cljs.core.PersistentQueueSeq(self__.meta,self__.rear,null,null)); +} +} +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentQueueSeq(new_meta,self__.front,self__.rear,self__.__hash)); +} +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.PersistentQueueSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$front,cljs.core.cst$sym$rear,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentQueueSeq.cljs$lang$type = true; + +cljs.core.PersistentQueueSeq.cljs$lang$ctorStr = "cljs.core/PersistentQueueSeq"; + +cljs.core.PersistentQueueSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentQueueSeq"); +}); + +/** + * Positional factory function for cljs.core/PersistentQueueSeq. + */ +cljs.core.__GT_PersistentQueueSeq = (function cljs$core$__GT_PersistentQueueSeq(meta,front,rear,__hash){ +return (new cljs.core.PersistentQueueSeq(meta,front,rear,__hash)); +}); + +var G__4292_4295 = cljs.core.PersistentQueueSeq.prototype; +var G__4293_4296 = cljs.core.ITER_SYMBOL; +var G__4294_4297 = ((function (G__4292_4295,G__4293_4296){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4292_4295,G__4293_4296)) +; +goog.object.set(G__4292_4295,G__4293_4296,G__4294_4297); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IStack} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} +*/ +cljs.core.PersistentQueue = (function (meta,count,front,rear,__hash){ +this.meta = meta; +this.count = count; +this.front = front; +this.rear = rear; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition1$ = 139264; +this.cljs$lang$protocol_mask$partition0$ = 31858766; +}); +cljs.core.PersistentQueue.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentQueue.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentQueue.prototype.indexOf = (function() { +var G__4298 = null; +var G__4298__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4298__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4298 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4298__1.call(this,x); +case 2: +return G__4298__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4298.cljs$core$IFn$_invoke$arity$1 = G__4298__1; +G__4298.cljs$core$IFn$_invoke$arity$2 = G__4298__2; +return G__4298; +})() +; + +cljs.core.PersistentQueue.prototype.lastIndexOf = (function() { +var G__4299 = null; +var G__4299__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(self__.count.cljs$core$IFn$_invoke$arity$1 ? self__.count.cljs$core$IFn$_invoke$arity$1(coll) : self__.count.call(null,coll))); +}); +var G__4299__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4299 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4299__1.call(this,x); +case 2: +return G__4299__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4299.cljs$core$IFn$_invoke$arity$1 = G__4299__1; +G__4299.cljs$core$IFn$_invoke$arity$2 = G__4299__2; +return G__4299; +})() +; + +cljs.core.PersistentQueue.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.PersistentQueueIter(self__.front,cljs.core._iterator(self__.rear))); +}); + +cljs.core.PersistentQueue.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentQueue.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.PersistentQueue(self__.meta,self__.count,self__.front,self__.rear,self__.__hash)); +}); + +cljs.core.PersistentQueue.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.count; +}); + +cljs.core.PersistentQueue.prototype.cljs$core$IStack$_peek$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.first(self__.front); +}); + +cljs.core.PersistentQueue.prototype.cljs$core$IStack$_pop$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if(cljs.core.truth_(self__.front)){ +var temp__5733__auto__ = cljs.core.next(self__.front); +if(temp__5733__auto__){ +var f1 = temp__5733__auto__; +return (new cljs.core.PersistentQueue(self__.meta,(self__.count - (1)),f1,self__.rear,null)); +} else { +return (new cljs.core.PersistentQueue(self__.meta,(self__.count - (1)),cljs.core.seq(self__.rear),cljs.core.PersistentVector.EMPTY,null)); +} +} else { +return coll__$1; +} +}); + +cljs.core.PersistentQueue.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentQueue.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.PersistentQueue.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.PersistentQueue.EMPTY,self__.meta); +}); + +cljs.core.PersistentQueue.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.first(self__.front); +}); + +cljs.core.PersistentQueue.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.rest(cljs.core.seq(coll__$1)); +}); + +cljs.core.PersistentQueue.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var rear__$1 = cljs.core.seq(self__.rear); +if(cljs.core.truth_((function (){var or__4131__auto__ = self__.front; +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return rear__$1; +} +})())){ +return (new cljs.core.PersistentQueueSeq(null,self__.front,cljs.core.seq(rear__$1),null)); +} else { +return null; +} +}); + +cljs.core.PersistentQueue.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentQueue(new_meta,self__.count,self__.front,self__.rear,self__.__hash)); +} +}); + +cljs.core.PersistentQueue.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +if(cljs.core.truth_(self__.front)){ +return (new cljs.core.PersistentQueue(self__.meta,(self__.count + (1)),self__.front,cljs.core.conj.cljs$core$IFn$_invoke$arity$2((function (){var or__4131__auto__ = self__.rear; +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.PersistentVector.EMPTY; +} +})(),o),null)); +} else { +return (new cljs.core.PersistentQueue(self__.meta,(self__.count + (1)),cljs.core.conj.cljs$core$IFn$_invoke$arity$2(self__.front,o),cljs.core.PersistentVector.EMPTY,null)); +} +}); + +cljs.core.PersistentQueue.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$count,cljs.core.cst$sym$front,cljs.core.cst$sym$rear,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentQueue.cljs$lang$type = true; + +cljs.core.PersistentQueue.cljs$lang$ctorStr = "cljs.core/PersistentQueue"; + +cljs.core.PersistentQueue.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentQueue"); +}); + +/** + * Positional factory function for cljs.core/PersistentQueue. + */ +cljs.core.__GT_PersistentQueue = (function cljs$core$__GT_PersistentQueue(meta,count,front,rear,__hash){ +return (new cljs.core.PersistentQueue(meta,count,front,rear,__hash)); +}); + +cljs.core.PersistentQueue.EMPTY = (new cljs.core.PersistentQueue(null,(0),null,cljs.core.PersistentVector.EMPTY,cljs.core.empty_ordered_hash)); +var G__4300_4303 = cljs.core.PersistentQueue.prototype; +var G__4301_4304 = cljs.core.ITER_SYMBOL; +var G__4302_4305 = ((function (G__4300_4303,G__4301_4304){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4300_4303,G__4301_4304)) +; +goog.object.set(G__4300_4303,G__4301_4304,G__4302_4305); + +/** +* @constructor + * @implements {cljs.core.IEquiv} +*/ +cljs.core.NeverEquiv = (function (){ +this.cljs$lang$protocol_mask$partition0$ = 2097152; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.NeverEquiv.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.NeverEquiv.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (o,other){ +var self__ = this; +var o__$1 = this; +return false; +}); + +cljs.core.NeverEquiv.getBasis = (function (){ +return cljs.core.PersistentVector.EMPTY; +}); + +cljs.core.NeverEquiv.cljs$lang$type = true; + +cljs.core.NeverEquiv.cljs$lang$ctorStr = "cljs.core/NeverEquiv"; + +cljs.core.NeverEquiv.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/NeverEquiv"); +}); + +/** + * Positional factory function for cljs.core/NeverEquiv. + */ +cljs.core.__GT_NeverEquiv = (function cljs$core$__GT_NeverEquiv(){ +return (new cljs.core.NeverEquiv()); +}); + +cljs.core.never_equiv = (new cljs.core.NeverEquiv()); +/** + * Test map equivalence. Returns true if x equals y, otherwise returns false. + */ +cljs.core.equiv_map = (function cljs$core$equiv_map(x,y){ +return cljs.core.boolean$(((((cljs.core.map_QMARK_(y)) && ((!(cljs.core.record_QMARK_(y))))))?(((cljs.core.count(x) === cljs.core.count(y)))?(((((!((x == null))))?(((((x.cljs$lang$protocol_mask$partition0$ & (1048576))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IKVReduce$))))?true:(((!x.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_(cljs.core.IKVReduce,x):false)):cljs.core.native_satisfies_QMARK_(cljs.core.IKVReduce,x)))?cljs.core.reduce_kv((function (_,k,v){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.get.cljs$core$IFn$_invoke$arity$3(y,k,cljs.core.never_equiv),v)){ +return true; +} else { +return cljs.core.reduced(false); +} +}),true,x):cljs.core.every_QMARK_((function (xkv){ +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.get.cljs$core$IFn$_invoke$arity$3(y,cljs.core.first(xkv),cljs.core.never_equiv),cljs.core.second(xkv)); +}),x)):null):null)); +}); +cljs.core.scan_array = (function cljs$core$scan_array(incr,k,array){ +var len = array.length; +var i = (0); +while(true){ +if((i < len)){ +if((k === (array[i]))){ +return i; +} else { +var G__4307 = (i + incr); +i = G__4307; +continue; +} +} else { +return null; +} +break; +} +}); +cljs.core.obj_map_compare_keys = (function cljs$core$obj_map_compare_keys(a,b){ +var a__$1 = cljs.core.hash(a); +var b__$1 = cljs.core.hash(b); +if((a__$1 < b__$1)){ +return (-1); +} else { +if((a__$1 > b__$1)){ +return (1); +} else { +return (0); + +} +} +}); +cljs.core.obj_map__GT_hash_map = (function cljs$core$obj_map__GT_hash_map(m,k,v){ +var ks = m.keys; +var len = ks.length; +var so = m.strobj; +var mm = cljs.core.meta(m); +var i = (0); +var out = cljs.core.transient$(cljs.core.PersistentHashMap.EMPTY); +while(true){ +if((i < len)){ +var k__$1 = (ks[i]); +var G__4308 = (i + (1)); +var G__4309 = cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(out,k__$1,goog.object.get(so,k__$1)); +i = G__4308; +out = G__4309; +continue; +} else { +return cljs.core._with_meta(cljs.core.persistent_BANG_(cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(out,k,v)),mm); +} +break; +} +}); +cljs.core.obj_clone = (function cljs$core$obj_clone(obj,ks){ +var new_obj = ({}); +var l = ks.length; +var i_4315 = (0); +while(true){ +if((i_4315 < l)){ +var k_4316 = (ks[i_4315]); +var G__4312_4317 = new_obj; +var G__4313_4318 = k_4316; +var G__4314_4319 = goog.object.get(obj,k_4316); +goog.object.set(G__4312_4317,G__4313_4318,G__4314_4319); + +var G__4320 = (i_4315 + (1)); +i_4315 = G__4320; +continue; +} else { +} +break; +} + +return new_obj; +}); + +/** +* @constructor + * @implements {cljs.core.IKVReduce} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEditableCollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.IMap} + * @implements {cljs.core.ILookup} +*/ +cljs.core.ObjMap = (function (meta,keys,strobj,update_count,__hash){ +this.meta = meta; +this.keys = keys; +this.strobj = strobj; +this.update_count = update_count; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 16123663; +this.cljs$lang$protocol_mask$partition1$ = 4; +}); +cljs.core.ObjMap.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ObjMap.prototype.cljs$core$IFind$_find$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +if(((goog.isString(k)) && ((!((cljs.core.scan_array((1),k,self__.keys) == null)))))){ +return (new cljs.core.MapEntry(k,(self__.strobj[k]),null)); +} else { +return null; +} +}); + +cljs.core.ObjMap.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.ObjMap.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.ObjMap.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,k,null); +}); + +cljs.core.ObjMap.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,k,not_found){ +var self__ = this; +var coll__$1 = this; +if(((goog.isString(k)) && ((!((cljs.core.scan_array((1),k,self__.keys) == null)))))){ +return (self__.strobj[k]); +} else { +return not_found; +} +}); + +cljs.core.ObjMap.prototype.cljs$core$IKVReduce$_kv_reduce$arity$3 = (function (coll,f,init){ +var self__ = this; +var coll__$1 = this; +var len = self__.keys.length; +var keys__$1 = self__.keys.sort(cljs.core.obj_map_compare_keys); +var init__$1 = init; +while(true){ +if(cljs.core.seq(keys__$1)){ +var k = cljs.core.first(keys__$1); +var init__$2 = (function (){var G__4323 = init__$1; +var G__4324 = k; +var G__4325 = (self__.strobj[k]); +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__4323,G__4324,G__4325) : f.call(null,G__4323,G__4324,G__4325)); +})(); +if(cljs.core.reduced_QMARK_(init__$2)){ +return cljs.core.deref(init__$2); +} else { +var G__4326 = cljs.core.rest(keys__$1); +var G__4327 = init__$2; +keys__$1 = G__4326; +init__$1 = G__4327; +continue; +} +} else { +return init__$1; +} +break; +} +}); + +cljs.core.ObjMap.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.ObjMap.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.keys.length; +}); + +cljs.core.ObjMap.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_unordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.ObjMap.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_map(coll__$1,other); +}); + +cljs.core.ObjMap.prototype.cljs$core$IEditableCollection$_as_transient$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.transient$(cljs.core.into.cljs$core$IFn$_invoke$arity$2(cljs.core.PersistentHashMap.EMPTY,coll__$1)); +}); + +cljs.core.ObjMap.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.ObjMap.EMPTY,self__.meta); +}); + +cljs.core.ObjMap.prototype.cljs$core$IMap$_dissoc$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +if(((goog.isString(k)) && ((!((cljs.core.scan_array((1),k,self__.keys) == null)))))){ +var new_keys = cljs.core.aclone(self__.keys); +var new_strobj = cljs.core.obj_clone(self__.strobj,self__.keys); +new_keys.splice(cljs.core.scan_array((1),k,new_keys),(1)); + +delete new_strobj[k]; + +return (new cljs.core.ObjMap(self__.meta,new_keys,new_strobj,(self__.update_count + (1)),null)); +} else { +return coll__$1; +} +}); + +cljs.core.ObjMap.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (coll,k,v){ +var self__ = this; +var coll__$1 = this; +if(goog.isString(k)){ +if((((self__.update_count > cljs.core.ObjMap.HASHMAP_THRESHOLD)) || ((self__.keys.length >= cljs.core.ObjMap.HASHMAP_THRESHOLD)))){ +return cljs.core.obj_map__GT_hash_map(coll__$1,k,v); +} else { +if((!((cljs.core.scan_array((1),k,self__.keys) == null)))){ +var new_strobj = cljs.core.obj_clone(self__.strobj,self__.keys); +goog.object.set(new_strobj,k,v); + +return (new cljs.core.ObjMap(self__.meta,self__.keys,new_strobj,(self__.update_count + (1)),null)); +} else { +var new_strobj = cljs.core.obj_clone(self__.strobj,self__.keys); +var new_keys = cljs.core.aclone(self__.keys); +goog.object.set(new_strobj,k,v); + +new_keys.push(k); + +return (new cljs.core.ObjMap(self__.meta,new_keys,new_strobj,(self__.update_count + (1)),null)); +} +} +} else { +return cljs.core.obj_map__GT_hash_map(coll__$1,k,v); +} +}); + +cljs.core.ObjMap.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +if(((goog.isString(k)) && ((!((cljs.core.scan_array((1),k,self__.keys) == null)))))){ +return true; +} else { +return false; +} +}); + +cljs.core.ObjMap.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.keys.length > (0))){ +return cljs.core.map.cljs$core$IFn$_invoke$arity$2(((function (coll__$1){ +return (function (p1__4321_SHARP_){ +return (new cljs.core.PersistentVector(null,2,(5),cljs.core.PersistentVector.EMPTY_NODE,[p1__4321_SHARP_,(self__.strobj[p1__4321_SHARP_])],null)); +});})(coll__$1)) +,self__.keys.sort(cljs.core.obj_map_compare_keys)); +} else { +return null; +} +}); + +cljs.core.ObjMap.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.ObjMap(new_meta,self__.keys,self__.strobj,self__.update_count,self__.__hash)); +} +}); + +cljs.core.ObjMap.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,entry){ +var self__ = this; +var coll__$1 = this; +if(cljs.core.vector_QMARK_(entry)){ +return coll__$1.cljs$core$IAssociative$_assoc$arity$3(null,cljs.core._nth.cljs$core$IFn$_invoke$arity$2(entry,(0)),cljs.core._nth.cljs$core$IFn$_invoke$arity$2(entry,(1))); +} else { +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._conj,coll__$1,entry); +} +}); + +cljs.core.ObjMap.prototype.call = (function() { +var G__4328 = null; +var G__4328__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); +var G__4328__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); +G__4328 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4328__2.call(this,self__,k); +case 3: +return G__4328__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4328.cljs$core$IFn$_invoke$arity$2 = G__4328__2; +G__4328.cljs$core$IFn$_invoke$arity$3 = G__4328__3; +return G__4328; +})() +; + +cljs.core.ObjMap.prototype.apply = (function (self__,args4322){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4322))); +}); + +cljs.core.ObjMap.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); + +cljs.core.ObjMap.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.ObjMap.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$keys,cljs.core.cst$sym$strobj,cljs.core.cst$sym$update_DASH_count,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ObjMap.cljs$lang$type = true; + +cljs.core.ObjMap.cljs$lang$ctorStr = "cljs.core/ObjMap"; + +cljs.core.ObjMap.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ObjMap"); +}); + +/** + * Positional factory function for cljs.core/ObjMap. + */ +cljs.core.__GT_ObjMap = (function cljs$core$__GT_ObjMap(meta,keys,strobj,update_count,__hash){ +return (new cljs.core.ObjMap(meta,keys,strobj,update_count,__hash)); +}); + +cljs.core.ObjMap.EMPTY = (new cljs.core.ObjMap(null,[],({}),(0),cljs.core.empty_unordered_hash)); +cljs.core.ObjMap.HASHMAP_THRESHOLD = (8); +cljs.core.ObjMap.fromObject = (function (ks,obj){ +return (new cljs.core.ObjMap(null,ks,obj,(0),null)); +}); + +/** +* @constructor +*/ +cljs.core.RecordIter = (function (i,record,base_count,fields,ext_map_iter){ +this.i = i; +this.record = record; +this.base_count = base_count; +this.fields = fields; +this.ext_map_iter = ext_map_iter; +}); +cljs.core.RecordIter.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +var or__4131__auto__ = (self__.i < self__.base_count); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return self__.ext_map_iter.hasNext(); +} +}); + +cljs.core.RecordIter.prototype.next = (function (){ +var self__ = this; +var _ = this; +if((self__.i < self__.base_count)){ +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(self__.fields,self__.i); +self__.i = (self__.i + (1)); + +return (new cljs.core.MapEntry(k,cljs.core._lookup.cljs$core$IFn$_invoke$arity$2(self__.record,k),null)); +} else { +return self__.ext_map_iter.next(); +} +}); + +cljs.core.RecordIter.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.RecordIter.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.cst$sym$record,cljs.core.cst$sym$base_DASH_count,cljs.core.cst$sym$fields,cljs.core.cst$sym$ext_DASH_map_DASH_iter], null); +}); + +cljs.core.RecordIter.cljs$lang$type = true; + +cljs.core.RecordIter.cljs$lang$ctorStr = "cljs.core/RecordIter"; + +cljs.core.RecordIter.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/RecordIter"); +}); + +/** + * Positional factory function for cljs.core/RecordIter. + */ +cljs.core.__GT_RecordIter = (function cljs$core$__GT_RecordIter(i,record,base_count,fields,ext_map_iter){ +return (new cljs.core.RecordIter(i,record,base_count,fields,ext_map_iter)); +}); + + +/** +* @constructor +*/ +cljs.core.ES6EntriesIterator = (function (s){ +this.s = s; +}); +cljs.core.ES6EntriesIterator.prototype.next = (function (){ +var self__ = this; +var _ = this; +if((!((self__.s == null)))){ +var vec__4331 = cljs.core.first(self__.s); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4331,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4331,(1),null); +self__.s = cljs.core.next(self__.s); + +return ({"value": [k,v], "done": false}); +} else { +return ({"value": null, "done": true}); +} +}); + +cljs.core.ES6EntriesIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$s,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ES6EntriesIterator.cljs$lang$type = true; + +cljs.core.ES6EntriesIterator.cljs$lang$ctorStr = "cljs.core/ES6EntriesIterator"; + +cljs.core.ES6EntriesIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ES6EntriesIterator"); +}); + +/** + * Positional factory function for cljs.core/ES6EntriesIterator. + */ +cljs.core.__GT_ES6EntriesIterator = (function cljs$core$__GT_ES6EntriesIterator(s){ +return (new cljs.core.ES6EntriesIterator(s)); +}); + +cljs.core.es6_entries_iterator = (function cljs$core$es6_entries_iterator(coll){ +return (new cljs.core.ES6EntriesIterator(cljs.core.seq(coll))); +}); + +/** +* @constructor +*/ +cljs.core.ES6SetEntriesIterator = (function (s){ +this.s = s; +}); +cljs.core.ES6SetEntriesIterator.prototype.next = (function (){ +var self__ = this; +var _ = this; +if((!((self__.s == null)))){ +var x = cljs.core.first(self__.s); +self__.s = cljs.core.next(self__.s); + +return ({"value": [x,x], "done": false}); +} else { +return ({"value": null, "done": true}); +} +}); + +cljs.core.ES6SetEntriesIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$s,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ES6SetEntriesIterator.cljs$lang$type = true; + +cljs.core.ES6SetEntriesIterator.cljs$lang$ctorStr = "cljs.core/ES6SetEntriesIterator"; + +cljs.core.ES6SetEntriesIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ES6SetEntriesIterator"); +}); + +/** + * Positional factory function for cljs.core/ES6SetEntriesIterator. + */ +cljs.core.__GT_ES6SetEntriesIterator = (function cljs$core$__GT_ES6SetEntriesIterator(s){ +return (new cljs.core.ES6SetEntriesIterator(s)); +}); + +cljs.core.es6_set_entries_iterator = (function cljs$core$es6_set_entries_iterator(coll){ +return (new cljs.core.ES6SetEntriesIterator(cljs.core.seq(coll))); +}); +cljs.core.array_index_of_nil_QMARK_ = (function cljs$core$array_index_of_nil_QMARK_(arr){ +var len = arr.length; +var i = (0); +while(true){ +if((len <= i)){ +return (-1); +} else { +if(((arr[i]) == null)){ +return i; +} else { +var G__4334 = (i + (2)); +i = G__4334; +continue; + +} +} +break; +} +}); +cljs.core.array_index_of_keyword_QMARK_ = (function cljs$core$array_index_of_keyword_QMARK_(arr,k){ +var len = arr.length; +var kstr = k.fqn; +var i = (0); +while(true){ +if((len <= i)){ +return (-1); +} else { +if(((((arr[i]) instanceof cljs.core.Keyword)) && ((kstr === (arr[i]).fqn)))){ +return i; +} else { +var G__4335 = (i + (2)); +i = G__4335; +continue; + +} +} +break; +} +}); +cljs.core.array_index_of_symbol_QMARK_ = (function cljs$core$array_index_of_symbol_QMARK_(arr,k){ +var len = arr.length; +var kstr = k.str; +var i = (0); +while(true){ +if((len <= i)){ +return (-1); +} else { +if(((((arr[i]) instanceof cljs.core.Symbol)) && ((kstr === (arr[i]).str)))){ +return i; +} else { +var G__4336 = (i + (2)); +i = G__4336; +continue; + +} +} +break; +} +}); +cljs.core.array_index_of_identical_QMARK_ = (function cljs$core$array_index_of_identical_QMARK_(arr,k){ +var len = arr.length; +var i = (0); +while(true){ +if((len <= i)){ +return (-1); +} else { +if((k === (arr[i]))){ +return i; +} else { +var G__4337 = (i + (2)); +i = G__4337; +continue; + +} +} +break; +} +}); +cljs.core.array_index_of_equiv_QMARK_ = (function cljs$core$array_index_of_equiv_QMARK_(arr,k){ +var len = arr.length; +var i = (0); +while(true){ +if((len <= i)){ +return (-1); +} else { +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(k,(arr[i]))){ +return i; +} else { +var G__4338 = (i + (2)); +i = G__4338; +continue; + +} +} +break; +} +}); +cljs.core.array_index_of = (function cljs$core$array_index_of(arr,k){ +if((k instanceof cljs.core.Keyword)){ +return cljs.core.array_index_of_keyword_QMARK_(arr,k); +} else { +if(((goog.isString(k)) || (typeof k === 'number'))){ +return cljs.core.array_index_of_identical_QMARK_(arr,k); +} else { +if((k instanceof cljs.core.Symbol)){ +return cljs.core.array_index_of_symbol_QMARK_(arr,k); +} else { +if((k == null)){ +return cljs.core.array_index_of_nil_QMARK_(arr); +} else { +return cljs.core.array_index_of_equiv_QMARK_(arr,k); + +} +} +} +} +}); +cljs.core.array_map_index_of = (function cljs$core$array_map_index_of(m,k){ +return cljs.core.array_index_of(m.arr,k); +}); +cljs.core.array_extend_kv = (function cljs$core$array_extend_kv(arr,k,v){ +var l = arr.length; +var narr = (new Array((l + (2)))); +var i_4339 = (0); +while(true){ +if((i_4339 < l)){ +(narr[i_4339] = (arr[i_4339])); + +var G__4340 = (i_4339 + (1)); +i_4339 = G__4340; +continue; +} else { +} +break; +} + +(narr[l] = k); + +(narr[(l + (1))] = v); + +return narr; +}); +cljs.core.array_map_extend_kv = (function cljs$core$array_map_extend_kv(m,k,v){ +return cljs.core.array_extend_kv(m.arr,k,v); +}); + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.IVector} + * @implements {cljs.core.IReversible} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IStack} + * @implements {cljs.core.IMapEntry} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.ILookup} + * @implements {cljs.core.IReduce} +*/ +cljs.core.MapEntry = (function (key,val,__hash){ +this.key = key; +this.val = val; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 166619935; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.MapEntry.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.MapEntry.prototype.cljs$core$IFind$_find$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +var G__4342 = k; +switch (G__4342) { +case (0): +return (new cljs.core.MapEntry((0),self__.key,null)); + +break; +case (1): +return (new cljs.core.MapEntry((1),self__.val,null)); + +break; +default: +return null; + +} +}); + +cljs.core.MapEntry.prototype.indexOf = (function() { +var G__4344 = null; +var G__4344__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4344__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4344 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4344__1.call(this,x); +case 2: +return G__4344__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4344.cljs$core$IFn$_invoke$arity$1 = G__4344__1; +G__4344.cljs$core$IFn$_invoke$arity$2 = G__4344__2; +return G__4344; +})() +; + +cljs.core.MapEntry.prototype.lastIndexOf = (function() { +var G__4345 = null; +var G__4345__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4345__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4345 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4345__1.call(this,x); +case 2: +return G__4345__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4345.cljs$core$IFn$_invoke$arity$1 = G__4345__1; +G__4345.cljs$core$IFn$_invoke$arity$2 = G__4345__2; +return G__4345; +})() +; + +cljs.core.MapEntry.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +return node__$1.cljs$core$IIndexed$_nth$arity$3(null,k,null); +}); + +cljs.core.MapEntry.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (node,k,not_found){ +var self__ = this; +var node__$1 = this; +return node__$1.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); + +cljs.core.MapEntry.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (node,n){ +var self__ = this; +var node__$1 = this; +if((n === (0))){ +return self__.key; +} else { +if((n === (1))){ +return self__.val; +} else { +throw (new Error("Index out of bounds")); + +} +} +}); + +cljs.core.MapEntry.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (node,n,not_found){ +var self__ = this; +var node__$1 = this; +if((n === (0))){ +return self__.key; +} else { +if((n === (1))){ +return self__.val; +} else { +return not_found; + +} +} +}); + +cljs.core.MapEntry.prototype.cljs$core$IVector$_assoc_n$arity$3 = (function (node,n,v){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null).cljs$core$IVector$_assoc_n$arity$3(null,n,v); +}); + +cljs.core.MapEntry.prototype.cljs$core$IMeta$_meta$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return null; +}); + +cljs.core.MapEntry.prototype.cljs$core$ICounted$_count$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (2); +}); + +cljs.core.MapEntry.prototype.cljs$core$IMapEntry$_key$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.key; +}); + +cljs.core.MapEntry.prototype.cljs$core$IMapEntry$_val$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.val; +}); + +cljs.core.MapEntry.prototype.cljs$core$IStack$_peek$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.val; +}); + +cljs.core.MapEntry.prototype.cljs$core$IStack$_pop$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key], null); +}); + +cljs.core.MapEntry.prototype.cljs$core$IReversible$_rseq$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (new cljs.core.IndexedSeq([self__.val,self__.key],(0),null)); +}); + +cljs.core.MapEntry.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.MapEntry.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.MapEntry.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return null; +}); + +cljs.core.MapEntry.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (node,f){ +var self__ = this; +var node__$1 = this; +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$2(node__$1,f); +}); + +cljs.core.MapEntry.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (node,f,start){ +var self__ = this; +var node__$1 = this; +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$3(node__$1,f,start); +}); + +cljs.core.MapEntry.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (node,k,v){ +var self__ = this; +var node__$1 = this; +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null),k,v); +}); + +cljs.core.MapEntry.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +return (((k === (0))) || ((k === (1)))); +}); + +cljs.core.MapEntry.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (new cljs.core.IndexedSeq([self__.key,self__.val],(0),null)); +}); + +cljs.core.MapEntry.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (node,meta){ +var self__ = this; +var node__$1 = this; +return cljs.core.with_meta(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null),meta); +}); + +cljs.core.MapEntry.prototype.cljs$core$ICollection$_conj$arity$2 = (function (node,o){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val,o], null); +}); + +cljs.core.MapEntry.prototype.call = (function() { +var G__4346 = null; +var G__4346__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var node = self____$1; +return node.cljs$core$IIndexed$_nth$arity$2(null,k); +}); +var G__4346__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var node = self____$1; +return node.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); +G__4346 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4346__2.call(this,self__,k); +case 3: +return G__4346__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4346.cljs$core$IFn$_invoke$arity$2 = G__4346__2; +G__4346.cljs$core$IFn$_invoke$arity$3 = G__4346__3; +return G__4346; +})() +; + +cljs.core.MapEntry.prototype.apply = (function (self__,args4341){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4341))); +}); + +cljs.core.MapEntry.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var node = this; +return node.cljs$core$IIndexed$_nth$arity$2(null,k); +}); + +cljs.core.MapEntry.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var node = this; +return node.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); + +cljs.core.MapEntry.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$key,cljs.core.cst$sym$val,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.MapEntry.cljs$lang$type = true; + +cljs.core.MapEntry.cljs$lang$ctorStr = "cljs.core/MapEntry"; + +cljs.core.MapEntry.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/MapEntry"); +}); + +/** + * Positional factory function for cljs.core/MapEntry. + */ +cljs.core.__GT_MapEntry = (function cljs$core$__GT_MapEntry(key,val,__hash){ +return (new cljs.core.MapEntry(key,val,__hash)); +}); + +/** + * Returns true if x satisfies IMapEntry + */ +cljs.core.map_entry_QMARK_ = (function cljs$core$map_entry_QMARK_(x){ +if((!((x == null)))){ +if((((x.cljs$lang$protocol_mask$partition0$ & (2048))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IMapEntry$)))){ +return true; +} else { +return false; +} +} else { +return false; +} +}); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.PersistentArrayMapSeq = (function (arr,i,_meta){ +this.arr = arr; +this.i = i; +this._meta = _meta; +this.cljs$lang$protocol_mask$partition0$ = 32374990; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.PersistentArrayMapSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentArrayMapSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentArrayMapSeq.prototype.indexOf = (function() { +var G__4348 = null; +var G__4348__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4348__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4348 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4348__1.call(this,x); +case 2: +return G__4348__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4348.cljs$core$IFn$_invoke$arity$1 = G__4348__1; +G__4348.cljs$core$IFn$_invoke$arity$2 = G__4348__2; +return G__4348; +})() +; + +cljs.core.PersistentArrayMapSeq.prototype.lastIndexOf = (function() { +var G__4349 = null; +var G__4349__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4349__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4349 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4349__1.call(this,x); +case 2: +return G__4349__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4349.cljs$core$IFn$_invoke$arity$1 = G__4349__1; +G__4349.cljs$core$IFn$_invoke$arity$2 = G__4349__2; +return G__4349; +})() +; + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__._meta; +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.i < (self__.arr.length - (2)))){ +return (new cljs.core.PersistentArrayMapSeq(self__.arr,(self__.i + (2)),null)); +} else { +return null; +} +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return ((self__.arr.length - self__.i) / (2)); +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.hash_ordered_coll(coll__$1); +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.MapEntry((self__.arr[self__.i]),(self__.arr[(self__.i + (1))]),null)); +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.i < (self__.arr.length - (2)))){ +return (new cljs.core.PersistentArrayMapSeq(self__.arr,(self__.i + (2)),null)); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__._meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentArrayMapSeq(self__.arr,self__.i,new_meta)); +} +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.PersistentArrayMapSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$arr,cljs.core.cst$sym$i,cljs.core.cst$sym$_meta], null); +}); + +cljs.core.PersistentArrayMapSeq.cljs$lang$type = true; + +cljs.core.PersistentArrayMapSeq.cljs$lang$ctorStr = "cljs.core/PersistentArrayMapSeq"; + +cljs.core.PersistentArrayMapSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentArrayMapSeq"); +}); + +/** + * Positional factory function for cljs.core/PersistentArrayMapSeq. + */ +cljs.core.__GT_PersistentArrayMapSeq = (function cljs$core$__GT_PersistentArrayMapSeq(arr,i,_meta){ +return (new cljs.core.PersistentArrayMapSeq(arr,i,_meta)); +}); + +var G__4350_4353 = cljs.core.PersistentArrayMapSeq.prototype; +var G__4351_4354 = cljs.core.ITER_SYMBOL; +var G__4352_4355 = ((function (G__4350_4353,G__4351_4354){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4350_4353,G__4351_4354)) +; +goog.object.set(G__4350_4353,G__4351_4354,G__4352_4355); +cljs.core.persistent_array_map_seq = (function cljs$core$persistent_array_map_seq(arr,i,_meta){ +if((i <= (arr.length - (2)))){ +return (new cljs.core.PersistentArrayMapSeq(arr,i,_meta)); +} else { +return null; +} +}); + + +/** +* @constructor +*/ +cljs.core.PersistentArrayMapIterator = (function (arr,i,cnt){ +this.arr = arr; +this.i = i; +this.cnt = cnt; +}); +cljs.core.PersistentArrayMapIterator.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +return (self__.i < self__.cnt); +}); + +cljs.core.PersistentArrayMapIterator.prototype.next = (function (){ +var self__ = this; +var _ = this; +var ret = (new cljs.core.MapEntry((self__.arr[self__.i]),(self__.arr[(self__.i + (1))]),null)); +self__.i = (self__.i + (2)); + +return ret; +}); + +cljs.core.PersistentArrayMapIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$arr,cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.cst$sym$cnt], null); +}); + +cljs.core.PersistentArrayMapIterator.cljs$lang$type = true; + +cljs.core.PersistentArrayMapIterator.cljs$lang$ctorStr = "cljs.core/PersistentArrayMapIterator"; + +cljs.core.PersistentArrayMapIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentArrayMapIterator"); +}); + +/** + * Positional factory function for cljs.core/PersistentArrayMapIterator. + */ +cljs.core.__GT_PersistentArrayMapIterator = (function cljs$core$__GT_PersistentArrayMapIterator(arr,i,cnt){ +return (new cljs.core.PersistentArrayMapIterator(arr,i,cnt)); +}); + + +/** +* @constructor + * @implements {cljs.core.IKVReduce} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEditableCollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.IMap} + * @implements {cljs.core.ILookup} + * @implements {cljs.core.IReduce} +*/ +cljs.core.PersistentArrayMap = (function (meta,cnt,arr,__hash){ +this.meta = meta; +this.cnt = cnt; +this.arr = arr; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 16647951; +this.cljs$lang$protocol_mask$partition1$ = 139268; +}); +cljs.core.PersistentArrayMap.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentArrayMap.prototype.cljs$core$IFind$_find$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +var idx = cljs.core.array_map_index_of(coll__$1,k); +if((idx === (-1))){ +return null; +} else { +return (new cljs.core.MapEntry((self__.arr[idx]),(self__.arr[(idx + (1))]),null)); +} +}); + +cljs.core.PersistentArrayMap.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentArrayMap.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentArrayMap.prototype.keys = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.keys(coll)); +}); + +cljs.core.PersistentArrayMap.prototype.entries = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_entries_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentArrayMap.prototype.values = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.vals(coll)); +}); + +cljs.core.PersistentArrayMap.prototype.has = (function (k){ +var self__ = this; +var coll = this; +return cljs.core.contains_QMARK_(coll,k); +}); + +cljs.core.PersistentArrayMap.prototype.get = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.PersistentArrayMap.prototype.forEach = (function (f){ +var self__ = this; +var coll = this; +var seq__4357 = cljs.core.seq(coll); +var chunk__4358 = null; +var count__4359 = (0); +var i__4360 = (0); +while(true){ +if((i__4360 < count__4359)){ +var vec__4367 = chunk__4358.cljs$core$IIndexed$_nth$arity$2(null,i__4360); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4367,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4367,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4379 = seq__4357; +var G__4380 = chunk__4358; +var G__4381 = count__4359; +var G__4382 = (i__4360 + (1)); +seq__4357 = G__4379; +chunk__4358 = G__4380; +count__4359 = G__4381; +i__4360 = G__4382; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__4357); +if(temp__5735__auto__){ +var seq__4357__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__4357__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__4357__$1); +var G__4383 = cljs.core.chunk_rest(seq__4357__$1); +var G__4384 = c__4550__auto__; +var G__4385 = cljs.core.count(c__4550__auto__); +var G__4386 = (0); +seq__4357 = G__4383; +chunk__4358 = G__4384; +count__4359 = G__4385; +i__4360 = G__4386; +continue; +} else { +var vec__4370 = cljs.core.first(seq__4357__$1); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4370,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4370,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4387 = cljs.core.next(seq__4357__$1); +var G__4388 = null; +var G__4389 = (0); +var G__4390 = (0); +seq__4357 = G__4387; +chunk__4358 = G__4388; +count__4359 = G__4389; +i__4360 = G__4390; +continue; +} +} else { +return null; +} +} +break; +} +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,k,null); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,k,not_found){ +var self__ = this; +var coll__$1 = this; +var idx = cljs.core.array_map_index_of(coll__$1,k); +if((idx === (-1))){ +return not_found; +} else { +return (self__.arr[(idx + (1))]); +} +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IKVReduce$_kv_reduce$arity$3 = (function (coll,f,init){ +var self__ = this; +var coll__$1 = this; +var len = self__.arr.length; +var i = (0); +var init__$1 = init; +while(true){ +if((i < len)){ +var init__$2 = (function (){var G__4373 = init__$1; +var G__4374 = (self__.arr[i]); +var G__4375 = (self__.arr[(i + (1))]); +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__4373,G__4374,G__4375) : f.call(null,G__4373,G__4374,G__4375)); +})(); +if(cljs.core.reduced_QMARK_(init__$2)){ +return cljs.core.deref(init__$2); +} else { +var G__4391 = (i + (2)); +var G__4392 = init__$2; +i = G__4391; +init__$1 = G__4392; +continue; +} +} else { +return init__$1; +} +break; +} +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return (new cljs.core.PersistentArrayMapIterator(self__.arr,(0),(self__.cnt * (2)))); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.PersistentArrayMap(self__.meta,self__.cnt,self__.arr,self__.__hash)); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.cnt; +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_unordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +if(((cljs.core.map_QMARK_(other)) && ((!(cljs.core.record_QMARK_(other)))))){ +var alen = self__.arr.length; +var other__$1 = other; +if((self__.cnt === other__$1.cljs$core$ICounted$_count$arity$1(null))){ +var i = (0); +while(true){ +if((i < alen)){ +var v = other__$1.cljs$core$ILookup$_lookup$arity$3(null,(self__.arr[i]),cljs.core.lookup_sentinel); +if((!((v === cljs.core.lookup_sentinel)))){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2((self__.arr[(i + (1))]),v)){ +var G__4393 = (i + (2)); +i = G__4393; +continue; +} else { +return false; +} +} else { +return false; +} +} else { +return true; +} +break; +} +} else { +return false; +} +} else { +return false; +} +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IEditableCollection$_as_transient$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.TransientArrayMap(({}),self__.arr.length,cljs.core.aclone(self__.arr))); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.PersistentArrayMap.EMPTY,self__.meta); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.iter_reduce.cljs$core$IFn$_invoke$arity$2(coll__$1,f); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.iter_reduce.cljs$core$IFn$_invoke$arity$3(coll__$1,f,start); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IMap$_dissoc$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +var idx = cljs.core.array_map_index_of(coll__$1,k); +if((idx >= (0))){ +var len = self__.arr.length; +var new_len = (len - (2)); +if((new_len === (0))){ +return coll__$1.cljs$core$IEmptyableCollection$_empty$arity$1(null); +} else { +var new_arr = (new Array(new_len)); +var s = (0); +var d = (0); +while(true){ +if((s >= len)){ +return (new cljs.core.PersistentArrayMap(self__.meta,(self__.cnt - (1)),new_arr,null)); +} else { +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(k,(self__.arr[s]))){ +var G__4394 = (s + (2)); +var G__4395 = d; +s = G__4394; +d = G__4395; +continue; +} else { +(new_arr[d] = (self__.arr[s])); + +(new_arr[(d + (1))] = (self__.arr[(s + (1))])); + +var G__4396 = (s + (2)); +var G__4397 = (d + (2)); +s = G__4396; +d = G__4397; +continue; + +} +} +break; +} +} +} else { +return coll__$1; +} +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (coll,k,v){ +var self__ = this; +var coll__$1 = this; +var idx = cljs.core.array_map_index_of(coll__$1,k); +if((idx === (-1))){ +if((self__.cnt < cljs.core.PersistentArrayMap.HASHMAP_THRESHOLD)){ +var arr__$1 = cljs.core.array_map_extend_kv(coll__$1,k,v); +return (new cljs.core.PersistentArrayMap(self__.meta,(self__.cnt + (1)),arr__$1,null)); +} else { +return cljs.core._with_meta(cljs.core._assoc(cljs.core.into.cljs$core$IFn$_invoke$arity$2(cljs.core.PersistentHashMap.EMPTY,coll__$1),k,v),self__.meta); +} +} else { +if((v === (self__.arr[(idx + (1))]))){ +return coll__$1; +} else { +var arr__$1 = (function (){var G__4378 = cljs.core.aclone(self__.arr); +(G__4378[(idx + (1))] = v); + +return G__4378; +})(); +return (new cljs.core.PersistentArrayMap(self__.meta,self__.cnt,arr__$1,null)); + +} +} +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return (!((cljs.core.array_map_index_of(coll__$1,k) === (-1)))); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.persistent_array_map_seq(self__.arr,(0),null); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentArrayMap(new_meta,self__.cnt,self__.arr,self__.__hash)); +} +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,entry){ +var self__ = this; +var coll__$1 = this; +if(cljs.core.vector_QMARK_(entry)){ +return coll__$1.cljs$core$IAssociative$_assoc$arity$3(null,cljs.core._nth.cljs$core$IFn$_invoke$arity$2(entry,(0)),cljs.core._nth.cljs$core$IFn$_invoke$arity$2(entry,(1))); +} else { +var ret = coll__$1; +var es = cljs.core.seq(entry); +while(true){ +if((es == null)){ +return ret; +} else { +var e = cljs.core.first(es); +if(cljs.core.vector_QMARK_(e)){ +var G__4398 = cljs.core._assoc(ret,cljs.core._nth.cljs$core$IFn$_invoke$arity$2(e,(0)),cljs.core._nth.cljs$core$IFn$_invoke$arity$2(e,(1))); +var G__4399 = cljs.core.next(es); +ret = G__4398; +es = G__4399; +continue; +} else { +throw (new Error("conj on a map takes map entries or seqables of map entries")); +} +} +break; +} +} +}); + +cljs.core.PersistentArrayMap.prototype.call = (function() { +var G__4400 = null; +var G__4400__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); +var G__4400__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); +G__4400 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4400__2.call(this,self__,k); +case 3: +return G__4400__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4400.cljs$core$IFn$_invoke$arity$2 = G__4400__2; +G__4400.cljs$core$IFn$_invoke$arity$3 = G__4400__3; +return G__4400; +})() +; + +cljs.core.PersistentArrayMap.prototype.apply = (function (self__,args4356){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4356))); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.PersistentArrayMap.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$cnt,cljs.core.cst$sym$arr,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentArrayMap.cljs$lang$type = true; + +cljs.core.PersistentArrayMap.cljs$lang$ctorStr = "cljs.core/PersistentArrayMap"; + +cljs.core.PersistentArrayMap.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentArrayMap"); +}); + +/** + * Positional factory function for cljs.core/PersistentArrayMap. + */ +cljs.core.__GT_PersistentArrayMap = (function cljs$core$__GT_PersistentArrayMap(meta,cnt,arr,__hash){ +return (new cljs.core.PersistentArrayMap(meta,cnt,arr,__hash)); +}); + +cljs.core.PersistentArrayMap.EMPTY = (new cljs.core.PersistentArrayMap(null,(0),[],cljs.core.empty_unordered_hash)); +cljs.core.PersistentArrayMap.HASHMAP_THRESHOLD = (8); +cljs.core.PersistentArrayMap.fromArray = (function (arr,no_clone,no_check){ +var arr__$1 = ((no_clone)?arr:cljs.core.aclone(arr)); +var arr__$2 = ((no_check)?arr__$1:(function (){var ret = []; +var i_4401 = (0); +while(true){ +if((i_4401 < arr__$1.length)){ +var k_4402 = (arr__$1[i_4401]); +var v_4403 = (arr__$1[(i_4401 + (1))]); +var idx_4404 = cljs.core.array_index_of(ret,k_4402); +if((idx_4404 === (-1))){ +ret.push(k_4402); + +ret.push(v_4403); +} else { +} + +var G__4405 = (i_4401 + (2)); +i_4401 = G__4405; +continue; +} else { +} +break; +} + +return ret; +})()); +var cnt = (arr__$2.length / (2)); +return (new cljs.core.PersistentArrayMap(null,cnt,arr__$2,null)); +}); +cljs.core.PersistentArrayMap.createWithCheck = (function (arr){ +var ret = []; +var i_4407 = (0); +while(true){ +if((i_4407 < arr.length)){ +var k_4408 = (arr[i_4407]); +var v_4409 = (arr[(i_4407 + (1))]); +var idx_4410 = cljs.core.array_index_of(ret,k_4408); +if((idx_4410 === (-1))){ +var G__4406_4411 = ret; +G__4406_4411.push(k_4408); + +G__4406_4411.push(v_4409); + +} else { +throw (new Error(["Duplicate key: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(k_4408)].join(''))); +} + +var G__4412 = (i_4407 + (2)); +i_4407 = G__4412; +continue; +} else { +} +break; +} + +var cnt = (arr.length / (2)); +return (new cljs.core.PersistentArrayMap(null,cnt,arr,null)); +}); +cljs.core.PersistentArrayMap.createAsIfByAssoc = (function (arr){ +var ret = []; +var i_4414 = (0); +while(true){ +if((i_4414 < arr.length)){ +var k_4415 = (arr[i_4414]); +var v_4416 = (arr[(i_4414 + (1))]); +var idx_4417 = cljs.core.array_index_of(ret,k_4415); +if((idx_4417 === (-1))){ +var G__4413_4418 = ret; +G__4413_4418.push(k_4415); + +G__4413_4418.push(v_4416); + +} else { +(ret[(idx_4417 + (1))] = v_4416); +} + +var G__4419 = (i_4414 + (2)); +i_4414 = G__4419; +continue; +} else { +} +break; +} + +return (new cljs.core.PersistentArrayMap(null,(ret.length / (2)),ret,null)); +}); +var G__4420_4423 = cljs.core.PersistentArrayMap.prototype; +var G__4421_4424 = cljs.core.ITER_SYMBOL; +var G__4422_4425 = ((function (G__4420_4423,G__4421_4424){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4420_4423,G__4421_4424)) +; +goog.object.set(G__4420_4423,G__4421_4424,G__4422_4425); + +/** +* @constructor + * @implements {cljs.core.IFn} + * @implements {cljs.core.ITransientMap} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ITransientCollection} + * @implements {cljs.core.ITransientAssociative} + * @implements {cljs.core.ILookup} +*/ +cljs.core.TransientArrayMap = (function (editable_QMARK_,len,arr){ +this.editable_QMARK_ = editable_QMARK_; +this.len = len; +this.arr = arr; +this.cljs$lang$protocol_mask$partition0$ = 259; +this.cljs$lang$protocol_mask$partition1$ = 56; +}); +cljs.core.TransientArrayMap.prototype.cljs$core$ICounted$_count$arity$1 = (function (tcoll){ +var self__ = this; +var tcoll__$1 = this; +if(cljs.core.truth_(self__.editable_QMARK_)){ +return cljs.core.quot(self__.len,(2)); +} else { +throw (new Error("count after persistent!")); +} +}); + +cljs.core.TransientArrayMap.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (tcoll,k){ +var self__ = this; +var tcoll__$1 = this; +return tcoll__$1.cljs$core$ILookup$_lookup$arity$3(null,k,null); +}); + +cljs.core.TransientArrayMap.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (tcoll,k,not_found){ +var self__ = this; +var tcoll__$1 = this; +if(cljs.core.truth_(self__.editable_QMARK_)){ +var idx = cljs.core.array_map_index_of(tcoll__$1,k); +if((idx === (-1))){ +return not_found; +} else { +return (self__.arr[(idx + (1))]); +} +} else { +throw (new Error("lookup after persistent!")); +} +}); + +cljs.core.TransientArrayMap.prototype.cljs$core$ITransientCollection$_conj_BANG_$arity$2 = (function (tcoll,o){ +var self__ = this; +var tcoll__$1 = this; +if(cljs.core.truth_(self__.editable_QMARK_)){ +if(cljs.core.map_entry_QMARK_(o)){ +return tcoll__$1.cljs$core$ITransientAssociative$_assoc_BANG_$arity$3(null,cljs.core.key(o),cljs.core.val(o)); +} else { +if(cljs.core.vector_QMARK_(o)){ +return tcoll__$1.cljs$core$ITransientAssociative$_assoc_BANG_$arity$3(null,(o.cljs$core$IFn$_invoke$arity$1 ? o.cljs$core$IFn$_invoke$arity$1((0)) : o.call(null,(0))),(o.cljs$core$IFn$_invoke$arity$1 ? o.cljs$core$IFn$_invoke$arity$1((1)) : o.call(null,(1)))); +} else { +var es = cljs.core.seq(o); +var tcoll__$2 = tcoll__$1; +while(true){ +var temp__5733__auto__ = cljs.core.first(es); +if(cljs.core.truth_(temp__5733__auto__)){ +var e = temp__5733__auto__; +var G__4428 = cljs.core.next(es); +var G__4429 = cljs.core._assoc_BANG_(tcoll__$2,cljs.core.key(e),cljs.core.val(e)); +es = G__4428; +tcoll__$2 = G__4429; +continue; +} else { +return tcoll__$2; +} +break; +} + +} +} +} else { +throw (new Error("conj! after persistent!")); +} +}); + +cljs.core.TransientArrayMap.prototype.cljs$core$ITransientCollection$_persistent_BANG_$arity$1 = (function (tcoll){ +var self__ = this; +var tcoll__$1 = this; +if(cljs.core.truth_(self__.editable_QMARK_)){ +self__.editable_QMARK_ = false; + +return (new cljs.core.PersistentArrayMap(null,cljs.core.quot(self__.len,(2)),self__.arr,null)); +} else { +throw (new Error("persistent! called twice")); +} +}); + +cljs.core.TransientArrayMap.prototype.cljs$core$ITransientAssociative$_assoc_BANG_$arity$3 = (function (tcoll,key,val){ +var self__ = this; +var tcoll__$1 = this; +if(cljs.core.truth_(self__.editable_QMARK_)){ +var idx = cljs.core.array_map_index_of(tcoll__$1,key); +if((idx === (-1))){ +if(((self__.len + (2)) <= ((2) * cljs.core.PersistentArrayMap.HASHMAP_THRESHOLD))){ +self__.len = (self__.len + (2)); + +self__.arr.push(key); + +self__.arr.push(val); + +return tcoll__$1; +} else { +return cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(cljs.core.array__GT_transient_hash_map(self__.len,self__.arr),key,val); +} +} else { +if((val === (self__.arr[(idx + (1))]))){ +return tcoll__$1; +} else { +(self__.arr[(idx + (1))] = val); + +return tcoll__$1; +} +} +} else { +throw (new Error("assoc! after persistent!")); +} +}); + +cljs.core.TransientArrayMap.prototype.cljs$core$ITransientMap$_dissoc_BANG_$arity$2 = (function (tcoll,key){ +var self__ = this; +var tcoll__$1 = this; +if(cljs.core.truth_(self__.editable_QMARK_)){ +var idx = cljs.core.array_map_index_of(tcoll__$1,key); +if((idx >= (0))){ +(self__.arr[idx] = (self__.arr[(self__.len - (2))])); + +(self__.arr[(idx + (1))] = (self__.arr[(self__.len - (1))])); + +var G__4427_4430 = self__.arr; +G__4427_4430.pop(); + +G__4427_4430.pop(); + + +self__.len = (self__.len - (2)); +} else { +} + +return tcoll__$1; +} else { +throw (new Error("dissoc! after persistent!")); +} +}); + +cljs.core.TransientArrayMap.prototype.call = (function() { +var G__4431 = null; +var G__4431__2 = (function (self__,key){ +var self__ = this; +var self____$1 = this; +var tcoll = self____$1; +return tcoll.cljs$core$ILookup$_lookup$arity$3(null,key,null); +}); +var G__4431__3 = (function (self__,key,not_found){ +var self__ = this; +var self____$1 = this; +var tcoll = self____$1; +return tcoll.cljs$core$ILookup$_lookup$arity$3(null,key,not_found); +}); +G__4431 = function(self__,key,not_found){ +switch(arguments.length){ +case 2: +return G__4431__2.call(this,self__,key); +case 3: +return G__4431__3.call(this,self__,key,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4431.cljs$core$IFn$_invoke$arity$2 = G__4431__2; +G__4431.cljs$core$IFn$_invoke$arity$3 = G__4431__3; +return G__4431; +})() +; + +cljs.core.TransientArrayMap.prototype.apply = (function (self__,args4426){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4426))); +}); + +cljs.core.TransientArrayMap.prototype.cljs$core$IFn$_invoke$arity$1 = (function (key){ +var self__ = this; +var tcoll = this; +return tcoll.cljs$core$ILookup$_lookup$arity$3(null,key,null); +}); + +cljs.core.TransientArrayMap.prototype.cljs$core$IFn$_invoke$arity$2 = (function (key,not_found){ +var self__ = this; +var tcoll = this; +return tcoll.cljs$core$ILookup$_lookup$arity$3(null,key,not_found); +}); + +cljs.core.TransientArrayMap.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$editable_QMARK_,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$len,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.cst$sym$arr], null); +}); + +cljs.core.TransientArrayMap.cljs$lang$type = true; + +cljs.core.TransientArrayMap.cljs$lang$ctorStr = "cljs.core/TransientArrayMap"; + +cljs.core.TransientArrayMap.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/TransientArrayMap"); +}); + +/** + * Positional factory function for cljs.core/TransientArrayMap. + */ +cljs.core.__GT_TransientArrayMap = (function cljs$core$__GT_TransientArrayMap(editable_QMARK_,len,arr){ +return (new cljs.core.TransientArrayMap(editable_QMARK_,len,arr)); +}); + +cljs.core.array__GT_transient_hash_map = (function cljs$core$array__GT_transient_hash_map(len,arr){ +var out = cljs.core.transient$(cljs.core.PersistentHashMap.EMPTY); +var i = (0); +while(true){ +if((i < len)){ +var G__4432 = cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(out,(arr[i]),(arr[(i + (1))])); +var G__4433 = (i + (2)); +out = G__4432; +i = G__4433; +continue; +} else { +return out; +} +break; +} +}); + +/** +* @constructor +*/ +cljs.core.Box = (function (val){ +this.val = val; +}); + +cljs.core.Box.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$val,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Box.cljs$lang$type = true; + +cljs.core.Box.cljs$lang$ctorStr = "cljs.core/Box"; + +cljs.core.Box.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Box"); +}); + +/** + * Positional factory function for cljs.core/Box. + */ +cljs.core.__GT_Box = (function cljs$core$__GT_Box(val){ +return (new cljs.core.Box(val)); +}); + + + + + + +cljs.core.key_test = (function cljs$core$key_test(key,other){ +if((key === other)){ +return true; +} else { +if(cljs.core.keyword_identical_QMARK_(key,other)){ +return true; +} else { +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(key,other); + +} +} +}); +cljs.core.mask = (function cljs$core$mask(hash,shift){ +return ((hash >>> shift) & (31)); +}); +cljs.core.clone_and_set = (function cljs$core$clone_and_set(var_args){ +var G__4435 = arguments.length; +switch (G__4435) { +case 3: +return cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 5: +return cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3 = (function (arr,i,a){ +var G__4436 = cljs.core.aclone(arr); +(G__4436[i] = a); + +return G__4436; +}); + +cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$5 = (function (arr,i,a,j,b){ +var G__4437 = cljs.core.aclone(arr); +(G__4437[i] = a); + +(G__4437[j] = b); + +return G__4437; +}); + +cljs.core.clone_and_set.cljs$lang$maxFixedArity = 5; + +cljs.core.remove_pair = (function cljs$core$remove_pair(arr,i){ +var new_arr = (new Array((arr.length - (2)))); +cljs.core.array_copy(arr,(0),new_arr,(0),((2) * i)); + +cljs.core.array_copy(arr,((2) * (i + (1))),new_arr,((2) * i),(new_arr.length - ((2) * i))); + +return new_arr; +}); +cljs.core.bitmap_indexed_node_index = (function cljs$core$bitmap_indexed_node_index(bitmap,bit){ +return cljs.core.bit_count((bitmap & (bit - (1)))); +}); +cljs.core.bitpos = (function cljs$core$bitpos(hash,shift){ +return ((1) << ((hash >>> shift) & 0x01f)); +}); +cljs.core.edit_and_set = (function cljs$core$edit_and_set(var_args){ +var G__4440 = arguments.length; +switch (G__4440) { +case 4: +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)])); + +break; +case 6: +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$6((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4 = (function (inode,edit,i,a){ +var editable = inode.ensure_editable(edit); +(editable.arr[i] = a); + +return editable; +}); + +cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$6 = (function (inode,edit,i,a,j,b){ +var editable = inode.ensure_editable(edit); +(editable.arr[i] = a); + +(editable.arr[j] = b); + +return editable; +}); + +cljs.core.edit_and_set.cljs$lang$maxFixedArity = 6; + +cljs.core.inode_kv_reduce = (function cljs$core$inode_kv_reduce(arr,f,init){ +var len = arr.length; +var i = (0); +var init__$1 = init; +while(true){ +if((i < len)){ +var init__$2 = (function (){var k = (arr[i]); +if((!((k == null)))){ +var G__4442 = init__$1; +var G__4443 = k; +var G__4444 = (arr[(i + (1))]); +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__4442,G__4443,G__4444) : f.call(null,G__4442,G__4443,G__4444)); +} else { +var node = (arr[(i + (1))]); +if((!((node == null)))){ +return node.kv_reduce(f,init__$1); +} else { +return init__$1; +} +} +})(); +if(cljs.core.reduced_QMARK_(init__$2)){ +return init__$2; +} else { +var G__4445 = (i + (2)); +var G__4446 = init__$2; +i = G__4445; +init__$1 = G__4446; +continue; +} +} else { +return init__$1; +} +break; +} +}); + +/** +* @constructor +*/ +cljs.core.NodeIterator = (function (arr,i,next_entry,next_iter){ +this.arr = arr; +this.i = i; +this.next_entry = next_entry; +this.next_iter = next_iter; +}); +cljs.core.NodeIterator.prototype.advance = (function (){ +var self__ = this; +var this$ = this; +var len = self__.arr.length; +while(true){ +if((self__.i < len)){ +var key = (self__.arr[self__.i]); +var node_or_val = (self__.arr[(self__.i + (1))]); +var found = (((!((key == null))))?self__.next_entry = (new cljs.core.MapEntry(key,node_or_val,null)):(((!((node_or_val == null))))?(function (){var new_iter = cljs.core._iterator(node_or_val); +if(new_iter.hasNext()){ +return self__.next_iter = new_iter; +} else { +return false; +} +})():false +)); +self__.i = (self__.i + (2)); + +if(found){ +return true; +} else { +continue; +} +} else { +return false; +} +break; +} +}); + +cljs.core.NodeIterator.prototype.hasNext = (function (){ +var self__ = this; +var this$ = this; +var or__4131__auto__ = (!((self__.next_entry == null))); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (!((self__.next_iter == null))); +if(or__4131__auto____$1){ +return or__4131__auto____$1; +} else { +return this$.advance(); +} +} +}); + +cljs.core.NodeIterator.prototype.next = (function (){ +var self__ = this; +var this$ = this; +if((!((self__.next_entry == null)))){ +var ret = self__.next_entry; +self__.next_entry = null; + +return ret; +} else { +if((!((self__.next_iter == null)))){ +var ret = self__.next_iter.next(); +if(self__.next_iter.hasNext()){ +} else { +self__.next_iter = null; +} + +return ret; +} else { +if(this$.advance()){ +return this$.next(); +} else { +throw (new Error("No such element")); + +} +} +} +}); + +cljs.core.NodeIterator.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.NodeIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$arr,cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$next_DASH_entry,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$next_DASH_iter,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.NodeIterator.cljs$lang$type = true; + +cljs.core.NodeIterator.cljs$lang$ctorStr = "cljs.core/NodeIterator"; + +cljs.core.NodeIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/NodeIterator"); +}); + +/** + * Positional factory function for cljs.core/NodeIterator. + */ +cljs.core.__GT_NodeIterator = (function cljs$core$__GT_NodeIterator(arr,i,next_entry,next_iter){ +return (new cljs.core.NodeIterator(arr,i,next_entry,next_iter)); +}); + + +/** +* @constructor + * @implements {cljs.core.IIterable} +*/ +cljs.core.BitmapIndexedNode = (function (edit,bitmap,arr){ +this.edit = edit; +this.bitmap = bitmap; +this.arr = arr; +this.cljs$lang$protocol_mask$partition1$ = 131072; +this.cljs$lang$protocol_mask$partition0$ = 0; +}); +cljs.core.BitmapIndexedNode.prototype.ensure_editable = (function (e){ +var self__ = this; +var inode = this; +if((e === self__.edit)){ +return inode; +} else { +var n = cljs.core.bit_count(self__.bitmap); +var new_arr = (new Array((((n < (0)))?(4):((2) * (n + (1)))))); +cljs.core.array_copy(self__.arr,(0),new_arr,(0),((2) * n)); + +return (new cljs.core.BitmapIndexedNode(e,self__.bitmap,new_arr)); +} +}); + +cljs.core.BitmapIndexedNode.prototype.inode_without_BANG_ = (function (edit__$1,shift,hash,key,removed_leaf_QMARK_){ +var self__ = this; +var inode = this; +var bit = (1 << ((hash >>> shift) & 0x01f)); +if(((self__.bitmap & bit) === (0))){ +return inode; +} else { +var idx = cljs.core.bitmap_indexed_node_index(self__.bitmap,bit); +var key_or_nil = (self__.arr[((2) * idx)]); +var val_or_node = (self__.arr[(((2) * idx) + (1))]); +if((key_or_nil == null)){ +var n = val_or_node.inode_without_BANG_(edit__$1,(shift + (5)),hash,key,removed_leaf_QMARK_); +if((n === val_or_node)){ +return inode; +} else { +if((!((n == null)))){ +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4(inode,edit__$1,(((2) * idx) + (1)),n); +} else { +if((self__.bitmap === bit)){ +return null; +} else { +return inode.edit_and_remove_pair(edit__$1,bit,idx); + +} +} +} +} else { +if(cljs.core.key_test(key,key_or_nil)){ +removed_leaf_QMARK_.val = true; + +return inode.edit_and_remove_pair(edit__$1,bit,idx); +} else { +return inode; + +} +} +} +}); + +cljs.core.BitmapIndexedNode.prototype.edit_and_remove_pair = (function (e,bit,i){ +var self__ = this; +var inode = this; +if((self__.bitmap === bit)){ +return null; +} else { +var editable = inode.ensure_editable(e); +var earr = editable.arr; +var len = earr.length; +editable.bitmap = (bit ^ editable.bitmap); + +cljs.core.array_copy(earr,((2) * (i + (1))),earr,((2) * i),(len - ((2) * (i + (1))))); + +(earr[(len - (2))] = null); + +(earr[(len - (1))] = null); + +return editable; +} +}); + +cljs.core.BitmapIndexedNode.prototype.inode_seq = (function (){ +var self__ = this; +var inode = this; +return cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$1(self__.arr); +}); + +cljs.core.BitmapIndexedNode.prototype.kv_reduce = (function (f,init){ +var self__ = this; +var inode = this; +return cljs.core.inode_kv_reduce(self__.arr,f,init); +}); + +cljs.core.BitmapIndexedNode.prototype.inode_lookup = (function (shift,hash,key,not_found){ +var self__ = this; +var inode = this; +var bit = (1 << ((hash >>> shift) & 0x01f)); +if(((self__.bitmap & bit) === (0))){ +return not_found; +} else { +var idx = cljs.core.bitmap_indexed_node_index(self__.bitmap,bit); +var key_or_nil = (self__.arr[((2) * idx)]); +var val_or_node = (self__.arr[(((2) * idx) + (1))]); +if((key_or_nil == null)){ +return val_or_node.inode_lookup((shift + (5)),hash,key,not_found); +} else { +if(cljs.core.key_test(key,key_or_nil)){ +return val_or_node; +} else { +return not_found; + +} +} +} +}); + +cljs.core.BitmapIndexedNode.prototype.inode_assoc_BANG_ = (function (edit__$1,shift,hash,key,val,added_leaf_QMARK_){ +var self__ = this; +var inode = this; +var bit = (1 << ((hash >>> shift) & 0x01f)); +var idx = cljs.core.bitmap_indexed_node_index(self__.bitmap,bit); +if(((self__.bitmap & bit) === (0))){ +var n = cljs.core.bit_count(self__.bitmap); +if((((2) * n) < self__.arr.length)){ +var editable = inode.ensure_editable(edit__$1); +var earr = editable.arr; +added_leaf_QMARK_.val = true; + +cljs.core.array_copy_downward(earr,((2) * idx),earr,((2) * (idx + (1))),((2) * (n - idx))); + +(earr[((2) * idx)] = key); + +(earr[(((2) * idx) + (1))] = val); + +editable.bitmap = (editable.bitmap | bit); + +return editable; +} else { +if((n >= (16))){ +var nodes = [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]; +var jdx = ((hash >>> shift) & 0x01f); +(nodes[jdx] = cljs.core.BitmapIndexedNode.EMPTY.inode_assoc_BANG_(edit__$1,(shift + (5)),hash,key,val,added_leaf_QMARK_)); + +var i_4447 = (0); +var j_4448 = (0); +while(true){ +if((i_4447 < (32))){ +if((((self__.bitmap >>> i_4447) & (1)) === (0))){ +var G__4449 = (i_4447 + (1)); +var G__4450 = j_4448; +i_4447 = G__4449; +j_4448 = G__4450; +continue; +} else { +(nodes[i_4447] = (((!(((self__.arr[j_4448]) == null))))?cljs.core.BitmapIndexedNode.EMPTY.inode_assoc_BANG_(edit__$1,(shift + (5)),cljs.core.hash((self__.arr[j_4448])),(self__.arr[j_4448]),(self__.arr[(j_4448 + (1))]),added_leaf_QMARK_):(self__.arr[(j_4448 + (1))]))); + +var G__4451 = (i_4447 + (1)); +var G__4452 = (j_4448 + (2)); +i_4447 = G__4451; +j_4448 = G__4452; +continue; +} +} else { +} +break; +} + +return (new cljs.core.ArrayNode(edit__$1,(n + (1)),nodes)); +} else { +var new_arr = (new Array(((2) * (n + (4))))); +cljs.core.array_copy(self__.arr,(0),new_arr,(0),((2) * idx)); + +(new_arr[((2) * idx)] = key); + +(new_arr[(((2) * idx) + (1))] = val); + +cljs.core.array_copy(self__.arr,((2) * idx),new_arr,((2) * (idx + (1))),((2) * (n - idx))); + +added_leaf_QMARK_.val = true; + +var editable = inode.ensure_editable(edit__$1); +editable.arr = new_arr; + +editable.bitmap = (editable.bitmap | bit); + +return editable; + +} +} +} else { +var key_or_nil = (self__.arr[((2) * idx)]); +var val_or_node = (self__.arr[(((2) * idx) + (1))]); +if((key_or_nil == null)){ +var n = val_or_node.inode_assoc_BANG_(edit__$1,(shift + (5)),hash,key,val,added_leaf_QMARK_); +if((n === val_or_node)){ +return inode; +} else { +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4(inode,edit__$1,(((2) * idx) + (1)),n); +} +} else { +if(cljs.core.key_test(key,key_or_nil)){ +if((val === val_or_node)){ +return inode; +} else { +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4(inode,edit__$1,(((2) * idx) + (1)),val); +} +} else { +added_leaf_QMARK_.val = true; + +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$6(inode,edit__$1,((2) * idx),null,(((2) * idx) + (1)),cljs.core.create_node.cljs$core$IFn$_invoke$arity$7(edit__$1,(shift + (5)),key_or_nil,val_or_node,hash,key,val)); + +} +} +} +}); + +cljs.core.BitmapIndexedNode.prototype.inode_assoc = (function (shift,hash,key,val,added_leaf_QMARK_){ +var self__ = this; +var inode = this; +var bit = (1 << ((hash >>> shift) & 0x01f)); +var idx = cljs.core.bitmap_indexed_node_index(self__.bitmap,bit); +if(((self__.bitmap & bit) === (0))){ +var n = cljs.core.bit_count(self__.bitmap); +if((n >= (16))){ +var nodes = [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]; +var jdx = ((hash >>> shift) & 0x01f); +(nodes[jdx] = cljs.core.BitmapIndexedNode.EMPTY.inode_assoc((shift + (5)),hash,key,val,added_leaf_QMARK_)); + +var i_4453 = (0); +var j_4454 = (0); +while(true){ +if((i_4453 < (32))){ +if((((self__.bitmap >>> i_4453) & (1)) === (0))){ +var G__4455 = (i_4453 + (1)); +var G__4456 = j_4454; +i_4453 = G__4455; +j_4454 = G__4456; +continue; +} else { +(nodes[i_4453] = (((!(((self__.arr[j_4454]) == null))))?cljs.core.BitmapIndexedNode.EMPTY.inode_assoc((shift + (5)),cljs.core.hash((self__.arr[j_4454])),(self__.arr[j_4454]),(self__.arr[(j_4454 + (1))]),added_leaf_QMARK_):(self__.arr[(j_4454 + (1))]))); + +var G__4457 = (i_4453 + (1)); +var G__4458 = (j_4454 + (2)); +i_4453 = G__4457; +j_4454 = G__4458; +continue; +} +} else { +} +break; +} + +return (new cljs.core.ArrayNode(null,(n + (1)),nodes)); +} else { +var new_arr = (new Array(((2) * (n + (1))))); +cljs.core.array_copy(self__.arr,(0),new_arr,(0),((2) * idx)); + +(new_arr[((2) * idx)] = key); + +(new_arr[(((2) * idx) + (1))] = val); + +cljs.core.array_copy(self__.arr,((2) * idx),new_arr,((2) * (idx + (1))),((2) * (n - idx))); + +added_leaf_QMARK_.val = true; + +return (new cljs.core.BitmapIndexedNode(null,(self__.bitmap | bit),new_arr)); +} +} else { +var key_or_nil = (self__.arr[((2) * idx)]); +var val_or_node = (self__.arr[(((2) * idx) + (1))]); +if((key_or_nil == null)){ +var n = val_or_node.inode_assoc((shift + (5)),hash,key,val,added_leaf_QMARK_); +if((n === val_or_node)){ +return inode; +} else { +return (new cljs.core.BitmapIndexedNode(null,self__.bitmap,cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3(self__.arr,(((2) * idx) + (1)),n))); +} +} else { +if(cljs.core.key_test(key,key_or_nil)){ +if((val === val_or_node)){ +return inode; +} else { +return (new cljs.core.BitmapIndexedNode(null,self__.bitmap,cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3(self__.arr,(((2) * idx) + (1)),val))); +} +} else { +added_leaf_QMARK_.val = true; + +return (new cljs.core.BitmapIndexedNode(null,self__.bitmap,cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$5(self__.arr,((2) * idx),null,(((2) * idx) + (1)),cljs.core.create_node.cljs$core$IFn$_invoke$arity$6((shift + (5)),key_or_nil,val_or_node,hash,key,val)))); + +} +} +} +}); + +cljs.core.BitmapIndexedNode.prototype.inode_find = (function (shift,hash,key,not_found){ +var self__ = this; +var inode = this; +var bit = (1 << ((hash >>> shift) & 0x01f)); +if(((self__.bitmap & bit) === (0))){ +return not_found; +} else { +var idx = cljs.core.bitmap_indexed_node_index(self__.bitmap,bit); +var key_or_nil = (self__.arr[((2) * idx)]); +var val_or_node = (self__.arr[(((2) * idx) + (1))]); +if((key_or_nil == null)){ +return val_or_node.inode_find((shift + (5)),hash,key,not_found); +} else { +if(cljs.core.key_test(key,key_or_nil)){ +return (new cljs.core.MapEntry(key_or_nil,val_or_node,null)); +} else { +return not_found; + +} +} +} +}); + +cljs.core.BitmapIndexedNode.prototype.inode_without = (function (shift,hash,key){ +var self__ = this; +var inode = this; +var bit = (1 << ((hash >>> shift) & 0x01f)); +if(((self__.bitmap & bit) === (0))){ +return inode; +} else { +var idx = cljs.core.bitmap_indexed_node_index(self__.bitmap,bit); +var key_or_nil = (self__.arr[((2) * idx)]); +var val_or_node = (self__.arr[(((2) * idx) + (1))]); +if((key_or_nil == null)){ +var n = val_or_node.inode_without((shift + (5)),hash,key); +if((n === val_or_node)){ +return inode; +} else { +if((!((n == null)))){ +return (new cljs.core.BitmapIndexedNode(null,self__.bitmap,cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3(self__.arr,(((2) * idx) + (1)),n))); +} else { +if((self__.bitmap === bit)){ +return null; +} else { +return (new cljs.core.BitmapIndexedNode(null,(self__.bitmap ^ bit),cljs.core.remove_pair(self__.arr,idx))); + +} +} +} +} else { +if(cljs.core.key_test(key,key_or_nil)){ +return (new cljs.core.BitmapIndexedNode(null,(self__.bitmap ^ bit),cljs.core.remove_pair(self__.arr,idx))); +} else { +return inode; + +} +} +} +}); + +cljs.core.BitmapIndexedNode.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.NodeIterator(self__.arr,(0),null,null)); +}); + +cljs.core.BitmapIndexedNode.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$edit,cljs.core.with_meta(cljs.core.cst$sym$bitmap,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$arr,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.BitmapIndexedNode.cljs$lang$type = true; + +cljs.core.BitmapIndexedNode.cljs$lang$ctorStr = "cljs.core/BitmapIndexedNode"; + +cljs.core.BitmapIndexedNode.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/BitmapIndexedNode"); +}); + +/** + * Positional factory function for cljs.core/BitmapIndexedNode. + */ +cljs.core.__GT_BitmapIndexedNode = (function cljs$core$__GT_BitmapIndexedNode(edit,bitmap,arr){ +return (new cljs.core.BitmapIndexedNode(edit,bitmap,arr)); +}); + +cljs.core.BitmapIndexedNode.EMPTY = (new cljs.core.BitmapIndexedNode(null,(0),[])); +cljs.core.pack_array_node = (function cljs$core$pack_array_node(array_node,edit,idx){ +var arr = array_node.arr; +var len = arr.length; +var new_arr = (new Array(((2) * (array_node.cnt - (1))))); +var i = (0); +var j = (1); +var bitmap = (0); +while(true){ +if((i < len)){ +if((((!((i === idx)))) && ((!(((arr[i]) == null)))))){ +(new_arr[j] = (arr[i])); + +var G__4459 = (i + (1)); +var G__4460 = (j + (2)); +var G__4461 = (bitmap | ((1) << i)); +i = G__4459; +j = G__4460; +bitmap = G__4461; +continue; +} else { +var G__4462 = (i + (1)); +var G__4463 = j; +var G__4464 = bitmap; +i = G__4462; +j = G__4463; +bitmap = G__4464; +continue; +} +} else { +return (new cljs.core.BitmapIndexedNode(edit,bitmap,new_arr)); +} +break; +} +}); + +/** +* @constructor +*/ +cljs.core.ArrayNodeIterator = (function (arr,i,next_iter){ +this.arr = arr; +this.i = i; +this.next_iter = next_iter; +}); +cljs.core.ArrayNodeIterator.prototype.hasNext = (function (){ +var self__ = this; +var this$ = this; +var len = self__.arr.length; +while(true){ +if((!((((!((self__.next_iter == null)))) && (self__.next_iter.hasNext()))))){ +if((self__.i < len)){ +var node = (self__.arr[self__.i]); +self__.i = (self__.i + (1)); + +if((!((node == null)))){ +self__.next_iter = cljs.core._iterator(node); +} else { +} + +continue; +} else { +return false; +} +} else { +return true; +} +break; +} +}); + +cljs.core.ArrayNodeIterator.prototype.next = (function (){ +var self__ = this; +var this$ = this; +if(this$.hasNext()){ +return self__.next_iter.next(); +} else { +throw (new Error("No such element")); +} +}); + +cljs.core.ArrayNodeIterator.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.ArrayNodeIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$arr,cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$next_DASH_iter,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ArrayNodeIterator.cljs$lang$type = true; + +cljs.core.ArrayNodeIterator.cljs$lang$ctorStr = "cljs.core/ArrayNodeIterator"; + +cljs.core.ArrayNodeIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ArrayNodeIterator"); +}); + +/** + * Positional factory function for cljs.core/ArrayNodeIterator. + */ +cljs.core.__GT_ArrayNodeIterator = (function cljs$core$__GT_ArrayNodeIterator(arr,i,next_iter){ +return (new cljs.core.ArrayNodeIterator(arr,i,next_iter)); +}); + + +/** +* @constructor + * @implements {cljs.core.IIterable} +*/ +cljs.core.ArrayNode = (function (edit,cnt,arr){ +this.edit = edit; +this.cnt = cnt; +this.arr = arr; +this.cljs$lang$protocol_mask$partition1$ = 131072; +this.cljs$lang$protocol_mask$partition0$ = 0; +}); +cljs.core.ArrayNode.prototype.ensure_editable = (function (e){ +var self__ = this; +var inode = this; +if((e === self__.edit)){ +return inode; +} else { +return (new cljs.core.ArrayNode(e,self__.cnt,cljs.core.aclone(self__.arr))); +} +}); + +cljs.core.ArrayNode.prototype.inode_without_BANG_ = (function (edit__$1,shift,hash,key,removed_leaf_QMARK_){ +var self__ = this; +var inode = this; +var idx = ((hash >>> shift) & 0x01f); +var node = (self__.arr[idx]); +if((node == null)){ +return inode; +} else { +var n = node.inode_without_BANG_(edit__$1,(shift + (5)),hash,key,removed_leaf_QMARK_); +if((n === node)){ +return inode; +} else { +if((n == null)){ +if((self__.cnt <= (8))){ +return cljs.core.pack_array_node(inode,edit__$1,idx); +} else { +var editable = cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4(inode,edit__$1,idx,n); +editable.cnt = (editable.cnt - (1)); + +return editable; +} +} else { +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4(inode,edit__$1,idx,n); + +} +} +} +}); + +cljs.core.ArrayNode.prototype.inode_seq = (function (){ +var self__ = this; +var inode = this; +return cljs.core.create_array_node_seq.cljs$core$IFn$_invoke$arity$1(self__.arr); +}); + +cljs.core.ArrayNode.prototype.kv_reduce = (function (f,init){ +var self__ = this; +var inode = this; +var len = self__.arr.length; +var i = (0); +var init__$1 = init; +while(true){ +if((i < len)){ +var node = (self__.arr[i]); +if((!((node == null)))){ +var init__$2 = node.kv_reduce(f,init__$1); +if(cljs.core.reduced_QMARK_(init__$2)){ +return init__$2; +} else { +var G__4465 = (i + (1)); +var G__4466 = init__$2; +i = G__4465; +init__$1 = G__4466; +continue; +} +} else { +var G__4467 = (i + (1)); +var G__4468 = init__$1; +i = G__4467; +init__$1 = G__4468; +continue; +} +} else { +return init__$1; +} +break; +} +}); + +cljs.core.ArrayNode.prototype.inode_lookup = (function (shift,hash,key,not_found){ +var self__ = this; +var inode = this; +var idx = ((hash >>> shift) & 0x01f); +var node = (self__.arr[idx]); +if((!((node == null)))){ +return node.inode_lookup((shift + (5)),hash,key,not_found); +} else { +return not_found; +} +}); + +cljs.core.ArrayNode.prototype.inode_assoc_BANG_ = (function (edit__$1,shift,hash,key,val,added_leaf_QMARK_){ +var self__ = this; +var inode = this; +var idx = ((hash >>> shift) & 0x01f); +var node = (self__.arr[idx]); +if((node == null)){ +var editable = cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4(inode,edit__$1,idx,cljs.core.BitmapIndexedNode.EMPTY.inode_assoc_BANG_(edit__$1,(shift + (5)),hash,key,val,added_leaf_QMARK_)); +editable.cnt = (editable.cnt + (1)); + +return editable; +} else { +var n = node.inode_assoc_BANG_(edit__$1,(shift + (5)),hash,key,val,added_leaf_QMARK_); +if((n === node)){ +return inode; +} else { +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4(inode,edit__$1,idx,n); +} +} +}); + +cljs.core.ArrayNode.prototype.inode_assoc = (function (shift,hash,key,val,added_leaf_QMARK_){ +var self__ = this; +var inode = this; +var idx = ((hash >>> shift) & 0x01f); +var node = (self__.arr[idx]); +if((node == null)){ +return (new cljs.core.ArrayNode(null,(self__.cnt + (1)),cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3(self__.arr,idx,cljs.core.BitmapIndexedNode.EMPTY.inode_assoc((shift + (5)),hash,key,val,added_leaf_QMARK_)))); +} else { +var n = node.inode_assoc((shift + (5)),hash,key,val,added_leaf_QMARK_); +if((n === node)){ +return inode; +} else { +return (new cljs.core.ArrayNode(null,self__.cnt,cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3(self__.arr,idx,n))); +} +} +}); + +cljs.core.ArrayNode.prototype.inode_find = (function (shift,hash,key,not_found){ +var self__ = this; +var inode = this; +var idx = ((hash >>> shift) & 0x01f); +var node = (self__.arr[idx]); +if((!((node == null)))){ +return node.inode_find((shift + (5)),hash,key,not_found); +} else { +return not_found; +} +}); + +cljs.core.ArrayNode.prototype.inode_without = (function (shift,hash,key){ +var self__ = this; +var inode = this; +var idx = ((hash >>> shift) & 0x01f); +var node = (self__.arr[idx]); +if((!((node == null)))){ +var n = node.inode_without((shift + (5)),hash,key); +if((n === node)){ +return inode; +} else { +if((n == null)){ +if((self__.cnt <= (8))){ +return cljs.core.pack_array_node(inode,null,idx); +} else { +return (new cljs.core.ArrayNode(null,(self__.cnt - (1)),cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3(self__.arr,idx,n))); +} +} else { +return (new cljs.core.ArrayNode(null,self__.cnt,cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3(self__.arr,idx,n))); + +} +} +} else { +return inode; +} +}); + +cljs.core.ArrayNode.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.ArrayNodeIterator(self__.arr,(0),null)); +}); + +cljs.core.ArrayNode.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$edit,cljs.core.with_meta(cljs.core.cst$sym$cnt,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$arr,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ArrayNode.cljs$lang$type = true; + +cljs.core.ArrayNode.cljs$lang$ctorStr = "cljs.core/ArrayNode"; + +cljs.core.ArrayNode.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ArrayNode"); +}); + +/** + * Positional factory function for cljs.core/ArrayNode. + */ +cljs.core.__GT_ArrayNode = (function cljs$core$__GT_ArrayNode(edit,cnt,arr){ +return (new cljs.core.ArrayNode(edit,cnt,arr)); +}); + +cljs.core.hash_collision_node_find_index = (function cljs$core$hash_collision_node_find_index(arr,cnt,key){ +var lim = ((2) * cnt); +var i = (0); +while(true){ +if((i < lim)){ +if(cljs.core.key_test(key,(arr[i]))){ +return i; +} else { +var G__4469 = (i + (2)); +i = G__4469; +continue; +} +} else { +return (-1); +} +break; +} +}); + +/** +* @constructor + * @implements {cljs.core.IIterable} +*/ +cljs.core.HashCollisionNode = (function (edit,collision_hash,cnt,arr){ +this.edit = edit; +this.collision_hash = collision_hash; +this.cnt = cnt; +this.arr = arr; +this.cljs$lang$protocol_mask$partition1$ = 131072; +this.cljs$lang$protocol_mask$partition0$ = 0; +}); +cljs.core.HashCollisionNode.prototype.ensure_editable = (function (e){ +var self__ = this; +var inode = this; +if((e === self__.edit)){ +return inode; +} else { +var new_arr = (new Array(((2) * (self__.cnt + (1))))); +cljs.core.array_copy(self__.arr,(0),new_arr,(0),((2) * self__.cnt)); + +return (new cljs.core.HashCollisionNode(e,self__.collision_hash,self__.cnt,new_arr)); +} +}); + +cljs.core.HashCollisionNode.prototype.inode_without_BANG_ = (function (edit__$1,shift,hash,key,removed_leaf_QMARK_){ +var self__ = this; +var inode = this; +var idx = cljs.core.hash_collision_node_find_index(self__.arr,self__.cnt,key); +if((idx === (-1))){ +return inode; +} else { +removed_leaf_QMARK_.val = true; + +if((self__.cnt === (1))){ +return null; +} else { +var editable = inode.ensure_editable(edit__$1); +var earr = editable.arr; +(earr[idx] = (earr[(((2) * self__.cnt) - (2))])); + +(earr[(idx + (1))] = (earr[(((2) * self__.cnt) - (1))])); + +(earr[(((2) * self__.cnt) - (1))] = null); + +(earr[(((2) * self__.cnt) - (2))] = null); + +editable.cnt = (editable.cnt - (1)); + +return editable; +} +} +}); + +cljs.core.HashCollisionNode.prototype.inode_seq = (function (){ +var self__ = this; +var inode = this; +return cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$1(self__.arr); +}); + +cljs.core.HashCollisionNode.prototype.kv_reduce = (function (f,init){ +var self__ = this; +var inode = this; +return cljs.core.inode_kv_reduce(self__.arr,f,init); +}); + +cljs.core.HashCollisionNode.prototype.inode_lookup = (function (shift,hash,key,not_found){ +var self__ = this; +var inode = this; +var idx = cljs.core.hash_collision_node_find_index(self__.arr,self__.cnt,key); +if((idx < (0))){ +return not_found; +} else { +if(cljs.core.key_test(key,(self__.arr[idx]))){ +return (self__.arr[(idx + (1))]); +} else { +return not_found; + +} +} +}); + +cljs.core.HashCollisionNode.prototype.inode_assoc_BANG_ = (function (edit__$1,shift,hash,key,val,added_leaf_QMARK_){ +var self__ = this; +var inode = this; +if((hash === self__.collision_hash)){ +var idx = cljs.core.hash_collision_node_find_index(self__.arr,self__.cnt,key); +if((idx === (-1))){ +if((self__.arr.length > ((2) * self__.cnt))){ +var editable = cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$6(inode,edit__$1,((2) * self__.cnt),key,(((2) * self__.cnt) + (1)),val); +added_leaf_QMARK_.val = true; + +editable.cnt = (editable.cnt + (1)); + +return editable; +} else { +var len = self__.arr.length; +var new_arr = (new Array((len + (2)))); +cljs.core.array_copy(self__.arr,(0),new_arr,(0),len); + +(new_arr[len] = key); + +(new_arr[(len + (1))] = val); + +added_leaf_QMARK_.val = true; + +return inode.ensure_editable_array(edit__$1,(self__.cnt + (1)),new_arr); +} +} else { +if(((self__.arr[(idx + (1))]) === val)){ +return inode; +} else { +return cljs.core.edit_and_set.cljs$core$IFn$_invoke$arity$4(inode,edit__$1,(idx + (1)),val); +} +} +} else { +return (new cljs.core.BitmapIndexedNode(edit__$1,(1 << ((self__.collision_hash >>> shift) & 0x01f)),[null,inode,null,null])).inode_assoc_BANG_(edit__$1,shift,hash,key,val,added_leaf_QMARK_); +} +}); + +cljs.core.HashCollisionNode.prototype.inode_assoc = (function (shift,hash,key,val,added_leaf_QMARK_){ +var self__ = this; +var inode = this; +if((hash === self__.collision_hash)){ +var idx = cljs.core.hash_collision_node_find_index(self__.arr,self__.cnt,key); +if((idx === (-1))){ +var len = ((2) * self__.cnt); +var new_arr = (new Array((len + (2)))); +cljs.core.array_copy(self__.arr,(0),new_arr,(0),len); + +(new_arr[len] = key); + +(new_arr[(len + (1))] = val); + +added_leaf_QMARK_.val = true; + +return (new cljs.core.HashCollisionNode(null,self__.collision_hash,(self__.cnt + (1)),new_arr)); +} else { +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2((self__.arr[(idx + (1))]),val)){ +return inode; +} else { +return (new cljs.core.HashCollisionNode(null,self__.collision_hash,self__.cnt,cljs.core.clone_and_set.cljs$core$IFn$_invoke$arity$3(self__.arr,(idx + (1)),val))); +} +} +} else { +return (new cljs.core.BitmapIndexedNode(null,(1 << ((self__.collision_hash >>> shift) & 0x01f)),[null,inode])).inode_assoc(shift,hash,key,val,added_leaf_QMARK_); +} +}); + +cljs.core.HashCollisionNode.prototype.ensure_editable_array = (function (e,count,array){ +var self__ = this; +var inode = this; +if((e === self__.edit)){ +self__.arr = array; + +self__.cnt = count; + +return inode; +} else { +return (new cljs.core.HashCollisionNode(self__.edit,self__.collision_hash,count,array)); +} +}); + +cljs.core.HashCollisionNode.prototype.inode_find = (function (shift,hash,key,not_found){ +var self__ = this; +var inode = this; +var idx = cljs.core.hash_collision_node_find_index(self__.arr,self__.cnt,key); +if((idx < (0))){ +return not_found; +} else { +if(cljs.core.key_test(key,(self__.arr[idx]))){ +return (new cljs.core.MapEntry((self__.arr[idx]),(self__.arr[(idx + (1))]),null)); +} else { +return not_found; + +} +} +}); + +cljs.core.HashCollisionNode.prototype.inode_without = (function (shift,hash,key){ +var self__ = this; +var inode = this; +var idx = cljs.core.hash_collision_node_find_index(self__.arr,self__.cnt,key); +if((idx === (-1))){ +return inode; +} else { +if((self__.cnt === (1))){ +return null; +} else { +return (new cljs.core.HashCollisionNode(null,self__.collision_hash,(self__.cnt - (1)),cljs.core.remove_pair(self__.arr,cljs.core.quot(idx,(2))))); + +} +} +}); + +cljs.core.HashCollisionNode.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.NodeIterator(self__.arr,(0),null,null)); +}); + +cljs.core.HashCollisionNode.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$edit,cljs.core.with_meta(cljs.core.cst$sym$collision_DASH_hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$cnt,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$arr,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.HashCollisionNode.cljs$lang$type = true; + +cljs.core.HashCollisionNode.cljs$lang$ctorStr = "cljs.core/HashCollisionNode"; + +cljs.core.HashCollisionNode.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/HashCollisionNode"); +}); + +/** + * Positional factory function for cljs.core/HashCollisionNode. + */ +cljs.core.__GT_HashCollisionNode = (function cljs$core$__GT_HashCollisionNode(edit,collision_hash,cnt,arr){ +return (new cljs.core.HashCollisionNode(edit,collision_hash,cnt,arr)); +}); + +cljs.core.create_node = (function cljs$core$create_node(var_args){ +var G__4471 = arguments.length; +switch (G__4471) { +case 6: +return cljs.core.create_node.cljs$core$IFn$_invoke$arity$6((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)])); + +break; +case 7: +return cljs.core.create_node.cljs$core$IFn$_invoke$arity$7((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)]),(arguments[(5)]),(arguments[(6)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.create_node.cljs$core$IFn$_invoke$arity$6 = (function (shift,key1,val1,key2hash,key2,val2){ +var key1hash = cljs.core.hash(key1); +if((key1hash === key2hash)){ +return (new cljs.core.HashCollisionNode(null,key1hash,(2),[key1,val1,key2,val2])); +} else { +var added_leaf_QMARK_ = (new cljs.core.Box(false)); +return cljs.core.BitmapIndexedNode.EMPTY.inode_assoc(shift,key1hash,key1,val1,added_leaf_QMARK_).inode_assoc(shift,key2hash,key2,val2,added_leaf_QMARK_); +} +}); + +cljs.core.create_node.cljs$core$IFn$_invoke$arity$7 = (function (edit,shift,key1,val1,key2hash,key2,val2){ +var key1hash = cljs.core.hash(key1); +if((key1hash === key2hash)){ +return (new cljs.core.HashCollisionNode(null,key1hash,(2),[key1,val1,key2,val2])); +} else { +var added_leaf_QMARK_ = (new cljs.core.Box(false)); +return cljs.core.BitmapIndexedNode.EMPTY.inode_assoc_BANG_(edit,shift,key1hash,key1,val1,added_leaf_QMARK_).inode_assoc_BANG_(edit,shift,key2hash,key2,val2,added_leaf_QMARK_); +} +}); + +cljs.core.create_node.cljs$lang$maxFixedArity = 7; + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.NodeSeq = (function (meta,nodes,i,s,__hash){ +this.meta = meta; +this.nodes = nodes; +this.i = i; +this.s = s; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 32374988; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.NodeSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.NodeSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.NodeSeq.prototype.indexOf = (function() { +var G__4473 = null; +var G__4473__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4473__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4473 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4473__1.call(this,x); +case 2: +return G__4473__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4473.cljs$core$IFn$_invoke$arity$1 = G__4473__1; +G__4473.cljs$core$IFn$_invoke$arity$2 = G__4473__2; +return G__4473; +})() +; + +cljs.core.NodeSeq.prototype.lastIndexOf = (function() { +var G__4474 = null; +var G__4474__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4474__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4474 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4474__1.call(this,x); +case 2: +return G__4474__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4474.cljs$core$IFn$_invoke$arity$1 = G__4474__1; +G__4474.cljs$core$IFn$_invoke$arity$2 = G__4474__2; +return G__4474; +})() +; + +cljs.core.NodeSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.NodeSeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.s == null)){ +return cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$3(self__.nodes,(self__.i + (2)),null); +} else { +return cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$3(self__.nodes,self__.i,cljs.core.next(self__.s)); +} +}); + +cljs.core.NodeSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.NodeSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.NodeSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.NodeSeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.NodeSeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.NodeSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.s == null)){ +return (new cljs.core.MapEntry((self__.nodes[self__.i]),(self__.nodes[(self__.i + (1))]),null)); +} else { +return cljs.core.first(self__.s); +} +}); + +cljs.core.NodeSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var ret = (((self__.s == null))?cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$3(self__.nodes,(self__.i + (2)),null):cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$3(self__.nodes,self__.i,cljs.core.next(self__.s))); +if((!((ret == null)))){ +return ret; +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.NodeSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return this$__$1; +}); + +cljs.core.NodeSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.NodeSeq(new_meta,self__.nodes,self__.i,self__.s,self__.__hash)); +} +}); + +cljs.core.NodeSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.NodeSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$nodes,cljs.core.cst$sym$i,cljs.core.cst$sym$s,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.NodeSeq.cljs$lang$type = true; + +cljs.core.NodeSeq.cljs$lang$ctorStr = "cljs.core/NodeSeq"; + +cljs.core.NodeSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/NodeSeq"); +}); + +/** + * Positional factory function for cljs.core/NodeSeq. + */ +cljs.core.__GT_NodeSeq = (function cljs$core$__GT_NodeSeq(meta,nodes,i,s,__hash){ +return (new cljs.core.NodeSeq(meta,nodes,i,s,__hash)); +}); + +var G__4475_4478 = cljs.core.NodeSeq.prototype; +var G__4476_4479 = cljs.core.ITER_SYMBOL; +var G__4477_4480 = ((function (G__4475_4478,G__4476_4479){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4475_4478,G__4476_4479)) +; +goog.object.set(G__4475_4478,G__4476_4479,G__4477_4480); +cljs.core.create_inode_seq = (function cljs$core$create_inode_seq(var_args){ +var G__4482 = arguments.length; +switch (G__4482) { +case 1: +return cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 3: +return cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$1 = (function (nodes){ +return cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$3(nodes,(0),null); +}); + +cljs.core.create_inode_seq.cljs$core$IFn$_invoke$arity$3 = (function (nodes,i,s){ +if((s == null)){ +var len = nodes.length; +var j = i; +while(true){ +if((j < len)){ +if((!(((nodes[j]) == null)))){ +return (new cljs.core.NodeSeq(null,nodes,j,null,null)); +} else { +var temp__5733__auto__ = (nodes[(j + (1))]); +if(cljs.core.truth_(temp__5733__auto__)){ +var node = temp__5733__auto__; +var temp__5733__auto____$1 = node.inode_seq(); +if(cljs.core.truth_(temp__5733__auto____$1)){ +var node_seq = temp__5733__auto____$1; +return (new cljs.core.NodeSeq(null,nodes,(j + (2)),node_seq,null)); +} else { +var G__4484 = (j + (2)); +j = G__4484; +continue; +} +} else { +var G__4485 = (j + (2)); +j = G__4485; +continue; +} +} +} else { +return null; +} +break; +} +} else { +return (new cljs.core.NodeSeq(null,nodes,i,s,null)); +} +}); + +cljs.core.create_inode_seq.cljs$lang$maxFixedArity = 3; + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.ArrayNodeSeq = (function (meta,nodes,i,s,__hash){ +this.meta = meta; +this.nodes = nodes; +this.i = i; +this.s = s; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 32374988; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.ArrayNodeSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.ArrayNodeSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.ArrayNodeSeq.prototype.indexOf = (function() { +var G__4486 = null; +var G__4486__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4486__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4486 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4486__1.call(this,x); +case 2: +return G__4486__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4486.cljs$core$IFn$_invoke$arity$1 = G__4486__1; +G__4486.cljs$core$IFn$_invoke$arity$2 = G__4486__2; +return G__4486; +})() +; + +cljs.core.ArrayNodeSeq.prototype.lastIndexOf = (function() { +var G__4487 = null; +var G__4487__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4487__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4487 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4487__1.call(this,x); +case 2: +return G__4487__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4487.cljs$core$IFn$_invoke$arity$1 = G__4487__1; +G__4487.cljs$core$IFn$_invoke$arity$2 = G__4487__2; +return G__4487; +})() +; + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.create_array_node_seq.cljs$core$IFn$_invoke$arity$3(self__.nodes,self__.i,cljs.core.next(self__.s)); +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.first(self__.s); +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var ret = cljs.core.create_array_node_seq.cljs$core$IFn$_invoke$arity$3(self__.nodes,self__.i,cljs.core.next(self__.s)); +if((!((ret == null)))){ +return ret; +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return this$__$1; +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.ArrayNodeSeq(new_meta,self__.nodes,self__.i,self__.s,self__.__hash)); +} +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.ArrayNodeSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$nodes,cljs.core.cst$sym$i,cljs.core.cst$sym$s,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ArrayNodeSeq.cljs$lang$type = true; + +cljs.core.ArrayNodeSeq.cljs$lang$ctorStr = "cljs.core/ArrayNodeSeq"; + +cljs.core.ArrayNodeSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ArrayNodeSeq"); +}); + +/** + * Positional factory function for cljs.core/ArrayNodeSeq. + */ +cljs.core.__GT_ArrayNodeSeq = (function cljs$core$__GT_ArrayNodeSeq(meta,nodes,i,s,__hash){ +return (new cljs.core.ArrayNodeSeq(meta,nodes,i,s,__hash)); +}); + +var G__4488_4491 = cljs.core.ArrayNodeSeq.prototype; +var G__4489_4492 = cljs.core.ITER_SYMBOL; +var G__4490_4493 = ((function (G__4488_4491,G__4489_4492){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4488_4491,G__4489_4492)) +; +goog.object.set(G__4488_4491,G__4489_4492,G__4490_4493); +cljs.core.create_array_node_seq = (function cljs$core$create_array_node_seq(var_args){ +var G__4495 = arguments.length; +switch (G__4495) { +case 1: +return cljs.core.create_array_node_seq.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 3: +return cljs.core.create_array_node_seq.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.create_array_node_seq.cljs$core$IFn$_invoke$arity$1 = (function (nodes){ +return cljs.core.create_array_node_seq.cljs$core$IFn$_invoke$arity$3(nodes,(0),null); +}); + +cljs.core.create_array_node_seq.cljs$core$IFn$_invoke$arity$3 = (function (nodes,i,s){ +if((s == null)){ +var len = nodes.length; +var j = i; +while(true){ +if((j < len)){ +var temp__5733__auto__ = (nodes[j]); +if(cljs.core.truth_(temp__5733__auto__)){ +var nj = temp__5733__auto__; +var temp__5733__auto____$1 = nj.inode_seq(); +if(cljs.core.truth_(temp__5733__auto____$1)){ +var ns = temp__5733__auto____$1; +return (new cljs.core.ArrayNodeSeq(null,nodes,(j + (1)),ns,null)); +} else { +var G__4497 = (j + (1)); +j = G__4497; +continue; +} +} else { +var G__4498 = (j + (1)); +j = G__4498; +continue; +} +} else { +return null; +} +break; +} +} else { +return (new cljs.core.ArrayNodeSeq(null,nodes,i,s,null)); +} +}); + +cljs.core.create_array_node_seq.cljs$lang$maxFixedArity = 3; + + +/** +* @constructor +*/ +cljs.core.HashMapIter = (function (nil_val,root_iter,seen){ +this.nil_val = nil_val; +this.root_iter = root_iter; +this.seen = seen; +}); +cljs.core.HashMapIter.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +return (((!(self__.seen))) || (self__.root_iter.hasNext())); +}); + +cljs.core.HashMapIter.prototype.next = (function (){ +var self__ = this; +var _ = this; +if((!(self__.seen))){ +self__.seen = true; + +return (new cljs.core.MapEntry(null,self__.nil_val,null)); +} else { +return self__.root_iter.next(); +} +}); + +cljs.core.HashMapIter.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.HashMapIter.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$nil_DASH_val,cljs.core.cst$sym$root_DASH_iter,cljs.core.with_meta(cljs.core.cst$sym$seen,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.HashMapIter.cljs$lang$type = true; + +cljs.core.HashMapIter.cljs$lang$ctorStr = "cljs.core/HashMapIter"; + +cljs.core.HashMapIter.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/HashMapIter"); +}); + +/** + * Positional factory function for cljs.core/HashMapIter. + */ +cljs.core.__GT_HashMapIter = (function cljs$core$__GT_HashMapIter(nil_val,root_iter,seen){ +return (new cljs.core.HashMapIter(nil_val,root_iter,seen)); +}); + + +/** +* @constructor + * @implements {cljs.core.IKVReduce} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEditableCollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.IMap} + * @implements {cljs.core.ILookup} +*/ +cljs.core.PersistentHashMap = (function (meta,cnt,root,has_nil_QMARK_,nil_val,__hash){ +this.meta = meta; +this.cnt = cnt; +this.root = root; +this.has_nil_QMARK_ = has_nil_QMARK_; +this.nil_val = nil_val; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 16123663; +this.cljs$lang$protocol_mask$partition1$ = 139268; +}); +cljs.core.PersistentHashMap.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentHashMap.prototype.cljs$core$IFind$_find$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +if((k == null)){ +if(self__.has_nil_QMARK_){ +return (new cljs.core.MapEntry(null,self__.nil_val,null)); +} else { +return null; +} +} else { +if((self__.root == null)){ +return null; +} else { +return self__.root.inode_find((0),cljs.core.hash(k),k,null); + +} +} +}); + +cljs.core.PersistentHashMap.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentHashMap.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentHashMap.prototype.keys = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.keys(coll)); +}); + +cljs.core.PersistentHashMap.prototype.entries = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_entries_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentHashMap.prototype.values = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.vals(coll)); +}); + +cljs.core.PersistentHashMap.prototype.has = (function (k){ +var self__ = this; +var coll = this; +return cljs.core.contains_QMARK_(coll,k); +}); + +cljs.core.PersistentHashMap.prototype.get = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.PersistentHashMap.prototype.forEach = (function (f){ +var self__ = this; +var coll = this; +var seq__4500 = cljs.core.seq(coll); +var chunk__4501 = null; +var count__4502 = (0); +var i__4503 = (0); +while(true){ +if((i__4503 < count__4502)){ +var vec__4510 = chunk__4501.cljs$core$IIndexed$_nth$arity$2(null,i__4503); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4510,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4510,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4518 = seq__4500; +var G__4519 = chunk__4501; +var G__4520 = count__4502; +var G__4521 = (i__4503 + (1)); +seq__4500 = G__4518; +chunk__4501 = G__4519; +count__4502 = G__4520; +i__4503 = G__4521; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__4500); +if(temp__5735__auto__){ +var seq__4500__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__4500__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__4500__$1); +var G__4522 = cljs.core.chunk_rest(seq__4500__$1); +var G__4523 = c__4550__auto__; +var G__4524 = cljs.core.count(c__4550__auto__); +var G__4525 = (0); +seq__4500 = G__4522; +chunk__4501 = G__4523; +count__4502 = G__4524; +i__4503 = G__4525; +continue; +} else { +var vec__4513 = cljs.core.first(seq__4500__$1); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4513,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4513,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4526 = cljs.core.next(seq__4500__$1); +var G__4527 = null; +var G__4528 = (0); +var G__4529 = (0); +seq__4500 = G__4526; +chunk__4501 = G__4527; +count__4502 = G__4528; +i__4503 = G__4529; +continue; +} +} else { +return null; +} +} +break; +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,k,null); +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,k,not_found){ +var self__ = this; +var coll__$1 = this; +if((k == null)){ +if(self__.has_nil_QMARK_){ +return self__.nil_val; +} else { +return not_found; +} +} else { +if((self__.root == null)){ +return not_found; +} else { +return self__.root.inode_lookup((0),cljs.core.hash(k),k,not_found); + +} +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IKVReduce$_kv_reduce$arity$3 = (function (coll,f,init){ +var self__ = this; +var coll__$1 = this; +var init__$1 = ((self__.has_nil_QMARK_)?(f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(init,null,self__.nil_val) : f.call(null,init,null,self__.nil_val)):init); +if(cljs.core.reduced_QMARK_(init__$1)){ +return cljs.core.deref(init__$1); +} else { +if((!((self__.root == null)))){ +return cljs.core.unreduced(self__.root.kv_reduce(f,init__$1)); +} else { +return init__$1; + +} +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var root_iter = ((self__.root)?cljs.core._iterator(self__.root):cljs.core.nil_iter()); +if(self__.has_nil_QMARK_){ +return (new cljs.core.HashMapIter(self__.nil_val,root_iter,false)); +} else { +return root_iter; +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.PersistentHashMap(self__.meta,self__.cnt,self__.root,self__.has_nil_QMARK_,self__.nil_val,self__.__hash)); +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.cnt; +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_unordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_map(coll__$1,other); +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IEditableCollection$_as_transient$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.TransientHashMap(({}),self__.root,self__.cnt,self__.has_nil_QMARK_,self__.nil_val)); +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.PersistentHashMap.EMPTY,self__.meta); +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IMap$_dissoc$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +if((k == null)){ +if(self__.has_nil_QMARK_){ +return (new cljs.core.PersistentHashMap(self__.meta,(self__.cnt - (1)),self__.root,false,null,null)); +} else { +return coll__$1; +} +} else { +if((self__.root == null)){ +return coll__$1; +} else { +var new_root = self__.root.inode_without((0),cljs.core.hash(k),k); +if((new_root === self__.root)){ +return coll__$1; +} else { +return (new cljs.core.PersistentHashMap(self__.meta,(self__.cnt - (1)),new_root,self__.has_nil_QMARK_,self__.nil_val,null)); +} + +} +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (coll,k,v){ +var self__ = this; +var coll__$1 = this; +if((k == null)){ +if(((self__.has_nil_QMARK_) && ((v === self__.nil_val)))){ +return coll__$1; +} else { +return (new cljs.core.PersistentHashMap(self__.meta,((self__.has_nil_QMARK_)?self__.cnt:(self__.cnt + (1))),self__.root,true,v,null)); +} +} else { +var added_leaf_QMARK_ = (new cljs.core.Box(false)); +var new_root = (((self__.root == null))?cljs.core.BitmapIndexedNode.EMPTY:self__.root).inode_assoc((0),cljs.core.hash(k),k,v,added_leaf_QMARK_); +if((new_root === self__.root)){ +return coll__$1; +} else { +return (new cljs.core.PersistentHashMap(self__.meta,((added_leaf_QMARK_.val)?(self__.cnt + (1)):self__.cnt),new_root,self__.has_nil_QMARK_,self__.nil_val,null)); +} +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +if((k == null)){ +return self__.has_nil_QMARK_; +} else { +if((self__.root == null)){ +return false; +} else { +return (!((self__.root.inode_lookup((0),cljs.core.hash(k),k,cljs.core.lookup_sentinel) === cljs.core.lookup_sentinel))); + +} +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt > (0))){ +var s = (((!((self__.root == null))))?self__.root.inode_seq():null); +if(self__.has_nil_QMARK_){ +return cljs.core.cons((new cljs.core.MapEntry(null,self__.nil_val,null)),s); +} else { +return s; +} +} else { +return null; +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentHashMap(new_meta,self__.cnt,self__.root,self__.has_nil_QMARK_,self__.nil_val,self__.__hash)); +} +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,entry){ +var self__ = this; +var coll__$1 = this; +if(cljs.core.vector_QMARK_(entry)){ +return coll__$1.cljs$core$IAssociative$_assoc$arity$3(null,cljs.core._nth.cljs$core$IFn$_invoke$arity$2(entry,(0)),cljs.core._nth.cljs$core$IFn$_invoke$arity$2(entry,(1))); +} else { +var ret = coll__$1; +var es = cljs.core.seq(entry); +while(true){ +if((es == null)){ +return ret; +} else { +var e = cljs.core.first(es); +if(cljs.core.vector_QMARK_(e)){ +var G__4530 = cljs.core._assoc(ret,cljs.core._nth.cljs$core$IFn$_invoke$arity$2(e,(0)),cljs.core._nth.cljs$core$IFn$_invoke$arity$2(e,(1))); +var G__4531 = cljs.core.next(es); +ret = G__4530; +es = G__4531; +continue; +} else { +throw (new Error("conj on a map takes map entries or seqables of map entries")); +} +} +break; +} +} +}); + +cljs.core.PersistentHashMap.prototype.call = (function() { +var G__4532 = null; +var G__4532__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); +var G__4532__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); +G__4532 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4532__2.call(this,self__,k); +case 3: +return G__4532__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4532.cljs$core$IFn$_invoke$arity$2 = G__4532__2; +G__4532.cljs$core$IFn$_invoke$arity$3 = G__4532__3; +return G__4532; +})() +; + +cljs.core.PersistentHashMap.prototype.apply = (function (self__,args4499){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4499))); +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.PersistentHashMap.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 6, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$cnt,cljs.core.cst$sym$root,cljs.core.with_meta(cljs.core.cst$sym$has_DASH_nil_QMARK_,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$tag,cljs.core.cst$sym$boolean], null)),cljs.core.cst$sym$nil_DASH_val,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentHashMap.cljs$lang$type = true; + +cljs.core.PersistentHashMap.cljs$lang$ctorStr = "cljs.core/PersistentHashMap"; + +cljs.core.PersistentHashMap.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentHashMap"); +}); + +/** + * Positional factory function for cljs.core/PersistentHashMap. + */ +cljs.core.__GT_PersistentHashMap = (function cljs$core$__GT_PersistentHashMap(meta,cnt,root,has_nil_QMARK_,nil_val,__hash){ +return (new cljs.core.PersistentHashMap(meta,cnt,root,has_nil_QMARK_,nil_val,__hash)); +}); + +cljs.core.PersistentHashMap.EMPTY = (new cljs.core.PersistentHashMap(null,(0),null,false,null,cljs.core.empty_unordered_hash)); +cljs.core.PersistentHashMap.fromArray = (function (arr,no_clone){ +var arr__$1 = ((no_clone)?arr:cljs.core.aclone(arr)); +var len = arr__$1.length; +var i = (0); +var ret = cljs.core.transient$(cljs.core.PersistentHashMap.EMPTY); +while(true){ +if((i < len)){ +var G__4533 = (i + (2)); +var G__4534 = cljs.core._assoc_BANG_(ret,(arr__$1[i]),(arr__$1[(i + (1))])); +i = G__4533; +ret = G__4534; +continue; +} else { +return cljs.core._persistent_BANG_(ret); +} +break; +} +}); +cljs.core.PersistentHashMap.fromArrays = (function (ks,vs){ +var len = ks.length; +var i = (0); +var out = cljs.core.transient$(cljs.core.PersistentHashMap.EMPTY); +while(true){ +if((i < len)){ +var G__4535 = (i + (1)); +var G__4536 = cljs.core._assoc_BANG_(out,(ks[i]),(vs[i])); +i = G__4535; +out = G__4536; +continue; +} else { +return cljs.core.persistent_BANG_(out); +} +break; +} +}); +cljs.core.PersistentHashMap.createWithCheck = (function (arr){ +var len = arr.length; +var ret = cljs.core.transient$(cljs.core.PersistentHashMap.EMPTY); +var i_4537 = (0); +while(true){ +if((i_4537 < len)){ +cljs.core._assoc_BANG_(ret,(arr[i_4537]),(arr[(i_4537 + (1))])); + +if(cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core._count(ret),((i_4537 / (2)) + (1)))){ +throw (new Error(["Duplicate key: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1((arr[i_4537]))].join(''))); +} else { +var G__4538 = (i_4537 + (2)); +i_4537 = G__4538; +continue; +} +} else { +} +break; +} + +return cljs.core._persistent_BANG_(ret); +}); +var G__4539_4542 = cljs.core.PersistentHashMap.prototype; +var G__4540_4543 = cljs.core.ITER_SYMBOL; +var G__4541_4544 = ((function (G__4539_4542,G__4540_4543){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4539_4542,G__4540_4543)) +; +goog.object.set(G__4539_4542,G__4540_4543,G__4541_4544); + +/** +* @constructor + * @implements {cljs.core.IFn} + * @implements {cljs.core.ITransientMap} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ITransientCollection} + * @implements {cljs.core.ITransientAssociative} + * @implements {cljs.core.ILookup} +*/ +cljs.core.TransientHashMap = (function (edit,root,count,has_nil_QMARK_,nil_val){ +this.edit = edit; +this.root = root; +this.count = count; +this.has_nil_QMARK_ = has_nil_QMARK_; +this.nil_val = nil_val; +this.cljs$lang$protocol_mask$partition0$ = 259; +this.cljs$lang$protocol_mask$partition1$ = 56; +}); +cljs.core.TransientHashMap.prototype.conj_BANG_ = (function (o){ +var self__ = this; +var tcoll = this; +if(self__.edit){ +if(cljs.core.map_entry_QMARK_(o)){ +return tcoll.assoc_BANG_(cljs.core.key(o),cljs.core.val(o)); +} else { +if(cljs.core.vector_QMARK_(o)){ +return tcoll.assoc_BANG_((o.cljs$core$IFn$_invoke$arity$1 ? o.cljs$core$IFn$_invoke$arity$1((0)) : o.call(null,(0))),(o.cljs$core$IFn$_invoke$arity$1 ? o.cljs$core$IFn$_invoke$arity$1((1)) : o.call(null,(1)))); +} else { +var es = cljs.core.seq(o); +var tcoll__$1 = tcoll; +while(true){ +var temp__5733__auto__ = cljs.core.first(es); +if(cljs.core.truth_(temp__5733__auto__)){ +var e = temp__5733__auto__; +var G__4546 = cljs.core.next(es); +var G__4547 = tcoll__$1.assoc_BANG_(cljs.core.key(e),cljs.core.val(e)); +es = G__4546; +tcoll__$1 = G__4547; +continue; +} else { +return tcoll__$1; +} +break; +} + +} +} +} else { +throw (new Error("conj! after persistent")); +} +}); + +cljs.core.TransientHashMap.prototype.assoc_BANG_ = (function (k,v){ +var self__ = this; +var tcoll = this; +if(self__.edit){ +if((k == null)){ +if((self__.nil_val === v)){ +} else { +self__.nil_val = v; +} + +if(self__.has_nil_QMARK_){ +} else { +self__.count = (self__.count + (1)); + +self__.has_nil_QMARK_ = true; +} + +return tcoll; +} else { +var added_leaf_QMARK_ = (new cljs.core.Box(false)); +var node = (((self__.root == null))?cljs.core.BitmapIndexedNode.EMPTY:self__.root).inode_assoc_BANG_(self__.edit,(0),cljs.core.hash(k),k,v,added_leaf_QMARK_); +if((node === self__.root)){ +} else { +self__.root = node; +} + +if(added_leaf_QMARK_.val){ +self__.count = (self__.count + (1)); +} else { +} + +return tcoll; +} +} else { +throw (new Error("assoc! after persistent!")); +} +}); + +cljs.core.TransientHashMap.prototype.without_BANG_ = (function (k){ +var self__ = this; +var tcoll = this; +if(self__.edit){ +if((k == null)){ +if(self__.has_nil_QMARK_){ +self__.has_nil_QMARK_ = false; + +self__.nil_val = null; + +self__.count = (self__.count - (1)); + +return tcoll; +} else { +return tcoll; +} +} else { +if((self__.root == null)){ +return tcoll; +} else { +var removed_leaf_QMARK_ = (new cljs.core.Box(false)); +var node = self__.root.inode_without_BANG_(self__.edit,(0),cljs.core.hash(k),k,removed_leaf_QMARK_); +if((node === self__.root)){ +} else { +self__.root = node; +} + +if(removed_leaf_QMARK_.val){ +self__.count = (self__.count - (1)); +} else { +} + +return tcoll; +} +} +} else { +throw (new Error("dissoc! after persistent!")); +} +}); + +cljs.core.TransientHashMap.prototype.persistent_BANG_ = (function (){ +var self__ = this; +var tcoll = this; +if(self__.edit){ +self__.edit = null; + +return (new cljs.core.PersistentHashMap(null,self__.count,self__.root,self__.has_nil_QMARK_,self__.nil_val,null)); +} else { +throw (new Error("persistent! called twice")); +} +}); + +cljs.core.TransientHashMap.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if(self__.edit){ +return self__.count; +} else { +throw (new Error("count after persistent!")); +} +}); + +cljs.core.TransientHashMap.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (tcoll,k){ +var self__ = this; +var tcoll__$1 = this; +if((k == null)){ +if(self__.has_nil_QMARK_){ +return self__.nil_val; +} else { +return null; +} +} else { +if((self__.root == null)){ +return null; +} else { +return self__.root.inode_lookup((0),cljs.core.hash(k),k); +} +} +}); + +cljs.core.TransientHashMap.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (tcoll,k,not_found){ +var self__ = this; +var tcoll__$1 = this; +if((k == null)){ +if(self__.has_nil_QMARK_){ +return self__.nil_val; +} else { +return not_found; +} +} else { +if((self__.root == null)){ +return not_found; +} else { +return self__.root.inode_lookup((0),cljs.core.hash(k),k,not_found); +} +} +}); + +cljs.core.TransientHashMap.prototype.cljs$core$ITransientCollection$_conj_BANG_$arity$2 = (function (tcoll,val){ +var self__ = this; +var tcoll__$1 = this; +return tcoll__$1.conj_BANG_(val); +}); + +cljs.core.TransientHashMap.prototype.cljs$core$ITransientCollection$_persistent_BANG_$arity$1 = (function (tcoll){ +var self__ = this; +var tcoll__$1 = this; +return tcoll__$1.persistent_BANG_(); +}); + +cljs.core.TransientHashMap.prototype.cljs$core$ITransientAssociative$_assoc_BANG_$arity$3 = (function (tcoll,key,val){ +var self__ = this; +var tcoll__$1 = this; +return tcoll__$1.assoc_BANG_(key,val); +}); + +cljs.core.TransientHashMap.prototype.cljs$core$ITransientMap$_dissoc_BANG_$arity$2 = (function (tcoll,key){ +var self__ = this; +var tcoll__$1 = this; +return tcoll__$1.without_BANG_(key); +}); + +cljs.core.TransientHashMap.prototype.call = (function() { +var G__4548 = null; +var G__4548__2 = (function (self__,key){ +var self__ = this; +var self____$1 = this; +var tcoll = self____$1; +return tcoll.cljs$core$ILookup$_lookup$arity$2(null,key); +}); +var G__4548__3 = (function (self__,key,not_found){ +var self__ = this; +var self____$1 = this; +var tcoll = self____$1; +return tcoll.cljs$core$ILookup$_lookup$arity$3(null,key,not_found); +}); +G__4548 = function(self__,key,not_found){ +switch(arguments.length){ +case 2: +return G__4548__2.call(this,self__,key); +case 3: +return G__4548__3.call(this,self__,key,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4548.cljs$core$IFn$_invoke$arity$2 = G__4548__2; +G__4548.cljs$core$IFn$_invoke$arity$3 = G__4548__3; +return G__4548; +})() +; + +cljs.core.TransientHashMap.prototype.apply = (function (self__,args4545){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4545))); +}); + +cljs.core.TransientHashMap.prototype.cljs$core$IFn$_invoke$arity$1 = (function (key){ +var self__ = this; +var tcoll = this; +return tcoll.cljs$core$ILookup$_lookup$arity$2(null,key); +}); + +cljs.core.TransientHashMap.prototype.cljs$core$IFn$_invoke$arity$2 = (function (key,not_found){ +var self__ = this; +var tcoll = this; +return tcoll.cljs$core$ILookup$_lookup$arity$3(null,key,not_found); +}); + +cljs.core.TransientHashMap.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$edit,new cljs.core.PersistentArrayMap(null, 2, [cljs.core.cst$kw$tag,cljs.core.cst$sym$boolean,cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$root,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$count,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$has_DASH_nil_QMARK_,new cljs.core.PersistentArrayMap(null, 2, [cljs.core.cst$kw$tag,cljs.core.cst$sym$boolean,cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$nil_DASH_val,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.TransientHashMap.cljs$lang$type = true; + +cljs.core.TransientHashMap.cljs$lang$ctorStr = "cljs.core/TransientHashMap"; + +cljs.core.TransientHashMap.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/TransientHashMap"); +}); + +/** + * Positional factory function for cljs.core/TransientHashMap. + */ +cljs.core.__GT_TransientHashMap = (function cljs$core$__GT_TransientHashMap(edit,root,count,has_nil_QMARK_,nil_val){ +return (new cljs.core.TransientHashMap(edit,root,count,has_nil_QMARK_,nil_val)); +}); + +cljs.core.tree_map_seq_push = (function cljs$core$tree_map_seq_push(node,stack,ascending_QMARK_){ +var t = node; +var stack__$1 = stack; +while(true){ +if((!((t == null)))){ +var G__4549 = ((ascending_QMARK_)?t.left:t.right); +var G__4550 = cljs.core.conj.cljs$core$IFn$_invoke$arity$2(stack__$1,t); +t = G__4549; +stack__$1 = G__4550; +continue; +} else { +return stack__$1; +} +break; +} +}); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.PersistentTreeMapSeq = (function (meta,stack,ascending_QMARK_,cnt,__hash){ +this.meta = meta; +this.stack = stack; +this.ascending_QMARK_ = ascending_QMARK_; +this.cnt = cnt; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 32374990; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.PersistentTreeMapSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentTreeMapSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentTreeMapSeq.prototype.indexOf = (function() { +var G__4551 = null; +var G__4551__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4551__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4551 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4551__1.call(this,x); +case 2: +return G__4551__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4551.cljs$core$IFn$_invoke$arity$1 = G__4551__1; +G__4551.cljs$core$IFn$_invoke$arity$2 = G__4551__2; +return G__4551; +})() +; + +cljs.core.PersistentTreeMapSeq.prototype.lastIndexOf = (function() { +var G__4552 = null; +var G__4552__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4552__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4552 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4552__1.call(this,x); +case 2: +return G__4552__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4552.cljs$core$IFn$_invoke$arity$1 = G__4552__1; +G__4552.cljs$core$IFn$_invoke$arity$2 = G__4552__2; +return G__4552; +})() +; + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$INext$_next$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +var t = cljs.core.first(self__.stack); +var next_stack = cljs.core.tree_map_seq_push(((self__.ascending_QMARK_)?t.right:t.left),cljs.core.next(self__.stack),self__.ascending_QMARK_); +if((next_stack == null)){ +return null; +} else { +return (new cljs.core.PersistentTreeMapSeq(null,next_stack,self__.ascending_QMARK_,(self__.cnt - (1)),null)); +} +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt < (0))){ +return (cljs.core.count(cljs.core.next(coll__$1)) + (1)); +} else { +return self__.cnt; +} +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return cljs.core.peek(self__.stack); +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +var t = cljs.core.first(self__.stack); +var next_stack = cljs.core.tree_map_seq_push(((self__.ascending_QMARK_)?t.right:t.left),cljs.core.next(self__.stack),self__.ascending_QMARK_); +if((!((next_stack == null)))){ +return (new cljs.core.PersistentTreeMapSeq(null,next_stack,self__.ascending_QMARK_,(self__.cnt - (1)),null)); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return this$__$1; +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentTreeMapSeq(new_meta,self__.stack,self__.ascending_QMARK_,self__.cnt,self__.__hash)); +} +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.PersistentTreeMapSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$stack,cljs.core.with_meta(cljs.core.cst$sym$ascending_QMARK_,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$tag,cljs.core.cst$sym$boolean], null)),cljs.core.cst$sym$cnt,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentTreeMapSeq.cljs$lang$type = true; + +cljs.core.PersistentTreeMapSeq.cljs$lang$ctorStr = "cljs.core/PersistentTreeMapSeq"; + +cljs.core.PersistentTreeMapSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentTreeMapSeq"); +}); + +/** + * Positional factory function for cljs.core/PersistentTreeMapSeq. + */ +cljs.core.__GT_PersistentTreeMapSeq = (function cljs$core$__GT_PersistentTreeMapSeq(meta,stack,ascending_QMARK_,cnt,__hash){ +return (new cljs.core.PersistentTreeMapSeq(meta,stack,ascending_QMARK_,cnt,__hash)); +}); + +var G__4553_4556 = cljs.core.PersistentTreeMapSeq.prototype; +var G__4554_4557 = cljs.core.ITER_SYMBOL; +var G__4555_4558 = ((function (G__4553_4556,G__4554_4557){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4553_4556,G__4554_4557)) +; +goog.object.set(G__4553_4556,G__4554_4557,G__4555_4558); +cljs.core.create_tree_map_seq = (function cljs$core$create_tree_map_seq(tree,ascending_QMARK_,cnt){ +return (new cljs.core.PersistentTreeMapSeq(null,cljs.core.tree_map_seq_push(tree,null,ascending_QMARK_),ascending_QMARK_,cnt,null)); +}); + +cljs.core.balance_left = (function cljs$core$balance_left(key,val,ins,right){ +if((ins instanceof cljs.core.RedNode)){ +if((ins.left instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(ins.key,ins.val,ins.left.blacken(),(new cljs.core.BlackNode(key,val,ins.right,right,null)),null)); +} else { +if((ins.right instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(ins.right.key,ins.right.val,(new cljs.core.BlackNode(ins.key,ins.val,ins.left,ins.right.left,null)),(new cljs.core.BlackNode(key,val,ins.right.right,right,null)),null)); +} else { +return (new cljs.core.BlackNode(key,val,ins,right,null)); + +} +} +} else { +return (new cljs.core.BlackNode(key,val,ins,right,null)); +} +}); +cljs.core.balance_right = (function cljs$core$balance_right(key,val,left,ins){ +if((ins instanceof cljs.core.RedNode)){ +if((ins.right instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(ins.key,ins.val,(new cljs.core.BlackNode(key,val,left,ins.left,null)),ins.right.blacken(),null)); +} else { +if((ins.left instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(ins.left.key,ins.left.val,(new cljs.core.BlackNode(key,val,left,ins.left.left,null)),(new cljs.core.BlackNode(ins.key,ins.val,ins.left.right,ins.right,null)),null)); +} else { +return (new cljs.core.BlackNode(key,val,left,ins,null)); + +} +} +} else { +return (new cljs.core.BlackNode(key,val,left,ins,null)); +} +}); +cljs.core.balance_left_del = (function cljs$core$balance_left_del(key,val,del,right){ +if((del instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(key,val,del.blacken(),right,null)); +} else { +if((right instanceof cljs.core.BlackNode)){ +return cljs.core.balance_right(key,val,del,right.redden()); +} else { +if((((right instanceof cljs.core.RedNode)) && ((right.left instanceof cljs.core.BlackNode)))){ +return (new cljs.core.RedNode(right.left.key,right.left.val,(new cljs.core.BlackNode(key,val,del,right.left.left,null)),cljs.core.balance_right(right.key,right.val,right.left.right,right.right.redden()),null)); +} else { +throw (new Error("red-black tree invariant violation")); + +} +} +} +}); +cljs.core.balance_right_del = (function cljs$core$balance_right_del(key,val,left,del){ +if((del instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(key,val,left,del.blacken(),null)); +} else { +if((left instanceof cljs.core.BlackNode)){ +return cljs.core.balance_left(key,val,left.redden(),del); +} else { +if((((left instanceof cljs.core.RedNode)) && ((left.right instanceof cljs.core.BlackNode)))){ +return (new cljs.core.RedNode(left.right.key,left.right.val,cljs.core.balance_left(left.key,left.val,left.left.redden(),left.right.left),(new cljs.core.BlackNode(key,val,left.right.right,del,null)),null)); +} else { +throw (new Error("red-black tree invariant violation")); + +} +} +} +}); +cljs.core.tree_map_kv_reduce = (function cljs$core$tree_map_kv_reduce(node,f,init){ +var init__$1 = (((!((node.left == null))))?(function (){var G__4559 = node.left; +var G__4560 = f; +var G__4561 = init; +return (cljs.core.tree_map_kv_reduce.cljs$core$IFn$_invoke$arity$3 ? cljs.core.tree_map_kv_reduce.cljs$core$IFn$_invoke$arity$3(G__4559,G__4560,G__4561) : cljs.core.tree_map_kv_reduce.call(null,G__4559,G__4560,G__4561)); +})():init); +if(cljs.core.reduced_QMARK_(init__$1)){ +return init__$1; +} else { +var init__$2 = (function (){var G__4562 = init__$1; +var G__4563 = node.key; +var G__4564 = node.val; +return (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(G__4562,G__4563,G__4564) : f.call(null,G__4562,G__4563,G__4564)); +})(); +if(cljs.core.reduced_QMARK_(init__$2)){ +return init__$2; +} else { +if((!((node.right == null)))){ +var G__4565 = node.right; +var G__4566 = f; +var G__4567 = init__$2; +return (cljs.core.tree_map_kv_reduce.cljs$core$IFn$_invoke$arity$3 ? cljs.core.tree_map_kv_reduce.cljs$core$IFn$_invoke$arity$3(G__4565,G__4566,G__4567) : cljs.core.tree_map_kv_reduce.call(null,G__4565,G__4566,G__4567)); +} else { +return init__$2; +} +} +} +}); + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.IVector} + * @implements {cljs.core.IReversible} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IStack} + * @implements {cljs.core.IMapEntry} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.ILookup} + * @implements {cljs.core.IReduce} +*/ +cljs.core.BlackNode = (function (key,val,left,right,__hash){ +this.key = key; +this.val = val; +this.left = left; +this.right = right; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 166619935; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.BlackNode.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.BlackNode.prototype.cljs$core$IFind$_find$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +var G__4569 = k; +switch (G__4569) { +case (0): +return (new cljs.core.MapEntry((0),self__.key,null)); + +break; +case (1): +return (new cljs.core.MapEntry((1),self__.val,null)); + +break; +default: +return null; + +} +}); + +cljs.core.BlackNode.prototype.lastIndexOf = (function() { +var G__4571 = null; +var G__4571__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4571__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4571 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4571__1.call(this,x); +case 2: +return G__4571__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4571.cljs$core$IFn$_invoke$arity$1 = G__4571__1; +G__4571.cljs$core$IFn$_invoke$arity$2 = G__4571__2; +return G__4571; +})() +; + +cljs.core.BlackNode.prototype.indexOf = (function() { +var G__4572 = null; +var G__4572__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4572__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4572 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4572__1.call(this,x); +case 2: +return G__4572__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4572.cljs$core$IFn$_invoke$arity$1 = G__4572__1; +G__4572.cljs$core$IFn$_invoke$arity$2 = G__4572__2; +return G__4572; +})() +; + +cljs.core.BlackNode.prototype.add_right = (function (ins){ +var self__ = this; +var node = this; +return ins.balance_right(node); +}); + +cljs.core.BlackNode.prototype.redden = (function (){ +var self__ = this; +var node = this; +return (new cljs.core.RedNode(self__.key,self__.val,self__.left,self__.right,null)); +}); + +cljs.core.BlackNode.prototype.blacken = (function (){ +var self__ = this; +var node = this; +return node; +}); + +cljs.core.BlackNode.prototype.add_left = (function (ins){ +var self__ = this; +var node = this; +return ins.balance_left(node); +}); + +cljs.core.BlackNode.prototype.replace = (function (key__$1,val__$1,left__$1,right__$1){ +var self__ = this; +var node = this; +return (new cljs.core.BlackNode(key__$1,val__$1,left__$1,right__$1,null)); +}); + +cljs.core.BlackNode.prototype.balance_left = (function (parent){ +var self__ = this; +var node = this; +return (new cljs.core.BlackNode(parent.key,parent.val,node,parent.right,null)); +}); + +cljs.core.BlackNode.prototype.balance_right = (function (parent){ +var self__ = this; +var node = this; +return (new cljs.core.BlackNode(parent.key,parent.val,parent.left,node,null)); +}); + +cljs.core.BlackNode.prototype.remove_left = (function (del){ +var self__ = this; +var node = this; +return cljs.core.balance_left_del(self__.key,self__.val,del,self__.right); +}); + +cljs.core.BlackNode.prototype.kv_reduce = (function (f,init){ +var self__ = this; +var node = this; +return cljs.core.tree_map_kv_reduce(node,f,init); +}); + +cljs.core.BlackNode.prototype.remove_right = (function (del){ +var self__ = this; +var node = this; +return cljs.core.balance_right_del(self__.key,self__.val,self__.left,del); +}); + +cljs.core.BlackNode.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +return node__$1.cljs$core$IIndexed$_nth$arity$3(null,k,null); +}); + +cljs.core.BlackNode.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (node,k,not_found){ +var self__ = this; +var node__$1 = this; +return node__$1.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); + +cljs.core.BlackNode.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (node,n){ +var self__ = this; +var node__$1 = this; +if((n === (0))){ +return self__.key; +} else { +if((n === (1))){ +return self__.val; +} else { +throw (new Error("Index out of bounds")); + +} +} +}); + +cljs.core.BlackNode.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (node,n,not_found){ +var self__ = this; +var node__$1 = this; +if((n === (0))){ +return self__.key; +} else { +if((n === (1))){ +return self__.val; +} else { +return not_found; + +} +} +}); + +cljs.core.BlackNode.prototype.cljs$core$IVector$_assoc_n$arity$3 = (function (node,n,v){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null).cljs$core$IVector$_assoc_n$arity$3(null,n,v); +}); + +cljs.core.BlackNode.prototype.cljs$core$IMeta$_meta$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return null; +}); + +cljs.core.BlackNode.prototype.cljs$core$ICounted$_count$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (2); +}); + +cljs.core.BlackNode.prototype.cljs$core$IMapEntry$_key$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.key; +}); + +cljs.core.BlackNode.prototype.cljs$core$IMapEntry$_val$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.val; +}); + +cljs.core.BlackNode.prototype.cljs$core$IStack$_peek$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.val; +}); + +cljs.core.BlackNode.prototype.cljs$core$IStack$_pop$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key], null); +}); + +cljs.core.BlackNode.prototype.cljs$core$IReversible$_rseq$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (new cljs.core.IndexedSeq([self__.val,self__.key],(0),null)); +}); + +cljs.core.BlackNode.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.BlackNode.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.BlackNode.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return null; +}); + +cljs.core.BlackNode.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (node,f){ +var self__ = this; +var node__$1 = this; +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$2(node__$1,f); +}); + +cljs.core.BlackNode.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (node,f,start){ +var self__ = this; +var node__$1 = this; +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$3(node__$1,f,start); +}); + +cljs.core.BlackNode.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (node,k,v){ +var self__ = this; +var node__$1 = this; +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null),k,v); +}); + +cljs.core.BlackNode.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +return (((k === (0))) || ((k === (1)))); +}); + +cljs.core.BlackNode.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (new cljs.core.IndexedSeq([self__.key,self__.val],(0),null)); +}); + +cljs.core.BlackNode.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (node,meta){ +var self__ = this; +var node__$1 = this; +return cljs.core._with_meta(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null),meta); +}); + +cljs.core.BlackNode.prototype.cljs$core$ICollection$_conj$arity$2 = (function (node,o){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val,o], null); +}); + +cljs.core.BlackNode.prototype.call = (function() { +var G__4573 = null; +var G__4573__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var node = self____$1; +return node.cljs$core$IIndexed$_nth$arity$2(null,k); +}); +var G__4573__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var node = self____$1; +return node.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); +G__4573 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4573__2.call(this,self__,k); +case 3: +return G__4573__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4573.cljs$core$IFn$_invoke$arity$2 = G__4573__2; +G__4573.cljs$core$IFn$_invoke$arity$3 = G__4573__3; +return G__4573; +})() +; + +cljs.core.BlackNode.prototype.apply = (function (self__,args4568){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4568))); +}); + +cljs.core.BlackNode.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var node = this; +return node.cljs$core$IIndexed$_nth$arity$2(null,k); +}); + +cljs.core.BlackNode.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var node = this; +return node.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); + +cljs.core.BlackNode.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$key,cljs.core.cst$sym$val,cljs.core.cst$sym$left,cljs.core.cst$sym$right,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.BlackNode.cljs$lang$type = true; + +cljs.core.BlackNode.cljs$lang$ctorStr = "cljs.core/BlackNode"; + +cljs.core.BlackNode.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/BlackNode"); +}); + +/** + * Positional factory function for cljs.core/BlackNode. + */ +cljs.core.__GT_BlackNode = (function cljs$core$__GT_BlackNode(key,val,left,right,__hash){ +return (new cljs.core.BlackNode(key,val,left,right,__hash)); +}); + +var G__4574_4577 = cljs.core.BlackNode.prototype; +var G__4575_4578 = cljs.core.ITER_SYMBOL; +var G__4576_4579 = ((function (G__4574_4577,G__4575_4578){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4574_4577,G__4575_4578)) +; +goog.object.set(G__4574_4577,G__4575_4578,G__4576_4579); + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.IVector} + * @implements {cljs.core.IReversible} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.IStack} + * @implements {cljs.core.IMapEntry} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.ILookup} + * @implements {cljs.core.IReduce} +*/ +cljs.core.RedNode = (function (key,val,left,right,__hash){ +this.key = key; +this.val = val; +this.left = left; +this.right = right; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 166619935; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.RedNode.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.RedNode.prototype.cljs$core$IFind$_find$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +var G__4581 = k; +switch (G__4581) { +case (0): +return (new cljs.core.MapEntry((0),self__.key,null)); + +break; +case (1): +return (new cljs.core.MapEntry((1),self__.val,null)); + +break; +default: +return null; + +} +}); + +cljs.core.RedNode.prototype.lastIndexOf = (function() { +var G__4583 = null; +var G__4583__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4583__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4583 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4583__1.call(this,x); +case 2: +return G__4583__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4583.cljs$core$IFn$_invoke$arity$1 = G__4583__1; +G__4583.cljs$core$IFn$_invoke$arity$2 = G__4583__2; +return G__4583; +})() +; + +cljs.core.RedNode.prototype.indexOf = (function() { +var G__4584 = null; +var G__4584__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4584__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4584 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4584__1.call(this,x); +case 2: +return G__4584__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4584.cljs$core$IFn$_invoke$arity$1 = G__4584__1; +G__4584.cljs$core$IFn$_invoke$arity$2 = G__4584__2; +return G__4584; +})() +; + +cljs.core.RedNode.prototype.add_right = (function (ins){ +var self__ = this; +var node = this; +return (new cljs.core.RedNode(self__.key,self__.val,self__.left,ins,null)); +}); + +cljs.core.RedNode.prototype.redden = (function (){ +var self__ = this; +var node = this; +throw (new Error("red-black tree invariant violation")); +}); + +cljs.core.RedNode.prototype.blacken = (function (){ +var self__ = this; +var node = this; +return (new cljs.core.BlackNode(self__.key,self__.val,self__.left,self__.right,null)); +}); + +cljs.core.RedNode.prototype.add_left = (function (ins){ +var self__ = this; +var node = this; +return (new cljs.core.RedNode(self__.key,self__.val,ins,self__.right,null)); +}); + +cljs.core.RedNode.prototype.replace = (function (key__$1,val__$1,left__$1,right__$1){ +var self__ = this; +var node = this; +return (new cljs.core.RedNode(key__$1,val__$1,left__$1,right__$1,null)); +}); + +cljs.core.RedNode.prototype.balance_left = (function (parent){ +var self__ = this; +var node = this; +if((self__.left instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(self__.key,self__.val,self__.left.blacken(),(new cljs.core.BlackNode(parent.key,parent.val,self__.right,parent.right,null)),null)); +} else { +if((self__.right instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(self__.right.key,self__.right.val,(new cljs.core.BlackNode(self__.key,self__.val,self__.left,self__.right.left,null)),(new cljs.core.BlackNode(parent.key,parent.val,self__.right.right,parent.right,null)),null)); +} else { +return (new cljs.core.BlackNode(parent.key,parent.val,node,parent.right,null)); + +} +} +}); + +cljs.core.RedNode.prototype.balance_right = (function (parent){ +var self__ = this; +var node = this; +if((self__.right instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(self__.key,self__.val,(new cljs.core.BlackNode(parent.key,parent.val,parent.left,self__.left,null)),self__.right.blacken(),null)); +} else { +if((self__.left instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(self__.left.key,self__.left.val,(new cljs.core.BlackNode(parent.key,parent.val,parent.left,self__.left.left,null)),(new cljs.core.BlackNode(self__.key,self__.val,self__.left.right,self__.right,null)),null)); +} else { +return (new cljs.core.BlackNode(parent.key,parent.val,parent.left,node,null)); + +} +} +}); + +cljs.core.RedNode.prototype.remove_left = (function (del){ +var self__ = this; +var node = this; +return (new cljs.core.RedNode(self__.key,self__.val,del,self__.right,null)); +}); + +cljs.core.RedNode.prototype.kv_reduce = (function (f,init){ +var self__ = this; +var node = this; +return cljs.core.tree_map_kv_reduce(node,f,init); +}); + +cljs.core.RedNode.prototype.remove_right = (function (del){ +var self__ = this; +var node = this; +return (new cljs.core.RedNode(self__.key,self__.val,self__.left,del,null)); +}); + +cljs.core.RedNode.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +return node__$1.cljs$core$IIndexed$_nth$arity$3(null,k,null); +}); + +cljs.core.RedNode.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (node,k,not_found){ +var self__ = this; +var node__$1 = this; +return node__$1.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); + +cljs.core.RedNode.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (node,n){ +var self__ = this; +var node__$1 = this; +if((n === (0))){ +return self__.key; +} else { +if((n === (1))){ +return self__.val; +} else { +throw (new Error("Index out of bounds")); + +} +} +}); + +cljs.core.RedNode.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (node,n,not_found){ +var self__ = this; +var node__$1 = this; +if((n === (0))){ +return self__.key; +} else { +if((n === (1))){ +return self__.val; +} else { +return not_found; + +} +} +}); + +cljs.core.RedNode.prototype.cljs$core$IVector$_assoc_n$arity$3 = (function (node,n,v){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null).cljs$core$IVector$_assoc_n$arity$3(null,n,v); +}); + +cljs.core.RedNode.prototype.cljs$core$IMeta$_meta$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return null; +}); + +cljs.core.RedNode.prototype.cljs$core$ICounted$_count$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (2); +}); + +cljs.core.RedNode.prototype.cljs$core$IMapEntry$_key$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.key; +}); + +cljs.core.RedNode.prototype.cljs$core$IMapEntry$_val$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.val; +}); + +cljs.core.RedNode.prototype.cljs$core$IStack$_peek$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return self__.val; +}); + +cljs.core.RedNode.prototype.cljs$core$IStack$_pop$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key], null); +}); + +cljs.core.RedNode.prototype.cljs$core$IReversible$_rseq$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (new cljs.core.IndexedSeq([self__.val,self__.key],(0),null)); +}); + +cljs.core.RedNode.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.RedNode.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.RedNode.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return null; +}); + +cljs.core.RedNode.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (node,f){ +var self__ = this; +var node__$1 = this; +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$2(node__$1,f); +}); + +cljs.core.RedNode.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (node,f,start){ +var self__ = this; +var node__$1 = this; +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$3(node__$1,f,start); +}); + +cljs.core.RedNode.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (node,k,v){ +var self__ = this; +var node__$1 = this; +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null),k,v); +}); + +cljs.core.RedNode.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (node,k){ +var self__ = this; +var node__$1 = this; +return (((k === (0))) || ((k === (1)))); +}); + +cljs.core.RedNode.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (node){ +var self__ = this; +var node__$1 = this; +return (new cljs.core.IndexedSeq([self__.key,self__.val],(0),null)); +}); + +cljs.core.RedNode.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (node,meta){ +var self__ = this; +var node__$1 = this; +return cljs.core._with_meta(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val], null),meta); +}); + +cljs.core.RedNode.prototype.cljs$core$ICollection$_conj$arity$2 = (function (node,o){ +var self__ = this; +var node__$1 = this; +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [self__.key,self__.val,o], null); +}); + +cljs.core.RedNode.prototype.call = (function() { +var G__4585 = null; +var G__4585__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var node = self____$1; +return node.cljs$core$IIndexed$_nth$arity$2(null,k); +}); +var G__4585__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var node = self____$1; +return node.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); +G__4585 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4585__2.call(this,self__,k); +case 3: +return G__4585__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4585.cljs$core$IFn$_invoke$arity$2 = G__4585__2; +G__4585.cljs$core$IFn$_invoke$arity$3 = G__4585__3; +return G__4585; +})() +; + +cljs.core.RedNode.prototype.apply = (function (self__,args4580){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4580))); +}); + +cljs.core.RedNode.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var node = this; +return node.cljs$core$IIndexed$_nth$arity$2(null,k); +}); + +cljs.core.RedNode.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var node = this; +return node.cljs$core$IIndexed$_nth$arity$3(null,k,not_found); +}); + +cljs.core.RedNode.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$key,cljs.core.cst$sym$val,cljs.core.cst$sym$left,cljs.core.cst$sym$right,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.RedNode.cljs$lang$type = true; + +cljs.core.RedNode.cljs$lang$ctorStr = "cljs.core/RedNode"; + +cljs.core.RedNode.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/RedNode"); +}); + +/** + * Positional factory function for cljs.core/RedNode. + */ +cljs.core.__GT_RedNode = (function cljs$core$__GT_RedNode(key,val,left,right,__hash){ +return (new cljs.core.RedNode(key,val,left,right,__hash)); +}); + +var G__4586_4589 = cljs.core.RedNode.prototype; +var G__4587_4590 = cljs.core.ITER_SYMBOL; +var G__4588_4591 = ((function (G__4586_4589,G__4587_4590){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4586_4589,G__4587_4590)) +; +goog.object.set(G__4586_4589,G__4587_4590,G__4588_4591); +cljs.core.tree_map_add = (function cljs$core$tree_map_add(comp,tree,k,v,found){ +if((tree == null)){ +return (new cljs.core.RedNode(k,v,null,null,null)); +} else { +var c = (function (){var G__4592 = k; +var G__4593 = tree.key; +return (comp.cljs$core$IFn$_invoke$arity$2 ? comp.cljs$core$IFn$_invoke$arity$2(G__4592,G__4593) : comp.call(null,G__4592,G__4593)); +})(); +if((c === (0))){ +(found[(0)] = tree); + +return null; +} else { +if((c < (0))){ +var ins = (function (){var G__4594 = comp; +var G__4595 = tree.left; +var G__4596 = k; +var G__4597 = v; +var G__4598 = found; +return (cljs.core.tree_map_add.cljs$core$IFn$_invoke$arity$5 ? cljs.core.tree_map_add.cljs$core$IFn$_invoke$arity$5(G__4594,G__4595,G__4596,G__4597,G__4598) : cljs.core.tree_map_add.call(null,G__4594,G__4595,G__4596,G__4597,G__4598)); +})(); +if((!((ins == null)))){ +return tree.add_left(ins); +} else { +return null; +} +} else { +var ins = (function (){var G__4599 = comp; +var G__4600 = tree.right; +var G__4601 = k; +var G__4602 = v; +var G__4603 = found; +return (cljs.core.tree_map_add.cljs$core$IFn$_invoke$arity$5 ? cljs.core.tree_map_add.cljs$core$IFn$_invoke$arity$5(G__4599,G__4600,G__4601,G__4602,G__4603) : cljs.core.tree_map_add.call(null,G__4599,G__4600,G__4601,G__4602,G__4603)); +})(); +if((!((ins == null)))){ +return tree.add_right(ins); +} else { +return null; +} + +} +} +} +}); +cljs.core.tree_map_append = (function cljs$core$tree_map_append(left,right){ +if((left == null)){ +return right; +} else { +if((right == null)){ +return left; +} else { +if((left instanceof cljs.core.RedNode)){ +if((right instanceof cljs.core.RedNode)){ +var app = (function (){var G__4604 = left.right; +var G__4605 = right.left; +return (cljs.core.tree_map_append.cljs$core$IFn$_invoke$arity$2 ? cljs.core.tree_map_append.cljs$core$IFn$_invoke$arity$2(G__4604,G__4605) : cljs.core.tree_map_append.call(null,G__4604,G__4605)); +})(); +if((app instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(app.key,app.val,(new cljs.core.RedNode(left.key,left.val,left.left,app.left,null)),(new cljs.core.RedNode(right.key,right.val,app.right,right.right,null)),null)); +} else { +return (new cljs.core.RedNode(left.key,left.val,left.left,(new cljs.core.RedNode(right.key,right.val,app,right.right,null)),null)); +} +} else { +return (new cljs.core.RedNode(left.key,left.val,left.left,(function (){var G__4606 = left.right; +var G__4607 = right; +return (cljs.core.tree_map_append.cljs$core$IFn$_invoke$arity$2 ? cljs.core.tree_map_append.cljs$core$IFn$_invoke$arity$2(G__4606,G__4607) : cljs.core.tree_map_append.call(null,G__4606,G__4607)); +})(),null)); +} +} else { +if((right instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(right.key,right.val,(function (){var G__4608 = left; +var G__4609 = right.left; +return (cljs.core.tree_map_append.cljs$core$IFn$_invoke$arity$2 ? cljs.core.tree_map_append.cljs$core$IFn$_invoke$arity$2(G__4608,G__4609) : cljs.core.tree_map_append.call(null,G__4608,G__4609)); +})(),right.right,null)); +} else { +var app = (function (){var G__4610 = left.right; +var G__4611 = right.left; +return (cljs.core.tree_map_append.cljs$core$IFn$_invoke$arity$2 ? cljs.core.tree_map_append.cljs$core$IFn$_invoke$arity$2(G__4610,G__4611) : cljs.core.tree_map_append.call(null,G__4610,G__4611)); +})(); +if((app instanceof cljs.core.RedNode)){ +return (new cljs.core.RedNode(app.key,app.val,(new cljs.core.BlackNode(left.key,left.val,left.left,app.left,null)),(new cljs.core.BlackNode(right.key,right.val,app.right,right.right,null)),null)); +} else { +return cljs.core.balance_left_del(left.key,left.val,left.left,(new cljs.core.BlackNode(right.key,right.val,app,right.right,null))); +} + +} +} +} +} +}); +cljs.core.tree_map_remove = (function cljs$core$tree_map_remove(comp,tree,k,found){ +if((!((tree == null)))){ +var c = (function (){var G__4612 = k; +var G__4613 = tree.key; +return (comp.cljs$core$IFn$_invoke$arity$2 ? comp.cljs$core$IFn$_invoke$arity$2(G__4612,G__4613) : comp.call(null,G__4612,G__4613)); +})(); +if((c === (0))){ +(found[(0)] = tree); + +return cljs.core.tree_map_append(tree.left,tree.right); +} else { +if((c < (0))){ +var del = (function (){var G__4614 = comp; +var G__4615 = tree.left; +var G__4616 = k; +var G__4617 = found; +return (cljs.core.tree_map_remove.cljs$core$IFn$_invoke$arity$4 ? cljs.core.tree_map_remove.cljs$core$IFn$_invoke$arity$4(G__4614,G__4615,G__4616,G__4617) : cljs.core.tree_map_remove.call(null,G__4614,G__4615,G__4616,G__4617)); +})(); +if((((!((del == null)))) || ((!(((found[(0)]) == null)))))){ +if((tree.left instanceof cljs.core.BlackNode)){ +return cljs.core.balance_left_del(tree.key,tree.val,del,tree.right); +} else { +return (new cljs.core.RedNode(tree.key,tree.val,del,tree.right,null)); +} +} else { +return null; +} +} else { +var del = (function (){var G__4618 = comp; +var G__4619 = tree.right; +var G__4620 = k; +var G__4621 = found; +return (cljs.core.tree_map_remove.cljs$core$IFn$_invoke$arity$4 ? cljs.core.tree_map_remove.cljs$core$IFn$_invoke$arity$4(G__4618,G__4619,G__4620,G__4621) : cljs.core.tree_map_remove.call(null,G__4618,G__4619,G__4620,G__4621)); +})(); +if((((!((del == null)))) || ((!(((found[(0)]) == null)))))){ +if((tree.right instanceof cljs.core.BlackNode)){ +return cljs.core.balance_right_del(tree.key,tree.val,tree.left,del); +} else { +return (new cljs.core.RedNode(tree.key,tree.val,tree.left,del,null)); +} +} else { +return null; +} + +} +} +} else { +return null; +} +}); +cljs.core.tree_map_replace = (function cljs$core$tree_map_replace(comp,tree,k,v){ +var tk = tree.key; +var c = (comp.cljs$core$IFn$_invoke$arity$2 ? comp.cljs$core$IFn$_invoke$arity$2(k,tk) : comp.call(null,k,tk)); +if((c === (0))){ +return tree.replace(tk,v,tree.left,tree.right); +} else { +if((c < (0))){ +return tree.replace(tk,tree.val,(function (){var G__4622 = comp; +var G__4623 = tree.left; +var G__4624 = k; +var G__4625 = v; +return (cljs.core.tree_map_replace.cljs$core$IFn$_invoke$arity$4 ? cljs.core.tree_map_replace.cljs$core$IFn$_invoke$arity$4(G__4622,G__4623,G__4624,G__4625) : cljs.core.tree_map_replace.call(null,G__4622,G__4623,G__4624,G__4625)); +})(),tree.right); +} else { +return tree.replace(tk,tree.val,tree.left,(function (){var G__4626 = comp; +var G__4627 = tree.right; +var G__4628 = k; +var G__4629 = v; +return (cljs.core.tree_map_replace.cljs$core$IFn$_invoke$arity$4 ? cljs.core.tree_map_replace.cljs$core$IFn$_invoke$arity$4(G__4626,G__4627,G__4628,G__4629) : cljs.core.tree_map_replace.call(null,G__4626,G__4627,G__4628,G__4629)); +})()); + +} +} +}); + +/** +* @constructor + * @implements {cljs.core.IReversible} + * @implements {cljs.core.IKVReduce} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IFind} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISorted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IAssociative} + * @implements {cljs.core.IMap} + * @implements {cljs.core.ILookup} +*/ +cljs.core.PersistentTreeMap = (function (comp,tree,cnt,meta,__hash){ +this.comp = comp; +this.tree = tree; +this.cnt = cnt; +this.meta = meta; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 418776847; +this.cljs$lang$protocol_mask$partition1$ = 8192; +}); +cljs.core.PersistentTreeMap.prototype.cljs$core$IFind$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentTreeMap.prototype.cljs$core$IFind$_find$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return coll__$1.entry_at(k); +}); + +cljs.core.PersistentTreeMap.prototype.forEach = (function (f){ +var self__ = this; +var coll = this; +var seq__4631 = cljs.core.seq(coll); +var chunk__4632 = null; +var count__4633 = (0); +var i__4634 = (0); +while(true){ +if((i__4634 < count__4633)){ +var vec__4641 = chunk__4632.cljs$core$IIndexed$_nth$arity$2(null,i__4634); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4641,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4641,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4653 = seq__4631; +var G__4654 = chunk__4632; +var G__4655 = count__4633; +var G__4656 = (i__4634 + (1)); +seq__4631 = G__4653; +chunk__4632 = G__4654; +count__4633 = G__4655; +i__4634 = G__4656; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__4631); +if(temp__5735__auto__){ +var seq__4631__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__4631__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__4631__$1); +var G__4657 = cljs.core.chunk_rest(seq__4631__$1); +var G__4658 = c__4550__auto__; +var G__4659 = cljs.core.count(c__4550__auto__); +var G__4660 = (0); +seq__4631 = G__4657; +chunk__4632 = G__4658; +count__4633 = G__4659; +i__4634 = G__4660; +continue; +} else { +var vec__4644 = cljs.core.first(seq__4631__$1); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4644,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4644,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4661 = cljs.core.next(seq__4631__$1); +var G__4662 = null; +var G__4663 = (0); +var G__4664 = (0); +seq__4631 = G__4661; +chunk__4632 = G__4662; +count__4633 = G__4663; +i__4634 = G__4664; +continue; +} +} else { +return null; +} +} +break; +} +}); + +cljs.core.PersistentTreeMap.prototype.get = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.PersistentTreeMap.prototype.entries = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_entries_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentTreeMap.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentTreeMap.prototype.keys = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.keys(coll)); +}); + +cljs.core.PersistentTreeMap.prototype.values = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.vals(coll)); +}); + +cljs.core.PersistentTreeMap.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentTreeMap.prototype.entry_at = (function (k){ +var self__ = this; +var coll = this; +var t = self__.tree; +while(true){ +if((!((t == null)))){ +var c = (function (){var G__4647 = k; +var G__4648 = t.key; +return (self__.comp.cljs$core$IFn$_invoke$arity$2 ? self__.comp.cljs$core$IFn$_invoke$arity$2(G__4647,G__4648) : self__.comp.call(null,G__4647,G__4648)); +})(); +if((c === (0))){ +return t; +} else { +if((c < (0))){ +var G__4665 = t.left; +t = G__4665; +continue; +} else { +var G__4666 = t.right; +t = G__4666; +continue; + +} +} +} else { +return null; +} +break; +} +}); + +cljs.core.PersistentTreeMap.prototype.has = (function (k){ +var self__ = this; +var coll = this; +return cljs.core.contains_QMARK_(coll,k); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,k,null); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,k,not_found){ +var self__ = this; +var coll__$1 = this; +var n = coll__$1.entry_at(k); +if((!((n == null)))){ +return n.val; +} else { +return not_found; +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IKVReduce$_kv_reduce$arity$3 = (function (coll,f,init){ +var self__ = this; +var coll__$1 = this; +if((!((self__.tree == null)))){ +return cljs.core.unreduced(cljs.core.tree_map_kv_reduce(self__.tree,f,init)); +} else { +return init; +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.PersistentTreeMap(self__.comp,self__.tree,self__.cnt,self__.meta,self__.__hash)); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.cnt; +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IReversible$_rseq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt > (0))){ +return cljs.core.create_tree_map_seq(self__.tree,false,self__.cnt); +} else { +return null; +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_unordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_map(coll__$1,other); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.PersistentTreeMap(self__.comp,null,(0),self__.meta,(0))); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IMap$_dissoc$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +var found = [null]; +var t = cljs.core.tree_map_remove(self__.comp,self__.tree,k,found); +if((t == null)){ +if((cljs.core.nth.cljs$core$IFn$_invoke$arity$2(found,(0)) == null)){ +return coll__$1; +} else { +return (new cljs.core.PersistentTreeMap(self__.comp,null,(0),self__.meta,null)); +} +} else { +return (new cljs.core.PersistentTreeMap(self__.comp,t.blacken(),(self__.cnt - (1)),self__.meta,null)); +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IAssociative$_assoc$arity$3 = (function (coll,k,v){ +var self__ = this; +var coll__$1 = this; +var found = [null]; +var t = cljs.core.tree_map_add(self__.comp,self__.tree,k,v,found); +if((t == null)){ +var found_node = cljs.core.nth.cljs$core$IFn$_invoke$arity$2(found,(0)); +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(v,found_node.val)){ +return coll__$1; +} else { +return (new cljs.core.PersistentTreeMap(self__.comp,cljs.core.tree_map_replace(self__.comp,self__.tree,k,v),self__.cnt,self__.meta,null)); +} +} else { +return (new cljs.core.PersistentTreeMap(self__.comp,t.blacken(),(self__.cnt + (1)),self__.meta,null)); +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (coll,k){ +var self__ = this; +var coll__$1 = this; +return (!((coll__$1.entry_at(k) == null))); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt > (0))){ +return cljs.core.create_tree_map_seq(self__.tree,true,self__.cnt); +} else { +return null; +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentTreeMap(self__.comp,self__.tree,self__.cnt,new_meta,self__.__hash)); +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,entry){ +var self__ = this; +var coll__$1 = this; +if(cljs.core.vector_QMARK_(entry)){ +return coll__$1.cljs$core$IAssociative$_assoc$arity$3(null,cljs.core._nth.cljs$core$IFn$_invoke$arity$2(entry,(0)),cljs.core._nth.cljs$core$IFn$_invoke$arity$2(entry,(1))); +} else { +var ret = coll__$1; +var es = cljs.core.seq(entry); +while(true){ +if((es == null)){ +return ret; +} else { +var e = cljs.core.first(es); +if(cljs.core.vector_QMARK_(e)){ +var G__4667 = cljs.core._assoc(ret,cljs.core._nth.cljs$core$IFn$_invoke$arity$2(e,(0)),cljs.core._nth.cljs$core$IFn$_invoke$arity$2(e,(1))); +var G__4668 = cljs.core.next(es); +ret = G__4667; +es = G__4668; +continue; +} else { +throw (new Error("conj on a map takes map entries or seqables of map entries")); +} +} +break; +} +} +}); + +cljs.core.PersistentTreeMap.prototype.call = (function() { +var G__4669 = null; +var G__4669__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); +var G__4669__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); +G__4669 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4669__2.call(this,self__,k); +case 3: +return G__4669__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4669.cljs$core$IFn$_invoke$arity$2 = G__4669__2; +G__4669.cljs$core$IFn$_invoke$arity$3 = G__4669__3; +return G__4669; +})() +; + +cljs.core.PersistentTreeMap.prototype.apply = (function (self__,args4630){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4630))); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ISorted$_sorted_seq$arity$2 = (function (coll,ascending_QMARK_){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt > (0))){ +return cljs.core.create_tree_map_seq(self__.tree,ascending_QMARK_,self__.cnt); +} else { +return null; +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ISorted$_sorted_seq_from$arity$3 = (function (coll,k,ascending_QMARK_){ +var self__ = this; +var coll__$1 = this; +if((self__.cnt > (0))){ +var stack = null; +var t = self__.tree; +while(true){ +if((!((t == null)))){ +var c = (function (){var G__4651 = k; +var G__4652 = t.key; +return (self__.comp.cljs$core$IFn$_invoke$arity$2 ? self__.comp.cljs$core$IFn$_invoke$arity$2(G__4651,G__4652) : self__.comp.call(null,G__4651,G__4652)); +})(); +if((c === (0))){ +return (new cljs.core.PersistentTreeMapSeq(null,cljs.core.conj.cljs$core$IFn$_invoke$arity$2(stack,t),ascending_QMARK_,(-1),null)); +} else { +if(cljs.core.truth_(ascending_QMARK_)){ +if((c < (0))){ +var G__4670 = cljs.core.conj.cljs$core$IFn$_invoke$arity$2(stack,t); +var G__4671 = t.left; +stack = G__4670; +t = G__4671; +continue; +} else { +var G__4672 = stack; +var G__4673 = t.right; +stack = G__4672; +t = G__4673; +continue; +} +} else { +if((c > (0))){ +var G__4674 = cljs.core.conj.cljs$core$IFn$_invoke$arity$2(stack,t); +var G__4675 = t.right; +stack = G__4674; +t = G__4675; +continue; +} else { +var G__4676 = stack; +var G__4677 = t.left; +stack = G__4676; +t = G__4677; +continue; +} + +} +} +} else { +if((stack == null)){ +return null; +} else { +return (new cljs.core.PersistentTreeMapSeq(null,stack,ascending_QMARK_,(-1),null)); +} +} +break; +} +} else { +return null; +} +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ISorted$_entry_key$arity$2 = (function (coll,entry){ +var self__ = this; +var coll__$1 = this; +return cljs.core.key(entry); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$ISorted$_comparator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.comp; +}); + +cljs.core.PersistentTreeMap.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 5, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$comp,cljs.core.cst$sym$tree,cljs.core.cst$sym$cnt,cljs.core.cst$sym$meta,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentTreeMap.cljs$lang$type = true; + +cljs.core.PersistentTreeMap.cljs$lang$ctorStr = "cljs.core/PersistentTreeMap"; + +cljs.core.PersistentTreeMap.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentTreeMap"); +}); + +/** + * Positional factory function for cljs.core/PersistentTreeMap. + */ +cljs.core.__GT_PersistentTreeMap = (function cljs$core$__GT_PersistentTreeMap(comp,tree,cnt,meta,__hash){ +return (new cljs.core.PersistentTreeMap(comp,tree,cnt,meta,__hash)); +}); + +cljs.core.PersistentTreeMap.EMPTY = (new cljs.core.PersistentTreeMap(cljs.core.compare,null,(0),null,cljs.core.empty_unordered_hash)); +var G__4678_4681 = cljs.core.PersistentTreeMap.prototype; +var G__4679_4682 = cljs.core.ITER_SYMBOL; +var G__4680_4683 = ((function (G__4678_4681,G__4679_4682){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4678_4681,G__4679_4682)) +; +goog.object.set(G__4678_4681,G__4679_4682,G__4680_4683); +/** + * keyval => key val + * Returns a new hash map with supplied mappings. + */ +cljs.core.hash_map = (function cljs$core$hash_map(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4685 = arguments.length; +var i__4731__auto___4686 = (0); +while(true){ +if((i__4731__auto___4686 < len__4730__auto___4685)){ +args__4736__auto__.push((arguments[i__4731__auto___4686])); + +var G__4687 = (i__4731__auto___4686 + (1)); +i__4731__auto___4686 = G__4687; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.hash_map.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.hash_map.cljs$core$IFn$_invoke$arity$variadic = (function (keyvals){ +var in$ = cljs.core.seq(keyvals); +var out = cljs.core.transient$(cljs.core.PersistentHashMap.EMPTY); +while(true){ +if(in$){ +var G__4688 = cljs.core.nnext(in$); +var G__4689 = cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(out,cljs.core.first(in$),cljs.core.second(in$)); +in$ = G__4688; +out = G__4689; +continue; +} else { +return cljs.core.persistent_BANG_(out); +} +break; +} +}); + +cljs.core.hash_map.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.hash_map.cljs$lang$applyTo = (function (seq4684){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq4684)); +}); + +/** + * keyval => key val + * Returns a new array map with supplied mappings. + */ +cljs.core.array_map = (function cljs$core$array_map(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4691 = arguments.length; +var i__4731__auto___4692 = (0); +while(true){ +if((i__4731__auto___4692 < len__4730__auto___4691)){ +args__4736__auto__.push((arguments[i__4731__auto___4692])); + +var G__4693 = (i__4731__auto___4692 + (1)); +i__4731__auto___4692 = G__4693; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.array_map.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.array_map.cljs$core$IFn$_invoke$arity$variadic = (function (keyvals){ +var arr = (((((keyvals instanceof cljs.core.IndexedSeq)) && ((keyvals.i === (0)))))?keyvals.arr:cljs.core.into_array.cljs$core$IFn$_invoke$arity$1(keyvals)); +return cljs.core.PersistentArrayMap.createAsIfByAssoc(arr); +}); + +cljs.core.array_map.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.array_map.cljs$lang$applyTo = (function (seq4690){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq4690)); +}); + +/** + * keyval => key val + * Returns a new object map with supplied mappings. + */ +cljs.core.obj_map = (function cljs$core$obj_map(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4700 = arguments.length; +var i__4731__auto___4701 = (0); +while(true){ +if((i__4731__auto___4701 < len__4730__auto___4700)){ +args__4736__auto__.push((arguments[i__4731__auto___4701])); + +var G__4702 = (i__4731__auto___4701 + (1)); +i__4731__auto___4701 = G__4702; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.obj_map.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.obj_map.cljs$core$IFn$_invoke$arity$variadic = (function (keyvals){ +var ks = []; +var obj = ({}); +var kvs = cljs.core.seq(keyvals); +while(true){ +if(kvs){ +ks.push(cljs.core.first(kvs)); + +var G__4697_4703 = obj; +var G__4698_4704 = cljs.core.first(kvs); +var G__4699_4705 = cljs.core.second(kvs); +goog.object.set(G__4697_4703,G__4698_4704,G__4699_4705); + +var G__4706 = cljs.core.nnext(kvs); +kvs = G__4706; +continue; +} else { +return cljs.core.ObjMap.fromObject(ks,obj); +} +break; +} +}); + +cljs.core.obj_map.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.obj_map.cljs$lang$applyTo = (function (seq4694){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq4694)); +}); + +/** + * keyval => key val + * Returns a new sorted map with supplied mappings. + */ +cljs.core.sorted_map = (function cljs$core$sorted_map(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4708 = arguments.length; +var i__4731__auto___4709 = (0); +while(true){ +if((i__4731__auto___4709 < len__4730__auto___4708)){ +args__4736__auto__.push((arguments[i__4731__auto___4709])); + +var G__4710 = (i__4731__auto___4709 + (1)); +i__4731__auto___4709 = G__4710; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.sorted_map.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.sorted_map.cljs$core$IFn$_invoke$arity$variadic = (function (keyvals){ +var in$ = cljs.core.seq(keyvals); +var out = cljs.core.PersistentTreeMap.EMPTY; +while(true){ +if(in$){ +var G__4711 = cljs.core.nnext(in$); +var G__4712 = cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(out,cljs.core.first(in$),cljs.core.second(in$)); +in$ = G__4711; +out = G__4712; +continue; +} else { +return out; +} +break; +} +}); + +cljs.core.sorted_map.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.sorted_map.cljs$lang$applyTo = (function (seq4707){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq4707)); +}); + +/** + * keyval => key val + * Returns a new sorted map with supplied mappings, using the supplied comparator. + */ +cljs.core.sorted_map_by = (function cljs$core$sorted_map_by(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4715 = arguments.length; +var i__4731__auto___4716 = (0); +while(true){ +if((i__4731__auto___4716 < len__4730__auto___4715)){ +args__4736__auto__.push((arguments[i__4731__auto___4716])); + +var G__4717 = (i__4731__auto___4716 + (1)); +i__4731__auto___4716 = G__4717; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null); +return cljs.core.sorted_map_by.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__); +}); + +cljs.core.sorted_map_by.cljs$core$IFn$_invoke$arity$variadic = (function (comparator,keyvals){ +var in$ = cljs.core.seq(keyvals); +var out = (new cljs.core.PersistentTreeMap(cljs.core.fn__GT_comparator(comparator),null,(0),null,(0))); +while(true){ +if(in$){ +var G__4718 = cljs.core.nnext(in$); +var G__4719 = cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(out,cljs.core.first(in$),cljs.core.second(in$)); +in$ = G__4718; +out = G__4719; +continue; +} else { +return out; +} +break; +} +}); + +cljs.core.sorted_map_by.cljs$lang$maxFixedArity = (1); + +/** @this {Function} */ +cljs.core.sorted_map_by.cljs$lang$applyTo = (function (seq4713){ +var G__4714 = cljs.core.first(seq4713); +var seq4713__$1 = cljs.core.next(seq4713); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4714,seq4713__$1); +}); + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.KeySeq = (function (mseq,_meta){ +this.mseq = mseq; +this._meta = _meta; +this.cljs$lang$protocol_mask$partition0$ = 32374988; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.KeySeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.KeySeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.KeySeq.prototype.indexOf = (function() { +var G__4722 = null; +var G__4722__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4722__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4722 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4722__1.call(this,x); +case 2: +return G__4722__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4722.cljs$core$IFn$_invoke$arity$1 = G__4722__1; +G__4722.cljs$core$IFn$_invoke$arity$2 = G__4722__2; +return G__4722; +})() +; + +cljs.core.KeySeq.prototype.lastIndexOf = (function() { +var G__4723 = null; +var G__4723__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4723__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4723 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4723__1.call(this,x); +case 2: +return G__4723__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4723.cljs$core$IFn$_invoke$arity$1 = G__4723__1; +G__4723.cljs$core$IFn$_invoke$arity$2 = G__4723__2; +return G__4723; +})() +; + +cljs.core.KeySeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__._meta; +}); + +cljs.core.KeySeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var nseq = (((((!((self__.mseq == null))))?(((((self__.mseq.cljs$lang$protocol_mask$partition0$ & (128))) || ((cljs.core.PROTOCOL_SENTINEL === self__.mseq.cljs$core$INext$))))?true:(((!self__.mseq.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_(cljs.core.INext,self__.mseq):false)):cljs.core.native_satisfies_QMARK_(cljs.core.INext,self__.mseq)))?self__.mseq.cljs$core$INext$_next$arity$1(null):cljs.core.next(self__.mseq)); +if((nseq == null)){ +return null; +} else { +return (new cljs.core.KeySeq(nseq,null)); +} +}); + +cljs.core.KeySeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.hash_ordered_coll(coll__$1); +}); + +cljs.core.KeySeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.KeySeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.KeySeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.KeySeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.KeySeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var me = self__.mseq.cljs$core$ISeq$_first$arity$1(null); +return me.cljs$core$IMapEntry$_key$arity$1(null); +}); + +cljs.core.KeySeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var nseq = (((((!((self__.mseq == null))))?(((((self__.mseq.cljs$lang$protocol_mask$partition0$ & (128))) || ((cljs.core.PROTOCOL_SENTINEL === self__.mseq.cljs$core$INext$))))?true:(((!self__.mseq.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_(cljs.core.INext,self__.mseq):false)):cljs.core.native_satisfies_QMARK_(cljs.core.INext,self__.mseq)))?self__.mseq.cljs$core$INext$_next$arity$1(null):cljs.core.next(self__.mseq)); +if((!((nseq == null)))){ +return (new cljs.core.KeySeq(nseq,null)); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.KeySeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.KeySeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__._meta)){ +return coll__$1; +} else { +return (new cljs.core.KeySeq(self__.mseq,new_meta)); +} +}); + +cljs.core.KeySeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.KeySeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$mseq,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$tag,cljs.core.cst$sym$not_DASH_native], null)),cljs.core.cst$sym$_meta], null); +}); + +cljs.core.KeySeq.cljs$lang$type = true; + +cljs.core.KeySeq.cljs$lang$ctorStr = "cljs.core/KeySeq"; + +cljs.core.KeySeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/KeySeq"); +}); + +/** + * Positional factory function for cljs.core/KeySeq. + */ +cljs.core.__GT_KeySeq = (function cljs$core$__GT_KeySeq(mseq,_meta){ +return (new cljs.core.KeySeq(mseq,_meta)); +}); + +var G__4724_4727 = cljs.core.KeySeq.prototype; +var G__4725_4728 = cljs.core.ITER_SYMBOL; +var G__4726_4729 = ((function (G__4724_4727,G__4725_4728){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4724_4727,G__4725_4728)) +; +goog.object.set(G__4724_4727,G__4725_4728,G__4726_4729); +/** + * Returns a sequence of the map's keys, in the same order as (seq map). + */ +cljs.core.keys = (function cljs$core$keys(map){ +var temp__5735__auto__ = cljs.core.seq(map); +if(temp__5735__auto__){ +var mseq = temp__5735__auto__; +return (new cljs.core.KeySeq(mseq,null)); +} else { +return null; +} +}); +/** + * Returns the key of the map entry. + */ +cljs.core.key = (function cljs$core$key(map_entry){ +return cljs.core._key(map_entry); +}); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.ValSeq = (function (mseq,_meta){ +this.mseq = mseq; +this._meta = _meta; +this.cljs$lang$protocol_mask$partition0$ = 32374988; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.ValSeq.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.ValSeq.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.ValSeq.prototype.indexOf = (function() { +var G__4732 = null; +var G__4732__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4732__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4732 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4732__1.call(this,x); +case 2: +return G__4732__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4732.cljs$core$IFn$_invoke$arity$1 = G__4732__1; +G__4732.cljs$core$IFn$_invoke$arity$2 = G__4732__2; +return G__4732; +})() +; + +cljs.core.ValSeq.prototype.lastIndexOf = (function() { +var G__4733 = null; +var G__4733__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4733__2 = (function (x,start){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start); +}); +G__4733 = function(x,start){ +switch(arguments.length){ +case 1: +return G__4733__1.call(this,x); +case 2: +return G__4733__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4733.cljs$core$IFn$_invoke$arity$1 = G__4733__1; +G__4733.cljs$core$IFn$_invoke$arity$2 = G__4733__2; +return G__4733; +})() +; + +cljs.core.ValSeq.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__._meta; +}); + +cljs.core.ValSeq.prototype.cljs$core$INext$_next$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var nseq = (((((!((self__.mseq == null))))?(((((self__.mseq.cljs$lang$protocol_mask$partition0$ & (128))) || ((cljs.core.PROTOCOL_SENTINEL === self__.mseq.cljs$core$INext$))))?true:(((!self__.mseq.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_(cljs.core.INext,self__.mseq):false)):cljs.core.native_satisfies_QMARK_(cljs.core.INext,self__.mseq)))?self__.mseq.cljs$core$INext$_next$arity$1(null):cljs.core.next(self__.mseq)); +if((nseq == null)){ +return null; +} else { +return (new cljs.core.ValSeq(nseq,null)); +} +}); + +cljs.core.ValSeq.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.hash_ordered_coll(coll__$1); +}); + +cljs.core.ValSeq.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +return cljs.core.equiv_sequential(coll__$1,other); +}); + +cljs.core.ValSeq.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.ValSeq.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (coll,f){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$2(f,coll__$1); +}); + +cljs.core.ValSeq.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (coll,f,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core.seq_reduce.cljs$core$IFn$_invoke$arity$3(f,start,coll__$1); +}); + +cljs.core.ValSeq.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var me = self__.mseq.cljs$core$ISeq$_first$arity$1(null); +return me.cljs$core$IMapEntry$_val$arity$1(null); +}); + +cljs.core.ValSeq.prototype.cljs$core$ISeq$_rest$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var nseq = (((((!((self__.mseq == null))))?(((((self__.mseq.cljs$lang$protocol_mask$partition0$ & (128))) || ((cljs.core.PROTOCOL_SENTINEL === self__.mseq.cljs$core$INext$))))?true:(((!self__.mseq.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_(cljs.core.INext,self__.mseq):false)):cljs.core.native_satisfies_QMARK_(cljs.core.INext,self__.mseq)))?self__.mseq.cljs$core$INext$_next$arity$1(null):cljs.core.next(self__.mseq)); +if((!((nseq == null)))){ +return (new cljs.core.ValSeq(nseq,null)); +} else { +return cljs.core.List.EMPTY; +} +}); + +cljs.core.ValSeq.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return coll__$1; +}); + +cljs.core.ValSeq.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__._meta)){ +return coll__$1; +} else { +return (new cljs.core.ValSeq(self__.mseq,new_meta)); +} +}); + +cljs.core.ValSeq.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return cljs.core.cons(o,coll__$1); +}); + +cljs.core.ValSeq.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$mseq,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$tag,cljs.core.cst$sym$not_DASH_native], null)),cljs.core.cst$sym$_meta], null); +}); + +cljs.core.ValSeq.cljs$lang$type = true; + +cljs.core.ValSeq.cljs$lang$ctorStr = "cljs.core/ValSeq"; + +cljs.core.ValSeq.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ValSeq"); +}); + +/** + * Positional factory function for cljs.core/ValSeq. + */ +cljs.core.__GT_ValSeq = (function cljs$core$__GT_ValSeq(mseq,_meta){ +return (new cljs.core.ValSeq(mseq,_meta)); +}); + +var G__4734_4737 = cljs.core.ValSeq.prototype; +var G__4735_4738 = cljs.core.ITER_SYMBOL; +var G__4736_4739 = ((function (G__4734_4737,G__4735_4738){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4734_4737,G__4735_4738)) +; +goog.object.set(G__4734_4737,G__4735_4738,G__4736_4739); +/** + * Returns a sequence of the map's values, in the same order as (seq map). + */ +cljs.core.vals = (function cljs$core$vals(map){ +var temp__5735__auto__ = cljs.core.seq(map); +if(temp__5735__auto__){ +var mseq = temp__5735__auto__; +return (new cljs.core.ValSeq(mseq,null)); +} else { +return null; +} +}); +/** + * Returns the value in the map entry. + */ +cljs.core.val = (function cljs$core$val(map_entry){ +return cljs.core._val(map_entry); +}); +/** + * Returns a map that consists of the rest of the maps conj-ed onto + * the first. If a key occurs in more than one map, the mapping from + * the latter (left-to-right) will be the mapping in the result. + */ +cljs.core.merge = (function cljs$core$merge(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4743 = arguments.length; +var i__4731__auto___4744 = (0); +while(true){ +if((i__4731__auto___4744 < len__4730__auto___4743)){ +args__4736__auto__.push((arguments[i__4731__auto___4744])); + +var G__4745 = (i__4731__auto___4744 + (1)); +i__4731__auto___4744 = G__4745; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.merge.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.merge.cljs$core$IFn$_invoke$arity$variadic = (function (maps){ +if(cljs.core.truth_(cljs.core.some(cljs.core.identity,maps))){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$2((function (p1__4740_SHARP_,p2__4741_SHARP_){ +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2((function (){var or__4131__auto__ = p1__4740_SHARP_; +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.PersistentArrayMap.EMPTY; +} +})(),p2__4741_SHARP_); +}),maps); +} else { +return null; +} +}); + +cljs.core.merge.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.merge.cljs$lang$applyTo = (function (seq4742){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq4742)); +}); + +/** + * Returns a map that consists of the rest of the maps conj-ed onto + * the first. If a key occurs in more than one map, the mapping(s) + * from the latter (left-to-right) will be combined with the mapping in + * the result by calling (f val-in-result val-in-latter). + */ +cljs.core.merge_with = (function cljs$core$merge_with(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4750 = arguments.length; +var i__4731__auto___4751 = (0); +while(true){ +if((i__4731__auto___4751 < len__4730__auto___4750)){ +args__4736__auto__.push((arguments[i__4731__auto___4751])); + +var G__4752 = (i__4731__auto___4751 + (1)); +i__4731__auto___4751 = G__4752; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null); +return cljs.core.merge_with.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__); +}); + +cljs.core.merge_with.cljs$core$IFn$_invoke$arity$variadic = (function (f,maps){ +if(cljs.core.truth_(cljs.core.some(cljs.core.identity,maps))){ +var merge_entry = (function (m,e){ +var k = cljs.core.key(e); +var v = cljs.core.val(e); +if(cljs.core.contains_QMARK_(m,k)){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,(function (){var G__4748 = cljs.core.get.cljs$core$IFn$_invoke$arity$2(m,k); +var G__4749 = v; +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__4748,G__4749) : f.call(null,G__4748,G__4749)); +})()); +} else { +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(m,k,v); +} +}); +var merge2 = ((function (merge_entry){ +return (function (m1,m2){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(merge_entry,(function (){var or__4131__auto__ = m1; +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.PersistentArrayMap.EMPTY; +} +})(),cljs.core.seq(m2)); +});})(merge_entry)) +; +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$2(merge2,maps); +} else { +return null; +} +}); + +cljs.core.merge_with.cljs$lang$maxFixedArity = (1); + +/** @this {Function} */ +cljs.core.merge_with.cljs$lang$applyTo = (function (seq4746){ +var G__4747 = cljs.core.first(seq4746); +var seq4746__$1 = cljs.core.next(seq4746); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4747,seq4746__$1); +}); + +/** + * Returns a map containing only those entries in map whose key is in keys + */ +cljs.core.select_keys = (function cljs$core$select_keys(map,keyseq){ +var ret = cljs.core.PersistentArrayMap.EMPTY; +var keys = cljs.core.seq(keyseq); +while(true){ +if(keys){ +var key = cljs.core.first(keys); +var entry = cljs.core.get.cljs$core$IFn$_invoke$arity$3(map,key,cljs.core.cst$kw$cljs$core_SLASH_not_DASH_found); +var G__4753 = ((cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2(entry,cljs.core.cst$kw$cljs$core_SLASH_not_DASH_found))?cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(ret,key,entry):ret); +var G__4754 = cljs.core.next(keys); +ret = G__4753; +keys = G__4754; +continue; +} else { +return cljs.core._with_meta(ret,cljs.core.meta(map)); +} +break; +} +}); + +/** +* @constructor +*/ +cljs.core.HashSetIter = (function (iter){ +this.iter = iter; +}); +cljs.core.HashSetIter.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +return self__.iter.hasNext(); +}); + +cljs.core.HashSetIter.prototype.next = (function (){ +var self__ = this; +var _ = this; +if(self__.iter.hasNext()){ +return self__.iter.next().key; +} else { +throw (new Error("No such element")); +} +}); + +cljs.core.HashSetIter.prototype.remove = (function (){ +var self__ = this; +var _ = this; +return (new Error("Unsupported operation")); +}); + +cljs.core.HashSetIter.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$iter], null); +}); + +cljs.core.HashSetIter.cljs$lang$type = true; + +cljs.core.HashSetIter.cljs$lang$ctorStr = "cljs.core/HashSetIter"; + +cljs.core.HashSetIter.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/HashSetIter"); +}); + +/** + * Positional factory function for cljs.core/HashSetIter. + */ +cljs.core.__GT_HashSetIter = (function cljs$core$__GT_HashSetIter(iter){ +return (new cljs.core.HashSetIter(iter)); +}); + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IEditableCollection} + * @implements {cljs.core.ISet} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.ILookup} +*/ +cljs.core.PersistentHashSet = (function (meta,hash_map,__hash){ +this.meta = meta; +this.hash_map = hash_map; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 15077647; +this.cljs$lang$protocol_mask$partition1$ = 139268; +}); +cljs.core.PersistentHashSet.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentHashSet.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentHashSet.prototype.keys = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentHashSet.prototype.entries = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_set_entries_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentHashSet.prototype.values = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentHashSet.prototype.has = (function (k){ +var self__ = this; +var coll = this; +return cljs.core.contains_QMARK_(coll,k); +}); + +cljs.core.PersistentHashSet.prototype.forEach = (function (f){ +var self__ = this; +var coll = this; +var seq__4758 = cljs.core.seq(coll); +var chunk__4759 = null; +var count__4760 = (0); +var i__4761 = (0); +while(true){ +if((i__4761 < count__4760)){ +var vec__4768 = chunk__4759.cljs$core$IIndexed$_nth$arity$2(null,i__4761); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4768,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4768,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4777 = seq__4758; +var G__4778 = chunk__4759; +var G__4779 = count__4760; +var G__4780 = (i__4761 + (1)); +seq__4758 = G__4777; +chunk__4759 = G__4778; +count__4760 = G__4779; +i__4761 = G__4780; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__4758); +if(temp__5735__auto__){ +var seq__4758__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__4758__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__4758__$1); +var G__4781 = cljs.core.chunk_rest(seq__4758__$1); +var G__4782 = c__4550__auto__; +var G__4783 = cljs.core.count(c__4550__auto__); +var G__4784 = (0); +seq__4758 = G__4781; +chunk__4759 = G__4782; +count__4760 = G__4783; +i__4761 = G__4784; +continue; +} else { +var vec__4771 = cljs.core.first(seq__4758__$1); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4771,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4771,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4785 = cljs.core.next(seq__4758__$1); +var G__4786 = null; +var G__4787 = (0); +var G__4788 = (0); +seq__4758 = G__4785; +chunk__4759 = G__4786; +count__4760 = G__4787; +i__4761 = G__4788; +continue; +} +} else { +return null; +} +} +break; +} +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,v){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,v,null); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,v,not_found){ +var self__ = this; +var coll__$1 = this; +var temp__5733__auto__ = cljs.core._find(self__.hash_map,v); +if(cljs.core.truth_(temp__5733__auto__)){ +var entry = temp__5733__auto__; +return cljs.core.key(entry); +} else { +return not_found; +} +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.HashSetIter(cljs.core._iterator(self__.hash_map))); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.PersistentHashSet(self__.meta,self__.hash_map,self__.__hash)); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._count(self__.hash_map); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_unordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +var and__4120__auto__ = cljs.core.set_QMARK_(other); +if(and__4120__auto__){ +var and__4120__auto____$1 = (cljs.core.count(coll__$1) === cljs.core.count(other)); +if(and__4120__auto____$1){ +try{return cljs.core.reduce_kv(((function (and__4120__auto____$1,and__4120__auto__,coll__$1){ +return (function (p1__4756_SHARP_,p2__4755_SHARP_){ +var or__4131__auto__ = cljs.core.contains_QMARK_(other,p2__4755_SHARP_); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return cljs.core.reduced(false); +} +});})(and__4120__auto____$1,and__4120__auto__,coll__$1)) +,true,self__.hash_map); +}catch (e4776){if((e4776 instanceof Error)){ +var ex = e4776; +return false; +} else { +throw e4776; + +} +}} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IEditableCollection$_as_transient$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.TransientHashSet(cljs.core._as_transient(self__.hash_map))); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._with_meta(cljs.core.PersistentHashSet.EMPTY,self__.meta); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$ISet$_disjoin$arity$2 = (function (coll,v){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.PersistentHashSet(self__.meta,cljs.core._dissoc(self__.hash_map,v),null)); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.keys(self__.hash_map); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentHashSet(new_meta,self__.hash_map,self__.__hash)); +} +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.PersistentHashSet(self__.meta,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(self__.hash_map,o,null),null)); +}); + +cljs.core.PersistentHashSet.prototype.call = (function() { +var G__4789 = null; +var G__4789__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); +var G__4789__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); +G__4789 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4789__2.call(this,self__,k); +case 3: +return G__4789__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4789.cljs$core$IFn$_invoke$arity$2 = G__4789__2; +G__4789.cljs$core$IFn$_invoke$arity$3 = G__4789__3; +return G__4789; +})() +; + +cljs.core.PersistentHashSet.prototype.apply = (function (self__,args4757){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4757))); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.PersistentHashSet.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$hash_DASH_map,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentHashSet.cljs$lang$type = true; + +cljs.core.PersistentHashSet.cljs$lang$ctorStr = "cljs.core/PersistentHashSet"; + +cljs.core.PersistentHashSet.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentHashSet"); +}); + +/** + * Positional factory function for cljs.core/PersistentHashSet. + */ +cljs.core.__GT_PersistentHashSet = (function cljs$core$__GT_PersistentHashSet(meta,hash_map,__hash){ +return (new cljs.core.PersistentHashSet(meta,hash_map,__hash)); +}); + +cljs.core.PersistentHashSet.EMPTY = (new cljs.core.PersistentHashSet(null,cljs.core.PersistentArrayMap.EMPTY,cljs.core.empty_unordered_hash)); +cljs.core.PersistentHashSet.fromArray = (function (items,no_clone){ +var len = items.length; +if((len <= cljs.core.PersistentArrayMap.HASHMAP_THRESHOLD)){ +var arr = ((no_clone)?items:cljs.core.aclone(items)); +var i = (0); +var out = cljs.core.transient$(cljs.core.PersistentArrayMap.EMPTY); +while(true){ +if((i < len)){ +var G__4790 = (i + (1)); +var G__4791 = cljs.core._assoc_BANG_(out,(items[i]),null); +i = G__4790; +out = G__4791; +continue; +} else { +return (new cljs.core.PersistentHashSet(null,cljs.core._persistent_BANG_(out),null)); +} +break; +} +} else { +var i = (0); +var out = cljs.core.transient$(cljs.core.PersistentHashSet.EMPTY); +while(true){ +if((i < len)){ +var G__4792 = (i + (1)); +var G__4793 = cljs.core._conj_BANG_(out,(items[i])); +i = G__4792; +out = G__4793; +continue; +} else { +return cljs.core._persistent_BANG_(out); +} +break; +} +} +}); +cljs.core.PersistentHashSet.createWithCheck = (function (items){ +var len = items.length; +var t = cljs.core._as_transient(cljs.core.PersistentHashSet.EMPTY); +var n__4607__auto___4794 = len; +var i_4795 = (0); +while(true){ +if((i_4795 < n__4607__auto___4794)){ +cljs.core._conj_BANG_(t,(items[i_4795])); + +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.count(t),(i_4795 + (1)))){ +} else { +throw (new Error(["Duplicate key: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1((items[i_4795]))].join(''))); +} + +var G__4796 = (i_4795 + (1)); +i_4795 = G__4796; +continue; +} else { +} +break; +} + +return cljs.core._persistent_BANG_(t); +}); +cljs.core.PersistentHashSet.createAsIfByAssoc = (function (items){ +var len = items.length; +var t = cljs.core._as_transient(cljs.core.PersistentHashSet.EMPTY); +var n__4607__auto___4797 = len; +var i_4798 = (0); +while(true){ +if((i_4798 < n__4607__auto___4797)){ +cljs.core._conj_BANG_(t,(items[i_4798])); + +var G__4799 = (i_4798 + (1)); +i_4798 = G__4799; +continue; +} else { +} +break; +} + +return cljs.core._persistent_BANG_(t); +}); +var G__4800_4803 = cljs.core.PersistentHashSet.prototype; +var G__4801_4804 = cljs.core.ITER_SYMBOL; +var G__4802_4805 = ((function (G__4800_4803,G__4801_4804){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4800_4803,G__4801_4804)) +; +goog.object.set(G__4800_4803,G__4801_4804,G__4802_4805); + +/** +* @constructor + * @implements {cljs.core.ITransientSet} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ITransientCollection} + * @implements {cljs.core.ILookup} +*/ +cljs.core.TransientHashSet = (function (transient_map){ +this.transient_map = transient_map; +this.cljs$lang$protocol_mask$partition1$ = 136; +this.cljs$lang$protocol_mask$partition0$ = 259; +}); +cljs.core.TransientHashSet.prototype.cljs$core$ITransientCollection$_conj_BANG_$arity$2 = (function (tcoll,o){ +var self__ = this; +var tcoll__$1 = this; +self__.transient_map = cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(self__.transient_map,o,null); + +return tcoll__$1; +}); + +cljs.core.TransientHashSet.prototype.cljs$core$ITransientCollection$_persistent_BANG_$arity$1 = (function (tcoll){ +var self__ = this; +var tcoll__$1 = this; +return (new cljs.core.PersistentHashSet(null,cljs.core.persistent_BANG_(self__.transient_map),null)); +}); + +cljs.core.TransientHashSet.prototype.cljs$core$ITransientSet$_disjoin_BANG_$arity$2 = (function (tcoll,v){ +var self__ = this; +var tcoll__$1 = this; +self__.transient_map = cljs.core.dissoc_BANG_.cljs$core$IFn$_invoke$arity$2(self__.transient_map,v); + +return tcoll__$1; +}); + +cljs.core.TransientHashSet.prototype.cljs$core$ICounted$_count$arity$1 = (function (tcoll){ +var self__ = this; +var tcoll__$1 = this; +return cljs.core.count(self__.transient_map); +}); + +cljs.core.TransientHashSet.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (tcoll,v){ +var self__ = this; +var tcoll__$1 = this; +return tcoll__$1.cljs$core$ILookup$_lookup$arity$3(null,v,null); +}); + +cljs.core.TransientHashSet.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (tcoll,v,not_found){ +var self__ = this; +var tcoll__$1 = this; +if((cljs.core._lookup.cljs$core$IFn$_invoke$arity$3(self__.transient_map,v,cljs.core.lookup_sentinel) === cljs.core.lookup_sentinel)){ +return not_found; +} else { +return v; +} +}); + +cljs.core.TransientHashSet.prototype.call = (function() { +var G__4807 = null; +var G__4807__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var tcoll = self____$1; +if((cljs.core._lookup.cljs$core$IFn$_invoke$arity$3(self__.transient_map,k,cljs.core.lookup_sentinel) === cljs.core.lookup_sentinel)){ +return null; +} else { +return k; +} +}); +var G__4807__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var tcoll = self____$1; +if((cljs.core._lookup.cljs$core$IFn$_invoke$arity$3(self__.transient_map,k,cljs.core.lookup_sentinel) === cljs.core.lookup_sentinel)){ +return not_found; +} else { +return k; +} +}); +G__4807 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4807__2.call(this,self__,k); +case 3: +return G__4807__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4807.cljs$core$IFn$_invoke$arity$2 = G__4807__2; +G__4807.cljs$core$IFn$_invoke$arity$3 = G__4807__3; +return G__4807; +})() +; + +cljs.core.TransientHashSet.prototype.apply = (function (self__,args4806){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4806))); +}); + +cljs.core.TransientHashSet.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var tcoll = this; +if((cljs.core._lookup.cljs$core$IFn$_invoke$arity$3(self__.transient_map,k,cljs.core.lookup_sentinel) === cljs.core.lookup_sentinel)){ +return null; +} else { +return k; +} +}); + +cljs.core.TransientHashSet.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var tcoll = this; +if((cljs.core._lookup.cljs$core$IFn$_invoke$arity$3(self__.transient_map,k,cljs.core.lookup_sentinel) === cljs.core.lookup_sentinel)){ +return not_found; +} else { +return k; +} +}); + +cljs.core.TransientHashSet.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$transient_DASH_map,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.TransientHashSet.cljs$lang$type = true; + +cljs.core.TransientHashSet.cljs$lang$ctorStr = "cljs.core/TransientHashSet"; + +cljs.core.TransientHashSet.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/TransientHashSet"); +}); + +/** + * Positional factory function for cljs.core/TransientHashSet. + */ +cljs.core.__GT_TransientHashSet = (function cljs$core$__GT_TransientHashSet(transient_map){ +return (new cljs.core.TransientHashSet(transient_map)); +}); + + +/** +* @constructor + * @implements {cljs.core.IReversible} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.ISet} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISorted} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.ILookup} +*/ +cljs.core.PersistentTreeSet = (function (meta,tree_map,__hash){ +this.meta = meta; +this.tree_map = tree_map; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 417730831; +this.cljs$lang$protocol_mask$partition1$ = 8192; +}); +cljs.core.PersistentTreeSet.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.PersistentTreeSet.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.PersistentTreeSet.prototype.keys = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentTreeSet.prototype.entries = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_set_entries_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentTreeSet.prototype.values = (function (){ +var self__ = this; +var coll = this; +return cljs.core.es6_iterator(cljs.core.seq(coll)); +}); + +cljs.core.PersistentTreeSet.prototype.has = (function (k){ +var self__ = this; +var coll = this; +return cljs.core.contains_QMARK_(coll,k); +}); + +cljs.core.PersistentTreeSet.prototype.forEach = (function (f){ +var self__ = this; +var coll = this; +var seq__4811 = cljs.core.seq(coll); +var chunk__4812 = null; +var count__4813 = (0); +var i__4814 = (0); +while(true){ +if((i__4814 < count__4813)){ +var vec__4821 = chunk__4812.cljs$core$IIndexed$_nth$arity$2(null,i__4814); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4821,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4821,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4830 = seq__4811; +var G__4831 = chunk__4812; +var G__4832 = count__4813; +var G__4833 = (i__4814 + (1)); +seq__4811 = G__4830; +chunk__4812 = G__4831; +count__4813 = G__4832; +i__4814 = G__4833; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__4811); +if(temp__5735__auto__){ +var seq__4811__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__4811__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__4811__$1); +var G__4834 = cljs.core.chunk_rest(seq__4811__$1); +var G__4835 = c__4550__auto__; +var G__4836 = cljs.core.count(c__4550__auto__); +var G__4837 = (0); +seq__4811 = G__4834; +chunk__4812 = G__4835; +count__4813 = G__4836; +i__4814 = G__4837; +continue; +} else { +var vec__4824 = cljs.core.first(seq__4811__$1); +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4824,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4824,(1),null); +(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(v,k) : f.call(null,v,k)); + + +var G__4838 = cljs.core.next(seq__4811__$1); +var G__4839 = null; +var G__4840 = (0); +var G__4841 = (0); +seq__4811 = G__4838; +chunk__4812 = G__4839; +count__4813 = G__4840; +i__4814 = G__4841; +continue; +} +} else { +return null; +} +} +break; +} +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (coll,v){ +var self__ = this; +var coll__$1 = this; +return coll__$1.cljs$core$ILookup$_lookup$arity$3(null,v,null); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (coll,v,not_found){ +var self__ = this; +var coll__$1 = this; +var n = self__.tree_map.entry_at(v); +if((!((n == null)))){ +return n.key; +} else { +return not_found; +} +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IMeta$_meta$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.meta; +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.PersistentTreeSet(self__.meta,self__.tree_map,self__.__hash)); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.count(self__.tree_map); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IReversible$_rseq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((cljs.core.count(self__.tree_map) > (0))){ +return cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.key,cljs.core.rseq(self__.tree_map)); +} else { +return null; +} +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IHash$_hash$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_unordered_coll(coll__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (coll,other){ +var self__ = this; +var coll__$1 = this; +var and__4120__auto__ = cljs.core.set_QMARK_(other); +if(and__4120__auto__){ +var and__4120__auto____$1 = (cljs.core.count(coll__$1) === cljs.core.count(other)); +if(and__4120__auto____$1){ +try{return cljs.core.reduce_kv(((function (and__4120__auto____$1,and__4120__auto__,coll__$1){ +return (function (p1__4809_SHARP_,p2__4808_SHARP_){ +var or__4131__auto__ = cljs.core.contains_QMARK_(other,p2__4808_SHARP_); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return cljs.core.reduced(false); +} +});})(and__4120__auto____$1,and__4120__auto__,coll__$1)) +,true,self__.tree_map); +}catch (e4829){if((e4829 instanceof Error)){ +var ex = e4829; +return false; +} else { +throw e4829; + +} +}} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.PersistentTreeSet(self__.meta,cljs.core._empty(self__.tree_map),(0))); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ISet$_disjoin$arity$2 = (function (coll,v){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.PersistentTreeSet(self__.meta,cljs.core.dissoc.cljs$core$IFn$_invoke$arity$2(self__.tree_map,v),null)); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core.keys(self__.tree_map); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (coll,new_meta){ +var self__ = this; +var coll__$1 = this; +if((new_meta === self__.meta)){ +return coll__$1; +} else { +return (new cljs.core.PersistentTreeSet(new_meta,self__.tree_map,self__.__hash)); +} +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ICollection$_conj$arity$2 = (function (coll,o){ +var self__ = this; +var coll__$1 = this; +return (new cljs.core.PersistentTreeSet(self__.meta,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(self__.tree_map,o,null),null)); +}); + +cljs.core.PersistentTreeSet.prototype.call = (function() { +var G__4842 = null; +var G__4842__2 = (function (self__,k){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); +var G__4842__3 = (function (self__,k,not_found){ +var self__ = this; +var self____$1 = this; +var coll = self____$1; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); +G__4842 = function(self__,k,not_found){ +switch(arguments.length){ +case 2: +return G__4842__2.call(this,self__,k); +case 3: +return G__4842__3.call(this,self__,k,not_found); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__4842.cljs$core$IFn$_invoke$arity$2 = G__4842__2; +G__4842.cljs$core$IFn$_invoke$arity$3 = G__4842__3; +return G__4842; +})() +; + +cljs.core.PersistentTreeSet.prototype.apply = (function (self__,args4810){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args4810))); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$2(null,k); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ +var self__ = this; +var coll = this; +return coll.cljs$core$ILookup$_lookup$arity$3(null,k,not_found); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ISorted$_sorted_seq$arity$2 = (function (coll,ascending_QMARK_){ +var self__ = this; +var coll__$1 = this; +return cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.key,cljs.core._sorted_seq(self__.tree_map,ascending_QMARK_)); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ISorted$_sorted_seq_from$arity$3 = (function (coll,k,ascending_QMARK_){ +var self__ = this; +var coll__$1 = this; +return cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.key,cljs.core._sorted_seq_from(self__.tree_map,k,ascending_QMARK_)); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ISorted$_entry_key$arity$2 = (function (coll,entry){ +var self__ = this; +var coll__$1 = this; +return entry; +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$ISorted$_comparator$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return cljs.core._comparator(self__.tree_map); +}); + +cljs.core.PersistentTreeSet.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$tree_DASH_map,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.PersistentTreeSet.cljs$lang$type = true; + +cljs.core.PersistentTreeSet.cljs$lang$ctorStr = "cljs.core/PersistentTreeSet"; + +cljs.core.PersistentTreeSet.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/PersistentTreeSet"); +}); + +/** + * Positional factory function for cljs.core/PersistentTreeSet. + */ +cljs.core.__GT_PersistentTreeSet = (function cljs$core$__GT_PersistentTreeSet(meta,tree_map,__hash){ +return (new cljs.core.PersistentTreeSet(meta,tree_map,__hash)); +}); + +cljs.core.PersistentTreeSet.EMPTY = (new cljs.core.PersistentTreeSet(null,cljs.core.PersistentTreeMap.EMPTY,cljs.core.empty_unordered_hash)); +var G__4843_4846 = cljs.core.PersistentTreeSet.prototype; +var G__4844_4847 = cljs.core.ITER_SYMBOL; +var G__4845_4848 = ((function (G__4843_4846,G__4844_4847){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4843_4846,G__4844_4847)) +; +goog.object.set(G__4843_4846,G__4844_4847,G__4845_4848); +cljs.core.set_from_indexed_seq = (function cljs$core$set_from_indexed_seq(iseq){ +var arr = iseq.arr; +var ret = (function (){var a__4604__auto__ = arr; +var l__4605__auto__ = a__4604__auto__.length; +var i = (0); +var res = cljs.core._as_transient(cljs.core.PersistentHashSet.EMPTY); +while(true){ +if((i < l__4605__auto__)){ +var G__4849 = (i + (1)); +var G__4850 = cljs.core._conj_BANG_(res,(arr[i])); +i = G__4849; +res = G__4850; +continue; +} else { +return res; +} +break; +} +})(); +return ret.cljs$core$ITransientCollection$_persistent_BANG_$arity$1(null); +}); +/** + * Returns a set of the distinct elements of coll. + */ +cljs.core.set = (function cljs$core$set(coll){ +if(cljs.core.set_QMARK_(coll)){ +return cljs.core.with_meta(coll,null); +} else { +var in$ = cljs.core.seq(coll); +if((in$ == null)){ +return cljs.core.PersistentHashSet.EMPTY; +} else { +if((((in$ instanceof cljs.core.IndexedSeq)) && ((in$.i === (0))))){ +return cljs.core.PersistentHashSet.createAsIfByAssoc(in$.arr); +} else { +var in$__$1 = in$; +var out = cljs.core._as_transient(cljs.core.PersistentHashSet.EMPTY); +while(true){ +if((!((in$__$1 == null)))){ +var G__4851 = cljs.core.next(in$__$1); +var G__4852 = cljs.core._conj_BANG_(out,cljs.core._first(in$__$1)); +in$__$1 = G__4851; +out = G__4852; +continue; +} else { +return cljs.core.persistent_BANG_(out); +} +break; +} + +} +} +} +}); +/** + * Returns a new hash set with supplied keys. Any equal keys are + * handled as if by repeated uses of conj. + */ +cljs.core.hash_set = (function cljs$core$hash_set(var_args){ +var G__4855 = arguments.length; +switch (G__4855) { +case 0: +return cljs.core.hash_set.cljs$core$IFn$_invoke$arity$0(); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4857 = arguments.length; +var i__4731__auto___4858 = (0); +while(true){ +if((i__4731__auto___4858 < len__4730__auto___4857)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___4858])); + +var G__4859 = (i__4731__auto___4858 + (1)); +i__4731__auto___4858 = G__4859; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((0)),(0),null)); +return cljs.core.hash_set.cljs$core$IFn$_invoke$arity$variadic(argseq__4752__auto__); + +} +}); + +cljs.core.hash_set.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.PersistentHashSet.EMPTY; +}); + +cljs.core.hash_set.cljs$core$IFn$_invoke$arity$variadic = (function (keys){ +return cljs.core.set(keys); +}); + +/** @this {Function} */ +cljs.core.hash_set.cljs$lang$applyTo = (function (seq4854){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq4854)); +}); + +cljs.core.hash_set.cljs$lang$maxFixedArity = (0); + +/** + * Returns a new sorted set with supplied keys. + */ +cljs.core.sorted_set = (function cljs$core$sorted_set(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4861 = arguments.length; +var i__4731__auto___4862 = (0); +while(true){ +if((i__4731__auto___4862 < len__4730__auto___4861)){ +args__4736__auto__.push((arguments[i__4731__auto___4862])); + +var G__4863 = (i__4731__auto___4862 + (1)); +i__4731__auto___4862 = G__4863; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.sorted_set.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.sorted_set.cljs$core$IFn$_invoke$arity$variadic = (function (keys){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._conj,cljs.core.PersistentTreeSet.EMPTY,keys); +}); + +cljs.core.sorted_set.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.sorted_set.cljs$lang$applyTo = (function (seq4860){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq4860)); +}); + +/** + * Returns a new sorted set with supplied keys, using the supplied comparator. + */ +cljs.core.sorted_set_by = (function cljs$core$sorted_set_by(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___4866 = arguments.length; +var i__4731__auto___4867 = (0); +while(true){ +if((i__4731__auto___4867 < len__4730__auto___4866)){ +args__4736__auto__.push((arguments[i__4731__auto___4867])); + +var G__4868 = (i__4731__auto___4867 + (1)); +i__4731__auto___4867 = G__4868; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null); +return cljs.core.sorted_set_by.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__); +}); + +cljs.core.sorted_set_by.cljs$core$IFn$_invoke$arity$variadic = (function (comparator,keys){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core._conj,(new cljs.core.PersistentTreeSet(null,cljs.core.sorted_map_by(comparator),(0))),keys); +}); + +cljs.core.sorted_set_by.cljs$lang$maxFixedArity = (1); + +/** @this {Function} */ +cljs.core.sorted_set_by.cljs$lang$applyTo = (function (seq4864){ +var G__4865 = cljs.core.first(seq4864); +var seq4864__$1 = cljs.core.next(seq4864); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4865,seq4864__$1); +}); + +/** + * Given a map of replacement pairs and a vector/collection, returns a + * vector/seq with any elements = a key in smap replaced with the + * corresponding val in smap. Returns a transducer when no collection + * is provided. + */ +cljs.core.replace = (function cljs$core$replace(var_args){ +var G__4872 = arguments.length; +switch (G__4872) { +case 1: +return cljs.core.replace.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.replace.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.replace.cljs$core$IFn$_invoke$arity$1 = (function (smap){ +return cljs.core.map.cljs$core$IFn$_invoke$arity$1((function (p1__4869_SHARP_){ +var temp__5733__auto__ = cljs.core.find(smap,p1__4869_SHARP_); +if(cljs.core.truth_(temp__5733__auto__)){ +var e = temp__5733__auto__; +return cljs.core.val(e); +} else { +return p1__4869_SHARP_; +} +})); +}); + +cljs.core.replace.cljs$core$IFn$_invoke$arity$2 = (function (smap,coll){ +if(cljs.core.vector_QMARK_(coll)){ +var n = cljs.core.count(coll); +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (n){ +return (function (v,i){ +var temp__5733__auto__ = cljs.core.find(smap,cljs.core.nth.cljs$core$IFn$_invoke$arity$2(v,i)); +if(cljs.core.truth_(temp__5733__auto__)){ +var e = temp__5733__auto__; +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(v,i,cljs.core.second(e)); +} else { +return v; +} +});})(n)) +,coll,cljs.core.take.cljs$core$IFn$_invoke$arity$2(n,cljs.core.iterate(cljs.core.inc,(0)))); +} else { +return cljs.core.map.cljs$core$IFn$_invoke$arity$2((function (p1__4870_SHARP_){ +var temp__5733__auto__ = cljs.core.find(smap,p1__4870_SHARP_); +if(cljs.core.truth_(temp__5733__auto__)){ +var e = temp__5733__auto__; +return cljs.core.second(e); +} else { +return p1__4870_SHARP_; +} +}),coll); +} +}); + +cljs.core.replace.cljs$lang$maxFixedArity = 2; + +/** + * Returns a lazy sequence of the elements of coll with duplicates removed. + * Returns a stateful transducer when no collection is provided. + */ +cljs.core.distinct = (function cljs$core$distinct(var_args){ +var G__4875 = arguments.length; +switch (G__4875) { +case 0: +return cljs.core.distinct.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.distinct.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.distinct.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (function (rf){ +var seen = cljs.core.volatile_BANG_(cljs.core.PersistentHashSet.EMPTY); +return ((function (seen){ +return (function() { +var G__4886 = null; +var G__4886__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4886__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__4886__2 = (function (result,input){ +if(cljs.core.contains_QMARK_(cljs.core.deref(seen),input)){ +return result; +} else { +seen.cljs$core$IVolatile$_vreset_BANG_$arity$2(null,cljs.core.conj.cljs$core$IFn$_invoke$arity$2(seen.cljs$core$IDeref$_deref$arity$1(null),input)); + +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} +}); +G__4886 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4886__0.call(this); +case 1: +return G__4886__1.call(this,result); +case 2: +return G__4886__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4886.cljs$core$IFn$_invoke$arity$0 = G__4886__0; +G__4886.cljs$core$IFn$_invoke$arity$1 = G__4886__1; +G__4886.cljs$core$IFn$_invoke$arity$2 = G__4886__2; +return G__4886; +})() +;})(seen)) +}); +}); + +cljs.core.distinct.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +var step = (function cljs$core$step(xs,seen){ +return (new cljs.core.LazySeq(null,(function (){ +var fexpr__4880 = (function (p__4881,seen__$1){ +while(true){ +var vec__4882 = p__4881; +var f = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4882,(0),null); +var xs__$1 = vec__4882; +var temp__5735__auto__ = cljs.core.seq(xs__$1); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +if(cljs.core.contains_QMARK_(seen__$1,f)){ +var G__4887 = cljs.core.rest(s); +var G__4888 = seen__$1; +p__4881 = G__4887; +seen__$1 = G__4888; +continue; +} else { +return cljs.core.cons(f,cljs$core$step(cljs.core.rest(s),cljs.core.conj.cljs$core$IFn$_invoke$arity$2(seen__$1,f))); +} +} else { +return null; +} +break; +} +}); +return fexpr__4880(xs,seen); +}),null,null)); +}); +return step(coll,cljs.core.PersistentHashSet.EMPTY); +}); + +cljs.core.distinct.cljs$lang$maxFixedArity = 1; + +/** + * Return a seq of all but the last item in coll, in linear time + */ +cljs.core.butlast = (function cljs$core$butlast(s){ +var ret = cljs.core.PersistentVector.EMPTY; +var s__$1 = s; +while(true){ +if(cljs.core.next(s__$1)){ +var G__4889 = cljs.core.conj.cljs$core$IFn$_invoke$arity$2(ret,cljs.core.first(s__$1)); +var G__4890 = cljs.core.next(s__$1); +ret = G__4889; +s__$1 = G__4890; +continue; +} else { +return cljs.core.seq(ret); +} +break; +} +}); +/** + * Returns the name String of a string, symbol or keyword. + */ +cljs.core.name = (function cljs$core$name(x){ +if((((!((x == null))))?(((((x.cljs$lang$protocol_mask$partition1$ & (4096))) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$INamed$))))?true:false):false)){ +return cljs.core._name(x); +} else { +if(typeof x === 'string'){ +return x; +} else { +throw (new Error(["Doesn't support name: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x)].join(''))); +} +} +}); +/** + * Returns a map with the keys mapped to the corresponding vals. + */ +cljs.core.zipmap = (function cljs$core$zipmap(keys,vals){ +var map = cljs.core.transient$(cljs.core.PersistentArrayMap.EMPTY); +var ks = cljs.core.seq(keys); +var vs = cljs.core.seq(vals); +while(true){ +if(((ks) && (vs))){ +var G__4892 = cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(map,cljs.core.first(ks),cljs.core.first(vs)); +var G__4893 = cljs.core.next(ks); +var G__4894 = cljs.core.next(vs); +map = G__4892; +ks = G__4893; +vs = G__4894; +continue; +} else { +return cljs.core.persistent_BANG_(map); +} +break; +} +}); +/** + * Returns the x for which (k x), a number, is greatest. + * + * If there are multiple such xs, the last one is returned. + */ +cljs.core.max_key = (function cljs$core$max_key(var_args){ +var G__4902 = arguments.length; +switch (G__4902) { +case 2: +return cljs.core.max_key.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.max_key.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4904 = arguments.length; +var i__4731__auto___4905 = (0); +while(true){ +if((i__4731__auto___4905 < len__4730__auto___4904)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___4905])); + +var G__4906 = (i__4731__auto___4905 + (1)); +i__4731__auto___4905 = G__4906; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.max_key.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.max_key.cljs$core$IFn$_invoke$arity$2 = (function (k,x){ +return x; +}); + +cljs.core.max_key.cljs$core$IFn$_invoke$arity$3 = (function (k,x,y){ +if(((k.cljs$core$IFn$_invoke$arity$1 ? k.cljs$core$IFn$_invoke$arity$1(x) : k.call(null,x)) > (k.cljs$core$IFn$_invoke$arity$1 ? k.cljs$core$IFn$_invoke$arity$1(y) : k.call(null,y)))){ +return x; +} else { +return y; +} +}); + +cljs.core.max_key.cljs$core$IFn$_invoke$arity$variadic = (function (k,x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p1__4895_SHARP_,p2__4896_SHARP_){ +return cljs.core.max_key.cljs$core$IFn$_invoke$arity$3(k,p1__4895_SHARP_,p2__4896_SHARP_); +}),cljs.core.max_key.cljs$core$IFn$_invoke$arity$3(k,x,y),more); +}); + +/** @this {Function} */ +cljs.core.max_key.cljs$lang$applyTo = (function (seq4898){ +var G__4899 = cljs.core.first(seq4898); +var seq4898__$1 = cljs.core.next(seq4898); +var G__4900 = cljs.core.first(seq4898__$1); +var seq4898__$2 = cljs.core.next(seq4898__$1); +var G__4901 = cljs.core.first(seq4898__$2); +var seq4898__$3 = cljs.core.next(seq4898__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4899,G__4900,G__4901,seq4898__$3); +}); + +cljs.core.max_key.cljs$lang$maxFixedArity = (3); + +/** + * Returns the x for which (k x), a number, is least. + * + * If there are multiple such xs, the last one is returned. + */ +cljs.core.min_key = (function cljs$core$min_key(var_args){ +var G__4914 = arguments.length; +switch (G__4914) { +case 2: +return cljs.core.min_key.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.min_key.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4916 = arguments.length; +var i__4731__auto___4917 = (0); +while(true){ +if((i__4731__auto___4917 < len__4730__auto___4916)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___4917])); + +var G__4918 = (i__4731__auto___4917 + (1)); +i__4731__auto___4917 = G__4918; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.min_key.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.min_key.cljs$core$IFn$_invoke$arity$2 = (function (k,x){ +return x; +}); + +cljs.core.min_key.cljs$core$IFn$_invoke$arity$3 = (function (k,x,y){ +if(((k.cljs$core$IFn$_invoke$arity$1 ? k.cljs$core$IFn$_invoke$arity$1(x) : k.call(null,x)) < (k.cljs$core$IFn$_invoke$arity$1 ? k.cljs$core$IFn$_invoke$arity$1(y) : k.call(null,y)))){ +return x; +} else { +return y; +} +}); + +cljs.core.min_key.cljs$core$IFn$_invoke$arity$variadic = (function (k,x,y,more){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p1__4907_SHARP_,p2__4908_SHARP_){ +return cljs.core.min_key.cljs$core$IFn$_invoke$arity$3(k,p1__4907_SHARP_,p2__4908_SHARP_); +}),cljs.core.min_key.cljs$core$IFn$_invoke$arity$3(k,x,y),more); +}); + +/** @this {Function} */ +cljs.core.min_key.cljs$lang$applyTo = (function (seq4910){ +var G__4911 = cljs.core.first(seq4910); +var seq4910__$1 = cljs.core.next(seq4910); +var G__4912 = cljs.core.first(seq4910__$1); +var seq4910__$2 = cljs.core.next(seq4910__$1); +var G__4913 = cljs.core.first(seq4910__$2); +var seq4910__$3 = cljs.core.next(seq4910__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4911,G__4912,G__4913,seq4910__$3); +}); + +cljs.core.min_key.cljs$lang$maxFixedArity = (3); + + +/** +* @constructor +*/ +cljs.core.ArrayList = (function (arr){ +this.arr = arr; +}); +cljs.core.ArrayList.prototype.add = (function (x){ +var self__ = this; +var _ = this; +return self__.arr.push(x); +}); + +cljs.core.ArrayList.prototype.size = (function (){ +var self__ = this; +var _ = this; +return self__.arr.length; +}); + +cljs.core.ArrayList.prototype.clear = (function (){ +var self__ = this; +var _ = this; +return self__.arr = []; +}); + +cljs.core.ArrayList.prototype.isEmpty = (function (){ +var self__ = this; +var _ = this; +return (self__.arr.length === (0)); +}); + +cljs.core.ArrayList.prototype.toArray = (function (){ +var self__ = this; +var _ = this; +return self__.arr; +}); + +cljs.core.ArrayList.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$arr,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.ArrayList.cljs$lang$type = true; + +cljs.core.ArrayList.cljs$lang$ctorStr = "cljs.core/ArrayList"; + +cljs.core.ArrayList.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/ArrayList"); +}); + +/** + * Positional factory function for cljs.core/ArrayList. + */ +cljs.core.__GT_ArrayList = (function cljs$core$__GT_ArrayList(arr){ +return (new cljs.core.ArrayList(arr)); +}); + +cljs.core.array_list = (function cljs$core$array_list(){ +return (new cljs.core.ArrayList([])); +}); +/** + * Returns a lazy sequence of lists like partition, but may include + * partitions with fewer than n items at the end. Returns a stateful + * transducer when no collection is provided. + */ +cljs.core.partition_all = (function cljs$core$partition_all(var_args){ +var G__4920 = arguments.length; +switch (G__4920) { +case 1: +return cljs.core.partition_all.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.partition_all.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.partition_all.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.partition_all.cljs$core$IFn$_invoke$arity$1 = (function (n){ +return (function (rf){ +var a = cljs.core.array_list(); +return ((function (a){ +return (function() { +var G__4922 = null; +var G__4922__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4922__1 = (function (result){ +var result__$1 = (cljs.core.truth_(a.isEmpty())?result:(function (){var v = cljs.core.vec(a.toArray()); +a.clear(); + +return cljs.core.unreduced((rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,v) : rf.call(null,result,v))); +})()); +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result__$1) : rf.call(null,result__$1)); +}); +var G__4922__2 = (function (result,input){ +a.add(input); + +if((n === a.size())){ +var v = cljs.core.vec(a.toArray()); +a.clear(); + +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,v) : rf.call(null,result,v)); +} else { +return result; +} +}); +G__4922 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4922__0.call(this); +case 1: +return G__4922__1.call(this,result); +case 2: +return G__4922__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4922.cljs$core$IFn$_invoke$arity$0 = G__4922__0; +G__4922.cljs$core$IFn$_invoke$arity$1 = G__4922__1; +G__4922.cljs$core$IFn$_invoke$arity$2 = G__4922__2; +return G__4922; +})() +;})(a)) +}); +}); + +cljs.core.partition_all.cljs$core$IFn$_invoke$arity$2 = (function (n,coll){ +return cljs.core.partition_all.cljs$core$IFn$_invoke$arity$3(n,n,coll); +}); + +cljs.core.partition_all.cljs$core$IFn$_invoke$arity$3 = (function (n,step,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +return cljs.core.cons(cljs.core.take.cljs$core$IFn$_invoke$arity$2(n,s),cljs.core.partition_all.cljs$core$IFn$_invoke$arity$3(n,step,cljs.core.drop.cljs$core$IFn$_invoke$arity$2(step,s))); +} else { +return null; +} +}),null,null)); +}); + +cljs.core.partition_all.cljs$lang$maxFixedArity = 3; + +/** + * Returns a lazy sequence of successive items from coll while + * (pred item) returns logical true. pred must be free of side-effects. + * Returns a transducer when no collection is provided. + */ +cljs.core.take_while = (function cljs$core$take_while(var_args){ +var G__4924 = arguments.length; +switch (G__4924) { +case 1: +return cljs.core.take_while.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.take_while.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.take_while.cljs$core$IFn$_invoke$arity$1 = (function (pred){ +return (function (rf){ +return (function() { +var G__4927 = null; +var G__4927__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4927__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__4927__2 = (function (result,input){ +if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(input) : pred.call(null,input)))){ +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} else { +return cljs.core.reduced(result); +} +}); +G__4927 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4927__0.call(this); +case 1: +return G__4927__1.call(this,result); +case 2: +return G__4927__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4927.cljs$core$IFn$_invoke$arity$0 = G__4927__0; +G__4927.cljs$core$IFn$_invoke$arity$1 = G__4927__1; +G__4927.cljs$core$IFn$_invoke$arity$2 = G__4927__2; +return G__4927; +})() +}); +}); + +cljs.core.take_while.cljs$core$IFn$_invoke$arity$2 = (function (pred,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +if(cljs.core.truth_((function (){var G__4925 = cljs.core.first(s); +return (pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(G__4925) : pred.call(null,G__4925)); +})())){ +return cljs.core.cons(cljs.core.first(s),cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(pred,cljs.core.rest(s))); +} else { +return null; +} +} else { +return null; +} +}),null,null)); +}); + +cljs.core.take_while.cljs$lang$maxFixedArity = 2; + +cljs.core.mk_bound_fn = (function cljs$core$mk_bound_fn(sc,test,key){ +return (function (e){ +var comp = cljs.core._comparator(sc); +var G__4928 = (function (){var G__4930 = cljs.core._entry_key(sc,e); +var G__4931 = key; +return (comp.cljs$core$IFn$_invoke$arity$2 ? comp.cljs$core$IFn$_invoke$arity$2(G__4930,G__4931) : comp.call(null,G__4930,G__4931)); +})(); +var G__4929 = (0); +return (test.cljs$core$IFn$_invoke$arity$2 ? test.cljs$core$IFn$_invoke$arity$2(G__4928,G__4929) : test.call(null,G__4928,G__4929)); +}); +}); +/** + * sc must be a sorted collection, test(s) one of <, <=, > or + * >=. Returns a seq of those entries with keys ek for + * which (test (.. sc comparator (compare ek key)) 0) is true + */ +cljs.core.subseq = (function cljs$core$subseq(var_args){ +var G__4933 = arguments.length; +switch (G__4933) { +case 3: +return cljs.core.subseq.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 5: +return cljs.core.subseq.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.subseq.cljs$core$IFn$_invoke$arity$3 = (function (sc,test,key){ +var include = cljs.core.mk_bound_fn(sc,test,key); +if(cljs.core.truth_((function (){var fexpr__4934 = cljs.core.PersistentHashSet.createAsIfByAssoc([cljs.core._GT_,cljs.core._GT__EQ_]); +return (fexpr__4934.cljs$core$IFn$_invoke$arity$1 ? fexpr__4934.cljs$core$IFn$_invoke$arity$1(test) : fexpr__4934.call(null,test)); +})())){ +var temp__5735__auto__ = cljs.core._sorted_seq_from(sc,key,true); +if(cljs.core.truth_(temp__5735__auto__)){ +var vec__4935 = temp__5735__auto__; +var e = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4935,(0),null); +var s = vec__4935; +if(cljs.core.truth_((include.cljs$core$IFn$_invoke$arity$1 ? include.cljs$core$IFn$_invoke$arity$1(e) : include.call(null,e)))){ +return s; +} else { +return cljs.core.next(s); +} +} else { +return null; +} +} else { +return cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(include,cljs.core._sorted_seq(sc,true)); +} +}); + +cljs.core.subseq.cljs$core$IFn$_invoke$arity$5 = (function (sc,start_test,start_key,end_test,end_key){ +var temp__5735__auto__ = cljs.core._sorted_seq_from(sc,start_key,true); +if(cljs.core.truth_(temp__5735__auto__)){ +var vec__4938 = temp__5735__auto__; +var e = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4938,(0),null); +var s = vec__4938; +return cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(cljs.core.mk_bound_fn(sc,end_test,end_key),(cljs.core.truth_((function (){var fexpr__4941 = cljs.core.mk_bound_fn(sc,start_test,start_key); +return (fexpr__4941.cljs$core$IFn$_invoke$arity$1 ? fexpr__4941.cljs$core$IFn$_invoke$arity$1(e) : fexpr__4941.call(null,e)); +})())?s:cljs.core.next(s))); +} else { +return null; +} +}); + +cljs.core.subseq.cljs$lang$maxFixedArity = 5; + +/** + * sc must be a sorted collection, test(s) one of <, <=, > or + * >=. Returns a reverse seq of those entries with keys ek for + * which (test (.. sc comparator (compare ek key)) 0) is true + */ +cljs.core.rsubseq = (function cljs$core$rsubseq(var_args){ +var G__4944 = arguments.length; +switch (G__4944) { +case 3: +return cljs.core.rsubseq.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +case 5: +return cljs.core.rsubseq.cljs$core$IFn$_invoke$arity$5((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),(arguments[(3)]),(arguments[(4)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.rsubseq.cljs$core$IFn$_invoke$arity$3 = (function (sc,test,key){ +var include = cljs.core.mk_bound_fn(sc,test,key); +if(cljs.core.truth_((function (){var fexpr__4945 = cljs.core.PersistentHashSet.createAsIfByAssoc([cljs.core._LT_,cljs.core._LT__EQ_]); +return (fexpr__4945.cljs$core$IFn$_invoke$arity$1 ? fexpr__4945.cljs$core$IFn$_invoke$arity$1(test) : fexpr__4945.call(null,test)); +})())){ +var temp__5735__auto__ = cljs.core._sorted_seq_from(sc,key,false); +if(cljs.core.truth_(temp__5735__auto__)){ +var vec__4946 = temp__5735__auto__; +var e = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4946,(0),null); +var s = vec__4946; +if(cljs.core.truth_((include.cljs$core$IFn$_invoke$arity$1 ? include.cljs$core$IFn$_invoke$arity$1(e) : include.call(null,e)))){ +return s; +} else { +return cljs.core.next(s); +} +} else { +return null; +} +} else { +return cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(include,cljs.core._sorted_seq(sc,false)); +} +}); + +cljs.core.rsubseq.cljs$core$IFn$_invoke$arity$5 = (function (sc,start_test,start_key,end_test,end_key){ +var temp__5735__auto__ = cljs.core._sorted_seq_from(sc,end_key,false); +if(cljs.core.truth_(temp__5735__auto__)){ +var vec__4949 = temp__5735__auto__; +var e = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__4949,(0),null); +var s = vec__4949; +return cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(cljs.core.mk_bound_fn(sc,start_test,start_key),(cljs.core.truth_((function (){var fexpr__4952 = cljs.core.mk_bound_fn(sc,end_test,end_key); +return (fexpr__4952.cljs$core$IFn$_invoke$arity$1 ? fexpr__4952.cljs$core$IFn$_invoke$arity$1(e) : fexpr__4952.call(null,e)); +})())?s:cljs.core.next(s))); +} else { +return null; +} +}); + +cljs.core.rsubseq.cljs$lang$maxFixedArity = 5; + + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.IChunk} +*/ +cljs.core.RangeChunk = (function (start,step,count){ +this.start = start; +this.step = step; +this.count = count; +this.cljs$lang$protocol_mask$partition0$ = 82; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.RangeChunk.prototype.cljs$core$ICounted$_count$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.count; +}); + +cljs.core.RangeChunk.prototype.cljs$core$ISeq$_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +return self__.start; +}); + +cljs.core.RangeChunk.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (coll,i){ +var self__ = this; +var coll__$1 = this; +return (self__.start + (i * self__.step)); +}); + +cljs.core.RangeChunk.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (coll,i,not_found){ +var self__ = this; +var coll__$1 = this; +if((((i >= (0))) && ((i < self__.count)))){ +return (self__.start + (i * self__.step)); +} else { +return not_found; +} +}); + +cljs.core.RangeChunk.prototype.cljs$core$IChunk$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.RangeChunk.prototype.cljs$core$IChunk$_drop_first$arity$1 = (function (coll){ +var self__ = this; +var coll__$1 = this; +if((self__.count <= (1))){ +throw (new Error("-drop-first of empty chunk")); +} else { +return (new cljs.core.RangeChunk((self__.start + self__.step),self__.step,(self__.count - (1)))); +} +}); + +cljs.core.RangeChunk.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$start,cljs.core.cst$sym$step,cljs.core.cst$sym$count], null); +}); + +cljs.core.RangeChunk.cljs$lang$type = true; + +cljs.core.RangeChunk.cljs$lang$ctorStr = "cljs.core/RangeChunk"; + +cljs.core.RangeChunk.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/RangeChunk"); +}); + +/** + * Positional factory function for cljs.core/RangeChunk. + */ +cljs.core.__GT_RangeChunk = (function cljs$core$__GT_RangeChunk(start,step,count){ +return (new cljs.core.RangeChunk(start,step,count)); +}); + + +/** +* @constructor +*/ +cljs.core.RangeIterator = (function (i,end,step){ +this.i = i; +this.end = end; +this.step = step; +}); +cljs.core.RangeIterator.prototype.hasNext = (function (){ +var self__ = this; +var _ = this; +if((self__.step > (0))){ +return (self__.i < self__.end); +} else { +return (self__.i > self__.end); +} +}); + +cljs.core.RangeIterator.prototype.next = (function (){ +var self__ = this; +var _ = this; +var ret = self__.i; +self__.i = (self__.i + self__.step); + +return ret; +}); + +cljs.core.RangeIterator.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$i,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.cst$sym$end,cljs.core.cst$sym$step], null); +}); + +cljs.core.RangeIterator.cljs$lang$type = true; + +cljs.core.RangeIterator.cljs$lang$ctorStr = "cljs.core/RangeIterator"; + +cljs.core.RangeIterator.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/RangeIterator"); +}); + +/** + * Positional factory function for cljs.core/RangeIterator. + */ +cljs.core.__GT_RangeIterator = (function cljs$core$__GT_RangeIterator(i,end,step){ +return (new cljs.core.RangeIterator(i,end,step)); +}); + + +/** +* @constructor + * @implements {cljs.core.IIndexed} + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.ICollection} + * @implements {cljs.core.IChunkedNext} + * @implements {cljs.core.IEmptyableCollection} + * @implements {cljs.core.ICounted} + * @implements {cljs.core.ISeq} + * @implements {cljs.core.INext} + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IMeta} + * @implements {cljs.core.ICloneable} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.IChunkedSeq} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IWithMeta} + * @implements {cljs.core.IReduce} +*/ +cljs.core.Range = (function (meta,start,end,step,chunk,chunk_next,__hash){ +this.meta = meta; +this.start = start; +this.end = end; +this.step = step; +this.chunk = chunk; +this.chunk_next = chunk_next; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 32375006; +this.cljs$lang$protocol_mask$partition1$ = 140800; +}); +cljs.core.Range.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.Range.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.Range.prototype.indexOf = (function() { +var G__4955 = null; +var G__4955__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,(0)); +}); +var G__4955__2 = (function (x,start__$1){ +var self__ = this; +var coll = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start__$1); +}); +G__4955 = function(x,start__$1){ +switch(arguments.length){ +case 1: +return G__4955__1.call(this,x); +case 2: +return G__4955__2.call(this,x,start__$1); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4955.cljs$core$IFn$_invoke$arity$1 = G__4955__1; +G__4955.cljs$core$IFn$_invoke$arity$2 = G__4955__2; +return G__4955; +})() +; + +cljs.core.Range.prototype.lastIndexOf = (function() { +var G__4956 = null; +var G__4956__1 = (function (x){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,cljs.core.count(coll)); +}); +var G__4956__2 = (function (x,start__$1){ +var self__ = this; +var coll = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll,x,start__$1); +}); +G__4956 = function(x,start__$1){ +switch(arguments.length){ +case 1: +return G__4956__1.call(this,x); +case 2: +return G__4956__2.call(this,x,start__$1); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4956.cljs$core$IFn$_invoke$arity$1 = G__4956__1; +G__4956.cljs$core$IFn$_invoke$arity$2 = G__4956__2; +return G__4956; +})() +; + +cljs.core.Range.prototype.forceChunk = (function (){ +var self__ = this; +var coll = this; +if((self__.chunk == null)){ +var count = coll.cljs$core$ICounted$_count$arity$1(null); +if((count > (32))){ +self__.chunk_next = (new cljs.core.Range(null,(self__.start + (self__.step * (32))),self__.end,self__.step,null,null,null)); + +return self__.chunk = (new cljs.core.RangeChunk(self__.start,self__.step,(32))); +} else { +return self__.chunk = (new cljs.core.RangeChunk(self__.start,self__.step,count)); +} +} else { +return null; +} +}); + +cljs.core.Range.prototype.cljs$core$IIndexed$_nth$arity$2 = (function (rng,n){ +var self__ = this; +var rng__$1 = this; +if(((((0) <= n)) && ((n < rng__$1.cljs$core$ICounted$_count$arity$1(null))))){ +return (self__.start + (n * self__.step)); +} else { +if(((((0) <= n)) && ((self__.start > self__.end)) && ((self__.step === (0))))){ +return self__.start; +} else { +throw (new Error("Index out of bounds")); +} +} +}); + +cljs.core.Range.prototype.cljs$core$IIndexed$_nth$arity$3 = (function (rng,n,not_found){ +var self__ = this; +var rng__$1 = this; +if(((((0) <= n)) && ((n < rng__$1.cljs$core$ICounted$_count$arity$1(null))))){ +return (self__.start + (n * self__.step)); +} else { +if(((((0) <= n)) && ((self__.start > self__.end)) && ((self__.step === (0))))){ +return self__.start; +} else { +return not_found; +} +} +}); + +cljs.core.Range.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.RangeIterator(self__.start,self__.end,self__.step)); +}); + +cljs.core.Range.prototype.cljs$core$IMeta$_meta$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +return self__.meta; +}); + +cljs.core.Range.prototype.cljs$core$ICloneable$_clone$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return (new cljs.core.Range(self__.meta,self__.start,self__.end,self__.step,self__.chunk,self__.chunk_next,self__.__hash)); +}); + +cljs.core.Range.prototype.cljs$core$INext$_next$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +if((self__.step > (0))){ +if(((self__.start + self__.step) < self__.end)){ +return (new cljs.core.Range(null,(self__.start + self__.step),self__.end,self__.step,null,null,null)); +} else { +return null; +} +} else { +if(((self__.start + self__.step) > self__.end)){ +return (new cljs.core.Range(null,(self__.start + self__.step),self__.end,self__.step,null,null,null)); +} else { +return null; +} +} +}); + +cljs.core.Range.prototype.cljs$core$ICounted$_count$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +var G__4954 = ((self__.end - self__.start) / self__.step); +return Math.ceil(G__4954); +}); + +cljs.core.Range.prototype.cljs$core$IHash$_hash$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +var h__4243__auto__ = self__.__hash; +if((!((h__4243__auto__ == null)))){ +return h__4243__auto__; +} else { +var h__4243__auto____$1 = cljs.core.hash_ordered_coll(rng__$1); +self__.__hash = h__4243__auto____$1; + +return h__4243__auto____$1; +} +}); + +cljs.core.Range.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (rng,other){ +var self__ = this; +var rng__$1 = this; +return cljs.core.equiv_sequential(rng__$1,other); +}); + +cljs.core.Range.prototype.cljs$core$IEmptyableCollection$_empty$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +return cljs.core.List.EMPTY; +}); + +cljs.core.Range.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (rng,f){ +var self__ = this; +var rng__$1 = this; +return cljs.core.ci_reduce.cljs$core$IFn$_invoke$arity$2(rng__$1,f); +}); + +cljs.core.Range.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (rng,f,init){ +var self__ = this; +var rng__$1 = this; +var i = self__.start; +var ret = init; +while(true){ +if((((self__.step > (0)))?(i < self__.end):(i > self__.end))){ +var ret__$1 = (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(ret,i) : f.call(null,ret,i)); +if(cljs.core.reduced_QMARK_(ret__$1)){ +return cljs.core.deref(ret__$1); +} else { +var G__4957 = (i + self__.step); +var G__4958 = ret__$1; +i = G__4957; +ret = G__4958; +continue; +} +} else { +return ret; +} +break; +} +}); + +cljs.core.Range.prototype.cljs$core$ISeq$_first$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +return self__.start; +}); + +cljs.core.Range.prototype.cljs$core$ISeq$_rest$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +var s = rng__$1.cljs$core$INext$_next$arity$1(null); +if((s == null)){ +return cljs.core.List.EMPTY; +} else { +return s; +} +}); + +cljs.core.Range.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +return rng__$1; +}); + +cljs.core.Range.prototype.cljs$core$IChunkedSeq$_chunked_first$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +rng__$1.forceChunk(); + +return self__.chunk; +}); + +cljs.core.Range.prototype.cljs$core$IChunkedSeq$_chunked_rest$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +rng__$1.forceChunk(); + +if((self__.chunk_next == null)){ +return cljs.core.List.EMPTY; +} else { +return self__.chunk_next; +} +}); + +cljs.core.Range.prototype.cljs$core$IWithMeta$_with_meta$arity$2 = (function (rng,new_meta){ +var self__ = this; +var rng__$1 = this; +if((new_meta === self__.meta)){ +return rng__$1; +} else { +return (new cljs.core.Range(new_meta,self__.start,self__.end,self__.step,self__.chunk,self__.chunk_next,self__.__hash)); +} +}); + +cljs.core.Range.prototype.cljs$core$ICollection$_conj$arity$2 = (function (rng,o){ +var self__ = this; +var rng__$1 = this; +return cljs.core.cons(o,rng__$1); +}); + +cljs.core.Range.prototype.cljs$core$IChunkedNext$_chunked_next$arity$1 = (function (rng){ +var self__ = this; +var rng__$1 = this; +return cljs.core.seq(rng__$1.cljs$core$IChunkedSeq$_chunked_rest$arity$1(null)); +}); + +cljs.core.Range.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 7, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$meta,cljs.core.cst$sym$start,cljs.core.cst$sym$end,cljs.core.cst$sym$step,cljs.core.with_meta(cljs.core.cst$sym$chunk,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$chunk_DASH_next,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Range.cljs$lang$type = true; + +cljs.core.Range.cljs$lang$ctorStr = "cljs.core/Range"; + +cljs.core.Range.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Range"); +}); + +/** + * Positional factory function for cljs.core/Range. + */ +cljs.core.__GT_Range = (function cljs$core$__GT_Range(meta,start,end,step,chunk,chunk_next,__hash){ +return (new cljs.core.Range(meta,start,end,step,chunk,chunk_next,__hash)); +}); + +var G__4959_4962 = cljs.core.Range.prototype; +var G__4960_4963 = cljs.core.ITER_SYMBOL; +var G__4961_4964 = ((function (G__4959_4962,G__4960_4963){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__4959_4962,G__4960_4963)) +; +goog.object.set(G__4959_4962,G__4960_4963,G__4961_4964); +/** + * Returns a lazy seq of nums from start (inclusive) to end + * (exclusive), by step, where start defaults to 0, step to 1, + * and end to infinity. + */ +cljs.core.range = (function cljs$core$range(var_args){ +var G__4966 = arguments.length; +switch (G__4966) { +case 0: +return cljs.core.range.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.range.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.range.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.range.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.range.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.range.cljs$core$IFn$_invoke$arity$3((0),Number.MAX_VALUE,(1)); +}); + +cljs.core.range.cljs$core$IFn$_invoke$arity$1 = (function (end){ +return cljs.core.range.cljs$core$IFn$_invoke$arity$3((0),end,(1)); +}); + +cljs.core.range.cljs$core$IFn$_invoke$arity$2 = (function (start,end){ +return cljs.core.range.cljs$core$IFn$_invoke$arity$3(start,end,(1)); +}); + +cljs.core.range.cljs$core$IFn$_invoke$arity$3 = (function (start,end,step){ +if((step > (0))){ +if((end <= start)){ +return cljs.core.List.EMPTY; +} else { +return (new cljs.core.Range(null,start,end,step,null,null,null)); +} +} else { +if((step < (0))){ +if((end >= start)){ +return cljs.core.List.EMPTY; +} else { +return (new cljs.core.Range(null,start,end,step,null,null,null)); +} +} else { +if((end === start)){ +return cljs.core.List.EMPTY; +} else { +return cljs.core.repeat.cljs$core$IFn$_invoke$arity$1(start); +} + +} +} +}); + +cljs.core.range.cljs$lang$maxFixedArity = 3; + +/** + * Returns a lazy seq of every nth item in coll. Returns a stateful + * transducer when no collection is provided. + */ +cljs.core.take_nth = (function cljs$core$take_nth(var_args){ +var G__4969 = arguments.length; +switch (G__4969) { +case 1: +return cljs.core.take_nth.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.take_nth.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.take_nth.cljs$core$IFn$_invoke$arity$1 = (function (n){ +if(typeof n === 'number'){ +} else { +throw (new Error("Assert failed: (number? n)")); +} + +return (function (rf){ +var ia = cljs.core.volatile_BANG_((-1)); +return ((function (ia){ +return (function() { +var G__4971 = null; +var G__4971__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4971__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__4971__2 = (function (result,input){ +var i = ia.cljs$core$IVolatile$_vreset_BANG_$arity$2(null,(ia.cljs$core$IDeref$_deref$arity$1(null) + (1))); +if((cljs.core.rem(i,n) === (0))){ +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} else { +return result; +} +}); +G__4971 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4971__0.call(this); +case 1: +return G__4971__1.call(this,result); +case 2: +return G__4971__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4971.cljs$core$IFn$_invoke$arity$0 = G__4971__0; +G__4971.cljs$core$IFn$_invoke$arity$1 = G__4971__1; +G__4971.cljs$core$IFn$_invoke$arity$2 = G__4971__2; +return G__4971; +})() +;})(ia)) +}); +}); + +cljs.core.take_nth.cljs$core$IFn$_invoke$arity$2 = (function (n,coll){ +if(typeof n === 'number'){ +} else { +throw (new Error("Assert failed: (number? n)")); +} + +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +return cljs.core.cons(cljs.core.first(s),cljs.core.take_nth.cljs$core$IFn$_invoke$arity$2(n,cljs.core.drop.cljs$core$IFn$_invoke$arity$2(n,s))); +} else { +return null; +} +}),null,null)); +}); + +cljs.core.take_nth.cljs$lang$maxFixedArity = 2; + +/** + * Returns a vector of [(take-while pred coll) (drop-while pred coll)] + */ +cljs.core.split_with = (function cljs$core$split_with(pred,coll){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(pred,coll),cljs.core.drop_while.cljs$core$IFn$_invoke$arity$2(pred,coll)], null); +}); +/** + * Applies f to each value in coll, splitting it each time f returns a + * new value. Returns a lazy seq of partitions. Returns a stateful + * transducer when no collection is provided. + */ +cljs.core.partition_by = (function cljs$core$partition_by(var_args){ +var G__4974 = arguments.length; +switch (G__4974) { +case 1: +return cljs.core.partition_by.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.partition_by.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.partition_by.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return (function (rf){ +var a = cljs.core.array_list(); +var pa = cljs.core.volatile_BANG_(cljs.core.cst$kw$cljs$core_SLASH_none); +return ((function (a,pa){ +return (function() { +var G__4976 = null; +var G__4976__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__4976__1 = (function (result){ +var result__$1 = (cljs.core.truth_(a.isEmpty())?result:(function (){var v = cljs.core.vec(a.toArray()); +a.clear(); + +return cljs.core.unreduced((rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,v) : rf.call(null,result,v))); +})()); +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result__$1) : rf.call(null,result__$1)); +}); +var G__4976__2 = (function (result,input){ +var pval = cljs.core.deref(pa); +var val = (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(input) : f.call(null,input)); +cljs.core.vreset_BANG_(pa,val); + +if(((cljs.core.keyword_identical_QMARK_(pval,cljs.core.cst$kw$cljs$core_SLASH_none)) || (cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(val,pval)))){ +a.add(input); + +return result; +} else { +var v = cljs.core.vec(a.toArray()); +a.clear(); + +var ret = (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,v) : rf.call(null,result,v)); +if(cljs.core.reduced_QMARK_(ret)){ +} else { +a.add(input); +} + +return ret; +} +}); +G__4976 = function(result,input){ +switch(arguments.length){ +case 0: +return G__4976__0.call(this); +case 1: +return G__4976__1.call(this,result); +case 2: +return G__4976__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__4976.cljs$core$IFn$_invoke$arity$0 = G__4976__0; +G__4976.cljs$core$IFn$_invoke$arity$1 = G__4976__1; +G__4976.cljs$core$IFn$_invoke$arity$2 = G__4976__2; +return G__4976; +})() +;})(a,pa)) +}); +}); + +cljs.core.partition_by.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +var fst = cljs.core.first(s); +var fv = (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(fst) : f.call(null,fst)); +var run = cljs.core.cons(fst,cljs.core.take_while.cljs$core$IFn$_invoke$arity$2(((function (fst,fv,s,temp__5735__auto__){ +return (function (p1__4972_SHARP_){ +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(fv,(f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(p1__4972_SHARP_) : f.call(null,p1__4972_SHARP_))); +});})(fst,fv,s,temp__5735__auto__)) +,cljs.core.next(s))); +return cljs.core.cons(run,cljs.core.partition_by.cljs$core$IFn$_invoke$arity$2(f,(new cljs.core.LazySeq(null,((function (fst,fv,run,s,temp__5735__auto__){ +return (function (){ +return cljs.core.drop.cljs$core$IFn$_invoke$arity$2(cljs.core.count(run),s); +});})(fst,fv,run,s,temp__5735__auto__)) +,null,null)))); +} else { +return null; +} +}),null,null)); +}); + +cljs.core.partition_by.cljs$lang$maxFixedArity = 2; + +/** + * Returns a map from distinct items in coll to the number of times + * they appear. + */ +cljs.core.frequencies = (function cljs$core$frequencies(coll){ +return cljs.core.persistent_BANG_(cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (counts,x){ +return cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(counts,x,(cljs.core.get.cljs$core$IFn$_invoke$arity$3(counts,x,(0)) + (1))); +}),cljs.core.transient$(cljs.core.PersistentArrayMap.EMPTY),coll)); +}); +/** + * Returns a lazy seq of the intermediate values of the reduction (as + * per reduce) of coll by f, starting with init. + */ +cljs.core.reductions = (function cljs$core$reductions(var_args){ +var G__4978 = arguments.length; +switch (G__4978) { +case 2: +return cljs.core.reductions.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.reductions.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.reductions.cljs$core$IFn$_invoke$arity$2 = (function (f,coll){ +return (new cljs.core.LazySeq(null,(function (){ +var temp__5733__auto__ = cljs.core.seq(coll); +if(temp__5733__auto__){ +var s = temp__5733__auto__; +return cljs.core.reductions.cljs$core$IFn$_invoke$arity$3(f,cljs.core.first(s),cljs.core.rest(s)); +} else { +return (new cljs.core.List(null,(f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)),null,(1),null)); +} +}),null,null)); +}); + +cljs.core.reductions.cljs$core$IFn$_invoke$arity$3 = (function (f,init,coll){ +if(cljs.core.reduced_QMARK_(init)){ +return (new cljs.core.List(null,cljs.core.deref(init),null,(1),null)); +} else { +return cljs.core.cons(init,(new cljs.core.LazySeq(null,(function (){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +return cljs.core.reductions.cljs$core$IFn$_invoke$arity$3(f,(function (){var G__4979 = init; +var G__4980 = cljs.core.first(s); +return (f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(G__4979,G__4980) : f.call(null,G__4979,G__4980)); +})(),cljs.core.rest(s)); +} else { +return null; +} +}),null,null))); +} +}); + +cljs.core.reductions.cljs$lang$maxFixedArity = 3; + +/** + * Takes a set of functions and returns a fn that is the juxtaposition + * of those fns. The returned fn takes a variable number of args, and + * returns a vector containing the result of applying each fn to the + * args (left-to-right). + * ((juxt a b c) x) => [(a x) (b x) (c x)] + */ +cljs.core.juxt = (function cljs$core$juxt(var_args){ +var G__4997 = arguments.length; +switch (G__4997) { +case 1: +return cljs.core.juxt.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.juxt.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.juxt.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___4999 = arguments.length; +var i__4731__auto___5000 = (0); +while(true){ +if((i__4731__auto___5000 < len__4730__auto___4999)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___5000])); + +var G__5001 = (i__4731__auto___5000 + (1)); +i__4731__auto___5000 = G__5001; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((3)),(0),null)); +return cljs.core.juxt.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),(arguments[(2)]),argseq__4752__auto__); + +} +}); + +cljs.core.juxt.cljs$core$IFn$_invoke$arity$1 = (function (f){ +return (function() { +var G__5002 = null; +var G__5002__0 = (function (){ +return (new cljs.core.PersistentVector(null,1,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null))],null)); +}); +var G__5002__1 = (function (x){ +return (new cljs.core.PersistentVector(null,1,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(x) : f.call(null,x))],null)); +}); +var G__5002__2 = (function (x,y){ +return (new cljs.core.PersistentVector(null,1,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(x,y) : f.call(null,x,y))],null)); +}); +var G__5002__3 = (function (x,y,z){ +return (new cljs.core.PersistentVector(null,1,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(x,y,z) : f.call(null,x,y,z))],null)); +}); +var G__5002__4 = (function() { +var G__5003__delegate = function (x,y,z,args){ +return (new cljs.core.PersistentVector(null,1,(5),cljs.core.PersistentVector.EMPTY_NODE,[cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,x,y,z,args)],null)); +}; +var G__5003 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__5004__i = 0, G__5004__a = new Array(arguments.length - 3); +while (G__5004__i < G__5004__a.length) {G__5004__a[G__5004__i] = arguments[G__5004__i + 3]; ++G__5004__i;} + args = new cljs.core.IndexedSeq(G__5004__a,0,null); +} +return G__5003__delegate.call(this,x,y,z,args);}; +G__5003.cljs$lang$maxFixedArity = 3; +G__5003.cljs$lang$applyTo = (function (arglist__5005){ +var x = cljs.core.first(arglist__5005); +arglist__5005 = cljs.core.next(arglist__5005); +var y = cljs.core.first(arglist__5005); +arglist__5005 = cljs.core.next(arglist__5005); +var z = cljs.core.first(arglist__5005); +var args = cljs.core.rest(arglist__5005); +return G__5003__delegate(x,y,z,args); +}); +G__5003.cljs$core$IFn$_invoke$arity$variadic = G__5003__delegate; +return G__5003; +})() +; +G__5002 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__5002__0.call(this); +case 1: +return G__5002__1.call(this,x); +case 2: +return G__5002__2.call(this,x,y); +case 3: +return G__5002__3.call(this,x,y,z); +default: +var G__5006 = null; +if (arguments.length > 3) { +var G__5007__i = 0, G__5007__a = new Array(arguments.length - 3); +while (G__5007__i < G__5007__a.length) {G__5007__a[G__5007__i] = arguments[G__5007__i + 3]; ++G__5007__i;} +G__5006 = new cljs.core.IndexedSeq(G__5007__a,0,null); +} +return G__5002__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__5006); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5002.cljs$lang$maxFixedArity = 3; +G__5002.cljs$lang$applyTo = G__5002__4.cljs$lang$applyTo; +G__5002.cljs$core$IFn$_invoke$arity$0 = G__5002__0; +G__5002.cljs$core$IFn$_invoke$arity$1 = G__5002__1; +G__5002.cljs$core$IFn$_invoke$arity$2 = G__5002__2; +G__5002.cljs$core$IFn$_invoke$arity$3 = G__5002__3; +G__5002.cljs$core$IFn$_invoke$arity$variadic = G__5002__4.cljs$core$IFn$_invoke$arity$variadic; +return G__5002; +})() +}); + +cljs.core.juxt.cljs$core$IFn$_invoke$arity$2 = (function (f,g){ +return (function() { +var G__5008 = null; +var G__5008__0 = (function (){ +return (new cljs.core.PersistentVector(null,2,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)),(g.cljs$core$IFn$_invoke$arity$0 ? g.cljs$core$IFn$_invoke$arity$0() : g.call(null))],null)); +}); +var G__5008__1 = (function (x){ +return (new cljs.core.PersistentVector(null,2,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(x) : f.call(null,x)),(g.cljs$core$IFn$_invoke$arity$1 ? g.cljs$core$IFn$_invoke$arity$1(x) : g.call(null,x))],null)); +}); +var G__5008__2 = (function (x,y){ +return (new cljs.core.PersistentVector(null,2,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(x,y) : f.call(null,x,y)),(g.cljs$core$IFn$_invoke$arity$2 ? g.cljs$core$IFn$_invoke$arity$2(x,y) : g.call(null,x,y))],null)); +}); +var G__5008__3 = (function (x,y,z){ +return (new cljs.core.PersistentVector(null,2,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(x,y,z) : f.call(null,x,y,z)),(g.cljs$core$IFn$_invoke$arity$3 ? g.cljs$core$IFn$_invoke$arity$3(x,y,z) : g.call(null,x,y,z))],null)); +}); +var G__5008__4 = (function() { +var G__5009__delegate = function (x,y,z,args){ +return (new cljs.core.PersistentVector(null,2,(5),cljs.core.PersistentVector.EMPTY_NODE,[cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,x,y,z,args),cljs.core.apply.cljs$core$IFn$_invoke$arity$5(g,x,y,z,args)],null)); +}; +var G__5009 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__5010__i = 0, G__5010__a = new Array(arguments.length - 3); +while (G__5010__i < G__5010__a.length) {G__5010__a[G__5010__i] = arguments[G__5010__i + 3]; ++G__5010__i;} + args = new cljs.core.IndexedSeq(G__5010__a,0,null); +} +return G__5009__delegate.call(this,x,y,z,args);}; +G__5009.cljs$lang$maxFixedArity = 3; +G__5009.cljs$lang$applyTo = (function (arglist__5011){ +var x = cljs.core.first(arglist__5011); +arglist__5011 = cljs.core.next(arglist__5011); +var y = cljs.core.first(arglist__5011); +arglist__5011 = cljs.core.next(arglist__5011); +var z = cljs.core.first(arglist__5011); +var args = cljs.core.rest(arglist__5011); +return G__5009__delegate(x,y,z,args); +}); +G__5009.cljs$core$IFn$_invoke$arity$variadic = G__5009__delegate; +return G__5009; +})() +; +G__5008 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__5008__0.call(this); +case 1: +return G__5008__1.call(this,x); +case 2: +return G__5008__2.call(this,x,y); +case 3: +return G__5008__3.call(this,x,y,z); +default: +var G__5012 = null; +if (arguments.length > 3) { +var G__5013__i = 0, G__5013__a = new Array(arguments.length - 3); +while (G__5013__i < G__5013__a.length) {G__5013__a[G__5013__i] = arguments[G__5013__i + 3]; ++G__5013__i;} +G__5012 = new cljs.core.IndexedSeq(G__5013__a,0,null); +} +return G__5008__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__5012); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5008.cljs$lang$maxFixedArity = 3; +G__5008.cljs$lang$applyTo = G__5008__4.cljs$lang$applyTo; +G__5008.cljs$core$IFn$_invoke$arity$0 = G__5008__0; +G__5008.cljs$core$IFn$_invoke$arity$1 = G__5008__1; +G__5008.cljs$core$IFn$_invoke$arity$2 = G__5008__2; +G__5008.cljs$core$IFn$_invoke$arity$3 = G__5008__3; +G__5008.cljs$core$IFn$_invoke$arity$variadic = G__5008__4.cljs$core$IFn$_invoke$arity$variadic; +return G__5008; +})() +}); + +cljs.core.juxt.cljs$core$IFn$_invoke$arity$3 = (function (f,g,h){ +return (function() { +var G__5014 = null; +var G__5014__0 = (function (){ +return (new cljs.core.PersistentVector(null,3,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)),(g.cljs$core$IFn$_invoke$arity$0 ? g.cljs$core$IFn$_invoke$arity$0() : g.call(null)),(h.cljs$core$IFn$_invoke$arity$0 ? h.cljs$core$IFn$_invoke$arity$0() : h.call(null))],null)); +}); +var G__5014__1 = (function (x){ +return (new cljs.core.PersistentVector(null,3,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(x) : f.call(null,x)),(g.cljs$core$IFn$_invoke$arity$1 ? g.cljs$core$IFn$_invoke$arity$1(x) : g.call(null,x)),(h.cljs$core$IFn$_invoke$arity$1 ? h.cljs$core$IFn$_invoke$arity$1(x) : h.call(null,x))],null)); +}); +var G__5014__2 = (function (x,y){ +return (new cljs.core.PersistentVector(null,3,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$2 ? f.cljs$core$IFn$_invoke$arity$2(x,y) : f.call(null,x,y)),(g.cljs$core$IFn$_invoke$arity$2 ? g.cljs$core$IFn$_invoke$arity$2(x,y) : g.call(null,x,y)),(h.cljs$core$IFn$_invoke$arity$2 ? h.cljs$core$IFn$_invoke$arity$2(x,y) : h.call(null,x,y))],null)); +}); +var G__5014__3 = (function (x,y,z){ +return (new cljs.core.PersistentVector(null,3,(5),cljs.core.PersistentVector.EMPTY_NODE,[(f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(x,y,z) : f.call(null,x,y,z)),(g.cljs$core$IFn$_invoke$arity$3 ? g.cljs$core$IFn$_invoke$arity$3(x,y,z) : g.call(null,x,y,z)),(h.cljs$core$IFn$_invoke$arity$3 ? h.cljs$core$IFn$_invoke$arity$3(x,y,z) : h.call(null,x,y,z))],null)); +}); +var G__5014__4 = (function() { +var G__5015__delegate = function (x,y,z,args){ +return (new cljs.core.PersistentVector(null,3,(5),cljs.core.PersistentVector.EMPTY_NODE,[cljs.core.apply.cljs$core$IFn$_invoke$arity$5(f,x,y,z,args),cljs.core.apply.cljs$core$IFn$_invoke$arity$5(g,x,y,z,args),cljs.core.apply.cljs$core$IFn$_invoke$arity$5(h,x,y,z,args)],null)); +}; +var G__5015 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__5016__i = 0, G__5016__a = new Array(arguments.length - 3); +while (G__5016__i < G__5016__a.length) {G__5016__a[G__5016__i] = arguments[G__5016__i + 3]; ++G__5016__i;} + args = new cljs.core.IndexedSeq(G__5016__a,0,null); +} +return G__5015__delegate.call(this,x,y,z,args);}; +G__5015.cljs$lang$maxFixedArity = 3; +G__5015.cljs$lang$applyTo = (function (arglist__5017){ +var x = cljs.core.first(arglist__5017); +arglist__5017 = cljs.core.next(arglist__5017); +var y = cljs.core.first(arglist__5017); +arglist__5017 = cljs.core.next(arglist__5017); +var z = cljs.core.first(arglist__5017); +var args = cljs.core.rest(arglist__5017); +return G__5015__delegate(x,y,z,args); +}); +G__5015.cljs$core$IFn$_invoke$arity$variadic = G__5015__delegate; +return G__5015; +})() +; +G__5014 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__5014__0.call(this); +case 1: +return G__5014__1.call(this,x); +case 2: +return G__5014__2.call(this,x,y); +case 3: +return G__5014__3.call(this,x,y,z); +default: +var G__5018 = null; +if (arguments.length > 3) { +var G__5019__i = 0, G__5019__a = new Array(arguments.length - 3); +while (G__5019__i < G__5019__a.length) {G__5019__a[G__5019__i] = arguments[G__5019__i + 3]; ++G__5019__i;} +G__5018 = new cljs.core.IndexedSeq(G__5019__a,0,null); +} +return G__5014__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__5018); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5014.cljs$lang$maxFixedArity = 3; +G__5014.cljs$lang$applyTo = G__5014__4.cljs$lang$applyTo; +G__5014.cljs$core$IFn$_invoke$arity$0 = G__5014__0; +G__5014.cljs$core$IFn$_invoke$arity$1 = G__5014__1; +G__5014.cljs$core$IFn$_invoke$arity$2 = G__5014__2; +G__5014.cljs$core$IFn$_invoke$arity$3 = G__5014__3; +G__5014.cljs$core$IFn$_invoke$arity$variadic = G__5014__4.cljs$core$IFn$_invoke$arity$variadic; +return G__5014; +})() +}); + +cljs.core.juxt.cljs$core$IFn$_invoke$arity$variadic = (function (f,g,h,fs){ +var fs__$1 = cljs.core.list_STAR_.cljs$core$IFn$_invoke$arity$4(f,g,h,fs); +return ((function (fs__$1){ +return (function() { +var G__5020 = null; +var G__5020__0 = (function (){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (fs__$1){ +return (function (p1__4982_SHARP_,p2__4983_SHARP_){ +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(p1__4982_SHARP_,(p2__4983_SHARP_.cljs$core$IFn$_invoke$arity$0 ? p2__4983_SHARP_.cljs$core$IFn$_invoke$arity$0() : p2__4983_SHARP_.call(null))); +});})(fs__$1)) +,cljs.core.PersistentVector.EMPTY,fs__$1); +}); +var G__5020__1 = (function (x){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (fs__$1){ +return (function (p1__4984_SHARP_,p2__4985_SHARP_){ +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(p1__4984_SHARP_,(p2__4985_SHARP_.cljs$core$IFn$_invoke$arity$1 ? p2__4985_SHARP_.cljs$core$IFn$_invoke$arity$1(x) : p2__4985_SHARP_.call(null,x))); +});})(fs__$1)) +,cljs.core.PersistentVector.EMPTY,fs__$1); +}); +var G__5020__2 = (function (x,y){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (fs__$1){ +return (function (p1__4986_SHARP_,p2__4987_SHARP_){ +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(p1__4986_SHARP_,(p2__4987_SHARP_.cljs$core$IFn$_invoke$arity$2 ? p2__4987_SHARP_.cljs$core$IFn$_invoke$arity$2(x,y) : p2__4987_SHARP_.call(null,x,y))); +});})(fs__$1)) +,cljs.core.PersistentVector.EMPTY,fs__$1); +}); +var G__5020__3 = (function (x,y,z){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (fs__$1){ +return (function (p1__4988_SHARP_,p2__4989_SHARP_){ +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(p1__4988_SHARP_,(p2__4989_SHARP_.cljs$core$IFn$_invoke$arity$3 ? p2__4989_SHARP_.cljs$core$IFn$_invoke$arity$3(x,y,z) : p2__4989_SHARP_.call(null,x,y,z))); +});})(fs__$1)) +,cljs.core.PersistentVector.EMPTY,fs__$1); +}); +var G__5020__4 = (function() { +var G__5021__delegate = function (x,y,z,args){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (fs__$1){ +return (function (p1__4990_SHARP_,p2__4991_SHARP_){ +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(p1__4990_SHARP_,cljs.core.apply.cljs$core$IFn$_invoke$arity$5(p2__4991_SHARP_,x,y,z,args)); +});})(fs__$1)) +,cljs.core.PersistentVector.EMPTY,fs__$1); +}; +var G__5021 = function (x,y,z,var_args){ +var args = null; +if (arguments.length > 3) { +var G__5022__i = 0, G__5022__a = new Array(arguments.length - 3); +while (G__5022__i < G__5022__a.length) {G__5022__a[G__5022__i] = arguments[G__5022__i + 3]; ++G__5022__i;} + args = new cljs.core.IndexedSeq(G__5022__a,0,null); +} +return G__5021__delegate.call(this,x,y,z,args);}; +G__5021.cljs$lang$maxFixedArity = 3; +G__5021.cljs$lang$applyTo = (function (arglist__5023){ +var x = cljs.core.first(arglist__5023); +arglist__5023 = cljs.core.next(arglist__5023); +var y = cljs.core.first(arglist__5023); +arglist__5023 = cljs.core.next(arglist__5023); +var z = cljs.core.first(arglist__5023); +var args = cljs.core.rest(arglist__5023); +return G__5021__delegate(x,y,z,args); +}); +G__5021.cljs$core$IFn$_invoke$arity$variadic = G__5021__delegate; +return G__5021; +})() +; +G__5020 = function(x,y,z,var_args){ +var args = var_args; +switch(arguments.length){ +case 0: +return G__5020__0.call(this); +case 1: +return G__5020__1.call(this,x); +case 2: +return G__5020__2.call(this,x,y); +case 3: +return G__5020__3.call(this,x,y,z); +default: +var G__5024 = null; +if (arguments.length > 3) { +var G__5025__i = 0, G__5025__a = new Array(arguments.length - 3); +while (G__5025__i < G__5025__a.length) {G__5025__a[G__5025__i] = arguments[G__5025__i + 3]; ++G__5025__i;} +G__5024 = new cljs.core.IndexedSeq(G__5025__a,0,null); +} +return G__5020__4.cljs$core$IFn$_invoke$arity$variadic(x,y,z, G__5024); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5020.cljs$lang$maxFixedArity = 3; +G__5020.cljs$lang$applyTo = G__5020__4.cljs$lang$applyTo; +G__5020.cljs$core$IFn$_invoke$arity$0 = G__5020__0; +G__5020.cljs$core$IFn$_invoke$arity$1 = G__5020__1; +G__5020.cljs$core$IFn$_invoke$arity$2 = G__5020__2; +G__5020.cljs$core$IFn$_invoke$arity$3 = G__5020__3; +G__5020.cljs$core$IFn$_invoke$arity$variadic = G__5020__4.cljs$core$IFn$_invoke$arity$variadic; +return G__5020; +})() +;})(fs__$1)) +}); + +/** @this {Function} */ +cljs.core.juxt.cljs$lang$applyTo = (function (seq4993){ +var G__4994 = cljs.core.first(seq4993); +var seq4993__$1 = cljs.core.next(seq4993); +var G__4995 = cljs.core.first(seq4993__$1); +var seq4993__$2 = cljs.core.next(seq4993__$1); +var G__4996 = cljs.core.first(seq4993__$2); +var seq4993__$3 = cljs.core.next(seq4993__$2); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__4994,G__4995,G__4996,seq4993__$3); +}); + +cljs.core.juxt.cljs$lang$maxFixedArity = (3); + +/** + * When lazy sequences are produced via functions that have side + * effects, any effects other than those needed to produce the first + * element in the seq do not occur until the seq is consumed. dorun can + * be used to force any effects. Walks through the successive nexts of + * the seq, does not retain the head and returns nil. + */ +cljs.core.dorun = (function cljs$core$dorun(var_args){ +var G__5027 = arguments.length; +switch (G__5027) { +case 1: +return cljs.core.dorun.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.dorun.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.dorun.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +while(true){ +var temp__5735__auto__ = cljs.core.seq(coll); +if(temp__5735__auto__){ +var s = temp__5735__auto__; +var G__5029 = cljs.core.next(s); +coll = G__5029; +continue; +} else { +return null; +} +break; +} +}); + +cljs.core.dorun.cljs$core$IFn$_invoke$arity$2 = (function (n,coll){ +while(true){ +if(((cljs.core.seq(coll)) && ((n > (0))))){ +var G__5030 = (n - (1)); +var G__5031 = cljs.core.next(coll); +n = G__5030; +coll = G__5031; +continue; +} else { +return null; +} +break; +} +}); + +cljs.core.dorun.cljs$lang$maxFixedArity = 2; + +/** + * When lazy sequences are produced via functions that have side + * effects, any effects other than those needed to produce the first + * element in the seq do not occur until the seq is consumed. doall can + * be used to force any effects. Walks through the successive nexts of + * the seq, retains the head and returns it, thus causing the entire + * seq to reside in memory at one time. + */ +cljs.core.doall = (function cljs$core$doall(var_args){ +var G__5033 = arguments.length; +switch (G__5033) { +case 1: +return cljs.core.doall.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.doall.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.doall.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +cljs.core.dorun.cljs$core$IFn$_invoke$arity$1(coll); + +return coll; +}); + +cljs.core.doall.cljs$core$IFn$_invoke$arity$2 = (function (n,coll){ +cljs.core.dorun.cljs$core$IFn$_invoke$arity$2(n,coll); + +return coll; +}); + +cljs.core.doall.cljs$lang$maxFixedArity = 2; + +/** + * Returns true if x is a JavaScript RegExp instance. + */ +cljs.core.regexp_QMARK_ = (function cljs$core$regexp_QMARK_(x){ +return (x instanceof RegExp); +}); +/** + * Returns the result of (re-find re s) if re fully matches s. + */ +cljs.core.re_matches = (function cljs$core$re_matches(re,s){ +if(typeof s === 'string'){ +var matches = re.exec(s); +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.first(matches),s)){ +if((cljs.core.count(matches) === (1))){ +return cljs.core.first(matches); +} else { +return cljs.core.vec(matches); +} +} else { +return null; +} +} else { +throw (new TypeError("re-matches must match against a string.")); +} +}); +/** + * Returns the first regex match, if any, of s to re, using + * re.exec(s). Returns a vector, containing first the matching + * substring, then any capturing groups if the regular expression contains + * capturing groups. + */ +cljs.core.re_find = (function cljs$core$re_find(re,s){ +if(typeof s === 'string'){ +var matches = re.exec(s); +if((matches == null)){ +return null; +} else { +if((cljs.core.count(matches) === (1))){ +return cljs.core.first(matches); +} else { +return cljs.core.vec(matches); +} +} +} else { +throw (new TypeError("re-find must match against a string.")); +} +}); +cljs.core.re_seq_STAR_ = (function cljs$core$re_seq_STAR_(re,s){ +var temp__5739__auto__ = re.exec(s); +if((temp__5739__auto__ == null)){ +return null; +} else { +var matches = temp__5739__auto__; +var match_str = (matches[(0)]); +var match_vals = (((matches.length === (1)))?match_str:cljs.core.vec(matches)); +return cljs.core.cons(match_vals,(new cljs.core.LazySeq(null,((function (match_str,match_vals,matches,temp__5739__auto__){ +return (function (){ +var post_idx = (matches.index + (function (){var x__4219__auto__ = (1); +var y__4220__auto__ = match_str.length; +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +})()); +if((post_idx <= s.length)){ +var G__5035 = re; +var G__5036 = cljs.core.subs.cljs$core$IFn$_invoke$arity$2(s,post_idx); +return (cljs.core.re_seq_STAR_.cljs$core$IFn$_invoke$arity$2 ? cljs.core.re_seq_STAR_.cljs$core$IFn$_invoke$arity$2(G__5035,G__5036) : cljs.core.re_seq_STAR_.call(null,G__5035,G__5036)); +} else { +return null; +} +});})(match_str,match_vals,matches,temp__5739__auto__)) +,null,null))); +} +}); +/** + * Returns a lazy sequence of successive matches of re in s. + */ +cljs.core.re_seq = (function cljs$core$re_seq(re,s){ +if(typeof s === 'string'){ +return cljs.core.re_seq_STAR_(re,s); +} else { +throw (new TypeError("re-seq must match against a string.")); +} +}); +/** + * Returns an instance of RegExp which has compiled the provided string. + */ +cljs.core.re_pattern = (function cljs$core$re_pattern(s){ +if((s instanceof RegExp)){ +return s; +} else { +var vec__5037 = cljs.core.re_find(/^\(\?([idmsux]*)\)/,s); +var prefix = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5037,(0),null); +var flags = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5037,(1),null); +var pattern = cljs.core.subs.cljs$core$IFn$_invoke$arity$2(s,cljs.core.count(prefix)); +return (new RegExp(pattern,(function (){var or__4131__auto__ = flags; +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return ""; +} +})())); +} +}); +cljs.core.pr_sequential_writer = (function cljs$core$pr_sequential_writer(writer,print_one,begin,sep,end,opts,coll){ +var _STAR_print_level_STAR__orig_val__5040 = cljs.core._STAR_print_level_STAR_; +var _STAR_print_level_STAR__temp_val__5041 = (((cljs.core._STAR_print_level_STAR_ == null))?null:(cljs.core._STAR_print_level_STAR_ - (1))); +cljs.core._STAR_print_level_STAR_ = _STAR_print_level_STAR__temp_val__5041; + +try{if((((!((cljs.core._STAR_print_level_STAR_ == null)))) && ((cljs.core._STAR_print_level_STAR_ < (0))))){ +return cljs.core._write(writer,"#"); +} else { +cljs.core._write(writer,begin); + +if((cljs.core.cst$kw$print_DASH_length.cljs$core$IFn$_invoke$arity$1(opts) === (0))){ +if(cljs.core.seq(coll)){ +cljs.core._write(writer,(function (){var or__4131__auto__ = cljs.core.cst$kw$more_DASH_marker.cljs$core$IFn$_invoke$arity$1(opts); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return "..."; +} +})()); +} else { +} +} else { +if(cljs.core.seq(coll)){ +var G__5042_5048 = cljs.core.first(coll); +var G__5043_5049 = writer; +var G__5044_5050 = opts; +(print_one.cljs$core$IFn$_invoke$arity$3 ? print_one.cljs$core$IFn$_invoke$arity$3(G__5042_5048,G__5043_5049,G__5044_5050) : print_one.call(null,G__5042_5048,G__5043_5049,G__5044_5050)); +} else { +} + +var coll_5051__$1 = cljs.core.next(coll); +var n_5052 = (cljs.core.cst$kw$print_DASH_length.cljs$core$IFn$_invoke$arity$1(opts) - (1)); +while(true){ +if(((coll_5051__$1) && ((((n_5052 == null)) || ((!((n_5052 === (0))))))))){ +cljs.core._write(writer,sep); + +var G__5045_5053 = cljs.core.first(coll_5051__$1); +var G__5046_5054 = writer; +var G__5047_5055 = opts; +(print_one.cljs$core$IFn$_invoke$arity$3 ? print_one.cljs$core$IFn$_invoke$arity$3(G__5045_5053,G__5046_5054,G__5047_5055) : print_one.call(null,G__5045_5053,G__5046_5054,G__5047_5055)); + +var G__5056 = cljs.core.next(coll_5051__$1); +var G__5057 = (n_5052 - (1)); +coll_5051__$1 = G__5056; +n_5052 = G__5057; +continue; +} else { +if(((cljs.core.seq(coll_5051__$1)) && ((n_5052 === (0))))){ +cljs.core._write(writer,sep); + +cljs.core._write(writer,(function (){var or__4131__auto__ = cljs.core.cst$kw$more_DASH_marker.cljs$core$IFn$_invoke$arity$1(opts); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return "..."; +} +})()); +} else { +} +} +break; +} +} + +return cljs.core._write(writer,end); +} +}finally {cljs.core._STAR_print_level_STAR_ = _STAR_print_level_STAR__orig_val__5040; +}}); +cljs.core.write_all = (function cljs$core$write_all(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5064 = arguments.length; +var i__4731__auto___5065 = (0); +while(true){ +if((i__4731__auto___5065 < len__4730__auto___5064)){ +args__4736__auto__.push((arguments[i__4731__auto___5065])); + +var G__5066 = (i__4731__auto___5065 + (1)); +i__4731__auto___5065 = G__5066; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null); +return cljs.core.write_all.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__); +}); + +cljs.core.write_all.cljs$core$IFn$_invoke$arity$variadic = (function (writer,ss){ +var seq__5060 = cljs.core.seq(ss); +var chunk__5061 = null; +var count__5062 = (0); +var i__5063 = (0); +while(true){ +if((i__5063 < count__5062)){ +var s = chunk__5061.cljs$core$IIndexed$_nth$arity$2(null,i__5063); +cljs.core._write(writer,s); + + +var G__5067 = seq__5060; +var G__5068 = chunk__5061; +var G__5069 = count__5062; +var G__5070 = (i__5063 + (1)); +seq__5060 = G__5067; +chunk__5061 = G__5068; +count__5062 = G__5069; +i__5063 = G__5070; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__5060); +if(temp__5735__auto__){ +var seq__5060__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__5060__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__5060__$1); +var G__5071 = cljs.core.chunk_rest(seq__5060__$1); +var G__5072 = c__4550__auto__; +var G__5073 = cljs.core.count(c__4550__auto__); +var G__5074 = (0); +seq__5060 = G__5071; +chunk__5061 = G__5072; +count__5062 = G__5073; +i__5063 = G__5074; +continue; +} else { +var s = cljs.core.first(seq__5060__$1); +cljs.core._write(writer,s); + + +var G__5075 = cljs.core.next(seq__5060__$1); +var G__5076 = null; +var G__5077 = (0); +var G__5078 = (0); +seq__5060 = G__5075; +chunk__5061 = G__5076; +count__5062 = G__5077; +i__5063 = G__5078; +continue; +} +} else { +return null; +} +} +break; +} +}); + +cljs.core.write_all.cljs$lang$maxFixedArity = (1); + +/** @this {Function} */ +cljs.core.write_all.cljs$lang$applyTo = (function (seq5058){ +var G__5059 = cljs.core.first(seq5058); +var seq5058__$1 = cljs.core.next(seq5058); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__5059,seq5058__$1); +}); + +cljs.core.string_print = (function cljs$core$string_print(x){ +if((cljs.core._STAR_print_fn_STAR_ == null)){ +throw (new Error("No *print-fn* fn set for evaluation environment")); +} else { +} + +(cljs.core._STAR_print_fn_STAR_.cljs$core$IFn$_invoke$arity$1 ? cljs.core._STAR_print_fn_STAR_.cljs$core$IFn$_invoke$arity$1(x) : cljs.core._STAR_print_fn_STAR_.call(null,x)); + +return null; +}); +cljs.core.flush = (function cljs$core$flush(){ +return null; +}); +cljs.core.char_escapes = (function (){var obj5080 = ({"\"":"\\\"","\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r","\t":"\\t"}); +return obj5080; +})(); +cljs.core.quote_string = (function cljs$core$quote_string(s){ +return ["\"",cljs.core.str.cljs$core$IFn$_invoke$arity$1(s.replace(RegExp("[\\\\\"\b\f\n\r\t]","g"),(function (match){ +return (cljs.core.char_escapes[match]); +}))),"\""].join(''); +}); +cljs.core.print_meta_QMARK_ = (function cljs$core$print_meta_QMARK_(opts,obj){ +var and__4120__auto__ = cljs.core.boolean$(cljs.core.get.cljs$core$IFn$_invoke$arity$2(opts,cljs.core.cst$kw$meta)); +if(and__4120__auto__){ +var and__4120__auto____$1 = (((!((obj == null))))?(((((obj.cljs$lang$protocol_mask$partition0$ & (131072))) || ((cljs.core.PROTOCOL_SENTINEL === obj.cljs$core$IMeta$))))?true:false):false); +if(and__4120__auto____$1){ +return (!((cljs.core.meta(obj) == null))); +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +}); +cljs.core.pr_writer_impl = (function cljs$core$pr_writer_impl(obj,writer,opts){ +if((obj == null)){ +return cljs.core._write(writer,"nil"); +} else { +if(cljs.core.print_meta_QMARK_(opts,obj)){ +cljs.core._write(writer,"^"); + +cljs.core.pr_writer(cljs.core.meta(obj),writer,opts); + +cljs.core._write(writer," "); +} else { +} + +if(obj.cljs$lang$type){ +return obj.cljs$lang$ctorPrWriter(obj,writer,opts); +} else { +if((((!((obj == null))))?(((((obj.cljs$lang$protocol_mask$partition0$ & (2147483648))) || ((cljs.core.PROTOCOL_SENTINEL === obj.cljs$core$IPrintWithWriter$))))?true:(((!obj.cljs$lang$protocol_mask$partition0$))?cljs.core.native_satisfies_QMARK_(cljs.core.IPrintWithWriter,obj):false)):cljs.core.native_satisfies_QMARK_(cljs.core.IPrintWithWriter,obj))){ +return cljs.core._pr_writer(obj,writer,opts); +} else { +if(((obj === true) || (obj === false))){ +return cljs.core._write(writer,cljs.core.str.cljs$core$IFn$_invoke$arity$1(obj)); +} else { +if(typeof obj === 'number'){ +return cljs.core._write(writer,((isNaN(obj))?"##NaN":(((obj === Number.POSITIVE_INFINITY))?"##Inf":(((obj === Number.NEGATIVE_INFINITY))?"##-Inf":cljs.core.str.cljs$core$IFn$_invoke$arity$1(obj) +)))); +} else { +if(cljs.core.object_QMARK_(obj)){ +cljs.core._write(writer,"#js "); + +return cljs.core.print_map(cljs.core.map.cljs$core$IFn$_invoke$arity$2((function (k){ +return (new cljs.core.MapEntry((function (){var G__5085 = k; +if((!((cljs.core.re_matches(/[A-Za-z_\*\+\?!\-'][\w\*\+\?!\-']*/,k) == null)))){ +return cljs.core.keyword.cljs$core$IFn$_invoke$arity$1(G__5085); +} else { +return G__5085; +} +})(),(obj[k]),null)); +}),cljs.core.js_keys(obj)),cljs.core.pr_writer,writer,opts); +} else { +if(cljs.core.array_QMARK_(obj)){ +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"#js ["," ","]",opts,obj); +} else { +if(goog.isString(obj)){ +if(cljs.core.truth_(cljs.core.cst$kw$readably.cljs$core$IFn$_invoke$arity$1(opts))){ +return cljs.core._write(writer,cljs.core.quote_string(obj)); +} else { +return cljs.core._write(writer,obj); +} +} else { +if(goog.isFunction(obj)){ +var name = obj.name; +var name__$1 = (cljs.core.truth_((function (){var or__4131__auto__ = (name == null); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return goog.string.isEmpty(name); +} +})())?"Function":name); +return cljs.core.write_all.cljs$core$IFn$_invoke$arity$variadic(writer,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["#object[",name__$1,((cljs.core._STAR_print_fn_bodies_STAR_)?[" \"",cljs.core.str.cljs$core$IFn$_invoke$arity$1(obj),"\""].join(''):""),"]"], 0)); +} else { +if((obj instanceof Date)){ +var normalize = (function (n,len){ +var ns = cljs.core.str.cljs$core$IFn$_invoke$arity$1(n); +while(true){ +if((cljs.core.count(ns) < len)){ +var G__5088 = ["0",ns].join(''); +ns = G__5088; +continue; +} else { +return ns; +} +break; +} +}); +return cljs.core.write_all.cljs$core$IFn$_invoke$arity$variadic(writer,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["#inst \"",cljs.core.str.cljs$core$IFn$_invoke$arity$1(obj.getUTCFullYear()),"-",normalize((obj.getUTCMonth() + (1)),(2)),"-",normalize(obj.getUTCDate(),(2)),"T",normalize(obj.getUTCHours(),(2)),":",normalize(obj.getUTCMinutes(),(2)),":",normalize(obj.getUTCSeconds(),(2)),".",normalize(obj.getUTCMilliseconds(),(3)),"-","00:00\""], 0)); +} else { +if(cljs.core.regexp_QMARK_(obj)){ +return cljs.core.write_all.cljs$core$IFn$_invoke$arity$variadic(writer,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["#\"",obj.source,"\""], 0)); +} else { +if(cljs.core.truth_((function (){var G__5086 = obj; +var G__5086__$1 = (((G__5086 == null))?null:G__5086.constructor); +if((G__5086__$1 == null)){ +return null; +} else { +return G__5086__$1.cljs$lang$ctorStr; +} +})())){ +return cljs.core.write_all.cljs$core$IFn$_invoke$arity$variadic(writer,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["#object[",obj.constructor.cljs$lang$ctorStr.replace((new RegExp("/","g")),"."),"]"], 0)); +} else { +var name = (function (){var G__5087 = obj; +var G__5087__$1 = (((G__5087 == null))?null:G__5087.constructor); +if((G__5087__$1 == null)){ +return null; +} else { +return G__5087__$1.name; +} +})(); +var name__$1 = (cljs.core.truth_((function (){var or__4131__auto__ = (name == null); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +return goog.string.isEmpty(name); +} +})())?"Object":name); +if((obj.constructor == null)){ +return cljs.core.write_all.cljs$core$IFn$_invoke$arity$variadic(writer,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["#object[",name__$1,"]"], 0)); +} else { +return cljs.core.write_all.cljs$core$IFn$_invoke$arity$variadic(writer,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2(["#object[",name__$1," ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(obj),"]"], 0)); +} +} + +} +} +} +} +} +} +} +} +} +} + +} +}); +/** + * Prefer this to pr-seq, because it makes the printing function + * configurable, allowing efficient implementations such as appending + * to a StringBuffer. + */ +cljs.core.pr_writer = (function cljs$core$pr_writer(obj,writer,opts){ +var temp__5733__auto__ = cljs.core.cst$kw$alt_DASH_impl.cljs$core$IFn$_invoke$arity$1(opts); +if(cljs.core.truth_(temp__5733__auto__)){ +var alt_impl = temp__5733__auto__; +var G__5089 = obj; +var G__5090 = writer; +var G__5091 = cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(opts,cljs.core.cst$kw$fallback_DASH_impl,cljs.core.pr_writer_impl); +return (alt_impl.cljs$core$IFn$_invoke$arity$3 ? alt_impl.cljs$core$IFn$_invoke$arity$3(G__5089,G__5090,G__5091) : alt_impl.call(null,G__5089,G__5090,G__5091)); +} else { +return cljs.core.pr_writer_impl(obj,writer,opts); +} +}); +cljs.core.pr_seq_writer = (function cljs$core$pr_seq_writer(objs,writer,opts){ +cljs.core.pr_writer(cljs.core.first(objs),writer,opts); + +var seq__5092 = cljs.core.seq(cljs.core.next(objs)); +var chunk__5093 = null; +var count__5094 = (0); +var i__5095 = (0); +while(true){ +if((i__5095 < count__5094)){ +var obj = chunk__5093.cljs$core$IIndexed$_nth$arity$2(null,i__5095); +cljs.core._write(writer," "); + +cljs.core.pr_writer(obj,writer,opts); + + +var G__5096 = seq__5092; +var G__5097 = chunk__5093; +var G__5098 = count__5094; +var G__5099 = (i__5095 + (1)); +seq__5092 = G__5096; +chunk__5093 = G__5097; +count__5094 = G__5098; +i__5095 = G__5099; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__5092); +if(temp__5735__auto__){ +var seq__5092__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__5092__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__5092__$1); +var G__5100 = cljs.core.chunk_rest(seq__5092__$1); +var G__5101 = c__4550__auto__; +var G__5102 = cljs.core.count(c__4550__auto__); +var G__5103 = (0); +seq__5092 = G__5100; +chunk__5093 = G__5101; +count__5094 = G__5102; +i__5095 = G__5103; +continue; +} else { +var obj = cljs.core.first(seq__5092__$1); +cljs.core._write(writer," "); + +cljs.core.pr_writer(obj,writer,opts); + + +var G__5104 = cljs.core.next(seq__5092__$1); +var G__5105 = null; +var G__5106 = (0); +var G__5107 = (0); +seq__5092 = G__5104; +chunk__5093 = G__5105; +count__5094 = G__5106; +i__5095 = G__5107; +continue; +} +} else { +return null; +} +} +break; +} +}); +cljs.core.pr_sb_with_opts = (function cljs$core$pr_sb_with_opts(objs,opts){ +var sb = (new goog.string.StringBuffer()); +var writer = (new cljs.core.StringBufferWriter(sb)); +cljs.core.pr_seq_writer(objs,writer,opts); + +writer.cljs$core$IWriter$_flush$arity$1(null); + +return sb; +}); +/** + * Prints a sequence of objects to a string, observing all the + * options given in opts + */ +cljs.core.pr_str_with_opts = (function cljs$core$pr_str_with_opts(objs,opts){ +if(cljs.core.empty_QMARK_(objs)){ +return ""; +} else { +return cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.pr_sb_with_opts(objs,opts)); +} +}); +/** + * Same as pr-str-with-opts followed by (newline) + */ +cljs.core.prn_str_with_opts = (function cljs$core$prn_str_with_opts(objs,opts){ +if(cljs.core.empty_QMARK_(objs)){ +return "\n"; +} else { +var sb = cljs.core.pr_sb_with_opts(objs,opts); +sb.append("\n"); + +return cljs.core.str.cljs$core$IFn$_invoke$arity$1(sb); +} +}); +/** + * Prints a sequence of objects using string-print, observing all + * the options given in opts + */ +cljs.core.pr_with_opts = (function cljs$core$pr_with_opts(objs,opts){ +return cljs.core.string_print(cljs.core.pr_str_with_opts(objs,opts)); +}); +/** + * Prints a newline using *print-fn* + */ +cljs.core.newline = (function cljs$core$newline(var_args){ +var G__5109 = arguments.length; +switch (G__5109) { +case 0: +return cljs.core.newline.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.newline.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.newline.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.newline.cljs$core$IFn$_invoke$arity$1(null); +}); + +cljs.core.newline.cljs$core$IFn$_invoke$arity$1 = (function (opts){ +cljs.core.string_print("\n"); + +if(cljs.core.truth_(cljs.core.get.cljs$core$IFn$_invoke$arity$2(opts,cljs.core.cst$kw$flush_DASH_on_DASH_newline))){ +return cljs.core.flush(); +} else { +return null; +} +}); + +cljs.core.newline.cljs$lang$maxFixedArity = 1; + +/** + * pr to a string, returning it. Fundamental entrypoint to IPrintWithWriter. + */ +cljs.core.pr_str = (function cljs$core$pr_str(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5112 = arguments.length; +var i__4731__auto___5113 = (0); +while(true){ +if((i__4731__auto___5113 < len__4730__auto___5112)){ +args__4736__auto__.push((arguments[i__4731__auto___5113])); + +var G__5114 = (i__4731__auto___5113 + (1)); +i__4731__auto___5113 = G__5114; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic = (function (objs){ +return cljs.core.pr_str_with_opts(objs,cljs.core.pr_opts()); +}); + +cljs.core.pr_str.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.pr_str.cljs$lang$applyTo = (function (seq5111){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq5111)); +}); + +/** + * Same as pr-str followed by (newline) + */ +cljs.core.prn_str = (function cljs$core$prn_str(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5116 = arguments.length; +var i__4731__auto___5117 = (0); +while(true){ +if((i__4731__auto___5117 < len__4730__auto___5116)){ +args__4736__auto__.push((arguments[i__4731__auto___5117])); + +var G__5118 = (i__4731__auto___5117 + (1)); +i__4731__auto___5117 = G__5118; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.prn_str.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.prn_str.cljs$core$IFn$_invoke$arity$variadic = (function (objs){ +return cljs.core.prn_str_with_opts(objs,cljs.core.pr_opts()); +}); + +cljs.core.prn_str.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.prn_str.cljs$lang$applyTo = (function (seq5115){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq5115)); +}); + +/** + * Prints the object(s) using string-print. Prints the + * object(s), separated by spaces if there is more than one. + * By default, pr and prn print in a way that objects can be + * read by the reader + */ +cljs.core.pr = (function cljs$core$pr(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5120 = arguments.length; +var i__4731__auto___5121 = (0); +while(true){ +if((i__4731__auto___5121 < len__4730__auto___5120)){ +args__4736__auto__.push((arguments[i__4731__auto___5121])); + +var G__5122 = (i__4731__auto___5121 + (1)); +i__4731__auto___5121 = G__5122; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.pr.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.pr.cljs$core$IFn$_invoke$arity$variadic = (function (objs){ +return cljs.core.pr_with_opts(objs,cljs.core.pr_opts()); +}); + +cljs.core.pr.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.pr.cljs$lang$applyTo = (function (seq5119){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq5119)); +}); + +/** + * Prints the object(s) using string-print. + * print and println produce output for human consumption. + * @param {...*} var_args + */ +cljs.core.print = (function() { +var cljs$core$cljs_core_print__delegate = function (objs){ +return cljs.core.pr_with_opts(objs,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(cljs.core.pr_opts(),cljs.core.cst$kw$readably,false)); +}; +var cljs$core$cljs_core_print = function (var_args){ +var objs = null; +if (arguments.length > 0) { +var G__5123__i = 0, G__5123__a = new Array(arguments.length - 0); +while (G__5123__i < G__5123__a.length) {G__5123__a[G__5123__i] = arguments[G__5123__i + 0]; ++G__5123__i;} + objs = new cljs.core.IndexedSeq(G__5123__a,0,null); +} +return cljs$core$cljs_core_print__delegate.call(this,objs);}; +cljs$core$cljs_core_print.cljs$lang$maxFixedArity = 0; +cljs$core$cljs_core_print.cljs$lang$applyTo = (function (arglist__5124){ +var objs = cljs.core.seq(arglist__5124); +return cljs$core$cljs_core_print__delegate(objs); +}); +cljs$core$cljs_core_print.cljs$core$IFn$_invoke$arity$variadic = cljs$core$cljs_core_print__delegate; +return cljs$core$cljs_core_print; +})() +; +/** + * print to a string, returning it + */ +cljs.core.print_str = (function cljs$core$print_str(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5126 = arguments.length; +var i__4731__auto___5127 = (0); +while(true){ +if((i__4731__auto___5127 < len__4730__auto___5126)){ +args__4736__auto__.push((arguments[i__4731__auto___5127])); + +var G__5128 = (i__4731__auto___5127 + (1)); +i__4731__auto___5127 = G__5128; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.print_str.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.print_str.cljs$core$IFn$_invoke$arity$variadic = (function (objs){ +return cljs.core.pr_str_with_opts(objs,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(cljs.core.pr_opts(),cljs.core.cst$kw$readably,false)); +}); + +cljs.core.print_str.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.print_str.cljs$lang$applyTo = (function (seq5125){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq5125)); +}); + +/** + * Same as print followed by (newline) + */ +cljs.core.println = (function cljs$core$println(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5130 = arguments.length; +var i__4731__auto___5131 = (0); +while(true){ +if((i__4731__auto___5131 < len__4730__auto___5130)){ +args__4736__auto__.push((arguments[i__4731__auto___5131])); + +var G__5132 = (i__4731__auto___5131 + (1)); +i__4731__auto___5131 = G__5132; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.println.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.println.cljs$core$IFn$_invoke$arity$variadic = (function (objs){ +cljs.core.pr_with_opts(objs,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(cljs.core.pr_opts(),cljs.core.cst$kw$readably,false)); + +if(cljs.core._STAR_print_newline_STAR_){ +return cljs.core.newline.cljs$core$IFn$_invoke$arity$1(cljs.core.pr_opts()); +} else { +return null; +} +}); + +cljs.core.println.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.println.cljs$lang$applyTo = (function (seq5129){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq5129)); +}); + +/** + * println to a string, returning it + */ +cljs.core.println_str = (function cljs$core$println_str(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5134 = arguments.length; +var i__4731__auto___5135 = (0); +while(true){ +if((i__4731__auto___5135 < len__4730__auto___5134)){ +args__4736__auto__.push((arguments[i__4731__auto___5135])); + +var G__5136 = (i__4731__auto___5135 + (1)); +i__4731__auto___5135 = G__5136; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.println_str.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.println_str.cljs$core$IFn$_invoke$arity$variadic = (function (objs){ +return cljs.core.prn_str_with_opts(objs,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(cljs.core.pr_opts(),cljs.core.cst$kw$readably,false)); +}); + +cljs.core.println_str.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.println_str.cljs$lang$applyTo = (function (seq5133){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq5133)); +}); + +/** + * Same as pr followed by (newline). + */ +cljs.core.prn = (function cljs$core$prn(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5138 = arguments.length; +var i__4731__auto___5139 = (0); +while(true){ +if((i__4731__auto___5139 < len__4730__auto___5138)){ +args__4736__auto__.push((arguments[i__4731__auto___5139])); + +var G__5140 = (i__4731__auto___5139 + (1)); +i__4731__auto___5139 = G__5140; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.prn.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.prn.cljs$core$IFn$_invoke$arity$variadic = (function (objs){ +cljs.core.pr_with_opts(objs,cljs.core.pr_opts()); + +if(cljs.core._STAR_print_newline_STAR_){ +return cljs.core.newline.cljs$core$IFn$_invoke$arity$1(cljs.core.pr_opts()); +} else { +return null; +} +}); + +cljs.core.prn.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.prn.cljs$lang$applyTo = (function (seq5137){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq5137)); +}); + +cljs.core.strip_ns = (function cljs$core$strip_ns(named){ +if((named instanceof cljs.core.Symbol)){ +return cljs.core.symbol.cljs$core$IFn$_invoke$arity$2(null,cljs.core.name(named)); +} else { +return cljs.core.keyword.cljs$core$IFn$_invoke$arity$2(null,cljs.core.name(named)); +} +}); +/** + * Returns [lifted-ns lifted-map] or nil if m can't be lifted. + */ +cljs.core.lift_ns = (function cljs$core$lift_ns(m){ +if(cljs.core._STAR_print_namespace_maps_STAR_){ +var ns = null; +var G__5147 = cljs.core.seq(m); +var vec__5148 = G__5147; +var seq__5149 = cljs.core.seq(vec__5148); +var first__5150 = cljs.core.first(seq__5149); +var seq__5149__$1 = cljs.core.next(seq__5149); +var vec__5151 = first__5150; +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5151,(0),null); +var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5151,(1),null); +var entry = vec__5151; +var entries = seq__5149__$1; +var lm = cljs.core.empty(m); +var ns__$1 = ns; +var G__5147__$1 = G__5147; +var lm__$1 = lm; +while(true){ +var ns__$2 = ns__$1; +var vec__5160 = G__5147__$1; +var seq__5161 = cljs.core.seq(vec__5160); +var first__5162 = cljs.core.first(seq__5161); +var seq__5161__$1 = cljs.core.next(seq__5161); +var vec__5163 = first__5162; +var k__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5163,(0),null); +var v__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5163,(1),null); +var entry__$1 = vec__5163; +var entries__$1 = seq__5161__$1; +var lm__$2 = lm__$1; +if(cljs.core.truth_(entry__$1)){ +if((((k__$1 instanceof cljs.core.Keyword)) || ((k__$1 instanceof cljs.core.Symbol)))){ +if(cljs.core.truth_(ns__$2)){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(ns__$2,cljs.core.namespace(k__$1))){ +var G__5166 = ns__$2; +var G__5167 = entries__$1; +var G__5168 = cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(lm__$2,cljs.core.strip_ns(k__$1),v__$1); +ns__$1 = G__5166; +G__5147__$1 = G__5167; +lm__$1 = G__5168; +continue; +} else { +return null; +} +} else { +var temp__5735__auto__ = cljs.core.namespace(k__$1); +if(cljs.core.truth_(temp__5735__auto__)){ +var new_ns = temp__5735__auto__; +var G__5169 = new_ns; +var G__5170 = entries__$1; +var G__5171 = cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(lm__$2,cljs.core.strip_ns(k__$1),v__$1); +ns__$1 = G__5169; +G__5147__$1 = G__5170; +lm__$1 = G__5171; +continue; +} else { +return null; +} +} +} else { +return null; +} +} else { +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [ns__$2,lm__$2], null); +} +break; +} +} else { +return null; +} +}); +cljs.core.print_prefix_map = (function cljs$core$print_prefix_map(prefix,m,print_one,writer,opts){ +return cljs.core.pr_sequential_writer(writer,(function (e,w,opts__$1){ +var G__5172_5178 = cljs.core.key(e); +var G__5173_5179 = w; +var G__5174_5180 = opts__$1; +(print_one.cljs$core$IFn$_invoke$arity$3 ? print_one.cljs$core$IFn$_invoke$arity$3(G__5172_5178,G__5173_5179,G__5174_5180) : print_one.call(null,G__5172_5178,G__5173_5179,G__5174_5180)); + +cljs.core._write(w," "); + +var G__5175 = cljs.core.val(e); +var G__5176 = w; +var G__5177 = opts__$1; +return (print_one.cljs$core$IFn$_invoke$arity$3 ? print_one.cljs$core$IFn$_invoke$arity$3(G__5175,G__5176,G__5177) : print_one.call(null,G__5175,G__5176,G__5177)); +}),[cljs.core.str.cljs$core$IFn$_invoke$arity$1(prefix),"{"].join(''),", ","}",opts,cljs.core.seq(m)); +}); +cljs.core.print_map = (function cljs$core$print_map(m,print_one,writer,opts){ +var vec__5181 = ((cljs.core.map_QMARK_(m))?cljs.core.lift_ns(m):null); +var ns = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5181,(0),null); +var lift_map = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5181,(1),null); +if(cljs.core.truth_(ns)){ +return cljs.core.print_prefix_map(["#:",cljs.core.str.cljs$core$IFn$_invoke$arity$1(ns)].join(''),lift_map,print_one,writer,opts); +} else { +return cljs.core.print_prefix_map(null,m,print_one,writer,opts); +} +}); +cljs.core.Volatile.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Volatile.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (a,writer,opts){ +var a__$1 = this; +cljs.core._write(writer,"#object[cljs.core.Volatile "); + +cljs.core.pr_writer(new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$val,a__$1.state], null),writer,opts); + +return cljs.core._write(writer,"]"); +}); + +cljs.core.Var.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Var.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (a,writer,opts){ +var a__$1 = this; +cljs.core._write(writer,"#'"); + +return cljs.core.pr_writer(a__$1.sym,writer,opts); +}); + +cljs.core.IndexedSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.IndexedSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.LazySeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.LazySeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.MapEntry.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.MapEntry.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"["," ","]",opts,coll__$1); +}); + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentTreeMapSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.NodeSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.NodeSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.BlackNode.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.BlackNode.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"["," ","]",opts,coll__$1); +}); + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentArrayMapSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.ES6IteratorSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ES6IteratorSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.PersistentTreeSet.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentTreeSet.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"#{"," ","}",opts,coll__$1); +}); + +cljs.core.ChunkedSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ChunkedSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.ObjMap.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ObjMap.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.print_map(coll__$1,cljs.core.pr_writer,writer,opts); +}); + +cljs.core.Cons.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Cons.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.Iterate.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Iterate.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.RSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.RSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.PersistentHashMap.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentHashMap.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.print_map(coll__$1,cljs.core.pr_writer,writer,opts); +}); + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ArrayNodeSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.Subvec.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Subvec.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"["," ","]",opts,coll__$1); +}); + +cljs.core.Cycle.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Cycle.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.PersistentTreeMap.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentTreeMap.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.print_map(coll__$1,cljs.core.pr_writer,writer,opts); +}); + +cljs.core.PersistentHashSet.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentHashSet.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"#{"," ","}",opts,coll__$1); +}); + +cljs.core.ChunkedCons.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ChunkedCons.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.Atom.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Atom.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (a,writer,opts){ +var a__$1 = this; +cljs.core._write(writer,"#object[cljs.core.Atom "); + +cljs.core.pr_writer(new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$val,a__$1.state], null),writer,opts); + +return cljs.core._write(writer,"]"); +}); + +cljs.core.ValSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ValSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.RedNode.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.RedNode.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"["," ","]",opts,coll__$1); +}); + +cljs.core.Repeat.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Repeat.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.PersistentVector.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentVector.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"["," ","]",opts,coll__$1); +}); + +cljs.core.PersistentQueueSeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentQueueSeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.EmptyList.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.EmptyList.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core._write(writer,"()"); +}); + +cljs.core.PersistentQueue.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentQueue.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"#queue ["," ","]",opts,cljs.core.seq(coll__$1)); +}); + +cljs.core.PersistentArrayMap.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentArrayMap.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.print_map(coll__$1,cljs.core.pr_writer,writer,opts); +}); + +cljs.core.Range.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Range.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.TransformerIterator.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.TransformerIterator.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.KeySeq.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.KeySeq.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); + +cljs.core.List.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.List.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll,writer,opts){ +var coll__$1 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$1); +}); +cljs.core.Symbol.prototype.cljs$core$IComparable$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Symbol.prototype.cljs$core$IComparable$_compare$arity$2 = (function (x,y){ +var x__$1 = this; +if((y instanceof cljs.core.Symbol)){ +return cljs.core.compare_symbols(x__$1,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x__$1)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} +}); + +cljs.core.Keyword.prototype.cljs$core$IComparable$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Keyword.prototype.cljs$core$IComparable$_compare$arity$2 = (function (x,y){ +var x__$1 = this; +if((y instanceof cljs.core.Keyword)){ +return cljs.core.compare_keywords(x__$1,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x__$1)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} +}); + +cljs.core.Subvec.prototype.cljs$core$IComparable$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.Subvec.prototype.cljs$core$IComparable$_compare$arity$2 = (function (x,y){ +var x__$1 = this; +if(cljs.core.vector_QMARK_(y)){ +return cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$2(x__$1,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x__$1)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} +}); + +cljs.core.PersistentVector.prototype.cljs$core$IComparable$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.PersistentVector.prototype.cljs$core$IComparable$_compare$arity$2 = (function (x,y){ +var x__$1 = this; +if(cljs.core.vector_QMARK_(y)){ +return cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$2(x__$1,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x__$1)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} +}); + +cljs.core.MapEntry.prototype.cljs$core$IComparable$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.MapEntry.prototype.cljs$core$IComparable$_compare$arity$2 = (function (x,y){ +var x__$1 = this; +if(cljs.core.vector_QMARK_(y)){ +return cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$2(x__$1,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x__$1)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} +}); + +cljs.core.BlackNode.prototype.cljs$core$IComparable$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.BlackNode.prototype.cljs$core$IComparable$_compare$arity$2 = (function (x,y){ +var x__$1 = this; +if(cljs.core.vector_QMARK_(y)){ +return cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$2(x__$1,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x__$1)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} +}); + +cljs.core.RedNode.prototype.cljs$core$IComparable$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.RedNode.prototype.cljs$core$IComparable$_compare$arity$2 = (function (x,y){ +var x__$1 = this; +if(cljs.core.vector_QMARK_(y)){ +return cljs.core.compare_indexed.cljs$core$IFn$_invoke$arity$2(x__$1,y); +} else { +throw (new Error(["Cannot compare ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(x__$1)," to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(y)].join(''))); +} +}); +/** + * Atomically sets the metadata for a namespace/var/ref/agent/atom to be: + * + * (apply f its-current-meta args) + * + * f must be free of side-effects + */ +cljs.core.alter_meta_BANG_ = (function cljs$core$alter_meta_BANG_(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5187 = arguments.length; +var i__4731__auto___5188 = (0); +while(true){ +if((i__4731__auto___5188 < len__4730__auto___5187)){ +args__4736__auto__.push((arguments[i__4731__auto___5188])); + +var G__5189 = (i__4731__auto___5188 + (1)); +i__4731__auto___5188 = G__5189; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((2) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((2)),(0),null)):null); +return cljs.core.alter_meta_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),(arguments[(1)]),argseq__4737__auto__); +}); + +cljs.core.alter_meta_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (iref,f,args){ +return iref.meta = cljs.core.apply.cljs$core$IFn$_invoke$arity$3(f,iref.meta,args); +}); + +cljs.core.alter_meta_BANG_.cljs$lang$maxFixedArity = (2); + +/** @this {Function} */ +cljs.core.alter_meta_BANG_.cljs$lang$applyTo = (function (seq5184){ +var G__5185 = cljs.core.first(seq5184); +var seq5184__$1 = cljs.core.next(seq5184); +var G__5186 = cljs.core.first(seq5184__$1); +var seq5184__$2 = cljs.core.next(seq5184__$1); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__5185,G__5186,seq5184__$2); +}); + +/** + * Atomically resets the metadata for an atom + */ +cljs.core.reset_meta_BANG_ = (function cljs$core$reset_meta_BANG_(iref,m){ +return iref.meta = m; +}); +/** + * Adds a watch function to an atom reference. The watch fn must be a + * fn of 4 args: a key, the reference, its old-state, its + * new-state. Whenever the reference's state might have been changed, + * any registered watches will have their functions called. The watch + * fn will be called synchronously. Note that an atom's state + * may have changed again prior to the fn call, so use old/new-state + * rather than derefing the reference. Keys must be unique per + * reference, and can be used to remove the watch with remove-watch, + * but are otherwise considered opaque by the watch mechanism. Bear in + * mind that regardless of the result or action of the watch fns the + * atom's value will change. Example: + * + * (def a (atom 0)) + * (add-watch a :inc (fn [k r o n] (assert (== 0 n)))) + * (swap! a inc) + * ;; Assertion Error + * (deref a) + * ;=> 1 + */ +cljs.core.add_watch = (function cljs$core$add_watch(iref,key,f){ +cljs.core._add_watch(iref,key,f); + +return iref; +}); +/** + * Removes a watch (set by add-watch) from a reference + */ +cljs.core.remove_watch = (function cljs$core$remove_watch(iref,key){ +cljs.core._remove_watch(iref,key); + +return iref; +}); +/** + * @type {*} + */ +cljs.core.gensym_counter = null; +/** + * Returns a new symbol with a unique name. If a prefix string is + * supplied, the name is prefix# where # is some unique number. If + * prefix is not supplied, the prefix is 'G__'. + */ +cljs.core.gensym = (function cljs$core$gensym(var_args){ +var G__5191 = arguments.length; +switch (G__5191) { +case 0: +return cljs.core.gensym.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.gensym.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.gensym.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.gensym.cljs$core$IFn$_invoke$arity$1("G__"); +}); + +cljs.core.gensym.cljs$core$IFn$_invoke$arity$1 = (function (prefix_string){ +if((cljs.core.gensym_counter == null)){ +cljs.core.gensym_counter = cljs.core.atom.cljs$core$IFn$_invoke$arity$1((0)); +} else { +} + +return cljs.core.symbol.cljs$core$IFn$_invoke$arity$1([cljs.core.str.cljs$core$IFn$_invoke$arity$1(prefix_string),cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(cljs.core.gensym_counter,cljs.core.inc))].join('')); +}); + +cljs.core.gensym.cljs$lang$maxFixedArity = 1; + + +/** +* @constructor + * @implements {cljs.core.IPending} + * @implements {cljs.core.IDeref} + * @implements {cljs.core.IPrintWithWriter} +*/ +cljs.core.Delay = (function (f,value){ +this.f = f; +this.value = value; +this.cljs$lang$protocol_mask$partition0$ = 2147516416; +this.cljs$lang$protocol_mask$partition1$ = 1; +}); +cljs.core.Delay.prototype.cljs$core$IDeref$_deref$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +if(cljs.core.truth_(self__.f)){ +self__.value = (self__.f.cljs$core$IFn$_invoke$arity$0 ? self__.f.cljs$core$IFn$_invoke$arity$0() : self__.f.call(null)); + +self__.f = null; +} else { +} + +return self__.value; +}); + +cljs.core.Delay.prototype.cljs$core$IPending$_realized_QMARK_$arity$1 = (function (x){ +var self__ = this; +var x__$1 = this; +return cljs.core.not(self__.f); +}); + +cljs.core.Delay.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (x,writer,opts){ +var self__ = this; +var x__$1 = this; +cljs.core._write(writer,"#object[cljs.core.Delay "); + +cljs.core.pr_writer(new cljs.core.PersistentArrayMap(null, 2, [cljs.core.cst$kw$status,(((self__.f == null))?cljs.core.cst$kw$ready:cljs.core.cst$kw$pending),cljs.core.cst$kw$val,self__.value], null),writer,opts); + +return cljs.core._write(writer,"]"); +}); + +cljs.core.Delay.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.with_meta(cljs.core.cst$sym$f,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null)),cljs.core.with_meta(cljs.core.cst$sym$value,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.Delay.cljs$lang$type = true; + +cljs.core.Delay.cljs$lang$ctorStr = "cljs.core/Delay"; + +cljs.core.Delay.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Delay"); +}); + +/** + * Positional factory function for cljs.core/Delay. + */ +cljs.core.__GT_Delay = (function cljs$core$__GT_Delay(f,value){ +return (new cljs.core.Delay(f,value)); +}); + +/** + * returns true if x is a Delay created with delay + */ +cljs.core.delay_QMARK_ = (function cljs$core$delay_QMARK_(x){ +return (x instanceof cljs.core.Delay); +}); +/** + * If x is a Delay, returns the (possibly cached) value of its expression, else returns x + */ +cljs.core.force = (function cljs$core$force(x){ +if(cljs.core.delay_QMARK_(x)){ +return cljs.core.deref(x); +} else { +return x; +} +}); +/** + * Returns true if a value has been produced for a delay or lazy sequence. + */ +cljs.core.realized_QMARK_ = (function cljs$core$realized_QMARK_(x){ +return cljs.core._realized_QMARK_(x); +}); +cljs.core.preserving_reduced = (function cljs$core$preserving_reduced(rf){ +return (function (p1__5193_SHARP_,p2__5194_SHARP_){ +var ret = (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(p1__5193_SHARP_,p2__5194_SHARP_) : rf.call(null,p1__5193_SHARP_,p2__5194_SHARP_)); +if(cljs.core.reduced_QMARK_(ret)){ +return cljs.core.reduced(ret); +} else { +return ret; +} +}); +}); +/** + * A transducer which concatenates the contents of each input, which must be a + * collection, into the reduction. + */ +cljs.core.cat = (function cljs$core$cat(rf){ +var rf1 = cljs.core.preserving_reduced(rf); +return ((function (rf1){ +return (function() { +var G__5195 = null; +var G__5195__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__5195__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__5195__2 = (function (result,input){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(rf1,result,input); +}); +G__5195 = function(result,input){ +switch(arguments.length){ +case 0: +return G__5195__0.call(this); +case 1: +return G__5195__1.call(this,result); +case 2: +return G__5195__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5195.cljs$core$IFn$_invoke$arity$0 = G__5195__0; +G__5195.cljs$core$IFn$_invoke$arity$1 = G__5195__1; +G__5195.cljs$core$IFn$_invoke$arity$2 = G__5195__2; +return G__5195; +})() +;})(rf1)) +}); +/** + * Returns a transducer that ends transduction when pred returns true + * for an input. When retf is supplied it must be a fn of 2 arguments - + * it will be passed the (completed) result so far and the input that + * triggered the predicate, and its return value (if it does not throw + * an exception) will be the return value of the transducer. If retf + * is not supplied, the input that triggered the predicate will be + * returned. If the predicate never returns true the transduction is + * unaffected. + */ +cljs.core.halt_when = (function cljs$core$halt_when(var_args){ +var G__5197 = arguments.length; +switch (G__5197) { +case 1: +return cljs.core.halt_when.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.halt_when.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.halt_when.cljs$core$IFn$_invoke$arity$1 = (function (pred){ +return cljs.core.halt_when.cljs$core$IFn$_invoke$arity$2(pred,null); +}); + +cljs.core.halt_when.cljs$core$IFn$_invoke$arity$2 = (function (pred,retf){ +return (function (rf){ +return (function() { +var G__5201 = null; +var G__5201__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__5201__1 = (function (result){ +if(((cljs.core.map_QMARK_(result)) && (cljs.core.contains_QMARK_(result,cljs.core.cst$kw$cljs$core_SLASH_halt)))){ +return cljs.core.cst$kw$cljs$core_SLASH_halt.cljs$core$IFn$_invoke$arity$1(result); +} else { +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +} +}); +var G__5201__2 = (function (result,input){ +if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$1 ? pred.cljs$core$IFn$_invoke$arity$1(input) : pred.call(null,input)))){ +return cljs.core.reduced(new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$cljs$core_SLASH_halt,(cljs.core.truth_(retf)?(function (){var G__5198 = (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +var G__5199 = input; +return (retf.cljs$core$IFn$_invoke$arity$2 ? retf.cljs$core$IFn$_invoke$arity$2(G__5198,G__5199) : retf.call(null,G__5198,G__5199)); +})():input)], null)); +} else { +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} +}); +G__5201 = function(result,input){ +switch(arguments.length){ +case 0: +return G__5201__0.call(this); +case 1: +return G__5201__1.call(this,result); +case 2: +return G__5201__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5201.cljs$core$IFn$_invoke$arity$0 = G__5201__0; +G__5201.cljs$core$IFn$_invoke$arity$1 = G__5201__1; +G__5201.cljs$core$IFn$_invoke$arity$2 = G__5201__2; +return G__5201; +})() +}); +}); + +cljs.core.halt_when.cljs$lang$maxFixedArity = 2; + +/** + * Returns a lazy sequence removing consecutive duplicates in coll. + * Returns a transducer when no collection is provided. + */ +cljs.core.dedupe = (function cljs$core$dedupe(var_args){ +var G__5203 = arguments.length; +switch (G__5203) { +case 0: +return cljs.core.dedupe.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.dedupe.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.dedupe.cljs$core$IFn$_invoke$arity$0 = (function (){ +return (function (rf){ +var pa = cljs.core.volatile_BANG_(cljs.core.cst$kw$cljs$core_SLASH_none); +return ((function (pa){ +return (function() { +var G__5205 = null; +var G__5205__0 = (function (){ +return (rf.cljs$core$IFn$_invoke$arity$0 ? rf.cljs$core$IFn$_invoke$arity$0() : rf.call(null)); +}); +var G__5205__1 = (function (result){ +return (rf.cljs$core$IFn$_invoke$arity$1 ? rf.cljs$core$IFn$_invoke$arity$1(result) : rf.call(null,result)); +}); +var G__5205__2 = (function (result,input){ +var prior = cljs.core.deref(pa); +cljs.core.vreset_BANG_(pa,input); + +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(prior,input)){ +return result; +} else { +return (rf.cljs$core$IFn$_invoke$arity$2 ? rf.cljs$core$IFn$_invoke$arity$2(result,input) : rf.call(null,result,input)); +} +}); +G__5205 = function(result,input){ +switch(arguments.length){ +case 0: +return G__5205__0.call(this); +case 1: +return G__5205__1.call(this,result); +case 2: +return G__5205__2.call(this,result,input); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5205.cljs$core$IFn$_invoke$arity$0 = G__5205__0; +G__5205.cljs$core$IFn$_invoke$arity$1 = G__5205__1; +G__5205.cljs$core$IFn$_invoke$arity$2 = G__5205__2; +return G__5205; +})() +;})(pa)) +}); +}); + +cljs.core.dedupe.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +return cljs.core.sequence.cljs$core$IFn$_invoke$arity$2(cljs.core.dedupe.cljs$core$IFn$_invoke$arity$0(),coll); +}); + +cljs.core.dedupe.cljs$lang$maxFixedArity = 1; + +/** + * Returns items from coll with random probability of prob (0.0 - + * 1.0). Returns a transducer when no collection is provided. + */ +cljs.core.random_sample = (function cljs$core$random_sample(var_args){ +var G__5207 = arguments.length; +switch (G__5207) { +case 1: +return cljs.core.random_sample.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.random_sample.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.random_sample.cljs$core$IFn$_invoke$arity$1 = (function (prob){ +return cljs.core.filter.cljs$core$IFn$_invoke$arity$1((function (_){ +return (cljs.core.rand.cljs$core$IFn$_invoke$arity$0() < prob); +})); +}); + +cljs.core.random_sample.cljs$core$IFn$_invoke$arity$2 = (function (prob,coll){ +return cljs.core.filter.cljs$core$IFn$_invoke$arity$2((function (_){ +return (cljs.core.rand.cljs$core$IFn$_invoke$arity$0() < prob); +}),coll); +}); + +cljs.core.random_sample.cljs$lang$maxFixedArity = 2; + + +/** +* @constructor + * @implements {cljs.core.ISeqable} + * @implements {cljs.core.IPrintWithWriter} + * @implements {cljs.core.IIterable} + * @implements {cljs.core.ISequential} + * @implements {cljs.core.IReduce} +*/ +cljs.core.Eduction = (function (xform,coll){ +this.xform = xform; +this.coll = coll; +this.cljs$lang$protocol_mask$partition0$ = 2173173760; +this.cljs$lang$protocol_mask$partition1$ = 131072; +}); +cljs.core.Eduction.prototype.indexOf = (function() { +var G__5209 = null; +var G__5209__1 = (function (x){ +var self__ = this; +var coll__$1 = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll__$1,x,(0)); +}); +var G__5209__2 = (function (x,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core._indexOf.cljs$core$IFn$_invoke$arity$3(coll__$1,x,start); +}); +G__5209 = function(x,start){ +switch(arguments.length){ +case 1: +return G__5209__1.call(this,x); +case 2: +return G__5209__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5209.cljs$core$IFn$_invoke$arity$1 = G__5209__1; +G__5209.cljs$core$IFn$_invoke$arity$2 = G__5209__2; +return G__5209; +})() +; + +cljs.core.Eduction.prototype.lastIndexOf = (function() { +var G__5210 = null; +var G__5210__1 = (function (x){ +var self__ = this; +var coll__$1 = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll__$1,x,cljs.core.count(coll__$1)); +}); +var G__5210__2 = (function (x,start){ +var self__ = this; +var coll__$1 = this; +return cljs.core._lastIndexOf.cljs$core$IFn$_invoke$arity$3(coll__$1,x,start); +}); +G__5210 = function(x,start){ +switch(arguments.length){ +case 1: +return G__5210__1.call(this,x); +case 2: +return G__5210__2.call(this,x,start); +} +throw(new Error('Invalid arity: ' + arguments.length)); +}; +G__5210.cljs$core$IFn$_invoke$arity$1 = G__5210__1; +G__5210.cljs$core$IFn$_invoke$arity$2 = G__5210__2; +return G__5210; +})() +; + +cljs.core.Eduction.prototype.cljs$core$IIterable$_iterator$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return cljs.core.TransformerIterator.create(self__.xform,cljs.core.iter(self__.coll)); +}); + +cljs.core.Eduction.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return cljs.core.seq(cljs.core.sequence.cljs$core$IFn$_invoke$arity$2(self__.xform,self__.coll)); +}); + +cljs.core.Eduction.prototype.cljs$core$IReduce$_reduce$arity$2 = (function (_,f){ +var self__ = this; +var ___$1 = this; +return cljs.core.transduce.cljs$core$IFn$_invoke$arity$3(self__.xform,cljs.core.completing.cljs$core$IFn$_invoke$arity$1(f),self__.coll); +}); + +cljs.core.Eduction.prototype.cljs$core$IReduce$_reduce$arity$3 = (function (_,f,init){ +var self__ = this; +var ___$1 = this; +return cljs.core.transduce.cljs$core$IFn$_invoke$arity$4(self__.xform,cljs.core.completing.cljs$core$IFn$_invoke$arity$1(f),init,self__.coll); +}); + +cljs.core.Eduction.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (coll__$1,writer,opts){ +var self__ = this; +var coll__$2 = this; +return cljs.core.pr_sequential_writer(writer,cljs.core.pr_writer,"("," ",")",opts,coll__$2); +}); + +cljs.core.Eduction.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$xform,cljs.core.cst$sym$coll], null); +}); + +cljs.core.Eduction.cljs$lang$type = true; + +cljs.core.Eduction.cljs$lang$ctorStr = "cljs.core/Eduction"; + +cljs.core.Eduction.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Eduction"); +}); + +/** + * Positional factory function for cljs.core/Eduction. + */ +cljs.core.__GT_Eduction = (function cljs$core$__GT_Eduction(xform,coll){ +return (new cljs.core.Eduction(xform,coll)); +}); + +var G__5211_5214 = cljs.core.Eduction.prototype; +var G__5212_5215 = cljs.core.ITER_SYMBOL; +var G__5213_5216 = ((function (G__5211_5214,G__5212_5215){ +return (function (){ +var this__4669__auto__ = this; +return cljs.core.es6_iterator(this__4669__auto__); +});})(G__5211_5214,G__5212_5215)) +; +goog.object.set(G__5211_5214,G__5212_5215,G__5213_5216); +/** + * Returns a reducible/iterable application of the transducers + * to the items in coll. Transducers are applied in order as if + * combined with comp. Note that these applications will be + * performed every time reduce/iterator is called. + */ +cljs.core.eduction = (function cljs$core$eduction(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5218 = arguments.length; +var i__4731__auto___5219 = (0); +while(true){ +if((i__4731__auto___5219 < len__4730__auto___5218)){ +args__4736__auto__.push((arguments[i__4731__auto___5219])); + +var G__5220 = (i__4731__auto___5219 + (1)); +i__4731__auto___5219 = G__5220; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return cljs.core.eduction.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +cljs.core.eduction.cljs$core$IFn$_invoke$arity$variadic = (function (xforms){ +return (new cljs.core.Eduction(cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.comp,cljs.core.butlast(xforms)),cljs.core.last(xforms))); +}); + +cljs.core.eduction.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +cljs.core.eduction.cljs$lang$applyTo = (function (seq5217){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq5217)); +}); + +/** + * Runs the supplied procedure (via reduce), for purposes of side + * effects, on successive items in the collection. Returns nil + */ +cljs.core.run_BANG_ = (function cljs$core$run_BANG_(proc,coll){ +cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p1__5222_SHARP_,p2__5221_SHARP_){ +return (proc.cljs$core$IFn$_invoke$arity$1 ? proc.cljs$core$IFn$_invoke$arity$1(p2__5221_SHARP_) : proc.call(null,p2__5221_SHARP_)); +}),null,coll); + +return null; +}); + +/** + * @interface + */ +cljs.core.IEncodeJS = function(){}; + +/** + * Recursively transforms clj values to JavaScript + */ +cljs.core._clj__GT_js = (function cljs$core$_clj__GT_js(x){ +if((((!((x == null)))) && ((!((x.cljs$core$IEncodeJS$_clj__GT_js$arity$1 == null)))))){ +return x.cljs$core$IEncodeJS$_clj__GT_js$arity$1(x); +} else { +var x__4433__auto__ = (((x == null))?null:x); +var m__4434__auto__ = (cljs.core._clj__GT_js[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4434__auto__.call(null,x)); +} else { +var m__4431__auto__ = (cljs.core._clj__GT_js["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4431__auto__.call(null,x)); +} else { +throw cljs.core.missing_protocol("IEncodeJS.-clj->js",x); +} +} +} +}); + +/** + * Transforms map keys to valid JavaScript keys. Arbitrary keys are + * encoded to their string representation via (pr-str x) + */ +cljs.core._key__GT_js = (function cljs$core$_key__GT_js(x){ +if((((!((x == null)))) && ((!((x.cljs$core$IEncodeJS$_key__GT_js$arity$1 == null)))))){ +return x.cljs$core$IEncodeJS$_key__GT_js$arity$1(x); +} else { +var x__4433__auto__ = (((x == null))?null:x); +var m__4434__auto__ = (cljs.core._key__GT_js[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4434__auto__.call(null,x)); +} else { +var m__4431__auto__ = (cljs.core._key__GT_js["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(x) : m__4431__auto__.call(null,x)); +} else { +throw cljs.core.missing_protocol("IEncodeJS.-key->js",x); +} +} +} +}); + +cljs.core.key__GT_js = (function cljs$core$key__GT_js(var_args){ +var G__5224 = arguments.length; +switch (G__5224) { +case 1: +return cljs.core.key__GT_js.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.key__GT_js.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.key__GT_js.cljs$core$IFn$_invoke$arity$1 = (function (k){ +return cljs.core.key__GT_js.cljs$core$IFn$_invoke$arity$2(k,cljs.core.clj__GT_js); +}); + +cljs.core.key__GT_js.cljs$core$IFn$_invoke$arity$2 = (function (k,primitive_fn){ +if((((!((k == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === k.cljs$core$IEncodeJS$))))?true:(((!k.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_(cljs.core.IEncodeJS,k):false)):cljs.core.native_satisfies_QMARK_(cljs.core.IEncodeJS,k))){ +return cljs.core._clj__GT_js(k); +} else { +if(((typeof k === 'string') || (typeof k === 'number') || ((k instanceof cljs.core.Keyword)) || ((k instanceof cljs.core.Symbol)))){ +return (primitive_fn.cljs$core$IFn$_invoke$arity$1 ? primitive_fn.cljs$core$IFn$_invoke$arity$1(k) : primitive_fn.call(null,k)); +} else { +return cljs.core.pr_str.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([k], 0)); + +} +} +}); + +cljs.core.key__GT_js.cljs$lang$maxFixedArity = 2; + +/** + * Recursively transforms ClojureScript values to JavaScript. + * sets/vectors/lists become Arrays, Keywords and Symbol become Strings, + * Maps become Objects. Arbitrary keys are encoded to by `key->js`. + * Options is a key-value pair, where the only valid key is + * :keyword-fn, which should point to a single-argument function to be + * called on keyword keys. Default to `name`. + */ +cljs.core.clj__GT_js = (function cljs$core$clj__GT_js(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5302 = arguments.length; +var i__4731__auto___5303 = (0); +while(true){ +if((i__4731__auto___5303 < len__4730__auto___5302)){ +args__4736__auto__.push((arguments[i__4731__auto___5303])); + +var G__5304 = (i__4731__auto___5303 + (1)); +i__4731__auto___5303 = G__5304; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null); +return cljs.core.clj__GT_js.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__); +}); + +cljs.core.clj__GT_js.cljs$core$IFn$_invoke$arity$variadic = (function (x,p__5229){ +var map__5230 = p__5229; +var map__5230__$1 = (((((!((map__5230 == null))))?(((((map__5230.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__5230.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__5230):map__5230); +var options = map__5230__$1; +var keyword_fn = cljs.core.get.cljs$core$IFn$_invoke$arity$3(map__5230__$1,cljs.core.cst$kw$keyword_DASH_fn,cljs.core.name); +var keyfn = ((function (map__5230,map__5230__$1,options,keyword_fn){ +return (function cljs$core$keyfn(k){ +return cljs.core.key__GT_js.cljs$core$IFn$_invoke$arity$2(k,thisfn); +});})(map__5230,map__5230__$1,options,keyword_fn)) +; +var thisfn = ((function (map__5230,map__5230__$1,options,keyword_fn){ +return (function cljs$core$thisfn(x__$1){ +if((x__$1 == null)){ +return null; +} else { +if((((!((x__$1 == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === x__$1.cljs$core$IEncodeJS$))))?true:(((!x__$1.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_(cljs.core.IEncodeJS,x__$1):false)):cljs.core.native_satisfies_QMARK_(cljs.core.IEncodeJS,x__$1))){ +return cljs.core._clj__GT_js(x__$1); +} else { +if((x__$1 instanceof cljs.core.Keyword)){ +return (keyword_fn.cljs$core$IFn$_invoke$arity$1 ? keyword_fn.cljs$core$IFn$_invoke$arity$1(x__$1) : keyword_fn.call(null,x__$1)); +} else { +if((x__$1 instanceof cljs.core.Symbol)){ +return cljs.core.str.cljs$core$IFn$_invoke$arity$1(x__$1); +} else { +if(cljs.core.map_QMARK_(x__$1)){ +var m = ({}); +var seq__5270_5305 = cljs.core.seq(x__$1); +var chunk__5271_5306 = null; +var count__5272_5307 = (0); +var i__5273_5308 = (0); +while(true){ +if((i__5273_5308 < count__5272_5307)){ +var vec__5286_5309 = chunk__5271_5306.cljs$core$IIndexed$_nth$arity$2(null,i__5273_5308); +var k_5310 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5286_5309,(0),null); +var v_5311 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5286_5309,(1),null); +var G__5289_5312 = m; +var G__5290_5313 = keyfn(k_5310); +var G__5291_5314 = cljs$core$thisfn(v_5311); +goog.object.set(G__5289_5312,G__5290_5313,G__5291_5314); + + +var G__5315 = seq__5270_5305; +var G__5316 = chunk__5271_5306; +var G__5317 = count__5272_5307; +var G__5318 = (i__5273_5308 + (1)); +seq__5270_5305 = G__5315; +chunk__5271_5306 = G__5316; +count__5272_5307 = G__5317; +i__5273_5308 = G__5318; +continue; +} else { +var temp__5735__auto___5319 = cljs.core.seq(seq__5270_5305); +if(temp__5735__auto___5319){ +var seq__5270_5320__$1 = temp__5735__auto___5319; +if(cljs.core.chunked_seq_QMARK_(seq__5270_5320__$1)){ +var c__4550__auto___5321 = cljs.core.chunk_first(seq__5270_5320__$1); +var G__5322 = cljs.core.chunk_rest(seq__5270_5320__$1); +var G__5323 = c__4550__auto___5321; +var G__5324 = cljs.core.count(c__4550__auto___5321); +var G__5325 = (0); +seq__5270_5305 = G__5322; +chunk__5271_5306 = G__5323; +count__5272_5307 = G__5324; +i__5273_5308 = G__5325; +continue; +} else { +var vec__5292_5326 = cljs.core.first(seq__5270_5320__$1); +var k_5327 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5292_5326,(0),null); +var v_5328 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5292_5326,(1),null); +var G__5295_5329 = m; +var G__5296_5330 = keyfn(k_5327); +var G__5297_5331 = cljs$core$thisfn(v_5328); +goog.object.set(G__5295_5329,G__5296_5330,G__5297_5331); + + +var G__5332 = cljs.core.next(seq__5270_5320__$1); +var G__5333 = null; +var G__5334 = (0); +var G__5335 = (0); +seq__5270_5305 = G__5332; +chunk__5271_5306 = G__5333; +count__5272_5307 = G__5334; +i__5273_5308 = G__5335; +continue; +} +} else { +} +} +break; +} + +return m; +} else { +if(cljs.core.coll_QMARK_(x__$1)){ +var arr = []; +var seq__5298_5336 = cljs.core.seq(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs$core$thisfn,x__$1)); +var chunk__5299_5337 = null; +var count__5300_5338 = (0); +var i__5301_5339 = (0); +while(true){ +if((i__5301_5339 < count__5300_5338)){ +var x_5340__$2 = chunk__5299_5337.cljs$core$IIndexed$_nth$arity$2(null,i__5301_5339); +arr.push(x_5340__$2); + + +var G__5341 = seq__5298_5336; +var G__5342 = chunk__5299_5337; +var G__5343 = count__5300_5338; +var G__5344 = (i__5301_5339 + (1)); +seq__5298_5336 = G__5341; +chunk__5299_5337 = G__5342; +count__5300_5338 = G__5343; +i__5301_5339 = G__5344; +continue; +} else { +var temp__5735__auto___5345 = cljs.core.seq(seq__5298_5336); +if(temp__5735__auto___5345){ +var seq__5298_5346__$1 = temp__5735__auto___5345; +if(cljs.core.chunked_seq_QMARK_(seq__5298_5346__$1)){ +var c__4550__auto___5347 = cljs.core.chunk_first(seq__5298_5346__$1); +var G__5348 = cljs.core.chunk_rest(seq__5298_5346__$1); +var G__5349 = c__4550__auto___5347; +var G__5350 = cljs.core.count(c__4550__auto___5347); +var G__5351 = (0); +seq__5298_5336 = G__5348; +chunk__5299_5337 = G__5349; +count__5300_5338 = G__5350; +i__5301_5339 = G__5351; +continue; +} else { +var x_5352__$2 = cljs.core.first(seq__5298_5346__$1); +arr.push(x_5352__$2); + + +var G__5353 = cljs.core.next(seq__5298_5346__$1); +var G__5354 = null; +var G__5355 = (0); +var G__5356 = (0); +seq__5298_5336 = G__5353; +chunk__5299_5337 = G__5354; +count__5300_5338 = G__5355; +i__5301_5339 = G__5356; +continue; +} +} else { +} +} +break; +} + +return arr; +} else { +return x__$1; + +} +} +} +} +} +} +});})(map__5230,map__5230__$1,options,keyword_fn)) +; +return thisfn(x); +}); + +cljs.core.clj__GT_js.cljs$lang$maxFixedArity = (1); + +/** @this {Function} */ +cljs.core.clj__GT_js.cljs$lang$applyTo = (function (seq5227){ +var G__5228 = cljs.core.first(seq5227); +var seq5227__$1 = cljs.core.next(seq5227); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__5228,seq5227__$1); +}); + + +/** + * @interface + */ +cljs.core.IEncodeClojure = function(){}; + +/** + * Transforms JavaScript values to Clojure + */ +cljs.core._js__GT_clj = (function cljs$core$_js__GT_clj(x,options){ +if((((!((x == null)))) && ((!((x.cljs$core$IEncodeClojure$_js__GT_clj$arity$2 == null)))))){ +return x.cljs$core$IEncodeClojure$_js__GT_clj$arity$2(x,options); +} else { +var x__4433__auto__ = (((x == null))?null:x); +var m__4434__auto__ = (cljs.core._js__GT_clj[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(x,options) : m__4434__auto__.call(null,x,options)); +} else { +var m__4431__auto__ = (cljs.core._js__GT_clj["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(x,options) : m__4431__auto__.call(null,x,options)); +} else { +throw cljs.core.missing_protocol("IEncodeClojure.-js->clj",x); +} +} +} +}); + +/** + * Recursively transforms JavaScript arrays into ClojureScript + * vectors, and JavaScript objects into ClojureScript maps. With + * option ':keywordize-keys true' will convert object fields from + * strings to keywords. + */ +cljs.core.js__GT_clj = (function cljs$core$js__GT_clj(var_args){ +var G__5362 = arguments.length; +switch (G__5362) { +case 1: +return cljs.core.js__GT_clj.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___5367 = arguments.length; +var i__4731__auto___5368 = (0); +while(true){ +if((i__4731__auto___5368 < len__4730__auto___5367)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___5368])); + +var G__5369 = (i__4731__auto___5368 + (1)); +i__4731__auto___5368 = G__5369; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((1)),(0),null)); +return cljs.core.js__GT_clj.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4752__auto__); + +} +}); + +cljs.core.js__GT_clj.cljs$core$IFn$_invoke$arity$1 = (function (x){ +return cljs.core.js__GT_clj.cljs$core$IFn$_invoke$arity$variadic(x,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([cljs.core.cst$kw$keywordize_DASH_keys,false], 0)); +}); + +cljs.core.js__GT_clj.cljs$core$IFn$_invoke$arity$variadic = (function (x,opts){ +var map__5363 = opts; +var map__5363__$1 = (((((!((map__5363 == null))))?(((((map__5363.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__5363.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.hash_map,map__5363):map__5363); +var keywordize_keys = cljs.core.get.cljs$core$IFn$_invoke$arity$2(map__5363__$1,cljs.core.cst$kw$keywordize_DASH_keys); +var keyfn = (cljs.core.truth_(keywordize_keys)?cljs.core.keyword:cljs.core.str); +var f = ((function (map__5363,map__5363__$1,keywordize_keys,keyfn){ +return (function cljs$core$thisfn(x__$1){ +if((((!((x__$1 == null))))?((((false) || ((cljs.core.PROTOCOL_SENTINEL === x__$1.cljs$core$IEncodeClojure$))))?true:(((!x__$1.cljs$lang$protocol_mask$partition$))?cljs.core.native_satisfies_QMARK_(cljs.core.IEncodeClojure,x__$1):false)):cljs.core.native_satisfies_QMARK_(cljs.core.IEncodeClojure,x__$1))){ +return cljs.core._js__GT_clj(x__$1,cljs.core.apply.cljs$core$IFn$_invoke$arity$2(cljs.core.array_map,opts)); +} else { +if(cljs.core.seq_QMARK_(x__$1)){ +return cljs.core.doall.cljs$core$IFn$_invoke$arity$1(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs$core$thisfn,x__$1)); +} else { +if(cljs.core.map_entry_QMARK_(x__$1)){ +return (new cljs.core.MapEntry(cljs$core$thisfn(cljs.core.key(x__$1)),cljs$core$thisfn(cljs.core.val(x__$1)),null)); +} else { +if(cljs.core.coll_QMARK_(x__$1)){ +return cljs.core.into.cljs$core$IFn$_invoke$arity$3(cljs.core.empty(x__$1),cljs.core.map.cljs$core$IFn$_invoke$arity$1(cljs$core$thisfn),x__$1); +} else { +if(cljs.core.array_QMARK_(x__$1)){ +return cljs.core.persistent_BANG_(cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (map__5363,map__5363__$1,keywordize_keys,keyfn){ +return (function (p1__5357_SHARP_,p2__5358_SHARP_){ +return cljs.core.conj_BANG_.cljs$core$IFn$_invoke$arity$2(p1__5357_SHARP_,cljs$core$thisfn(p2__5358_SHARP_)); +});})(map__5363,map__5363__$1,keywordize_keys,keyfn)) +,cljs.core.transient$(cljs.core.PersistentVector.EMPTY),x__$1)); +} else { +if((cljs.core.type(x__$1) === Object)){ +return cljs.core.persistent_BANG_(cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (map__5363,map__5363__$1,keywordize_keys,keyfn){ +return (function (r,k){ +return cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(r,(keyfn.cljs$core$IFn$_invoke$arity$1 ? keyfn.cljs$core$IFn$_invoke$arity$1(k) : keyfn.call(null,k)),cljs$core$thisfn(goog.object.get(x__$1,k))); +});})(map__5363,map__5363__$1,keywordize_keys,keyfn)) +,cljs.core.transient$(cljs.core.PersistentArrayMap.EMPTY),cljs.core.js_keys(x__$1))); +} else { +return x__$1; + +} +} +} +} +} +} +});})(map__5363,map__5363__$1,keywordize_keys,keyfn)) +; +return f(x); +}); + +/** @this {Function} */ +cljs.core.js__GT_clj.cljs$lang$applyTo = (function (seq5360){ +var G__5361 = cljs.core.first(seq5360); +var seq5360__$1 = cljs.core.next(seq5360); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__5361,seq5360__$1); +}); + +cljs.core.js__GT_clj.cljs$lang$maxFixedArity = (1); + +/** + * Returns a memoized version of a referentially transparent function. The + * memoized version of the function keeps a cache of the mapping from arguments + * to results and, when calls with the same arguments are repeated often, has + * higher performance at the expense of higher memory use. + */ +cljs.core.memoize = (function cljs$core$memoize(f){ +var mem = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentArrayMap.EMPTY); +return ((function (mem){ +return (function() { +var G__5370__delegate = function (args){ +var v = cljs.core.get.cljs$core$IFn$_invoke$arity$3(cljs.core.deref(mem),args,cljs.core.lookup_sentinel); +if((v === cljs.core.lookup_sentinel)){ +var ret = cljs.core.apply.cljs$core$IFn$_invoke$arity$2(f,args); +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(mem,cljs.core.assoc,args,ret); + +return ret; +} else { +return v; +} +}; +var G__5370 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__5371__i = 0, G__5371__a = new Array(arguments.length - 0); +while (G__5371__i < G__5371__a.length) {G__5371__a[G__5371__i] = arguments[G__5371__i + 0]; ++G__5371__i;} + args = new cljs.core.IndexedSeq(G__5371__a,0,null); +} +return G__5370__delegate.call(this,args);}; +G__5370.cljs$lang$maxFixedArity = 0; +G__5370.cljs$lang$applyTo = (function (arglist__5372){ +var args = cljs.core.seq(arglist__5372); +return G__5370__delegate(args); +}); +G__5370.cljs$core$IFn$_invoke$arity$variadic = G__5370__delegate; +return G__5370; +})() +; +;})(mem)) +}); +/** + * trampoline can be used to convert algorithms requiring mutual + * recursion without stack consumption. Calls f with supplied args, if + * any. If f returns a fn, calls that fn with no arguments, and + * continues to repeat, until the return value is not a fn, then + * returns that non-fn value. Note that if you want to return a fn as a + * final value, you must wrap it in some data structure and unpack it + * after trampoline returns. + */ +cljs.core.trampoline = (function cljs$core$trampoline(var_args){ +var G__5376 = arguments.length; +switch (G__5376) { +case 1: +return cljs.core.trampoline.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +var args_arr__4751__auto__ = []; +var len__4730__auto___5378 = arguments.length; +var i__4731__auto___5379 = (0); +while(true){ +if((i__4731__auto___5379 < len__4730__auto___5378)){ +args_arr__4751__auto__.push((arguments[i__4731__auto___5379])); + +var G__5380 = (i__4731__auto___5379 + (1)); +i__4731__auto___5379 = G__5380; +continue; +} else { +} +break; +} + +var argseq__4752__auto__ = (new cljs.core.IndexedSeq(args_arr__4751__auto__.slice((1)),(0),null)); +return cljs.core.trampoline.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4752__auto__); + +} +}); + +cljs.core.trampoline.cljs$core$IFn$_invoke$arity$1 = (function (f){ +while(true){ +var ret = (f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); +if(cljs.core.fn_QMARK_(ret)){ +var G__5381 = ret; +f = G__5381; +continue; +} else { +return ret; +} +break; +} +}); + +cljs.core.trampoline.cljs$core$IFn$_invoke$arity$variadic = (function (f,args){ +return cljs.core.trampoline.cljs$core$IFn$_invoke$arity$1((function (){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(f,args); +})); +}); + +/** @this {Function} */ +cljs.core.trampoline.cljs$lang$applyTo = (function (seq5374){ +var G__5375 = cljs.core.first(seq5374); +var seq5374__$1 = cljs.core.next(seq5374); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__5375,seq5374__$1); +}); + +cljs.core.trampoline.cljs$lang$maxFixedArity = (1); + +/** + * Returns a random floating point number between 0 (inclusive) and + * n (default 1) (exclusive). + */ +cljs.core.rand = (function cljs$core$rand(var_args){ +var G__5383 = arguments.length; +switch (G__5383) { +case 0: +return cljs.core.rand.cljs$core$IFn$_invoke$arity$0(); + +break; +case 1: +return cljs.core.rand.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.rand.cljs$core$IFn$_invoke$arity$0 = (function (){ +return cljs.core.rand.cljs$core$IFn$_invoke$arity$1((1)); +}); + +cljs.core.rand.cljs$core$IFn$_invoke$arity$1 = (function (n){ +return (Math.random() * n); +}); + +cljs.core.rand.cljs$lang$maxFixedArity = 1; + +/** + * Returns a random integer between 0 (inclusive) and n (exclusive). + */ +cljs.core.rand_int = (function cljs$core$rand_int(n){ +var G__5385 = (Math.random() * n); +return Math.floor(G__5385); +}); +/** + * Return a random element of the (sequential) collection. Will have + * the same performance characteristics as nth for the given + * collection. + */ +cljs.core.rand_nth = (function cljs$core$rand_nth(coll){ +return cljs.core.nth.cljs$core$IFn$_invoke$arity$2(coll,cljs.core.rand_int(cljs.core.count(coll))); +}); +/** + * Returns a map of the elements of coll keyed by the result of + * f on each element. The value at each key will be a vector of the + * corresponding elements, in the order they appeared in coll. + */ +cljs.core.group_by = (function cljs$core$group_by(f,coll){ +return cljs.core.persistent_BANG_(cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (ret,x){ +var k = (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(x) : f.call(null,x)); +return cljs.core.assoc_BANG_.cljs$core$IFn$_invoke$arity$3(ret,k,cljs.core.conj.cljs$core$IFn$_invoke$arity$2(cljs.core.get.cljs$core$IFn$_invoke$arity$3(ret,k,cljs.core.PersistentVector.EMPTY),x)); +}),cljs.core.transient$(cljs.core.PersistentArrayMap.EMPTY),coll)); +}); +/** + * Creates a hierarchy object for use with derive, isa? etc. + */ +cljs.core.make_hierarchy = (function cljs$core$make_hierarchy(){ +return new cljs.core.PersistentArrayMap(null, 3, [cljs.core.cst$kw$parents,cljs.core.PersistentArrayMap.EMPTY,cljs.core.cst$kw$descendants,cljs.core.PersistentArrayMap.EMPTY,cljs.core.cst$kw$ancestors,cljs.core.PersistentArrayMap.EMPTY], null); +}); +/** + * @type {*} + */ +cljs.core._global_hierarchy = null; +cljs.core.get_global_hierarchy = (function cljs$core$get_global_hierarchy(){ +if((cljs.core._global_hierarchy == null)){ +cljs.core._global_hierarchy = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.make_hierarchy()); +} else { +} + +return cljs.core._global_hierarchy; +}); +cljs.core.swap_global_hierarchy_BANG_ = (function cljs$core$swap_global_hierarchy_BANG_(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___5388 = arguments.length; +var i__4731__auto___5389 = (0); +while(true){ +if((i__4731__auto___5389 < len__4730__auto___5388)){ +args__4736__auto__.push((arguments[i__4731__auto___5389])); + +var G__5390 = (i__4731__auto___5389 + (1)); +i__4731__auto___5389 = G__5390; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((1) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((1)),(0),null)):null); +return cljs.core.swap_global_hierarchy_BANG_.cljs$core$IFn$_invoke$arity$variadic((arguments[(0)]),argseq__4737__auto__); +}); + +cljs.core.swap_global_hierarchy_BANG_.cljs$core$IFn$_invoke$arity$variadic = (function (f,args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$4(cljs.core.swap_BANG_,cljs.core.get_global_hierarchy(),f,args); +}); + +cljs.core.swap_global_hierarchy_BANG_.cljs$lang$maxFixedArity = (1); + +/** @this {Function} */ +cljs.core.swap_global_hierarchy_BANG_.cljs$lang$applyTo = (function (seq5386){ +var G__5387 = cljs.core.first(seq5386); +var seq5386__$1 = cljs.core.next(seq5386); +var self__4717__auto__ = this; +return self__4717__auto__.cljs$core$IFn$_invoke$arity$variadic(G__5387,seq5386__$1); +}); + +/** + * Returns true if (= child parent), or child is directly or indirectly derived from + * parent, either via a JavaScript type inheritance relationship or a + * relationship established via derive. h must be a hierarchy obtained + * from make-hierarchy, if not supplied defaults to the global + * hierarchy + */ +cljs.core.isa_QMARK_ = (function cljs$core$isa_QMARK_(var_args){ +var G__5392 = arguments.length; +switch (G__5392) { +case 2: +return cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$2 = (function (child,parent){ +return cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$3(cljs.core.deref(cljs.core.get_global_hierarchy()),child,parent); +}); + +cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$3 = (function (h,child,parent){ +var or__4131__auto__ = cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(child,parent); +if(or__4131__auto__){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = cljs.core.contains_QMARK_((function (){var fexpr__5395 = cljs.core.cst$kw$ancestors.cljs$core$IFn$_invoke$arity$1(h); +return (fexpr__5395.cljs$core$IFn$_invoke$arity$1 ? fexpr__5395.cljs$core$IFn$_invoke$arity$1(child) : fexpr__5395.call(null,child)); +})(),parent); +if(or__4131__auto____$1){ +return or__4131__auto____$1; +} else { +var and__4120__auto__ = cljs.core.vector_QMARK_(parent); +if(and__4120__auto__){ +var and__4120__auto____$1 = cljs.core.vector_QMARK_(child); +if(and__4120__auto____$1){ +var and__4120__auto____$2 = (cljs.core.count(parent) === cljs.core.count(child)); +if(and__4120__auto____$2){ +var ret = true; +var i = (0); +while(true){ +if((((!(ret))) || ((i === cljs.core.count(parent))))){ +return ret; +} else { +var G__5397 = cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$3(h,(child.cljs$core$IFn$_invoke$arity$1 ? child.cljs$core$IFn$_invoke$arity$1(i) : child.call(null,i)),(parent.cljs$core$IFn$_invoke$arity$1 ? parent.cljs$core$IFn$_invoke$arity$1(i) : parent.call(null,i))); +var G__5398 = (i + (1)); +ret = G__5397; +i = G__5398; +continue; +} +break; +} +} else { +return and__4120__auto____$2; +} +} else { +return and__4120__auto____$1; +} +} else { +return and__4120__auto__; +} +} +} +}); + +cljs.core.isa_QMARK_.cljs$lang$maxFixedArity = 3; + +/** + * Returns the immediate parents of tag, either via a JavaScript type + * inheritance relationship or a relationship established via derive. h + * must be a hierarchy obtained from make-hierarchy, if not supplied + * defaults to the global hierarchy + */ +cljs.core.parents = (function cljs$core$parents(var_args){ +var G__5400 = arguments.length; +switch (G__5400) { +case 1: +return cljs.core.parents.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.parents.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.parents.cljs$core$IFn$_invoke$arity$1 = (function (tag){ +return cljs.core.parents.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(cljs.core.get_global_hierarchy()),tag); +}); + +cljs.core.parents.cljs$core$IFn$_invoke$arity$2 = (function (h,tag){ +return cljs.core.not_empty(cljs.core.get.cljs$core$IFn$_invoke$arity$2(cljs.core.cst$kw$parents.cljs$core$IFn$_invoke$arity$1(h),tag)); +}); + +cljs.core.parents.cljs$lang$maxFixedArity = 2; + +/** + * Returns the immediate and indirect parents of tag, either via a JavaScript type + * inheritance relationship or a relationship established via derive. h + * must be a hierarchy obtained from make-hierarchy, if not supplied + * defaults to the global hierarchy + */ +cljs.core.ancestors = (function cljs$core$ancestors(var_args){ +var G__5403 = arguments.length; +switch (G__5403) { +case 1: +return cljs.core.ancestors.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.ancestors.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.ancestors.cljs$core$IFn$_invoke$arity$1 = (function (tag){ +return cljs.core.ancestors.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(cljs.core.get_global_hierarchy()),tag); +}); + +cljs.core.ancestors.cljs$core$IFn$_invoke$arity$2 = (function (h,tag){ +return cljs.core.not_empty(cljs.core.get.cljs$core$IFn$_invoke$arity$2(cljs.core.cst$kw$ancestors.cljs$core$IFn$_invoke$arity$1(h),tag)); +}); + +cljs.core.ancestors.cljs$lang$maxFixedArity = 2; + +/** + * Returns the immediate and indirect children of tag, through a + * relationship established via derive. h must be a hierarchy obtained + * from make-hierarchy, if not supplied defaults to the global + * hierarchy. Note: does not work on JavaScript type inheritance + * relationships. + */ +cljs.core.descendants = (function cljs$core$descendants(var_args){ +var G__5406 = arguments.length; +switch (G__5406) { +case 1: +return cljs.core.descendants.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.descendants.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.descendants.cljs$core$IFn$_invoke$arity$1 = (function (tag){ +return cljs.core.descendants.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(cljs.core.get_global_hierarchy()),tag); +}); + +cljs.core.descendants.cljs$core$IFn$_invoke$arity$2 = (function (h,tag){ +return cljs.core.not_empty(cljs.core.get.cljs$core$IFn$_invoke$arity$2(cljs.core.cst$kw$descendants.cljs$core$IFn$_invoke$arity$1(h),tag)); +}); + +cljs.core.descendants.cljs$lang$maxFixedArity = 2; + +/** + * Establishes a parent/child relationship between parent and + * tag. Parent must be a namespace-qualified symbol or keyword and + * child can be either a namespace-qualified symbol or keyword or a + * class. h must be a hierarchy obtained from make-hierarchy, if not + * supplied defaults to, and modifies, the global hierarchy. + */ +cljs.core.derive = (function cljs$core$derive(var_args){ +var G__5409 = arguments.length; +switch (G__5409) { +case 2: +return cljs.core.derive.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.derive.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.derive.cljs$core$IFn$_invoke$arity$2 = (function (tag,parent){ +if(cljs.core.truth_(cljs.core.namespace(parent))){ +} else { +throw (new Error("Assert failed: (namespace parent)")); +} + +cljs.core.swap_global_hierarchy_BANG_.cljs$core$IFn$_invoke$arity$variadic(cljs.core.derive,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([tag,parent], 0)); + +return null; +}); + +cljs.core.derive.cljs$core$IFn$_invoke$arity$3 = (function (h,tag,parent){ +if(cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2(tag,parent)){ +} else { +throw (new Error("Assert failed: (not= tag parent)")); +} + +var tp = cljs.core.cst$kw$parents.cljs$core$IFn$_invoke$arity$1(h); +var td = cljs.core.cst$kw$descendants.cljs$core$IFn$_invoke$arity$1(h); +var ta = cljs.core.cst$kw$ancestors.cljs$core$IFn$_invoke$arity$1(h); +var tf = ((function (tp,td,ta){ +return (function (m,source,sources,target,targets){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (tp,td,ta){ +return (function (ret,k){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(ret,k,cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.conj,cljs.core.get.cljs$core$IFn$_invoke$arity$3(targets,k,cljs.core.PersistentHashSet.EMPTY),cljs.core.cons(target,(targets.cljs$core$IFn$_invoke$arity$1 ? targets.cljs$core$IFn$_invoke$arity$1(target) : targets.call(null,target))))); +});})(tp,td,ta)) +,m,cljs.core.cons(source,(sources.cljs$core$IFn$_invoke$arity$1 ? sources.cljs$core$IFn$_invoke$arity$1(source) : sources.call(null,source)))); +});})(tp,td,ta)) +; +var or__4131__auto__ = ((cljs.core.contains_QMARK_((tp.cljs$core$IFn$_invoke$arity$1 ? tp.cljs$core$IFn$_invoke$arity$1(tag) : tp.call(null,tag)),parent))?null:(function (){ +if(cljs.core.contains_QMARK_((ta.cljs$core$IFn$_invoke$arity$1 ? ta.cljs$core$IFn$_invoke$arity$1(tag) : ta.call(null,tag)),parent)){ +throw (new Error([cljs.core.str.cljs$core$IFn$_invoke$arity$1(tag),"already has",cljs.core.str.cljs$core$IFn$_invoke$arity$1(parent),"as ancestor"].join(''))); +} else { +} + +if(cljs.core.contains_QMARK_((ta.cljs$core$IFn$_invoke$arity$1 ? ta.cljs$core$IFn$_invoke$arity$1(parent) : ta.call(null,parent)),tag)){ +throw (new Error(["Cyclic derivation:",cljs.core.str.cljs$core$IFn$_invoke$arity$1(parent),"has",cljs.core.str.cljs$core$IFn$_invoke$arity$1(tag),"as ancestor"].join(''))); +} else { +} + +return new cljs.core.PersistentArrayMap(null, 3, [cljs.core.cst$kw$parents,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(cljs.core.cst$kw$parents.cljs$core$IFn$_invoke$arity$1(h),tag,cljs.core.conj.cljs$core$IFn$_invoke$arity$2(cljs.core.get.cljs$core$IFn$_invoke$arity$3(tp,tag,cljs.core.PersistentHashSet.EMPTY),parent)),cljs.core.cst$kw$ancestors,tf(cljs.core.cst$kw$ancestors.cljs$core$IFn$_invoke$arity$1(h),tag,td,parent,ta),cljs.core.cst$kw$descendants,tf(cljs.core.cst$kw$descendants.cljs$core$IFn$_invoke$arity$1(h),parent,ta,tag,td)], null); +})() +); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return h; +} +}); + +cljs.core.derive.cljs$lang$maxFixedArity = 3; + +/** + * Removes a parent/child relationship between parent and + * tag. h must be a hierarchy obtained from make-hierarchy, if not + * supplied defaults to, and modifies, the global hierarchy. + */ +cljs.core.underive = (function cljs$core$underive(var_args){ +var G__5415 = arguments.length; +switch (G__5415) { +case 2: +return cljs.core.underive.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.underive.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.underive.cljs$core$IFn$_invoke$arity$2 = (function (tag,parent){ +cljs.core.swap_global_hierarchy_BANG_.cljs$core$IFn$_invoke$arity$variadic(cljs.core.underive,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([tag,parent], 0)); + +return null; +}); + +cljs.core.underive.cljs$core$IFn$_invoke$arity$3 = (function (h,tag,parent){ +var parentMap = cljs.core.cst$kw$parents.cljs$core$IFn$_invoke$arity$1(h); +var childsParents = (cljs.core.truth_((parentMap.cljs$core$IFn$_invoke$arity$1 ? parentMap.cljs$core$IFn$_invoke$arity$1(tag) : parentMap.call(null,tag)))?cljs.core.disj.cljs$core$IFn$_invoke$arity$2((parentMap.cljs$core$IFn$_invoke$arity$1 ? parentMap.cljs$core$IFn$_invoke$arity$1(tag) : parentMap.call(null,tag)),parent):cljs.core.PersistentHashSet.EMPTY); +var newParents = (cljs.core.truth_(cljs.core.not_empty(childsParents))?cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(parentMap,tag,childsParents):cljs.core.dissoc.cljs$core$IFn$_invoke$arity$2(parentMap,tag)); +var deriv_seq = cljs.core.flatten(cljs.core.map.cljs$core$IFn$_invoke$arity$2(((function (parentMap,childsParents,newParents){ +return (function (p1__5411_SHARP_){ +return cljs.core.cons(cljs.core.first(p1__5411_SHARP_),cljs.core.interpose.cljs$core$IFn$_invoke$arity$2(cljs.core.first(p1__5411_SHARP_),cljs.core.second(p1__5411_SHARP_))); +});})(parentMap,childsParents,newParents)) +,cljs.core.seq(newParents))); +if(cljs.core.contains_QMARK_((parentMap.cljs$core$IFn$_invoke$arity$1 ? parentMap.cljs$core$IFn$_invoke$arity$1(tag) : parentMap.call(null,tag)),parent)){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(((function (parentMap,childsParents,newParents,deriv_seq){ +return (function (p1__5412_SHARP_,p2__5413_SHARP_){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$3(cljs.core.derive,p1__5412_SHARP_,p2__5413_SHARP_); +});})(parentMap,childsParents,newParents,deriv_seq)) +,cljs.core.make_hierarchy(),cljs.core.partition.cljs$core$IFn$_invoke$arity$2((2),deriv_seq)); +} else { +return h; +} +}); + +cljs.core.underive.cljs$lang$maxFixedArity = 3; + +cljs.core.reset_cache = (function cljs$core$reset_cache(method_cache,method_table,cached_hierarchy,hierarchy){ +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(method_cache,(function (_){ +return cljs.core.deref(method_table); +})); + +return cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(cached_hierarchy,(function (_){ +return cljs.core.deref(hierarchy); +})); +}); +cljs.core.prefers_STAR_ = (function cljs$core$prefers_STAR_(x,y,prefer_table){ +var xprefs = (function (){var fexpr__5417 = cljs.core.deref(prefer_table); +return (fexpr__5417.cljs$core$IFn$_invoke$arity$1 ? fexpr__5417.cljs$core$IFn$_invoke$arity$1(x) : fexpr__5417.call(null,x)); +})(); +var or__4131__auto__ = (cljs.core.truth_((function (){var and__4120__auto__ = xprefs; +if(cljs.core.truth_(and__4120__auto__)){ +return (xprefs.cljs$core$IFn$_invoke$arity$1 ? xprefs.cljs$core$IFn$_invoke$arity$1(y) : xprefs.call(null,y)); +} else { +return and__4120__auto__; +} +})())?true:null); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +var or__4131__auto____$1 = (function (){var ps = cljs.core.parents.cljs$core$IFn$_invoke$arity$1(y); +while(true){ +if((cljs.core.count(ps) > (0))){ +if(cljs.core.truth_((function (){var G__5421 = x; +var G__5422 = cljs.core.first(ps); +var G__5423 = prefer_table; +return (cljs.core.prefers_STAR_.cljs$core$IFn$_invoke$arity$3 ? cljs.core.prefers_STAR_.cljs$core$IFn$_invoke$arity$3(G__5421,G__5422,G__5423) : cljs.core.prefers_STAR_.call(null,G__5421,G__5422,G__5423)); +})())){ +} else { +} + +var G__5430 = cljs.core.rest(ps); +ps = G__5430; +continue; +} else { +return null; +} +break; +} +})(); +if(cljs.core.truth_(or__4131__auto____$1)){ +return or__4131__auto____$1; +} else { +var or__4131__auto____$2 = (function (){var ps = cljs.core.parents.cljs$core$IFn$_invoke$arity$1(x); +while(true){ +if((cljs.core.count(ps) > (0))){ +if(cljs.core.truth_((function (){var G__5427 = cljs.core.first(ps); +var G__5428 = y; +var G__5429 = prefer_table; +return (cljs.core.prefers_STAR_.cljs$core$IFn$_invoke$arity$3 ? cljs.core.prefers_STAR_.cljs$core$IFn$_invoke$arity$3(G__5427,G__5428,G__5429) : cljs.core.prefers_STAR_.call(null,G__5427,G__5428,G__5429)); +})())){ +} else { +} + +var G__5431 = cljs.core.rest(ps); +ps = G__5431; +continue; +} else { +return null; +} +break; +} +})(); +if(cljs.core.truth_(or__4131__auto____$2)){ +return or__4131__auto____$2; +} else { +return false; +} +} +} +}); +cljs.core.dominates = (function cljs$core$dominates(x,y,prefer_table,hierarchy){ +var or__4131__auto__ = cljs.core.prefers_STAR_(x,y,prefer_table); +if(cljs.core.truth_(or__4131__auto__)){ +return or__4131__auto__; +} else { +return cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$3(hierarchy,x,y); +} +}); +cljs.core.find_and_cache_best_method = (function cljs$core$find_and_cache_best_method(name,dispatch_val,hierarchy,method_table,prefer_table,method_cache,cached_hierarchy,default_dispatch_val){ +var best_entry = cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (be,p__5432){ +var vec__5433 = p__5432; +var k = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5433,(0),null); +var _ = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5433,(1),null); +var e = vec__5433; +if(cljs.core.isa_QMARK_.cljs$core$IFn$_invoke$arity$3(cljs.core.deref(hierarchy),dispatch_val,k)){ +var be2 = (((((be == null)) || (cljs.core.dominates(k,cljs.core.first(be),prefer_table,cljs.core.deref(hierarchy)))))?e:be); +if(cljs.core.dominates(cljs.core.first(be2),k,prefer_table,cljs.core.deref(hierarchy))){ +} else { +throw (new Error(["Multiple methods in multimethod '",cljs.core.str.cljs$core$IFn$_invoke$arity$1(name),"' match dispatch value: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(dispatch_val)," -> ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(k)," and ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.first(be2)),", and neither is preferred"].join(''))); +} + +return be2; +} else { +return be; +} +}),null,cljs.core.deref(method_table)); +var best_entry__$1 = (function (){var temp__5733__auto__ = (function (){var and__4120__auto__ = (best_entry == null); +if(and__4120__auto__){ +var fexpr__5437 = cljs.core.deref(method_table); +return (fexpr__5437.cljs$core$IFn$_invoke$arity$1 ? fexpr__5437.cljs$core$IFn$_invoke$arity$1(default_dispatch_val) : fexpr__5437.call(null,default_dispatch_val)); +} else { +return and__4120__auto__; +} +})(); +if(cljs.core.truth_(temp__5733__auto__)){ +var entry = temp__5733__auto__; +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [default_dispatch_val,entry], null); +} else { +return best_entry; +} +})(); +if(cljs.core.truth_(best_entry__$1)){ +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(cached_hierarchy),cljs.core.deref(hierarchy))){ +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(method_cache,cljs.core.assoc,dispatch_val,cljs.core.second(best_entry__$1)); + +return cljs.core.second(best_entry__$1); +} else { +cljs.core.reset_cache(method_cache,method_table,cached_hierarchy,hierarchy); + +return (cljs.core.find_and_cache_best_method.cljs$core$IFn$_invoke$arity$8 ? cljs.core.find_and_cache_best_method.cljs$core$IFn$_invoke$arity$8(name,dispatch_val,hierarchy,method_table,prefer_table,method_cache,cached_hierarchy,default_dispatch_val) : cljs.core.find_and_cache_best_method.call(null,name,dispatch_val,hierarchy,method_table,prefer_table,method_cache,cached_hierarchy,default_dispatch_val)); +} +} else { +return null; +} +}); + +/** + * @interface + */ +cljs.core.IMultiFn = function(){}; + +cljs.core._reset = (function cljs$core$_reset(mf){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_reset$arity$1 == null)))))){ +return mf.cljs$core$IMultiFn$_reset$arity$1(mf); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._reset[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4434__auto__.call(null,mf)); +} else { +var m__4431__auto__ = (cljs.core._reset["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4431__auto__.call(null,mf)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-reset",mf); +} +} +} +}); + +cljs.core._add_method = (function cljs$core$_add_method(mf,dispatch_val,method){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_add_method$arity$3 == null)))))){ +return mf.cljs$core$IMultiFn$_add_method$arity$3(mf,dispatch_val,method); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._add_method[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(mf,dispatch_val,method) : m__4434__auto__.call(null,mf,dispatch_val,method)); +} else { +var m__4431__auto__ = (cljs.core._add_method["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(mf,dispatch_val,method) : m__4431__auto__.call(null,mf,dispatch_val,method)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-add-method",mf); +} +} +} +}); + +cljs.core._remove_method = (function cljs$core$_remove_method(mf,dispatch_val){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_remove_method$arity$2 == null)))))){ +return mf.cljs$core$IMultiFn$_remove_method$arity$2(mf,dispatch_val); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._remove_method[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(mf,dispatch_val) : m__4434__auto__.call(null,mf,dispatch_val)); +} else { +var m__4431__auto__ = (cljs.core._remove_method["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(mf,dispatch_val) : m__4431__auto__.call(null,mf,dispatch_val)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-remove-method",mf); +} +} +} +}); + +cljs.core._prefer_method = (function cljs$core$_prefer_method(mf,dispatch_val,dispatch_val_y){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_prefer_method$arity$3 == null)))))){ +return mf.cljs$core$IMultiFn$_prefer_method$arity$3(mf,dispatch_val,dispatch_val_y); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._prefer_method[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$3(mf,dispatch_val,dispatch_val_y) : m__4434__auto__.call(null,mf,dispatch_val,dispatch_val_y)); +} else { +var m__4431__auto__ = (cljs.core._prefer_method["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$3 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$3(mf,dispatch_val,dispatch_val_y) : m__4431__auto__.call(null,mf,dispatch_val,dispatch_val_y)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-prefer-method",mf); +} +} +} +}); + +cljs.core._get_method = (function cljs$core$_get_method(mf,dispatch_val){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_get_method$arity$2 == null)))))){ +return mf.cljs$core$IMultiFn$_get_method$arity$2(mf,dispatch_val); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._get_method[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$2(mf,dispatch_val) : m__4434__auto__.call(null,mf,dispatch_val)); +} else { +var m__4431__auto__ = (cljs.core._get_method["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$2 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$2(mf,dispatch_val) : m__4431__auto__.call(null,mf,dispatch_val)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-get-method",mf); +} +} +} +}); + +cljs.core._methods = (function cljs$core$_methods(mf){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_methods$arity$1 == null)))))){ +return mf.cljs$core$IMultiFn$_methods$arity$1(mf); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._methods[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4434__auto__.call(null,mf)); +} else { +var m__4431__auto__ = (cljs.core._methods["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4431__auto__.call(null,mf)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-methods",mf); +} +} +} +}); + +cljs.core._prefers = (function cljs$core$_prefers(mf){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_prefers$arity$1 == null)))))){ +return mf.cljs$core$IMultiFn$_prefers$arity$1(mf); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._prefers[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4434__auto__.call(null,mf)); +} else { +var m__4431__auto__ = (cljs.core._prefers["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4431__auto__.call(null,mf)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-prefers",mf); +} +} +} +}); + +cljs.core._default_dispatch_val = (function cljs$core$_default_dispatch_val(mf){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_default_dispatch_val$arity$1 == null)))))){ +return mf.cljs$core$IMultiFn$_default_dispatch_val$arity$1(mf); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._default_dispatch_val[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4434__auto__.call(null,mf)); +} else { +var m__4431__auto__ = (cljs.core._default_dispatch_val["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4431__auto__.call(null,mf)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-default-dispatch-val",mf); +} +} +} +}); + +cljs.core._dispatch_fn = (function cljs$core$_dispatch_fn(mf){ +if((((!((mf == null)))) && ((!((mf.cljs$core$IMultiFn$_dispatch_fn$arity$1 == null)))))){ +return mf.cljs$core$IMultiFn$_dispatch_fn$arity$1(mf); +} else { +var x__4433__auto__ = (((mf == null))?null:mf); +var m__4434__auto__ = (cljs.core._dispatch_fn[goog.typeOf(x__4433__auto__)]); +if((!((m__4434__auto__ == null)))){ +return (m__4434__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4434__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4434__auto__.call(null,mf)); +} else { +var m__4431__auto__ = (cljs.core._dispatch_fn["_"]); +if((!((m__4431__auto__ == null)))){ +return (m__4431__auto__.cljs$core$IFn$_invoke$arity$1 ? m__4431__auto__.cljs$core$IFn$_invoke$arity$1(mf) : m__4431__auto__.call(null,mf)); +} else { +throw cljs.core.missing_protocol("IMultiFn.-dispatch-fn",mf); +} +} +} +}); + +cljs.core.throw_no_method_error = (function cljs$core$throw_no_method_error(name,dispatch_val){ +throw (new Error(["No method in multimethod '",cljs.core.str.cljs$core$IFn$_invoke$arity$1(name),"' for dispatch value: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(dispatch_val)].join(''))); +}); + +/** +* @constructor + * @implements {cljs.core.IHash} + * @implements {cljs.core.IFn} + * @implements {cljs.core.IMultiFn} + * @implements {cljs.core.INamed} +*/ +cljs.core.MultiFn = (function (name,dispatch_fn,default_dispatch_val,hierarchy,method_table,prefer_table,method_cache,cached_hierarchy){ +this.name = name; +this.dispatch_fn = dispatch_fn; +this.default_dispatch_val = default_dispatch_val; +this.hierarchy = hierarchy; +this.method_table = method_table; +this.prefer_table = prefer_table; +this.method_cache = method_cache; +this.cached_hierarchy = cached_hierarchy; +this.cljs$lang$protocol_mask$partition0$ = 4194305; +this.cljs$lang$protocol_mask$partition1$ = 4352; +}); +cljs.core.MultiFn.prototype.call = (function() { +var G__5440 = null; +var G__5440__1 = (function (self__){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$0 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$0() : self__.dispatch_fn.call(null)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$0 ? target_fn.cljs$core$IFn$_invoke$arity$0() : target_fn.call(null)); +}); +var G__5440__2 = (function (self__,a){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$1 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$1(a) : self__.dispatch_fn.call(null,a)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$1 ? target_fn.cljs$core$IFn$_invoke$arity$1(a) : target_fn.call(null,a)); +}); +var G__5440__3 = (function (self__,a,b){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$2 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$2(a,b) : self__.dispatch_fn.call(null,a,b)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$2 ? target_fn.cljs$core$IFn$_invoke$arity$2(a,b) : target_fn.call(null,a,b)); +}); +var G__5440__4 = (function (self__,a,b,c){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$3 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$3(a,b,c) : self__.dispatch_fn.call(null,a,b,c)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$3 ? target_fn.cljs$core$IFn$_invoke$arity$3(a,b,c) : target_fn.call(null,a,b,c)); +}); +var G__5440__5 = (function (self__,a,b,c,d){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$4 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$4(a,b,c,d) : self__.dispatch_fn.call(null,a,b,c,d)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$4 ? target_fn.cljs$core$IFn$_invoke$arity$4(a,b,c,d) : target_fn.call(null,a,b,c,d)); +}); +var G__5440__6 = (function (self__,a,b,c,d,e){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$5 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$5(a,b,c,d,e) : self__.dispatch_fn.call(null,a,b,c,d,e)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$5 ? target_fn.cljs$core$IFn$_invoke$arity$5(a,b,c,d,e) : target_fn.call(null,a,b,c,d,e)); +}); +var G__5440__7 = (function (self__,a,b,c,d,e,f){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$6 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$6(a,b,c,d,e,f) : self__.dispatch_fn.call(null,a,b,c,d,e,f)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$6 ? target_fn.cljs$core$IFn$_invoke$arity$6(a,b,c,d,e,f) : target_fn.call(null,a,b,c,d,e,f)); +}); +var G__5440__8 = (function (self__,a,b,c,d,e,f,g){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$7 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$7(a,b,c,d,e,f,g) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$7 ? target_fn.cljs$core$IFn$_invoke$arity$7(a,b,c,d,e,f,g) : target_fn.call(null,a,b,c,d,e,f,g)); +}); +var G__5440__9 = (function (self__,a,b,c,d,e,f,g,h){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$8 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$8(a,b,c,d,e,f,g,h) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$8 ? target_fn.cljs$core$IFn$_invoke$arity$8(a,b,c,d,e,f,g,h) : target_fn.call(null,a,b,c,d,e,f,g,h)); +}); +var G__5440__10 = (function (self__,a,b,c,d,e,f,g,h,i){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$9 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$9(a,b,c,d,e,f,g,h,i) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$9 ? target_fn.cljs$core$IFn$_invoke$arity$9(a,b,c,d,e,f,g,h,i) : target_fn.call(null,a,b,c,d,e,f,g,h,i)); +}); +var G__5440__11 = (function (self__,a,b,c,d,e,f,g,h,i,j){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$10 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$10(a,b,c,d,e,f,g,h,i,j) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$10 ? target_fn.cljs$core$IFn$_invoke$arity$10(a,b,c,d,e,f,g,h,i,j) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j)); +}); +var G__5440__12 = (function (self__,a,b,c,d,e,f,g,h,i,j,k){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$11 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$11(a,b,c,d,e,f,g,h,i,j,k) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$11 ? target_fn.cljs$core$IFn$_invoke$arity$11(a,b,c,d,e,f,g,h,i,j,k) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k)); +}); +var G__5440__13 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$12 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$12(a,b,c,d,e,f,g,h,i,j,k,l) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$12 ? target_fn.cljs$core$IFn$_invoke$arity$12(a,b,c,d,e,f,g,h,i,j,k,l) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l)); +}); +var G__5440__14 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$13 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$13(a,b,c,d,e,f,g,h,i,j,k,l,m) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$13 ? target_fn.cljs$core$IFn$_invoke$arity$13(a,b,c,d,e,f,g,h,i,j,k,l,m) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m)); +}); +var G__5440__15 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$14 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$14 ? target_fn.cljs$core$IFn$_invoke$arity$14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +}); +var G__5440__16 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$15 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$15 ? target_fn.cljs$core$IFn$_invoke$arity$15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +}); +var G__5440__17 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$16 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$16 ? target_fn.cljs$core$IFn$_invoke$arity$16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +}); +var G__5440__18 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$17 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$17 ? target_fn.cljs$core$IFn$_invoke$arity$17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +}); +var G__5440__19 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$18 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$18 ? target_fn.cljs$core$IFn$_invoke$arity$18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +}); +var G__5440__20 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$19 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$19 ? target_fn.cljs$core$IFn$_invoke$arity$19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +}); +var G__5440__21 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$20 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$20 ? target_fn.cljs$core$IFn$_invoke$arity$20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +}); +var G__5440__22 = (function (self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +var self__ = this; +var self____$1 = this; +var mf = self____$1; +var dispatch_val = cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(self__.dispatch_fn,a,b,c,d,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest], 0)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(target_fn,a,b,c,d,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest], 0)); +}); +G__5440 = function(self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +switch(arguments.length){ +case 1: +return G__5440__1.call(this,self__); +case 2: +return G__5440__2.call(this,self__,a); +case 3: +return G__5440__3.call(this,self__,a,b); +case 4: +return G__5440__4.call(this,self__,a,b,c); +case 5: +return G__5440__5.call(this,self__,a,b,c,d); +case 6: +return G__5440__6.call(this,self__,a,b,c,d,e); +case 7: +return G__5440__7.call(this,self__,a,b,c,d,e,f); +case 8: +return G__5440__8.call(this,self__,a,b,c,d,e,f,g); +case 9: +return G__5440__9.call(this,self__,a,b,c,d,e,f,g,h); +case 10: +return G__5440__10.call(this,self__,a,b,c,d,e,f,g,h,i); +case 11: +return G__5440__11.call(this,self__,a,b,c,d,e,f,g,h,i,j); +case 12: +return G__5440__12.call(this,self__,a,b,c,d,e,f,g,h,i,j,k); +case 13: +return G__5440__13.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l); +case 14: +return G__5440__14.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m); +case 15: +return G__5440__15.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n); +case 16: +return G__5440__16.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o); +case 17: +return G__5440__17.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); +case 18: +return G__5440__18.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q); +case 19: +return G__5440__19.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r); +case 20: +return G__5440__20.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s); +case 21: +return G__5440__21.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t); +case 22: +return G__5440__22.call(this,self__,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest); +} +throw(new Error('Invalid arity: ' + (arguments.length - 1))); +}; +G__5440.cljs$core$IFn$_invoke$arity$1 = G__5440__1; +G__5440.cljs$core$IFn$_invoke$arity$2 = G__5440__2; +G__5440.cljs$core$IFn$_invoke$arity$3 = G__5440__3; +G__5440.cljs$core$IFn$_invoke$arity$4 = G__5440__4; +G__5440.cljs$core$IFn$_invoke$arity$5 = G__5440__5; +G__5440.cljs$core$IFn$_invoke$arity$6 = G__5440__6; +G__5440.cljs$core$IFn$_invoke$arity$7 = G__5440__7; +G__5440.cljs$core$IFn$_invoke$arity$8 = G__5440__8; +G__5440.cljs$core$IFn$_invoke$arity$9 = G__5440__9; +G__5440.cljs$core$IFn$_invoke$arity$10 = G__5440__10; +G__5440.cljs$core$IFn$_invoke$arity$11 = G__5440__11; +G__5440.cljs$core$IFn$_invoke$arity$12 = G__5440__12; +G__5440.cljs$core$IFn$_invoke$arity$13 = G__5440__13; +G__5440.cljs$core$IFn$_invoke$arity$14 = G__5440__14; +G__5440.cljs$core$IFn$_invoke$arity$15 = G__5440__15; +G__5440.cljs$core$IFn$_invoke$arity$16 = G__5440__16; +G__5440.cljs$core$IFn$_invoke$arity$17 = G__5440__17; +G__5440.cljs$core$IFn$_invoke$arity$18 = G__5440__18; +G__5440.cljs$core$IFn$_invoke$arity$19 = G__5440__19; +G__5440.cljs$core$IFn$_invoke$arity$20 = G__5440__20; +G__5440.cljs$core$IFn$_invoke$arity$21 = G__5440__21; +G__5440.cljs$core$IFn$_invoke$arity$22 = G__5440__22; +return G__5440; +})() +; + +cljs.core.MultiFn.prototype.apply = (function (self__,args5438){ +var self__ = this; +var self____$1 = this; +return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args5438))); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$0 = (function (){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$0 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$0() : self__.dispatch_fn.call(null)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$0 ? target_fn.cljs$core$IFn$_invoke$arity$0() : target_fn.call(null)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$1 = (function (a){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$1 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$1(a) : self__.dispatch_fn.call(null,a)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$1 ? target_fn.cljs$core$IFn$_invoke$arity$1(a) : target_fn.call(null,a)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$2 = (function (a,b){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$2 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$2(a,b) : self__.dispatch_fn.call(null,a,b)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$2 ? target_fn.cljs$core$IFn$_invoke$arity$2(a,b) : target_fn.call(null,a,b)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$3 = (function (a,b,c){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$3 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$3(a,b,c) : self__.dispatch_fn.call(null,a,b,c)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$3 ? target_fn.cljs$core$IFn$_invoke$arity$3(a,b,c) : target_fn.call(null,a,b,c)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$4 = (function (a,b,c,d){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$4 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$4(a,b,c,d) : self__.dispatch_fn.call(null,a,b,c,d)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$4 ? target_fn.cljs$core$IFn$_invoke$arity$4(a,b,c,d) : target_fn.call(null,a,b,c,d)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$5 = (function (a,b,c,d,e){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$5 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$5(a,b,c,d,e) : self__.dispatch_fn.call(null,a,b,c,d,e)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$5 ? target_fn.cljs$core$IFn$_invoke$arity$5(a,b,c,d,e) : target_fn.call(null,a,b,c,d,e)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$6 = (function (a,b,c,d,e,f){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$6 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$6(a,b,c,d,e,f) : self__.dispatch_fn.call(null,a,b,c,d,e,f)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$6 ? target_fn.cljs$core$IFn$_invoke$arity$6(a,b,c,d,e,f) : target_fn.call(null,a,b,c,d,e,f)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$7 = (function (a,b,c,d,e,f,g){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$7 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$7(a,b,c,d,e,f,g) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$7 ? target_fn.cljs$core$IFn$_invoke$arity$7(a,b,c,d,e,f,g) : target_fn.call(null,a,b,c,d,e,f,g)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$8 = (function (a,b,c,d,e,f,g,h){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$8 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$8(a,b,c,d,e,f,g,h) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$8 ? target_fn.cljs$core$IFn$_invoke$arity$8(a,b,c,d,e,f,g,h) : target_fn.call(null,a,b,c,d,e,f,g,h)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$9 = (function (a,b,c,d,e,f,g,h,i){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$9 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$9(a,b,c,d,e,f,g,h,i) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$9 ? target_fn.cljs$core$IFn$_invoke$arity$9(a,b,c,d,e,f,g,h,i) : target_fn.call(null,a,b,c,d,e,f,g,h,i)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$10 = (function (a,b,c,d,e,f,g,h,i,j){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$10 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$10(a,b,c,d,e,f,g,h,i,j) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$10 ? target_fn.cljs$core$IFn$_invoke$arity$10(a,b,c,d,e,f,g,h,i,j) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$11 = (function (a,b,c,d,e,f,g,h,i,j,k){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$11 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$11(a,b,c,d,e,f,g,h,i,j,k) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$11 ? target_fn.cljs$core$IFn$_invoke$arity$11(a,b,c,d,e,f,g,h,i,j,k) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$12 = (function (a,b,c,d,e,f,g,h,i,j,k,l){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$12 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$12(a,b,c,d,e,f,g,h,i,j,k,l) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$12 ? target_fn.cljs$core$IFn$_invoke$arity$12(a,b,c,d,e,f,g,h,i,j,k,l) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$13 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$13 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$13(a,b,c,d,e,f,g,h,i,j,k,l,m) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$13 ? target_fn.cljs$core$IFn$_invoke$arity$13(a,b,c,d,e,f,g,h,i,j,k,l,m) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$14 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$14 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$14 ? target_fn.cljs$core$IFn$_invoke$arity$14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$15 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$15 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$15 ? target_fn.cljs$core$IFn$_invoke$arity$15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$16 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$16 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$16 ? target_fn.cljs$core$IFn$_invoke$arity$16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$17 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$17 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$17 ? target_fn.cljs$core$IFn$_invoke$arity$17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$18 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$18 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$18 ? target_fn.cljs$core$IFn$_invoke$arity$18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$19 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$19 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$19 ? target_fn.cljs$core$IFn$_invoke$arity$19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$20 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t){ +var self__ = this; +var mf = this; +var dispatch_val = (self__.dispatch_fn.cljs$core$IFn$_invoke$arity$20 ? self__.dispatch_fn.cljs$core$IFn$_invoke$arity$20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : self__.dispatch_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return (target_fn.cljs$core$IFn$_invoke$arity$20 ? target_fn.cljs$core$IFn$_invoke$arity$20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) : target_fn.call(null,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IFn$_invoke$arity$21 = (function (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest){ +var self__ = this; +var mf = this; +var dispatch_val = cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(self__.dispatch_fn,a,b,c,d,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest], 0)); +var target_fn = mf.cljs$core$IMultiFn$_get_method$arity$2(null,dispatch_val); +if(cljs.core.truth_(target_fn)){ +} else { +cljs.core.throw_no_method_error(self__.name,dispatch_val); +} + +return cljs.core.apply.cljs$core$IFn$_invoke$arity$variadic(target_fn,a,b,c,d,cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,rest], 0)); +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_prefer_method$arity$3 = (function (mf,dispatch_val_x,dispatch_val_y){ +var self__ = this; +var mf__$1 = this; +if(cljs.core.truth_(cljs.core.prefers_STAR_(dispatch_val_x,dispatch_val_y,self__.prefer_table))){ +throw (new Error(["Preference conflict in multimethod '",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.name),"': ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(dispatch_val_y)," is already preferred to ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(dispatch_val_x)].join(''))); +} else { +} + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(self__.prefer_table,((function (mf__$1){ +return (function (old){ +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(old,dispatch_val_x,cljs.core.conj.cljs$core$IFn$_invoke$arity$2(cljs.core.get.cljs$core$IFn$_invoke$arity$3(old,dispatch_val_x,cljs.core.PersistentHashSet.EMPTY),dispatch_val_y)); +});})(mf__$1)) +); + +return cljs.core.reset_cache(self__.method_cache,self__.method_table,self__.cached_hierarchy,self__.hierarchy); +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_default_dispatch_val$arity$1 = (function (mf){ +var self__ = this; +var mf__$1 = this; +return self__.default_dispatch_val; +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_remove_method$arity$2 = (function (mf,dispatch_val){ +var self__ = this; +var mf__$1 = this; +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3(self__.method_table,cljs.core.dissoc,dispatch_val); + +cljs.core.reset_cache(self__.method_cache,self__.method_table,self__.cached_hierarchy,self__.hierarchy); + +return mf__$1; +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_methods$arity$1 = (function (mf){ +var self__ = this; +var mf__$1 = this; +return cljs.core.deref(self__.method_table); +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_prefers$arity$1 = (function (mf){ +var self__ = this; +var mf__$1 = this; +return cljs.core.deref(self__.prefer_table); +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_dispatch_fn$arity$1 = (function (mf){ +var self__ = this; +var mf__$1 = this; +return self__.dispatch_fn; +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_add_method$arity$3 = (function (mf,dispatch_val,method){ +var self__ = this; +var mf__$1 = this; +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(self__.method_table,cljs.core.assoc,dispatch_val,method); + +cljs.core.reset_cache(self__.method_cache,self__.method_table,self__.cached_hierarchy,self__.hierarchy); + +return mf__$1; +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_reset$arity$1 = (function (mf){ +var self__ = this; +var mf__$1 = this; +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(self__.method_table,((function (mf__$1){ +return (function (mf__$2){ +return cljs.core.PersistentArrayMap.EMPTY; +});})(mf__$1)) +); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(self__.method_cache,((function (mf__$1){ +return (function (mf__$2){ +return cljs.core.PersistentArrayMap.EMPTY; +});})(mf__$1)) +); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(self__.prefer_table,((function (mf__$1){ +return (function (mf__$2){ +return cljs.core.PersistentArrayMap.EMPTY; +});})(mf__$1)) +); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$2(self__.cached_hierarchy,((function (mf__$1){ +return (function (mf__$2){ +return null; +});})(mf__$1)) +); + +return mf__$1; +}); + +cljs.core.MultiFn.prototype.cljs$core$IMultiFn$_get_method$arity$2 = (function (mf,dispatch_val){ +var self__ = this; +var mf__$1 = this; +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(self__.cached_hierarchy),cljs.core.deref(self__.hierarchy))){ +} else { +cljs.core.reset_cache(self__.method_cache,self__.method_table,self__.cached_hierarchy,self__.hierarchy); +} + +var temp__5733__auto__ = (function (){var fexpr__5439 = cljs.core.deref(self__.method_cache); +return (fexpr__5439.cljs$core$IFn$_invoke$arity$1 ? fexpr__5439.cljs$core$IFn$_invoke$arity$1(dispatch_val) : fexpr__5439.call(null,dispatch_val)); +})(); +if(cljs.core.truth_(temp__5733__auto__)){ +var target_fn = temp__5733__auto__; +return target_fn; +} else { +return cljs.core.find_and_cache_best_method(self__.name,dispatch_val,self__.hierarchy,self__.method_table,self__.prefer_table,self__.method_cache,self__.cached_hierarchy,self__.default_dispatch_val); +} +}); + +cljs.core.MultiFn.prototype.cljs$core$INamed$_name$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return cljs.core._name(self__.name); +}); + +cljs.core.MultiFn.prototype.cljs$core$INamed$_namespace$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return cljs.core._namespace(self__.name); +}); + +cljs.core.MultiFn.prototype.cljs$core$IHash$_hash$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return goog.getUid(this$__$1); +}); + +cljs.core.MultiFn.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 8, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$name,cljs.core.cst$sym$dispatch_DASH_fn,cljs.core.cst$sym$default_DASH_dispatch_DASH_val,cljs.core.cst$sym$hierarchy,cljs.core.cst$sym$method_DASH_table,cljs.core.cst$sym$prefer_DASH_table,cljs.core.cst$sym$method_DASH_cache,cljs.core.cst$sym$cached_DASH_hierarchy], null); +}); + +cljs.core.MultiFn.cljs$lang$type = true; + +cljs.core.MultiFn.cljs$lang$ctorStr = "cljs.core/MultiFn"; + +cljs.core.MultiFn.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/MultiFn"); +}); + +/** + * Positional factory function for cljs.core/MultiFn. + */ +cljs.core.__GT_MultiFn = (function cljs$core$__GT_MultiFn(name,dispatch_fn,default_dispatch_val,hierarchy,method_table,prefer_table,method_cache,cached_hierarchy){ +return (new cljs.core.MultiFn(name,dispatch_fn,default_dispatch_val,hierarchy,method_table,prefer_table,method_cache,cached_hierarchy)); +}); + +/** + * Removes all of the methods of multimethod. + */ +cljs.core.remove_all_methods = (function cljs$core$remove_all_methods(multifn){ +return cljs.core._reset(multifn); +}); +/** + * Removes the method of multimethod associated with dispatch-value. + */ +cljs.core.remove_method = (function cljs$core$remove_method(multifn,dispatch_val){ +return cljs.core._remove_method(multifn,dispatch_val); +}); +/** + * Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y + * when there is a conflict + */ +cljs.core.prefer_method = (function cljs$core$prefer_method(multifn,dispatch_val_x,dispatch_val_y){ +return cljs.core._prefer_method(multifn,dispatch_val_x,dispatch_val_y); +}); +/** + * Given a multimethod, returns a map of dispatch values -> dispatch fns + */ +cljs.core.methods$ = (function cljs$core$methods(multifn){ +return cljs.core._methods(multifn); +}); +/** + * Given a multimethod and a dispatch value, returns the dispatch fn + * that would apply to that value, or nil if none apply and no default + */ +cljs.core.get_method = (function cljs$core$get_method(multifn,dispatch_val){ +return cljs.core._get_method(multifn,dispatch_val); +}); +/** + * Given a multimethod, returns a map of preferred value -> set of other values + */ +cljs.core.prefers = (function cljs$core$prefers(multifn){ +return cljs.core._prefers(multifn); +}); +/** + * Given a multimethod, return it's default-dispatch-val. + */ +cljs.core.default_dispatch_val = (function cljs$core$default_dispatch_val(multifn){ +return cljs.core._default_dispatch_val(multifn); +}); +/** + * Given a multimethod, return it's dispatch-fn. + */ +cljs.core.dispatch_fn = (function cljs$core$dispatch_fn(multifn){ +return cljs.core._dispatch_fn(multifn); +}); + +/** + * A marker protocol for UUIDs + * @interface + */ +cljs.core.IUUID = function(){}; + + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IPrintWithWriter} + * @implements {cljs.core.IComparable} + * @implements {cljs.core.IUUID} +*/ +cljs.core.UUID = (function (uuid,__hash){ +this.uuid = uuid; +this.__hash = __hash; +this.cljs$lang$protocol_mask$partition0$ = 2153775104; +this.cljs$lang$protocol_mask$partition1$ = 2048; +}); +cljs.core.UUID.prototype.cljs$core$IUUID$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.UUID.prototype.toString = (function (){ +var self__ = this; +var _ = this; +return self__.uuid; +}); + +cljs.core.UUID.prototype.equiv = (function (other){ +var self__ = this; +var this$ = this; +return this$.cljs$core$IEquiv$_equiv$arity$2(null,other); +}); + +cljs.core.UUID.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (_,other){ +var self__ = this; +var ___$1 = this; +return (((other instanceof cljs.core.UUID)) && ((self__.uuid === other.uuid))); +}); + +cljs.core.UUID.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (_,writer,___$1){ +var self__ = this; +var ___$2 = this; +return cljs.core._write(writer,["#uuid \"",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.uuid),"\""].join('')); +}); + +cljs.core.UUID.prototype.cljs$core$IHash$_hash$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +if((self__.__hash == null)){ +self__.__hash = cljs.core.hash(self__.uuid); +} else { +} + +return self__.__hash; +}); + +cljs.core.UUID.prototype.cljs$core$IComparable$_compare$arity$2 = (function (_,other){ +var self__ = this; +var ___$1 = this; +var G__5441 = self__.uuid; +var G__5442 = other.uuid; +return goog.array.defaultCompare(G__5441,G__5442); +}); + +cljs.core.UUID.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$uuid,cljs.core.with_meta(cljs.core.cst$sym$__hash,new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$mutable,true], null))], null); +}); + +cljs.core.UUID.cljs$lang$type = true; + +cljs.core.UUID.cljs$lang$ctorStr = "cljs.core/UUID"; + +cljs.core.UUID.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/UUID"); +}); + +/** + * Positional factory function for cljs.core/UUID. + */ +cljs.core.__GT_UUID = (function cljs$core$__GT_UUID(uuid,__hash){ +return (new cljs.core.UUID(uuid,__hash)); +}); + +cljs.core.uuid = (function cljs$core$uuid(s){ +if(typeof s === 'string'){ +} else { +throw (new Error("Assert failed: (string? s)")); +} + +return (new cljs.core.UUID(s.toLowerCase(),null)); +}); +cljs.core.random_uuid = (function cljs$core$random_uuid(){ +var hex = (function cljs$core$random_uuid_$_hex(){ +return cljs.core.rand_int((16)).toString((16)); +}); +var rhex = ((8) | ((3) & cljs.core.rand_int((16)))).toString((16)); +return cljs.core.uuid([cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),"-",cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),"-","4",cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),"-",cljs.core.str.cljs$core$IFn$_invoke$arity$1(rhex),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),"-",cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex()),cljs.core.str.cljs$core$IFn$_invoke$arity$1(hex())].join('')); +}); +cljs.core.uuid_QMARK_ = (function cljs$core$uuid_QMARK_(x){ +if((!((x == null)))){ +if(((false) || ((cljs.core.PROTOCOL_SENTINEL === x.cljs$core$IUUID$)))){ +return true; +} else { +return false; +} +} else { +return false; +} +}); +cljs.core.pr_writer_ex_info = (function cljs$core$pr_writer_ex_info(obj,writer,opts){ +cljs.core._write(writer,"#error {:message "); + +cljs.core.pr_writer(obj.message,writer,opts); + +if(cljs.core.truth_(obj.data)){ +cljs.core._write(writer,", :data "); + +cljs.core.pr_writer(obj.data,writer,opts); +} else { +} + +if(cljs.core.truth_(obj.cause)){ +cljs.core._write(writer,", :cause "); + +cljs.core.pr_writer(obj.cause,writer,opts); +} else { +} + +return cljs.core._write(writer,"}"); +}); +/** + * @constructor + */ +cljs.core.ExceptionInfo = (function cljs$core$ExceptionInfo(message,data,cause){ +var e = (new Error(message)); +var this$ = this; +this$.message = message; + +this$.data = data; + +this$.cause = cause; + +this$.name = e.name; + +this$.description = e.description; + +this$.number = e.number; + +this$.fileName = e.fileName; + +this$.lineNumber = e.lineNumber; + +this$.columnNumber = e.columnNumber; + +this$.stack = e.stack; + +return this$; +}); +cljs.core.ExceptionInfo.prototype.__proto__ = Error.prototype; +cljs.core.ExceptionInfo.prototype.cljs$core$IPrintWithWriter$ = cljs.core.PROTOCOL_SENTINEL; + +cljs.core.ExceptionInfo.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (obj,writer,opts){ +var obj__$1 = this; +return cljs.core.pr_writer_ex_info(obj__$1,writer,opts); +}); +cljs.core.ExceptionInfo.prototype.toString = (function (){ +var this$ = this; +return cljs.core.pr_str_STAR_(this$); +}); +/** + * Create an instance of ExceptionInfo, an Error type that carries a + * map of additional data. + */ +cljs.core.ex_info = (function cljs$core$ex_info(var_args){ +var G__5445 = arguments.length; +switch (G__5445) { +case 2: +return cljs.core.ex_info.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.ex_info.cljs$core$IFn$_invoke$arity$2 = (function (msg,data){ +return cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3(msg,data,null); +}); + +cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 = (function (msg,data,cause){ +return (new cljs.core.ExceptionInfo(msg,data,cause)); +}); + +cljs.core.ex_info.cljs$lang$maxFixedArity = 3; + +/** + * Returns exception data (a map) if ex is an ExceptionInfo. + * Otherwise returns nil. + */ +cljs.core.ex_data = (function cljs$core$ex_data(ex){ +if((ex instanceof cljs.core.ExceptionInfo)){ +return ex.data; +} else { +return null; +} +}); +/** + * Returns the message attached to the given Error / ExceptionInfo object. + * For non-Errors returns nil. + */ +cljs.core.ex_message = (function cljs$core$ex_message(ex){ +if((ex instanceof Error)){ +return ex.message; +} else { +return null; +} +}); +/** + * Returns exception cause (an Error / ExceptionInfo) if ex is an + * ExceptionInfo. + * Otherwise returns nil. + */ +cljs.core.ex_cause = (function cljs$core$ex_cause(ex){ +if((ex instanceof cljs.core.ExceptionInfo)){ +return ex.cause; +} else { +return null; +} +}); +/** + * Returns an JavaScript compatible comparator based upon pred. + */ +cljs.core.comparator = (function cljs$core$comparator(pred){ +return (function (x,y){ +if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$2 ? pred.cljs$core$IFn$_invoke$arity$2(x,y) : pred.call(null,x,y)))){ +return (-1); +} else { +if(cljs.core.truth_((pred.cljs$core$IFn$_invoke$arity$2 ? pred.cljs$core$IFn$_invoke$arity$2(y,x) : pred.call(null,y,x)))){ +return (1); +} else { +return (0); + +} +} +}); +}); +/** + * Returns true if x names a special form + */ +cljs.core.special_symbol_QMARK_ = (function cljs$core$special_symbol_QMARK_(x){ +return cljs.core.contains_QMARK_(new cljs.core.PersistentHashSet(null, new cljs.core.PersistentArrayMap(null, 24, [cljs.core.cst$sym$_AMPERSAND_,"null",cljs.core.cst$sym$case_STAR_,"null",cljs.core.cst$sym$defrecord_STAR_,"null",cljs.core.cst$sym$try,"null",cljs.core.cst$sym$ns_STAR_,"null",cljs.core.cst$sym$finally,"null",cljs.core.cst$sym$loop_STAR_,"null",cljs.core.cst$sym$do,"null",cljs.core.cst$sym$letfn_STAR_,"null",cljs.core.cst$sym$if,"null",cljs.core.cst$sym$new,"null",cljs.core.cst$sym$ns,"null",cljs.core.cst$sym$deftype_STAR_,"null",cljs.core.cst$sym$let_STAR_,"null",cljs.core.cst$sym$js_STAR_,"null",cljs.core.cst$sym$fn_STAR_,"null",cljs.core.cst$sym$recur,"null",cljs.core.cst$sym$set_BANG_,"null",cljs.core.cst$sym$_DOT_,"null",cljs.core.cst$sym$var,"null",cljs.core.cst$sym$quote,"null",cljs.core.cst$sym$catch,"null",cljs.core.cst$sym$throw,"null",cljs.core.cst$sym$def,"null"], null), null),x); +}); +/** + * test [v] finds fn at key :test in var metadata and calls it, + * presuming failure will throw exception + */ +cljs.core.test = (function cljs$core$test(v){ +var f = v.cljs$lang$test; +if(cljs.core.truth_(f)){ +(f.cljs$core$IFn$_invoke$arity$0 ? f.cljs$core$IFn$_invoke$arity$0() : f.call(null)); + +return cljs.core.cst$kw$ok; +} else { +return cljs.core.cst$kw$no_DASH_test; +} +}); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} + * @implements {cljs.core.IPrintWithWriter} + * @implements {cljs.core.ILookup} +*/ +cljs.core.TaggedLiteral = (function (tag,form){ +this.tag = tag; +this.form = form; +this.cljs$lang$protocol_mask$partition0$ = 2153775360; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.TaggedLiteral.prototype.toString = (function (){ +var self__ = this; +var coll = this; +return cljs.core.pr_str_STAR_(coll); +}); + +cljs.core.TaggedLiteral.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (this$,other){ +var self__ = this; +var this$__$1 = this; +return (((other instanceof cljs.core.TaggedLiteral)) && (cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(self__.tag,other.tag)) && (cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(self__.form,other.form))); +}); + +cljs.core.TaggedLiteral.prototype.cljs$core$IHash$_hash$arity$1 = (function (this$){ +var self__ = this; +var this$__$1 = this; +return (((31) * cljs.core.hash(self__.tag)) + cljs.core.hash(self__.form)); +}); + +cljs.core.TaggedLiteral.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (this$,v){ +var self__ = this; +var this$__$1 = this; +return this$__$1.cljs$core$ILookup$_lookup$arity$3(null,v,null); +}); + +cljs.core.TaggedLiteral.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (this$,v,not_found){ +var self__ = this; +var this$__$1 = this; +var G__5447 = v; +var G__5447__$1 = (((G__5447 instanceof cljs.core.Keyword))?G__5447.fqn:null); +switch (G__5447__$1) { +case "tag": +return self__.tag; + +break; +case "form": +return self__.form; + +break; +default: +return not_found; + +} +}); + +cljs.core.TaggedLiteral.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (o,writer,opts){ +var self__ = this; +var o__$1 = this; +cljs.core._write(writer,["#",cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.tag)," "].join('')); + +return cljs.core.pr_writer(self__.form,writer,opts); +}); + +cljs.core.TaggedLiteral.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$tag,cljs.core.cst$sym$form], null); +}); + +cljs.core.TaggedLiteral.cljs$lang$type = true; + +cljs.core.TaggedLiteral.cljs$lang$ctorStr = "cljs.core/TaggedLiteral"; + +cljs.core.TaggedLiteral.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/TaggedLiteral"); +}); + +/** + * Positional factory function for cljs.core/TaggedLiteral. + */ +cljs.core.__GT_TaggedLiteral = (function cljs$core$__GT_TaggedLiteral(tag,form){ +return (new cljs.core.TaggedLiteral(tag,form)); +}); + +/** + * Return true if the value is the data representation of a tagged literal + */ +cljs.core.tagged_literal_QMARK_ = (function cljs$core$tagged_literal_QMARK_(value){ +return (value instanceof cljs.core.TaggedLiteral); +}); +/** + * Construct a data representation of a tagged literal from a + * tag symbol and a form. + */ +cljs.core.tagged_literal = (function cljs$core$tagged_literal(tag,form){ +if((tag instanceof cljs.core.Symbol)){ +} else { +throw (new Error("Assert failed: (symbol? tag)")); +} + +return (new cljs.core.TaggedLiteral(tag,form)); +}); +/** + * @type {*} + */ +cljs.core.js_reserved_arr = ["arguments","abstract","await","boolean","break","byte","case","catch","char","class","const","continue","debugger","default","delete","do","double","else","enum","export","extends","final","finally","float","for","function","goto","if","implements","import","in","instanceof","int","interface","let","long","native","new","package","private","protected","public","return","short","static","super","switch","synchronized","this","throw","throws","transient","try","typeof","var","void","volatile","while","with","yield","methods","null","constructor"]; +/** + * @type {null|Object} + */ +cljs.core.js_reserved = null; +cljs.core.js_reserved_QMARK_ = (function cljs$core$js_reserved_QMARK_(x){ +if((cljs.core.js_reserved == null)){ +cljs.core.js_reserved = cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p1__5449_SHARP_,p2__5450_SHARP_){ +goog.object.set(p1__5449_SHARP_,p2__5450_SHARP_,true); + +return p1__5449_SHARP_; +}),({}),cljs.core.js_reserved_arr); +} else { +} + +return cljs.core.js_reserved.hasOwnProperty(x); +}); +cljs.core.demunge_pattern = (function cljs$core$demunge_pattern(){ +if(cljs.core.truth_(cljs.core.DEMUNGE_PATTERN)){ +} else { +cljs.core.DEMUNGE_PATTERN = (function (){var ks = cljs.core.sort.cljs$core$IFn$_invoke$arity$2((function (a,b){ +return (b.length - a.length); +}),cljs.core.js_keys(cljs.core.DEMUNGE_MAP)); +var ks__$1 = ks; +var ret = ""; +while(true){ +if(cljs.core.seq(ks__$1)){ +var G__5453 = cljs.core.next(ks__$1); +var G__5454 = [(function (){var G__5452 = ret; +if((!((ret === "")))){ +return [G__5452,"|"].join(''); +} else { +return G__5452; +} +})(),cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.first(ks__$1))].join(''); +ks__$1 = G__5453; +ret = G__5454; +continue; +} else { +return [ret,"|\\$"].join(''); +} +break; +} +})(); +} + +return cljs.core.DEMUNGE_PATTERN; +}); +cljs.core.munge_str = (function cljs$core$munge_str(name){ +var sb = (new goog.string.StringBuffer()); +var i_5455 = (0); +while(true){ +if((i_5455 < name.length)){ +var c_5456 = name.charAt(i_5455); +var sub_5457 = goog.object.get(cljs.core.CHAR_MAP,c_5456); +if((!((sub_5457 == null)))){ +sb.append(sub_5457); +} else { +sb.append(c_5456); +} + +var G__5458 = (i_5455 + (1)); +i_5455 = G__5458; +continue; +} else { +} +break; +} + +return sb.toString(); +}); +cljs.core.munge = (function cljs$core$munge(name){ +var name_SINGLEQUOTE_ = cljs.core.munge_str(cljs.core.str.cljs$core$IFn$_invoke$arity$1(name)); +var name_SINGLEQUOTE___$1 = (((name_SINGLEQUOTE_ === ".."))?"_DOT__DOT_":(cljs.core.truth_(cljs.core.js_reserved_QMARK_(name_SINGLEQUOTE_))?[cljs.core.str.cljs$core$IFn$_invoke$arity$1(name_SINGLEQUOTE_),"$"].join(''):name_SINGLEQUOTE_ +)); +if((name instanceof cljs.core.Symbol)){ +return cljs.core.symbol.cljs$core$IFn$_invoke$arity$1(name_SINGLEQUOTE___$1); +} else { +return name_SINGLEQUOTE___$1; +} +}); +cljs.core.demunge_str = (function cljs$core$demunge_str(munged_name){ +var r = (new RegExp(cljs.core.demunge_pattern(),"g")); +var munged_name__$1 = (cljs.core.truth_(goog.string.endsWith(munged_name,"$"))?munged_name.substring((0),(munged_name.length - (1))):munged_name); +var ret = ""; +var last_match_end = (0); +while(true){ +var temp__5733__auto__ = r.exec(munged_name__$1); +if(cljs.core.truth_(temp__5733__auto__)){ +var match = temp__5733__auto__; +var vec__5462 = match; +var x = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__5462,(0),null); +var G__5465 = [ret,cljs.core.str.cljs$core$IFn$_invoke$arity$1(munged_name__$1.substring(last_match_end,(r.lastIndex - x.length))),cljs.core.str.cljs$core$IFn$_invoke$arity$1((((x === "$"))?"/":goog.object.get(cljs.core.DEMUNGE_MAP,x)))].join(''); +var G__5466 = r.lastIndex; +ret = G__5465; +last_match_end = G__5466; +continue; +} else { +return [ret,cljs.core.str.cljs$core$IFn$_invoke$arity$1(munged_name__$1.substring(last_match_end,munged_name__$1.length))].join(''); +} +break; +} +}); +cljs.core.demunge = (function cljs$core$demunge(name){ +var G__5468 = (function (){var name_SINGLEQUOTE_ = cljs.core.str.cljs$core$IFn$_invoke$arity$1(name); +if((name_SINGLEQUOTE_ === "_DOT__DOT_")){ +return ".."; +} else { +return cljs.core.demunge_str(name_SINGLEQUOTE_); +} +})(); +var fexpr__5467 = (((name instanceof cljs.core.Symbol))?cljs.core.symbol:cljs.core.str); +return (fexpr__5467.cljs$core$IFn$_invoke$arity$1 ? fexpr__5467.cljs$core$IFn$_invoke$arity$1(G__5468) : fexpr__5467.call(null,G__5468)); +}); +if((typeof cljs !== 'undefined') && (typeof cljs.core !== 'undefined') && (typeof cljs.core.tapset !== 'undefined')){ +} else { +/** + * @type {*} + */ +cljs.core.tapset = null; +} +cljs.core.maybe_init_tapset = (function cljs$core$maybe_init_tapset(){ +if((cljs.core.tapset == null)){ +return cljs.core.tapset = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentHashSet.EMPTY); +} else { +return null; +} +}); +/** + * Adds f, a fn of one argument, to the tap set. This function will be called with + * anything sent via tap>. Remember f in order to remove-tap + */ +cljs.core.add_tap = (function cljs$core$add_tap(f){ +cljs.core.maybe_init_tapset(); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3(cljs.core.tapset,cljs.core.conj,f); + +return null; +}); +/** + * Remove f from the tap set. + */ +cljs.core.remove_tap = (function cljs$core$remove_tap(f){ +cljs.core.maybe_init_tapset(); + +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3(cljs.core.tapset,cljs.core.disj,f); + +return null; +}); +/** + * Sends x to any taps. Returns the result of *exec-tap-fn*, a Boolean value. + */ +cljs.core.tap_GT_ = (function cljs$core$tap_GT_(x){ +cljs.core.maybe_init_tapset(); + +return (cljs.core._STAR_exec_tap_fn_STAR_.cljs$core$IFn$_invoke$arity$1 ? cljs.core._STAR_exec_tap_fn_STAR_.cljs$core$IFn$_invoke$arity$1((function (){ +var seq__5469 = cljs.core.seq(cljs.core.deref(cljs.core.tapset)); +var chunk__5470 = null; +var count__5471 = (0); +var i__5472 = (0); +while(true){ +if((i__5472 < count__5471)){ +var tap = chunk__5470.cljs$core$IIndexed$_nth$arity$2(null,i__5472); +try{(tap.cljs$core$IFn$_invoke$arity$1 ? tap.cljs$core$IFn$_invoke$arity$1(x) : tap.call(null,x)); +}catch (e5475){if((e5475 instanceof Error)){ +var ex_5477 = e5475; +} else { +throw e5475; + +} +} + +var G__5478 = seq__5469; +var G__5479 = chunk__5470; +var G__5480 = count__5471; +var G__5481 = (i__5472 + (1)); +seq__5469 = G__5478; +chunk__5470 = G__5479; +count__5471 = G__5480; +i__5472 = G__5481; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__5469); +if(temp__5735__auto__){ +var seq__5469__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__5469__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__5469__$1); +var G__5482 = cljs.core.chunk_rest(seq__5469__$1); +var G__5483 = c__4550__auto__; +var G__5484 = cljs.core.count(c__4550__auto__); +var G__5485 = (0); +seq__5469 = G__5482; +chunk__5470 = G__5483; +count__5471 = G__5484; +i__5472 = G__5485; +continue; +} else { +var tap = cljs.core.first(seq__5469__$1); +try{(tap.cljs$core$IFn$_invoke$arity$1 ? tap.cljs$core$IFn$_invoke$arity$1(x) : tap.call(null,x)); +}catch (e5476){if((e5476 instanceof Error)){ +var ex_5486 = e5476; +} else { +throw e5476; + +} +} + +var G__5487 = cljs.core.next(seq__5469__$1); +var G__5488 = null; +var G__5489 = (0); +var G__5490 = (0); +seq__5469 = G__5487; +chunk__5470 = G__5488; +count__5471 = G__5489; +i__5472 = G__5490; +continue; +} +} else { +return null; +} +} +break; +} +})) : cljs.core._STAR_exec_tap_fn_STAR_.call(null,(function (){ +var seq__5469 = cljs.core.seq(cljs.core.deref(cljs.core.tapset)); +var chunk__5470 = null; +var count__5471 = (0); +var i__5472 = (0); +while(true){ +if((i__5472 < count__5471)){ +var tap = chunk__5470.cljs$core$IIndexed$_nth$arity$2(null,i__5472); +try{(tap.cljs$core$IFn$_invoke$arity$1 ? tap.cljs$core$IFn$_invoke$arity$1(x) : tap.call(null,x)); +}catch (e5475){if((e5475 instanceof Error)){ +var ex_5491 = e5475; +} else { +throw e5475; + +} +} + +var G__5492 = seq__5469; +var G__5493 = chunk__5470; +var G__5494 = count__5471; +var G__5495 = (i__5472 + (1)); +seq__5469 = G__5492; +chunk__5470 = G__5493; +count__5471 = G__5494; +i__5472 = G__5495; +continue; +} else { +var temp__5735__auto__ = cljs.core.seq(seq__5469); +if(temp__5735__auto__){ +var seq__5469__$1 = temp__5735__auto__; +if(cljs.core.chunked_seq_QMARK_(seq__5469__$1)){ +var c__4550__auto__ = cljs.core.chunk_first(seq__5469__$1); +var G__5496 = cljs.core.chunk_rest(seq__5469__$1); +var G__5497 = c__4550__auto__; +var G__5498 = cljs.core.count(c__4550__auto__); +var G__5499 = (0); +seq__5469 = G__5496; +chunk__5470 = G__5497; +count__5471 = G__5498; +i__5472 = G__5499; +continue; +} else { +var tap = cljs.core.first(seq__5469__$1); +try{(tap.cljs$core$IFn$_invoke$arity$1 ? tap.cljs$core$IFn$_invoke$arity$1(x) : tap.call(null,x)); +}catch (e5476){if((e5476 instanceof Error)){ +var ex_5500 = e5476; +} else { +throw e5476; + +} +} + +var G__5501 = cljs.core.next(seq__5469__$1); +var G__5502 = null; +var G__5503 = (0); +var G__5504 = (0); +seq__5469 = G__5501; +chunk__5470 = G__5502; +count__5471 = G__5503; +i__5472 = G__5504; +continue; +} +} else { +return null; +} +} +break; +} +}))); +}); +/** + * Bootstrap only. + */ +cljs.core.ns_lookup = (function cljs$core$ns_lookup(ns_obj,k){ +return (function (){ +return goog.object.get(ns_obj,k); +}); +}); + +/** +* @constructor + * @implements {cljs.core.IEquiv} + * @implements {cljs.core.IHash} +*/ +cljs.core.Namespace = (function (obj,name){ +this.obj = obj; +this.name = name; +this.cljs$lang$protocol_mask$partition0$ = 6291456; +this.cljs$lang$protocol_mask$partition1$ = 0; +}); +cljs.core.Namespace.prototype.findInternedVar = (function (sym){ +var self__ = this; +var this$ = this; +var k = cljs.core.munge(cljs.core.str.cljs$core$IFn$_invoke$arity$1(sym)); +if(goog.object.containsKey(self__.obj,k)){ +var var_sym = cljs.core.symbol.cljs$core$IFn$_invoke$arity$2(cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.name),cljs.core.str.cljs$core$IFn$_invoke$arity$1(sym)); +var var_meta = new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$ns,this$], null); +return (new cljs.core.Var(cljs.core.ns_lookup(self__.obj,k),var_sym,var_meta)); +} else { +return null; +} +}); + +cljs.core.Namespace.prototype.getName = (function (){ +var self__ = this; +var _ = this; +return self__.name; +}); + +cljs.core.Namespace.prototype.toString = (function (){ +var self__ = this; +var _ = this; +return cljs.core.str.cljs$core$IFn$_invoke$arity$1(self__.name); +}); + +cljs.core.Namespace.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (_,other){ +var self__ = this; +var ___$1 = this; +if((other instanceof cljs.core.Namespace)){ +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(self__.name,other.name); +} else { +return false; +} +}); + +cljs.core.Namespace.prototype.cljs$core$IHash$_hash$arity$1 = (function (_){ +var self__ = this; +var ___$1 = this; +return cljs.core.hash(self__.name); +}); + +cljs.core.Namespace.getBasis = (function (){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$sym$obj,cljs.core.cst$sym$name], null); +}); + +cljs.core.Namespace.cljs$lang$type = true; + +cljs.core.Namespace.cljs$lang$ctorStr = "cljs.core/Namespace"; + +cljs.core.Namespace.cljs$lang$ctorPrWriter = (function (this__4374__auto__,writer__4375__auto__,opt__4376__auto__){ +return cljs.core._write(writer__4375__auto__,"cljs.core/Namespace"); +}); + +/** + * Positional factory function for cljs.core/Namespace. + */ +cljs.core.__GT_Namespace = (function cljs$core$__GT_Namespace(obj,name){ +return (new cljs.core.Namespace(obj,name)); +}); + +/** + * Bootstrap only. + * @type {*} + */ +cljs.core.NS_CACHE = null; +/** + * Bootstrap only. + */ +cljs.core.find_ns_obj_STAR_ = (function cljs$core$find_ns_obj_STAR_(ctxt,xs){ +while(true){ +if((ctxt == null)){ +return null; +} else { +if((xs == null)){ +return ctxt; +} else { +var G__5507 = (function (){var G__5505 = ctxt; +var G__5506 = cljs.core.first(xs); +return goog.object.get(G__5505,G__5506); +})(); +var G__5508 = cljs.core.next(xs); +ctxt = G__5507; +xs = G__5508; +continue; + +} +} +break; +} +}); +/** + * Bootstrap only. + */ +cljs.core.find_ns_obj = (function cljs$core$find_ns_obj(ns){ +var munged_ns = cljs.core.munge(cljs.core.str.cljs$core$IFn$_invoke$arity$1(ns)); +var segs = munged_ns.split("."); +var G__5509 = cljs.core._STAR_target_STAR_; +switch (G__5509) { +case "nodejs": +if(COMPILED){ +return cljs.core.find_ns_obj_STAR_((function (){try{var ctxt = eval(cljs.core.first(segs)); +if(cljs.core.truth_((function (){var and__4120__auto__ = ctxt; +if(cljs.core.truth_(and__4120__auto__)){ +return cljs.core.object_QMARK_(ctxt); +} else { +return and__4120__auto__; +} +})())){ +return ctxt; +} else { +return null; +} +}catch (e5510){if((e5510 instanceof ReferenceError)){ +var e = e5510; +return null; +} else { +throw e5510; + +} +}})(),cljs.core.next(segs)); +} else { +return cljs.core.find_ns_obj_STAR_(goog.global,segs); +} + +break; +case "default": +case "webworker": +return cljs.core.find_ns_obj_STAR_(goog.global,segs); + +break; +default: +throw (new Error(["find-ns-obj not supported for target ",cljs.core._STAR_target_STAR_].join(''))); + +} +}); +/** + * Returns a map of the intern mappings for the namespace. + * Bootstrap only. + */ +cljs.core.ns_interns_STAR_ = (function cljs$core$ns_interns_STAR_(sym){ +var ns_obj = cljs.core.find_ns_obj(sym); +var ns = (new cljs.core.Namespace(ns_obj,sym)); +var step = ((function (ns_obj,ns){ +return (function cljs$core$ns_interns_STAR__$_step(ret,k){ +var var_sym = cljs.core.symbol.cljs$core$IFn$_invoke$arity$1(cljs.core.demunge(k)); +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(ret,var_sym,(new cljs.core.Var(((function (var_sym,ns_obj,ns){ +return (function (){ +return goog.object.get(ns_obj,k); +});})(var_sym,ns_obj,ns)) +,cljs.core.symbol.cljs$core$IFn$_invoke$arity$2(cljs.core.str.cljs$core$IFn$_invoke$arity$1(sym),cljs.core.str.cljs$core$IFn$_invoke$arity$1(var_sym)),new cljs.core.PersistentArrayMap(null, 1, [cljs.core.cst$kw$ns,ns], null)))); +});})(ns_obj,ns)) +; +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(step,cljs.core.PersistentArrayMap.EMPTY,cljs.core.js_keys(ns_obj)); +}); +/** + * Create a new namespace named by the symbol. Bootstrap only. + */ +cljs.core.create_ns = (function cljs$core$create_ns(var_args){ +var G__5513 = arguments.length; +switch (G__5513) { +case 1: +return cljs.core.create_ns.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return cljs.core.create_ns.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +cljs.core.create_ns.cljs$core$IFn$_invoke$arity$1 = (function (sym){ +return cljs.core.create_ns.cljs$core$IFn$_invoke$arity$2(sym,cljs.core.find_ns_obj(sym)); +}); + +cljs.core.create_ns.cljs$core$IFn$_invoke$arity$2 = (function (sym,ns_obj){ +return (new cljs.core.Namespace(ns_obj,sym)); +}); + +cljs.core.create_ns.cljs$lang$maxFixedArity = 2; + +/** + * Returns the namespace named by the symbol or nil if it doesn't exist. + * Bootstrap only. + */ +cljs.core.find_ns = (function cljs$core$find_ns(ns){ +if((cljs.core.NS_CACHE == null)){ +cljs.core.NS_CACHE = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentArrayMap.EMPTY); +} else { +} + +var the_ns = cljs.core.get.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(cljs.core.NS_CACHE),ns); +if((!((the_ns == null)))){ +return the_ns; +} else { +var ns_obj = cljs.core.find_ns_obj(ns); +if((ns_obj == null)){ +return null; +} else { +var new_ns = cljs.core.create_ns.cljs$core$IFn$_invoke$arity$2(ns,ns_obj); +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(cljs.core.NS_CACHE,cljs.core.assoc,ns,new_ns); + +return new_ns; +} +} +}); +/** + * Returns the macros namespace named by the symbol or nil if it doesn't exist. + * Bootstrap only. + */ +cljs.core.find_macros_ns = (function cljs$core$find_macros_ns(ns){ +if((cljs.core.NS_CACHE == null)){ +cljs.core.NS_CACHE = cljs.core.atom.cljs$core$IFn$_invoke$arity$1(cljs.core.PersistentArrayMap.EMPTY); +} else { +} + +var ns_str = cljs.core.str.cljs$core$IFn$_invoke$arity$1(ns); +var ns__$1 = (((!(goog.string.contains(ns_str,"$macros"))))?cljs.core.symbol.cljs$core$IFn$_invoke$arity$1([ns_str,"$macros"].join('')):ns); +var the_ns = cljs.core.get.cljs$core$IFn$_invoke$arity$2(cljs.core.deref(cljs.core.NS_CACHE),ns__$1); +if((!((the_ns == null)))){ +return the_ns; +} else { +var ns_obj = cljs.core.find_ns_obj(ns__$1); +if((ns_obj == null)){ +return null; +} else { +var new_ns = cljs.core.create_ns.cljs$core$IFn$_invoke$arity$2(ns__$1,ns_obj); +cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$4(cljs.core.NS_CACHE,cljs.core.assoc,ns__$1,new_ns); + +return new_ns; +} +} +}); +/** + * Returns the name of the namespace, a Namespace object. + * Bootstrap only. + */ +cljs.core.ns_name = (function cljs$core$ns_name(ns_obj){ +return ns_obj.name; +}); +/** + * Returns true x is a goog.Uri instance. + */ +cljs.core.uri_QMARK_ = (function cljs$core$uri_QMARK_(x){ +return (x instanceof goog.Uri); +}); +cljs.core.maybe_enable_print_BANG_ = (function cljs$core$maybe_enable_print_BANG_(){ +if((typeof console !== 'undefined')){ +return cljs.core.enable_console_print_BANG_(); +} else { +if((((cljs.core._STAR_target_STAR_ === "nashorn")) || ((cljs.core._STAR_target_STAR_ === "graaljs")))){ +var system = Java.type("java.lang.System"); +cljs.core._STAR_print_newline_STAR_ = false; + +cljs.core.set_print_fn_BANG_(((function (system){ +return (function (){ +var xs = arguments; +var s = goog.array.clone(xs).join(""); +return system.out.println(s); +});})(system)) +); + +return cljs.core.set_print_err_fn_BANG_(((function (system){ +return (function (){ +var xs = arguments; +var s = goog.array.clone(xs).join(""); +return system.error.println(s); +});})(system)) +); +} else { +return null; +} +} +}); +cljs.core.maybe_enable_print_BANG_(); +if((typeof cljs !== 'undefined') && (typeof cljs.core !== 'undefined') && (typeof cljs.core._STAR_eval_STAR_ !== 'undefined')){ +} else { +/** + * Runtime environments may provide a way to evaluate ClojureScript + * forms. Whatever function *eval* is bound to will be passed any forms which + * should be evaluated. + */ +cljs.core._STAR_eval_STAR_ = (function cljs$core$_STAR_eval_STAR_(_){ +throw (new Error("cljs.core/*eval* not bound")); +}); +} +/** + * Evaluates the form data structure (not text!) and returns the result. + * Delegates to cljs.core/*eval*. Intended for use in self-hosted ClojureScript, + * which sets up an implementation of cljs.core/*eval* for that environment. + */ +cljs.core.eval = (function cljs$core$eval(form){ +return (cljs.core._STAR_eval_STAR_.cljs$core$IFn$_invoke$arity$1 ? cljs.core._STAR_eval_STAR_.cljs$core$IFn$_invoke$arity$1(form) : cljs.core._STAR_eval_STAR_.call(null,form)); +}); diff --git a/resources/public/js/optimized/cljs/core/constants.js b/resources/public/js/optimized/cljs/core/constants.js new file mode 100644 index 0000000..bb368c5 --- /dev/null +++ b/resources/public/js/optimized/cljs/core/constants.js @@ -0,0 +1,386 @@ +goog.provide('cljs.core.constants'); +goog.require('cljs.core'); +cljs.core.cst$kw$y = new cljs.core.Keyword(null,"y","y",-1757859776); +cljs.core.cst$sym$form = new cljs.core.Symbol(null,"form","form",16469056,null); +cljs.core.cst$kw$key_DASH_code = new cljs.core.Keyword(null,"key-code","key-code",-1732114304); +cljs.core.cst$sym$tag = new cljs.core.Symbol(null,"tag","tag",350170304,null); +cljs.core.cst$sym$_AMPERSAND_ = new cljs.core.Symbol(null,"&","&",-2144855648,null); +cljs.core.cst$sym$uuid = new cljs.core.Symbol(null,"uuid","uuid",-504564192,null); +cljs.core.cst$kw$shift = new cljs.core.Keyword(null,"shift","shift",997140064); +cljs.core.cst$kw$features = new cljs.core.Keyword(null,"features","features",-1146962336); +cljs.core.cst$sym$case_STAR_ = new cljs.core.Symbol(null,"case*","case*",-1938255072,null); +cljs.core.cst$kw$open = new cljs.core.Keyword(null,"open","open",-1763596448); +cljs.core.cst$kw$baseline = new cljs.core.Keyword(null,"baseline","baseline",1151033280); +cljs.core.cst$kw$bold = new cljs.core.Keyword(null,"bold","bold",-116809535); +cljs.core.cst$sym$end = new cljs.core.Symbol(null,"end","end",1372345569,null); +cljs.core.cst$kw$disable_DASH_stroke_DASH_perspective = new cljs.core.Keyword(null,"disable-stroke-perspective","disable-stroke-perspective",479198433); +cljs.core.cst$sym$quil$core_SLASH_PGraphics = new cljs.core.Symbol("quil.core","PGraphics","quil.core/PGraphics",-1265754815,null); +cljs.core.cst$sym$defrecord_STAR_ = new cljs.core.Symbol(null,"defrecord*","defrecord*",-1936366207,null); +cljs.core.cst$sym$base = new cljs.core.Symbol(null,"base","base",1825810849,null); +cljs.core.cst$sym$obj = new cljs.core.Symbol(null,"obj","obj",-1672671807,null); +cljs.core.cst$kw$hsb = new cljs.core.Keyword(null,"hsb","hsb",-753472031); +cljs.core.cst$kw$quads = new cljs.core.Keyword(null,"quads","quads",1347497505); +cljs.core.cst$sym$fqn = new cljs.core.Symbol(null,"fqn","fqn",-1749334463,null); +cljs.core.cst$kw$arrow = new cljs.core.Keyword(null,"arrow","arrow",1071351425); +cljs.core.cst$kw$dilate = new cljs.core.Keyword(null,"dilate","dilate",1504745153); +cljs.core.cst$sym$first = new cljs.core.Symbol(null,"first","first",996428481,null); +cljs.core.cst$sym$quil$core_SLASH_current_DASH_fill = new cljs.core.Symbol("quil.core","current-fill","quil.core/current-fill",269663137,null); +cljs.core.cst$sym$try = new cljs.core.Symbol(null,"try","try",-1273693247,null); +cljs.core.cst$sym$has_DASH_nil_QMARK_ = new cljs.core.Symbol(null,"has-nil?","has-nil?",825886722,null); +cljs.core.cst$sym$quil$core_SLASH__STAR_graphics_STAR_ = new cljs.core.Symbol("quil.core","*graphics*","quil.core/*graphics*",-1088142302,null); +cljs.core.cst$kw$quad_DASH_strip = new cljs.core.Keyword(null,"quad-strip","quad-strip",-1297270686); +cljs.core.cst$kw$down = new cljs.core.Keyword(null,"down","down",1565245570); +cljs.core.cst$sym$cljs$core_SLASH_sequential_QMARK_ = new cljs.core.Symbol("cljs.core","sequential?","cljs.core/sequential?",1777854658,null); +cljs.core.cst$kw$disable_DASH_depth_DASH_mask = new cljs.core.Keyword(null,"disable-depth-mask","disable-depth-mask",3298562); +cljs.core.cst$kw$pixels_DASH_in_DASH_360 = new cljs.core.Keyword(null,"pixels-in-360","pixels-in-360",1789567298); +cljs.core.cst$kw$frame_DASH_rate = new cljs.core.Keyword(null,"frame-rate","frame-rate",-994918942); +cljs.core.cst$kw$p_DASH_y = new cljs.core.Keyword(null,"p-y","p-y",-530704830); +cljs.core.cst$sym$tr__5974__auto__ = new cljs.core.Symbol(null,"tr__5974__auto__","tr__5974__auto__",-592553406,null); +cljs.core.cst$kw$step_DASH_size = new cljs.core.Keyword(null,"step-size","step-size",1545609922); +cljs.core.cst$kw$zoom = new cljs.core.Keyword(null,"zoom","zoom",-1827487038); +cljs.core.cst$sym$quil$core_SLASH_no_DASH_fill = new cljs.core.Symbol("quil.core","no-fill","quil.core/no-fill",-389901598,null); +cljs.core.cst$sym$rear = new cljs.core.Symbol(null,"rear","rear",-900164830,null); +cljs.core.cst$sym$hierarchy = new cljs.core.Symbol(null,"hierarchy","hierarchy",587061186,null); +cljs.core.cst$sym$iter = new cljs.core.Symbol(null,"iter","iter",-1346195486,null); +cljs.core.cst$sym$cljs$core_SLASH_binding = new cljs.core.Symbol("cljs.core","binding","cljs.core/binding",2050379843,null); +cljs.core.cst$kw$space = new cljs.core.Keyword(null,"space","space",348133475); +cljs.core.cst$kw$burn = new cljs.core.Keyword(null,"burn","burn",-458179293); +cljs.core.cst$sym$step = new cljs.core.Symbol(null,"step","step",-1365547645,null); +cljs.core.cst$sym$boolean = new cljs.core.Symbol(null,"boolean","boolean",-278886877,null); +cljs.core.cst$kw$key_DASH_typed = new cljs.core.Keyword(null,"key-typed","key-typed",-876037597); +cljs.core.cst$sym$update_DASH_count = new cljs.core.Symbol(null,"update-count","update-count",-411982269,null); +cljs.core.cst$kw$mouse_DASH_clicked = new cljs.core.Keyword(null,"mouse-clicked","mouse-clicked",-199339421); +cljs.core.cst$sym$method_DASH_table = new cljs.core.Symbol(null,"method-table","method-table",-1878263165,null); +cljs.core.cst$kw$mouse_DASH_released = new cljs.core.Keyword(null,"mouse-released","mouse-released",-664480061); +cljs.core.cst$kw$ready = new cljs.core.Keyword(null,"ready","ready",1086465795); +cljs.core.cst$kw$posterize = new cljs.core.Keyword(null,"posterize","posterize",-148251901); +cljs.core.cst$sym$chunk = new cljs.core.Symbol(null,"chunk","chunk",449371907,null); +cljs.core.cst$kw$fn = new cljs.core.Keyword(null,"fn","fn",-1175266204); +cljs.core.cst$sym$quil$sketch_SLASH_with_DASH_sketch = new cljs.core.Symbol("quil.sketch","with-sketch","quil.sketch/with-sketch",-634067708,null); +cljs.core.cst$sym$i = new cljs.core.Symbol(null,"i","i",253690212,null); +cljs.core.cst$kw$f8 = new cljs.core.Keyword(null,"f8","f8",-2141475484); +cljs.core.cst$kw$bolditalic = new cljs.core.Keyword(null,"bolditalic","bolditalic",-1629061788); +cljs.core.cst$sym$rest = new cljs.core.Symbol(null,"rest","rest",398835108,null); +cljs.core.cst$kw$meta = new cljs.core.Keyword(null,"meta","meta",1499536964); +cljs.core.cst$sym$quil$core_SLASH_translate = new cljs.core.Symbol("quil.core","translate","quil.core/translate",150889028,null); +cljs.core.cst$kw$screen = new cljs.core.Keyword(null,"screen","screen",1990059748); +cljs.core.cst$kw$enable_DASH_depth_DASH_test = new cljs.core.Keyword(null,"enable-depth-test","enable-depth-test",1519326084); +cljs.core.cst$kw$mouse_DASH_exited = new cljs.core.Keyword(null,"mouse-exited","mouse-exited",-483205244); +cljs.core.cst$kw$gray = new cljs.core.Keyword(null,"gray","gray",1013268388); +cljs.core.cst$kw$frame = new cljs.core.Keyword(null,"frame","frame",-1711082588); +cljs.core.cst$kw$enable_DASH_depth_DASH_sort = new cljs.core.Keyword(null,"enable-depth-sort","enable-depth-sort",-383089627); +cljs.core.cst$kw$f1 = new cljs.core.Keyword(null,"f1","f1",1714532389); +cljs.core.cst$sym$stroke__5954__auto__ = new cljs.core.Symbol(null,"stroke__5954__auto__","stroke__5954__auto__",-1076007899,null); +cljs.core.cst$sym$quil$core_SLASH_no_DASH_stroke = new cljs.core.Symbol("quil.core","no-stroke","quil.core/no-stroke",779188421,null); +cljs.core.cst$kw$dup = new cljs.core.Keyword(null,"dup","dup",556298533); +cljs.core.cst$kw$java2d = new cljs.core.Keyword(null,"java2d","java2d",166099237); +cljs.core.cst$kw$corner = new cljs.core.Keyword(null,"corner","corner",1296717125); +cljs.core.cst$kw$disable_DASH_texture_DASH_mipmaps = new cljs.core.Keyword(null,"disable-texture-mipmaps","disable-texture-mipmaps",1697917541); +cljs.core.cst$kw$key = new cljs.core.Keyword(null,"key","key",-1516042587); +cljs.core.cst$sym$comp = new cljs.core.Symbol(null,"comp","comp",-1462482139,null); +cljs.core.cst$sym$dispatch_DASH_fn = new cljs.core.Symbol(null,"dispatch-fn","dispatch-fn",-1401088155,null); +cljs.core.cst$kw$darkest = new cljs.core.Keyword(null,"darkest","darkest",68197253); +cljs.core.cst$sym$buffer = new cljs.core.Symbol(null,"buffer","buffer",-2037140571,null); +cljs.core.cst$kw$f10 = new cljs.core.Keyword(null,"f10","f10",627525541); +cljs.core.cst$kw$dodge = new cljs.core.Keyword(null,"dodge","dodge",-1556666427); +cljs.core.cst$kw$bottom = new cljs.core.Keyword(null,"bottom","bottom",-1550509018); +cljs.core.cst$kw$bevel = new cljs.core.Keyword(null,"bevel","bevel",2090515654); +cljs.core.cst$sym$quil$core_SLASH_end_DASH_draw = new cljs.core.Symbol("quil.core","end-draw","quil.core/end-draw",1718268198,null); +cljs.core.cst$kw$else = new cljs.core.Keyword(null,"else","else",-1508377146); +cljs.core.cst$kw$on_DASH_close = new cljs.core.Keyword(null,"on-close","on-close",-761178394); +cljs.core.cst$kw$disable_DASH_stroke_DASH_pure = new cljs.core.Keyword(null,"disable-stroke-pure","disable-stroke-pure",735493926); +cljs.core.cst$kw$replace = new cljs.core.Keyword(null,"replace","replace",-786587770); +cljs.core.cst$kw$alt = new cljs.core.Keyword(null,"alt","alt",-3214426); +cljs.core.cst$sym$left = new cljs.core.Symbol(null,"left","left",1241415590,null); +cljs.core.cst$sym$ns_STAR_ = new cljs.core.Symbol(null,"ns*","ns*",1840949383,null); +cljs.core.cst$kw$cljs$core_SLASH_none = new cljs.core.Keyword("cljs.core","none","cljs.core/none",926646439); +cljs.core.cst$sym$shift = new cljs.core.Symbol(null,"shift","shift",-1657295705,null); +cljs.core.cst$sym$iters = new cljs.core.Symbol(null,"iters","iters",719353031,null); +cljs.core.cst$kw$button = new cljs.core.Keyword(null,"button","button",1456579943); +cljs.core.cst$kw$top = new cljs.core.Keyword(null,"top","top",-1856271961); +cljs.core.cst$kw$mouse_DASH_wheel = new cljs.core.Keyword(null,"mouse-wheel","mouse-wheel",1811662439); +cljs.core.cst$sym$cljs$core_SLASH_apply = new cljs.core.Symbol("cljs.core","apply","cljs.core/apply",1757277831,null); +cljs.core.cst$sym$xform = new cljs.core.Symbol(null,"xform","xform",-85179481,null); +cljs.core.cst$kw$validator = new cljs.core.Keyword(null,"validator","validator",-1966190681); +cljs.core.cst$kw$disable_DASH_depth_DASH_test = new cljs.core.Keyword(null,"disable-depth-test","disable-depth-test",284606407); +cljs.core.cst$sym$finally = new cljs.core.Symbol(null,"finally","finally",-1065347064,null); +cljs.core.cst$kw$keyPressed = new cljs.core.Keyword(null,"keyPressed","keyPressed",1791025256); +cljs.core.cst$kw$default = new cljs.core.Keyword(null,"default","default",-1987822328); +cljs.core.cst$sym$prefer_DASH_table = new cljs.core.Symbol(null,"prefer-table","prefer-table",462168584,null); +cljs.core.cst$sym$loop_STAR_ = new cljs.core.Symbol(null,"loop*","loop*",615029416,null); +cljs.core.cst$sym$watches = new cljs.core.Symbol(null,"watches","watches",1367433992,null); +cljs.core.cst$kw$ns = new cljs.core.Keyword(null,"ns","ns",441598760); +cljs.core.cst$kw$grid = new cljs.core.Keyword(null,"grid","grid",402978600); +cljs.core.cst$kw$pie = new cljs.core.Keyword(null,"pie","pie",1530441672); +cljs.core.cst$sym$quil$core_SLASH_pop_DASH_matrix = new cljs.core.Symbol("quil.core","pop-matrix","quil.core/pop-matrix",310892617,null); +cljs.core.cst$kw$decor = new cljs.core.Keyword(null,"decor","decor",-1730969431); +cljs.core.cst$kw$w = new cljs.core.Keyword(null,"w","w",354169001); +cljs.core.cst$kw$pending = new cljs.core.Keyword(null,"pending","pending",-220036727); +cljs.core.cst$sym$bitmap = new cljs.core.Symbol(null,"bitmap","bitmap",501334601,null); +cljs.core.cst$kw$enable_DASH_stroke_DASH_perspective = new cljs.core.Keyword(null,"enable-stroke-perspective","enable-stroke-perspective",-259923319); +cljs.core.cst$sym$_seq = new cljs.core.Symbol(null,"_seq","_seq",-449557847,null); +cljs.core.cst$sym$nil_DASH_val = new cljs.core.Symbol(null,"nil-val","nil-val",-513933559,null); +cljs.core.cst$kw$opengl = new cljs.core.Keyword(null,"opengl","opengl",-614998103); +cljs.core.cst$kw$mouse_DASH_moved = new cljs.core.Keyword(null,"mouse-moved","mouse-moved",-1918152310); +cljs.core.cst$kw$file = new cljs.core.Keyword(null,"file","file",-1269645878); +cljs.core.cst$sym$v = new cljs.core.Symbol(null,"v","v",1661996586,null); +cljs.core.cst$kw$end_DASH_column = new cljs.core.Keyword(null,"end-column","end-column",1425389514); +cljs.core.cst$kw$safe_DASH_draw_DASH_fn = new cljs.core.Keyword(null,"safe-draw-fn","safe-draw-fn",1454900202); +cljs.core.cst$kw$chord = new cljs.core.Keyword(null,"chord","chord",-696248342); +cljs.core.cst$sym$riter = new cljs.core.Symbol(null,"riter","riter",-237834262,null); +cljs.core.cst$sym$__hash = new cljs.core.Symbol(null,"__hash","__hash",-1328796629,null); +cljs.core.cst$kw$rgb = new cljs.core.Keyword(null,"rgb","rgb",1432123467); +cljs.core.cst$sym$meta = new cljs.core.Symbol(null,"meta","meta",-1154898805,null); +cljs.core.cst$sym$_meta = new cljs.core.Symbol(null,"_meta","_meta",-1716892533,null); +cljs.core.cst$sym$meta1566 = new cljs.core.Symbol(null,"meta1566","meta1566",-1745668885,null); +cljs.core.cst$sym$$dispose = new cljs.core.Symbol(null,".dispose",".dispose",-1697594101,null); +cljs.core.cst$sym$gr__5983__auto__ = new cljs.core.Symbol(null,"gr__5983__auto__","gr__5983__auto__",1565352203,null); +cljs.core.cst$kw$lines = new cljs.core.Keyword(null,"lines","lines",-700165781); +cljs.core.cst$sym$afn = new cljs.core.Symbol(null,"afn","afn",216963467,null); +cljs.core.cst$kw$argb = new cljs.core.Keyword(null,"argb","argb",633844107); +cljs.core.cst$kw$mouseOut = new cljs.core.Keyword(null,"mouseOut","mouseOut",-386669045); +cljs.core.cst$kw$move = new cljs.core.Keyword(null,"move","move",-2110884309); +cljs.core.cst$sym$tree = new cljs.core.Symbol(null,"tree","tree",1444219499,null); +cljs.core.cst$sym$fn = new cljs.core.Symbol(null,"fn","fn",465265323,null); +cljs.core.cst$kw$f5 = new cljs.core.Keyword(null,"f5","f5",1587057387); +cljs.core.cst$kw$settings = new cljs.core.Keyword(null,"settings","settings",1556144875); +cljs.core.cst$sym$front = new cljs.core.Symbol(null,"front","front",117022539,null); +cljs.core.cst$sym$buf = new cljs.core.Symbol(null,"buf","buf",1426618187,null); +cljs.core.cst$sym$tr__5965__auto__ = new cljs.core.Symbol(null,"tr__5965__auto__","tr__5965__auto__",-816620693,null); +cljs.core.cst$kw$command = new cljs.core.Keyword(null,"command","command",-894540724); +cljs.core.cst$sym$next_DASH_entry = new cljs.core.Symbol(null,"next-entry","next-entry",1091342476,null); +cljs.core.cst$kw$val = new cljs.core.Keyword(null,"val","val",128701612); +cljs.core.cst$sym$key = new cljs.core.Symbol(null,"key","key",124488940,null); +cljs.core.cst$sym$_next = new cljs.core.Symbol(null,"_next","_next",101877036,null); +cljs.core.cst$sym$quil$core_SLASH_stroke = new cljs.core.Symbol("quil.core","stroke","quil.core/stroke",577473004,null); +cljs.core.cst$kw$hsl = new cljs.core.Keyword(null,"hsl","hsl",-1282948596); +cljs.core.cst$kw$update = new cljs.core.Keyword(null,"update","update",1045576396); +cljs.core.cst$sym$root_DASH_iter = new cljs.core.Symbol(null,"root-iter","root-iter",1974672108,null); +cljs.core.cst$sym$do = new cljs.core.Symbol(null,"do","do",1686842252,null); +cljs.core.cst$sym$vec = new cljs.core.Symbol(null,"vec","vec",982683596,null); +cljs.core.cst$kw$miter = new cljs.core.Keyword(null,"miter","miter",327727052); +cljs.core.cst$kw$points = new cljs.core.Keyword(null,"points","points",-1486596883); +cljs.core.cst$kw$fallback_DASH_impl = new cljs.core.Keyword(null,"fallback-impl","fallback-impl",-1501286995); +cljs.core.cst$kw$keyword_DASH_fn = new cljs.core.Keyword(null,"keyword-fn","keyword-fn",-64566675); +cljs.core.cst$kw$hand = new cljs.core.Keyword(null,"hand","hand",791601933); +cljs.core.cst$kw$flush_DASH_on_DASH_newline = new cljs.core.Keyword(null,"flush-on-newline","flush-on-newline",-151457939); +cljs.core.cst$kw$mouseDragged = new cljs.core.Keyword(null,"mouseDragged","mouseDragged",129975181); +cljs.core.cst$sym$default_DASH_dispatch_DASH_val = new cljs.core.Symbol(null,"default-dispatch-val","default-dispatch-val",-1231201266,null); +cljs.core.cst$kw$no_DASH_test = new cljs.core.Keyword(null,"no-test","no-test",-1679482642); +cljs.core.cst$kw$close = new cljs.core.Keyword(null,"close","close",1835149582); +cljs.core.cst$sym$fill__5943__auto__ = new cljs.core.Symbol(null,"fill__5943__auto__","fill__5943__auto__",-2049998450,null); +cljs.core.cst$sym$validator = new cljs.core.Symbol(null,"validator","validator",-325659154,null); +cljs.core.cst$kw$radius = new cljs.core.Keyword(null,"radius","radius",-2073122258); +cljs.core.cst$kw$normal = new cljs.core.Keyword(null,"normal","normal",-1519123858); +cljs.core.cst$sym$letfn_STAR_ = new cljs.core.Symbol(null,"letfn*","letfn*",-110097810,null); +cljs.core.cst$sym$if = new cljs.core.Symbol(null,"if","if",1181717262,null); +cljs.core.cst$kw$s = new cljs.core.Keyword(null,"s","s",1705939918); +cljs.core.cst$sym$previous_DASH_fill__5944__auto__ = new cljs.core.Symbol(null,"previous-fill__5944__auto__","previous-fill__5944__auto__",1519336559,null); +cljs.core.cst$sym$arr = new cljs.core.Symbol(null,"arr","arr",2115492975,null); +cljs.core.cst$kw$threshold = new cljs.core.Keyword(null,"threshold","threshold",204221583); +cljs.core.cst$sym$new = new cljs.core.Symbol(null,"new","new",-444906321,null); +cljs.core.cst$kw$rotate_DASH_on = new cljs.core.Keyword(null,"rotate-on","rotate-on",-1282225937); +cljs.core.cst$kw$up = new cljs.core.Keyword(null,"up","up",-269712113); +cljs.core.cst$kw$descendants = new cljs.core.Keyword(null,"descendants","descendants",1824886031); +cljs.core.cst$kw$renderer = new cljs.core.Keyword(null,"renderer","renderer",336841071); +cljs.core.cst$sym$ns = new cljs.core.Symbol(null,"ns","ns",2082130287,null); +cljs.core.cst$kw$size = new cljs.core.Keyword(null,"size","size",1098693007); +cljs.core.cst$kw$title = new cljs.core.Keyword(null,"title","title",636505583); +cljs.core.cst$kw$column = new cljs.core.Keyword(null,"column","column",2078222095); +cljs.core.cst$kw$center = new cljs.core.Keyword(null,"center","center",-748944368); +cljs.core.cst$sym$completed = new cljs.core.Symbol(null,"completed","completed",1154475024,null); +cljs.core.cst$kw$setup = new cljs.core.Keyword(null,"setup","setup",1987730512); +cljs.core.cst$kw$mouse_DASH_pressed = new cljs.core.Keyword(null,"mouse-pressed","mouse-pressed",736955536); +cljs.core.cst$kw$ancestors = new cljs.core.Keyword(null,"ancestors","ancestors",-776045424); +cljs.core.cst$kw$middleware = new cljs.core.Keyword(null,"middleware","middleware",1462115504); +cljs.core.cst$kw$round = new cljs.core.Keyword(null,"round","round",2009433328); +cljs.core.cst$kw$disable_DASH_optimized_DASH_stroke = new cljs.core.Keyword(null,"disable-optimized-stroke","disable-optimized-stroke",74038544); +cljs.core.cst$kw$mouseWheel = new cljs.core.Keyword(null,"mouseWheel","mouseWheel",-1057803856); +cljs.core.cst$sym$value = new cljs.core.Symbol(null,"value","value",1946509744,null); +cljs.core.cst$kw$focus_DASH_gained = new cljs.core.Keyword(null,"focus-gained","focus-gained",-857086384); +cljs.core.cst$sym$name = new cljs.core.Symbol(null,"name","name",-810760592,null); +cljs.core.cst$kw$readably = new cljs.core.Keyword(null,"readably","readably",1129599760); +cljs.core.cst$kw$more_DASH_marker = new cljs.core.Keyword(null,"more-marker","more-marker",-14717935); +cljs.core.cst$sym$cljs$core_SLASH_let = new cljs.core.Symbol("cljs.core","let","cljs.core/let",-308701135,null); +cljs.core.cst$sym$fields = new cljs.core.Symbol(null,"fields","fields",-291534703,null); +cljs.core.cst$kw$corners = new cljs.core.Keyword(null,"corners","corners",-137817903); +cljs.core.cst$sym$method_DASH_cache = new cljs.core.Symbol(null,"method-cache","method-cache",1230193905,null); +cljs.core.cst$kw$z = new cljs.core.Keyword(null,"z","z",-789527183); +cljs.core.cst$kw$f11 = new cljs.core.Keyword(null,"f11","f11",-1417398799); +cljs.core.cst$kw$host = new cljs.core.Keyword(null,"host","host",-1558485167); +cljs.core.cst$sym$edit = new cljs.core.Symbol(null,"edit","edit",-1302639,null); +cljs.core.cst$sym$cljs$core_SLASH_cond = new cljs.core.Symbol("cljs.core","cond","cljs.core/cond",2005388338,null); +cljs.core.cst$sym$editable_QMARK_ = new cljs.core.Symbol(null,"editable?","editable?",-164945806,null); +cljs.core.cst$kw$opaque = new cljs.core.Keyword(null,"opaque","opaque",-1243552654); +cljs.core.cst$kw$straight = new cljs.core.Keyword(null,"straight","straight",-1252567854); +cljs.core.cst$sym$base_DASH_count = new cljs.core.Symbol(null,"base-count","base-count",-1180647182,null); +cljs.core.cst$kw$overlay = new cljs.core.Keyword(null,"overlay","overlay",-139131598); +cljs.core.cst$kw$mouse_DASH_entered = new cljs.core.Keyword(null,"mouse-entered","mouse-entered",811350322); +cljs.core.cst$sym$collision_DASH_hash = new cljs.core.Symbol(null,"collision-hash","collision-hash",-35831342,null); +cljs.core.cst$sym$deftype_STAR_ = new cljs.core.Symbol(null,"deftype*","deftype*",962659890,null); +cljs.core.cst$sym$let_STAR_ = new cljs.core.Symbol(null,"let*","let*",1920721458,null); +cljs.core.cst$kw$enable_DASH_opengl_DASH_errors = new cljs.core.Keyword(null,"enable-opengl-errors","enable-opengl-errors",89998962); +cljs.core.cst$sym$start = new cljs.core.Symbol(null,"start","start",1285322546,null); +cljs.core.cst$sym$sourceIter = new cljs.core.Symbol(null,"sourceIter","sourceIter",1068220306,null); +cljs.core.cst$sym$coll = new cljs.core.Symbol(null,"coll","coll",-1006698606,null); +cljs.core.cst$sym$not_DASH_native = new cljs.core.Symbol(null,"not-native","not-native",-236392494,null); +cljs.core.cst$sym$js_STAR_ = new cljs.core.Symbol(null,"js*","js*",-1134233646,null); +cljs.core.cst$kw$enable_DASH_stroke_DASH_pure = new cljs.core.Keyword(null,"enable-stroke-pure","enable-stroke-pure",881345587); +cljs.core.cst$sym$strobj = new cljs.core.Symbol(null,"strobj","strobj",1088091283,null); +cljs.core.cst$kw$no_DASH_safe_DASH_draw = new cljs.core.Keyword(null,"no-safe-draw","no-safe-draw",-1157778157); +cljs.core.cst$kw$line = new cljs.core.Keyword(null,"line","line",212345235); +cljs.core.cst$kw$blur = new cljs.core.Keyword(null,"blur","blur",-453500461); +cljs.core.cst$sym$_rest = new cljs.core.Symbol(null,"_rest","_rest",-2100466189,null); +cljs.core.cst$kw$enable_DASH_async_DASH_saveframe = new cljs.core.Keyword(null,"enable-async-saveframe","enable-async-saveframe",-1817644525); +cljs.core.cst$kw$project = new cljs.core.Keyword(null,"project","project",1124394579); +cljs.core.cst$kw$triangle_DASH_fan = new cljs.core.Keyword(null,"triangle-fan","triangle-fan",1743150739); +cljs.core.cst$kw$focus_DASH_lost = new cljs.core.Keyword(null,"focus-lost","focus-lost",-554849613); +cljs.core.cst$sym$fn_STAR_ = new cljs.core.Symbol(null,"fn*","fn*",-752876845,null); +cljs.core.cst$kw$f3 = new cljs.core.Keyword(null,"f3","f3",1954829043); +cljs.core.cst$sym$val = new cljs.core.Symbol(null,"val","val",1769233139,null); +cljs.core.cst$sym$ascending_QMARK_ = new cljs.core.Symbol(null,"ascending?","ascending?",-1938452653,null); +cljs.core.cst$sym$recur = new cljs.core.Symbol(null,"recur","recur",1202958259,null); +cljs.core.cst$sym$xf = new cljs.core.Symbol(null,"xf","xf",2042434515,null); +cljs.core.cst$sym$ci = new cljs.core.Symbol(null,"ci","ci",2049808339,null); +cljs.core.cst$kw$enable_DASH_depth_DASH_mask = new cljs.core.Keyword(null,"enable-depth-mask","enable-depth-mask",872785875); +cljs.core.cst$kw$status = new cljs.core.Keyword(null,"status","status",-1997798413); +cljs.core.cst$kw$key_DASH_pressed = new cljs.core.Keyword(null,"key-pressed","key-pressed",-757100364); +cljs.core.cst$kw$key_DASH_released = new cljs.core.Keyword(null,"key-released","key-released",215919828); +cljs.core.cst$kw$print_DASH_length = new cljs.core.Keyword(null,"print-length","print-length",1931866356); +cljs.core.cst$sym$gr__5797__auto__ = new cljs.core.Symbol(null,"gr__5797__auto__","gr__5797__auto__",804484404,null); +cljs.core.cst$kw$f2 = new cljs.core.Keyword(null,"f2","f2",396168596); +cljs.core.cst$kw$keyReleased = new cljs.core.Keyword(null,"keyReleased","keyReleased",541714964); +cljs.core.cst$sym$state = new cljs.core.Symbol(null,"state","state",-348086572,null); +cljs.core.cst$kw$control = new cljs.core.Keyword(null,"control","control",1892578036); +cljs.core.cst$kw$ok = new cljs.core.Keyword(null,"ok","ok",967785236); +cljs.core.cst$kw$current_DASH_fill = new cljs.core.Keyword(null,"current-fill","current-fill",1421462292); +cljs.core.cst$kw$difference = new cljs.core.Keyword(null,"difference","difference",1916101396); +cljs.core.cst$sym$quil$core_SLASH_push_DASH_matrix = new cljs.core.Symbol("quil.core","push-matrix","quil.core/push-matrix",1356326676,null); +cljs.core.cst$sym$vals = new cljs.core.Symbol(null,"vals","vals",-1886377036,null); +cljs.core.cst$sym$all = new cljs.core.Symbol(null,"all","all",-1762306027,null); +cljs.core.cst$kw$looping_QMARK_ = new cljs.core.Keyword(null,"looping?","looping?",78344245); +cljs.core.cst$kw$cljs$core_SLASH_halt = new cljs.core.Keyword("cljs.core","halt","cljs.core/halt",-1049036715); +cljs.core.cst$kw$mouseClicked = new cljs.core.Keyword(null,"mouseClicked","mouseClicked",1764302965); +cljs.core.cst$kw$square = new cljs.core.Keyword(null,"square","square",812434677); +cljs.core.cst$sym$cached_DASH_hierarchy = new cljs.core.Symbol(null,"cached-hierarchy","cached-hierarchy",-1085460203,null); +cljs.core.cst$kw$enable_DASH_optimized_DASH_stroke = new cljs.core.Keyword(null,"enable-optimized-stroke","enable-optimized-stroke",1537575253); +cljs.core.cst$sym$s = new cljs.core.Symbol(null,"s","s",-948495851,null); +cljs.core.cst$kw$parents = new cljs.core.Keyword(null,"parents","parents",-2027538891); +cljs.core.cst$sym$cnt = new cljs.core.Symbol(null,"cnt","cnt",1924510325,null); +cljs.core.cst$sym$js_SLASH_p5$prototype = new cljs.core.Symbol("js","p5.prototype","js/p5.prototype",-1153964427,null); +cljs.core.cst$kw$p_DASH_x = new cljs.core.Keyword(null,"p-x","p-x",-1721211211); +cljs.core.cst$sym$cljs$core_SLASH_nil_QMARK_ = new cljs.core.Symbol("cljs.core","nil?","cljs.core/nil?",945071861,null); +cljs.core.cst$kw$p2d = new cljs.core.Keyword(null,"p2d","p2d",-2106175755); +cljs.core.cst$kw$keep_DASH_on_DASH_top = new cljs.core.Keyword(null,"keep-on-top","keep-on-top",-970284267); +cljs.core.cst$kw$navigation_DASH_3d = new cljs.core.Keyword(null,"navigation-3d","navigation-3d",682305301); +cljs.core.cst$sym$node = new cljs.core.Symbol(null,"node","node",-2073234571,null); +cljs.core.cst$kw$mouseReleased = new cljs.core.Keyword(null,"mouseReleased","mouseReleased",1116234838); +cljs.core.cst$kw$mousePressed = new cljs.core.Keyword(null,"mousePressed","mousePressed",1776186454); +cljs.core.cst$sym$sym = new cljs.core.Symbol(null,"sym","sym",195671222,null); +cljs.core.cst$kw$mouseMoved = new cljs.core.Keyword(null,"mouseMoved","mouseMoved",-1936954058); +cljs.core.cst$kw$f12 = new cljs.core.Keyword(null,"f12","f12",853352790); +cljs.core.cst$sym$sb = new cljs.core.Symbol(null,"sb","sb",-1249746442,null); +cljs.core.cst$kw$mouseOver = new cljs.core.Keyword(null,"mouseOver","mouseOver",-1334461930); +cljs.core.cst$kw$exclusion = new cljs.core.Keyword(null,"exclusion","exclusion",531897910); +cljs.core.cst$sym$quil$core_SLASH_fill = new cljs.core.Symbol("quil.core","fill","quil.core/fill",814613078,null); +cljs.core.cst$sym$seed = new cljs.core.Symbol(null,"seed","seed",1709144854,null); +cljs.core.cst$kw$current_DASH_stroke = new cljs.core.Keyword(null,"current-stroke","current-stroke",-1338415274); +cljs.core.cst$kw$end_DASH_line = new cljs.core.Keyword(null,"end-line","end-line",1837326455); +cljs.core.cst$kw$disable_DASH_opengl_DASH_errors = new cljs.core.Keyword(null,"disable-opengl-errors","disable-opengl-errors",506822839); +cljs.core.cst$kw$unknown_DASH_key = new cljs.core.Keyword(null,"unknown-key","unknown-key",255305911); +cljs.core.cst$kw$alpha = new cljs.core.Keyword(null,"alpha","alpha",-1574982441); +cljs.core.cst$sym$prev_DASH_seed = new cljs.core.Symbol(null,"prev-seed","prev-seed",2126381367,null); +cljs.core.cst$kw$wait = new cljs.core.Keyword(null,"wait","wait",-260664777); +cljs.core.cst$kw$right = new cljs.core.Keyword(null,"right","right",-452581833); +cljs.core.cst$sym$quil$core_SLASH_current_DASH_stroke = new cljs.core.Symbol("quil.core","current-stroke","quil.core/current-stroke",-1148124489,null); +cljs.core.cst$kw$host_DASH_id = new cljs.core.Keyword(null,"host-id","host-id",742376279); +cljs.core.cst$kw$repeat = new cljs.core.Keyword(null,"repeat","repeat",832692087); +cljs.core.cst$kw$hard_DASH_light = new cljs.core.Keyword(null,"hard-light","hard-light",-37591145); +cljs.core.cst$sym$quil$sketch$macros_SLASH_defsketch = new cljs.core.Symbol("quil.sketch$macros","defsketch","quil.sketch$macros/defsketch",2065609719,null); +cljs.core.cst$kw$keyTyped = new cljs.core.Keyword(null,"keyTyped","keyTyped",1437329399); +cljs.core.cst$kw$position = new cljs.core.Keyword(null,"position","position",-2011731912); +cljs.core.cst$kw$no_DASH_start = new cljs.core.Keyword(null,"no-start","no-start",1381488856); +cljs.core.cst$sym$_hash = new cljs.core.Symbol(null,"_hash","_hash",-2130838312,null); +cljs.core.cst$kw$image = new cljs.core.Keyword(null,"image","image",-58725096); +cljs.core.cst$kw$d = new cljs.core.Keyword(null,"d","d",1972142424); +cljs.core.cst$kw$disable_DASH_async_DASH_saveframe = new cljs.core.Keyword(null,"disable-async-saveframe","disable-async-saveframe",-1346138728); +cljs.core.cst$kw$multiply = new cljs.core.Keyword(null,"multiply","multiply",-1036907048); +cljs.core.cst$kw$lightest = new cljs.core.Keyword(null,"lightest","lightest",-2043115912); +cljs.core.cst$sym$quil$core_SLASH_rotate = new cljs.core.Symbol("quil.core","rotate","quil.core/rotate",-1944995048,null); +cljs.core.cst$kw$f7 = new cljs.core.Keyword(null,"f7","f7",356150168); +cljs.core.cst$sym$keys = new cljs.core.Symbol(null,"keys","keys",-1586012071,null); +cljs.core.cst$kw$x = new cljs.core.Keyword(null,"x","x",2099068185); +cljs.core.cst$kw$blend = new cljs.core.Keyword(null,"blend","blend",249565561); +cljs.core.cst$sym$set_BANG_ = new cljs.core.Symbol(null,"set!","set!",250714521,null); +cljs.core.cst$kw$disable_DASH_depth_DASH_sort = new cljs.core.Keyword(null,"disable-depth-sort","disable-depth-sort",-1568352839); +cljs.core.cst$sym$quil$core_SLASH_begin_DASH_draw = new cljs.core.Symbol("quil.core","begin-draw","quil.core/begin-draw",454448665,null); +cljs.core.cst$kw$tag = new cljs.core.Keyword(null,"tag","tag",-1290361223); +cljs.core.cst$sym$tree_DASH_map = new cljs.core.Symbol(null,"tree-map","tree-map",1373073049,null); +cljs.core.cst$kw$raw_DASH_key = new cljs.core.Keyword(null,"raw-key","raw-key",-162482279); +cljs.core.cst$kw$target = new cljs.core.Keyword(null,"target","target",253001721); +cljs.core.cst$sym$_DOT_ = new cljs.core.Symbol(null,".",".",1975675962,null); +cljs.core.cst$sym$var = new cljs.core.Symbol(null,"var","var",870848730,null); +cljs.core.cst$kw$mutable = new cljs.core.Keyword(null,"mutable","mutable",875778266); +cljs.core.cst$sym$quote = new cljs.core.Symbol(null,"quote","quote",1377916282,null); +cljs.core.cst$kw$f9 = new cljs.core.Keyword(null,"f9","f9",704633338); +cljs.core.cst$sym$root = new cljs.core.Symbol(null,"root","root",1191874074,null); +cljs.core.cst$sym$multi = new cljs.core.Symbol(null,"multi","multi",1450238522,null); +cljs.core.cst$sym$str = new cljs.core.Symbol(null,"str","str",-1564826950,null); +cljs.core.cst$sym$next = new cljs.core.Symbol(null,"next","next",1522830042,null); +cljs.core.cst$kw$draw = new cljs.core.Keyword(null,"draw","draw",1358331674); +cljs.core.cst$sym$nodes = new cljs.core.Symbol(null,"nodes","nodes",-459054278,null); +cljs.core.cst$sym$seen = new cljs.core.Symbol(null,"seen","seen",1121531738,null); +cljs.core.cst$sym$hash_DASH_map = new cljs.core.Symbol(null,"hash-map","hash-map",-439030950,null); +cljs.core.cst$kw$erode = new cljs.core.Keyword(null,"erode","erode",1539530618); +cljs.core.cst$kw$add = new cljs.core.Keyword(null,"add","add",235287739); +cljs.core.cst$sym$catch = new cljs.core.Symbol(null,"catch","catch",-1616370245,null); +cljs.core.cst$sym$return_DASH_val__5956__auto__ = new cljs.core.Symbol(null,"return-val__5956__auto__","return-val__5956__auto__",-813190725,null); +cljs.core.cst$kw$soft_DASH_light = new cljs.core.Keyword(null,"soft-light","soft-light",513207899); +cljs.core.cst$kw$alt_DASH_impl = new cljs.core.Keyword(null,"alt-impl","alt-impl",670969595); +cljs.core.cst$sym$ext_DASH_map_DASH_iter = new cljs.core.Symbol(null,"ext-map-iter","ext-map-iter",-1215982757,null); +cljs.core.cst$sym$tail = new cljs.core.Symbol(null,"tail","tail",494507963,null); +cljs.core.cst$sym$quil$core_SLASH_with_DASH_graphics = new cljs.core.Symbol("quil.core","with-graphics","quil.core/with-graphics",481277883,null); +cljs.core.cst$kw$subtract = new cljs.core.Keyword(null,"subtract","subtract",2136988635); +cljs.core.cst$kw$clamp = new cljs.core.Keyword(null,"clamp","clamp",1803814940); +cljs.core.cst$sym$record = new cljs.core.Symbol(null,"record","record",861424668,null); +cljs.core.cst$sym$meta3617 = new cljs.core.Symbol(null,"meta3617","meta3617",-1967821732,null); +cljs.core.cst$kw$italic = new cljs.core.Keyword(null,"italic","italic",32599196); +cljs.core.cst$sym$mseq = new cljs.core.Symbol(null,"mseq","mseq",1602647196,null); +cljs.core.cst$sym$count = new cljs.core.Symbol(null,"count","count",-514511684,null); +cljs.core.cst$kw$last_DASH_time = new cljs.core.Keyword(null,"last-time","last-time",-1707132740); +cljs.core.cst$kw$radians = new cljs.core.Keyword(null,"radians","radians",1835725084); +cljs.core.cst$kw$degrees = new cljs.core.Keyword(null,"degrees","degrees",2015169884); +cljs.core.cst$sym$previous_DASH_stroke__5955__auto__ = new cljs.core.Symbol(null,"previous-stroke__5955__auto__","previous-stroke__5955__auto__",1882972700,null); +cljs.core.cst$kw$f6 = new cljs.core.Keyword(null,"f6","f6",2103080604); +cljs.core.cst$kw$keywordize_DASH_keys = new cljs.core.Keyword(null,"keywordize-keys","keywordize-keys",1310784252); +cljs.core.cst$sym$current = new cljs.core.Symbol(null,"current","current",552492924,null); +cljs.core.cst$sym$off = new cljs.core.Symbol(null,"off","off",-2047994980,null); +cljs.core.cst$kw$clj = new cljs.core.Keyword(null,"clj","clj",-660495428); +cljs.core.cst$kw$f4 = new cljs.core.Keyword(null,"f4","f4",990968764); +cljs.core.cst$kw$triangle_DASH_strip = new cljs.core.Keyword(null,"triangle-strip","triangle-strip",221845500); +cljs.core.cst$kw$navigation_DASH_2d = new cljs.core.Keyword(null,"navigation-2d","navigation-2d",-1924168611); +cljs.core.cst$sym$stack = new cljs.core.Symbol(null,"stack","stack",847125597,null); +cljs.core.cst$sym$transient_DASH_map = new cljs.core.Symbol(null,"transient-map","transient-map",351764893,null); +cljs.core.cst$sym$prev = new cljs.core.Symbol(null,"prev","prev",43462301,null); +cljs.core.cst$sym$len = new cljs.core.Symbol(null,"len","len",-1230778691,null); +cljs.core.cst$sym$return_DASH_val__5945__auto__ = new cljs.core.Symbol(null,"return-val__5945__auto__","return-val__5945__auto__",-1144998083,null); +cljs.core.cst$kw$cross = new cljs.core.Keyword(null,"cross","cross",194557789); +cljs.core.cst$sym$right = new cljs.core.Symbol(null,"right","right",1187949694,null); +cljs.core.cst$sym$throw = new cljs.core.Symbol(null,"throw","throw",595905694,null); +cljs.core.cst$kw$p3d = new cljs.core.Keyword(null,"p3d","p3d",-850380194); +cljs.core.cst$sym$fseq = new cljs.core.Symbol(null,"fseq","fseq",-1466412450,null); +cljs.core.cst$kw$a = new cljs.core.Keyword(null,"a","a",-2123407586); +cljs.core.cst$sym$chunk_DASH_next = new cljs.core.Symbol(null,"chunk-next","chunk-next",-547810434,null); +cljs.core.cst$kw$triangles = new cljs.core.Keyword(null,"triangles","triangles",-1525417058); +cljs.core.cst$kw$mouse_DASH_dragged = new cljs.core.Keyword(null,"mouse-dragged","mouse-dragged",-1220073441); +cljs.core.cst$sym$cljs$core_SLASH_aget = new cljs.core.Symbol("cljs.core","aget","cljs.core/aget",6345791,null); +cljs.core.cst$kw$left = new cljs.core.Keyword(null,"left","left",-399115937); +cljs.core.cst$kw$cljs$core_SLASH_not_DASH_found = new cljs.core.Keyword("cljs.core","not-found","cljs.core/not-found",-1572889185); +cljs.core.cst$sym$more = new cljs.core.Symbol(null,"more","more",-418290273,null); +cljs.core.cst$sym$def = new cljs.core.Symbol(null,"def","def",597100991,null); +cljs.core.cst$kw$invert = new cljs.core.Keyword(null,"invert","invert",1553577503); +cljs.core.cst$kw$text = new cljs.core.Keyword(null,"text","text",-1790561697); +cljs.core.cst$kw$enable_DASH_texture_DASH_mipmaps = new cljs.core.Keyword(null,"enable-texture-mipmaps","enable-texture-mipmaps",1241892671); +cljs.core.cst$kw$model = new cljs.core.Keyword(null,"model","model",331153215); +cljs.core.cst$sym$f = new cljs.core.Symbol(null,"f","f",43394975,null); +cljs.core.cst$sym$next_DASH_iter = new cljs.core.Symbol(null,"next-iter","next-iter",1526626239,null); diff --git a/resources/public/js/optimized/cljsc_opts.edn b/resources/public/js/optimized/cljsc_opts.edn new file mode 100644 index 0000000..6661b75 --- /dev/null +++ b/resources/public/js/optimized/cljsc_opts.edn @@ -0,0 +1 @@ +{:output-wrapper true, :externs ["closure-js/externs"], :libs ["closure-js/libs"], :main "curlnoise.core", :output-to "resources/public/js/main.js", :output-dir "resources/public/js/optimized", :asset-path "js/optimized", :optimizations :advanced} \ No newline at end of file diff --git a/resources/public/js/optimized/cljsjs/p5/production/p5.min.inc.js b/resources/public/js/optimized/cljsjs/p5/production/p5.min.inc.js new file mode 100644 index 0000000..6cfd84a --- /dev/null +++ b/resources/public/js/optimized/cljsjs/p5/production/p5.min.inc.js @@ -0,0 +1,90025 @@ +/*! p5.js v0.9.0 July 01, 2019 */ +(function(f) { + if (typeof exports === 'object' && typeof module !== 'undefined') { + module.exports = f(); + } else if (typeof define === 'function' && define.amd) { + define([], f); + } else { + var g; + if (typeof window !== 'undefined') { + g = window; + } else if (typeof global !== 'undefined') { + g = global; + } else if (typeof self !== 'undefined') { + g = self; + } else { + g = this; + } + g.p5 = f(); + } +})(function() { + var define, module, exports; + return (function() { + function r(e, n, t) { + function o(i, f) { + if (!n[i]) { + if (!e[i]) { + var c = 'function' == typeof require && require; + if (!f && c) return c(i, !0); + if (u) return u(i, !0); + var a = new Error("Cannot find module '" + i + "'"); + throw ((a.code = 'MODULE_NOT_FOUND'), a); + } + var p = (n[i] = { exports: {} }); + e[i][0].call( + p.exports, + function(r) { + var n = e[i][1][r]; + return o(n || r); + }, + p, + p.exports, + r, + e, + n, + t + ); + } + return n[i].exports; + } + for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++) + o(t[i]); + return o; + } + return r; + })()( + { + 1: [ + function(_dereq_, module, exports) { + module.exports = { + project: { + name: 'p5', + description: + '[![Build Status](https://travis-ci.org/processing/p5.js.svg?branch=master)](https://travis-ci.org/processing/p5.js) [![npm version](https://badge.fury.io/js/p5.svg)](https://www.npmjs.com/package/p5)', + version: '0.9.0', + url: 'https://github.com/processing/p5.js#readme' + }, + files: { + 'src/color/color_conversion.js': { + name: 'src/color/color_conversion.js', + modules: { + 'Color Conversion': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/color/creating_reading.js': { + name: 'src/color/creating_reading.js', + modules: { + 'Creating & Reading': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/color/p5.Color.js': { + name: 'src/color/p5.Color.js', + modules: {}, + classes: { + 'p5.Color': 1 + }, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/color/setting.js': { + name: 'src/color/setting.js', + modules: { + Setting: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/shape/2d_primitives.js': { + name: 'src/core/shape/2d_primitives.js', + modules: { + '2D Primitives': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/shape/attributes.js': { + name: 'src/core/shape/attributes.js', + modules: { + Attributes: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/shape/curves.js': { + name: 'src/core/shape/curves.js', + modules: { + Curves: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/shape/vertex.js': { + name: 'src/core/shape/vertex.js', + modules: { + Vertex: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/constants.js': { + name: 'src/core/constants.js', + modules: { + Constants: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/environment.js': { + name: 'src/core/environment.js', + modules: { + Environment: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/error_helpers.js': { + name: 'src/core/error_helpers.js', + modules: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/helpers.js': { + name: 'src/core/helpers.js', + modules: {}, + classes: {}, + fors: {}, + namespaces: {} + }, + 'src/core/init.js': { + name: 'src/core/init.js', + modules: {}, + classes: {}, + fors: {}, + namespaces: {} + }, + 'src/core/legacy.js': { + name: 'src/core/legacy.js', + modules: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/main.js': { + name: 'src/core/main.js', + modules: { + Structure: 1 + }, + classes: { + p5: 1 + }, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/p5.Element.js': { + name: 'src/core/p5.Element.js', + modules: { + DOM: 1 + }, + classes: { + 'p5.Element': 1 + }, + fors: { + 'p5.Element': 1 + }, + namespaces: {} + }, + 'src/core/p5.Graphics.js': { + name: 'src/core/p5.Graphics.js', + modules: { + Rendering: 1 + }, + classes: { + 'p5.Graphics': 1 + }, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/p5.Renderer.js': { + name: 'src/core/p5.Renderer.js', + modules: {}, + classes: { + 'p5.Renderer': 1 + }, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/p5.Renderer2D.js': { + name: 'src/core/p5.Renderer2D.js', + modules: {}, + classes: {}, + fors: {}, + namespaces: {} + }, + 'src/core/rendering.js': { + name: 'src/core/rendering.js', + modules: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/shim.js': { + name: 'src/core/shim.js', + modules: {}, + classes: {}, + fors: {}, + namespaces: {} + }, + 'src/core/structure.js': { + name: 'src/core/structure.js', + modules: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/core/transform.js': { + name: 'src/core/transform.js', + modules: { + Transform: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/data/local_storage.js': { + name: 'src/data/local_storage.js', + modules: { + LocalStorage: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/data/p5.TypedDict.js': { + name: 'src/data/p5.TypedDict.js', + modules: { + Dictionary: 1 + }, + classes: { + 'p5.TypedDict': 1, + 'p5.StringDict': 1, + 'p5.NumberDict': 1 + }, + fors: { + 'p5.TypedDict': 1, + p5: 1 + }, + namespaces: {} + }, + 'src/events/acceleration.js': { + name: 'src/events/acceleration.js', + modules: { + Acceleration: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/events/keyboard.js': { + name: 'src/events/keyboard.js', + modules: { + Keyboard: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/events/mouse.js': { + name: 'src/events/mouse.js', + modules: { + Mouse: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/events/touch.js': { + name: 'src/events/touch.js', + modules: { + Touch: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/image/filters.js': { + name: 'src/image/filters.js', + modules: {}, + classes: {}, + fors: {}, + namespaces: {} + }, + 'src/image/image.js': { + name: 'src/image/image.js', + modules: { + Image: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/image/loading_displaying.js': { + name: 'src/image/loading_displaying.js', + modules: { + 'Loading & Displaying': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/image/p5.Image.js': { + name: 'src/image/p5.Image.js', + modules: {}, + classes: { + 'p5.Image': 1 + }, + fors: {}, + namespaces: {} + }, + 'src/image/pixels.js': { + name: 'src/image/pixels.js', + modules: { + Pixels: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/io/files.js': { + name: 'src/io/files.js', + modules: { + Input: 1, + Output: 1 + }, + classes: { + 'p5.PrintWriter': 1 + }, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/io/p5.Table.js': { + name: 'src/io/p5.Table.js', + modules: { + Table: 1 + }, + classes: { + 'p5.Table': 1 + }, + fors: {}, + namespaces: {} + }, + 'src/io/p5.TableRow.js': { + name: 'src/io/p5.TableRow.js', + modules: {}, + classes: { + 'p5.TableRow': 1 + }, + fors: {}, + namespaces: {} + }, + 'src/io/p5.XML.js': { + name: 'src/io/p5.XML.js', + modules: { + XML: 1 + }, + classes: { + 'p5.XML': 1 + }, + fors: {}, + namespaces: {} + }, + 'src/math/calculation.js': { + name: 'src/math/calculation.js', + modules: { + Calculation: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/math/math.js': { + name: 'src/math/math.js', + modules: { + Math: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/math/noise.js': { + name: 'src/math/noise.js', + modules: { + Noise: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/math/p5.Vector.js': { + name: 'src/math/p5.Vector.js', + modules: {}, + classes: { + 'p5.Vector': 1 + }, + fors: {}, + namespaces: {} + }, + 'src/math/random.js': { + name: 'src/math/random.js', + modules: { + Random: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/math/trigonometry.js': { + name: 'src/math/trigonometry.js', + modules: { + Trigonometry: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/typography/attributes.js': { + name: 'src/typography/attributes.js', + modules: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/typography/loading_displaying.js': { + name: 'src/typography/loading_displaying.js', + modules: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/typography/p5.Font.js': { + name: 'src/typography/p5.Font.js', + modules: { + Font: 1 + }, + classes: { + 'p5.Font': 1 + }, + fors: {}, + namespaces: {} + }, + 'src/utilities/array_functions.js': { + name: 'src/utilities/array_functions.js', + modules: { + 'Array Functions': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/utilities/conversion.js': { + name: 'src/utilities/conversion.js', + modules: { + Conversion: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/utilities/string_functions.js': { + name: 'src/utilities/string_functions.js', + modules: { + 'String Functions': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/utilities/time_date.js': { + name: 'src/utilities/time_date.js', + modules: { + 'Time & Date': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/3d_primitives.js': { + name: 'src/webgl/3d_primitives.js', + modules: { + '3D Primitives': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/interaction.js': { + name: 'src/webgl/interaction.js', + modules: { + Interaction: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/light.js': { + name: 'src/webgl/light.js', + modules: { + Lights: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/loading.js': { + name: 'src/webgl/loading.js', + modules: { + '3D Models': 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/material.js': { + name: 'src/webgl/material.js', + modules: { + Material: 1 + }, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/p5.Camera.js': { + name: 'src/webgl/p5.Camera.js', + modules: { + Camera: 1 + }, + classes: { + 'p5.Camera': 1 + }, + fors: { + p5: 1, + 'p5.Camera': 1 + }, + namespaces: {} + }, + 'src/webgl/p5.Geometry.js': { + name: 'src/webgl/p5.Geometry.js', + modules: {}, + classes: { + 'p5.Geometry': 1 + }, + fors: {}, + namespaces: {} + }, + 'src/webgl/p5.Matrix.js': { + name: 'src/webgl/p5.Matrix.js', + modules: {}, + classes: { + 'p5.Matrix': 1 + }, + fors: {}, + namespaces: {} + }, + 'src/webgl/p5.RendererGL.Immediate.js': { + name: 'src/webgl/p5.RendererGL.Immediate.js', + modules: {}, + classes: {}, + fors: {}, + namespaces: {} + }, + 'src/webgl/p5.RendererGL.Retained.js': { + name: 'src/webgl/p5.RendererGL.Retained.js', + modules: {}, + classes: {}, + fors: {}, + namespaces: {} + }, + 'src/webgl/p5.RendererGL.js': { + name: 'src/webgl/p5.RendererGL.js', + modules: {}, + classes: { + 'p5.RendererGL': 1 + }, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/p5.Shader.js': { + name: 'src/webgl/p5.Shader.js', + modules: { + Shaders: 1 + }, + classes: { + 'p5.Shader': 1 + }, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/p5.Texture.js': { + name: 'src/webgl/p5.Texture.js', + modules: {}, + classes: { + 'p5.Texture': 1 + }, + fors: { + p5: 1 + }, + namespaces: {} + }, + 'src/webgl/text.js': { + name: 'src/webgl/text.js', + modules: {}, + classes: { + ImageInfos: 1, + FontInfo: 1, + Cubic: 1 + }, + fors: {}, + namespaces: {} + }, + 'lib/addons/p5.dom.js': { + name: 'lib/addons/p5.dom.js', + modules: { + 'p5.dom': 1 + }, + classes: { + 'p5.MediaElement': 1, + 'p5.File': 1 + }, + fors: { + p5: 1, + 'p5.Element': 1 + }, + namespaces: {} + }, + 'lib/addons/p5.sound.js': { + name: 'lib/addons/p5.sound.js', + modules: { + 'p5.sound': 1 + }, + classes: { + 'p5.SoundFile': 1, + 'p5.Amplitude': 1, + 'p5.FFT': 1, + 'p5.Signal': 1, + 'p5.Oscillator': 1, + 'p5.SinOsc': 1, + 'p5.TriOsc': 1, + 'p5.SawOsc': 1, + 'p5.SqrOsc': 1, + 'p5.Envelope': 1, + 'p5.Pulse': 1, + 'p5.Noise': 1, + 'p5.AudioIn': 1, + 'p5.Effect': 1, + 'p5.Filter': 1, + 'p5.LowPass': 1, + 'p5.HighPass': 1, + 'p5.BandPass': 1, + 'p5.EQ': 1, + 'p5.Panner3D': 1, + 'p5.Delay': 1, + 'p5.Reverb': 1, + 'p5.Convolver': 1, + 'p5.Phrase': 1, + 'p5.Part': 1, + 'p5.Score': 1, + 'p5.SoundLoop': 1, + 'p5.Compressor': 1, + 'p5.SoundRecorder': 1, + 'p5.PeakDetect': 1, + 'p5.Gain': 1, + 'p5.AudioVoice': 1, + 'p5.MonoSynth': 1, + 'p5.PolySynth': 1, + 'p5.Distortion': 1 + }, + fors: { + 'p5.sound': 1, + p5: 1 + }, + namespaces: {} + }, + 'lib/addons/p5.sound.min.js': { + name: 'lib/addons/p5.sound.min.js', + modules: {}, + classes: {}, + fors: {}, + namespaces: {} + } + }, + modules: { + Color: { + name: 'Color', + submodules: { + 'Color Conversion': 1, + 'Creating & Reading': 1, + Setting: 1 + }, + elements: {}, + classes: { + 'p5.Color': 1 + }, + fors: { + p5: 1 + }, + namespaces: {}, + file: 'src/color/p5.Color.js', + line: 16 + }, + 'Color Conversion': { + name: 'Color Conversion', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Color', + namespace: '', + file: 'src/color/color_conversion.js', + line: 1, + requires: ['core'] + }, + 'Creating & Reading': { + name: 'Creating & Reading', + submodules: {}, + elements: {}, + classes: { + 'p5.Color': 1 + }, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Color', + namespace: '', + file: 'src/color/p5.Color.js', + line: 16, + requires: ['core', 'constants'], + description: + '

Each color stores the color mode and level maxes that applied at the\ntime of its construction. These are used to interpret the input arguments\n(at construction and later for that instance of color) and to format the\noutput e.g. when saturation() is requested.

\n

Internally we store an array representing the ideal RGBA values in floating\npoint form, normalized from 0 to 1. From this we calculate the closest\nscreen color (RGBA levels from 0 to 255) and expose this to the renderer.

\n

We also cache normalized, floating point components of the color in various\nrepresentations as they are calculated. This is done to prevent repeating a\nconversion that has already been performed.

\n' + }, + Setting: { + name: 'Setting', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Color', + namespace: '', + file: 'src/color/setting.js', + line: 1, + requires: ['core', 'constants'] + }, + Shape: { + name: 'Shape', + submodules: { + '2D Primitives': 1, + Curves: 1, + Vertex: 1, + '3D Primitives': 1, + '3D Models': 1 + }, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + '2D Primitives': { + name: '2D Primitives', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Shape', + namespace: '', + file: 'src/core/shape/2d_primitives.js', + line: 1, + requires: ['core', 'constants'] + }, + Attributes: { + name: 'Attributes', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Typography', + namespace: '', + file: 'src/core/shape/attributes.js', + line: 1, + requires: ['core', 'constants'] + }, + Curves: { + name: 'Curves', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Shape', + namespace: '', + file: 'src/core/shape/curves.js', + line: 1, + requires: ['core'] + }, + Vertex: { + name: 'Vertex', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Shape', + namespace: '', + file: 'src/core/shape/vertex.js', + line: 1, + requires: ['core', 'constants'] + }, + Constants: { + name: 'Constants', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {}, + module: 'Constants', + file: 'src/core/constants.js', + line: 1 + }, + Environment: { + name: 'Environment', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {}, + module: 'Environment', + file: 'src/core/environment.js', + line: 1, + requires: ['core', 'constants'] + }, + Structure: { + name: 'Structure', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {}, + module: 'IO', + file: 'src/core/main.js', + line: 1, + requires: ['constants'] + }, + DOM: { + name: 'DOM', + submodules: {}, + elements: {}, + classes: { + 'p5.Element': 1 + }, + fors: { + 'p5.Element': 1 + }, + namespaces: {}, + module: 'DOM', + file: 'src/core/p5.Element.js', + line: 11, + description: + '

Base class for all elements added to a sketch, including canvas,\ngraphics buffers, and other HTML elements. Methods in blue are\nincluded in the core functionality, methods in brown are added\nwith the p5.dom\nlibrary.\nIt is not called directly, but p5.Element\nobjects are created by calling createCanvas, createGraphics,\nor in the p5.dom library, createDiv, createImg, createInput, etc.

\n' + }, + Rendering: { + name: 'Rendering', + submodules: { + undefined: 1 + }, + elements: {}, + classes: { + 'p5.RendererGL': 1, + 'p5.Graphics': 1, + 'p5.Renderer': 1 + }, + fors: { + p5: 1 + }, + namespaces: {}, + module: 'Rendering', + file: 'src/webgl/p5.RendererGL.js', + line: 519, + description: + '

Thin wrapper around a renderer, to be used for creating a\ngraphics buffer object. Use this class if you need\nto draw into an off-screen graphics buffer. The two parameters define the\nwidth and height in pixels. The fields and methods for this class are\nextensive, but mirror the normal drawing API for p5.

\n' + }, + Transform: { + name: 'Transform', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {}, + module: 'Transform', + file: 'src/core/transform.js', + line: 1, + requires: ['core', 'constants'] + }, + Data: { + name: 'Data', + submodules: { + LocalStorage: 1, + Dictionary: 1, + 'Array Functions': 1, + Conversion: 1, + 'String Functions': 1 + }, + elements: {}, + classes: { + 'p5.TypedDict': 1, + 'p5.StringDict': 1, + 'p5.NumberDict': 1 + }, + fors: { + p5: 1, + 'p5.TypedDict': 1 + }, + namespaces: {}, + file: 'src/data/p5.TypedDict.js', + line: 422 + }, + LocalStorage: { + name: 'LocalStorage', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Data', + namespace: '', + file: 'src/data/local_storage.js', + line: 1, + requires: [ + 'core\n\nThis module defines the p5 methods for working with local storage' + ] + }, + Dictionary: { + name: 'Dictionary', + submodules: {}, + elements: {}, + classes: { + 'p5.TypedDict': 1, + 'p5.StringDict': 1, + 'p5.NumberDict': 1 + }, + fors: { + 'p5.TypedDict': 1, + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Data', + namespace: '', + file: 'src/data/p5.TypedDict.js', + line: 422, + requires: [ + 'core\n\nThis module defines the p5 methods for the p5 Dictionary classes.\nThe classes StringDict and NumberDict are for storing and working\nwith key-value pairs.' + ], + description: + '

Base class for all p5.Dictionary types. Specifically\n typed Dictionary classes inherit from this class.

\n' + }, + Events: { + name: 'Events', + submodules: { + Acceleration: 1, + Keyboard: 1, + Mouse: 1, + Touch: 1 + }, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + namespaces: {} + }, + Acceleration: { + name: 'Acceleration', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Events', + namespace: '', + file: 'src/events/acceleration.js', + line: 1, + requires: ['core'] + }, + Keyboard: { + name: 'Keyboard', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Events', + namespace: '', + file: 'src/events/keyboard.js', + line: 1, + requires: ['core'] + }, + Mouse: { + name: 'Mouse', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Events', + namespace: '', + file: 'src/events/mouse.js', + line: 1, + requires: ['core', 'constants'] + }, + Touch: { + name: 'Touch', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Events', + namespace: '', + file: 'src/events/touch.js', + line: 1, + requires: ['core'] + }, + Image: { + name: 'Image', + submodules: { + Pixels: 1 + }, + elements: {}, + classes: { + 'p5.Image': 1 + }, + fors: { + p5: 1 + }, + namespaces: {}, + module: 'Image', + file: 'src/image/p5.Image.js', + line: 23, + requires: ['core'], + description: + '

Creates a new p5.Image. A p5.Image is a canvas backed representation of an\nimage.\n

\np5 can display .gif, .jpg and .png images. Images may be displayed\nin 2D and 3D space. Before an image is used, it must be loaded with the\nloadImage() function. The p5.Image class contains fields for the width and\nheight of the image, as well as an array called pixels[] that contains the\nvalues for every pixel in the image.\n

\nThe methods described below allow easy access to the image's pixels and\nalpha channel and simplify the process of compositing.\n

\nBefore using the pixels[] array, be sure to use the loadPixels() method on\nthe image to make sure that the pixel data is properly loaded.

\n' + }, + 'Loading & Displaying': { + name: 'Loading & Displaying', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Typography', + namespace: '', + file: 'src/image/loading_displaying.js', + line: 1, + requires: ['core'] + }, + Pixels: { + name: 'Pixels', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Image', + namespace: '', + file: 'src/image/pixels.js', + line: 1, + requires: ['core'] + }, + IO: { + name: 'IO', + submodules: { + Structure: 1, + Input: 1, + Output: 1, + Table: 1, + XML: 1, + 'Time & Date': 1 + }, + elements: {}, + classes: { + p5: 1, + 'p5.PrintWriter': 1, + 'p5.Table': 1, + 'p5.TableRow': 1, + 'p5.XML': 1 + }, + fors: { + p5: 1 + }, + namespaces: {}, + file: 'src/io/p5.XML.js', + line: 11 + }, + Input: { + name: 'Input', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'IO', + namespace: '', + file: 'src/io/files.js', + line: 1, + requires: ['core'] + }, + Output: { + name: 'Output', + submodules: {}, + elements: {}, + classes: { + p5: 1, + 'p5.PrintWriter': 1 + }, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'IO', + namespace: '', + file: 'src/io/files.js', + line: 1238, + description: + '

This is the p5 instance constructor.

\n

A p5 instance holds all the properties and methods related to\na p5 sketch. It expects an incoming sketch closure and it can also\ntake an optional node parameter for attaching the generated p5 canvas\nto a node. The sketch closure takes the newly created p5 instance as\nits sole argument and may optionally set preload(), setup(), and/or\ndraw() properties on it for running a sketch.

\n

A p5 sketch can run in "global" or "instance" mode:\n"global" - all properties and methods are attached to the window\n"instance" - all properties and methods are bound to this p5 object

\n' + }, + Table: { + name: 'Table', + submodules: {}, + elements: {}, + classes: { + 'p5.Table': 1, + 'p5.TableRow': 1 + }, + fors: {}, + is_submodule: 1, + namespaces: {}, + module: 'IO', + namespace: '', + file: 'src/io/p5.TableRow.js', + line: 11, + requires: ['core'], + description: + '

Table objects store data with multiple rows and columns, much\nlike in a traditional spreadsheet. Tables can be generated from\nscratch, dynamically, or using data from an existing file.

\n' + }, + XML: { + name: 'XML', + submodules: {}, + elements: {}, + classes: { + 'p5.XML': 1 + }, + fors: {}, + is_submodule: 1, + namespaces: {}, + module: 'IO', + namespace: '', + file: 'src/io/p5.XML.js', + line: 11, + requires: ['core'], + description: + '

XML is a representation of an XML object, able to parse XML code. Use\nloadXML() to load external XML files and create XML objects.

\n' + }, + Math: { + name: 'Math', + submodules: { + Calculation: 1, + Noise: 1, + Random: 1, + Trigonometry: 1 + }, + elements: {}, + classes: { + 'p5.Vector': 1 + }, + fors: { + p5: 1 + }, + namespaces: {}, + module: 'Math', + file: 'src/math/p5.Vector.js', + line: 12, + requires: ['core'], + description: + '

A class to describe a two or three dimensional vector, specifically\na Euclidean (also known as geometric) vector. A vector is an entity\nthat has both magnitude and direction. The datatype, however, stores\nthe components of the vector (x, y for 2D, and x, y, z for 3D). The magnitude\nand direction can be accessed via the methods mag() and heading().\n

\nIn many of the p5.js examples, you will see p5.Vector used to describe a\nposition, velocity, or acceleration. For example, if you consider a rectangle\nmoving across the screen, at any given instant it has a position (a vector\nthat points from the origin to its location), a velocity (the rate at which\nthe object's position changes per time unit, expressed as a vector), and\nacceleration (the rate at which the object's velocity changes per time\nunit, expressed as a vector).\n

\nSince vectors represent groupings of values, we cannot simply use\ntraditional addition/multiplication/etc. Instead, we'll need to do some\n"vector" math, which is made easy by the methods inside the p5.Vector class.

\n' + }, + Calculation: { + name: 'Calculation', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Math', + namespace: '', + file: 'src/math/calculation.js', + line: 1, + requires: ['core'] + }, + Noise: { + name: 'Noise', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Math', + namespace: '', + file: 'src/math/noise.js', + line: 14, + requires: ['core'] + }, + Random: { + name: 'Random', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Math', + namespace: '', + file: 'src/math/random.js', + line: 1, + requires: ['core'] + }, + Trigonometry: { + name: 'Trigonometry', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Math', + namespace: '', + file: 'src/math/trigonometry.js', + line: 1, + requires: ['core', 'constants'] + }, + Typography: { + name: 'Typography', + submodules: { + Attributes: 1, + 'Loading & Displaying': 1, + Font: 1 + }, + elements: {}, + classes: { + 'p5.Font': 1 + }, + fors: { + p5: 1 + }, + namespaces: {}, + file: 'src/typography/p5.Font.js', + line: 15 + }, + Font: { + name: 'Font', + submodules: {}, + elements: {}, + classes: { + 'p5.Font': 1 + }, + fors: {}, + is_submodule: 1, + namespaces: {}, + module: 'Typography', + namespace: '', + file: 'src/typography/p5.Font.js', + line: 15, + description: + '

This module defines the p5.Font class and functions for\ndrawing text to the display canvas.

\n', + requires: ['core', 'constants'] + }, + 'Array Functions': { + name: 'Array Functions', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Data', + namespace: '', + file: 'src/utilities/array_functions.js', + line: 1, + requires: ['core'] + }, + Conversion: { + name: 'Conversion', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Data', + namespace: '', + file: 'src/utilities/conversion.js', + line: 1, + requires: ['core'] + }, + 'String Functions': { + name: 'String Functions', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Data', + namespace: '', + file: 'src/utilities/string_functions.js', + line: 1, + requires: ['core'] + }, + 'Time & Date': { + name: 'Time & Date', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'IO', + namespace: '', + file: 'src/utilities/time_date.js', + line: 1, + requires: ['core'] + }, + '3D Primitives': { + name: '3D Primitives', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Shape', + namespace: '', + file: 'src/webgl/3d_primitives.js', + line: 1, + requires: ['core', 'p5.Geometry'] + }, + 'Lights, Camera': { + name: 'Lights, Camera', + submodules: { + Interaction: 1, + Lights: 1, + Material: 1, + Camera: 1, + Shaders: 1 + }, + elements: {}, + classes: { + 'p5.Camera': 1, + 'p5.Geometry': 1, + 'p5.Matrix': 1, + 'p5.Shader': 1, + 'p5.Texture': 1, + ImageInfos: 1, + FontInfo: 1, + Cubic: 1 + }, + fors: { + p5: 1, + 'p5.Camera': 1 + }, + namespaces: {}, + file: 'src/webgl/text.js', + line: 259 + }, + Interaction: { + name: 'Interaction', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Lights, Camera', + namespace: '', + file: 'src/webgl/interaction.js', + line: 1, + requires: ['core'] + }, + Lights: { + name: 'Lights', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Lights, Camera', + namespace: '', + file: 'src/webgl/light.js', + line: 1, + requires: ['core'] + }, + '3D Models': { + name: '3D Models', + submodules: {}, + elements: {}, + classes: {}, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Shape', + namespace: '', + file: 'src/webgl/loading.js', + line: 1, + requires: ['core', 'p5.Geometry'] + }, + Material: { + name: 'Material', + submodules: {}, + elements: {}, + classes: { + 'p5.Texture': 1 + }, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Lights, Camera', + namespace: '', + file: 'src/webgl/p5.Texture.js', + line: 14, + requires: ['core'], + description: '

This module defines the p5.Texture class

\n' + }, + Camera: { + name: 'Camera', + submodules: {}, + elements: {}, + classes: { + 'p5.Camera': 1 + }, + fors: { + p5: 1, + 'p5.Camera': 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Lights, Camera', + namespace: '', + file: 'src/webgl/p5.Camera.js', + line: 209, + requires: ['core'], + description: + '

This class describes a camera for use in p5's\n\nWebGL mode. It contains camera position, orientation, and projection\ninformation necessary for rendering a 3D scene.

\n

New p5.Camera objects can be made through the\ncreateCamera() function and controlled through\nthe methods described below. A camera created in this way will use a default\nposition in the scene and a default perspective projection until these\nproperties are changed through the various methods available. It is possible\nto create multiple cameras, in which case the current camera\ncan be set through the setCamera() method.

\n

Note:\nThe methods below operate in two coordinate systems: the 'world' coordinate\nsystem describe positions in terms of their relationship to the origin along\nthe X, Y and Z axes whereas the camera's 'local' coordinate system\ndescribes positions from the camera's point of view: left-right, up-down,\nand forward-backward. The move() method,\nfor instance, moves the camera along its own axes, whereas the\nsetPosition()\nmethod sets the camera's position in world-space.

\n' + }, + Shaders: { + name: 'Shaders', + submodules: {}, + elements: {}, + classes: { + 'p5.Shader': 1 + }, + fors: { + p5: 1 + }, + is_submodule: 1, + namespaces: {}, + module: 'Lights, Camera', + namespace: '', + file: 'src/webgl/p5.Shader.js', + line: 13, + description: '

This module defines the p5.Shader class

\n', + requires: ['core'] + }, + 'p5.dom': { + name: 'p5.dom', + submodules: {}, + elements: {}, + classes: { + 'p5.MediaElement': 1, + 'p5.File': 1 + }, + fors: { + p5: 1, + 'p5.Element': 1 + }, + namespaces: {}, + module: 'p5.dom', + file: 'lib/addons/p5.dom.js', + line: 3323, + description: + "

The web is much more than just canvas and p5.dom makes it easy to interact\nwith other HTML5 objects, including text, hyperlink, image, input, video,\naudio, and webcam.

\n

There is a set of creation methods, DOM manipulation methods, and\nan extended p5.Element that supports a range of HTML elements. See the\n\nbeyond the canvas tutorial for a full overview of how this addon works.

\n

Methods and properties shown in black are part of the p5.js core, items in\nblue are part of the p5.dom library. You will need to include an extra file\nin order to access the blue functions. See the\nusing a library\nsection for information on how to include this library. p5.dom comes with\np5 complete or you can download the single file\n\nhere.

\n

See tutorial: beyond the canvas\nfor more info on how to use this library.

\n", + tag: 'main', + itemtype: 'main' + }, + 'p5.sound': { + name: 'p5.sound', + submodules: {}, + elements: {}, + classes: { + 'p5.sound': 1, + 'p5.SoundFile': 1, + 'p5.Amplitude': 1, + 'p5.FFT': 1, + 'p5.Signal': 1, + 'p5.Oscillator': 1, + 'p5.SinOsc': 1, + 'p5.TriOsc': 1, + 'p5.SawOsc': 1, + 'p5.SqrOsc': 1, + 'p5.Envelope': 1, + 'p5.Pulse': 1, + 'p5.Noise': 1, + 'p5.AudioIn': 1, + 'p5.Effect': 1, + 'p5.Filter': 1, + 'p5.LowPass': 1, + 'p5.HighPass': 1, + 'p5.BandPass': 1, + 'p5.EQ': 1, + 'p5.Panner3D': 1, + 'p5.Delay': 1, + 'p5.Reverb': 1, + 'p5.Convolver': 1, + 'p5.Phrase': 1, + 'p5.Part': 1, + 'p5.Score': 1, + 'p5.SoundLoop': 1, + 'p5.Compressor': 1, + 'p5.SoundRecorder': 1, + 'p5.PeakDetect': 1, + 'p5.Gain': 1, + 'p5.AudioVoice': 1, + 'p5.MonoSynth': 1, + 'p5.PolySynth': 1, + 'p5.Distortion': 1 + }, + fors: { + 'p5.sound': 1, + p5: 1 + }, + namespaces: {}, + module: 'p5.sound', + file: 'lib/addons/p5.sound.js', + line: 12767, + description: + '

p5.sound extends p5 with Web Audio functionality including audio input,\nplayback, analysis and synthesis.\n

\np5.SoundFile: Load and play sound files.
\np5.Amplitude: Get the current volume of a sound.
\np5.AudioIn: Get sound from an input source, typically\n a computer microphone.
\np5.FFT: Analyze the frequency of sound. Returns\n results from the frequency spectrum or time domain (waveform).
\np5.Oscillator: Generate Sine,\n Triangle, Square and Sawtooth waveforms. Base class of\n p5.Noise and p5.Pulse.\n
\np5.Envelope: An Envelope is a series\n of fades over time. Often used to control an object's\n output gain level as an "ADSR Envelope" (Attack, Decay,\n Sustain, Release). Can also modulate other parameters.
\np5.Delay: A delay effect with\n parameters for feedback, delayTime, and lowpass filter.
\np5.Filter: Filter the frequency range of a\n sound.\n
\np5.Reverb: Add reverb to a sound by specifying\n duration and decay.
\np5.Convolver: Extends\np5.Reverb to simulate the sound of real\n physical spaces through convolution.
\np5.SoundRecorder: Record sound for playback\n / save the .wav file.\np5.Phrase, p5.Part and\np5.Score: Compose musical sequences.\n

\np5.sound is on GitHub.\nDownload the latest version\nhere.

\n', + tag: 'main', + itemtype: 'main' + } + }, + classes: { + p5: { + name: 'p5', + shortname: 'p5', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'IO', + submodule: 'Output', + namespace: '', + file: 'src/core/main.js', + line: 15, + description: + '

This is the p5 instance constructor.

\n

A p5 instance holds all the properties and methods related to\na p5 sketch. It expects an incoming sketch closure and it can also\ntake an optional node parameter for attaching the generated p5 canvas\nto a node. The sketch closure takes the newly created p5 instance as\nits sole argument and may optionally set preload(), setup(), and/or\ndraw() properties on it for running a sketch.

\n

A p5 sketch can run in "global" or "instance" mode:\n"global" - all properties and methods are attached to the window\n"instance" - all properties and methods are bound to this p5 object

\n', + is_constructor: 1, + params: [ + { + name: 'sketch', + description: + '

a closure that can set optional preload(),\n setup(), and/or draw() properties on the\n given p5 instance

\n', + type: 'Function' + }, + { + name: 'node', + description: '

element to attach canvas to

\n', + type: 'HTMLElement', + optional: true + } + ], + return: { + description: 'a p5 instance', + type: 'P5' + } + }, + 'p5.Color': { + name: 'p5.Color', + shortname: 'p5.Color', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Color', + submodule: 'Creating & Reading', + namespace: '', + file: 'src/color/p5.Color.js', + line: 16, + description: + '

Each color stores the color mode and level maxes that applied at the\ntime of its construction. These are used to interpret the input arguments\n(at construction and later for that instance of color) and to format the\noutput e.g. when saturation() is requested.

\n

Internally we store an array representing the ideal RGBA values in floating\npoint form, normalized from 0 to 1. From this we calculate the closest\nscreen color (RGBA levels from 0 to 255) and expose this to the renderer.

\n

We also cache normalized, floating point components of the color in various\nrepresentations as they are calculated. This is done to prevent repeating a\nconversion that has already been performed.

\n' + }, + 'p5.Element': { + name: 'p5.Element', + shortname: 'p5.Element', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'DOM', + submodule: 'DOM', + namespace: '', + file: 'src/core/p5.Element.js', + line: 11, + description: + '

Base class for all elements added to a sketch, including canvas,\ngraphics buffers, and other HTML elements. Methods in blue are\nincluded in the core functionality, methods in brown are added\nwith the p5.dom\nlibrary.\nIt is not called directly, but p5.Element\nobjects are created by calling createCanvas, createGraphics,\nor in the p5.dom library, createDiv, createImg, createInput, etc.

\n', + params: [ + { + name: 'elt', + description: '

DOM node that is wrapped

\n', + type: 'String' + }, + { + name: 'pInst', + description: '

pointer to p5 instance

\n', + type: 'P5', + optional: true + } + ] + }, + 'p5.Graphics': { + name: 'p5.Graphics', + shortname: 'p5.Graphics', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Rendering', + submodule: 'Rendering', + namespace: '', + file: 'src/core/p5.Graphics.js', + line: 12, + description: + '

Thin wrapper around a renderer, to be used for creating a\ngraphics buffer object. Use this class if you need\nto draw into an off-screen graphics buffer. The two parameters define the\nwidth and height in pixels. The fields and methods for this class are\nextensive, but mirror the normal drawing API for p5.

\n', + extends: 'p5.Element', + params: [ + { + name: 'w', + description: '

width

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height

\n', + type: 'Number' + }, + { + name: 'renderer', + description: '

the renderer to use, either P2D or WEBGL

\n', + type: 'Constant' + }, + { + name: 'pInst', + description: '

pointer to p5 instance

\n', + type: 'P5', + optional: true + } + ] + }, + 'p5.Renderer': { + name: 'p5.Renderer', + shortname: 'p5.Renderer', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Rendering', + submodule: 'Rendering', + namespace: '', + file: 'src/core/p5.Renderer.js', + line: 12, + description: + '

Main graphics and rendering context, as well as the base API\nimplementation for p5.js "core". To be used as the superclass for\nRenderer2D and Renderer3D classes, respecitvely.

\n', + is_constructor: 1, + extends: 'p5.Element', + params: [ + { + name: 'elt', + description: '

DOM node that is wrapped

\n', + type: 'String' + }, + { + name: 'pInst', + description: '

pointer to p5 instance

\n', + type: 'P5', + optional: true + }, + { + name: 'isMainCanvas', + description: '

whether we're using it as main canvas

\n', + type: 'Boolean', + optional: true + } + ] + }, + 'p5.TypedDict': { + name: 'p5.TypedDict', + shortname: 'p5.TypedDict', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Data', + submodule: 'Dictionary', + namespace: '', + file: 'src/data/p5.TypedDict.js', + line: 84, + description: + '

Base class for all p5.Dictionary types. Specifically\n typed Dictionary classes inherit from this class.

\n' + }, + 'p5.StringDict': { + name: 'p5.StringDict', + shortname: 'p5.StringDict', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Data', + submodule: 'Dictionary', + namespace: '', + file: 'src/data/p5.TypedDict.js', + line: 403, + description: '

A simple Dictionary class for Strings.

\n', + extends: 'p5.TypedDict' + }, + 'p5.NumberDict': { + name: 'p5.NumberDict', + shortname: 'p5.NumberDict', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Data', + submodule: 'Dictionary', + namespace: '', + file: 'src/data/p5.TypedDict.js', + line: 422, + description: '

A simple Dictionary class for Numbers.

\n', + extends: 'p5.TypedDict' + }, + 'p5.Image': { + name: 'p5.Image', + shortname: 'p5.Image', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Image', + submodule: 'Image', + namespace: '', + file: 'src/image/p5.Image.js', + line: 23, + description: + '

Creates a new p5.Image. A p5.Image is a canvas backed representation of an\nimage.\n

\np5 can display .gif, .jpg and .png images. Images may be displayed\nin 2D and 3D space. Before an image is used, it must be loaded with the\nloadImage() function. The p5.Image class contains fields for the width and\nheight of the image, as well as an array called pixels[] that contains the\nvalues for every pixel in the image.\n

\nThe methods described below allow easy access to the image's pixels and\nalpha channel and simplify the process of compositing.\n

\nBefore using the pixels[] array, be sure to use the loadPixels() method on\nthe image to make sure that the pixel data is properly loaded.

\n', + example: [ + '\n
\nfunction setup() {\n let img = createImage(100, 100); // same as new p5.Image(100, 100);\n img.loadPixels();\n createCanvas(100, 100);\n background(0);\n\n // helper for writing color to array\n function writeColor(image, x, y, red, green, blue, alpha) {\n let index = (x + y * width) * 4;\n image.pixels[index] = red;\n image.pixels[index + 1] = green;\n image.pixels[index + 2] = blue;\n image.pixels[index + 3] = alpha;\n }\n\n let x, y;\n // fill with random colors\n for (y = 0; y < img.height; y++) {\n for (x = 0; x < img.width; x++) {\n let red = random(255);\n let green = random(255);\n let blue = random(255);\n let alpha = 255;\n writeColor(img, x, y, red, green, blue, alpha);\n }\n }\n\n // draw a red line\n y = 0;\n for (x = 0; x < img.width; x++) {\n writeColor(img, x, y, 255, 0, 0, 255);\n }\n\n // draw a green line\n y = img.height - 1;\n for (x = 0; x < img.width; x++) {\n writeColor(img, x, y, 0, 255, 0, 255);\n }\n\n img.updatePixels();\n image(img, 0, 0);\n}\n
' + ], + params: [ + { + name: 'width', + description: '', + type: 'Number' + }, + { + name: 'height', + description: '', + type: 'Number' + } + ] + }, + 'p5.PrintWriter': { + name: 'p5.PrintWriter', + shortname: 'p5.PrintWriter', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'IO', + submodule: 'Output', + namespace: '', + file: 'src/io/files.js', + line: 1238, + params: [ + { + name: 'filename', + description: '', + type: 'String' + }, + { + name: 'extension', + description: '', + type: 'String', + optional: true + } + ] + }, + 'p5.Table': { + name: 'p5.Table', + shortname: 'p5.Table', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'IO', + submodule: 'Table', + namespace: '', + file: 'src/io/p5.Table.js', + line: 35, + description: + '

Table objects store data with multiple rows and columns, much\nlike in a traditional spreadsheet. Tables can be generated from\nscratch, dynamically, or using data from an existing file.

\n', + is_constructor: 1, + params: [ + { + name: 'rows', + description: '

An array of p5.TableRow objects

\n', + type: 'p5.TableRow[]', + optional: true + } + ] + }, + 'p5.TableRow': { + name: 'p5.TableRow', + shortname: 'p5.TableRow', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'IO', + submodule: 'Table', + namespace: '', + file: 'src/io/p5.TableRow.js', + line: 11, + description: + '

A TableRow object represents a single row of data values,\nstored in columns, from a table.

\n

A Table Row contains both an ordered array, and an unordered\nJSON object.

\n', + is_constructor: 1, + params: [ + { + name: 'str', + description: + '

optional: populate the row with a\n string of values, separated by the\n separator

\n', + type: 'String', + optional: true + }, + { + name: 'separator', + description: '

comma separated values (csv) by default

\n', + type: 'String', + optional: true + } + ] + }, + 'p5.XML': { + name: 'p5.XML', + shortname: 'p5.XML', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'IO', + submodule: 'XML', + namespace: '', + file: 'src/io/p5.XML.js', + line: 11, + description: + '

XML is a representation of an XML object, able to parse XML code. Use\nloadXML() to load external XML files and create XML objects.

\n', + is_constructor: 1, + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let children = xml.getChildren(\'animal\');\n\n for (let i = 0; i < children.length; i++) {\n let id = children[i].getNum(\'id\');\n let coloring = children[i].getString(\'species\');\n let name = children[i].getContent();\n print(id + \', \' + coloring + \', \' + name);\n }\n}\n\n// Sketch prints:\n// 0, Capra hircus, Goat\n// 1, Panthera pardus, Leopard\n// 2, Equus zebra, Zebra\n
' + ], + alt: 'no image displayed' + }, + 'p5.Vector': { + name: 'p5.Vector', + shortname: 'p5.Vector', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Math', + submodule: 'Math', + namespace: '', + file: 'src/math/p5.Vector.js', + line: 12, + description: + '

A class to describe a two or three dimensional vector, specifically\na Euclidean (also known as geometric) vector. A vector is an entity\nthat has both magnitude and direction. The datatype, however, stores\nthe components of the vector (x, y for 2D, and x, y, z for 3D). The magnitude\nand direction can be accessed via the methods mag() and heading().\n

\nIn many of the p5.js examples, you will see p5.Vector used to describe a\nposition, velocity, or acceleration. For example, if you consider a rectangle\nmoving across the screen, at any given instant it has a position (a vector\nthat points from the origin to its location), a velocity (the rate at which\nthe object's position changes per time unit, expressed as a vector), and\nacceleration (the rate at which the object's velocity changes per time\nunit, expressed as a vector).\n

\nSince vectors represent groupings of values, we cannot simply use\ntraditional addition/multiplication/etc. Instead, we'll need to do some\n"vector" math, which is made easy by the methods inside the p5.Vector class.

\n', + params: [ + { + name: 'x', + description: '

x component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: '

y component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

z component of the vector

\n', + type: 'Number', + optional: true + } + ], + example: [ + '\n
\n\nlet v1 = createVector(40, 50);\nlet v2 = createVector(40, 50);\n\nellipse(v1.x, v1.y, 50, 50);\nellipse(v2.x, v2.y, 50, 50);\nv1.add(v2);\nellipse(v1.x, v1.y, 50, 50);\n\n
' + ], + alt: + '2 white ellipses. One center-left the other bottom right and off canvas' + }, + 'p5.Font': { + name: 'p5.Font', + shortname: 'p5.Font', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Typography', + submodule: 'Font', + namespace: '', + file: 'src/typography/p5.Font.js', + line: 15, + description: '

Base class for font handling

\n', + params: [ + { + name: 'pInst', + description: '

pointer to p5 instance

\n', + type: 'P5', + optional: true + } + ] + }, + 'p5.Camera': { + name: 'p5.Camera', + shortname: 'p5.Camera', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Lights, Camera', + submodule: 'Camera', + namespace: '', + file: 'src/webgl/p5.Camera.js', + line: 209, + description: + '

This class describes a camera for use in p5's\n\nWebGL mode. It contains camera position, orientation, and projection\ninformation necessary for rendering a 3D scene.

\n

New p5.Camera objects can be made through the\ncreateCamera() function and controlled through\nthe methods described below. A camera created in this way will use a default\nposition in the scene and a default perspective projection until these\nproperties are changed through the various methods available. It is possible\nto create multiple cameras, in which case the current camera\ncan be set through the setCamera() method.

\n

Note:\nThe methods below operate in two coordinate systems: the 'world' coordinate\nsystem describe positions in terms of their relationship to the origin along\nthe X, Y and Z axes whereas the camera's 'local' coordinate system\ndescribes positions from the camera's point of view: left-right, up-down,\nand forward-backward. The move() method,\nfor instance, moves the camera along its own axes, whereas the\nsetPosition()\nmethod sets the camera's position in world-space.

\n', + params: [ + { + name: 'rendererGL', + description: '

instance of WebGL renderer

\n', + type: 'RendererGL' + } + ], + example: [ + "\n
\n\nlet cam;\nlet delta = 0.01;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n normalMaterial();\n cam = createCamera();\n // set initial pan angle\n cam.pan(-0.8);\n}\n\nfunction draw() {\n background(200);\n\n // pan camera according to angle 'delta'\n cam.pan(delta);\n\n // every 160 frames, switch direction\n if (frameCount % 160 === 0) {\n delta *= -1;\n }\n\n rotateX(frameCount * 0.01);\n translate(-100, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n}\n\n
" + ], + alt: 'camera view pans left and right across a series of rotating 3D boxes.' + }, + 'p5.Geometry': { + name: 'p5.Geometry', + shortname: 'p5.Geometry', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Lights, Camera', + namespace: '', + file: 'src/webgl/p5.Geometry.js', + line: 6, + description: '

p5 Geometry class

\n', + is_constructor: 1, + params: [ + { + name: 'detailX', + description: '

number of vertices on horizontal surface

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: '

number of vertices on horizontal surface

\n', + type: 'Integer', + optional: true + }, + { + name: 'callback', + description: '

function to call upon object instantiation.

\n', + type: 'Function', + optional: true + } + ] + }, + 'p5.Shader': { + name: 'p5.Shader', + shortname: 'p5.Shader', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'Lights, Camera', + submodule: 'Shaders', + namespace: '', + file: 'src/webgl/p5.Shader.js', + line: 13, + description: '

Shader class for WEBGL Mode

\n', + params: [ + { + name: 'renderer', + description: + '

an instance of p5.RendererGL that\nwill provide the GL context for this new p5.Shader

\n', + type: 'p5.RendererGL' + }, + { + name: 'vertSrc', + description: '

source code for the vertex shader (as a string)

\n', + type: 'String' + }, + { + name: 'fragSrc', + description: + '

source code for the fragment shader (as a string)

\n', + type: 'String' + } + ] + }, + 'p5.MediaElement': { + name: 'p5.MediaElement', + shortname: 'p5.MediaElement', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.dom', + submodule: 'p5.dom', + namespace: '', + file: 'lib/addons/p5.dom.js', + line: 2228, + description: + '

Extends p5.Element to handle audio and video. In addition to the methods\nof p5.Element, it also contains methods for controlling media. It is not\ncalled directly, but p5.MediaElements are created by calling createVideo,\ncreateAudio, and createCapture.

\n', + is_constructor: 1, + params: [ + { + name: 'elt', + description: '

DOM node that is wrapped

\n', + type: 'String' + } + ] + }, + 'p5.File': { + name: 'p5.File', + shortname: 'p5.File', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.dom', + submodule: 'p5.dom', + namespace: '', + file: 'lib/addons/p5.dom.js', + line: 3323, + description: + '

Base class for a file.\nUsed for Element.drop and createFileInput.

\n', + is_constructor: 1, + params: [ + { + name: 'file', + description: '

File that is wrapped

\n', + type: 'File' + } + ] + }, + 'p5.sound': { + name: 'p5.sound', + shortname: 'p5.sound', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '' + }, + 'p5.SoundFile': { + name: 'p5.SoundFile', + shortname: 'p5.SoundFile', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 1645, + description: + '

SoundFile object with a path to a file.

\n\n

The p5.SoundFile may not be available immediately because\nit loads the file information asynchronously.

\n\n

To do something with the sound as soon as it loads\npass the name of a function as the second parameter.

\n\n

Only one file path is required. However, audio file formats\n(i.e. mp3, ogg, wav and m4a/aac) are not supported by all\nweb browsers. If you want to ensure compatability, instead of a single\nfile path, you may include an Array of filepaths, and the browser will\nchoose a format that works.

', + is_constructor: 1, + params: [ + { + name: 'path', + description: + '

path to a sound file (String). Optionally,\n you may include multiple file formats in\n an array. Alternately, accepts an object\n from the HTML5 File API, or a p5.File.

\n', + type: 'String|Array' + }, + { + name: 'successCallback', + description: '

Name of a function to call once file loads

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

Name of a function to call if file fails to\n load. This function will receive an error or\n XMLHttpRequest object with information\n about what went wrong.

\n', + type: 'Function', + optional: true + }, + { + name: 'whileLoadingCallback', + description: + '

Name of a function to call while file\n is loading. That function will\n receive progress of the request to\n load the sound file\n (between 0 and 1) as its first\n parameter. This progress\n does not account for the additional\n time needed to decode the audio data.

\n', + type: 'Function', + optional: true + } + ], + example: [ + "\n
\n\nfunction preload() {\n soundFormats('mp3', 'ogg');\n mySound = loadSound('assets/doorbell.mp3');\n}\n\nfunction setup() {\n mySound.setVolume(0.1);\n mySound.play();\n}\n\n
" + ] + }, + 'p5.Amplitude': { + name: 'p5.Amplitude', + shortname: 'p5.Amplitude', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 3179, + description: + '

Amplitude measures volume between 0.0 and 1.0.\nListens to all p5sound by default, or use setInput()\nto listen to a specific sound source. Accepts an optional\nsmoothing value, which defaults to 0.

\n', + is_constructor: 1, + params: [ + { + name: 'smoothing', + description: + '

between 0.0 and .999 to smooth\n amplitude readings (defaults to 0)

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nvar sound, amplitude, cnv;\n\nfunction preload(){\n sound = loadSound('assets/beat.mp3');\n}\nfunction setup() {\n cnv = createCanvas(100,100);\n amplitude = new p5.Amplitude();\n\n // start / stop the sound when canvas is clicked\n cnv.mouseClicked(function() {\n if (sound.isPlaying() ){\n sound.stop();\n } else {\n sound.play();\n }\n });\n}\nfunction draw() {\n background(0);\n fill(255);\n var level = amplitude.getLevel();\n var size = map(level, 0, 1, 0, 200);\n ellipse(width/2, height/2, size, size);\n}\n\n
" + ] + }, + 'p5.FFT': { + name: 'p5.FFT', + shortname: 'p5.FFT', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 3458, + description: + '

FFT (Fast Fourier Transform) is an analysis algorithm that\nisolates individual\n\naudio frequencies within a waveform.

\n\n

Once instantiated, a p5.FFT object can return an array based on\ntwo types of analyses:
FFT.waveform() computes\namplitude values along the time domain. The array indices correspond\nto samples across a brief moment in time. Each value represents\namplitude of the waveform at that sample of time.
\n• FFT.analyze() computes amplitude values along the\nfrequency domain. The array indices correspond to frequencies (i.e.\npitches), from the lowest to the highest that humans can hear. Each\nvalue represents amplitude at that slice of the frequency spectrum.\nUse with getEnergy() to measure amplitude at specific\nfrequencies, or within a range of frequencies.

\n\n

FFT analyzes a very short snapshot of sound called a sample\nbuffer. It returns an array of amplitude measurements, referred\nto as bins. The array is 1024 bins long by default.\nYou can change the bin array length, but it must be a power of 2\nbetween 16 and 1024 in order for the FFT algorithm to function\ncorrectly. The actual size of the FFT buffer is twice the\nnumber of bins, so given a standard sample rate, the buffer is\n2048/44100 seconds long.

', + is_constructor: 1, + params: [ + { + name: 'smoothing', + description: + '

Smooth results of Freq Spectrum.\n 0.0 < smoothing < 1.0.\n Defaults to 0.8.

\n', + type: 'Number', + optional: true + }, + { + name: 'bins', + description: + '

Length of resulting array.\n Must be a power of two between\n 16 and 1024. Defaults to 1024.

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nfunction preload(){\n sound = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup(){\n var cnv = createCanvas(100,100);\n cnv.mouseClicked(togglePlay);\n fft = new p5.FFT();\n sound.amp(0.2);\n}\n\nfunction draw(){\n background(0);\n\n var spectrum = fft.analyze();\n noStroke();\n fill(0,255,0); // spectrum is green\n for (var i = 0; i< spectrum.length; i++){\n var x = map(i, 0, spectrum.length, 0, width);\n var h = -height + map(spectrum[i], 0, 255, height, 0);\n rect(x, height, width / spectrum.length, h )\n }\n\n var waveform = fft.waveform();\n noFill();\n beginShape();\n stroke(255,0,0); // waveform is red\n strokeWeight(1);\n for (var i = 0; i< waveform.length; i++){\n var x = map(i, 0, waveform.length, 0, width);\n var y = map( waveform[i], -1, 1, 0, height);\n vertex(x,y);\n }\n endShape();\n\n text('click to play/pause', 4, 10);\n}\n\n// fade sound if mouse is over canvas\nfunction togglePlay() {\n if (sound.isPlaying()) {\n sound.pause();\n } else {\n sound.loop();\n }\n}\n
" + ] + }, + 'p5.Signal': { + name: 'p5.Signal', + shortname: 'p5.Signal', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 5223, + description: + "

p5.Signal is a constant audio-rate signal used by p5.Oscillator\nand p5.Envelope for modulation math.

\n\n

This is necessary because Web Audio is processed on a seprate clock.\nFor example, the p5 draw loop runs about 60 times per second. But\nthe audio clock must process samples 44100 times per second. If we\nwant to add a value to each of those samples, we can't do it in the\ndraw loop, but we can do it by adding a constant-rate audio signal.</p.\n\n

This class mostly functions behind the scenes in p5.sound, and returns\na Tone.Signal from the Tone.js library by Yotam Mann.\nIf you want to work directly with audio signals for modular\nsynthesis, check out\ntone.js.

", + is_constructor: 1, + return: { + description: 'A Signal object from the Tone.js library', + type: 'Tone.Signal' + }, + example: [ + "\n
\nfunction setup() {\n carrier = new p5.Oscillator('sine');\n carrier.amp(1); // set amplitude\n carrier.freq(220); // set frequency\n carrier.start(); // start oscillating\n\n modulator = new p5.Oscillator('sawtooth');\n modulator.disconnect();\n modulator.amp(1);\n modulator.freq(4);\n modulator.start();\n\n // Modulator's default amplitude range is -1 to 1.\n // Multiply it by -200, so the range is -200 to 200\n // then add 220 so the range is 20 to 420\n carrier.freq( modulator.mult(-200).add(220) );\n}\n
" + ] + }, + 'p5.Oscillator': { + name: 'p5.Oscillator', + shortname: 'p5.Oscillator', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 5369, + description: + '

Creates a signal that oscillates between -1.0 and 1.0.\nBy default, the oscillation takes the form of a sinusoidal\nshape ('sine'). Additional types include 'triangle',\n'sawtooth' and 'square'. The frequency defaults to\n440 oscillations per second (440Hz, equal to the pitch of an\n'A' note).

\n\n

Set the type of oscillation with setType(), or by instantiating a\nspecific oscillator: p5.SinOsc, p5.TriOsc, p5.SqrOsc, or p5.SawOsc.\n

', + is_constructor: 1, + params: [ + { + name: 'freq', + description: '

frequency defaults to 440Hz

\n', + type: 'Number', + optional: true + }, + { + name: 'type', + description: + '

type of oscillator. Options:\n 'sine' (default), 'triangle',\n 'sawtooth', 'square'

\n', + type: 'String', + optional: true + } + ], + example: [ + "\n
\nvar osc;\nvar playing = false;\n\nfunction setup() {\n backgroundColor = color(255,0,255);\n textAlign(CENTER);\n\n osc = new p5.Oscillator();\n osc.setType('sine');\n osc.freq(240);\n osc.amp(0);\n osc.start();\n}\n\nfunction draw() {\n background(backgroundColor)\n text('click to play', width/2, height/2);\n}\n\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY < height && mouseY > 0) {\n if (!playing) {\n // ramp amplitude to 0.5 over 0.05 seconds\n osc.amp(0.5, 0.05);\n playing = true;\n backgroundColor = color(0,255,255);\n } else {\n // ramp amplitude to 0 over 0.5 seconds\n osc.amp(0, 0.5);\n playing = false;\n backgroundColor = color(255,0,255);\n }\n }\n}\n
" + ] + }, + 'p5.SinOsc': { + name: 'p5.SinOsc', + shortname: 'p5.SinOsc', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 5810, + description: + '

Constructor: new p5.SinOsc().\nThis creates a Sine Wave Oscillator and is\nequivalent to new p5.Oscillator('sine')\n or creating a p5.Oscillator and then calling\nits method setType('sine').\nSee p5.Oscillator for methods.

\n', + is_constructor: 1, + extends: 'p5.Oscillator', + params: [ + { + name: 'freq', + description: '

Set the frequency

\n', + type: 'Number', + optional: true + } + ] + }, + 'p5.TriOsc': { + name: 'p5.TriOsc', + shortname: 'p5.TriOsc', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 5827, + description: + '

Constructor: new p5.TriOsc().\nThis creates a Triangle Wave Oscillator and is\nequivalent to new p5.Oscillator('triangle')\n or creating a p5.Oscillator and then calling\nits method setType('triangle').\nSee p5.Oscillator for methods.

\n', + is_constructor: 1, + extends: 'p5.Oscillator', + params: [ + { + name: 'freq', + description: '

Set the frequency

\n', + type: 'Number', + optional: true + } + ] + }, + 'p5.SawOsc': { + name: 'p5.SawOsc', + shortname: 'p5.SawOsc', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 5844, + description: + '

Constructor: new p5.SawOsc().\nThis creates a SawTooth Wave Oscillator and is\nequivalent to new p5.Oscillator('sawtooth')\n or creating a p5.Oscillator and then calling\nits method setType('sawtooth').\nSee p5.Oscillator for methods.

\n', + is_constructor: 1, + extends: 'p5.Oscillator', + params: [ + { + name: 'freq', + description: '

Set the frequency

\n', + type: 'Number', + optional: true + } + ] + }, + 'p5.SqrOsc': { + name: 'p5.SqrOsc', + shortname: 'p5.SqrOsc', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 5861, + description: + '

Constructor: new p5.SqrOsc().\nThis creates a Square Wave Oscillator and is\nequivalent to new p5.Oscillator('square')\n or creating a p5.Oscillator and then calling\nits method setType('square').\nSee p5.Oscillator for methods.

\n', + is_constructor: 1, + extends: 'p5.Oscillator', + params: [ + { + name: 'freq', + description: '

Set the frequency

\n', + type: 'Number', + optional: true + } + ] + }, + 'p5.Envelope': { + name: 'p5.Envelope', + shortname: 'p5.Envelope', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 6316, + description: + '

Envelopes are pre-defined amplitude distribution over time.\nTypically, envelopes are used to control the output volume\nof an object, a series of fades referred to as Attack, Decay,\nSustain and Release (\nADSR\n). Envelopes can also control other Web Audio Parameters—for example, a p5.Envelope can\ncontrol an Oscillator's frequency like this: osc.freq(env).

\n

Use setRange to change the attack/release level.\nUse setADSR to change attackTime, decayTime, sustainPercent and releaseTime.

\n

Use the play method to play the entire envelope,\nthe ramp method for a pingable trigger,\nor triggerAttack/\ntriggerRelease to trigger noteOn/noteOff.

', + is_constructor: 1, + example: [ + "\n
\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001;\nvar decayTime = 0.2;\nvar susPercent = 0.2;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Envelope();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(playEnv);\n}\n\nfunction playEnv() {\n env.play();\n}\n
" + ] + }, + 'p5.Pulse': { + name: 'p5.Pulse', + shortname: 'p5.Pulse', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 7114, + description: + '

Creates a Pulse object, an oscillator that implements\nPulse Width Modulation.\nThe pulse is created with two oscillators.\nAccepts a parameter for frequency, and to set the\nwidth between the pulses. See \np5.Oscillator for a full list of methods.

\n', + extends: 'p5.Oscillator', + is_constructor: 1, + params: [ + { + name: 'freq', + description: '

Frequency in oscillations per second (Hz)

\n', + type: 'Number', + optional: true + }, + { + name: 'w', + description: + '

Width between the pulses (0 to 1.0,\n defaults to 0)

\n', + type: 'Number', + optional: true + } + ], + example: [ + '\n
\nvar pulse;\nfunction setup() {\n background(0);\n\n // Create and start the pulse wave oscillator\n pulse = new p5.Pulse();\n pulse.amp(0.5);\n pulse.freq(220);\n pulse.start();\n}\n\nfunction draw() {\n var w = map(mouseX, 0, width, 0, 1);\n w = constrain(w, 0, 1);\n pulse.width(w)\n}\n
' + ] + }, + 'p5.Noise': { + name: 'p5.Noise', + shortname: 'p5.Noise', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 7293, + description: + '

Noise is a type of oscillator that generates a buffer with random values.

\n', + extends: 'p5.Oscillator', + is_constructor: 1, + params: [ + { + name: 'type', + description: + '

Type of noise can be 'white' (default),\n 'brown' or 'pink'.

\n', + type: 'String' + } + ] + }, + 'p5.AudioIn': { + name: 'p5.AudioIn', + shortname: 'p5.AudioIn', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 7441, + description: + '

Get audio from an input, i.e. your computer's microphone.

\n\n

Turn the mic on/off with the start() and stop() methods. When the mic\nis on, its volume can be measured with getLevel or by connecting an\nFFT object.

\n\n

If you want to hear the AudioIn, use the .connect() method.\nAudioIn does not connect to p5.sound output by default to prevent\nfeedback.

\n\n

Note: This uses the getUserMedia/\nStream API, which is not supported by certain browsers. Access in Chrome browser\nis limited to localhost and https, but access over http may be limited.

', + is_constructor: 1, + params: [ + { + name: 'errorCallback', + description: + '

A function to call if there is an error\n accessing the AudioIn. For example,\n Safari and iOS devices do not\n currently allow microphone access.

\n', + type: 'Function', + optional: true + } + ], + example: [ + '\n
\nvar mic;\nfunction setup(){\n mic = new p5.AudioIn()\n mic.start();\n}\nfunction draw(){\n background(0);\n micLevel = mic.getLevel();\n ellipse(width/2, constrain(height-micLevel*height*5, 0, height), 10, 10);\n}\n
' + ] + }, + 'p5.Effect': { + name: 'p5.Effect', + shortname: 'p5.Effect', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 8357, + description: + '

Effect is a base class for audio effects in p5.
\nThis module handles the nodes and methods that are \ncommon and useful for current and future effects.

\n

This class is extended by p5.Distortion, \np5.Compressor,\np5.Delay, \np5.Filter, \np5.Reverb.

\n', + is_constructor: 1, + params: [ + { + name: 'ac', + description: '

Reference to the audio context of the p5 object

\n', + type: 'Object', + optional: true + }, + { + name: 'input', + description: '

Gain Node effect wrapper

\n', + type: 'AudioNode', + optional: true + }, + { + name: 'output', + description: '

Gain Node effect wrapper

\n', + type: 'AudioNode', + optional: true + }, + { + name: '_drywet', + description: '

Tone.JS CrossFade node (defaults to value: 1)

\n', + type: 'Object', + optional: true + }, + { + name: 'wet', + description: + '

Effects that extend this class should connect\n to the wet signal to this gain node, so that dry and wet \n signals are mixed properly.

\n', + type: 'AudioNode', + optional: true + } + ] + }, + 'p5.Filter': { + name: 'p5.Filter', + shortname: 'p5.Filter', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 8499, + description: + '

A p5.Filter uses a Web Audio Biquad Filter to filter\nthe frequency response of an input source. Subclasses\ninclude:

\n
    \n
  • p5.LowPass:\nAllows frequencies below the cutoff frequency to pass through,\nand attenuates frequencies above the cutoff.
  • \n
  • p5.HighPass:\nThe opposite of a lowpass filter.
  • \n
  • p5.BandPass:\nAllows a range of frequencies to pass through and attenuates\nthe frequencies below and above this frequency range.
  • \n
\n

The .res() method controls either width of the\nbandpass, or resonance of the low/highpass cutoff frequency.

\n

This class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.

\n', + extends: 'p5.Effect', + is_constructor: 1, + params: [ + { + name: 'type', + description: + '

'lowpass' (default), 'highpass', 'bandpass'

\n', + type: 'String', + optional: true + } + ], + example: [ + '\n
\nvar fft, noise, filter;\n\nfunction setup() {\n fill(255, 40, 255);\n\n filter = new p5.BandPass();\n\n noise = new p5.Noise();\n // disconnect unfiltered noise,\n // and connect to filter\n noise.disconnect();\n noise.connect(filter);\n noise.start();\n\n fft = new p5.FFT();\n}\n\nfunction draw() {\n background(30);\n\n // set the BandPass frequency based on mouseX\n var freq = map(mouseX, 0, width, 20, 10000);\n filter.freq(freq);\n // give the filter a narrow band (lower res = wider bandpass)\n filter.res(50);\n\n // draw filtered spectrum\n var spectrum = fft.analyze();\n noStroke();\n for (var i = 0; i < spectrum.length; i++) {\n var x = map(i, 0, spectrum.length, 0, width);\n var h = -height + map(spectrum[i], 0, 255, height, 0);\n rect(x, height, width/spectrum.length, h);\n }\n\n isMouseOverCanvas();\n}\n\nfunction isMouseOverCanvas() {\n var mX = mouseX, mY = mouseY;\n if (mX > 0 && mX < width && mY < height && mY > 0) {\n noise.amp(0.5, 0.2);\n } else {\n noise.amp(0, 0.2);\n }\n}\n
' + ] + }, + 'p5.LowPass': { + name: 'p5.LowPass', + shortname: 'p5.LowPass', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 8730, + description: + '

Constructor: new p5.LowPass() Filter.\nThis is the same as creating a p5.Filter and then calling\nits method setType('lowpass').\nSee p5.Filter for methods.

\n', + is_constructor: 1, + extends: 'p5.Filter' + }, + 'p5.HighPass': { + name: 'p5.HighPass', + shortname: 'p5.HighPass', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 8744, + description: + '

Constructor: new p5.HighPass() Filter.\nThis is the same as creating a p5.Filter and then calling\nits method setType('highpass').\nSee p5.Filter for methods.

\n', + is_constructor: 1, + extends: 'p5.Filter' + }, + 'p5.BandPass': { + name: 'p5.BandPass', + shortname: 'p5.BandPass', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 8758, + description: + '

Constructor: new p5.BandPass() Filter.\nThis is the same as creating a p5.Filter and then calling\nits method setType('bandpass').\nSee p5.Filter for methods.

\n', + is_constructor: 1, + extends: 'p5.Filter' + }, + 'p5.EQ': { + name: 'p5.EQ', + shortname: 'p5.EQ', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 8829, + description: + '

p5.EQ is an audio effect that performs the function of a multiband\naudio equalizer. Equalization is used to adjust the balance of\nfrequency compoenents of an audio signal. This process is commonly used\nin sound production and recording to change the waveform before it reaches\na sound output device. EQ can also be used as an audio effect to create\ninteresting distortions by filtering out parts of the spectrum. p5.EQ is\nbuilt using a chain of Web Audio Biquad Filter Nodes and can be\ninstantiated with 3 or 8 bands. Bands can be added or removed from\nthe EQ by directly modifying p5.EQ.bands (the array that stores filters).

\n

This class extends p5.Effect.\nMethods amp(), chain(),\ndrywet(), connect(), and\ndisconnect() are available.

\n', + is_constructor: 1, + extends: 'p5.Effect', + params: [ + { + name: '_eqsize', + description: '

Constructor will accept 3 or 8, defaults to 3

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'p5.EQ object', + type: 'Object' + }, + example: [ + "\n
\nvar eq;\nvar band_names;\nvar band_index;\n\nvar soundFile, play;\n\nfunction preload() {\n soundFormats('mp3', 'ogg');\n soundFile = loadSound('assets/beat');\n}\n\nfunction setup() {\n eq = new p5.EQ(3);\n soundFile.disconnect();\n eq.process(soundFile);\n\n band_names = ['lows','mids','highs'];\n band_index = 0;\n play = false;\n textAlign(CENTER);\n}\n\nfunction draw() {\n background(30);\n noStroke();\n fill(255);\n text('click to kill',50,25);\n\n fill(255, 40, 255);\n textSize(26);\n text(band_names[band_index],50,55);\n\n fill(255);\n textSize(9);\n text('space = play/pause',50,80);\n}\n\n//If mouse is over canvas, cycle to the next band and kill the frequency\nfunction mouseClicked() {\n for (var i = 0; i < eq.bands.length; i++) {\n eq.bands[i].gain(0);\n }\n eq.bands[band_index].gain(-40);\n if (mouseX > 0 && mouseX < width && mouseY < height && mouseY > 0) {\n band_index === 2 ? band_index = 0 : band_index++;\n }\n}\n\n//use space bar to trigger play / pause\nfunction keyPressed() {\n if (key===' ') {\n play = !play\n play ? soundFile.loop() : soundFile.pause();\n }\n}\n
" + ] + }, + 'p5.Panner3D': { + name: 'p5.Panner3D', + shortname: 'p5.Panner3D', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 9021, + description: + '

Panner3D is based on the \nWeb Audio Spatial Panner Node.\nThis panner is a spatial processing node that allows audio to be positioned\nand oriented in 3D space.

\n

The position is relative to an \nAudio Context Listener, which can be accessed\nby p5.soundOut.audiocontext.listener

\n', + is_constructor: 1 + }, + 'p5.Delay': { + name: 'p5.Delay', + shortname: 'p5.Delay', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 9472, + description: + '

Delay is an echo effect. It processes an existing sound source,\nand outputs a delayed version of that sound. The p5.Delay can\nproduce different effects depending on the delayTime, feedback,\nfilter, and type. In the example below, a feedback of 0.5 (the\ndefaul value) will produce a looping delay that decreases in\nvolume by 50% each repeat. A filter will cut out the high\nfrequencies so that the delay does not sound as piercing as the\noriginal source.

\n

This class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.

\n', + extends: 'p5.Effect', + is_constructor: 1, + example: [ + "\n
\nvar noise, env, delay;\n\nfunction setup() {\n background(0);\n noStroke();\n fill(255);\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n noise = new p5.Noise('brown');\n noise.amp(0);\n noise.start();\n\n delay = new p5.Delay();\n\n // delay.process() accepts 4 parameters:\n // source, delayTime, feedback, filter frequency\n // play with these numbers!!\n delay.process(noise, .12, .7, 2300);\n\n // play the noise with an envelope,\n // a series of fades ( time / value pairs )\n env = new p5.Envelope(.01, 0.2, .2, .1);\n}\n\n// mouseClick triggers envelope\nfunction mouseClicked() {\n // is mouse over canvas?\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n env.play(noise);\n }\n}\n
" + ] + }, + 'p5.Reverb': { + name: 'p5.Reverb', + shortname: 'p5.Reverb', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 9749, + description: + '

Reverb adds depth to a sound through a large number of decaying\nechoes. It creates the perception that sound is occurring in a\nphysical space. The p5.Reverb has paramters for Time (how long does the\nreverb last) and decayRate (how much the sound decays with each echo)\nthat can be set with the .set() or .process() methods. The p5.Convolver\nextends p5.Reverb allowing you to recreate the sound of actual physical\nspaces through convolution.

\n

This class extends p5.Effect.\nMethods amp(), chain(),\ndrywet(), connect(), and\ndisconnect() are available.

\n', + extends: 'p5.Effect', + is_constructor: 1, + example: [ + "\n
\nvar soundFile, reverb;\nfunction preload() {\n soundFile = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup() {\n reverb = new p5.Reverb();\n soundFile.disconnect(); // so we'll only hear reverb...\n\n // connect soundFile to reverb, process w/\n // 3 second reverbTime, decayRate of 2%\n reverb.process(soundFile, 3, 2);\n soundFile.play();\n}\n
" + ] + }, + 'p5.Convolver': { + name: 'p5.Convolver', + shortname: 'p5.Convolver', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 9920, + description: + '

p5.Convolver extends p5.Reverb. It can emulate the sound of real\nphysical spaces through a process called \nconvolution.

\n\n

Convolution multiplies any audio input by an "impulse response"\nto simulate the dispersion of sound over time. The impulse response is\ngenerated from an audio file that you provide. One way to\ngenerate an impulse response is to pop a balloon in a reverberant space\nand record the echo. Convolution can also be used to experiment with\nsound.

\n\n

Use the method createConvolution(path) to instantiate a\np5.Convolver with a path to your impulse response audio file.

', + extends: 'p5.Effect', + is_constructor: 1, + params: [ + { + name: 'path', + description: '

path to a sound file

\n', + type: 'String' + }, + { + name: 'callback', + description: '

function to call when loading succeeds

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to call if loading fails.\n This function will receive an error or\n XMLHttpRequest object with information\n about what went wrong.

\n', + type: 'Function', + optional: true + } + ], + example: [ + "\n
\nvar cVerb, sound;\nfunction preload() {\n // We have both MP3 and OGG versions of all sound assets\n soundFormats('ogg', 'mp3');\n\n // Try replacing 'bx-spring' with other soundfiles like\n // 'concrete-tunnel' 'small-plate' 'drum' 'beatbox'\n cVerb = createConvolver('assets/bx-spring.mp3');\n\n // Try replacing 'Damscray_DancingTiger' with\n // 'beat', 'doorbell', lucky_dragons_-_power_melody'\n sound = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup() {\n // disconnect from master output...\n sound.disconnect();\n\n // ...and process with cVerb\n // so that we only hear the convolution\n cVerb.process(sound);\n\n sound.play();\n}\n
" + ] + }, + 'p5.Phrase': { + name: 'p5.Phrase', + shortname: 'p5.Phrase', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 10476, + description: + '

A phrase is a pattern of musical events over time, i.e.\na series of notes and rests.

\n\n

Phrases must be added to a p5.Part for playback, and\neach part can play multiple phrases at the same time.\nFor example, one Phrase might be a kick drum, another\ncould be a snare, and another could be the bassline.

\n\n

The first parameter is a name so that the phrase can be\nmodified or deleted later. The callback is a a function that\nthis phrase will call at every step—for example it might be\ncalled playNote(value){}. The array determines\nwhich value is passed into the callback at each step of the\nphrase. It can be numbers, an object with multiple numbers,\nor a zero (0) indicates a rest so the callback won't be called).

', + is_constructor: 1, + params: [ + { + name: 'name', + description: '

Name so that you can access the Phrase.

\n', + type: 'String' + }, + { + name: 'callback', + description: + '

The name of a function that this phrase\n will call. Typically it will play a sound,\n and accept two parameters: a time at which\n to play the sound (in seconds from now),\n and a value from the sequence array. The\n time should be passed into the play() or\n start() method to ensure precision.

\n', + type: 'Function' + }, + { + name: 'sequence', + description: + '

Array of values to pass into the callback\n at each step of the phrase.

\n', + type: 'Array' + } + ], + example: [ + "\n
\nvar mySound, myPhrase, myPart;\nvar pattern = [1,0,0,2,0,2,0,0];\nvar msg = 'click to play';\n\nfunction preload() {\n mySound = loadSound('assets/beatbox.mp3');\n}\n\nfunction setup() {\n noStroke();\n fill(255);\n textAlign(CENTER);\n masterVolume(0.1);\n\n myPhrase = new p5.Phrase('bbox', makeSound, pattern);\n myPart = new p5.Part();\n myPart.addPhrase(myPhrase);\n myPart.setBPM(60);\n}\n\nfunction draw() {\n background(0);\n text(msg, width/2, height/2);\n}\n\nfunction makeSound(time, playbackRate) {\n mySound.rate(playbackRate);\n mySound.play(time);\n}\n\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n myPart.start();\n msg = 'playing pattern';\n }\n}\n\n
" + ] + }, + 'p5.Part': { + name: 'p5.Part', + shortname: 'p5.Part', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 10561, + description: + '

A p5.Part plays back one or more p5.Phrases. Instantiate a part\nwith steps and tatums. By default, each step represents a 1/16th note.

\n\n

See p5.Phrase for more about musical timing.

', + is_constructor: 1, + params: [ + { + name: 'steps', + description: '

Steps in the part

\n', + type: 'Number', + optional: true + }, + { + name: 'tatums', + description: + '

Divisions of a beat, e.g. use 1/4, or 0.25 for a quater note (default is 1/16, a sixteenth note)

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nvar box, drum, myPart;\nvar boxPat = [1,0,0,2,0,2,0,0];\nvar drumPat = [0,1,1,0,2,0,1,0];\nvar msg = 'click to play';\n\nfunction preload() {\n box = loadSound('assets/beatbox.mp3');\n drum = loadSound('assets/drum.mp3');\n}\n\nfunction setup() {\n noStroke();\n fill(255);\n textAlign(CENTER);\n masterVolume(0.1);\n\n var boxPhrase = new p5.Phrase('box', playBox, boxPat);\n var drumPhrase = new p5.Phrase('drum', playDrum, drumPat);\n myPart = new p5.Part();\n myPart.addPhrase(boxPhrase);\n myPart.addPhrase(drumPhrase);\n myPart.setBPM(60);\n masterVolume(0.1);\n}\n\nfunction draw() {\n background(0);\n text(msg, width/2, height/2);\n}\n\nfunction playBox(time, playbackRate) {\n box.rate(playbackRate);\n box.play(time);\n}\n\nfunction playDrum(time, playbackRate) {\n drum.rate(playbackRate);\n drum.play(time);\n}\n\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n myPart.start();\n msg = 'playing part';\n }\n}\n
" + ] + }, + 'p5.Score': { + name: 'p5.Score', + shortname: 'p5.Score', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 10814, + description: + '

A Score consists of a series of Parts. The parts will\nbe played back in order. For example, you could have an\nA part, a B part, and a C part, and play them back in this order\nnew p5.Score(a, a, b, a, c)

\n', + is_constructor: 1, + params: [ + { + name: 'parts', + description: + '

One or multiple parts, to be played in sequence.

\n', + type: 'p5.Part', + optional: true, + multiple: true + } + ] + }, + 'p5.SoundLoop': { + name: 'p5.SoundLoop', + shortname: 'p5.SoundLoop', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 10945, + description: '

SoundLoop

\n', + is_constructor: 1, + params: [ + { + name: 'callback', + description: + '

this function will be called on each iteration of theloop

\n', + type: 'Function' + }, + { + name: 'interval', + description: + '

amount of time or beats for each iteration of the loop\n defaults to 1

\n', + type: 'Number|String', + optional: true + } + ], + example: [ + "\n
\nvar click;\nvar looper1;\n\nfunction preload() {\n click = loadSound('assets/drum.mp3');\n}\n\nfunction setup() {\n //the looper's callback is passed the timeFromNow\n //this value should be used as a reference point from \n //which to schedule sounds \n looper1 = new p5.SoundLoop(function(timeFromNow){\n click.play(timeFromNow);\n background(255 * (looper1.iterations % 2));\n }, 2);\n\n //stop after 10 iteratios;\n looper1.maxIterations = 10;\n //start the loop\n looper1.start();\n}\n
" + ] + }, + 'p5.Compressor': { + name: 'p5.Compressor', + shortname: 'p5.Compressor', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 11205, + description: + '

Compressor is an audio effect class that performs dynamics compression\non an audio input source. This is a very commonly used technique in music\nand sound production. Compression creates an overall louder, richer, \nand fuller sound by lowering the volume of louds and raising that of softs.\nCompression can be used to avoid clipping (sound distortion due to \npeaks in volume) and is especially useful when many sounds are played \nat once. Compression can be used on indivudal sound sources in addition\nto the master output.

\n

This class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.

\n', + is_constructor: 1, + extends: 'p5.Effect' + }, + 'p5.SoundRecorder': { + name: 'p5.SoundRecorder', + shortname: 'p5.SoundRecorder', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 11417, + description: + '

Record sounds for playback and/or to save as a .wav file.\nThe p5.SoundRecorder records all sound output from your sketch,\nor can be assigned a specific source with setInput().

\n

The record() method accepts a p5.SoundFile as a parameter.\nWhen playback is stopped (either after the given amount of time,\nor with the stop() method), the p5.SoundRecorder will send its\nrecording to that p5.SoundFile for playback.

', + is_constructor: 1, + example: [ + "\n
\nvar mic, recorder, soundFile;\nvar state = 0;\n\nfunction setup() {\n background(200);\n // create an audio in\n mic = new p5.AudioIn();\n\n // prompts user to enable their browser mic\n mic.start();\n\n // create a sound recorder\n recorder = new p5.SoundRecorder();\n\n // connect the mic to the recorder\n recorder.setInput(mic);\n\n // this sound file will be used to\n // playback & save the recording\n soundFile = new p5.SoundFile();\n\n text('keyPress to record', 20, 20);\n}\n\nfunction keyPressed() {\n // make sure user enabled the mic\n if (state === 0 && mic.enabled) {\n\n // record to our p5.SoundFile\n recorder.record(soundFile);\n\n background(255,0,0);\n text('Recording!', 20, 20);\n state++;\n }\n else if (state === 1) {\n background(0,255,0);\n\n // stop recorder and\n // send result to soundFile\n recorder.stop();\n\n text('Stopped', 20, 20);\n state++;\n }\n\n else if (state === 2) {\n soundFile.play(); // play the result!\n save(soundFile, 'mySound.wav');\n state++;\n }\n}\n
" + ] + }, + 'p5.PeakDetect': { + name: 'p5.PeakDetect', + shortname: 'p5.PeakDetect', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 11655, + description: + '

PeakDetect works in conjunction with p5.FFT to\nlook for onsets in some or all of the frequency spectrum.\n

\n

\nTo use p5.PeakDetect, call update in the draw loop\nand pass in a p5.FFT object.\n

\n

\nYou can listen for a specific part of the frequency spectrum by\nsetting the range between freq1 and freq2.\n

\n\n

threshold is the threshold for detecting a peak,\nscaled between 0 and 1. It is logarithmic, so 0.1 is half as loud\nas 1.0.

\n\n

\nThe update method is meant to be run in the draw loop, and\nframes determines how many loops must pass before\nanother peak can be detected.\nFor example, if the frameRate() = 60, you could detect the beat of a\n120 beat-per-minute song with this equation:\n framesPerPeak = 60 / (estimatedBPM / 60 );\n

\n\n

\nBased on example contribtued by @b2renger, and a simple beat detection\nexplanation by Felix Turner.\n

', + is_constructor: 1, + params: [ + { + name: 'freq1', + description: '

lowFrequency - defaults to 20Hz

\n', + type: 'Number', + optional: true + }, + { + name: 'freq2', + description: '

highFrequency - defaults to 20000 Hz

\n', + type: 'Number', + optional: true + }, + { + name: 'threshold', + description: + '

Threshold for detecting a beat between 0 and 1\n scaled logarithmically where 0.1 is 1/2 the loudness\n of 1.0. Defaults to 0.35.

\n', + type: 'Number', + optional: true + }, + { + name: 'framesPerPeak', + description: '

Defaults to 20.

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\n\nvar cnv, soundFile, fft, peakDetect;\nvar ellipseWidth = 10;\n\nfunction preload() {\n soundFile = loadSound('assets/beat.mp3');\n}\n\nfunction setup() {\n background(0);\n noStroke();\n fill(255);\n textAlign(CENTER);\n\n // p5.PeakDetect requires a p5.FFT\n fft = new p5.FFT();\n peakDetect = new p5.PeakDetect();\n}\n\nfunction draw() {\n background(0);\n text('click to play/pause', width/2, height/2);\n\n // peakDetect accepts an fft post-analysis\n fft.analyze();\n peakDetect.update(fft);\n\n if ( peakDetect.isDetected ) {\n ellipseWidth = 50;\n } else {\n ellipseWidth *= 0.95;\n }\n\n ellipse(width/2, height/2, ellipseWidth, ellipseWidth);\n}\n\n// toggle play/stop when canvas is clicked\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n if (soundFile.isPlaying() ) {\n soundFile.stop();\n } else {\n soundFile.play();\n }\n }\n}\n
" + ] + }, + 'p5.Gain': { + name: 'p5.Gain', + shortname: 'p5.Gain', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 11879, + description: + '

A gain node is usefull to set the relative volume of sound.\nIt's typically used to build mixers.

\n', + is_constructor: 1, + example: [ + "\n
\n\n // load two soundfile and crossfade beetween them\n var sound1,sound2;\n var gain1, gain2, gain3;\n\n function preload(){\n soundFormats('ogg', 'mp3');\n sound1 = loadSound('assets/Damscray_-_Dancing_Tiger_01');\n sound2 = loadSound('assets/beat.mp3');\n }\n\n function setup() {\n createCanvas(400,200);\n\n // create a 'master' gain to which we will connect both soundfiles\n gain3 = new p5.Gain();\n gain3.connect();\n\n // setup first sound for playing\n sound1.rate(1);\n sound1.loop();\n sound1.disconnect(); // diconnect from p5 output\n\n gain1 = new p5.Gain(); // setup a gain node\n gain1.setInput(sound1); // connect the first sound to its input\n gain1.connect(gain3); // connect its output to the 'master'\n\n sound2.rate(1);\n sound2.disconnect();\n sound2.loop();\n\n gain2 = new p5.Gain();\n gain2.setInput(sound2);\n gain2.connect(gain3);\n\n }\n\n function draw(){\n background(180);\n\n // calculate the horizontal distance beetween the mouse and the right of the screen\n var d = dist(mouseX,0,width,0);\n\n // map the horizontal position of the mouse to values useable for volume control of sound1\n var vol1 = map(mouseX,0,width,0,1);\n var vol2 = 1-vol1; // when sound1 is loud, sound2 is quiet and vice versa\n\n gain1.amp(vol1,0.5,0);\n gain2.amp(vol2,0.5,0);\n\n // map the vertical position of the mouse to values useable for 'master volume control'\n var vol3 = map(mouseY,0,height,0,1);\n gain3.amp(vol3,0.5,0);\n }\n
\n" + ] + }, + 'p5.AudioVoice': { + name: 'p5.AudioVoice', + shortname: 'p5.AudioVoice', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 12020, + description: + '

Base class for monophonic synthesizers. Any extensions of this class\nshould follow the API and implement the methods below in order to \nremain compatible with p5.PolySynth();

\n', + is_constructor: 1 + }, + 'p5.MonoSynth': { + name: 'p5.MonoSynth', + shortname: 'p5.MonoSynth', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 12073, + description: + '

A MonoSynth is used as a single voice for sound synthesis.\nThis is a class to be used in conjunction with the PolySynth\nclass. Custom synthetisers should be built inheriting from\nthis class.

\n', + is_constructor: 1, + example: [ + '\n
\nvar monoSynth;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n cnv.mousePressed(playSynth);\n\n monoSynth = new p5.MonoSynth();\n\n textAlign(CENTER);\n text(\'click to play\', width/2, height/2);\n}\n\nfunction playSynth() {\n // time from now (in seconds)\n var time = 0;\n // note duration (in seconds)\n var dur = 0.25;\n // velocity (volume, from 0 to 1)\n var v = 0.2;\n\n monoSynth.play("G3", v, time, dur);\n monoSynth.play("C4", v, time += dur, dur);\n\n background(random(255), random(255), 255);\n text(\'click to play\', width/2, height/2);\n}\n
' + ] + }, + 'p5.PolySynth': { + name: 'p5.PolySynth', + shortname: 'p5.PolySynth', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 12362, + description: + '

An AudioVoice is used as a single voice for sound synthesis.\nThe PolySynth class holds an array of AudioVoice, and deals\nwith voices allocations, with setting notes to be played, and\nparameters to be set.

\n', + is_constructor: 1, + params: [ + { + name: 'synthVoice', + description: + '

A monophonic synth voice inheriting\n the AudioVoice class. Defaults to p5.MonoSynth

\n', + type: 'Number', + optional: true + }, + { + name: 'maxVoices', + description: '

Number of voices, defaults to 8;

\n', + type: 'Number', + optional: true + } + ], + example: [ + '\n
\nvar polySynth;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n cnv.mousePressed(playSynth);\n\n polySynth = new p5.PolySynth();\n\n textAlign(CENTER);\n text(\'click to play\', width/2, height/2);\n}\n\nfunction playSynth() {\n // note duration (in seconds)\n var dur = 1.5;\n\n // time from now (in seconds)\n var time = 0;\n\n // velocity (volume, from 0 to 1)\n var vel = 0.1;\n\n // notes can overlap with each other\n polySynth.play("G2", vel, 0, dur);\n polySynth.play("C3", vel, time += 1/3, dur);\n polySynth.play("G3", vel, time += 1/3, dur);\n\n background(random(255), random(255), 255);\n text(\'click to play\', width/2, height/2);\n}\n
' + ] + }, + 'p5.Distortion': { + name: 'p5.Distortion', + shortname: 'p5.Distortion', + classitems: [], + plugins: [], + extensions: [], + plugin_for: [], + extension_for: [], + module: 'p5.sound', + submodule: 'p5.sound', + namespace: '', + file: 'lib/addons/p5.sound.js', + line: 12767, + description: + '

A Distortion effect created with a Waveshaper Node,\nwith an approach adapted from\nKevin Ennis

\n

This class extends p5.Effect.
Methods amp(), chain(), \ndrywet(), connect(), and \ndisconnect() are available.

\n', + extends: 'p5.Effect', + is_constructor: 1, + params: [ + { + name: 'amount', + description: + '

Unbounded distortion amount.\n Normal values range from 0-1.

\n', + type: 'Number', + optional: true, + optdefault: '0.25' + }, + { + name: 'oversample', + description: '

'none', '2x', or '4x'.

\n', + type: 'String', + optional: true, + optdefault: "'none'" + } + ] + } + }, + elements: {}, + classitems: [ + { + file: 'src/color/color_conversion.js', + line: 10, + description: + '

Conversions adapted from http://www.easyrgb.com/en/math.php.

\n

In these functions, hue is always in the range [0, 1], just like all other\ncomponents are in the range [0, 1]. 'Brightness' and 'value' are used\ninterchangeably.

\n', + class: 'p5', + module: 'Color', + submodule: 'Color Conversion' + }, + { + file: 'src/color/color_conversion.js', + line: 21, + description: '

Convert an HSBA array to HSLA.

\n', + class: 'p5', + module: 'Color', + submodule: 'Color Conversion' + }, + { + file: 'src/color/color_conversion.js', + line: 47, + description: '

Convert an HSBA array to RGBA.

\n', + class: 'p5', + module: 'Color', + submodule: 'Color Conversion' + }, + { + file: 'src/color/color_conversion.js', + line: 102, + description: '

Convert an HSLA array to HSBA.

\n', + class: 'p5', + module: 'Color', + submodule: 'Color Conversion' + }, + { + file: 'src/color/color_conversion.js', + line: 125, + description: + '

Convert an HSLA array to RGBA.

\n

We need to change basis from HSLA to something that can be more easily be\nprojected onto RGBA. We will choose hue and brightness as our first two\ncomponents, and pick a convenient third one ('zest') so that we don't need\nto calculate formal HSBA saturation.

\n', + class: 'p5', + module: 'Color', + submodule: 'Color Conversion' + }, + { + file: 'src/color/color_conversion.js', + line: 189, + description: '

Convert an RGBA array to HSBA.

\n', + class: 'p5', + module: 'Color', + submodule: 'Color Conversion' + }, + { + file: 'src/color/color_conversion.js', + line: 228, + description: '

Convert an RGBA array to HSLA.

\n', + class: 'p5', + module: 'Color', + submodule: 'Color Conversion' + }, + { + file: 'src/color/creating_reading.js', + line: 16, + description: + '

Extracts the alpha value from a color or pixel array.

\n', + itemtype: 'method', + name: 'alpha', + params: [ + { + name: 'color', + description: + '

p5.Color object, color components,\n or CSS color

\n', + type: 'p5.Color|Number[]|String' + } + ], + return: { + description: 'the alpha value', + type: 'Number' + }, + example: [ + "\n
\n\nnoStroke();\nlet c = color(0, 126, 255, 102);\nfill(c);\nrect(15, 15, 35, 70);\nlet value = alpha(c); // Sets 'value' to 102\nfill(value);\nrect(50, 15, 35, 70);\n\n
" + ], + alt: + 'Left half of canvas light blue and right half light charcoal grey.\nLeft half of canvas light purple and right half a royal blue.\nLeft half of canvas salmon pink and the right half white.\nYellow rect in middle right of canvas, with 55 pixel width and height.\nYellow ellipse in top left canvas, black ellipse in bottom right,both 80x80.\nBright fuchsia rect in middle of canvas, 60 pixel width and height.\nTwo bright green rects on opposite sides of the canvas, both 45x80.\nFour blue rects in each corner of the canvas, each are 35x35.\nBright sea green rect on left and darker rect on right of canvas, both 45x80.\nDark green rect on left and light green rect on right of canvas, both 45x80.\nDark blue rect on left and light teal rect on right of canvas, both 45x80.\nblue rect on left and green on right, both with black outlines & 35x60.\nsalmon pink rect on left and black on right, both 35x60.\n4 rects, tan, brown, brownish purple and purple, with white outlines & 20x60.\nlight pastel green rect on left and dark grey rect on right, both 35x60.\nyellow rect on left and red rect on right, both with black outlines & 35x60.\ngrey canvas\ndeep pink rect on left and grey rect on right, both 35x60.', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/creating_reading.js', + line: 61, + description: + '

Extracts the blue value from a color or pixel array.

\n', + itemtype: 'method', + name: 'blue', + params: [ + { + name: 'color', + description: + '

p5.Color object, color components,\n or CSS color

\n', + type: 'p5.Color|Number[]|String' + } + ], + return: { + description: 'the blue value', + type: 'Number' + }, + example: [ + "\n
\n\nlet c = color(175, 100, 220); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nrect(15, 20, 35, 60); // Draw left rectangle\n\nlet blueValue = blue(c); // Get blue in 'c'\nprint(blueValue); // Prints \"220.0\"\nfill(0, 0, blueValue); // Use 'blueValue' in new fill\nrect(50, 20, 35, 60); // Draw right rectangle\n\n
" + ], + alt: 'Left half of canvas light purple and right half a royal blue.', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/creating_reading.js', + line: 91, + description: + '

Extracts the HSB brightness value from a color or pixel array.

\n', + itemtype: 'method', + name: 'brightness', + params: [ + { + name: 'color', + description: + '

p5.Color object, color components,\n or CSS color

\n', + type: 'p5.Color|Number[]|String' + } + ], + return: { + description: 'the brightness value', + type: 'Number' + }, + example: [ + "\n
\n\nnoStroke();\ncolorMode(HSB, 255);\nlet c = color(0, 126, 255);\nfill(c);\nrect(15, 20, 35, 60);\nlet value = brightness(c); // Sets 'value' to 255\nfill(value);\nrect(50, 20, 35, 60);\n\n
\n
\n\nnoStroke();\ncolorMode(HSB, 255);\nlet c = color('hsb(60, 100%, 50%)');\nfill(c);\nrect(15, 20, 35, 60);\nlet value = brightness(c); // A 'value' of 50% is 127.5\nfill(value);\nrect(50, 20, 35, 60);\n\n
" + ], + alt: + 'Left half of canvas salmon pink and the right half white.\nLeft half of canvas yellow at half brightness and the right gray .', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/creating_reading.js', + line: 134, + description: + '

Creates colors for storing in variables of the color datatype. The\nparameters are interpreted as RGB or HSB values depending on the\ncurrent colorMode(). The default mode is RGB values from 0 to 255\nand, therefore, the function call color(255, 204, 0) will return a\nbright yellow color.\n

\nNote that if only one value is provided to color(), it will be interpreted\nas a grayscale value. Add a second value, and it will be used for alpha\ntransparency. When three values are specified, they are interpreted as\neither RGB or HSB values. Adding a fourth value applies alpha\ntransparency.\n

\nIf a single string argument is provided, RGB, RGBA and Hex CSS color\nstrings and all named color strings are supported. In this case, an alpha\nnumber value as a second argument is not supported, the RGBA form should be\nused.

\n', + itemtype: 'method', + name: 'color', + return: { + description: 'resulting color', + type: 'p5.Color' + }, + example: [ + "\n
\n\nlet c = color(255, 204, 0); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nnoStroke(); // Don't draw a stroke around shapes\nrect(30, 20, 55, 55); // Draw rectangle\n\n
\n\n
\n\nlet c = color(255, 204, 0); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nnoStroke(); // Don't draw a stroke around shapes\nellipse(25, 25, 80, 80); // Draw left circle\n\n// Using only one value with color()\n// generates a grayscale value.\nc = color(65); // Update 'c' with grayscale value\nfill(c); // Use updated 'c' as fill color\nellipse(75, 75, 80, 80); // Draw right circle\n\n
\n\n
\n\n// Named SVG & CSS colors may be used,\nlet c = color('magenta');\nfill(c); // Use 'c' as fill color\nnoStroke(); // Don't draw a stroke around shapes\nrect(20, 20, 60, 60); // Draw rectangle\n\n
\n\n
\n\n// as can hex color codes:\nnoStroke(); // Don't draw a stroke around shapes\nlet c = color('#0f0');\nfill(c); // Use 'c' as fill color\nrect(0, 10, 45, 80); // Draw rectangle\n\nc = color('#00ff00');\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 45, 80); // Draw rectangle\n\n
\n\n
\n\n// RGB and RGBA color strings are also supported:\n// these all set to the same color (solid blue)\nlet c;\nnoStroke(); // Don't draw a stroke around shapes\nc = color('rgb(0,0,255)');\nfill(c); // Use 'c' as fill color\nrect(10, 10, 35, 35); // Draw rectangle\n\nc = color('rgb(0%, 0%, 100%)');\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 35, 35); // Draw rectangle\n\nc = color('rgba(0, 0, 255, 1)');\nfill(c); // Use updated 'c' as fill color\nrect(10, 55, 35, 35); // Draw rectangle\n\nc = color('rgba(0%, 0%, 100%, 1)');\nfill(c); // Use updated 'c' as fill color\nrect(55, 55, 35, 35); // Draw rectangle\n\n
\n\n
\n\n// HSL color is also supported and can be specified\n// by value\nlet c;\nnoStroke(); // Don't draw a stroke around shapes\nc = color('hsl(160, 100%, 50%)');\nfill(c); // Use 'c' as fill color\nrect(0, 10, 45, 80); // Draw rectangle\n\nc = color('hsla(160, 100%, 50%, 0.5)');\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 45, 80); // Draw rectangle\n\n
\n\n
\n\n// HSB color is also supported and can be specified\n// by value\nlet c;\nnoStroke(); // Don't draw a stroke around shapes\nc = color('hsb(160, 100%, 50%)');\nfill(c); // Use 'c' as fill color\nrect(0, 10, 45, 80); // Draw rectangle\n\nc = color('hsba(160, 100%, 50%, 0.5)');\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 45, 80); // Draw rectangle\n\n
\n\n
\n\nlet c; // Declare color 'c'\nnoStroke(); // Don't draw a stroke around shapes\n\n// If no colorMode is specified, then the\n// default of RGB with scale of 0-255 is used.\nc = color(50, 55, 100); // Create a color for 'c'\nfill(c); // Use color variable 'c' as fill color\nrect(0, 10, 45, 80); // Draw left rect\n\ncolorMode(HSB, 100); // Use HSB with scale of 0-100\nc = color(50, 55, 100); // Update 'c' with new color\nfill(c); // Use updated 'c' as fill color\nrect(55, 10, 45, 80); // Draw right rect\n\n
" + ], + alt: + 'Yellow rect in middle right of canvas, with 55 pixel width and height.\nYellow ellipse in top left of canvas, black ellipse in bottom right,both 80x80.\nBright fuchsia rect in middle of canvas, 60 pixel width and height.\nTwo bright green rects on opposite sides of the canvas, both 45x80.\nFour blue rects in each corner of the canvas, each are 35x35.\nBright sea green rect on left and darker rect on right of canvas, both 45x80.\nDark green rect on left and lighter green rect on right of canvas, both 45x80.\nDark blue rect on left and light teal rect on right of canvas, both 45x80.', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading', + overloads: [ + { + line: 134, + params: [ + { + name: 'gray', + description: + '

number specifying value between white\n and black.

\n', + type: 'Number' + }, + { + name: 'alpha', + description: + '

alpha value relative to current color range\n (default is 0-255)

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'resulting color', + type: 'p5.Color' + } + }, + { + line: 293, + params: [ + { + name: 'v1', + description: + '

red or hue value relative to\n the current color range

\n', + type: 'Number' + }, + { + name: 'v2', + description: + '

green or saturation value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'v3', + description: + '

blue or brightness value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + return: { + description: '', + type: 'p5.Color' + } + }, + { + line: 305, + params: [ + { + name: 'value', + description: '

a color string

\n', + type: 'String' + } + ], + return: { + description: '', + type: 'p5.Color' + } + }, + { + line: 310, + params: [ + { + name: 'values', + description: + '

an array containing the red,green,blue &\n and alpha components of the color

\n', + type: 'Number[]' + } + ], + return: { + description: '', + type: 'p5.Color' + } + }, + { + line: 316, + params: [ + { + name: 'color', + description: '', + type: 'p5.Color' + } + ], + return: { + description: '', + type: 'p5.Color' + } + } + ] + }, + { + file: 'src/color/creating_reading.js', + line: 332, + description: + '

Extracts the green value from a color or pixel array.

\n', + itemtype: 'method', + name: 'green', + params: [ + { + name: 'color', + description: + '

p5.Color object, color components,\n or CSS color

\n', + type: 'p5.Color|Number[]|String' + } + ], + return: { + description: 'the green value', + type: 'Number' + }, + example: [ + "\n
\n\nlet c = color(20, 75, 200); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nrect(15, 20, 35, 60); // Draw left rectangle\n\nlet greenValue = green(c); // Get green in 'c'\nprint(greenValue); // Print \"75.0\"\nfill(0, greenValue, 0); // Use 'greenValue' in new fill\nrect(50, 20, 35, 60); // Draw right rectangle\n\n
" + ], + alt: + 'blue rect on left and green on right, both with black outlines & 35x60.', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/creating_reading.js', + line: 363, + description: + '

Extracts the hue value from a color or pixel array.

\n

Hue exists in both HSB and HSL. This function will return the\nHSB-normalized hue when supplied with an HSB color object (or when supplied\nwith a pixel array while the color mode is HSB), but will default to the\nHSL-normalized hue otherwise. (The values will only be different if the\nmaximum hue setting for each system is different.)

\n', + itemtype: 'method', + name: 'hue', + params: [ + { + name: 'color', + description: + '

p5.Color object, color components,\n or CSS color

\n', + type: 'p5.Color|Number[]|String' + } + ], + return: { + description: 'the hue', + type: 'Number' + }, + example: [ + '\n
\n\nnoStroke();\ncolorMode(HSB, 255);\nlet c = color(0, 126, 255);\nfill(c);\nrect(15, 20, 35, 60);\nlet value = hue(c); // Sets \'value\' to "0"\nfill(value);\nrect(50, 20, 35, 60);\n\n
' + ], + alt: 'salmon pink rect on left and black on right, both 35x60.', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/creating_reading.js', + line: 400, + description: + '

Blends two colors to find a third color somewhere between them. The amt\nparameter is the amount to interpolate between the two values where 0.0\nequal to the first color, 0.1 is very near the first color, 0.5 is halfway\nin between, etc. An amount below 0 will be treated as 0. Likewise, amounts\nabove 1 will be capped at 1. This is different from the behavior of lerp(),\nbut necessary because otherwise numbers outside the range will produce\nstrange and unexpected colors.\n

\nThe way that colours are interpolated depends on the current color mode.

\n', + itemtype: 'method', + name: 'lerpColor', + params: [ + { + name: 'c1', + description: '

interpolate from this color

\n', + type: 'p5.Color' + }, + { + name: 'c2', + description: '

interpolate to this color

\n', + type: 'p5.Color' + }, + { + name: 'amt', + description: '

number between 0 and 1

\n', + type: 'Number' + } + ], + return: { + description: 'interpolated color', + type: 'p5.Color' + }, + example: [ + '\n
\n\ncolorMode(RGB);\nstroke(255);\nbackground(51);\nlet from = color(218, 165, 32);\nlet to = color(72, 61, 139);\ncolorMode(RGB); // Try changing to HSB.\nlet interA = lerpColor(from, to, 0.33);\nlet interB = lerpColor(from, to, 0.66);\nfill(from);\nrect(10, 20, 20, 60);\nfill(interA);\nrect(30, 20, 20, 60);\nfill(interB);\nrect(50, 20, 20, 60);\nfill(to);\nrect(70, 20, 20, 60);\n\n
' + ], + alt: + '4 rects one tan, brown, brownish purple, purple, with white outlines & 20x60', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/creating_reading.js', + line: 497, + description: + '

Extracts the HSL lightness value from a color or pixel array.

\n', + itemtype: 'method', + name: 'lightness', + params: [ + { + name: 'color', + description: + '

p5.Color object, color components,\n or CSS color

\n', + type: 'p5.Color|Number[]|String' + } + ], + return: { + description: 'the lightness', + type: 'Number' + }, + example: [ + "\n
\n\nnoStroke();\ncolorMode(HSL);\nlet c = color(156, 100, 50, 1);\nfill(c);\nrect(15, 20, 35, 60);\nlet value = lightness(c); // Sets 'value' to 50\nfill(value);\nrect(50, 20, 35, 60);\n\n
" + ], + alt: + 'light pastel green rect on left and dark grey rect on right, both 35x60.', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/creating_reading.js', + line: 527, + description: '

Extracts the red value from a color or pixel array.

\n', + itemtype: 'method', + name: 'red', + params: [ + { + name: 'color', + description: + '

p5.Color object, color components,\n or CSS color

\n', + type: 'p5.Color|Number[]|String' + } + ], + return: { + description: 'the red value', + type: 'Number' + }, + example: [ + "\n
\n\nlet c = color(255, 204, 0); // Define color 'c'\nfill(c); // Use color variable 'c' as fill color\nrect(15, 20, 35, 60); // Draw left rectangle\n\nlet redValue = red(c); // Get red in 'c'\nprint(redValue); // Print \"255.0\"\nfill(redValue, 0, 0); // Use 'redValue' in new fill\nrect(50, 20, 35, 60); // Draw right rectangle\n\n
\n\n
\n\ncolorMode(RGB, 255); // Sets the range for red, green, and blue to 255\nlet c = color(127, 255, 0);\ncolorMode(RGB, 1); // Sets the range for red, green, and blue to 1\nlet myColor = red(c);\nprint(myColor); // 0.4980392156862745\n\n
" + ], + alt: + 'yellow rect on left and red rect on right, both with black outlines and 35x60.\ngrey canvas', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/creating_reading.js', + line: 567, + description: + '

Extracts the saturation value from a color or pixel array.

\n

Saturation is scaled differently in HSB and HSL. This function will return\nthe HSB saturation when supplied with an HSB color object (or when supplied\nwith a pixel array while the color mode is HSB), but will default to the\nHSL saturation otherwise.

\n', + itemtype: 'method', + name: 'saturation', + params: [ + { + name: 'color', + description: + '

p5.Color object, color components,\n or CSS color

\n', + type: 'p5.Color|Number[]|String' + } + ], + return: { + description: 'the saturation value', + type: 'Number' + }, + example: [ + "\n
\n\nnoStroke();\ncolorMode(HSB, 255);\nlet c = color(0, 126, 255);\nfill(c);\nrect(15, 20, 35, 60);\nlet value = saturation(c); // Sets 'value' to 126\nfill(value);\nrect(50, 20, 35, 60);\n\n
" + ], + alt: 'deep pink rect on left and grey rect on right, both 35x60.', + class: 'p5', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 52, + description: + '

This function returns the color formatted as a string. This can be useful\nfor debugging, or for using p5.js with other libraries.

\n', + itemtype: 'method', + name: 'toString', + params: [ + { + name: 'format', + description: + '

How the color string will be formatted.\nLeaving this empty formats the string as rgba(r, g, b, a).\n'#rgb' '#rgba' '#rrggbb' and '#rrggbbaa' format as hexadecimal color codes.\n'rgb' 'hsb' and 'hsl' return the color formatted in the specified color mode.\n'rgba' 'hsba' and 'hsla' are the same as above but with alpha channels.\n'rgb%' 'hsb%' 'hsl%' 'rgba%' 'hsba%' and 'hsla%' format as percentages.

\n', + type: 'String', + optional: true + } + ], + return: { + description: 'the formatted string', + type: 'String' + }, + example: [ + "\n
\n\nlet myColor;\nfunction setup() {\n createCanvas(200, 200);\n stroke(255);\n myColor = color(100, 100, 250);\n fill(myColor);\n}\n\nfunction draw() {\n rotate(HALF_PI);\n text(myColor.toString(), 0, -5);\n text(myColor.toString('#rrggbb'), 0, -30);\n text(myColor.toString('rgba%'), 0, -55);\n}\n\n
" + ], + alt: 'canvas with text representation of color', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 253, + itemtype: 'method', + name: 'setRed', + params: [ + { + name: 'red', + description: '

the new red value

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\nlet backgroundColor;\n\nfunction setup() {\n backgroundColor = color(100, 50, 150);\n}\n\nfunction draw() {\n backgroundColor.setRed(128 + 128 * sin(millis() / 1000));\n background(backgroundColor);\n}\n\n
' + ], + alt: 'canvas with gradually changing background color', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 280, + itemtype: 'method', + name: 'setGreen', + params: [ + { + name: 'green', + description: '

the new green value

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\nlet backgroundColor;\n\nfunction setup() {\n backgroundColor = color(100, 50, 150);\n}\n\nfunction draw() {\n backgroundColor.setGreen(128 + 128 * sin(millis() / 1000));\n background(backgroundColor);\n}\n\n
' + ], + alt: 'canvas with gradually changing background color', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 307, + itemtype: 'method', + name: 'setBlue', + params: [ + { + name: 'blue', + description: '

the new blue value

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\nlet backgroundColor;\n\nfunction setup() {\n backgroundColor = color(100, 50, 150);\n}\n\nfunction draw() {\n backgroundColor.setBlue(128 + 128 * sin(millis() / 1000));\n background(backgroundColor);\n}\n\n
' + ], + alt: 'canvas with gradually changing background color', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 334, + itemtype: 'method', + name: 'setAlpha', + params: [ + { + name: 'alpha', + description: '

the new alpha value

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\nlet squareColor;\n\nfunction setup() {\n ellipseMode(CORNERS);\n strokeWeight(4);\n squareColor = color(100, 50, 150);\n}\n\nfunction draw() {\n background(255);\n\n noFill();\n stroke(0);\n ellipse(10, 10, width - 10, height - 10);\n\n squareColor.setAlpha(128 + 128 * sin(millis() / 1000));\n fill(squareColor);\n noStroke();\n rect(13, 13, width - 26, height - 26);\n}\n\n
' + ], + alt: 'circle behind a square with gradually changing opacity', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 415, + description: + '

Hue is the same in HSB and HSL, but the maximum value may be different.\nThis function will return the HSB-normalized saturation when supplied with\nan HSB color object, but will default to the HSL-normalized saturation\notherwise.

\n', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 446, + description: + '

Saturation is scaled differently in HSB and HSL. This function will return\nthe HSB saturation when supplied with an HSB color object, but will default\nto the HSL saturation otherwise.

\n', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 465, + description: '

CSS named colors.

\n', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 618, + description: + '

These regular expressions are used to build up the patterns for matching\nviable CSS color strings: fragmenting the regexes in this way increases the\nlegibility and comprehensibility of the code.

\n

Note that RGB values of .9 are not parsed by IE, but are supported here for\ncolor string consistency.

\n', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 631, + description: + '

Full color string patterns. The capture groups are necessary.

\n', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/p5.Color.js', + line: 994, + description: + '

For HSB and HSL, interpret the gray level as a brightness/lightness\nvalue (they are equivalent when chroma is zero). For RGB, normalize the\ngray level according to the blue maximum.

\n', + class: 'p5.Color', + module: 'Color', + submodule: 'Creating & Reading' + }, + { + file: 'src/color/setting.js', + line: 15, + description: + '

The background() function sets the color used for the background of the\np5.js canvas. The default background is transparent. This function is\ntypically used within draw() to clear the display window at the beginning\nof each frame, but it can be used inside setup() to set the background on\nthe first frame of animation or if the background need only be set once.\n

\nThe color is either specified in terms of the RGB, HSB, or HSL color\ndepending on the current colorMode. (The default color space is RGB, with\neach value in the range from 0 to 255). The alpha range by default is also 0 to 255.\n

\nIf a single string argument is provided, RGB, RGBA and Hex CSS color strings\nand all named color strings are supported. In this case, an alpha number\nvalue as a second argument is not supported, the RGBA form should be used.\n

\nA p5.Color object can also be provided to set the background color.\n

\nA p5.Image can also be provided to set the background image.

\n', + itemtype: 'method', + name: 'background', + chainable: 1, + example: [ + "\n
\n\n// Grayscale integer value\nbackground(51);\n\n
\n\n
\n\n// R, G & B integer values\nbackground(255, 204, 0);\n\n
\n\n
\n\n// H, S & B integer values\ncolorMode(HSB);\nbackground(255, 204, 100);\n\n
\n\n
\n\n// Named SVG/CSS color string\nbackground('red');\n\n
\n\n
\n\n// three-digit hexadecimal RGB notation\nbackground('#fae');\n\n
\n\n
\n\n// six-digit hexadecimal RGB notation\nbackground('#222222');\n\n
\n\n
\n\n// integer RGB notation\nbackground('rgb(0,255,0)');\n\n
\n\n
\n\n// integer RGBA notation\nbackground('rgba(0,255,0, 0.25)');\n\n
\n\n
\n\n// percentage RGB notation\nbackground('rgb(100%,0%,10%)');\n\n
\n\n
\n\n// percentage RGBA notation\nbackground('rgba(100%,0%,100%,0.5)');\n\n
\n\n
\n\n// p5 Color object\nbackground(color(0, 0, 255));\n\n
" + ], + alt: + 'canvas with darkest charcoal grey background.\ncanvas with yellow background.\ncanvas with royal blue background.\ncanvas with red background.\ncanvas with pink background.\ncanvas with black background.\ncanvas with bright green background.\ncanvas with soft green background.\ncanvas with red background.\ncanvas with light purple background.\ncanvas with blue background.', + class: 'p5', + module: 'Color', + submodule: 'Setting', + overloads: [ + { + line: 15, + params: [ + { + name: 'color', + description: + '

any value created by the color() function

\n', + type: 'p5.Color' + } + ], + chainable: 1 + }, + { + line: 131, + params: [ + { + name: 'colorstring', + description: + '

color string, possible formats include: integer\n rgb() or rgba(), percentage rgb() or rgba(),\n 3-digit hex, 6-digit hex

\n', + type: 'String' + }, + { + name: 'a', + description: + '

opacity of the background relative to current\n color range (default is 0-255)

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 141, + params: [ + { + name: 'gray', + description: '

specifies a value between white and black

\n', + type: 'Number' + }, + { + name: 'a', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 148, + params: [ + { + name: 'v1', + description: + '

red or hue value (depending on the current color\n mode)

\n', + type: 'Number' + }, + { + name: 'v2', + description: + '

green or saturation value (depending on the current\n color mode)

\n', + type: 'Number' + }, + { + name: 'v3', + description: + '

blue or brightness value (depending on the current\n color mode)

\n', + type: 'Number' + }, + { + name: 'a', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 160, + params: [ + { + name: 'values', + description: + '

an array containing the red, green, blue\n and alpha components of the color

\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + line: 167, + params: [ + { + name: 'image', + description: + '

image created with loadImage() or createImage(),\n to set as background\n (must be same size as the sketch window)

\n', + type: 'p5.Image' + }, + { + name: 'a', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/color/setting.js', + line: 181, + description: + '

Clears the pixels within a buffer. This function only clears the canvas.\nIt will not clear objects created by createX() methods such as\ncreateVideo() or createDiv().\nUnlike the main graphics context, pixels in additional graphics areas created\nwith createGraphics() can be entirely\nor partially transparent. This function clears everything to make all of\nthe pixels 100% transparent.

\n', + itemtype: 'method', + name: 'clear', + chainable: 1, + example: [ + '\n
\n\n// Clear the screen on mouse press.\nfunction setup() {\n createCanvas(100, 100);\n}\n\nfunction draw() {\n ellipse(mouseX, mouseY, 20, 20);\n}\n\nfunction mousePressed() {\n clear();\n}\n\n
' + ], + alt: + '20x20 white ellipses are continually drawn at mouse x and y coordinates.', + class: 'p5', + module: 'Color', + submodule: 'Setting' + }, + { + file: 'src/color/setting.js', + line: 220, + description: + '

colorMode() changes the way p5.js interprets color data. By default, the\nparameters for fill(), stroke(), background(), and color() are defined by\nvalues between 0 and 255 using the RGB color model. This is equivalent to\nsetting colorMode(RGB, 255). Setting colorMode(HSB) lets you use the HSB\nsystem instead. By default, this is colorMode(HSB, 360, 100, 100, 1). You\ncan also use HSL.\n

\nNote: existing color objects remember the mode that they were created in,\nso you can change modes as you like without affecting their appearance.

\n', + itemtype: 'method', + name: 'colorMode', + chainable: 1, + example: [ + '\n
\n\nnoStroke();\ncolorMode(RGB, 100);\nfor (let i = 0; i < 100; i++) {\n for (let j = 0; j < 100; j++) {\n stroke(i, j, 0);\n point(i, j);\n }\n}\n\n
\n\n
\n\nnoStroke();\ncolorMode(HSB, 100);\nfor (let i = 0; i < 100; i++) {\n for (let j = 0; j < 100; j++) {\n stroke(i, j, 100);\n point(i, j);\n }\n}\n\n
\n\n
\n\ncolorMode(RGB, 255);\nlet c = color(127, 255, 0);\n\ncolorMode(RGB, 1);\nlet myColor = c._getRed();\ntext(myColor, 10, 10, 80, 80);\n\n
\n\n
\n\nnoFill();\ncolorMode(RGB, 255, 255, 255, 1);\nbackground(255);\n\nstrokeWeight(4);\nstroke(255, 0, 10, 0.3);\nellipse(40, 40, 50, 50);\nellipse(50, 50, 40, 40);\n\n
' + ], + alt: + 'Green to red gradient from bottom L to top R. shading originates from top left.\nRainbow gradient from left to right. Brightness increasing to white at top.\nunknown image.\n50x50 ellipse at middle L & 40x40 ellipse at center. Translucent pink outlines.', + class: 'p5', + module: 'Color', + submodule: 'Setting', + overloads: [ + { + line: 220, + params: [ + { + name: 'mode', + description: + '

either RGB, HSB or HSL, corresponding to\n Red/Green/Blue and Hue/Saturation/Brightness\n (or Lightness)

\n', + type: 'Constant' + }, + { + name: 'max', + description: '

range for all values

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 297, + params: [ + { + name: 'mode', + description: '', + type: 'Constant' + }, + { + name: 'max1', + description: + '

range for the red or hue depending on the\n current color mode

\n', + type: 'Number' + }, + { + name: 'max2', + description: + '

range for the green or saturation depending\n on the current color mode

\n', + type: 'Number' + }, + { + name: 'max3', + description: + '

range for the blue or brightness/lightness\n depending on the current color mode

\n', + type: 'Number' + }, + { + name: 'maxA', + description: '

range for the alpha

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/color/setting.js', + line: 341, + description: + '

Sets the color used to fill shapes. For example, if you run\nfill(204, 102, 0), all shapes drawn after the fill command will be filled with the color orange. This\ncolor is either specified in terms of the RGB or HSB color depending on\nthe current colorMode(). (The default color space is RGB, with each value\nin the range from 0 to 255). The alpha range by default is also 0 to 255.\n

\nIf a single string argument is provided, RGB, RGBA and Hex CSS color strings\nand all named color strings are supported. In this case, an alpha number\nvalue as a second argument is not supported, the RGBA form should be used.\n

\nA p5 Color object can also be provided to set the fill color.

\n', + itemtype: 'method', + name: 'fill', + chainable: 1, + example: [ + "\n
\n\n// Grayscale integer value\nfill(51);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// R, G & B integer values\nfill(255, 204, 0);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// H, S & B integer values\ncolorMode(HSB);\nfill(255, 204, 100);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// Named SVG/CSS color string\nfill('red');\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// three-digit hexadecimal RGB notation\nfill('#fae');\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// six-digit hexadecimal RGB notation\nfill('#222222');\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// integer RGB notation\nfill('rgb(0,255,0)');\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// integer RGBA notation\nfill('rgba(0,255,0, 0.25)');\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// percentage RGB notation\nfill('rgb(100%,0%,10%)');\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// percentage RGBA notation\nfill('rgba(100%,0%,100%,0.5)');\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// p5 Color object\nfill(color(0, 0, 255));\nrect(20, 20, 60, 60);\n\n
" + ], + alt: + '60x60 dark charcoal grey rect with black outline in center of canvas.\n60x60 yellow rect with black outline in center of canvas.\n60x60 royal blue rect with black outline in center of canvas.\n60x60 red rect with black outline in center of canvas.\n60x60 pink rect with black outline in center of canvas.\n60x60 black rect with black outline in center of canvas.\n60x60 light green rect with black outline in center of canvas.\n60x60 soft green rect with black outline in center of canvas.\n60x60 red rect with black outline in center of canvas.\n60x60 dark fuchsia rect with black outline in center of canvas.\n60x60 blue rect with black outline in center of canvas.', + class: 'p5', + module: 'Color', + submodule: 'Setting', + overloads: [ + { + line: 341, + params: [ + { + name: 'v1', + description: + '

red or hue value relative to\n the current color range

\n', + type: 'Number' + }, + { + name: 'v2', + description: + '

green or saturation value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'v3', + description: + '

blue or brightness value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 466, + params: [ + { + name: 'value', + description: '

a color string

\n', + type: 'String' + } + ], + chainable: 1 + }, + { + line: 472, + params: [ + { + name: 'gray', + description: '

a gray value

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 479, + params: [ + { + name: 'values', + description: + '

an array containing the red,green,blue &\n and alpha components of the color

\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + line: 486, + params: [ + { + name: 'color', + description: '

the fill color

\n', + type: 'p5.Color' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/color/setting.js', + line: 498, + description: + '

Disables filling geometry. If both noStroke() and noFill() are called,\nnothing will be drawn to the screen.

\n', + itemtype: 'method', + name: 'noFill', + chainable: 1, + example: [ + "\n
\n\nrect(15, 10, 55, 55);\nnoFill();\nrect(20, 20, 60, 60);\n\n
\n\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(0);\n noFill();\n stroke(100, 100, 240);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n box(45, 45, 45);\n}\n\n
" + ], + alt: + 'white rect top middle and noFill rect center. Both 60x60 with black outlines.\nblack canvas with purple cube wireframe spinning', + class: 'p5', + module: 'Color', + submodule: 'Setting' + }, + { + file: 'src/color/setting.js', + line: 539, + description: + '

Disables drawing the stroke (outline). If both noStroke() and noFill()\nare called, nothing will be drawn to the screen.

\n', + itemtype: 'method', + name: 'noStroke', + chainable: 1, + example: [ + "\n
\n\nnoStroke();\nrect(20, 20, 60, 60);\n\n
\n\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(0);\n noStroke();\n fill(240, 150, 150);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n box(45, 45, 45);\n}\n\n
" + ], + alt: + '60x60 white rect at center. no outline.\nblack canvas with pink cube spinning', + class: 'p5', + module: 'Color', + submodule: 'Setting' + }, + { + file: 'src/color/setting.js', + line: 579, + description: + '

Sets the color used to draw lines and borders around shapes. This color\nis either specified in terms of the RGB or HSB color depending on the\ncurrent colorMode() (the default color space is RGB, with each value in\nthe range from 0 to 255). The alpha range by default is also 0 to 255.\n

\nIf a single string argument is provided, RGB, RGBA and Hex CSS color\nstrings and all named color strings are supported. In this case, an alpha\nnumber value as a second argument is not supported, the RGBA form should be\nused.\n

\nA p5 Color object can also be provided to set the stroke color.

\n', + itemtype: 'method', + name: 'stroke', + chainable: 1, + example: [ + "\n
\n\n// Grayscale integer value\nstrokeWeight(4);\nstroke(51);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// R, G & B integer values\nstroke(255, 204, 0);\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// H, S & B integer values\ncolorMode(HSB);\nstrokeWeight(4);\nstroke(255, 204, 100);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// Named SVG/CSS color string\nstroke('red');\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// three-digit hexadecimal RGB notation\nstroke('#fae');\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// six-digit hexadecimal RGB notation\nstroke('#222222');\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// integer RGB notation\nstroke('rgb(0,255,0)');\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// integer RGBA notation\nstroke('rgba(0,255,0,0.25)');\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// percentage RGB notation\nstroke('rgb(100%,0%,10%)');\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// percentage RGBA notation\nstroke('rgba(100%,0%,100%,0.5)');\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
\n\n
\n\n// p5 Color object\nstroke(color(0, 0, 255));\nstrokeWeight(4);\nrect(20, 20, 60, 60);\n\n
" + ], + alt: + '60x60 white rect at center. Dark charcoal grey outline.\n60x60 white rect at center. Yellow outline.\n60x60 white rect at center. Royal blue outline.\n60x60 white rect at center. Red outline.\n60x60 white rect at center. Pink outline.\n60x60 white rect at center. Black outline.\n60x60 white rect at center. Bright green outline.\n60x60 white rect at center. Soft green outline.\n60x60 white rect at center. Red outline.\n60x60 white rect at center. Dark fuchsia outline.\n60x60 white rect at center. Blue outline.', + class: 'p5', + module: 'Color', + submodule: 'Setting', + overloads: [ + { + line: 579, + params: [ + { + name: 'v1', + description: + '

red or hue value relative to\n the current color range

\n', + type: 'Number' + }, + { + name: 'v2', + description: + '

green or saturation value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'v3', + description: + '

blue or brightness value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 718, + params: [ + { + name: 'value', + description: '

a color string

\n', + type: 'String' + } + ], + chainable: 1 + }, + { + line: 724, + params: [ + { + name: 'gray', + description: '

a gray value

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 731, + params: [ + { + name: 'values', + description: + '

an array containing the red,green,blue &\n and alpha components of the color

\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + line: 738, + params: [ + { + name: 'color', + description: '

the stroke color

\n', + type: 'p5.Color' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 16, + description: + '

This function does 3 things:

\n
    \n
  1. Bounds the desired start/stop angles for an arc (in radians) so that:

    \n
    0 <= start < TWO_PI ;    start <= stop < start + TWO_PI\n

    This means that the arc rendering functions don't have to be concerned\nwith what happens if stop is smaller than start, or if the arc 'goes\nround more than once', etc.: they can just start at start and increase\nuntil stop and the correct arc will be drawn.

    \n
  2. \n
  3. Optionally adjusts the angles within each quadrant to counter the naive\nscaling of the underlying ellipse up from the unit circle. Without\nthis, the angles become arbitrary when width != height: 45 degrees\nmight be drawn at 5 degrees on a 'wide' ellipse, or at 85 degrees on\na 'tall' ellipse.

    \n
  4. \n
  5. Flags up when start and stop correspond to the same place on the\nunderlying ellipse. This is useful if you want to do something special\nthere (like rendering a whole ellipse instead).

    \n
  6. \n
\n', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives' + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 102, + description: + '

Draw an arc to the screen. If called with only x, y, w, h, start, and\nstop, the arc will be drawn and filled as an open pie segment. If a mode parameter is provided, the arc\nwill be filled like an open semi-circle (OPEN) , a closed semi-circle (CHORD), or as a closed pie segment (PIE). The\norigin may be changed with the ellipseMode() function.

\nThe arc is always drawn clockwise from wherever start falls to wherever stop falls on the ellipse.\nAdding or subtracting TWO_PI to either angle does not change where they fall.\nIf both start and stop fall at the same place, a full ellipse will be drawn. Be aware that the the\ny-axis increases in the downward direction therefore the values of PI is counter clockwise.

\n', + itemtype: 'method', + name: 'arc', + params: [ + { + name: 'x', + description: '

x-coordinate of the arc's ellipse

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the arc's ellipse

\n', + type: 'Number' + }, + { + name: 'w', + description: '

width of the arc's ellipse by default

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height of the arc's ellipse by default

\n', + type: 'Number' + }, + { + name: 'start', + description: '

angle to start the arc, specified in radians

\n', + type: 'Number' + }, + { + name: 'stop', + description: '

angle to stop the arc, specified in radians

\n', + type: 'Number' + }, + { + name: 'mode', + description: + '

optional parameter to determine the way of drawing\n the arc. either CHORD, PIE or OPEN

\n', + type: 'Constant', + optional: true + }, + { + name: 'detail', + description: + '

optional parameter for WebGL mode only. This is to\n specify the number of vertices that makes up the\n perimeter of the arc. Default value is 25.

\n', + type: 'Number', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\narc(50, 55, 50, 50, 0, HALF_PI);\nnoFill();\narc(50, 55, 60, 60, HALF_PI, PI);\narc(50, 55, 70, 70, PI, PI + QUARTER_PI);\narc(50, 55, 80, 80, PI + QUARTER_PI, TWO_PI);\n\n
\n\n
\n\narc(50, 50, 80, 80, 0, PI + QUARTER_PI);\n\n
\n\n
\n\narc(50, 50, 80, 80, 0, PI + QUARTER_PI, OPEN);\n\n
\n\n
\n\narc(50, 50, 80, 80, 0, PI + QUARTER_PI, CHORD);\n\n
\n\n
\n\narc(50, 50, 80, 80, 0, PI + QUARTER_PI, PIE);\n\n
' + ], + alt: + 'shattered outline of an ellipse with a quarter of a white circle bottom-right.\nwhite ellipse with top right quarter missing.\nwhite ellipse with black outline with top right missing.\nwhite ellipse with top right missing with black outline around shape.\nwhite ellipse with top right quarter missing with black outline around the shape.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives' + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 210, + description: + '

Draws an ellipse (oval) to the screen. An ellipse with equal width and\nheight is a circle. By default, the first two parameters set the location,\nand the third and fourth parameters set the shape's width and height. If\nno height is specified, the value of width is used for both the width and\nheight. If a negative height or width is specified, the absolute value is taken.\nThe origin may be changed with the ellipseMode() function.

\n', + itemtype: 'method', + name: 'ellipse', + chainable: 1, + example: ['\n
\n\nellipse(56, 46, 55, 55);\n\n
'], + alt: + 'white ellipse with black outline in middle-right of canvas that is 55x55.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives', + overloads: [ + { + line: 210, + params: [ + { + name: 'x', + description: '

x-coordinate of the ellipse.

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the ellipse.

\n', + type: 'Number' + }, + { + name: 'w', + description: '

width of the ellipse.

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height of the ellipse.

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 235, + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'w', + description: '', + type: 'Number' + }, + { + name: 'h', + description: '', + type: 'Number' + }, + { + name: 'detail', + description: + '

number of radial sectors to draw (for WebGL mode)

\n', + type: 'Integer' + } + ] + } + ] + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 270, + description: + '

Draws a circle to the screen. A circle is a simple closed shape.\nIt is the set of all points in a plane that are at a given distance from a given point, the centre.\nThis function is a special case of the ellipse() function, where the width and height of the ellipse are the same.\nHeight and width of the ellipse correspond to the diameter of the circle.\nBy default, the first two parameters set the location of the centre of the circle, the third sets the diameter of the circle.

\n', + itemtype: 'method', + name: 'circle', + params: [ + { + name: 'x', + description: '

x-coordinate of the centre of the circle.

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the centre of the circle.

\n', + type: 'Number' + }, + { + name: 'd', + description: '

diameter of the circle.

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + '\n
\n\n// Draw a circle at location (30, 30) with a diameter of 20.\ncircle(30, 30, 20);\n\n
' + ], + alt: 'white circle with black outline in mid of canvas that is 55x55.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives' + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 300, + description: + '

Draws a line (a direct path between two points) to the screen. The version\nof line() with four parameters draws the line in 2D. To color a line, use\nthe stroke() function. A line cannot be filled, therefore the fill()\nfunction will not affect the color of a line. 2D lines are drawn with a\nwidth of one pixel by default, but this can be changed with the\nstrokeWeight() function.

\n', + itemtype: 'method', + name: 'line', + chainable: 1, + example: [ + '\n
\n\nline(30, 20, 85, 75);\n\n
\n\n
\n\nline(30, 20, 85, 20);\nstroke(126);\nline(85, 20, 85, 75);\nstroke(255);\nline(85, 75, 30, 75);\n\n
' + ], + alt: + 'line 78 pixels long running from mid-top to bottom-right of canvas.\n3 lines of various stroke sizes. Form top, bottom and right sides of a square.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives', + overloads: [ + { + line: 300, + params: [ + { + name: 'x1', + description: '

the x-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'y1', + description: '

the y-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '

the x-coordinate of the second point

\n', + type: 'Number' + }, + { + name: 'y2', + description: '

the y-coordinate of the second point

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 336, + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: '

the z-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: '

the z-coordinate of the second point

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 356, + description: + '

Draws a point, a coordinate in space at the dimension of one pixel.\nThe first parameter is the horizontal value for the point, the second\nvalue is the vertical value for the point. The color of the point is\ndetermined by the current stroke.

\n', + itemtype: 'method', + name: 'point', + params: [ + { + name: 'x', + description: '

the x-coordinate

\n', + type: 'Number' + }, + { + name: 'y', + description: '

the y-coordinate

\n', + type: 'Number' + }, + { + name: 'z', + description: '

the z-coordinate (for WebGL mode)

\n', + type: 'Number', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\npoint(30, 20);\npoint(85, 20);\npoint(85, 75);\npoint(30, 75);\n\n
' + ], + alt: '4 points centered in the middle-right of the canvas.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives' + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 391, + description: + '

Draw a quad. A quad is a quadrilateral, a four sided polygon. It is\nsimilar to a rectangle, but the angles between its edges are not\nconstrained to ninety degrees. The first pair of parameters (x1,y1)\nsets the first vertex and the subsequent pairs should proceed\nclockwise or counter-clockwise around the defined shape.\nz-arguments only work when quad() is used in WEBGL mode.

\n', + itemtype: 'method', + name: 'quad', + chainable: 1, + example: [ + '\n
\n\nquad(38, 31, 86, 20, 69, 63, 30, 76);\n\n
' + ], + alt: + 'irregular white quadrilateral shape with black outline mid-right of canvas.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives', + overloads: [ + { + line: 391, + params: [ + { + name: 'x1', + description: '

the x-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'y1', + description: '

the y-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '

the x-coordinate of the second point

\n', + type: 'Number' + }, + { + name: 'y2', + description: '

the y-coordinate of the second point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '

the x-coordinate of the third point

\n', + type: 'Number' + }, + { + name: 'y3', + description: '

the y-coordinate of the third point

\n', + type: 'Number' + }, + { + name: 'x4', + description: '

the x-coordinate of the fourth point

\n', + type: 'Number' + }, + { + name: 'y4', + description: '

the y-coordinate of the fourth point

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 421, + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: '

the z-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: '

the z-coordinate of the second point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: '

the z-coordinate of the third point

\n', + type: 'Number' + }, + { + name: 'x4', + description: '', + type: 'Number' + }, + { + name: 'y4', + description: '', + type: 'Number' + }, + { + name: 'z4', + description: '

the z-coordinate of the fourth point

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 458, + description: + '

Draws a rectangle to the screen. A rectangle is a four-sided shape with\nevery angle at ninety degrees. By default, the first two parameters set\nthe location of the upper-left corner, the third sets the width, and the\nfourth sets the height. The way these parameters are interpreted, however,\nmay be changed with the rectMode() function.\n

\nThe fifth, sixth, seventh and eighth parameters, if specified,\ndetermine corner radius for the top-left, top-right, lower-right and\nlower-left corners, respectively. An omitted corner radius parameter is set\nto the value of the previously specified radius value in the parameter list.

\n', + itemtype: 'method', + name: 'rect', + chainable: 1, + example: [ + '\n
\n\n// Draw a rectangle at location (30, 20) with a width and height of 55.\nrect(30, 20, 55, 55);\n\n
\n\n
\n\n// Draw a rectangle with rounded corners, each having a radius of 20.\nrect(30, 20, 55, 55, 20);\n\n
\n\n
\n\n// Draw a rectangle with rounded corners having the following radii:\n// top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5.\nrect(30, 20, 55, 55, 20, 15, 10, 5);\n\n
' + ], + alt: + '55x55 white rect with black outline in mid-right of canvas.\n55x55 white rect with black outline and rounded edges in mid-right of canvas.\n55x55 white rect with black outline and rounded edges of different radii.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives', + overloads: [ + { + line: 458, + params: [ + { + name: 'x', + description: '

x-coordinate of the rectangle.

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the rectangle.

\n', + type: 'Number' + }, + { + name: 'w', + description: '

width of the rectangle.

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height of the rectangle.

\n', + type: 'Number' + }, + { + name: 'tl', + description: '

optional radius of top-left corner.

\n', + type: 'Number', + optional: true + }, + { + name: 'tr', + description: '

optional radius of top-right corner.

\n', + type: 'Number', + optional: true + }, + { + name: 'br', + description: '

optional radius of bottom-right corner.

\n', + type: 'Number', + optional: true + }, + { + name: 'bl', + description: '

optional radius of bottom-left corner.

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 508, + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'w', + description: '', + type: 'Number' + }, + { + name: 'h', + description: '', + type: 'Number' + }, + { + name: 'detailX', + description: + '

number of segments in the x-direction (for WebGL mode)

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + '

number of segments in the y-direction (for WebGL mode)

\n', + type: 'Integer', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 541, + description: + '

Draws a square to the screen. A square is a four-sided shape with\nevery angle at ninety degrees, and equal side size.\nThis function is a special case of the rect() function, where the width and height are the same, and the parameter is called "s" for side size.\nBy default, the first two parameters set the location of the upper-left corner, the third sets the side size of the square.\nThe way these parameters are interpreted, however,\nmay be changed with the rectMode() function.\n

\nThe fourth, fifth, sixth and seventh parameters, if specified,\ndetermine corner radius for the top-left, top-right, lower-right and\nlower-left corners, respectively. An omitted corner radius parameter is set\nto the value of the previously specified radius value in the parameter list.

\n', + itemtype: 'method', + name: 'square', + params: [ + { + name: 'x', + description: '

x-coordinate of the square.

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the square.

\n', + type: 'Number' + }, + { + name: 's', + description: '

side size of the square.

\n', + type: 'Number' + }, + { + name: 'tl', + description: '

optional radius of top-left corner.

\n', + type: 'Number', + optional: true + }, + { + name: 'tr', + description: '

optional radius of top-right corner.

\n', + type: 'Number', + optional: true + }, + { + name: 'br', + description: '

optional radius of bottom-right corner.

\n', + type: 'Number', + optional: true + }, + { + name: 'bl', + description: '

optional radius of bottom-left corner.

\n', + type: 'Number', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\n// Draw a square at location (30, 20) with a side size of 55.\nsquare(30, 20, 55);\n\n
\n\n
\n\n// Draw a square with rounded corners, each having a radius of 20.\nsquare(30, 20, 55, 20);\n\n
\n\n
\n\n// Draw a square with rounded corners having the following radii:\n// top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5.\nsquare(30, 20, 55, 20, 15, 10, 5);\n\n
' + ], + alt: + '55x55 white square with black outline in mid-right of canvas.\n55x55 white square with black outline and rounded edges in mid-right of canvas.\n55x55 white square with black outline and rounded edges of different radii.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives' + }, + { + file: 'src/core/shape/2d_primitives.js', + line: 595, + description: + '

A triangle is a plane created by connecting three points. The first two\narguments specify the first point, the middle two arguments specify the\nsecond point, and the last two arguments specify the third point.

\n', + itemtype: 'method', + name: 'triangle', + params: [ + { + name: 'x1', + description: '

x-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'y1', + description: '

y-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '

x-coordinate of the second point

\n', + type: 'Number' + }, + { + name: 'y2', + description: '

y-coordinate of the second point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '

x-coordinate of the third point

\n', + type: 'Number' + }, + { + name: 'y3', + description: '

y-coordinate of the third point

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + '\n
\n\ntriangle(30, 75, 58, 20, 86, 75);\n\n
' + ], + alt: 'white triangle with black outline in mid-right of canvas.', + class: 'p5', + module: 'Shape', + submodule: '2D Primitives' + }, + { + file: 'src/core/shape/attributes.js', + line: 14, + description: + '

Modifies the location from which ellipses are drawn by changing the way\nin which parameters given to ellipse() are interpreted.\n

\nThe default mode is ellipseMode(CENTER), which interprets the first two\nparameters of ellipse() as the shape's center point, while the third and\nfourth parameters are its width and height.\n

\nellipseMode(RADIUS) also uses the first two parameters of ellipse() as\nthe shape's center point, but uses the third and fourth parameters to\nspecify half of the shapes's width and height.\n

\nellipseMode(CORNER) interprets the first two parameters of ellipse() as\nthe upper-left corner of the shape, while the third and fourth parameters\nare its width and height.\n

\nellipseMode(CORNERS) interprets the first two parameters of ellipse() as\nthe location of one corner of the ellipse's bounding box, and the third\nand fourth parameters as the location of the opposite corner.\n

\nThe parameter must be written in ALL CAPS because Javascript is a\ncase-sensitive language.

\n', + itemtype: 'method', + name: 'ellipseMode', + params: [ + { + name: 'mode', + description: '

either CENTER, RADIUS, CORNER, or CORNERS

\n', + type: 'Constant' + } + ], + chainable: 1, + example: [ + '\n
\n\nellipseMode(RADIUS); // Set ellipseMode to RADIUS\nfill(255); // Set fill to white\nellipse(50, 50, 30, 30); // Draw white ellipse using RADIUS mode\n\nellipseMode(CENTER); // Set ellipseMode to CENTER\nfill(100); // Set fill to gray\nellipse(50, 50, 30, 30); // Draw gray ellipse using CENTER mode\n\n
\n\n
\n\nellipseMode(CORNER); // Set ellipseMode is CORNER\nfill(255); // Set fill to white\nellipse(25, 25, 50, 50); // Draw white ellipse using CORNER mode\n\nellipseMode(CORNERS); // Set ellipseMode to CORNERS\nfill(100); // Set fill to gray\nellipse(25, 25, 50, 50); // Draw gray ellipse using CORNERS mode\n\n
' + ], + alt: + '60x60 white ellipse and 30x30 grey ellipse with black outlines at center.\n60x60 white ellipse @center and 30x30 grey ellipse top-right, black outlines.', + class: 'p5', + module: 'Shape', + submodule: 'Attributes' + }, + { + file: 'src/core/shape/attributes.js', + line: 83, + description: + '

Draws all geometry with jagged (aliased) edges. Note that smooth() is\nactive by default in 2D mode, so it is necessary to call noSmooth() to disable\nsmoothing of geometry, images, and fonts. In 3D mode, noSmooth() is enabled\nby default, so it is necessary to call smooth() if you would like\nsmooth (antialiased) edges on your geometry.

\n', + itemtype: 'method', + name: 'noSmooth', + chainable: 1, + example: [ + '\n
\n\nbackground(0);\nnoStroke();\nsmooth();\nellipse(30, 48, 36, 36);\nnoSmooth();\nellipse(70, 48, 36, 36);\n\n
' + ], + alt: + '2 pixelated 36x36 white ellipses to left & right of center, black background', + class: 'p5', + module: 'Shape', + submodule: 'Attributes' + }, + { + file: 'src/core/shape/attributes.js', + line: 116, + description: + '

Modifies the location from which rectangles are drawn by changing the way\nin which parameters given to rect() are interpreted.\n

\nThe default mode is rectMode(CORNER), which interprets the first two\nparameters of rect() as the upper-left corner of the shape, while the\nthird and fourth parameters are its width and height.\n

\nrectMode(CORNERS) interprets the first two parameters of rect() as the\nlocation of one corner, and the third and fourth parameters as the\nlocation of the opposite corner.\n

\nrectMode(CENTER) interprets the first two parameters of rect() as the\nshape's center point, while the third and fourth parameters are its\nwidth and height.\n

\nrectMode(RADIUS) also uses the first two parameters of rect() as the\nshape's center point, but uses the third and fourth parameters to specify\nhalf of the shapes's width and height.\n

\nThe parameter must be written in ALL CAPS because Javascript is a\ncase-sensitive language.

\n', + itemtype: 'method', + name: 'rectMode', + params: [ + { + name: 'mode', + description: '

either CORNER, CORNERS, CENTER, or RADIUS

\n', + type: 'Constant' + } + ], + chainable: 1, + example: [ + '\n
\n\nrectMode(CORNER); // Default rectMode is CORNER\nfill(255); // Set fill to white\nrect(25, 25, 50, 50); // Draw white rect using CORNER mode\n\nrectMode(CORNERS); // Set rectMode to CORNERS\nfill(100); // Set fill to gray\nrect(25, 25, 50, 50); // Draw gray rect using CORNERS mode\n\n
\n\n
\n\nrectMode(RADIUS); // Set rectMode to RADIUS\nfill(255); // Set fill to white\nrect(50, 50, 30, 30); // Draw white rect using RADIUS mode\n\nrectMode(CENTER); // Set rectMode to CENTER\nfill(100); // Set fill to gray\nrect(50, 50, 30, 30); // Draw gray rect using CENTER mode\n\n
' + ], + alt: + '50x50 white rect at center and 25x25 grey rect in the top left of the other.\n50x50 white rect at center and 25x25 grey rect in the center of the other.', + class: 'p5', + module: 'Shape', + submodule: 'Attributes' + }, + { + file: 'src/core/shape/attributes.js', + line: 185, + description: + '

Draws all geometry with smooth (anti-aliased) edges. smooth() will also\nimprove image quality of resized images. Note that smooth() is active by\ndefault in 2D mode; noSmooth() can be used to disable smoothing of geometry,\nimages, and fonts. In 3D mode, noSmooth() is enabled\nby default, so it is necessary to call smooth() if you would like\nsmooth (antialiased) edges on your geometry.

\n', + itemtype: 'method', + name: 'smooth', + chainable: 1, + example: [ + '\n
\n\nbackground(0);\nnoStroke();\nsmooth();\nellipse(30, 48, 36, 36);\nnoSmooth();\nellipse(70, 48, 36, 36);\n\n
' + ], + alt: + '2 pixelated 36x36 white ellipses one left one right of center. On black.', + class: 'p5', + module: 'Shape', + submodule: 'Attributes' + }, + { + file: 'src/core/shape/attributes.js', + line: 219, + description: + '

Sets the style for rendering line endings. These ends are either squared,\nextended, or rounded, each of which specified with the corresponding\nparameters: SQUARE, PROJECT, and ROUND. The default cap is ROUND.

\n', + itemtype: 'method', + name: 'strokeCap', + params: [ + { + name: 'cap', + description: '

either SQUARE, PROJECT, or ROUND

\n', + type: 'Constant' + } + ], + chainable: 1, + example: [ + '\n
\n\nstrokeWeight(12.0);\nstrokeCap(ROUND);\nline(20, 30, 80, 30);\nstrokeCap(SQUARE);\nline(20, 50, 80, 50);\nstrokeCap(PROJECT);\nline(20, 70, 80, 70);\n\n
' + ], + alt: + '3 lines. Top line: rounded ends, mid: squared, bottom:longer squared ends.', + class: 'p5', + module: 'Shape', + submodule: 'Attributes' + }, + { + file: 'src/core/shape/attributes.js', + line: 256, + description: + '

Sets the style of the joints which connect line segments. These joints\nare either mitered, beveled, or rounded and specified with the\ncorresponding parameters MITER, BEVEL, and ROUND. The default joint is\nMITER.

\n', + itemtype: 'method', + name: 'strokeJoin', + params: [ + { + name: 'join', + description: '

either MITER, BEVEL, ROUND

\n', + type: 'Constant' + } + ], + chainable: 1, + example: [ + '\n
\n\nnoFill();\nstrokeWeight(10.0);\nstrokeJoin(MITER);\nbeginShape();\nvertex(35, 20);\nvertex(65, 50);\nvertex(35, 80);\nendShape();\n\n
\n\n
\n\nnoFill();\nstrokeWeight(10.0);\nstrokeJoin(BEVEL);\nbeginShape();\nvertex(35, 20);\nvertex(65, 50);\nvertex(35, 80);\nendShape();\n\n
\n\n
\n\nnoFill();\nstrokeWeight(10.0);\nstrokeJoin(ROUND);\nbeginShape();\nvertex(35, 20);\nvertex(65, 50);\nvertex(35, 80);\nendShape();\n\n
' + ], + alt: + 'Right-facing arrowhead shape with pointed tip in center of canvas.\nRight-facing arrowhead shape with flat tip in center of canvas.\nRight-facing arrowhead shape with rounded tip in center of canvas.', + class: 'p5', + module: 'Shape', + submodule: 'Attributes' + }, + { + file: 'src/core/shape/attributes.js', + line: 323, + description: + '

Sets the width of the stroke used for lines, points, and the border\naround shapes. All widths are set in units of pixels.

\n', + itemtype: 'method', + name: 'strokeWeight', + params: [ + { + name: 'weight', + description: '

the weight (in pixels) of the stroke

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + '\n
\n\nstrokeWeight(1); // Default\nline(20, 20, 80, 20);\nstrokeWeight(4); // Thicker\nline(20, 40, 80, 40);\nstrokeWeight(10); // Beastly\nline(20, 70, 80, 70);\n\n
' + ], + alt: '3 horizontal black lines. Top line: thin, mid: medium, bottom:thick.', + class: 'p5', + module: 'Shape', + submodule: 'Attributes' + }, + { + file: 'src/core/shape/curves.js', + line: 13, + description: + '

Draws a cubic Bezier curve on the screen. These curves are defined by a\nseries of anchor and control points. The first two parameters specify\nthe first anchor point and the last two parameters specify the other\nanchor point, which become the first and last points on the curve. The\nmiddle parameters specify the two control points which define the shape\nof the curve. Approximately speaking, control points "pull" the curve\ntowards them.

Bezier curves were developed by French\nautomotive engineer Pierre Bezier, and are commonly used in computer\ngraphics to define gently sloping curves. See also curve().

\n', + itemtype: 'method', + name: 'bezier', + chainable: 1, + example: [ + '\n
\n\nnoFill();\nstroke(255, 102, 0);\nline(85, 20, 10, 10);\nline(90, 90, 15, 80);\nstroke(0, 0, 0);\nbezier(85, 20, 10, 10, 90, 90, 15, 80);\n\n
\n\n
\n\nbackground(0, 0, 0);\nnoFill();\nstroke(255);\nbezier(250, 250, 0, 100, 100, 0, 100, 0, 0, 0, 100, 0);\n\n
' + ], + alt: + 'stretched black s-shape in center with orange lines extending from end points.\nstretched black s-shape with 10 5x5 white ellipses along the shape.\nstretched black s-shape with 7 5x5 ellipses and orange lines along the shape.\nstretched black s-shape with 17 small orange lines extending from under shape.\nhorseshoe shape with orange ends facing left and black curved center.\nhorseshoe shape with orange ends facing left and black curved center.\nLine shaped like right-facing arrow,points move with mouse-x and warp shape.\nhorizontal line that hooks downward on the right and 13 5x5 ellipses along it.\nright curving line mid-right of canvas with 7 short lines radiating from it.', + class: 'p5', + module: 'Shape', + submodule: 'Curves', + overloads: [ + { + line: 13, + params: [ + { + name: 'x1', + description: '

x-coordinate for the first anchor point

\n', + type: 'Number' + }, + { + name: 'y1', + description: '

y-coordinate for the first anchor point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '

x-coordinate for the first control point

\n', + type: 'Number' + }, + { + name: 'y2', + description: '

y-coordinate for the first control point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '

x-coordinate for the second control point

\n', + type: 'Number' + }, + { + name: 'y3', + description: '

y-coordinate for the second control point

\n', + type: 'Number' + }, + { + name: 'x4', + description: '

x-coordinate for the second anchor point

\n', + type: 'Number' + }, + { + name: 'y4', + description: '

y-coordinate for the second anchor point

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 66, + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: '

z-coordinate for the first anchor point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: '

z-coordinate for the first control point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: '

z-coordinate for the second control point

\n', + type: 'Number' + }, + { + name: 'x4', + description: '', + type: 'Number' + }, + { + name: 'y4', + description: '', + type: 'Number' + }, + { + name: 'z4', + description: '

z-coordinate for the second anchor point

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/curves.js', + line: 96, + description: + '

Sets the resolution at which Beziers display.

\n

The default value is 20.

\n

This function is only useful when using the WEBGL renderer\nas the default canvas renderer does not use this information.

\n', + itemtype: 'method', + name: 'bezierDetail', + params: [ + { + name: 'detail', + description: '

resolution of the curves

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n noFill();\n\n bezierDetail(5);\n}\n\nfunction draw() {\n background(200);\n\n bezier(-40, -40, 0,\n 90, -40, 0,\n -90, 40, 0,\n 40, 40, 0);\n}\n\n
" + ], + alt: 'stretched black s-shape with a low level of bezier detail', + class: 'p5', + module: 'Shape', + submodule: 'Curves' + }, + { + file: 'src/core/shape/curves.js', + line: 139, + description: + '

Evaluates the Bezier at position t for points a, b, c, d.\nThe parameters a and d are the first and last points\non the curve, and b and c are the control points.\nThe final parameter t varies between 0 and 1.\nThis can be done once with the x coordinates and a second time\nwith the y coordinates to get the location of a bezier curve at t.

\n', + itemtype: 'method', + name: 'bezierPoint', + params: [ + { + name: 'a', + description: '

coordinate of first point on the curve

\n', + type: 'Number' + }, + { + name: 'b', + description: '

coordinate of first control point

\n', + type: 'Number' + }, + { + name: 'c', + description: '

coordinate of second control point

\n', + type: 'Number' + }, + { + name: 'd', + description: '

coordinate of second point on the curve

\n', + type: 'Number' + }, + { + name: 't', + description: '

value between 0 and 1

\n', + type: 'Number' + } + ], + return: { + description: 'the value of the Bezier at position t', + type: 'Number' + }, + example: [ + '\n
\n\nnoFill();\nlet x1 = 85,\n x2 = 10,\n x3 = 90,\n x4 = 15;\nlet y1 = 20,\n y2 = 10,\n y3 = 90,\n y4 = 80;\nbezier(x1, y1, x2, y2, x3, y3, x4, y4);\nfill(255);\nlet steps = 10;\nfor (let i = 0; i <= steps; i++) {\n let t = i / steps;\n let x = bezierPoint(x1, x2, x3, x4, t);\n let y = bezierPoint(y1, y2, y3, y4, t);\n ellipse(x, y, 5, 5);\n}\n\n
' + ], + alt: + 'stretched black s-shape with 17 small orange lines extending from under shape.', + class: 'p5', + module: 'Shape', + submodule: 'Curves' + }, + { + file: 'src/core/shape/curves.js', + line: 194, + description: + '

Evaluates the tangent to the Bezier at position t for points a, b, c, d.\nThe parameters a and d are the first and last points\non the curve, and b and c are the control points.\nThe final parameter t varies between 0 and 1.

\n', + itemtype: 'method', + name: 'bezierTangent', + params: [ + { + name: 'a', + description: '

coordinate of first point on the curve

\n', + type: 'Number' + }, + { + name: 'b', + description: '

coordinate of first control point

\n', + type: 'Number' + }, + { + name: 'c', + description: '

coordinate of second control point

\n', + type: 'Number' + }, + { + name: 'd', + description: '

coordinate of second point on the curve

\n', + type: 'Number' + }, + { + name: 't', + description: '

value between 0 and 1

\n', + type: 'Number' + } + ], + return: { + description: 'the tangent at position t', + type: 'Number' + }, + example: [ + '\n
\n\nnoFill();\nbezier(85, 20, 10, 10, 90, 90, 15, 80);\nlet steps = 6;\nfill(255);\nfor (let i = 0; i <= steps; i++) {\n let t = i / steps;\n // Get the location of the point\n let x = bezierPoint(85, 10, 90, 15, t);\n let y = bezierPoint(20, 10, 90, 80, t);\n // Get the tangent points\n let tx = bezierTangent(85, 10, 90, 15, t);\n let ty = bezierTangent(20, 10, 90, 80, t);\n // Calculate an angle from the tangent points\n let a = atan2(ty, tx);\n a += PI;\n stroke(255, 102, 0);\n line(x, y, cos(a) * 30 + x, sin(a) * 30 + y);\n // The following line of code makes a line\n // inverse of the above line\n //line(x, y, cos(a)*-30 + x, sin(a)*-30 + y);\n stroke(0);\n ellipse(x, y, 5, 5);\n}\n\n
\n\n
\n\nnoFill();\nbezier(85, 20, 10, 10, 90, 90, 15, 80);\nstroke(255, 102, 0);\nlet steps = 16;\nfor (let i = 0; i <= steps; i++) {\n let t = i / steps;\n let x = bezierPoint(85, 10, 90, 15, t);\n let y = bezierPoint(20, 10, 90, 80, t);\n let tx = bezierTangent(85, 10, 90, 15, t);\n let ty = bezierTangent(20, 10, 90, 80, t);\n let a = atan2(ty, tx);\n a -= HALF_PI;\n line(x, y, cos(a) * 8 + x, sin(a) * 8 + y);\n}\n\n
' + ], + alt: + 's-shaped line with 17 short orange lines extending from underside of shape', + class: 'p5', + module: 'Shape', + submodule: 'Curves' + }, + { + file: 'src/core/shape/curves.js', + line: 273, + description: + '

Draws a curved line on the screen between two points, given as the\nmiddle four parameters. The first two parameters are a control point, as\nif the curve came from this point even though it's not drawn. The last\ntwo parameters similarly describe the other control point.

\nLonger curves can be created by putting a series of curve() functions\ntogether or using curveVertex(). An additional function called\ncurveTightness() provides control for the visual quality of the curve.\nThe curve() function is an implementation of Catmull-Rom splines.

\n', + itemtype: 'method', + name: 'curve', + chainable: 1, + example: [ + '\n
\n\nnoFill();\nstroke(255, 102, 0);\ncurve(5, 26, 5, 26, 73, 24, 73, 61);\nstroke(0);\ncurve(5, 26, 73, 24, 73, 61, 15, 65);\nstroke(255, 102, 0);\ncurve(73, 24, 73, 61, 15, 65, 15, 65);\n\n
\n
\n\n// Define the curve points as JavaScript objects\nlet p1 = { x: 5, y: 26 },\n p2 = { x: 73, y: 24 };\nlet p3 = { x: 73, y: 61 },\n p4 = { x: 15, y: 65 };\nnoFill();\nstroke(255, 102, 0);\ncurve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);\nstroke(0);\ncurve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y);\nstroke(255, 102, 0);\ncurve(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, p4.x, p4.y);\n\n
\n
\n\nnoFill();\nstroke(255, 102, 0);\ncurve(5, 26, 0, 5, 26, 0, 73, 24, 0, 73, 61, 0);\nstroke(0);\ncurve(5, 26, 0, 73, 24, 0, 73, 61, 0, 15, 65, 0);\nstroke(255, 102, 0);\ncurve(73, 24, 0, 73, 61, 0, 15, 65, 0, 15, 65, 0);\n\n
' + ], + alt: + 'horseshoe shape with orange ends facing left and black curved center.\nhorseshoe shape with orange ends facing left and black curved center.\ncurving black and orange lines.', + class: 'p5', + module: 'Shape', + submodule: 'Curves', + overloads: [ + { + line: 273, + params: [ + { + name: 'x1', + description: + '

x-coordinate for the beginning control point

\n', + type: 'Number' + }, + { + name: 'y1', + description: + '

y-coordinate for the beginning control point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '

x-coordinate for the first point

\n', + type: 'Number' + }, + { + name: 'y2', + description: '

y-coordinate for the first point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '

x-coordinate for the second point

\n', + type: 'Number' + }, + { + name: 'y3', + description: '

y-coordinate for the second point

\n', + type: 'Number' + }, + { + name: 'x4', + description: '

x-coordinate for the ending control point

\n', + type: 'Number' + }, + { + name: 'y4', + description: '

y-coordinate for the ending control point

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 338, + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: + '

z-coordinate for the beginning control point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: '

z-coordinate for the first point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: '

z-coordinate for the second point

\n', + type: 'Number' + }, + { + name: 'x4', + description: '', + type: 'Number' + }, + { + name: 'y4', + description: '', + type: 'Number' + }, + { + name: 'z4', + description: '

z-coordinate for the ending control point

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/curves.js', + line: 364, + description: + '

Sets the resolution at which curves display.

\n

The default value is 20 while the minimum value is 3.

\n

This function is only useful when using the WEBGL renderer\nas the default canvas renderer does not use this\ninformation.

\n', + itemtype: 'method', + name: 'curveDetail', + params: [ + { + name: 'resolution', + description: '

resolution of the curves

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n\n curveDetail(5);\n}\nfunction draw() {\n background(200);\n\n curve(250, 600, 0, -30, 40, 0, 30, 30, 0, -250, 600, 0);\n}\n\n
" + ], + alt: 'white arch shape with a low level of curve detail.', + class: 'p5', + module: 'Shape', + submodule: 'Curves' + }, + { + file: 'src/core/shape/curves.js', + line: 406, + description: + '

Modifies the quality of forms created with curve() and curveVertex().\nThe parameter tightness determines how the curve fits to the vertex\npoints. The value 0.0 is the default value for tightness (this value\ndefines the curves to be Catmull-Rom splines) and the value 1.0 connects\nall the points with straight lines. Values within the range -5.0 and 5.0\nwill deform the curves but will leave them recognizable and as values\nincrease in magnitude, they will continue to deform.

\n', + itemtype: 'method', + name: 'curveTightness', + params: [ + { + name: 'amount', + description: + '

amount of deformation from the original vertices

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + '\n
\n\n// Move the mouse left and right to see the curve change\n\nfunction setup() {\n createCanvas(100, 100);\n noFill();\n}\n\nfunction draw() {\n background(204);\n let t = map(mouseX, 0, width, -5, 5);\n curveTightness(t);\n beginShape();\n curveVertex(10, 26);\n curveVertex(10, 26);\n curveVertex(83, 24);\n curveVertex(83, 61);\n curveVertex(25, 65);\n curveVertex(25, 65);\n endShape();\n}\n\n
' + ], + alt: + 'Line shaped like right-facing arrow,points move with mouse-x and warp shape.', + class: 'p5', + module: 'Shape', + submodule: 'Curves' + }, + { + file: 'src/core/shape/curves.js', + line: 453, + description: + '

Evaluates the curve at position t for points a, b, c, d.\nThe parameter t varies between 0 and 1, a and d are control points\nof the curve, and b and c are the start and end points of the curve.\nThis can be done once with the x coordinates and a second time\nwith the y coordinates to get the location of a curve at t.

\n', + itemtype: 'method', + name: 'curvePoint', + params: [ + { + name: 'a', + description: '

coordinate of first control point of the curve

\n', + type: 'Number' + }, + { + name: 'b', + description: '

coordinate of first point

\n', + type: 'Number' + }, + { + name: 'c', + description: '

coordinate of second point

\n', + type: 'Number' + }, + { + name: 'd', + description: '

coordinate of second control point

\n', + type: 'Number' + }, + { + name: 't', + description: '

value between 0 and 1

\n', + type: 'Number' + } + ], + return: { + description: 'bezier value at position t', + type: 'Number' + }, + example: [ + '\n
\n\nnoFill();\ncurve(5, 26, 5, 26, 73, 24, 73, 61);\ncurve(5, 26, 73, 24, 73, 61, 15, 65);\nfill(255);\nellipseMode(CENTER);\nlet steps = 6;\nfor (let i = 0; i <= steps; i++) {\n let t = i / steps;\n let x = curvePoint(5, 5, 73, 73, t);\n let y = curvePoint(26, 26, 24, 61, t);\n ellipse(x, y, 5, 5);\n x = curvePoint(5, 73, 73, 15, t);\n y = curvePoint(26, 24, 61, 65, t);\n ellipse(x, y, 5, 5);\n}\n\n
\n\nline hooking down to right-bottom with 13 5x5 white ellipse points' + ], + class: 'p5', + module: 'Shape', + submodule: 'Curves' + }, + { + file: 'src/core/shape/curves.js', + line: 502, + description: + '

Evaluates the tangent to the curve at position t for points a, b, c, d.\nThe parameter t varies between 0 and 1, a and d are points on the curve,\nand b and c are the control points.

\n', + itemtype: 'method', + name: 'curveTangent', + params: [ + { + name: 'a', + description: '

coordinate of first point on the curve

\n', + type: 'Number' + }, + { + name: 'b', + description: '

coordinate of first control point

\n', + type: 'Number' + }, + { + name: 'c', + description: '

coordinate of second control point

\n', + type: 'Number' + }, + { + name: 'd', + description: '

coordinate of second point on the curve

\n', + type: 'Number' + }, + { + name: 't', + description: '

value between 0 and 1

\n', + type: 'Number' + } + ], + return: { + description: 'the tangent at position t', + type: 'Number' + }, + example: [ + '\n
\n\nnoFill();\ncurve(5, 26, 73, 24, 73, 61, 15, 65);\nlet steps = 6;\nfor (let i = 0; i <= steps; i++) {\n let t = i / steps;\n let x = curvePoint(5, 73, 73, 15, t);\n let y = curvePoint(26, 24, 61, 65, t);\n //ellipse(x, y, 5, 5);\n let tx = curveTangent(5, 73, 73, 15, t);\n let ty = curveTangent(26, 24, 61, 65, t);\n let a = atan2(ty, tx);\n a -= PI / 2.0;\n line(x, y, cos(a) * 8 + x, sin(a) * 8 + y);\n}\n\n
' + ], + alt: + 'right curving line mid-right of canvas with 7 short lines radiating from it.', + class: 'p5', + module: 'Shape', + submodule: 'Curves' + }, + { + file: 'src/core/shape/vertex.js', + line: 22, + description: + '

Use the beginContour() and endContour() functions to create negative\nshapes within shapes such as the center of the letter 'O'. beginContour()\nbegins recording vertices for the shape and endContour() stops recording.\nThe vertices that define a negative shape must "wind" in the opposite\ndirection from the exterior shape. First draw vertices for the exterior\nclockwise order, then for internal shapes, draw vertices\nshape in counter-clockwise.\n

\nThese functions can only be used within a beginShape()/endShape() pair and\ntransformations such as translate(), rotate(), and scale() do not work\nwithin a beginContour()/endContour() pair. It is also not possible to use\nother shapes, such as ellipse() or rect() within.

\n', + itemtype: 'method', + name: 'beginContour', + chainable: 1, + example: [ + '\n
\n\ntranslate(50, 50);\nstroke(255, 0, 0);\nbeginShape();\n// Exterior part of shape, clockwise winding\nvertex(-40, -40);\nvertex(40, -40);\nvertex(40, 40);\nvertex(-40, 40);\n// Interior part of shape, counter-clockwise winding\nbeginContour();\nvertex(-20, -20);\nvertex(-20, 20);\nvertex(20, 20);\nvertex(20, -20);\nendContour();\nendShape(CLOSE);\n\n
' + ], + alt: + 'white rect and smaller grey rect with red outlines in center of canvas.', + class: 'p5', + module: 'Shape', + submodule: 'Vertex' + }, + { + file: 'src/core/shape/vertex.js', + line: 70, + description: + '

Using the beginShape() and endShape() functions allow creating more\ncomplex forms. beginShape() begins recording vertices for a shape and\nendShape() stops recording. The value of the kind parameter tells it which\ntypes of shapes to create from the provided vertices. With no mode\nspecified, the shape can be any irregular polygon.\n

\nThe parameters available for beginShape() are POINTS, LINES, TRIANGLES,\nTRIANGLE_FAN, TRIANGLE_STRIP, QUADS, and QUAD_STRIP. After calling the\nbeginShape() function, a series of vertex() commands must follow. To stop\ndrawing the shape, call endShape(). Each shape will be outlined with the\ncurrent stroke color and filled with the fill color.\n

\nTransformations such as translate(), rotate(), and scale() do not work\nwithin beginShape(). It is also not possible to use other shapes, such as\nellipse() or rect() within beginShape().

\n', + itemtype: 'method', + name: 'beginShape', + params: [ + { + name: 'kind', + description: + '

either POINTS, LINES, TRIANGLES, TRIANGLE_FAN\n TRIANGLE_STRIP, QUADS, or QUAD_STRIP

\n', + type: 'Constant', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\nbeginShape();\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape(CLOSE);\n\n
\n\n
\n\nbeginShape(POINTS);\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape();\n\n
\n\n
\n\nbeginShape(LINES);\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape();\n\n
\n\n
\n\nnoFill();\nbeginShape();\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape();\n\n
\n\n
\n\nnoFill();\nbeginShape();\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape(CLOSE);\n\n
\n\n
\n\nbeginShape(TRIANGLES);\nvertex(30, 75);\nvertex(40, 20);\nvertex(50, 75);\nvertex(60, 20);\nvertex(70, 75);\nvertex(80, 20);\nendShape();\n\n
\n\n
\n\nbeginShape(TRIANGLE_STRIP);\nvertex(30, 75);\nvertex(40, 20);\nvertex(50, 75);\nvertex(60, 20);\nvertex(70, 75);\nvertex(80, 20);\nvertex(90, 75);\nendShape();\n\n
\n\n
\n\nbeginShape(TRIANGLE_FAN);\nvertex(57.5, 50);\nvertex(57.5, 15);\nvertex(92, 50);\nvertex(57.5, 85);\nvertex(22, 50);\nvertex(57.5, 15);\nendShape();\n\n
\n\n
\n\nbeginShape(QUADS);\nvertex(30, 20);\nvertex(30, 75);\nvertex(50, 75);\nvertex(50, 20);\nvertex(65, 20);\nvertex(65, 75);\nvertex(85, 75);\nvertex(85, 20);\nendShape();\n\n
\n\n
\n\nbeginShape(QUAD_STRIP);\nvertex(30, 20);\nvertex(30, 75);\nvertex(50, 20);\nvertex(50, 75);\nvertex(65, 20);\nvertex(65, 75);\nvertex(85, 20);\nvertex(85, 75);\nendShape();\n\n
\n\n
\n\nbeginShape();\nvertex(20, 20);\nvertex(40, 20);\nvertex(40, 40);\nvertex(60, 40);\nvertex(60, 60);\nvertex(20, 60);\nendShape(CLOSE);\n\n
' + ], + alt: + 'white square-shape with black outline in middle-right of canvas.\n4 black points in a square shape in middle-right of canvas.\n2 horizontal black lines. In the top-right and bottom-right of canvas.\n3 line shape with horizontal on top, vertical in middle and horizontal bottom.\nsquare line shape in middle-right of canvas.\n2 white triangle shapes mid-right canvas. left one pointing up and right down.\n5 horizontal interlocking and alternating white triangles in mid-right canvas.\n4 interlocking white triangles in 45 degree rotated square-shape.\n2 white rectangle shapes in mid-right canvas. Both 20x55.\n3 side-by-side white rectangles center rect is smaller in mid-right canvas.\nThick white l-shape with black outline mid-top-left of canvas.', + class: 'p5', + module: 'Shape', + submodule: 'Vertex' + }, + { + file: 'src/core/shape/vertex.js', + line: 270, + description: + '

Specifies vertex coordinates for Bezier curves. Each call to\nbezierVertex() defines the position of two control points and\none anchor point of a Bezier curve, adding a new segment to a\nline or shape. For WebGL mode bezierVertex() can be used in 2D\nas well as 3D mode. 2D mode expects 6 parameters, while 3D mode\nexpects 9 parameters (including z coordinates).\n

\nThe first time bezierVertex() is used within a beginShape()\ncall, it must be prefaced with a call to vertex() to set the first anchor\npoint. This function must be used between beginShape() and endShape()\nand only when there is no MODE or POINTS parameter specified to\nbeginShape().

\n', + itemtype: 'method', + name: 'bezierVertex', + chainable: 1, + example: [ + '\n
\n\nnoFill();\nbeginShape();\nvertex(30, 20);\nbezierVertex(80, 0, 80, 75, 30, 75);\nendShape();\n\n
', + '\n
\n\nbeginShape();\nvertex(30, 20);\nbezierVertex(80, 0, 80, 75, 30, 75);\nbezierVertex(50, 80, 60, 25, 30, 20);\nendShape();\n\n
', + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n setAttributes('antialias', true);\n}\nfunction draw() {\n orbitControl();\n background(50);\n strokeWeight(4);\n stroke(255);\n point(-25, 30);\n point(25, 30);\n point(25, -30);\n point(-25, -30);\n\n strokeWeight(1);\n noFill();\n\n beginShape();\n vertex(-25, 30);\n bezierVertex(25, 30, 25, -30, -25, -30);\n endShape();\n\n beginShape();\n vertex(-25, 30, 20);\n bezierVertex(25, 30, 20, 25, -30, 20, -25, -30, 20);\n endShape();\n}\n\n
" + ], + alt: + 'crescent shape in middle of canvas with another crescent shape on positive z-axis.', + class: 'p5', + module: 'Shape', + submodule: 'Vertex', + overloads: [ + { + line: 270, + params: [ + { + name: 'x2', + description: '

x-coordinate for the first control point

\n', + type: 'Number' + }, + { + name: 'y2', + description: '

y-coordinate for the first control point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '

x-coordinate for the second control point

\n', + type: 'Number' + }, + { + name: 'y3', + description: '

y-coordinate for the second control point

\n', + type: 'Number' + }, + { + name: 'x4', + description: '

x-coordinate for the anchor point

\n', + type: 'Number' + }, + { + name: 'y4', + description: '

y-coordinate for the anchor point

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 358, + params: [ + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: + '

z-coordinate for the first control point (for WebGL mode)

\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: + '

z-coordinate for the second control point (for WebGL mode)

\n', + type: 'Number' + }, + { + name: 'x4', + description: '', + type: 'Number' + }, + { + name: 'y4', + description: '', + type: 'Number' + }, + { + name: 'z4', + description: + '

z-coordinate for the anchor point (for WebGL mode)

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/vertex.js', + line: 398, + description: + '

Specifies vertex coordinates for curves. This function may only\nbe used between beginShape() and endShape() and only when there\nis no MODE parameter specified to beginShape().\nFor WebGL mode curveVertex() can be used in 2D as well as 3D mode.\n2D mode expects 2 parameters, while 3D mode expects 3 parameters.\n

\nThe first and last points in a series of curveVertex() lines will be used to\nguide the beginning and end of a the curve. A minimum of four\npoints is required to draw a tiny curve between the second and\nthird points. Adding a fifth point with curveVertex() will draw\nthe curve between the second, third, and fourth points. The\ncurveVertex() function is an implementation of Catmull-Rom\nsplines.

\n', + itemtype: 'method', + name: 'curveVertex', + chainable: 1, + example: [ + '\n
\n\nstrokeWeight(5);\npoint(84, 91);\npoint(68, 19);\npoint(21, 17);\npoint(32, 91);\nstrokeWeight(1);\n\nnoFill();\nbeginShape();\ncurveVertex(84, 91);\ncurveVertex(84, 91);\ncurveVertex(68, 19);\ncurveVertex(21, 17);\ncurveVertex(32, 91);\ncurveVertex(32, 91);\nendShape();\n\n
' + ], + alt: + 'Upside-down u-shape line, mid canvas. left point extends beyond canvas view.', + class: 'p5', + module: 'Shape', + submodule: 'Vertex', + overloads: [ + { + line: 398, + params: [ + { + name: 'x', + description: '

x-coordinate of the vertex

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the vertex

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 443, + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '

z-coordinate of the vertex (for WebGL mode)

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/vertex.js', + line: 508, + description: + '

Use the beginContour() and endContour() functions to create negative\nshapes within shapes such as the center of the letter 'O'. beginContour()\nbegins recording vertices for the shape and endContour() stops recording.\nThe vertices that define a negative shape must "wind" in the opposite\ndirection from the exterior shape. First draw vertices for the exterior\nclockwise order, then for internal shapes, draw vertices\nshape in counter-clockwise.\n

\nThese functions can only be used within a beginShape()/endShape() pair and\ntransformations such as translate(), rotate(), and scale() do not work\nwithin a beginContour()/endContour() pair. It is also not possible to use\nother shapes, such as ellipse() or rect() within.

\n', + itemtype: 'method', + name: 'endContour', + chainable: 1, + example: [ + '\n
\n\ntranslate(50, 50);\nstroke(255, 0, 0);\nbeginShape();\n// Exterior part of shape, clockwise winding\nvertex(-40, -40);\nvertex(40, -40);\nvertex(40, 40);\nvertex(-40, 40);\n// Interior part of shape, counter-clockwise winding\nbeginContour();\nvertex(-20, -20);\nvertex(-20, 20);\nvertex(20, 20);\nvertex(20, -20);\nendContour();\nendShape(CLOSE);\n\n
' + ], + alt: + 'white rect and smaller grey rect with red outlines in center of canvas.', + class: 'p5', + module: 'Shape', + submodule: 'Vertex' + }, + { + file: 'src/core/shape/vertex.js', + line: 568, + description: + '

The endShape() function is the companion to beginShape() and may only be\ncalled after beginShape(). When endshape() is called, all of image data\ndefined since the previous call to beginShape() is written into the image\nbuffer. The constant CLOSE as the value for the MODE parameter to close\nthe shape (to connect the beginning and the end).

\n', + itemtype: 'method', + name: 'endShape', + params: [ + { + name: 'mode', + description: '

use CLOSE to close the shape

\n', + type: 'Constant', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\nnoFill();\n\nbeginShape();\nvertex(20, 20);\nvertex(45, 20);\nvertex(45, 80);\nendShape(CLOSE);\n\nbeginShape();\nvertex(50, 20);\nvertex(75, 20);\nvertex(75, 80);\nendShape();\n\n
' + ], + alt: + 'Triangle line shape with smallest interior angle on bottom and upside-down L.', + class: 'p5', + module: 'Shape', + submodule: 'Vertex' + }, + { + file: 'src/core/shape/vertex.js', + line: 654, + description: + '

Specifies vertex coordinates for quadratic Bezier curves. Each call to\nquadraticVertex() defines the position of one control points and one\nanchor point of a Bezier curve, adding a new segment to a line or shape.\nThe first time quadraticVertex() is used within a beginShape() call, it\nmust be prefaced with a call to vertex() to set the first anchor point.\nFor WebGL mode quadraticVertex() can be used in 2D as well as 3D mode.\n2D mode expects 4 parameters, while 3D mode expects 6 parameters\n(including z coordinates).\n

\nThis function must be used between beginShape() and endShape()\nand only when there is no MODE or POINTS parameter specified to\nbeginShape().

\n', + itemtype: 'method', + name: 'quadraticVertex', + chainable: 1, + example: [ + '\n
\n\nstrokeWeight(5);\npoint(20, 20);\npoint(80, 20);\npoint(50, 50);\n\nnoFill();\nstrokeWeight(1);\nbeginShape();\nvertex(20, 20);\nquadraticVertex(80, 20, 50, 50);\nendShape();\n\n
\n\n
\n\nstrokeWeight(5);\npoint(20, 20);\npoint(80, 20);\npoint(50, 50);\n\npoint(20, 80);\npoint(80, 80);\npoint(80, 60);\n\nnoFill();\nstrokeWeight(1);\nbeginShape();\nvertex(20, 20);\nquadraticVertex(80, 20, 50, 50);\nquadraticVertex(20, 80, 80, 80);\nvertex(80, 60);\nendShape();\n\n
' + ], + alt: + 'arched-shaped black line with 4 pixel thick stroke weight.\nbackwards s-shaped black line with 4 pixel thick stroke weight.', + class: 'p5', + module: 'Shape', + submodule: 'Vertex', + overloads: [ + { + line: 654, + params: [ + { + name: 'cx', + description: '

x-coordinate for the control point

\n', + type: 'Number' + }, + { + name: 'cy', + description: '

y-coordinate for the control point

\n', + type: 'Number' + }, + { + name: 'x3', + description: '

x-coordinate for the anchor point

\n', + type: 'Number' + }, + { + name: 'y3', + description: '

y-coordinate for the anchor point

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 720, + params: [ + { + name: 'cx', + description: '', + type: 'Number' + }, + { + name: 'cy', + description: '', + type: 'Number' + }, + { + name: 'cz', + description: + '

z-coordinate for the control point (for WebGL mode)

\n', + type: 'Number' + }, + { + name: 'x3', + description: '', + type: 'Number' + }, + { + name: 'y3', + description: '', + type: 'Number' + }, + { + name: 'z3', + description: + '

z-coordinate for the anchor point (for WebGL mode)

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/shape/vertex.js', + line: 813, + description: + '

All shapes are constructed by connecting a series of vertices. vertex()\nis used to specify the vertex coordinates for points, lines, triangles,\nquads, and polygons. It is used exclusively within the beginShape() and\nendShape() functions.

\n', + itemtype: 'method', + name: 'vertex', + chainable: 1, + example: [ + "\n
\n\nstrokeWeight(3);\nbeginShape(POINTS);\nvertex(30, 20);\nvertex(85, 20);\nvertex(85, 75);\nvertex(30, 75);\nendShape();\n\n
\n\n
\n\ncreateCanvas(100, 100, WEBGL);\nbackground(240, 240, 240);\nfill(237, 34, 93);\nnoStroke();\nbeginShape();\nvertex(0, 35);\nvertex(35, 0);\nvertex(0, -35);\nvertex(-35, 0);\nendShape();\n\n
\n\n
\n\ncreateCanvas(100, 100, WEBGL);\nbackground(240, 240, 240);\nfill(237, 34, 93);\nnoStroke();\nbeginShape();\nvertex(-10, 10);\nvertex(0, 35);\nvertex(10, 10);\nvertex(35, 0);\nvertex(10, -8);\nvertex(0, -35);\nvertex(-10, -8);\nvertex(-35, 0);\nendShape();\n\n
\n\n
\n\nstrokeWeight(3);\nstroke(237, 34, 93);\nbeginShape(LINES);\nvertex(10, 35);\nvertex(90, 35);\nvertex(10, 65);\nvertex(90, 65);\nvertex(35, 10);\nvertex(35, 90);\nvertex(65, 10);\nvertex(65, 90);\nendShape();\n\n
\n\n
\n\n// Click to change the number of sides.\n// In WebGL mode, custom shapes will only\n// display hollow fill sections when\n// all calls to vertex() use the same z-value.\n\nlet sides = 3;\nlet angle, px, py;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n setAttributes('antialias', true);\n fill(237, 34, 93);\n strokeWeight(3);\n}\n\nfunction draw() {\n background(200);\n rotateX(frameCount * 0.01);\n rotateZ(frameCount * 0.01);\n ngon(sides, 0, 0, 80);\n}\n\nfunction mouseClicked() {\n if (sides > 6) {\n sides = 3;\n } else {\n sides++;\n }\n}\n\nfunction ngon(n, x, y, d) {\n beginShape();\n for (var i = 0; i < n + 1; i++) {\n angle = TWO_PI / n * i;\n px = x + sin(angle) * d / 2;\n py = y - cos(angle) * d / 2;\n vertex(px, py, 0);\n }\n for (i = 0; i < n + 1; i++) {\n angle = TWO_PI / n * i;\n px = x + sin(angle) * d / 4;\n py = y - cos(angle) * d / 4;\n vertex(px, py, 0);\n }\n endShape();\n}\n\n
" + ], + alt: + '4 black points in a square shape in middle-right of canvas.\n4 points making a diamond shape.\n8 points making a star.\n8 points making 4 lines.\nA rotating 3D shape with a hollow section in the middle.', + class: 'p5', + module: 'Shape', + submodule: 'Vertex', + overloads: [ + { + line: 813, + params: [ + { + name: 'x', + description: '

x-coordinate of the vertex

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the vertex

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 945, + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '

z-coordinate of the vertex

\n', + type: 'Number' + }, + { + name: 'u', + description: '

the vertex's texture u-coordinate

\n', + type: 'Number', + optional: true + }, + { + name: 'v', + description: '

the vertex's texture v-coordinate

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/constants.js', + line: 13, + description: '

The default, two-dimensional renderer.

\n', + itemtype: 'property', + name: 'P2D', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 19, + description: + '

One of the two render modes in p5.js: P2D (default renderer) and WEBGL\nEnables 3D render by introducing the third dimension: Z

\n', + itemtype: 'property', + name: 'WEBGL', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 28, + itemtype: 'property', + name: 'ARROW', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 33, + itemtype: 'property', + name: 'CROSS', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 38, + itemtype: 'property', + name: 'HAND', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 43, + itemtype: 'property', + name: 'MOVE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 48, + itemtype: 'property', + name: 'TEXT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 53, + itemtype: 'property', + name: 'WAIT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 61, + description: + '

HALF_PI is a mathematical constant with the value\n1.57079632679489661923. It is half the ratio of the\ncircumference of a circle to its diameter. It is useful in\ncombination with the trigonometric functions sin() and cos().

\n', + itemtype: 'property', + name: 'HALF_PI', + type: 'Number', + final: 1, + example: ['\n
\narc(50, 50, 80, 80, 0, HALF_PI);\n
'], + alt: '80x80 white quarter-circle with curve toward bottom right of canvas.', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 80, + description: + '

PI is a mathematical constant with the value\n3.14159265358979323846. It is the ratio of the circumference\nof a circle to its diameter. It is useful in combination with\nthe trigonometric functions sin() and cos().

\n', + itemtype: 'property', + name: 'PI', + type: 'Number', + final: 1, + example: ['\n
\narc(50, 50, 80, 80, 0, PI);\n
'], + alt: 'white half-circle with curve toward bottom of canvas.', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 99, + description: + '

QUARTER_PI is a mathematical constant with the value 0.7853982.\nIt is one quarter the ratio of the circumference of a circle to\nits diameter. It is useful in combination with the trigonometric\nfunctions sin() and cos().

\n', + itemtype: 'property', + name: 'QUARTER_PI', + type: 'Number', + final: 1, + example: [ + '\n
\narc(50, 50, 80, 80, 0, QUARTER_PI);\n
' + ], + alt: + 'white eighth-circle rotated about 40 degrees with curve bottom right canvas.', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 118, + description: + '

TAU is an alias for TWO_PI, a mathematical constant with the\nvalue 6.28318530717958647693. It is twice the ratio of the\ncircumference of a circle to its diameter. It is useful in\ncombination with the trigonometric functions sin() and cos().

\n', + itemtype: 'property', + name: 'TAU', + type: 'Number', + final: 1, + example: ['\n
\narc(50, 50, 80, 80, 0, TAU);\n
'], + alt: '80x80 white ellipse shape in center of canvas.', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 137, + description: + '

TWO_PI is a mathematical constant with the value\n6.28318530717958647693. It is twice the ratio of the\ncircumference of a circle to its diameter. It is useful in\ncombination with the trigonometric functions sin() and cos().

\n', + itemtype: 'property', + name: 'TWO_PI', + type: 'Number', + final: 1, + example: ['\n
\narc(50, 50, 80, 80, 0, TWO_PI);\n
'], + alt: '80x80 white ellipse shape in center of canvas.', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 156, + description: + '

Constant to be used with angleMode() function, to set the mode which\np5.js interprates and calculates angles (either DEGREES or RADIANS).

\n', + itemtype: 'property', + name: 'DEGREES', + type: 'String', + final: 1, + example: [ + "\n
\nfunction setup() {\n angleMode(DEGREES);\n}\n
" + ], + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 170, + description: + '

Constant to be used with angleMode() function, to set the mode which\np5.js interprates and calculates angles (either RADIANS or DEGREES).

\n', + itemtype: 'property', + name: 'RADIANS', + type: 'String', + final: 1, + example: [ + "\n
\nfunction setup() {\n angleMode(RADIANS);\n}\n
" + ], + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 188, + itemtype: 'property', + name: 'CORNER', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 193, + itemtype: 'property', + name: 'CORNERS', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 198, + itemtype: 'property', + name: 'RADIUS', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 203, + itemtype: 'property', + name: 'RIGHT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 208, + itemtype: 'property', + name: 'LEFT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 213, + itemtype: 'property', + name: 'CENTER', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 218, + itemtype: 'property', + name: 'TOP', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 223, + itemtype: 'property', + name: 'BOTTOM', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 228, + itemtype: 'property', + name: 'BASELINE', + type: 'String', + final: 1, + default: 'alphabetic', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 234, + itemtype: 'property', + name: 'POINTS', + type: 'Number', + final: 1, + default: '0x0000', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 240, + itemtype: 'property', + name: 'LINES', + type: 'Number', + final: 1, + default: '0x0001', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 246, + itemtype: 'property', + name: 'LINE_STRIP', + type: 'Number', + final: 1, + default: '0x0003', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 252, + itemtype: 'property', + name: 'LINE_LOOP', + type: 'Number', + final: 1, + default: '0x0002', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 258, + itemtype: 'property', + name: 'TRIANGLES', + type: 'Number', + final: 1, + default: '0x0004', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 264, + itemtype: 'property', + name: 'TRIANGLE_FAN', + type: 'Number', + final: 1, + default: '0x0006', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 270, + itemtype: 'property', + name: 'TRIANGLE_STRIP', + type: 'Number', + final: 1, + default: '0x0005', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 276, + itemtype: 'property', + name: 'QUADS', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 281, + itemtype: 'property', + name: 'QUAD_STRIP', + type: 'String', + final: 1, + default: 'quad_strip', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 287, + itemtype: 'property', + name: 'CLOSE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 292, + itemtype: 'property', + name: 'OPEN', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 297, + itemtype: 'property', + name: 'CHORD', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 302, + itemtype: 'property', + name: 'PIE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 307, + itemtype: 'property', + name: 'PROJECT', + type: 'String', + final: 1, + default: 'square', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 313, + itemtype: 'property', + name: 'SQUARE', + type: 'String', + final: 1, + default: 'butt', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 319, + itemtype: 'property', + name: 'ROUND', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 324, + itemtype: 'property', + name: 'BEVEL', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 329, + itemtype: 'property', + name: 'MITER', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 336, + itemtype: 'property', + name: 'RGB', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 341, + itemtype: 'property', + name: 'HSB', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 346, + itemtype: 'property', + name: 'HSL', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 353, + description: + '

AUTO allows us to automatically set the width or height of an element (but not both),\nbased on the current height and width of the element. Only one parameter can\nbe passed to the size function as AUTO, at a time.

\n', + itemtype: 'property', + name: 'AUTO', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 380, + itemtype: 'property', + name: 'BLEND', + type: 'String', + final: 1, + default: 'source-over', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 386, + itemtype: 'property', + name: 'ADD', + type: 'String', + final: 1, + default: 'lighter', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 394, + itemtype: 'property', + name: 'DARKEST', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 399, + itemtype: 'property', + name: 'LIGHTEST', + type: 'String', + final: 1, + default: 'lighten', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 405, + itemtype: 'property', + name: 'DIFFERENCE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 410, + itemtype: 'property', + name: 'SUBTRACT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 415, + itemtype: 'property', + name: 'EXCLUSION', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 420, + itemtype: 'property', + name: 'MULTIPLY', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 425, + itemtype: 'property', + name: 'SCREEN', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 430, + itemtype: 'property', + name: 'REPLACE', + type: 'String', + final: 1, + default: 'copy', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 436, + itemtype: 'property', + name: 'OVERLAY', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 441, + itemtype: 'property', + name: 'HARD_LIGHT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 446, + itemtype: 'property', + name: 'SOFT_LIGHT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 451, + itemtype: 'property', + name: 'DODGE', + type: 'String', + final: 1, + default: 'color-dodge', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 457, + itemtype: 'property', + name: 'BURN', + type: 'String', + final: 1, + default: 'color-burn', + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 465, + itemtype: 'property', + name: 'THRESHOLD', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 470, + itemtype: 'property', + name: 'GRAY', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 475, + itemtype: 'property', + name: 'OPAQUE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 480, + itemtype: 'property', + name: 'INVERT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 485, + itemtype: 'property', + name: 'POSTERIZE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 490, + itemtype: 'property', + name: 'DILATE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 495, + itemtype: 'property', + name: 'ERODE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 500, + itemtype: 'property', + name: 'BLUR', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 507, + itemtype: 'property', + name: 'NORMAL', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 512, + itemtype: 'property', + name: 'ITALIC', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 517, + itemtype: 'property', + name: 'BOLD', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 522, + itemtype: 'property', + name: 'BOLDITALIC', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 547, + itemtype: 'property', + name: 'IMAGE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 561, + itemtype: 'property', + name: 'LANDSCAPE', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 566, + itemtype: 'property', + name: 'PORTRAIT', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 576, + itemtype: 'property', + name: 'GRID', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/constants.js', + line: 582, + itemtype: 'property', + name: 'AXES', + type: 'String', + final: 1, + class: 'p5', + module: 'Constants', + submodule: 'Constants' + }, + { + file: 'src/core/environment.js', + line: 22, + description: + '

The print() function writes to the console area of your browser.\nThis function is often helpful for looking at the data a program is\nproducing. This function creates a new line of text for each call to\nthe function. Individual elements can be\nseparated with quotes ("") and joined with the addition operator (+).

\n

Note that calling print() without any arguments invokes the window.print()\nfunction which opens the browser's print dialog. To print a blank line\nto console you can write print('\\n').

\n', + itemtype: 'method', + name: 'print', + params: [ + { + name: 'contents', + description: + '

any combination of Number, String, Object, Boolean,\n Array to print

\n', + type: 'Any' + } + ], + example: [ + "\n
\nlet x = 10;\nprint('The value of x is ' + x);\n// prints \"The value of x is 10\"\n
" + ], + alt: 'default grey canvas', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 53, + description: + '

The system variable frameCount contains the number of frames that have\nbeen displayed since the program started. Inside setup() the value is 0,\nafter the first iteration of draw it is 1, etc.

\n', + itemtype: 'property', + name: 'frameCount', + type: 'Integer', + readonly: '', + example: [ + '\n
\nfunction setup() {\n frameRate(30);\n textSize(30);\n textAlign(CENTER);\n}\n\nfunction draw() {\n background(200);\n text(frameCount, width / 2, height / 2);\n}\n
' + ], + alt: 'numbers rapidly counting upward with frame count set to 30.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 80, + description: + '

The system variable deltaTime contains the time\ndifference between the beginning of the previous frame and the beginning\nof the current frame in milliseconds.\n

\nThis variable is useful for creating time sensitive animation or physics\ncalculation that should stay constant regardless of frame rate.

\n', + itemtype: 'property', + name: 'deltaTime', + type: 'Integer', + readonly: '', + example: [ + '\n
\nlet rectX = 0;\nlet fr = 30; //starting FPS\nlet clr;\n\nfunction setup() {\n background(200);\n frameRate(fr); // Attempt to refresh at starting FPS\n clr = color(255, 0, 0);\n}\n\nfunction draw() {\n background(200);\n rectX = rectX + 1 * (deltaTime / 50); // Move Rectangle in relation to deltaTime\n\n if (rectX >= width) {\n // If you go off screen.\n if (fr === 30) {\n clr = color(0, 0, 255);\n fr = 10;\n frameRate(fr); // make frameRate 10 FPS\n } else {\n clr = color(255, 0, 0);\n fr = 30;\n frameRate(fr); // make frameRate 30 FPS\n }\n rectX = 0;\n }\n fill(clr);\n rect(rectX, 40, 20, 20);\n}\n
' + ], + alt: + 'red rect moves left to right, followed by blue rect moving at the same speed\nwith a lower frame rate. Loops.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 131, + description: + '

Confirms if the window a p5.js program is in is "focused," meaning that\nthe sketch will accept mouse or keyboard input. This variable is\n"true" if the window is focused and "false" if not.

\n', + itemtype: 'property', + name: 'focused', + type: 'Boolean', + readonly: '', + example: [ + '\n
\n// To demonstrate, put two windows side by side.\n// Click on the window that the p5 sketch isn\'t in!\nfunction draw() {\n background(200);\n noStroke();\n fill(0, 200, 0);\n ellipse(25, 25, 50, 50);\n\n if (!focused) {\n // or "if (focused === false)"\n stroke(200, 0, 0);\n line(0, 0, 100, 100);\n line(100, 0, 0, 100);\n }\n}\n
' + ], + alt: + 'green 50x50 ellipse at top left. Red X covers canvas when page focus changes', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 163, + description: + '

Sets the cursor to a predefined symbol or an image, or makes it visible\nif already hidden. If you are trying to set an image as the cursor, the\nrecommended size is 16x16 or 32x32 pixels. The values for parameters x and y\nmust be less than the dimensions of the image.

\n', + itemtype: 'method', + name: 'cursor', + params: [ + { + name: 'type', + description: + '

Built-In: either ARROW, CROSS, HAND, MOVE, TEXT and WAIT\n Native CSS properties: 'grab', 'progress', 'cell' etc.\n External: path for cursor's images\n (Allowed File extensions: .cur, .gif, .jpg, .jpeg, .png)\n For more information on Native CSS cursors and url visit:\n https://developer.mozilla.org/en-US/docs/Web/CSS/cursor

\n', + type: 'String|Constant' + }, + { + name: 'x', + description: + '

the horizontal active spot of the cursor (must be less than 32)

\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: + '

the vertical active spot of the cursor (must be less than 32)

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\n// Move the mouse across the quadrants\n// to see the cursor change\nfunction draw() {\n line(width / 2, 0, width / 2, height);\n line(0, height / 2, width, height / 2);\n if (mouseX < 50 && mouseY < 50) {\n cursor(CROSS);\n } else if (mouseX > 50 && mouseY < 50) {\n cursor('progress');\n } else if (mouseX > 50 && mouseY > 50) {\n cursor('https://s3.amazonaws.com/mupublicdata/cursor.cur');\n } else {\n cursor('grab');\n }\n}\n
" + ], + alt: + 'canvas is divided into four quadrants. cursor on first is a cross, second is a progress,\nthird is a custom cursor using path to the cursor and fourth is a grab.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 232, + description: + '

Specifies the number of frames to be displayed every second. For example,\nthe function call frameRate(30) will attempt to refresh 30 times a second.\nIf the processor is not fast enough to maintain the specified rate, the\nframe rate will not be achieved. Setting the frame rate within setup() is\nrecommended. The default frame rate is based on the frame rate of the display\n(here also called "refresh rate"), which is set to 60 frames per second on most\ncomputers. A frame rate of 24 frames per second (usual for movies) or above\nwill be enough for smooth animations\nThis is the same as setFrameRate(val).\n

\nCalling frameRate() with no arguments returns the current framerate. The\ndraw function must run at least once before it will return a value. This\nis the same as getFrameRate().\n

\nCalling frameRate() with arguments that are not of the type numbers\nor are non positive also returns current framerate.

\n', + itemtype: 'method', + name: 'frameRate', + chainable: 1, + example: [ + '\n\n
\nlet rectX = 0;\nlet fr = 30; //starting FPS\nlet clr;\n\nfunction setup() {\n background(200);\n frameRate(fr); // Attempt to refresh at starting FPS\n clr = color(255, 0, 0);\n}\n\nfunction draw() {\n background(200);\n rectX = rectX += 1; // Move Rectangle\n\n if (rectX >= width) {\n // If you go off screen.\n if (fr === 30) {\n clr = color(0, 0, 255);\n fr = 10;\n frameRate(fr); // make frameRate 10 FPS\n } else {\n clr = color(255, 0, 0);\n fr = 30;\n frameRate(fr); // make frameRate 30 FPS\n }\n rectX = 0;\n }\n fill(clr);\n rect(rectX, 40, 20, 20);\n}\n
' + ], + alt: + 'blue rect moves left to right, followed by red rect moving faster. Loops.', + class: 'p5', + module: 'Environment', + submodule: 'Environment', + overloads: [ + { + line: 232, + params: [ + { + name: 'fps', + description: + '

number of frames to be displayed every second

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 293, + params: [], + return: { + description: 'current frameRate', + type: 'Number' + } + } + ] + }, + { + file: 'src/core/environment.js', + line: 332, + description: '

Hides the cursor from view.

\n', + itemtype: 'method', + name: 'noCursor', + example: [ + '\n
\nfunction setup() {\n noCursor();\n}\n\nfunction draw() {\n background(200);\n ellipse(mouseX, mouseY, 10, 10);\n}\n
' + ], + alt: 'cursor becomes 10x 10 white ellipse the moves with mouse x and y.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 357, + description: + '

System variable that stores the width of the screen display according to The\ndefault pixelDensity. This is used to run a\nfull-screen program on any display size. To return actual screen size,\nmultiply this by pixelDensity.

\n', + itemtype: 'property', + name: 'displayWidth', + type: 'Number', + readonly: '', + example: [ + '\n
\ncreateCanvas(displayWidth, displayHeight);\n
' + ], + alt: 'cursor becomes 10x 10 white ellipse the moves with mouse x and y.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 376, + description: + '

System variable that stores the height of the screen display according to The\ndefault pixelDensity. This is used to run a\nfull-screen program on any display size. To return actual screen size,\nmultiply this by pixelDensity.

\n', + itemtype: 'property', + name: 'displayHeight', + type: 'Number', + readonly: '', + example: [ + '\n
\ncreateCanvas(displayWidth, displayHeight);\n
' + ], + alt: 'no display.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 395, + description: + '

System variable that stores the width of the inner window, it maps to\nwindow.innerWidth.

\n', + itemtype: 'property', + name: 'windowWidth', + type: 'Number', + readonly: '', + example: [ + '\n
\ncreateCanvas(windowWidth, windowHeight);\n
' + ], + alt: 'no display.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 411, + description: + '

System variable that stores the height of the inner window, it maps to\nwindow.innerHeight.

\n', + itemtype: 'property', + name: 'windowHeight', + type: 'Number', + readonly: '', + example: [ + '\n
\ncreateCanvas(windowWidth, windowHeight);\n
' + ], + alt: 'no display.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 427, + description: + '

The windowResized() function is called once every time the browser window\nis resized. This is a good place to resize the canvas or do any other\nadjustments to accommodate the new window size.

\n', + itemtype: 'method', + name: 'windowResized', + example: [ + '\n
\nfunction setup() {\n createCanvas(windowWidth, windowHeight);\n}\n\nfunction draw() {\n background(0, 100, 200);\n}\n\nfunction windowResized() {\n resizeCanvas(windowWidth, windowHeight);\n}\n
' + ], + alt: 'no display.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 481, + description: + '

System variable that stores the width of the drawing canvas. This value\nis set by the first parameter of the createCanvas() function.\nFor example, the function call createCanvas(320, 240) sets the width\nvariable to the value 320. The value of width defaults to 100 if\ncreateCanvas() is not used in a program.

\n', + itemtype: 'property', + name: 'width', + type: 'Number', + readonly: '', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 493, + description: + '

System variable that stores the height of the drawing canvas. This value\nis set by the second parameter of the createCanvas() function. For\nexample, the function call createCanvas(320, 240) sets the height\nvariable to the value 240. The value of height defaults to 100 if\ncreateCanvas() is not used in a program.

\n', + itemtype: 'property', + name: 'height', + type: 'Number', + readonly: '', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 505, + description: + '

If argument is given, sets the sketch to fullscreen or not based on the\nvalue of the argument. If no argument is given, returns the current\nfullscreen state. Note that due to browser restrictions this can only\nbe called on user input, for example, on mouse press like the example\nbelow.

\n', + itemtype: 'method', + name: 'fullscreen', + params: [ + { + name: 'val', + description: + '

whether the sketch should be in fullscreen mode\nor not

\n', + type: 'Boolean', + optional: true + } + ], + return: { + description: 'current fullscreen state', + type: 'Boolean' + }, + example: [ + '\n
\n\n// Clicking in the box toggles fullscreen on and off.\nfunction setup() {\n background(200);\n}\nfunction mousePressed() {\n if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {\n let fs = fullscreen();\n fullscreen(!fs);\n }\n}\n\n
' + ], + alt: 'no display.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 556, + description: + '

Sets the pixel scaling for high pixel density displays. By default\npixel density is set to match display density, call pixelDensity(1)\nto turn this off. Calling pixelDensity() with no arguments returns\nthe current pixel density of the sketch.

\n', + itemtype: 'method', + name: 'pixelDensity', + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n pixelDensity(1);\n createCanvas(100, 100);\n background(200);\n ellipse(width / 2, height / 2, 50, 50);\n}\n\n
\n
\n\nfunction setup() {\n pixelDensity(3.0);\n createCanvas(100, 100);\n background(200);\n ellipse(width / 2, height / 2, 50, 50);\n}\n\n
' + ], + alt: + 'fuzzy 50x50 white ellipse with black outline in center of canvas.\nsharp 50x50 white ellipse with black outline in center of canvas.', + class: 'p5', + module: 'Environment', + submodule: 'Environment', + overloads: [ + { + line: 556, + params: [ + { + name: 'val', + description: '

whether or how much the sketch should scale

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 591, + params: [], + return: { + description: 'current pixel density of the sketch', + type: 'Number' + } + } + ] + }, + { + file: 'src/core/environment.js', + line: 611, + description: + '

Returns the pixel density of the current display the sketch is running on.

\n', + itemtype: 'method', + name: 'displayDensity', + return: { + description: 'current pixel density of the display', + type: 'Number' + }, + example: [ + '\n
\n\nfunction setup() {\n let density = displayDensity();\n pixelDensity(density);\n createCanvas(100, 100);\n background(200);\n ellipse(width / 2, height / 2, 50, 50);\n}\n\n
' + ], + alt: '50x50 white ellipse with black outline in center of canvas.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 668, + description: '

Gets the current URL.

\n', + itemtype: 'method', + name: 'getURL', + return: { + description: 'url', + type: 'String' + }, + example: [ + '\n
\n\nlet url;\nlet x = 100;\n\nfunction setup() {\n fill(0);\n noStroke();\n url = getURL();\n}\n\nfunction draw() {\n background(200);\n text(url, x, height / 2);\n x--;\n}\n\n
' + ], + alt: + 'current url (http://p5js.org/reference/#/p5/getURL) moves right to left.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 699, + description: '

Gets the current URL path as an array.

\n', + itemtype: 'method', + name: 'getURLPath', + return: { + description: 'path components', + type: 'String[]' + }, + example: [ + "\n
\nfunction setup() {\n let urlPath = getURLPath();\n for (let i = 0; i < urlPath.length; i++) {\n text(urlPath[i], 10, i * 20 + 20);\n }\n}\n
" + ], + alt: 'no display', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/environment.js', + line: 722, + description: '

Gets the current URL params as an Object.

\n', + itemtype: 'method', + name: 'getURLParams', + return: { + description: 'URL params', + type: 'Object' + }, + example: [ + "\n
\n\n// Example: http://p5js.org?year=2014&month=May&day=15\n\nfunction setup() {\n let params = getURLParams();\n text(params.day, 10, 20);\n text(params.month, 10, 40);\n text(params.year, 10, 60);\n}\n\n
" + ], + alt: 'no display.', + class: 'p5', + module: 'Environment', + submodule: 'Environment' + }, + { + file: 'src/core/error_helpers.js', + line: 1, + requires: ['core'], + class: 'p5', + module: 'Environment' + }, + { + file: 'src/core/error_helpers.js', + line: 584, + description: + '

Validates parameters\nparam {String} func the name of the function\nparam {Array} args user input arguments

\n

example:\n var a;\n ellipse(10,10,a,5);\nconsole ouput:\n "It looks like ellipse received an empty variable in spot #2."

\n

example:\n ellipse(10,"foo",5,5);\nconsole output:\n "ellipse was expecting a number for parameter #1,\n received "foo" instead."

\n', + class: 'p5', + module: 'Environment' + }, + { + file: 'src/core/error_helpers.js', + line: 645, + description: + '

Prints out all the colors in the color pallete with white text.\nFor color blindness testing.

\n', + class: 'p5', + module: 'Environment' + }, + { + file: 'src/core/helpers.js', + line: 1, + requires: ['constants'], + class: 'p5', + module: 'Environment' + }, + { + file: 'src/core/legacy.js', + line: 1, + requires: [ + 'core\nThese are functions that are part of the Processing API but are not part of\nthe p5.js API. In some cases they have a new name', + 'in others', + 'they are\nremoved completely. Not all unsupported Processing functions are listed here\nbut we try to include ones that a user coming from Processing might likely\ncall.' + ], + class: 'p5', + module: 'Environment' + }, + { + file: 'src/core/main.js', + line: 42, + description: + '

Called directly before setup(), the preload() function is used to handle\nasynchronous loading of external files in a blocking way. If a preload\nfunction is defined, setup() will wait until any load calls within have\nfinished. Nothing besides load calls (loadImage, loadJSON, loadFont,\nloadStrings, etc.) should be inside the preload function. If asynchronous\nloading is preferred, the load methods can instead be called in setup()\nor anywhere else with the use of a callback parameter.\n

\nBy default the text "loading..." will be displayed. To make your own\nloading page, include an HTML element with id "p5_loading" in your\npage. More information here.

\n', + itemtype: 'method', + name: 'preload', + example: [ + "\n
\nlet img;\nlet c;\nfunction preload() {\n // preload() runs once\n img = loadImage('assets/laDefense.jpg');\n}\n\nfunction setup() {\n // setup() waits until preload() is done\n img.loadPixels();\n // get color of middle pixel\n c = img.get(img.width / 2, img.height / 2);\n}\n\nfunction draw() {\n background(c);\n image(img, 25, 25, 50, 50);\n}\n
" + ], + alt: 'nothing displayed', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/main.js', + line: 83, + description: + '

The setup() function is called once when the program starts. It's used to\ndefine initial environment properties such as screen size and background\ncolor and to load media such as images and fonts as the program starts.\nThere can only be one setup() function for each program and it shouldn't\nbe called again after its initial execution.\n

\nNote: Variables declared within setup() are not accessible within other\nfunctions, including draw().

\n', + itemtype: 'method', + name: 'setup', + example: [ + '\n
\nlet a = 0;\n\nfunction setup() {\n background(0);\n noStroke();\n fill(102);\n}\n\nfunction draw() {\n rect(a++ % width, 10, 2, 80);\n}\n
' + ], + alt: 'nothing displayed', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/main.js', + line: 114, + description: + '

Called directly after setup(), the draw() function continuously executes\nthe lines of code contained inside its block until the program is stopped\nor noLoop() is called. Note if noLoop() is called in setup(), draw() will\nstill be executed once before stopping. draw() is called automatically and\nshould never be called explicitly.\n

\nIt should always be controlled with noLoop(), redraw() and loop(). After\nnoLoop() stops the code in draw() from executing, redraw() causes the\ncode inside draw() to execute once, and loop() will cause the code\ninside draw() to resume executing continuously.\n

\nThe number of times draw() executes in each second may be controlled with\nthe frameRate() function.\n

\nThere can only be one draw() function for each sketch, and draw() must\nexist if you want the code to run continuously, or to process events such\nas mousePressed(). Sometimes, you might have an empty call to draw() in\nyour program, as shown in the above example.\n

\nIt is important to note that the drawing coordinate system will be reset\nat the beginning of each draw() call. If any transformations are performed\nwithin draw() (ex: scale, rotate, translate), their effects will be\nundone at the beginning of draw(), so transformations will not accumulate\nover time. On the other hand, styling applied (ex: fill, stroke, etc) will\nremain in effect.

\n', + itemtype: 'method', + name: 'draw', + example: [ + '\n
\nlet yPos = 0;\nfunction setup() {\n // setup() runs once\n frameRate(30);\n}\nfunction draw() {\n // draw() loops forever, until stopped\n background(204);\n yPos = yPos - 1;\n if (yPos < 0) {\n yPos = height;\n }\n line(0, yPos, width, yPos);\n}\n
' + ], + alt: 'nothing displayed', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/main.js', + line: 396, + description: + '

Removes the entire p5 sketch. This will remove the canvas and any\nelements created by p5.js. It will also stop the draw loop and unbind\nany properties or methods from the window global scope. It will\nleave a variable p5 in case you wanted to create a new p5 sketch.\nIf you like, you can set p5 = null to erase it. While all functions and\nvariables and objects created by the p5 library will be removed, any\nother global variables created by your code will remain.

\n', + itemtype: 'method', + name: 'remove', + example: [ + "\n
\nfunction draw() {\n ellipse(50, 50, 10, 10);\n}\n\nfunction mousePressed() {\n remove(); // remove whole sketch on mouse press\n}\n
" + ], + alt: 'nothing displayed', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/main.js', + line: 577, + description: + "

Allows for the friendly error system (FES) to be turned off when creating a sketch,\nwhich can give a significant boost to performance when needed.\nSee \ndisabling the friendly error system.

\n", + itemtype: 'property', + name: 'disableFriendlyErrors', + type: 'Boolean', + example: [ + '\n
\np5.disableFriendlyErrors = true;\n\nfunction setup() {\n createCanvas(100, 50);\n}\n
' + ], + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/p5.Element.js', + line: 26, + description: + '

Underlying HTML element. All normal HTML methods can be called on this.

\n', + example: [ + "\n
\n\nfunction setup() {\n let c = createCanvas(50, 50);\n c.elt.style.border = '5px solid red';\n}\n\nfunction draw() {\n background(220);\n}\n\n
" + ], + itemtype: 'property', + name: 'elt', + readonly: '', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 52, + description: + "

Attaches the element to the parent specified. A way of setting\n the container for the element. Accepts either a string ID, DOM\n node, or p5.Element. If no arguments given, parent node is returned.\n For more ways to position the canvas, see the\n \n positioning the canvas wiki page.\nAll above examples except for the first one require the inclusion of\n the p5.dom library in your index.html. See the\n using a library\n section for information on how to include this library.

\n", + itemtype: 'method', + name: 'parent', + chainable: 1, + example: [ + "\n
\n // in the html file:\n // <div id=\"myContainer\"></div>\n// in the js file:\n let cnv = createCanvas(100, 100);\n cnv.parent('myContainer');\n
\n
\n let div0 = createDiv('this is the parent');\n let div1 = createDiv('this is the child');\n div1.parent(div0); // use p5.Element\n
\n
\n let div0 = createDiv('this is the parent');\n div0.id('apples');\n let div1 = createDiv('this is the child');\n div1.parent('apples'); // use id\n
\n
\n let elt = document.getElementById('myParentDiv');\n let div1 = createDiv('this is the child');\n div1.parent(elt); // use element from page\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM', + overloads: [ + { + line: 52, + params: [ + { + name: 'parent', + description: + '

the ID, DOM node, or p5.Element\n of desired parent element

\n', + type: 'String|p5.Element|Object' + } + ], + chainable: 1 + }, + { + line: 100, + params: [], + return: { + description: '', + type: 'p5.Element' + } + } + ] + }, + { + file: 'src/core/p5.Element.js', + line: 122, + description: + '

Sets the ID of the element. If no ID argument is passed in, it instead\n returns the current ID of the element.\n Note that only one element can have a particular id in a page.\n The .class() function can be used\n to identify multiple elements with the same class name.

\n', + itemtype: 'method', + name: 'id', + chainable: 1, + example: [ + "\n
\n function setup() {\n let cnv = createCanvas(100, 100);\n // Assigns a CSS selector ID to\n // the canvas element.\n cnv.id('mycanvas');\n }\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM', + overloads: [ + { + line: 122, + params: [ + { + name: 'id', + description: '

ID of the element

\n', + type: 'String' + } + ], + chainable: 1 + }, + { + line: 147, + params: [], + return: { + description: 'the id of the element', + type: 'String' + } + } + ] + }, + { + file: 'src/core/p5.Element.js', + line: 162, + description: + '

Adds given class to the element. If no class argument is passed in, it\n instead returns a string containing the current class(es) of the element.

\n', + itemtype: 'method', + name: 'class', + chainable: 1, + example: [ + "\n
\n function setup() {\n let cnv = createCanvas(100, 100);\n // Assigns a CSS selector class 'small'\n // to the canvas element.\n cnv.class('small');\n }\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM', + overloads: [ + { + line: 162, + params: [ + { + name: 'class', + description: '

class to add

\n', + type: 'String' + } + ], + chainable: 1 + }, + { + line: 184, + params: [], + return: { + description: 'the class of the element', + type: 'String' + } + } + ] + }, + { + file: 'src/core/p5.Element.js', + line: 197, + description: + '

The .mousePressed() function is called once after every time a\nmouse button is pressed over the element.\nSome mobile browsers may also trigger this event on a touch screen,\nif the user performs a quick tap.\nThis can be used to attach element specific event listeners.

\n', + itemtype: 'method', + name: 'mousePressed', + params: [ + { + name: 'fxn', + description: + '

function to be fired when mouse is\n pressed over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet d;\nlet g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mousePressed(changeGray); // attach listener for\n // canvas click only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width / 2, height / 2, d, d);\n}\n\n// this function fires with any click anywhere\nfunction mousePressed() {\n d = d + 10;\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 258, + description: + '

The .doubleClicked() function is called once after every time a\nmouse button is pressed twice over the element. This can be used to\nattach element and action specific event listeners.

\n', + itemtype: 'method', + name: 'doubleClicked', + params: [ + { + name: 'fxn', + description: + '

function to be fired when mouse is\n double clicked over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + return: { + description: '', + type: 'p5.Element' + }, + example: [ + "\n
\nlet cnv;\nlet d;\nlet g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.doubleClicked(changeGray); // attach listener for\n // canvas double click only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width / 2, height / 2, d, d);\n}\n\n// this function fires with any double click anywhere\nfunction doubleClicked() {\n d = d + 10;\n}\n\n// this function fires only when cnv is double clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 307, + description: + '

The .mouseWheel() function is called once after every time a\nmouse wheel is scrolled over the element. This can be used to\nattach element specific event listeners.\n

\nThe function accepts a callback function as argument which will be executed\nwhen the wheel event is triggered on the element, the callback function is\npassed one argument event. The event.deltaY property returns negative\nvalues if the mouse wheel is rotated up or away from the user and positive\nin the other direction. The event.deltaX does the same as event.deltaY\nexcept it reads the horizontal wheel scroll of the mouse wheel.\n

\nOn OS X with "natural" scrolling enabled, the event.deltaY values are\nreversed.

\n', + itemtype: 'method', + name: 'mouseWheel', + params: [ + { + name: 'fxn', + description: + '

function to be fired when mouse is\n scrolled over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet d;\nlet g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseWheel(changeSize); // attach listener for\n // activity on canvas only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width / 2, height / 2, d, d);\n}\n\n// this function fires with mousewheel movement\n// anywhere on screen\nfunction mouseWheel() {\n g = g + 10;\n}\n\n// this function fires with mousewheel movement\n// over canvas only\nfunction changeSize(event) {\n if (event.deltaY > 0) {\n d = d + 10;\n } else {\n d = d - 10;\n }\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 373, + description: + '

The .mouseReleased() function is called once after every time a\nmouse button is released over the element.\nSome mobile browsers may also trigger this event on a touch screen,\nif the user performs a quick tap.\nThis can be used to attach element specific event listeners.

\n', + itemtype: 'method', + name: 'mouseReleased', + params: [ + { + name: 'fxn', + description: + '

function to be fired when mouse is\n released over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet d;\nlet g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseReleased(changeGray); // attach listener for\n // activity on canvas only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width / 2, height / 2, d, d);\n}\n\n// this function fires after the mouse has been\n// released\nfunction mouseReleased() {\n d = d + 10;\n}\n\n// this function fires after the mouse has been\n// released while on canvas\nfunction changeGray() {\n g = random(0, 255);\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 427, + description: + '

The .mouseClicked() function is called once after a mouse button is\npressed and released over the element.\nSome mobile browsers may also trigger this event on a touch screen,\nif the user performs a quick tap.\nThis can be used to attach element specific event listeners.

\n', + itemtype: 'method', + name: 'mouseClicked', + params: [ + { + name: 'fxn', + description: + '

function to be fired when mouse is\n clicked over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + '\n
\n\nlet cnv;\nlet d;\nlet g;\n\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseClicked(changeGray); // attach listener for\n // activity on canvas only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width / 2, height / 2, d, d);\n}\n\n// this function fires after the mouse has been\n// clicked anywhere\nfunction mouseClicked() {\n d = d + 10;\n}\n\n// this function fires after the mouse has been\n// clicked on canvas\nfunction changeGray() {\n g = random(0, 255);\n}\n\n
' + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 483, + description: + '

The .mouseMoved() function is called once every time a\nmouse moves over the element. This can be used to attach an\nelement specific event listener.

\n', + itemtype: 'method', + name: 'mouseMoved', + params: [ + { + name: 'fxn', + description: + '

function to be fired when a mouse moves\n over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet d = 30;\nlet g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseMoved(changeSize); // attach listener for\n // activity on canvas only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n fill(200);\n ellipse(width / 2, height / 2, d, d);\n}\n\n// this function fires when mouse moves anywhere on\n// page\nfunction mouseMoved() {\n g = g + 5;\n if (g > 255) {\n g = 0;\n }\n}\n\n// this function fires when mouse moves over canvas\nfunction changeSize() {\n d = d + 2;\n if (d > 100) {\n d = 0;\n }\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 541, + description: + '

The .mouseOver() function is called once after every time a\nmouse moves onto the element. This can be used to attach an\nelement specific event listener.

\n', + itemtype: 'method', + name: 'mouseOver', + params: [ + { + name: 'fxn', + description: + '

function to be fired when a mouse moves\n onto the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet d;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseOver(changeGray);\n d = 10;\n}\n\nfunction draw() {\n ellipse(width / 2, height / 2, d, d);\n}\n\nfunction changeGray() {\n d = d + 10;\n if (d > 100) {\n d = 0;\n }\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 584, + description: + '

The .mouseOut() function is called once after every time a\nmouse moves off the element. This can be used to attach an\nelement specific event listener.

\n', + itemtype: 'method', + name: 'mouseOut', + params: [ + { + name: 'fxn', + description: + '

function to be fired when a mouse\n moves off of an element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet d;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.mouseOut(changeGray);\n d = 10;\n}\n\nfunction draw() {\n ellipse(width / 2, height / 2, d, d);\n}\n\nfunction changeGray() {\n d = d + 10;\n if (d > 100) {\n d = 0;\n }\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 626, + description: + '

The .touchStarted() function is called once after every time a touch is\nregistered. This can be used to attach element specific event listeners.

\n', + itemtype: 'method', + name: 'touchStarted', + params: [ + { + name: 'fxn', + description: + '

function to be fired when a touch\n starts over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet d;\nlet g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.touchStarted(changeGray); // attach listener for\n // canvas click only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width / 2, height / 2, d, d);\n}\n\n// this function fires with any touch anywhere\nfunction touchStarted() {\n d = d + 10;\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 674, + description: + '

The .touchMoved() function is called once after every time a touch move is\nregistered. This can be used to attach element specific event listeners.

\n', + itemtype: 'method', + name: 'touchMoved', + params: [ + { + name: 'fxn', + description: + '

function to be fired when a touch moves over\n the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.touchMoved(changeGray); // attach listener for\n // canvas click only\n g = 100;\n}\n\nfunction draw() {\n background(g);\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 714, + description: + '

The .touchEnded() function is called once after every time a touch is\nregistered. This can be used to attach element specific event listeners.

\n', + itemtype: 'method', + name: 'touchEnded', + params: [ + { + name: 'fxn', + description: + '

function to be fired when a touch ends\n over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nlet cnv;\nlet d;\nlet g;\nfunction setup() {\n cnv = createCanvas(100, 100);\n cnv.touchEnded(changeGray); // attach listener for\n // canvas click only\n d = 10;\n g = 100;\n}\n\nfunction draw() {\n background(g);\n ellipse(width / 2, height / 2, d, d);\n}\n\n// this function fires with any touch anywhere\nfunction touchEnded() {\n d = d + 10;\n}\n\n// this function fires only when cnv is clicked\nfunction changeGray() {\n g = random(0, 255);\n}\n
" + ], + alt: 'no display.', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 763, + description: + '

The .dragOver() function is called once after every time a\nfile is dragged over the element. This can be used to attach an\nelement specific event listener.

\n', + itemtype: 'method', + name: 'dragOver', + params: [ + { + name: 'fxn', + description: + '

function to be fired when a file is\n dragged over the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\n// To test this sketch, simply drag a\n// file over the canvas\nfunction setup() {\n let c = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('Drag file', width / 2, height / 2);\n c.dragOver(dragOverCallback);\n}\n\n// This function will be called whenever\n// a file is dragged over the canvas\nfunction dragOverCallback() {\n background(240);\n text('Dragged over', width / 2, height / 2);\n}\n
" + ], + alt: 'nothing displayed', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 801, + description: + '

The .dragLeave() function is called once after every time a\ndragged file leaves the element area. This can be used to attach an\nelement specific event listener.

\n', + itemtype: 'method', + name: 'dragLeave', + params: [ + { + name: 'fxn', + description: + '

function to be fired when a file is\n dragged off the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\n// To test this sketch, simply drag a file\n// over and then out of the canvas area\nfunction setup() {\n let c = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('Drag file', width / 2, height / 2);\n c.dragLeave(dragLeaveCallback);\n}\n\n// This function will be called whenever\n// a file is dragged out of the canvas\nfunction dragLeaveCallback() {\n background(240);\n text('Dragged off', width / 2, height / 2);\n}\n
" + ], + alt: 'nothing displayed', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Element.js', + line: 865, + description: '

Helper fxn for sharing pixel methods

\n', + class: 'p5.Element', + module: 'DOM', + submodule: 'DOM' + }, + { + file: 'src/core/p5.Graphics.js', + line: 65, + description: + "

Resets certain values such as those modified by functions in the Transform category\nand in the Lights category that are not automatically reset\nwith graphics buffer objects. Calling this in draw() will copy the behavior\nof the standard canvas.

\n", + itemtype: 'method', + name: 'reset', + example: [ + "\n\n
\nlet pg;\nfunction setup() {\n createCanvas(100, 100);\n background(0);\n pg = createGraphics(50, 100);\n pg.fill(0);\n frameRate(5);\n}\nfunction draw() {\n image(pg, width / 2, 0);\n pg.background(255);\n // p5.Graphics object behave a bit differently in some cases\n // The normal canvas on the left resets the translate\n // with every loop through draw()\n // the graphics object on the right doesn't automatically reset\n // so translate() is additive and it moves down the screen\n rect(0, 0, width / 2, 5);\n pg.rect(0, 0, width / 2, 5);\n translate(0, 5, 0);\n pg.translate(0, 5, 0);\n}\nfunction mouseClicked() {\n // if you click you will see that\n // reset() resets the translate back to the initial state\n // of the Graphics object\n pg.reset();\n}\n
" + ], + alt: + 'A white line on a black background stays still on the top-left half.\nA black line animates from top to bottom on a white background on the right half.\nWhen clicked, the black line starts back over at the top.', + class: 'p5.Graphics', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/p5.Graphics.js', + line: 117, + description: + '

Removes a Graphics object from the page and frees any resources\nassociated with it.

\n', + itemtype: 'method', + name: 'remove', + example: [ + "\n
\nlet bg;\nfunction setup() {\n bg = createCanvas(100, 100);\n bg.background(0);\n image(bg, 0, 0);\n bg.remove();\n}\n
\n\n
\nlet bg;\nfunction setup() {\n pixelDensity(1);\n createCanvas(100, 100);\n stroke(255);\n fill(0);\n\n // create and draw the background image\n bg = createGraphics(100, 100);\n bg.background(200);\n bg.ellipse(50, 50, 80, 80);\n}\nfunction draw() {\n let t = millis() / 1000;\n // draw the background\n if (bg) {\n image(bg, frameCount % 100, 0);\n image(bg, frameCount % 100 - 100, 0);\n }\n // draw the foreground\n let p = p5.Vector.fromAngle(t, 35).add(50, 50);\n ellipse(p.x, p.y, 30);\n}\nfunction mouseClicked() {\n // remove the background\n if (bg) {\n bg.remove();\n bg = null;\n }\n}\n
" + ], + alt: + 'no image\na multi-colored circle moving back and forth over a scrolling background.', + class: 'p5.Graphics', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/p5.Renderer.js', + line: 97, + description: '

Resize our canvas element.

\n', + class: 'p5.Renderer', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/p5.Renderer.js', + line: 335, + description: '

Helper fxn to check font type (system or otf)

\n', + class: 'p5.Renderer', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/p5.Renderer.js', + line: 388, + description: + '

Helper fxn to measure ascent and descent.\nAdapted from http://stackoverflow.com/a/25355178

\n', + class: 'p5.Renderer', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/p5.Renderer2D.js', + line: 9, + description: + '

p5.Renderer2D\nThe 2D graphics canvas renderer class.\nextends p5.Renderer

\n', + class: 'p5', + module: 'Rendering' + }, + { + file: 'src/core/p5.Renderer2D.js', + line: 407, + description: + '

Generate a cubic Bezier representing an arc on the unit circle of total\nangle size radians, beginning start radians above the x-axis. Up to\nfour of these curves are combined to make a full arc.

\n

See www.joecridge.me/bezier.pdf for an explanation of the method.

\n', + class: 'p5', + module: 'Rendering' + }, + { + file: 'src/core/rendering.js', + line: 17, + description: + '

Creates a canvas element in the document, and sets the dimensions of it\nin pixels. This method should be called only once at the start of setup.\nCalling createCanvas more than once in a sketch will result in very\nunpredictable behavior. If you want more than one drawing canvas\nyou could use createGraphics (hidden by default but it can be shown).\n

\nThe system variables width and height are set by the parameters passed\nto this function. If createCanvas() is not used, the window will be\ngiven a default size of 100x100 pixels.\n

\nFor more ways to position the canvas, see the\n\npositioning the canvas wiki page.

\n', + itemtype: 'method', + name: 'createCanvas', + params: [ + { + name: 'w', + description: '

width of the canvas

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height of the canvas

\n', + type: 'Number' + }, + { + name: 'renderer', + description: '

either P2D or WEBGL

\n', + type: 'Constant', + optional: true + } + ], + return: { + description: '', + type: 'p5.Renderer' + }, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 50);\n background(153);\n line(0, 0, width, height);\n}\n\n
' + ], + alt: 'Black line extending from top-left of canvas to bottom right.', + class: 'p5', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/rendering.js', + line: 119, + description: + '

Resizes the canvas to given width and height. The canvas will be cleared\nand draw will be called immediately, allowing the sketch to re-render itself\nin the resized canvas.

\n', + itemtype: 'method', + name: 'resizeCanvas', + params: [ + { + name: 'w', + description: '

width of the canvas

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height of the canvas

\n', + type: 'Number' + }, + { + name: 'noRedraw', + description: '

don't redraw the canvas immediately

\n', + type: 'Boolean', + optional: true + } + ], + example: [ + '\n
\nfunction setup() {\n createCanvas(windowWidth, windowHeight);\n}\n\nfunction draw() {\n background(0, 100, 200);\n}\n\nfunction windowResized() {\n resizeCanvas(windowWidth, windowHeight);\n}\n
' + ], + alt: 'No image displayed.', + class: 'p5', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/rendering.js', + line: 174, + description: + '

Removes the default canvas for a p5 sketch that doesn't\nrequire a canvas

\n', + itemtype: 'method', + name: 'noCanvas', + example: [ + '\n
\n\nfunction setup() {\n noCanvas();\n}\n\n
' + ], + alt: 'no image displayed', + class: 'p5', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/rendering.js', + line: 197, + description: + '

Creates and returns a new p5.Renderer object. Use this class if you need\nto draw into an off-screen graphics buffer. The two parameters define the\nwidth and height in pixels.

\n', + itemtype: 'method', + name: 'createGraphics', + params: [ + { + name: 'w', + description: '

width of the offscreen graphics buffer

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height of the offscreen graphics buffer

\n', + type: 'Number' + }, + { + name: 'renderer', + description: '

either P2D or WEBGL\nundefined defaults to p2d

\n', + type: 'Constant', + optional: true + } + ], + return: { + description: 'offscreen graphics buffer', + type: 'p5.Graphics' + }, + example: [ + '\n
\n\nlet pg;\nfunction setup() {\n createCanvas(100, 100);\n pg = createGraphics(100, 100);\n}\nfunction draw() {\n background(200);\n pg.background(100);\n pg.noStroke();\n pg.ellipse(pg.width / 2, pg.height / 2, 50, 50);\n image(pg, 50, 50);\n image(pg, 0, 0, 50, 50);\n}\n\n
' + ], + alt: + '4 grey squares alternating light and dark grey. White quarter circle mid-left.', + class: 'p5', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/rendering.js', + line: 236, + description: + '

Blends the pixels in the display window according to the defined mode.\nThere is a choice of the following modes to blend the source pixels (A)\nwith the ones of pixels already in the display window (B):

\n

    \n

  • BLEND - linear interpolation of colours: C =\nA*factor + B. This is the default blending mode.
  • \n

  • ADD - sum of A and B
  • \n

  • DARKEST - only the darkest colour succeeds: C =\nmin(A*factor, B).
  • \n

  • LIGHTEST - only the lightest colour succeeds: C =\nmax(A*factor, B).
  • \n

  • DIFFERENCE - subtract colors from underlying image.
  • \n

  • EXCLUSION - similar to DIFFERENCE, but less\nextreme.
  • \n

  • MULTIPLY - multiply the colors, result will always be\ndarker.
  • \n

  • SCREEN - opposite multiply, uses inverse values of the\ncolors.
  • \n

  • REPLACE - the pixels entirely replace the others and\ndon't utilize alpha (transparency) values.
  • \n

  • OVERLAY - mix of MULTIPLY and SCREEN\n. Multiplies dark values, and screens light values. (2D)
  • \n

  • HARD_LIGHT - SCREEN when greater than 50%\ngray, MULTIPLY when lower. (2D)
  • \n

  • SOFT_LIGHT - mix of DARKEST and\nLIGHTEST. Works like OVERLAY, but not as harsh. (2D)\n
  • \n

  • DODGE - lightens light tones and increases contrast,\nignores darks. (2D)
  • \n

  • BURN - darker areas are applied, increasing contrast,\nignores lights. (2D)
  • \n

  • SUBTRACT - remainder of A and B (3D)
  • \n
\n

\n(2D) indicates that this blend mode only works in the 2D renderer.
\n(3D) indicates that this blend mode only works in the WEBGL renderer.

\n', + itemtype: 'method', + name: 'blendMode', + params: [ + { + name: 'mode', + description: + '

blend mode to set for canvas.\n either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY,\n EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD, or SUBTRACT

\n', + type: 'Constant' + } + ], + example: [ + '\n
\n\nblendMode(LIGHTEST);\nstrokeWeight(30);\nstroke(80, 150, 255);\nline(25, 25, 75, 75);\nstroke(255, 50, 50);\nline(75, 25, 25, 75);\n\n
\n
\n\nblendMode(MULTIPLY);\nstrokeWeight(30);\nstroke(80, 150, 255);\nline(25, 25, 75, 75);\nstroke(255, 50, 50);\nline(75, 25, 25, 75);\n\n
' + ], + alt: + 'translucent image thick red & blue diagonal rounded lines intersecting center\nThick red & blue diagonal rounded lines intersecting center. dark at overlap', + class: 'p5', + module: 'Rendering', + submodule: 'Rendering' + }, + { + file: 'src/core/shim.js', + line: 23, + description: + '

shim for Uint8ClampedArray.slice\n(allows arrayCopy to work with pixels[])\nwith thanks to http://halfpapstudios.com/blog/tag/html5-canvas/\nEnumerable set to false to protect for...in from\nUint8ClampedArray.prototype pollution.

\n', + class: 'p5', + module: 'Rendering' + }, + { + file: 'src/core/shim.js', + line: 45, + description: + '

this is implementation of Object.assign() which is unavailable in\nIE11 and (non-Chrome) Android browsers.\nThe assign() method is used to copy the values of all enumerable\nown properties from one or more source objects to a target object.\nIt will return the target object.\nModified from https://github.com/ljharb/object.assign

\n', + class: 'p5', + module: 'Rendering' + }, + { + file: 'src/core/structure.js', + line: 12, + description: + '

Stops p5.js from continuously executing the code within draw().\nIf loop() is called, the code in draw() begins to run continuously again.\nIf using noLoop() in setup(), it should be the last line inside the block.\n

\nWhen noLoop() is used, it's not possible to manipulate or access the\nscreen inside event handling functions such as mousePressed() or\nkeyPressed(). Instead, use those functions to call redraw() or loop(),\nwhich will run draw(), which can update the screen properly. This means\nthat when noLoop() has been called, no drawing can happen, and functions\nlike saveFrame() or loadPixels() may not be used.\n

\nNote that if the sketch is resized, redraw() will be called to update\nthe sketch, even after noLoop() has been specified. Otherwise, the sketch\nwould enter an odd state until loop() was called.

\n', + itemtype: 'method', + name: 'noLoop', + example: [ + '\n
\nfunction setup() {\n createCanvas(100, 100);\n background(200);\n noLoop();\n}\n\nfunction draw() {\n line(10, 10, 90, 90);\n}\n
\n\n
\nlet x = 0;\nfunction setup() {\n createCanvas(100, 100);\n}\n\nfunction draw() {\n background(204);\n x = x + 0.1;\n if (x > width) {\n x = 0;\n }\n line(x, 0, x, height);\n}\n\nfunction mousePressed() {\n noLoop();\n}\n\nfunction mouseReleased() {\n loop();\n}\n
' + ], + alt: + '113 pixel long line extending from top-left to bottom right of canvas.\nhorizontal line moves slowly from left. Loops but stops on mouse press.', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/structure.js', + line: 74, + description: + '

By default, p5.js loops through draw() continuously, executing the code\nwithin it. However, the draw() loop may be stopped by calling noLoop().\nIn that case, the draw() loop can be resumed with loop().

\n

Avoid calling loop() from inside setup().

\n', + itemtype: 'method', + name: 'loop', + example: [ + '\n
\nlet x = 0;\nfunction setup() {\n createCanvas(100, 100);\n noLoop();\n}\n\nfunction draw() {\n background(204);\n x = x + 0.1;\n if (x > width) {\n x = 0;\n }\n line(x, 0, x, height);\n}\n\nfunction mousePressed() {\n loop();\n}\n\nfunction mouseReleased() {\n noLoop();\n}\n
' + ], + alt: + 'horizontal line moves slowly from left. Loops but stops on mouse press.', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/structure.js', + line: 122, + description: + '

The push() function saves the current drawing style settings and\ntransformations, while pop() restores these settings. Note that these\nfunctions are always used together. They allow you to change the style\nand transformation settings and later return to what you had. When a new\nstate is started with push(), it builds on the current style and transform\ninformation. The push() and pop() functions can be embedded to provide\nmore control. (See the second example for a demonstration.)\n

\npush() stores information related to the current transformation state\nand style settings controlled by the following functions: fill(),\nstroke(), tint(), strokeWeight(), strokeCap(), strokeJoin(),\nimageMode(), rectMode(), ellipseMode(), colorMode(), textAlign(),\ntextFont(), textSize(), textLeading().\n

\nIn WEBGL mode additional style settings are stored. These are controlled by the following functions: setCamera(), ambientLight(), directionalLight(),\npointLight(), texture(), specularMaterial(), shininess(), normalMaterial()\nand shader().

\n', + itemtype: 'method', + name: 'push', + example: [ + '\n
\n\nellipse(0, 50, 33, 33); // Left circle\n\npush(); // Start a new drawing state\nstrokeWeight(10);\nfill(204, 153, 0);\ntranslate(50, 0);\nellipse(0, 50, 33, 33); // Middle circle\npop(); // Restore original state\n\nellipse(100, 50, 33, 33); // Right circle\n\n
\n
\n\nellipse(0, 50, 33, 33); // Left circle\n\npush(); // Start a new drawing state\nstrokeWeight(10);\nfill(204, 153, 0);\nellipse(33, 50, 33, 33); // Left-middle circle\n\npush(); // Start another new drawing state\nstroke(0, 102, 153);\nellipse(66, 50, 33, 33); // Right-middle circle\npop(); // Restore previous state\n\npop(); // Restore original state\n\nellipse(100, 50, 33, 33); // Right circle\n\n
' + ], + alt: + 'Gold ellipse + thick black outline @center 2 white ellipses on left and right.\n2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right.', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/structure.js', + line: 191, + description: + '

The push() function saves the current drawing style settings and\ntransformations, while pop() restores these settings. Note that these\nfunctions are always used together. They allow you to change the style\nand transformation settings and later return to what you had. When a new\nstate is started with push(), it builds on the current style and transform\ninformation. The push() and pop() functions can be embedded to provide\nmore control. (See the second example for a demonstration.)\n

\npush() stores information related to the current transformation state\nand style settings controlled by the following functions: fill(),\nstroke(), tint(), strokeWeight(), strokeCap(), strokeJoin(),\nimageMode(), rectMode(), ellipseMode(), colorMode(), textAlign(),\ntextFont(), textSize(), textLeading().\n

\nIn WEBGL mode additional style settings are stored. These are controlled by the following functions: setCamera(), ambientLight(), directionalLight(),\npointLight(), texture(), specularMaterial(), shininess(), normalMaterial()\nand shader().

\n', + itemtype: 'method', + name: 'pop', + example: [ + '\n
\n\nellipse(0, 50, 33, 33); // Left circle\n\npush(); // Start a new drawing state\ntranslate(50, 0);\nstrokeWeight(10);\nfill(204, 153, 0);\nellipse(0, 50, 33, 33); // Middle circle\npop(); // Restore original state\n\nellipse(100, 50, 33, 33); // Right circle\n\n
\n
\n\nellipse(0, 50, 33, 33); // Left circle\n\npush(); // Start a new drawing state\nstrokeWeight(10);\nfill(204, 153, 0);\nellipse(33, 50, 33, 33); // Left-middle circle\n\npush(); // Start another new drawing state\nstroke(0, 102, 153);\nellipse(66, 50, 33, 33); // Right-middle circle\npop(); // Restore previous state\n\npop(); // Restore original state\n\nellipse(100, 50, 33, 33); // Right circle\n\n
' + ], + alt: + 'Gold ellipse + thick black outline @center 2 white ellipses on left and right.\n2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right.', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/structure.js', + line: 261, + description: + '

Executes the code within draw() one time. This functions allows the\n program to update the display window only when necessary, for example\n when an event registered by mousePressed() or keyPressed() occurs.\n

\n In structuring a program, it only makes sense to call redraw() within\n events such as mousePressed(). This is because redraw() does not run\n draw() immediately (it only sets a flag that indicates an update is\n needed).\n

\n The redraw() function does not work properly when called inside draw().\n To enable/disable animations, use loop() and noLoop().\n

\n In addition you can set the number of redraws per method call. Just\n add an integer as single parameter for the number of redraws.

\n', + itemtype: 'method', + name: 'redraw', + params: [ + { + name: 'n', + description: '

Redraw for n-times. The default value is 1.

\n', + type: 'Integer', + optional: true + } + ], + example: [ + "\n
\n let x = 0;\nfunction setup() {\n createCanvas(100, 100);\n noLoop();\n }\nfunction draw() {\n background(204);\n line(x, 0, x, height);\n }\nfunction mousePressed() {\n x += 1;\n redraw();\n }\n
\n
\n let x = 0;\nfunction setup() {\n createCanvas(100, 100);\n noLoop();\n }\nfunction draw() {\n background(204);\n x += 1;\n line(x, 0, x, height);\n }\nfunction mousePressed() {\n redraw(5);\n }\n
" + ], + alt: 'black line on far left of canvas\n black line on far left of canvas', + class: 'p5', + module: 'Structure', + submodule: 'Structure' + }, + { + file: 'src/core/transform.js', + line: 13, + description: + '

Multiplies the current matrix by the one specified through the parameters.\nThis is a powerful operation that can perform the equivalent of translate,\nscale, shear and rotate all at once. You can learn more about transformation\nmatrices on \nWikipedia.

\n

The naming of the arguments here follows the naming of the \nWHATWG specification and corresponds to a\ntransformation matrix of the\nform:

\n
\n

\n
\n', + itemtype: 'method', + name: 'applyMatrix', + params: [ + { + name: 'a', + description: + '

numbers which define the 2x3 matrix to be multiplied

\n', + type: 'Number' + }, + { + name: 'b', + description: + '

numbers which define the 2x3 matrix to be multiplied

\n', + type: 'Number' + }, + { + name: 'c', + description: + '

numbers which define the 2x3 matrix to be multiplied

\n', + type: 'Number' + }, + { + name: 'd', + description: + '

numbers which define the 2x3 matrix to be multiplied

\n', + type: 'Number' + }, + { + name: 'e', + description: + '

numbers which define the 2x3 matrix to be multiplied

\n', + type: 'Number' + }, + { + name: 'f', + description: + '

numbers which define the 2x3 matrix to be multiplied

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nfunction setup() {\n frameRate(10);\n rectMode(CENTER);\n}\n\nfunction draw() {\n var step = frameCount % 20;\n background(200);\n // Equivalent to translate(x, y);\n applyMatrix(1, 0, 0, 1, 40 + step, 50);\n rect(0, 0, 50, 50);\n}\n\n
\n
\n\nfunction setup() {\n frameRate(10);\n rectMode(CENTER);\n}\n\nfunction draw() {\n var step = frameCount % 20;\n background(200);\n translate(50, 50);\n // Equivalent to scale(x, y);\n applyMatrix(1 / step, 0, 0, 1 / step, 0, 0);\n rect(0, 0, 50, 50);\n}\n\n
\n
\n\nfunction setup() {\n frameRate(10);\n rectMode(CENTER);\n}\n\nfunction draw() {\n var step = frameCount % 20;\n var angle = map(step, 0, 20, 0, TWO_PI);\n var cos_a = cos(angle);\n var sin_a = sin(angle);\n background(200);\n translate(50, 50);\n // Equivalent to rotate(angle);\n applyMatrix(cos_a, sin_a, -sin_a, cos_a, 0, 0);\n rect(0, 0, 50, 50);\n}\n\n
\n
\n\nfunction setup() {\n frameRate(10);\n rectMode(CENTER);\n}\n\nfunction draw() {\n var step = frameCount % 20;\n var angle = map(step, 0, 20, -PI / 4, PI / 4);\n background(200);\n translate(50, 50);\n // equivalent to shearX(angle);\n var shear_factor = 1 / tan(PI / 2 - angle);\n applyMatrix(1, 0, shear_factor, 1, 0, 0);\n rect(0, 0, 50, 50);\n}\n\n
\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n noFill();\n}\n\nfunction draw() {\n background(200);\n rotateY(PI / 6);\n stroke(153);\n box(35);\n var rad = millis() / 1000;\n // Set rotation angles\n var ct = cos(rad);\n var st = sin(rad);\n // Matrix for rotation around the Y axis\n applyMatrix( ct, 0.0, st, 0.0,\n 0.0, 1.0, 0.0, 0.0,\n -st, 0.0, ct, 0.0,\n 0.0, 0.0, 0.0, 1.0);\n stroke(255);\n box(50);\n}\n\n
" + ], + alt: + 'A rectangle translating to the right\nA rectangle shrinking to the center\nA rectangle rotating clockwise about the center\nA rectangle shearing', + class: 'p5', + module: 'Transform', + submodule: 'Transform' + }, + { + file: 'src/core/transform.js', + line: 150, + description: + '

Replaces the current matrix with the identity matrix.

\n', + itemtype: 'method', + name: 'resetMatrix', + chainable: 1, + example: [ + '\n
\n\ntranslate(50, 50);\napplyMatrix(0.5, 0.5, -0.5, 0.5, 0, 0);\nrect(0, 0, 20, 20);\n// Note that the translate is also reset.\nresetMatrix();\nrect(0, 0, 20, 20);\n\n
' + ], + alt: 'A rotated retangle in the center with another at the top left corner', + class: 'p5', + module: 'Transform', + submodule: 'Transform' + }, + { + file: 'src/core/transform.js', + line: 176, + description: + '

Rotates a shape the amount specified by the angle parameter. This\nfunction accounts for angleMode, so angles can be entered in either\nRADIANS or DEGREES.\n

\nObjects are always rotated around their relative position to the\norigin and positive numbers rotate objects in a clockwise direction.\nTransformations apply to everything that happens after and subsequent\ncalls to the function accumulates the effect. For example, calling\nrotate(HALF_PI) and then rotate(HALF_PI) is the same as rotate(PI).\nAll tranformations are reset when draw() begins again.\n

\nTechnically, rotate() multiplies the current transformation matrix\nby a rotation matrix. This function can be further controlled by\nthe push() and pop().

\n', + itemtype: 'method', + name: 'rotate', + params: [ + { + name: 'angle', + description: + '

the angle of rotation, specified in radians\n or degrees, depending on current angleMode

\n', + type: 'Number' + }, + { + name: 'axis', + description: '

(in 3d) the axis to rotate around

\n', + type: 'p5.Vector|Number[]', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\ntranslate(width / 2, height / 2);\nrotate(PI / 3.0);\nrect(-26, -26, 52, 52);\n\n
' + ], + alt: + 'white 52x52 rect with black outline at center rotated counter 45 degrees', + class: 'p5', + module: 'Transform', + submodule: 'Transform' + }, + { + file: 'src/core/transform.js', + line: 216, + description: '

Rotates around X axis.

\n', + itemtype: 'method', + name: 'rotateX', + params: [ + { + name: 'angle', + description: + '

the angle of rotation, specified in radians\n or degrees, depending on current angleMode

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(255);\n rotateX(millis() / 1000);\n box();\n}\n\n
" + ], + alt: '3d box rotating around the x axis.', + class: 'p5', + module: 'Transform', + submodule: 'Transform' + }, + { + file: 'src/core/transform.js', + line: 246, + description: '

Rotates around Y axis.

\n', + itemtype: 'method', + name: 'rotateY', + params: [ + { + name: 'angle', + description: + '

the angle of rotation, specified in radians\n or degrees, depending on current angleMode

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(255);\n rotateY(millis() / 1000);\n box();\n}\n\n
" + ], + alt: '3d box rotating around the y axis.', + class: 'p5', + module: 'Transform', + submodule: 'Transform' + }, + { + file: 'src/core/transform.js', + line: 276, + description: '

Rotates around Z axis. Webgl mode only.

\n', + itemtype: 'method', + name: 'rotateZ', + params: [ + { + name: 'angle', + description: + '

the angle of rotation, specified in radians\n or degrees, depending on current angleMode

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(255);\n rotateZ(millis() / 1000);\n box();\n}\n\n
" + ], + alt: '3d box rotating around the z axis.', + class: 'p5', + module: 'Transform', + submodule: 'Transform' + }, + { + file: 'src/core/transform.js', + line: 306, + description: + '

Increases or decreases the size of a shape by expanding and contracting\nvertices. Objects always scale from their relative origin to the\ncoordinate system. Scale values are specified as decimal percentages.\nFor example, the function call scale(2.0) increases the dimension of a\nshape by 200%.\n

\nTransformations apply to everything that happens after and subsequent\ncalls to the function multiply the effect. For example, calling scale(2.0)\nand then scale(1.5) is the same as scale(3.0). If scale() is called\nwithin draw(), the transformation is reset when the loop begins again.\n

\nUsing this function with the z parameter is only available in WEBGL mode.\nThis function can be further controlled with push() and pop().

\n', + itemtype: 'method', + name: 'scale', + chainable: 1, + example: [ + '\n
\n\nrect(30, 20, 50, 50);\nscale(0.5);\nrect(30, 20, 50, 50);\n\n
\n\n
\n\nrect(30, 20, 50, 50);\nscale(0.5, 1.3);\nrect(30, 20, 50, 50);\n\n
' + ], + alt: + 'white 52x52 rect with black outline at center rotated counter 45 degrees\n2 white rects with black outline- 1 50x50 at center. other 25x65 bottom left', + class: 'p5', + module: 'Transform', + submodule: 'Transform', + overloads: [ + { + line: 306, + params: [ + { + name: 's', + description: + '

percent to scale the object, or percentage to\n scale the object in the x-axis if multiple arguments\n are given

\n', + type: 'Number|p5.Vector|Number[]' + }, + { + name: 'y', + description: '

percent to scale the object in the y-axis

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: + '

percent to scale the object in the z-axis (webgl only)

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 351, + params: [ + { + name: 'scales', + description: '

per-axis percents to scale the object

\n', + type: 'p5.Vector|Number[]' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/core/transform.js', + line: 381, + description: + '

Shears a shape around the x-axis the amount specified by the angle\nparameter. Angles should be specified in the current angleMode.\nObjects are always sheared around their relative position to the origin\nand positive numbers shear objects in a clockwise direction.\n

\nTransformations apply to everything that happens after and subsequent\ncalls to the function accumulates the effect. For example, calling\nshearX(PI/2) and then shearX(PI/2) is the same as shearX(PI).\nIf shearX() is called within the draw(), the transformation is reset when\nthe loop begins again.\n

\nTechnically, shearX() multiplies the current transformation matrix by a\nrotation matrix. This function can be further controlled by the\npush() and pop() functions.

\n', + itemtype: 'method', + name: 'shearX', + params: [ + { + name: 'angle', + description: + '

angle of shear specified in radians or degrees,\n depending on current angleMode

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + '\n
\n\ntranslate(width / 4, height / 4);\nshearX(PI / 4.0);\nrect(0, 0, 30, 30);\n\n
' + ], + alt: 'white irregular quadrilateral with black outline at top middle.', + class: 'p5', + module: 'Transform', + submodule: 'Transform' + }, + { + file: 'src/core/transform.js', + line: 421, + description: + '

Shears a shape around the y-axis the amount specified by the angle\nparameter. Angles should be specified in the current angleMode. Objects\nare always sheared around their relative position to the origin and\npositive numbers shear objects in a clockwise direction.\n

\nTransformations apply to everything that happens after and subsequent\ncalls to the function accumulates the effect. For example, calling\nshearY(PI/2) and then shearY(PI/2) is the same as shearY(PI). If\nshearY() is called within the draw(), the transformation is reset when\nthe loop begins again.\n

\nTechnically, shearY() multiplies the current transformation matrix by a\nrotation matrix. This function can be further controlled by the\npush() and pop() functions.

\n', + itemtype: 'method', + name: 'shearY', + params: [ + { + name: 'angle', + description: + '

angle of shear specified in radians or degrees,\n depending on current angleMode

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + '\n
\n\ntranslate(width / 4, height / 4);\nshearY(PI / 4.0);\nrect(0, 0, 30, 30);\n\n
' + ], + alt: 'white irregular quadrilateral with black outline at middle bottom.', + class: 'p5', + module: 'Transform', + submodule: 'Transform' + }, + { + file: 'src/core/transform.js', + line: 461, + description: + '

Specifies an amount to displace objects within the display window.\nThe x parameter specifies left/right translation, the y parameter\nspecifies up/down translation.\n

\nTransformations are cumulative and apply to everything that happens after\nand subsequent calls to the function accumulates the effect. For example,\ncalling translate(50, 0) and then translate(20, 0) is the same as\ntranslate(70, 0). If translate() is called within draw(), the\ntransformation is reset when the loop begins again. This function can be\nfurther controlled by using push() and pop().

\n', + itemtype: 'method', + name: 'translate', + chainable: 1, + example: [ + '\n
\n\ntranslate(30, 20);\nrect(0, 0, 55, 55);\n\n
\n\n
\n\nrect(0, 0, 55, 55); // Draw rect at original 0,0\ntranslate(30, 20);\nrect(0, 0, 55, 55); // Draw rect at new 0,0\ntranslate(14, 14);\nrect(0, 0, 55, 55); // Draw rect at new 0,0\n\n
\n\n\n
\n\nfunction draw() {\n background(200);\n rectMode(CENTER);\n translate(width / 2, height / 2);\n translate(p5.Vector.fromAngle(millis() / 1000, 40));\n rect(0, 0, 20, 20);\n}\n\n
' + ], + alt: + 'white 55x55 rect with black outline at center right.\n3 white 55x55 rects with black outlines at top-l, center-r and bottom-r.\na 20x20 white rect moving in a circle around the canvas', + class: 'p5', + module: 'Transform', + submodule: 'Transform', + overloads: [ + { + line: 461, + params: [ + { + name: 'x', + description: '

left/right translation

\n', + type: 'Number' + }, + { + name: 'y', + description: '

up/down translation

\n', + type: 'Number' + }, + { + name: 'z', + description: '

forward/backward translation (webgl only)

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 515, + params: [ + { + name: 'vector', + description: '

the vector to translate by

\n', + type: 'p5.Vector' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/data/local_storage.js', + line: 11, + description: + '

Stores a value in local storage under the key name.\n Local storage is saved in the browser and persists\n between browsing sessions and page reloads.\n The key can be the name of the variable but doesn't\n have to be. To retrieve stored items\n see getItem.\n

\n Sensitive data such as passwords or personal information\n should not be stored in local storage.

\n', + itemtype: 'method', + name: 'storeItem', + params: [ + { + name: 'key', + description: '', + type: 'String' + }, + { + name: 'value', + description: '', + type: 'String|Number|Object|Boolean|p5.Color' + } + ], + example: [ + "\n
\n // Type to change the letter in the\n // center of the canvas.\n // If you reload the page, it will\n // still display the last key you entered\nlet myText;\nfunction setup() {\n createCanvas(100, 100);\n myText = getItem('myText');\n if (myText === null) {\n myText = '';\n }\n }\nfunction draw() {\n textSize(40);\n background(255);\n text(myText, width / 2, height / 2);\n }\nfunction keyPressed() {\n myText = key;\n storeItem('myText', myText);\n }\n
" + ], + alt: + 'When you type the key name is displayed as black text on white background.\n If you reload the page, the last letter typed is still displaying.', + class: 'p5', + module: 'Data', + submodule: 'LocalStorage' + }, + { + file: 'src/data/local_storage.js', + line: 88, + description: + '

Returns the value of an item that was stored in local storage\n using storeItem()

\n', + itemtype: 'method', + name: 'getItem', + params: [ + { + name: 'key', + description: + '

name that you wish to use to store in local storage

\n', + type: 'String' + } + ], + return: { + description: 'Value of stored item', + type: 'Number|Object|String|Boolean|p5.Color' + }, + example: [ + "\n
\n // Click the mouse to change\n // the color of the background\n // Once you have changed the color\n // it will stay changed even when you\n // reload the page.\nlet myColor;\nfunction setup() {\n createCanvas(100, 100);\n myColor = getItem('myColor');\n }\nfunction draw() {\n if (myColor !== null) {\n background(myColor);\n }\n }\nfunction mousePressed() {\n myColor = color(random(255), random(255), random(255));\n storeItem('myColor', myColor);\n }\n
" + ], + alt: + 'If you click, the canvas changes to a random color.\n If you reload the page, the canvas is still the color it\n was when the page was previously loaded.', + class: 'p5', + module: 'Data', + submodule: 'LocalStorage' + }, + { + file: 'src/data/local_storage.js', + line: 163, + description: + '

Clears all local storage items set with storeItem()\n for the current domain.

\n', + itemtype: 'method', + name: 'clearStorage', + example: [ + "\n
\n \n function setup() {\n let myNum = 10;\n let myBool = false;\n storeItem('myNum', myNum);\n storeItem('myBool', myBool);\n print(getItem('myNum')); // logs 10 to the console\n print(getItem('myBool')); // logs false to the console\n clearStorage();\n print(getItem('myNum')); // logs null to the console\n print(getItem('myBool')); // logs null to the console\n }\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'LocalStorage' + }, + { + file: 'src/data/local_storage.js', + line: 191, + description: '

Removes an item that was stored with storeItem()

\n', + itemtype: 'method', + name: 'removeItem', + params: [ + { + name: 'key', + description: '', + type: 'String' + } + ], + example: [ + "\n
\n \n function setup() {\n let myVar = 10;\n storeItem('myVar', myVar);\n print(getItem('myVar')); // logs 10 to the console\n removeItem('myVar');\n print(getItem('myVar')); // logs null to the console\n }\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'LocalStorage' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 16, + description: + '

Creates a new instance of p5.StringDict using the key-value pair\n or the object you provide.

\n', + itemtype: 'method', + name: 'createStringDict', + return: { + description: '', + type: 'p5.StringDict' + }, + example: [ + "\n
\n \n function setup() {\n let myDictionary = createStringDict('p5', 'js');\n print(myDictionary.hasKey('p5')); // logs true to console\n let anotherDictionary = createStringDict({ happy: 'coding' });\n print(anotherDictionary.hasKey('happy')); // logs true to console\n }\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Dictionary', + overloads: [ + { + line: 16, + params: [ + { + name: 'key', + description: '', + type: 'String' + }, + { + name: 'value', + description: '', + type: 'String' + } + ], + return: { + description: '', + type: 'p5.StringDict' + } + }, + { + line: 39, + params: [ + { + name: 'object', + description: '

object

\n', + type: 'Object' + } + ], + return: { + description: '', + type: 'p5.StringDict' + } + } + ] + }, + { + file: 'src/data/p5.TypedDict.js', + line: 50, + description: + '

Creates a new instance of p5.NumberDict using the key-value pair\n or object you provide.

\n', + itemtype: 'method', + name: 'createNumberDict', + return: { + description: '', + type: 'p5.NumberDict' + }, + example: [ + '\n
\n \n function setup() {\n let myDictionary = createNumberDict(100, 42);\n print(myDictionary.hasKey(100)); // logs true to console\n let anotherDictionary = createNumberDict({ 200: 84 });\n print(anotherDictionary.hasKey(200)); // logs true to console\n }\n
' + ], + class: 'p5', + module: 'Data', + submodule: 'Dictionary', + overloads: [ + { + line: 50, + params: [ + { + name: 'key', + description: '', + type: 'Number' + }, + { + name: 'value', + description: '', + type: 'Number' + } + ], + return: { + description: '', + type: 'p5.NumberDict' + } + }, + { + line: 73, + params: [ + { + name: 'object', + description: '

object

\n', + type: 'Object' + } + ], + return: { + description: '', + type: 'p5.NumberDict' + } + } + ] + }, + { + file: 'src/data/p5.TypedDict.js', + line: 103, + description: + '

Returns the number of key-value pairs currently stored in the Dictionary.

\n', + itemtype: 'method', + name: 'size', + return: { + description: 'the number of key-value pairs in the Dictionary', + type: 'Integer' + }, + example: [ + '\n
\n\nfunction setup() {\n let myDictionary = createNumberDict(1, 10);\n myDictionary.create(2, 20);\n myDictionary.create(3, 30);\n print(myDictionary.size()); // logs 3 to the console\n}\n
\n' + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 125, + description: + '

Returns true if the given key exists in the Dictionary,\notherwise returns false.

\n', + itemtype: 'method', + name: 'hasKey', + params: [ + { + name: 'key', + description: '

that you want to look up

\n', + type: 'Number|String' + } + ], + return: { + description: 'whether that key exists in Dictionary', + type: 'Boolean' + }, + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createStringDict('p5', 'js');\n print(myDictionary.hasKey('p5')); // logs true to console\n}\n
\n" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 148, + description: '

Returns the value stored at the given key.

\n', + itemtype: 'method', + name: 'get', + params: [ + { + name: 'the', + description: '

key you want to access

\n', + type: 'Number|String' + } + ], + return: { + description: 'the value stored at that key', + type: 'Number|String' + }, + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createStringDict('p5', 'js');\n let myValue = myDictionary.get('p5');\n print(myValue === 'js'); // logs true to console\n}\n
\n" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 175, + description: + '

Updates the value associated with the given key in case it already exists\nin the Dictionary. Otherwise a new key-value pair is added.

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'key', + description: '', + type: 'Number|String' + }, + { + name: 'value', + description: '', + type: 'Number|String' + } + ], + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createStringDict('p5', 'js');\n myDictionary.set('p5', 'JS');\n myDictionary.print(); // logs \"key: p5 - value: JS\" to console\n}\n
\n" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 203, + description: + '

private helper function to handle the user passing in objects\nduring construction or calls to create()

\n', + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 214, + description: '

Creates a new key-value pair in the Dictionary.

\n', + itemtype: 'method', + name: 'create', + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createStringDict('p5', 'js');\n myDictionary.create('happy', 'coding');\n myDictionary.print();\n // above logs \"key: p5 - value: js, key: happy - value: coding\" to console\n}\n
" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary', + overloads: [ + { + line: 214, + params: [ + { + name: 'key', + description: '', + type: 'Number|String' + }, + { + name: 'value', + description: '', + type: 'Number|String' + } + ] + }, + { + line: 232, + params: [ + { + name: 'obj', + description: '

key/value pair

\n', + type: 'Object' + } + ] + } + ] + }, + { + file: 'src/data/p5.TypedDict.js', + line: 250, + description: + '

Removes all previously stored key-value pairs from the Dictionary.

\n', + itemtype: 'method', + name: 'clear', + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createStringDict('p5', 'js');\n print(myDictionary.hasKey('p5')); // prints 'true'\n myDictionary.clear();\n print(myDictionary.hasKey('p5')); // prints 'false'\n}\n\n
" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 271, + description: + '

Removes the key-value pair stored at the given key from the Dictionary.

\n', + itemtype: 'method', + name: 'remove', + params: [ + { + name: 'key', + description: '

for the pair to remove

\n', + type: 'Number|String' + } + ], + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createStringDict('p5', 'js');\n myDictionary.create('happy', 'coding');\n myDictionary.print();\n // above logs \"key: p5 - value: js, key: happy - value: coding\" to console\n myDictionary.remove('p5');\n myDictionary.print();\n // above logs \"key: happy value: coding\" to console\n}\n
\n" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 301, + description: + '

Logs the set of items currently stored in the Dictionary to the console.

\n', + itemtype: 'method', + name: 'print', + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createStringDict('p5', 'js');\n myDictionary.create('happy', 'coding');\n myDictionary.print();\n // above logs \"key: p5 - value: js, key: happy - value: coding\" to console\n}\n\n
" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 325, + description: + '

Converts the Dictionary into a CSV file for local download.

\n', + itemtype: 'method', + name: 'saveTable', + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100);\n background(200);\n text('click here to save', 10, 10, 70, 80);\n}\n\nfunction mousePressed() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n createStringDict({\n john: 1940,\n paul: 1942,\n george: 1943,\n ringo: 1940\n }).saveTable('beatles');\n }\n}\n\n
" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 363, + description: + '

Converts the Dictionary into a JSON file for local download.

\n', + itemtype: 'method', + name: 'saveJSON', + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100);\n background(200);\n text('click here to save', 10, 10, 70, 80);\n}\n\nfunction mousePressed() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n createStringDict({\n john: 1940,\n paul: 1942,\n george: 1943,\n ringo: 1940\n }).saveJSON('beatles');\n }\n}\n\n
" + ], + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 394, + description: + '

private helper function to ensure that the user passed in valid\nvalues for the Dictionary type

\n', + class: 'p5.TypedDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 437, + description: + '

private helper function to ensure that the user passed in valid\nvalues for the Dictionary type

\n', + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 446, + description: + '

Add the given number to the value currently stored at the given key.\nThe sum then replaces the value previously stored in the Dictionary.

\n', + itemtype: 'method', + name: 'add', + params: [ + { + name: 'Key', + description: '

for the value you wish to add to

\n', + type: 'Number' + }, + { + name: 'Number', + description: '

to add to the value

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createNumberDict(2, 5);\n myDictionary.add(2, 2);\n print(myDictionary.get(2)); // logs 7 to console.\n}\n
\n\n" + ], + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 474, + description: + '

Subtract the given number from the value currently stored at the given key.\nThe difference then replaces the value previously stored in the Dictionary.

\n', + itemtype: 'method', + name: 'sub', + params: [ + { + name: 'Key', + description: '

for the value you wish to subtract from

\n', + type: 'Number' + }, + { + name: 'Number', + description: '

to subtract from the value

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createNumberDict(2, 5);\n myDictionary.sub(2, 2);\n print(myDictionary.get(2)); // logs 3 to console.\n}\n
\n\n" + ], + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 498, + description: + '

Multiply the given number with the value currently stored at the given key.\nThe product then replaces the value previously stored in the Dictionary.

\n', + itemtype: 'method', + name: 'mult', + params: [ + { + name: 'Key', + description: '

for value you wish to multiply

\n', + type: 'Number' + }, + { + name: 'Amount', + description: '

to multiply the value by

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createNumberDict(2, 4);\n myDictionary.mult(2, 2);\n print(myDictionary.get(2)); // logs 8 to console.\n}\n
\n\n" + ], + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 526, + description: + '

Divide the given number with the value currently stored at the given key.\nThe quotient then replaces the value previously stored in the Dictionary.

\n', + itemtype: 'method', + name: 'div', + params: [ + { + name: 'Key', + description: '

for value you wish to divide

\n', + type: 'Number' + }, + { + name: 'Amount', + description: '

to divide the value by

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createNumberDict(2, 8);\n myDictionary.div(2, 2);\n print(myDictionary.get(2)); // logs 4 to console.\n}\n
\n\n" + ], + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 554, + description: + '

private helper function for finding lowest or highest value\nthe argument 'flip' is used to flip the comparison arrow\nfrom 'less than' to 'greater than'

\n', + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 579, + description: + '

Return the lowest number currently stored in the Dictionary.

\n', + itemtype: 'method', + name: 'minValue', + return: { + description: '', + type: 'Number' + }, + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });\n let lowestValue = myDictionary.minValue(); // value is -10\n print(lowestValue);\n}\n
\n" + ], + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 600, + description: + '

Return the highest number currently stored in the Dictionary.

\n', + itemtype: 'method', + name: 'maxValue', + return: { + description: '', + type: 'Number' + }, + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });\n let highestValue = myDictionary.maxValue(); // value is 3\n print(highestValue);\n}\n
\n" + ], + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 621, + description: + '

private helper function for finding lowest or highest key\nthe argument 'flip' is used to flip the comparison arrow\nfrom 'less than' to 'greater than'

\n', + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 644, + description: + '

Return the lowest key currently used in the Dictionary.

\n', + itemtype: 'method', + name: 'minKey', + return: { + description: '', + type: 'Number' + }, + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });\n let lowestKey = myDictionary.minKey(); // value is 1.2\n print(lowestKey);\n}\n
\n" + ], + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/data/p5.TypedDict.js', + line: 665, + description: + '

Return the highest key currently used in the Dictionary.

\n', + itemtype: 'method', + name: 'maxKey', + return: { + description: '', + type: 'Number' + }, + example: [ + "\n
\n\nfunction setup() {\n let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });\n let highestKey = myDictionary.maxKey(); // value is 4\n print(highestKey);\n}\n
\n" + ], + class: 'p5.NumberDict', + module: 'Data', + submodule: 'Dictionary' + }, + { + file: 'src/events/acceleration.js', + line: 12, + description: + '

The system variable deviceOrientation always contains the orientation of\nthe device. The value of this variable will either be set 'landscape'\nor 'portrait'. If no data is available it will be set to 'undefined'.\neither LANDSCAPE or PORTRAIT.

\n', + itemtype: 'property', + name: 'deviceOrientation', + type: 'Constant', + readonly: '', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 23, + description: + '

The system variable accelerationX always contains the acceleration of the\ndevice along the x axis. Value is represented as meters per second squared.

\n', + itemtype: 'property', + name: 'accelerationX', + type: 'Number', + readonly: '', + example: [ + "\n
\n\n// Move a touchscreen device to register\n// acceleration changes.\nfunction draw() {\n background(220, 50);\n fill('magenta');\n ellipse(width / 2, height / 2, accelerationX);\n}\n\n
" + ], + alt: 'Magnitude of device acceleration is displayed as ellipse size', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 46, + description: + '

The system variable accelerationY always contains the acceleration of the\ndevice along the y axis. Value is represented as meters per second squared.

\n', + itemtype: 'property', + name: 'accelerationY', + type: 'Number', + readonly: '', + example: [ + "\n
\n\n// Move a touchscreen device to register\n// acceleration changes.\nfunction draw() {\n background(220, 50);\n fill('magenta');\n ellipse(width / 2, height / 2, accelerationY);\n}\n\n
" + ], + alt: 'Magnitude of device acceleration is displayed as ellipse size', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 69, + description: + '

The system variable accelerationZ always contains the acceleration of the\ndevice along the z axis. Value is represented as meters per second squared.

\n', + itemtype: 'property', + name: 'accelerationZ', + type: 'Number', + readonly: '', + example: [ + "\n
\n\n// Move a touchscreen device to register\n// acceleration changes.\nfunction draw() {\n background(220, 50);\n fill('magenta');\n ellipse(width / 2, height / 2, accelerationZ);\n}\n\n
" + ], + alt: 'Magnitude of device acceleration is displayed as ellipse size', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 94, + description: + '

The system variable pAccelerationX always contains the acceleration of the\ndevice along the x axis in the frame previous to the current frame. Value\nis represented as meters per second squared.

\n', + itemtype: 'property', + name: 'pAccelerationX', + type: 'Number', + readonly: '', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 104, + description: + '

The system variable pAccelerationY always contains the acceleration of the\ndevice along the y axis in the frame previous to the current frame. Value\nis represented as meters per second squared.

\n', + itemtype: 'property', + name: 'pAccelerationY', + type: 'Number', + readonly: '', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 114, + description: + '

The system variable pAccelerationZ always contains the acceleration of the\ndevice along the z axis in the frame previous to the current frame. Value\nis represented as meters per second squared.

\n', + itemtype: 'property', + name: 'pAccelerationZ', + type: 'Number', + readonly: '', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 135, + description: + '

The system variable rotationX always contains the rotation of the\ndevice along the x axis. Value is represented as 0 to +/-180 degrees.\n

\nNote: The order the rotations are called is important, ie. if used\ntogether, it must be called in the order Z-X-Y or there might be\nunexpected behaviour.

\n', + itemtype: 'property', + name: 'rotationX', + type: 'Number', + readonly: '', + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n //rotateZ(radians(rotationZ));\n rotateX(radians(rotationX));\n //rotateY(radians(rotationY));\n box(200, 200, 200);\n}\n\n
' + ], + alt: + 'red horizontal line right, green vertical line bottom. black background.', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 166, + description: + '

The system variable rotationY always contains the rotation of the\ndevice along the y axis. Value is represented as 0 to +/-90 degrees.\n

\nNote: The order the rotations are called is important, ie. if used\ntogether, it must be called in the order Z-X-Y or there might be\nunexpected behaviour.

\n', + itemtype: 'property', + name: 'rotationY', + type: 'Number', + readonly: '', + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n //rotateZ(radians(rotationZ));\n //rotateX(radians(rotationX));\n rotateY(radians(rotationY));\n box(200, 200, 200);\n}\n\n
' + ], + alt: + 'red horizontal line right, green vertical line bottom. black background.', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 197, + description: + '

The system variable rotationZ always contains the rotation of the\ndevice along the z axis. Value is represented as 0 to 359 degrees.\n

\nUnlike rotationX and rotationY, this variable is available for devices\nwith a built-in compass only.\n

\nNote: The order the rotations are called is important, ie. if used\ntogether, it must be called in the order Z-X-Y or there might be\nunexpected behaviour.

\n', + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n rotateZ(radians(rotationZ));\n //rotateX(radians(rotationX));\n //rotateY(radians(rotationY));\n box(200, 200, 200);\n}\n\n
' + ], + itemtype: 'property', + name: 'rotationZ', + type: 'Number', + readonly: '', + alt: + 'red horizontal line right, green vertical line bottom. black background.', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 233, + description: + '

The system variable pRotationX always contains the rotation of the\ndevice along the x axis in the frame previous to the current frame. Value\nis represented as 0 to +/-180 degrees.\n

\npRotationX can also be used with rotationX to determine the rotate\ndirection of the device along the X-axis.

\n', + example: [ + "\n
\n\n// A simple if statement looking at whether\n// rotationX - pRotationX < 0 is true or not will be\n// sufficient for determining the rotate direction\n// in most cases.\n\n// Some extra logic is needed to account for cases where\n// the angles wrap around.\nlet rotateDirection = 'clockwise';\n\n// Simple range conversion to make things simpler.\n// This is not absolutely necessary but the logic\n// will be different in that case.\n\nlet rX = rotationX + 180;\nlet pRX = pRotationX + 180;\n\nif ((rX - pRX > 0 && rX - pRX < 270) || rX - pRX < -270) {\n rotateDirection = 'clockwise';\n} else if (rX - pRX < 0 || rX - pRX > 270) {\n rotateDirection = 'counter-clockwise';\n}\n\nprint(rotateDirection);\n\n
" + ], + alt: 'no image to display.', + itemtype: 'property', + name: 'pRotationX', + type: 'Number', + readonly: '', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 278, + description: + '

The system variable pRotationY always contains the rotation of the\ndevice along the y axis in the frame previous to the current frame. Value\nis represented as 0 to +/-90 degrees.\n

\npRotationY can also be used with rotationY to determine the rotate\ndirection of the device along the Y-axis.

\n', + example: [ + "\n
\n\n// A simple if statement looking at whether\n// rotationY - pRotationY < 0 is true or not will be\n// sufficient for determining the rotate direction\n// in most cases.\n\n// Some extra logic is needed to account for cases where\n// the angles wrap around.\nlet rotateDirection = 'clockwise';\n\n// Simple range conversion to make things simpler.\n// This is not absolutely necessary but the logic\n// will be different in that case.\n\nlet rY = rotationY + 180;\nlet pRY = pRotationY + 180;\n\nif ((rY - pRY > 0 && rY - pRY < 270) || rY - pRY < -270) {\n rotateDirection = 'clockwise';\n} else if (rY - pRY < 0 || rY - pRY > 270) {\n rotateDirection = 'counter-clockwise';\n}\nprint(rotateDirection);\n\n
" + ], + alt: 'no image to display.', + itemtype: 'property', + name: 'pRotationY', + type: 'Number', + readonly: '', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 322, + description: + '

The system variable pRotationZ always contains the rotation of the\ndevice along the z axis in the frame previous to the current frame. Value\nis represented as 0 to 359 degrees.\n

\npRotationZ can also be used with rotationZ to determine the rotate\ndirection of the device along the Z-axis.

\n', + example: [ + "\n
\n\n// A simple if statement looking at whether\n// rotationZ - pRotationZ < 0 is true or not will be\n// sufficient for determining the rotate direction\n// in most cases.\n\n// Some extra logic is needed to account for cases where\n// the angles wrap around.\nlet rotateDirection = 'clockwise';\n\nif (\n (rotationZ - pRotationZ > 0 && rotationZ - pRotationZ < 270) ||\n rotationZ - pRotationZ < -270\n) {\n rotateDirection = 'clockwise';\n} else if (rotationZ - pRotationZ < 0 || rotationZ - pRotationZ > 270) {\n rotateDirection = 'counter-clockwise';\n}\nprint(rotateDirection);\n\n
" + ], + alt: 'no image to display.', + itemtype: 'property', + name: 'pRotationZ', + type: 'Number', + readonly: '', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 380, + description: + '

When a device is rotated, the axis that triggers the deviceTurned()\nmethod is stored in the turnAxis variable. The turnAxis variable is only defined within\nthe scope of deviceTurned().

\n', + itemtype: 'property', + name: 'turnAxis', + type: 'String', + readonly: '', + example: [ + "\n
\n\n// Run this example on a mobile device\n// Rotate the device by 90 degrees in the\n// X-axis to change the value.\n\nvar value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceTurned() {\n if (turnAxis === 'X') {\n if (value === 0) {\n value = 255;\n } else if (value === 255) {\n value = 0;\n }\n }\n}\n\n
" + ], + alt: + '50x50 black rect in center of canvas. turns white on mobile when device turns\n50x50 black rect in center of canvas. turns white on mobile when x-axis turns', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 419, + description: + '

The setMoveThreshold() function is used to set the movement threshold for\nthe deviceMoved() function. The default threshold is set to 0.5.

\n', + itemtype: 'method', + name: 'setMoveThreshold', + params: [ + { + name: 'value', + description: '

The threshold value

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\n// Run this example on a mobile device\n// You will need to move the device incrementally further\n// the closer the square\'s color gets to white in order to change the value.\n\nlet value = 0;\nlet threshold = 0.5;\nfunction setup() {\n setMoveThreshold(threshold);\n}\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceMoved() {\n value = value + 5;\n threshold = threshold + 0.1;\n if (value > 255) {\n value = 0;\n threshold = 30;\n }\n setMoveThreshold(threshold);\n}\n\n
' + ], + alt: + '50x50 black rect in center of canvas. turns white on mobile when device moves', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 462, + description: + '

The setShakeThreshold() function is used to set the movement threshold for\nthe deviceShaken() function. The default threshold is set to 30.

\n', + itemtype: 'method', + name: 'setShakeThreshold', + params: [ + { + name: 'value', + description: '

The threshold value

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\n// Run this example on a mobile device\n// You will need to shake the device more firmly\n// the closer the box\'s fill gets to white in order to change the value.\n\nlet value = 0;\nlet threshold = 30;\nfunction setup() {\n setShakeThreshold(threshold);\n}\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceMoved() {\n value = value + 5;\n threshold = threshold + 5;\n if (value > 255) {\n value = 0;\n threshold = 30;\n }\n setShakeThreshold(threshold);\n}\n\n
' + ], + alt: + '50x50 black rect in center of canvas. turns white on mobile when device\nis being shaked', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 506, + description: + '

The deviceMoved() function is called when the device is moved by more than\nthe threshold value along X, Y or Z axis. The default threshold is set to 0.5.\nThe threshold value can be changed using setMoveThreshold().

\n', + itemtype: 'method', + name: 'deviceMoved', + example: [ + '\n
\n\n// Run this example on a mobile device\n// Move the device around\n// to change the value.\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceMoved() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n\n
' + ], + alt: + '50x50 black rect in center of canvas. turns white on mobile when device moves', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 538, + description: + '

The deviceTurned() function is called when the device rotates by\nmore than 90 degrees continuously.\n

\nThe axis that triggers the deviceTurned() method is stored in the turnAxis\nvariable. The deviceTurned() method can be locked to trigger on any axis:\nX, Y or Z by comparing the turnAxis variable to 'X', 'Y' or 'Z'.

\n', + itemtype: 'method', + name: 'deviceTurned', + example: [ + '\n
\n\n// Run this example on a mobile device\n// Rotate the device by 90 degrees\n// to change the value.\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceTurned() {\n if (value === 0) {\n value = 255;\n } else if (value === 255) {\n value = 0;\n }\n}\n\n
\n
\n\n// Run this example on a mobile device\n// Rotate the device by 90 degrees in the\n// X-axis to change the value.\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceTurned() {\n if (turnAxis === \'X\') {\n if (value === 0) {\n value = 255;\n } else if (value === 255) {\n value = 0;\n }\n }\n}\n\n
' + ], + alt: + '50x50 black rect in center of canvas. turns white on mobile when device turns\n50x50 black rect in center of canvas. turns white on mobile when x-axis turns', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/acceleration.js', + line: 597, + description: + '

The deviceShaken() function is called when the device total acceleration\nchanges of accelerationX and accelerationY values is more than\nthe threshold value. The default threshold is set to 30.\nThe threshold value can be changed using setShakeThreshold().

\n', + itemtype: 'method', + name: 'deviceShaken', + example: [ + '\n
\n\n// Run this example on a mobile device\n// Shake the device to change the value.\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction deviceShaken() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n\n
' + ], + alt: + '50x50 black rect in center of canvas. turns white on mobile when device shakes', + class: 'p5', + module: 'Events', + submodule: 'Acceleration' + }, + { + file: 'src/events/keyboard.js', + line: 12, + description: + '

The boolean system variable keyIsPressed is true if any key is pressed\nand false if no keys are pressed.

\n', + itemtype: 'property', + name: 'keyIsPressed', + type: 'Boolean', + readonly: '', + example: [ + '\n
\n\nfunction draw() {\n if (keyIsPressed === true) {\n fill(0);\n } else {\n fill(255);\n }\n rect(25, 25, 50, 50);\n}\n\n
' + ], + alt: '50x50 white rect that turns black on keypress.', + class: 'p5', + module: 'Events', + submodule: 'Keyboard' + }, + { + file: 'src/events/keyboard.js', + line: 39, + description: + '

The system variable key always contains the value of the most recent\nkey on the keyboard that was typed. To get the proper capitalization, it\nis best to use it within keyTyped(). For non-ASCII keys, use the keyCode\nvariable.

\n', + itemtype: 'property', + name: 'key', + type: 'String', + readonly: '', + example: [ + '\n
\n// Click any key to display it!\n// (Not Guaranteed to be Case Sensitive)\nfunction setup() {\n fill(245, 123, 158);\n textSize(50);\n}\n\nfunction draw() {\n background(200);\n text(key, 33, 65); // Display last key pressed.\n}\n
' + ], + alt: 'canvas displays any key value that is pressed in pink font.', + class: 'p5', + module: 'Events', + submodule: 'Keyboard' + }, + { + file: 'src/events/keyboard.js', + line: 68, + description: + '

The variable keyCode is used to detect special keys such as BACKSPACE,\nDELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, OPTION, ALT, UP_ARROW,\nDOWN_ARROW, LEFT_ARROW, RIGHT_ARROW.\nYou can also check for custom keys by looking up the keyCode of any key\non a site like this: keycode.info.

\n', + itemtype: 'property', + name: 'keyCode', + type: 'Integer', + readonly: '', + example: [ + "\n
\nlet fillVal = 126;\nfunction draw() {\n fill(fillVal);\n rect(25, 25, 50, 50);\n}\n\nfunction keyPressed() {\n if (keyCode === UP_ARROW) {\n fillVal = 255;\n } else if (keyCode === DOWN_ARROW) {\n fillVal = 0;\n }\n return false; // prevent default\n}\n
\n
\nfunction draw() {}\nfunction keyPressed() {\n background('yellow');\n text(`${key} ${keyCode}`, 10, 40);\n print(key, ' ', keyCode);\n return false; // prevent default\n}\n
" + ], + alt: + 'Grey rect center. turns white when up arrow pressed and black when down\nDisplay key pressed and its keyCode in a yellow box', + class: 'p5', + module: 'Events', + submodule: 'Keyboard' + }, + { + file: 'src/events/keyboard.js', + line: 109, + description: + '

The keyPressed() function is called once every time a key is pressed. The\nkeyCode for the key that was pressed is stored in the keyCode variable.\n

\nFor non-ASCII keys, use the keyCode variable. You can check if the keyCode\nequals BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL,\nOPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW.\n

\nFor ASCII keys, the key that was pressed is stored in the key variable. However, it\ndoes not distinguish between uppercase and lowercase. For this reason, it\nis recommended to use keyTyped() to read the key variable, in which the\ncase of the variable will be distinguished.\n

\nBecause of how operating systems handle key repeats, holding down a key\nmay cause multiple calls to keyTyped() (and keyReleased() as well). The\nrate of repeat is set by the operating system and how each computer is\nconfigured.

\nBrowsers may have different default\nbehaviors attached to various key events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.

\n', + itemtype: 'method', + name: 'keyPressed', + example: [ + '\n
\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction keyPressed() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n\n
\n
\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction keyPressed() {\n if (keyCode === LEFT_ARROW) {\n value = 255;\n } else if (keyCode === RIGHT_ARROW) {\n value = 0;\n }\n}\n\n
\n
\n\nfunction keyPressed() {\n // Do something\n return false; // prevent any default behaviour\n}\n\n
' + ], + alt: + 'black rect center. turns white when key pressed and black when released\nblack rect center. turns white when left arrow pressed and black when right.', + class: 'p5', + module: 'Events', + submodule: 'Keyboard' + }, + { + file: 'src/events/keyboard.js', + line: 196, + description: + '

The keyReleased() function is called once every time a key is released.\nSee key and keyCode for more information.

\nBrowsers may have different default\nbehaviors attached to various key events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.

\n', + itemtype: 'method', + name: 'keyReleased', + example: [ + '\n
\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction keyReleased() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n return false; // prevent any default behavior\n}\n\n
' + ], + alt: + 'black rect center. turns white when key pressed and black when pressed again', + class: 'p5', + module: 'Events', + submodule: 'Keyboard' + }, + { + file: 'src/events/keyboard.js', + line: 248, + description: + '

The keyTyped() function is called once every time a key is pressed, but\naction keys such as Backspace, Delete, Ctrl, Shift, and Alt are ignored. If you are trying to detect\na keyCode for one of these keys, use the keyPressed() function instead.\nThe most recent key typed will be stored in the key variable.\n

\nBecause of how operating systems handle key repeats, holding down a key\nwill cause multiple calls to keyTyped() (and keyReleased() as well). The\nrate of repeat is set by the operating system and how each computer is\nconfigured.

\nBrowsers may have different default behaviors attached to various key\nevents. To prevent any default behavior for this event, add "return false"\nto the end of the method.

\n', + itemtype: 'method', + name: 'keyTyped', + example: [ + "\n
\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction keyTyped() {\n if (key === 'a') {\n value = 255;\n } else if (key === 'b') {\n value = 0;\n }\n // uncomment to prevent any default behavior\n // return false;\n}\n\n
" + ], + alt: + "black rect center. turns white when 'a' key typed and black when 'b' pressed", + class: 'p5', + module: 'Events', + submodule: 'Keyboard' + }, + { + file: 'src/events/keyboard.js', + line: 302, + description: + '

The onblur function is called when the user is no longer focused\non the p5 element. Because the keyup events will not fire if the user is\nnot focused on the element we must assume all keys currently down have\nbeen released.

\n', + class: 'p5', + module: 'Events', + submodule: 'Keyboard' + }, + { + file: 'src/events/keyboard.js', + line: 312, + description: + '

The keyIsDown() function checks if the key is currently down, i.e. pressed.\nIt can be used if you have an object that moves, and you want several keys\nto be able to affect its behaviour simultaneously, such as moving a\nsprite diagonally. You can put in any number representing the keyCode of\nthe key, or use any of the variable keyCode names listed\nhere.

\n', + itemtype: 'method', + name: 'keyIsDown', + params: [ + { + name: 'code', + description: '

The key to check for.

\n', + type: 'Number' + } + ], + return: { + description: 'whether key is down or not', + type: 'Boolean' + }, + example: [ + '\n
\nlet x = 100;\nlet y = 100;\n\nfunction setup() {\n createCanvas(512, 512);\n fill(255, 0, 0);\n}\n\nfunction draw() {\n if (keyIsDown(LEFT_ARROW)) {\n x -= 5;\n }\n\n if (keyIsDown(RIGHT_ARROW)) {\n x += 5;\n }\n\n if (keyIsDown(UP_ARROW)) {\n y -= 5;\n }\n\n if (keyIsDown(DOWN_ARROW)) {\n y += 5;\n }\n\n clear();\n ellipse(x, y, 50, 50);\n}\n
\n\n
\nlet diameter = 50;\n\nfunction setup() {\n createCanvas(512, 512);\n}\n\nfunction draw() {\n // 107 and 187 are keyCodes for "+"\n if (keyIsDown(107) || keyIsDown(187)) {\n diameter += 1;\n }\n\n // 109 and 189 are keyCodes for "-"\n if (keyIsDown(109) || keyIsDown(189)) {\n diameter -= 1;\n }\n\n clear();\n fill(255, 0, 0);\n ellipse(50, 50, diameter, diameter);\n}\n
' + ], + alt: + '50x50 red ellipse moves left, right, up and down with arrow presses.\n50x50 red ellipse gets bigger or smaller when + or - are pressed.', + class: 'p5', + module: 'Events', + submodule: 'Keyboard' + }, + { + file: 'src/events/mouse.js', + line: 22, + description: + '

The system variable mouseX always contains the current horizontal\nposition of the mouse, relative to (0, 0) of the canvas. The value at\nthe top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL.\nIf touch is used instead of mouse input, mouseX will hold the x value\nof the most recent touch point.

\n', + itemtype: 'property', + name: 'mouseX', + type: 'Number', + readonly: '', + example: [ + '\n
\n\n// Move the mouse across the canvas\nfunction draw() {\n background(244, 248, 252);\n line(mouseX, 0, mouseX, 100);\n}\n\n
' + ], + alt: 'horizontal black line moves left and right with mouse x-position', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 49, + description: + '

The system variable mouseY always contains the current vertical\nposition of the mouse, relative to (0, 0) of the canvas. The value at\nthe top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL.\nIf touch is used instead of mouse input, mouseY will hold the y value\nof the most recent touch point.

\n', + itemtype: 'property', + name: 'mouseY', + type: 'Number', + readonly: '', + example: [ + '\n
\n\n// Move the mouse across the canvas\nfunction draw() {\n background(244, 248, 252);\n line(0, mouseY, 100, mouseY);\n}\n\n
' + ], + alt: 'vertical black line moves up and down with mouse y-position', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 76, + description: + '

The system variable pmouseX always contains the horizontal position of\nthe mouse or finger in the frame previous to the current frame, relative to\n(0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and\n(-width/2, -height/2) for WebGL. Note: pmouseX will be reset to the current mouseX\nvalue at the start of each touch event.

\n', + itemtype: 'property', + name: 'pmouseX', + type: 'Number', + readonly: '', + example: [ + "\n
\n\n// Move the mouse across the canvas to leave a trail\nfunction setup() {\n //slow down the frameRate to make it more visible\n frameRate(10);\n}\n\nfunction draw() {\n background(244, 248, 252);\n line(mouseX, mouseY, pmouseX, pmouseY);\n print(pmouseX + ' -> ' + mouseX);\n}\n\n
" + ], + alt: + 'line trail is created from cursor movements. faster movement make longer line.', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 109, + description: + '

The system variable pmouseY always contains the vertical position of\nthe mouse or finger in the frame previous to the current frame, relative to\n(0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and\n(-width/2, -height/2) for WebGL. Note: pmouseY will be reset to the current mouseY\nvalue at the start of each touch event.

\n', + itemtype: 'property', + name: 'pmouseY', + type: 'Number', + readonly: '', + example: [ + "\n
\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n //draw a square only if the mouse is not moving\n if (mouseY === pmouseY && mouseX === pmouseX) {\n rect(20, 20, 60, 60);\n }\n\n print(pmouseY + ' -> ' + mouseY);\n}\n\n
" + ], + alt: + '60x60 black rect center, fuchsia background. rect flickers on mouse movement', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 141, + description: + '

The system variable winMouseX always contains the current horizontal\nposition of the mouse, relative to (0, 0) of the window.

\n', + itemtype: 'property', + name: 'winMouseX', + type: 'Number', + readonly: '', + example: [ + "\n
\n\nlet myCanvas;\n\nfunction setup() {\n //use a variable to store a pointer to the canvas\n myCanvas = createCanvas(100, 100);\n const body = document.getElementsByTagName('body')[0];\n myCanvas.parent(body);\n}\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n\n //move the canvas to the horizontal mouse position\n //relative to the window\n myCanvas.position(winMouseX + 1, windowHeight / 2);\n\n //the y of the square is relative to the canvas\n rect(20, mouseY, 60, 60);\n}\n\n
" + ], + alt: + '60x60 black rect y moves with mouse y and fuchsia canvas moves with mouse x', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 180, + description: + '

The system variable winMouseY always contains the current vertical\nposition of the mouse, relative to (0, 0) of the window.

\n', + itemtype: 'property', + name: 'winMouseY', + type: 'Number', + readonly: '', + example: [ + "\n
\n\nlet myCanvas;\n\nfunction setup() {\n //use a variable to store a pointer to the canvas\n myCanvas = createCanvas(100, 100);\n const body = document.getElementsByTagName('body')[0];\n myCanvas.parent(body);\n}\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n\n //move the canvas to the vertical mouse position\n //relative to the window\n myCanvas.position(windowWidth / 2, winMouseY + 1);\n\n //the x of the square is relative to the canvas\n rect(mouseX, 20, 60, 60);\n}\n\n
" + ], + alt: + '60x60 black rect x moves with mouse x and fuchsia canvas y moves with mouse y', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 219, + description: + '

The system variable pwinMouseX always contains the horizontal position\nof the mouse in the frame previous to the current frame, relative to\n(0, 0) of the window. Note: pwinMouseX will be reset to the current winMouseX\nvalue at the start of each touch event.

\n', + itemtype: 'property', + name: 'pwinMouseX', + type: 'Number', + readonly: '', + example: [ + '\n
\n\nlet myCanvas;\n\nfunction setup() {\n //use a variable to store a pointer to the canvas\n myCanvas = createCanvas(100, 100);\n noStroke();\n fill(237, 34, 93);\n}\n\nfunction draw() {\n clear();\n //the difference between previous and\n //current x position is the horizontal mouse speed\n let speed = abs(winMouseX - pwinMouseX);\n //change the size of the circle\n //according to the horizontal speed\n ellipse(50, 50, 10 + speed * 5, 10 + speed * 5);\n //move the canvas to the mouse position\n myCanvas.position(winMouseX + 1, winMouseY + 1);\n}\n\n
' + ], + alt: + 'fuchsia ellipse moves with mouse x and y. Grows and shrinks with mouse speed', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 260, + description: + '

The system variable pwinMouseY always contains the vertical position of\nthe mouse in the frame previous to the current frame, relative to (0, 0)\nof the window. Note: pwinMouseY will be reset to the current winMouseY\nvalue at the start of each touch event.

\n', + itemtype: 'property', + name: 'pwinMouseY', + type: 'Number', + readonly: '', + example: [ + '\n
\n\nlet myCanvas;\n\nfunction setup() {\n //use a variable to store a pointer to the canvas\n myCanvas = createCanvas(100, 100);\n noStroke();\n fill(237, 34, 93);\n}\n\nfunction draw() {\n clear();\n //the difference between previous and\n //current y position is the vertical mouse speed\n let speed = abs(winMouseY - pwinMouseY);\n //change the size of the circle\n //according to the vertical speed\n ellipse(50, 50, 10 + speed * 5, 10 + speed * 5);\n //move the canvas to the mouse position\n myCanvas.position(winMouseX + 1, winMouseY + 1);\n}\n\n
' + ], + alt: + 'fuchsia ellipse moves with mouse x and y. Grows and shrinks with mouse speed', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 302, + description: + '

Processing automatically tracks if the mouse button is pressed and which\nbutton is pressed. The value of the system variable mouseButton is either\nLEFT, RIGHT, or CENTER depending on which button was pressed last.\nWarning: different browsers may track mouseButton differently.

\n', + itemtype: 'property', + name: 'mouseButton', + type: 'Constant', + readonly: '', + example: [ + '\n
\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n\n if (mouseIsPressed) {\n if (mouseButton === LEFT) {\n ellipse(50, 50, 50, 50);\n }\n if (mouseButton === RIGHT) {\n rect(25, 25, 50, 50);\n }\n if (mouseButton === CENTER) {\n triangle(23, 75, 50, 20, 78, 75);\n }\n }\n\n print(mouseButton);\n}\n\n
' + ], + alt: + '50x50 black ellipse appears on center of fuchsia canvas on mouse click/press.', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 341, + description: + '

The boolean system variable mouseIsPressed is true if the mouse is pressed\nand false if not.

\n', + itemtype: 'property', + name: 'mouseIsPressed', + type: 'Boolean', + readonly: '', + example: [ + '\n
\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n\n if (mouseIsPressed) {\n ellipse(50, 50, 50, 50);\n } else {\n rect(25, 25, 50, 50);\n }\n\n print(mouseIsPressed);\n}\n\n
' + ], + alt: + 'black 50x50 rect becomes ellipse with mouse click/press. fuchsia background.', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 432, + description: + '

The mouseMoved() function is called every time the mouse moves and a mouse\nbutton is not pressed.

\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.

\n', + itemtype: 'method', + name: 'mouseMoved', + params: [ + { + name: 'event', + description: '

optional MouseEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Move the mouse across the page\n// to change its value\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction mouseMoved() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction mouseMoved() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a MouseEvent object\n// as a callback argument\nfunction mouseMoved(event) {\n console.log(event);\n}\n\n
' + ], + alt: + 'black 50x50 rect becomes lighter with mouse movements until white then resets\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 487, + description: + '

The mouseDragged() function is called once every time the mouse moves and\na mouse button is pressed. If no mouseDragged() function is defined, the\ntouchMoved() function will be called instead if it is defined.

\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.

\n', + itemtype: 'method', + name: 'mouseDragged', + params: [ + { + name: 'event', + description: '

optional MouseEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Drag the mouse across the page\n// to change its value\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction mouseDragged() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction mouseDragged() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a MouseEvent object\n// as a callback argument\nfunction mouseDragged(event) {\n console.log(event);\n}\n\n
' + ], + alt: + 'black 50x50 rect turns lighter with mouse click and drag until white, resets\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 568, + description: + '

The mousePressed() function is called once after every time a mouse button\nis pressed. The mouseButton variable (see the related reference entry)\ncan be used to determine which button has been pressed. If no\nmousePressed() function is defined, the touchStarted() function will be\ncalled instead if it is defined.

\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.

\n', + itemtype: 'method', + name: 'mousePressed', + params: [ + { + name: 'event', + description: '

optional MouseEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Click within the image to change\n// the value of the rectangle\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction mousePressed() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction mousePressed() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a MouseEvent object\n// as a callback argument\nfunction mousePressed(event) {\n console.log(event);\n}\n\n
' + ], + alt: + 'black 50x50 rect turns white with mouse click/press.\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 650, + description: + '

The mouseReleased() function is called every time a mouse button is\nreleased. If no mouseReleased() function is defined, the touchEnded()\nfunction will be called instead if it is defined.

\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.

\n', + itemtype: 'method', + name: 'mouseReleased', + params: [ + { + name: 'event', + description: '

optional MouseEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Click within the image to change\n// the value of the rectangle\n// after the mouse has been clicked\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction mouseReleased() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction mouseReleased() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a MouseEvent object\n// as a callback argument\nfunction mouseReleased(event) {\n console.log(event);\n}\n\n
' + ], + alt: + 'black 50x50 rect turns white with mouse click/press.\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 728, + description: + '

The mouseClicked() function is called once after a mouse button has been\npressed and then released.

\nBrowsers handle clicks differently, so this function is only guaranteed to be\nrun when the left mouse button is clicked. To handle other mouse buttons\nbeing pressed or released, see mousePressed() or mouseReleased().

\nBrowsers may have different default\nbehaviors attached to various mouse events. To prevent any default\nbehavior for this event, add "return false" to the end of the method.

\n', + itemtype: 'method', + name: 'mouseClicked', + params: [ + { + name: 'event', + description: '

optional MouseEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Click within the image to change\n// the value of the rectangle\n// after the mouse has been clicked\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\n\nfunction mouseClicked() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction mouseClicked() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a MouseEvent object\n// as a callback argument\nfunction mouseClicked(event) {\n console.log(event);\n}\n\n
' + ], + alt: + 'black 50x50 rect turns white with mouse click/press.\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 798, + description: + '

The doubleClicked() function is executed every time a event\nlistener has detected a dblclick event which is a part of the\nDOM L3 specification. The doubleClicked event is fired when a\npointing device button (usually a mouse's primary button)\nis clicked twice on a single element. For more info on the\ndblclick event refer to mozilla's documentation here:\nhttps://developer.mozilla.org/en-US/docs/Web/Events/dblclick

\n', + itemtype: 'method', + name: 'doubleClicked', + params: [ + { + name: 'event', + description: '

optional MouseEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Click within the image to change\n// the value of the rectangle\n// after the mouse has been double clicked\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\n\nfunction doubleClicked() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction doubleClicked() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a MouseEvent object\n// as a callback argument\nfunction doubleClicked(event) {\n console.log(event);\n}\n\n
' + ], + alt: + 'black 50x50 rect turns white with mouse doubleClick/press.\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/mouse.js', + line: 883, + description: + '

The function mouseWheel() is executed every time a vertical mouse wheel\nevent is detected either triggered by an actual mouse wheel or by a\ntouchpad.

\nThe event.delta property returns the amount the mouse wheel\nhave scrolled. The values can be positive or negative depending on the\nscroll direction (on OS X with "natural" scrolling enabled, the signs\nare inverted).

\nBrowsers may have different default behaviors attached to various\nmouse events. To prevent any default behavior for this event, add\n"return false" to the end of the method.

\nDue to the current support of the "wheel" event on Safari, the function\nmay only work as expected if "return false" is included while using Safari.

\n', + itemtype: 'method', + name: 'mouseWheel', + params: [ + { + name: 'event', + description: '

optional WheelEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\nlet pos = 25;\n\nfunction draw() {\n background(237, 34, 93);\n fill(0);\n rect(25, pos, 50, 50);\n}\n\nfunction mouseWheel(event) {\n print(event.delta);\n //move the square according to the vertical scroll amount\n pos += event.delta;\n //uncomment to block page scrolling\n //return false;\n}\n\n
' + ], + alt: + 'black 50x50 rect moves up and down with vertical scroll. fuchsia background', + class: 'p5', + module: 'Events', + submodule: 'Mouse' + }, + { + file: 'src/events/touch.js', + line: 12, + description: + '

The system variable touches[] contains an array of the positions of all\ncurrent touch points, relative to (0, 0) of the canvas, and IDs identifying a\nunique touch as it moves. Each element in the array is an object with x, y,\nand id properties.

\n

The touches[] array is not supported on Safari and IE on touch-based\ndesktops (laptops).

\n', + itemtype: 'property', + name: 'touches', + type: 'Object[]', + readonly: '', + example: [ + "\n
\n\n// On a touchscreen device, touch\n// the canvas using one or more fingers\n// at the same time\nfunction draw() {\n clear();\n let display = touches.length + ' touches';\n text(display, 5, 10);\n}\n\n
" + ], + alt: 'Number of touches currently registered are displayed on the canvas', + class: 'p5', + module: 'Events', + submodule: 'Touch' + }, + { + file: 'src/events/touch.js', + line: 74, + description: + '

The touchStarted() function is called once after every time a touch is\nregistered. If no touchStarted() function is defined, the mousePressed()\nfunction will be called instead if it is defined.

\nBrowsers may have different default behaviors attached to various touch\nevents. To prevent any default behavior for this event, add "return false"\nto the end of the method.

\n', + itemtype: 'method', + name: 'touchStarted', + params: [ + { + name: 'event', + description: '

optional TouchEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Touch within the image to change\n// the value of the rectangle\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction touchStarted() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction touchStarted() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a TouchEvent object\n// as a callback argument\nfunction touchStarted(event) {\n console.log(event);\n}\n\n
' + ], + alt: '50x50 black rect turns white with touch event.\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Touch' + }, + { + file: 'src/events/touch.js', + line: 154, + description: + '

The touchMoved() function is called every time a touch move is registered.\nIf no touchMoved() function is defined, the mouseDragged() function will\nbe called instead if it is defined.

\nBrowsers may have different default behaviors attached to various touch\nevents. To prevent any default behavior for this event, add "return false"\nto the end of the method.

\n', + itemtype: 'method', + name: 'touchMoved', + params: [ + { + name: 'event', + description: '

optional TouchEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Move your finger across the page\n// to change its value\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction touchMoved() {\n value = value + 5;\n if (value > 255) {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction touchMoved() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a TouchEvent object\n// as a callback argument\nfunction touchMoved(event) {\n console.log(event);\n}\n\n
' + ], + alt: + '50x50 black rect turns lighter with touch until white. resets\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Touch' + }, + { + file: 'src/events/touch.js', + line: 227, + description: + '

The touchEnded() function is called every time a touch ends. If no\ntouchEnded() function is defined, the mouseReleased() function will be\ncalled instead if it is defined.

\nBrowsers may have different default behaviors attached to various touch\nevents. To prevent any default behavior for this event, add "return false"\nto the end of the method.

\n', + itemtype: 'method', + name: 'touchEnded', + params: [ + { + name: 'event', + description: '

optional TouchEvent callback argument.

\n', + type: 'Object', + optional: true + } + ], + example: [ + '\n
\n\n// Release touch within the image to\n// change the value of the rectangle\n\nlet value = 0;\nfunction draw() {\n fill(value);\n rect(25, 25, 50, 50);\n}\nfunction touchEnded() {\n if (value === 0) {\n value = 255;\n } else {\n value = 0;\n }\n}\n\n
\n\n
\n\nfunction touchEnded() {\n ellipse(mouseX, mouseY, 5, 5);\n // prevent default\n return false;\n}\n\n
\n\n
\n\n// returns a TouchEvent object\n// as a callback argument\nfunction touchEnded(event) {\n console.log(event);\n}\n\n
' + ], + alt: '50x50 black rect turns white with touch.\nno image displayed', + class: 'p5', + module: 'Events', + submodule: 'Touch' + }, + { + file: 'src/image/filters.js', + line: 3, + description: + '

This module defines the filters for use with image buffers.

\n

This module is basically a collection of functions stored in an object\nas opposed to modules. The functions are destructive, modifying\nthe passed in canvas rather than creating a copy.

\n

Generally speaking users of this module will use the Filters.apply method\non a canvas to create an effect.

\n

A number of functions are borrowed/adapted from\nhttp://www.html5rocks.com/en/tutorials/canvas/imagefilters/\nor the java processing implementation.

\n', + class: 'p5', + module: 'Events' + }, + { + file: 'src/image/image.js', + line: 8, + description: + '

This module defines the p5 methods for the p5.Image class\nfor drawing images to the main display canvas.

\n', + class: 'p5', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/image.js', + line: 22, + description: + '

Creates a new p5.Image (the datatype for storing images). This provides a\nfresh buffer of pixels to play with. Set the size of the buffer with the\nwidth and height parameters.\n

\n.pixels gives access to an array containing the values for all the pixels\nin the display window.\nThese values are numbers. This array is the size (including an appropriate\nfactor for the pixelDensity) of the display window x4,\nrepresenting the R, G, B, A values in order for each pixel, moving from\nleft to right across each row, then down each column. See .pixels for\nmore info. It may also be simpler to use set() or get().\n

\nBefore accessing the pixels of an image, the data must loaded with the\nloadPixels() function. After the array data has been modified, the\nupdatePixels() function must be run to update the changes.

\n', + itemtype: 'method', + name: 'createImage', + params: [ + { + name: 'width', + description: '

width in pixels

\n', + type: 'Integer' + }, + { + name: 'height', + description: '

height in pixels

\n', + type: 'Integer' + } + ], + return: { + description: 'the p5.Image object', + type: 'p5.Image' + }, + example: [ + '\n
\n\nlet img = createImage(66, 66);\nimg.loadPixels();\nfor (let i = 0; i < img.width; i++) {\n for (let j = 0; j < img.height; j++) {\n img.set(i, j, color(0, 90, 102));\n }\n}\nimg.updatePixels();\nimage(img, 17, 17);\n\n
\n\n
\n\nlet img = createImage(66, 66);\nimg.loadPixels();\nfor (let i = 0; i < img.width; i++) {\n for (let j = 0; j < img.height; j++) {\n img.set(i, j, color(0, 90, 102, (i % img.width) * 2));\n }\n}\nimg.updatePixels();\nimage(img, 17, 17);\nimage(img, 34, 34);\n\n
\n\n
\n\nlet pink = color(255, 102, 204);\nlet img = createImage(66, 66);\nimg.loadPixels();\nlet d = pixelDensity();\nlet halfImage = 4 * (img.width * d) * (img.height / 2 * d);\nfor (let i = 0; i < halfImage; i += 4) {\n img.pixels[i] = red(pink);\n img.pixels[i + 1] = green(pink);\n img.pixels[i + 2] = blue(pink);\n img.pixels[i + 3] = alpha(pink);\n}\nimg.updatePixels();\nimage(img, 17, 17);\n\n
' + ], + alt: + '66x66 dark turquoise rect in center of canvas.\n2 gradated dark turquoise rects fade left. 1 center 1 bottom right of canvas\nno image displayed', + class: 'p5', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/image.js', + line: 102, + description: + '

Save the current canvas as an image. The browser will either save the\nfile immediately, or prompt the user with a dialogue window.

\n', + itemtype: 'method', + name: 'saveCanvas', + example: [ + "\n
\n function setup() {\n let c = createCanvas(100, 100);\n background(255, 0, 0);\n saveCanvas(c, 'myCanvas', 'jpg');\n }\n
\n
\n // note that this example has the same result as above\n // if no canvas is specified, defaults to main canvas\n function setup() {\n let c = createCanvas(100, 100);\n background(255, 0, 0);\n saveCanvas('myCanvas', 'jpg');\n\n // all of the following are valid\n saveCanvas(c, 'myCanvas', 'jpg');\n saveCanvas(c, 'myCanvas.jpg');\n saveCanvas(c, 'myCanvas');\n saveCanvas(c);\n saveCanvas('myCanvas', 'png');\n saveCanvas('myCanvas');\n saveCanvas();\n }\n
" + ], + alt: 'no image displayed\n no image displayed\n no image displayed', + class: 'p5', + module: 'Image', + submodule: 'Image', + overloads: [ + { + line: 102, + params: [ + { + name: 'selectedCanvas', + description: + '

a variable\n representing a specific html5 canvas (optional)

\n', + type: 'p5.Element|HTMLCanvasElement' + }, + { + name: 'filename', + description: '', + type: 'String', + optional: true + }, + { + name: 'extension', + description: '

'jpg' or 'png'

\n', + type: 'String', + optional: true + } + ] + }, + { + line: 144, + params: [ + { + name: 'filename', + description: '', + type: 'String', + optional: true + }, + { + name: 'extension', + description: '', + type: 'String', + optional: true + } + ] + } + ] + }, + { + file: 'src/image/image.js', + line: 195, + description: + '

Capture a sequence of frames that can be used to create a movie.\nAccepts a callback. For example, you may wish to send the frames\nto a server where they can be stored or converted into a movie.\nIf no callback is provided, the browser will pop up save dialogues in an\nattempt to download all of the images that have just been created. With the\ncallback provided the image data isn't saved by default but instead passed\nas an argument to the callback function as an array of objects, with the\nsize of array equal to the total number of frames.

\n

Note that saveFrames() will only save the first 15 frames of an animation.\nTo export longer animations, you might look into a library like\nccapture.js.

\n', + itemtype: 'method', + name: 'saveFrames', + params: [ + { + name: 'filename', + description: '', + type: 'String' + }, + { + name: 'extension', + description: '

'jpg' or 'png'

\n', + type: 'String' + }, + { + name: 'duration', + description: '

Duration in seconds to save the frames for.

\n', + type: 'Number' + }, + { + name: 'framerate', + description: '

Framerate to save the frames in.

\n', + type: 'Number' + }, + { + name: 'callback', + description: + '

A callback function that will be executed\n to handle the image data. This function\n should accept an array as argument. The\n array will contain the specified number of\n frames of objects. Each object has three\n properties: imageData - an\n image/octet-stream, filename and extension.

\n', + type: 'Function(Array)', + optional: true + } + ], + example: [ + "\n
\n function draw() {\n background(mouseX);\n }\n\n function mousePressed() {\n saveFrames('out', 'png', 1, 25, data => {\n print(data);\n });\n }\n
" + ], + alt: 'canvas background goes from light to dark with mouse x.', + class: 'p5', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/loading_displaying.js', + line: 17, + description: + '

Loads an image from a path and creates a p5.Image from it.\n

\nThe image may not be immediately available for rendering\nIf you want to ensure that the image is ready before doing\nanything with it, place the loadImage() call in preload().\nYou may also supply a callback function to handle the image when it's ready.\n

\nThe path to the image should be relative to the HTML file\nthat links in your sketch. Loading an image from a URL or other\nremote location may be blocked due to your browser's built-in\nsecurity.

\n', + itemtype: 'method', + name: 'loadImage', + params: [ + { + name: 'path', + description: '

Path of the image to be loaded

\n', + type: 'String' + }, + { + name: 'successCallback', + description: + '

Function to be called once\n the image is loaded. Will be passed the\n p5.Image.

\n', + type: 'function(p5.Image)', + optional: true + }, + { + name: 'failureCallback', + description: + '

called with event error if\n the image fails to load.

\n', + type: 'Function(Event)', + optional: true + } + ], + return: { + description: 'the p5.Image object', + type: 'p5.Image' + }, + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/laDefense.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n}\n\n
\n
\n\nfunction setup() {\n // here we use a callback to display the image after loading\n loadImage('assets/laDefense.jpg', img => {\n image(img, 0, 0);\n });\n}\n\n
" + ], + alt: + 'image of the underside of a white umbrella and grided ceililng above\nimage of the underside of a white umbrella and grided ceililng above', + class: 'p5', + module: 'Image', + submodule: 'Loading & Displaying' + }, + { + file: 'src/image/loading_displaying.js', + line: 127, + description: + '

Draw an image to the p5.js canvas.

\n

This function can be used with different numbers of parameters. The\nsimplest use requires only three parameters: img, x, and y—where (x, y) is\nthe position of the image. Two more parameters can optionally be added to\nspecify the width and height of the image.

\n

This function can also be used with all eight Number parameters. To\ndifferentiate between all these parameters, p5.js uses the language of\n"destination rectangle" (which corresponds to "dx", "dy", etc.) and "source\nimage" (which corresponds to "sx", "sy", etc.) below. Specifying the\n"source image" dimensions can be useful when you want to display a\nsubsection of the source image instead of the whole thing. Here's a diagram\nto explain further:\n

\n', + itemtype: 'method', + name: 'image', + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/laDefense.jpg');\n}\nfunction setup() {\n // Top-left corner of the img is at (0, 0)\n // Width and height are the img's original width and height\n image(img, 0, 0);\n}\n\n
\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/laDefense.jpg');\n}\nfunction setup() {\n background(50);\n // Top-left corner of the img is at (10, 10)\n // Width and height are 50 x 50\n image(img, 10, 10, 50, 50);\n}\n\n
\n
\n\nfunction setup() {\n // Here, we use a callback to display the image after loading\n loadImage('assets/laDefense.jpg', img => {\n image(img, 0, 0);\n });\n}\n\n
\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/gradient.png');\n}\nfunction setup() {\n // 1. Background image\n // Top-left corner of the img is at (0, 0)\n // Width and height are the img's original width and height, 100 x 100\n image(img, 0, 0);\n // 2. Top right image\n // Top-left corner of destination rectangle is at (50, 0)\n // Destination rectangle width and height are 40 x 20\n // The next parameters are relative to the source image:\n // - Starting at position (50, 50) on the source image, capture a 50 x 50\n // subsection\n // - Draw this subsection to fill the dimensions of the destination rectangle\n image(img, 50, 0, 40, 20, 50, 50, 50, 50);\n}\n\n
" + ], + alt: + 'image of the underside of a white umbrella and gridded ceiling above\nimage of the underside of a white umbrella and gridded ceiling above', + class: 'p5', + module: 'Image', + submodule: 'Loading & Displaying', + overloads: [ + { + line: 127, + params: [ + { + name: 'img', + description: '

the image to display

\n', + type: 'p5.Image|p5.Element' + }, + { + name: 'x', + description: + '

the x-coordinate of the top-left corner of the image

\n', + type: 'Number' + }, + { + name: 'y', + description: + '

the y-coordinate of the top-left corner of the image

\n', + type: 'Number' + }, + { + name: 'width', + description: '

the width to draw the image

\n', + type: 'Number', + optional: true + }, + { + name: 'height', + description: '

the height to draw the image

\n', + type: 'Number', + optional: true + } + ] + }, + { + line: 215, + params: [ + { + name: 'img', + description: '', + type: 'p5.Image|p5.Element' + }, + { + name: 'dx', + description: + '

the x-coordinate of the destination\n rectangle in which to draw the source image

\n', + type: 'Number' + }, + { + name: 'dy', + description: + '

the y-coordinate of the destination\n rectangle in which to draw the source image

\n', + type: 'Number' + }, + { + name: 'dWidth', + description: '

the width of the destination rectangle

\n', + type: 'Number' + }, + { + name: 'dHeight', + description: '

the height of the destination rectangle

\n', + type: 'Number' + }, + { + name: 'sx', + description: + '

the x-coordinate of the subsection of the source\nimage to draw into the destination rectangle

\n', + type: 'Number' + }, + { + name: 'sy', + description: + '

the y-coordinate of the subsection of the source\nimage to draw into the destination rectangle

\n', + type: 'Number' + }, + { + name: 'sWidth', + description: + '

the width of the subsection of the\n source image to draw into the destination\n rectangle

\n', + type: 'Number', + optional: true + }, + { + name: 'sHeight', + description: + '

the height of the subsection of the\n source image to draw into the destination rectangle

\n', + type: 'Number', + optional: true + } + ] + } + ] + }, + { + file: 'src/image/loading_displaying.js', + line: 298, + description: + '

Sets the fill value for displaying images. Images can be tinted to\nspecified colors or made transparent by including an alpha value.\n

\nTo apply transparency to an image without affecting its color, use\nwhite as the tint color and specify an alpha value. For instance,\ntint(255, 128) will make an image 50% transparent (assuming the default\nalpha range of 0-255, which can be changed with colorMode()).\n

\nThe value for the gray parameter must be less than or equal to the current\nmaximum value as specified by colorMode(). The default maximum value is\n255.

\n', + itemtype: 'method', + name: 'tint', + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/laDefense.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n tint(0, 153, 204); // Tint blue\n image(img, 50, 0);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/laDefense.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n tint(0, 153, 204, 126); // Tint blue and set transparency\n image(img, 50, 0);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/laDefense.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n tint(255, 126); // Apply transparency without changing color\n image(img, 50, 0);\n}\n\n
" + ], + alt: + '2 side by side images of umbrella and ceiling, one image with blue tint\nImages of umbrella and ceiling, one half of image with blue tint\n2 side by side images of umbrella and ceiling, one image translucent', + class: 'p5', + module: 'Image', + submodule: 'Loading & Displaying', + overloads: [ + { + line: 298, + params: [ + { + name: 'v1', + description: + '

red or hue value relative to\n the current color range

\n', + type: 'Number' + }, + { + name: 'v2', + description: + '

green or saturation value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'v3', + description: + '

blue or brightness value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + line: 371, + params: [ + { + name: 'value', + description: '

a color string

\n', + type: 'String' + } + ] + }, + { + line: 376, + params: [ + { + name: 'gray', + description: '

a gray value

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + line: 382, + params: [ + { + name: 'values', + description: + '

an array containing the red,green,blue &\n and alpha components of the color

\n', + type: 'Number[]' + } + ] + }, + { + line: 388, + params: [ + { + name: 'color', + description: '

the tint color

\n', + type: 'p5.Color' + } + ] + } + ] + }, + { + file: 'src/image/loading_displaying.js', + line: 398, + description: + '

Removes the current fill value for displaying images and reverts to\ndisplaying images with their original hues.

\n', + itemtype: 'method', + name: 'noTint', + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n tint(0, 153, 204); // Tint blue\n image(img, 0, 0);\n noTint(); // Disable tint\n image(img, 50, 0);\n}\n\n
" + ], + alt: '2 side by side images of bricks, left image with blue tint', + class: 'p5', + module: 'Image', + submodule: 'Loading & Displaying' + }, + { + file: 'src/image/loading_displaying.js', + line: 464, + description: + '

Set image mode. Modifies the location from which images are drawn by\nchanging the way in which parameters given to image() are interpreted.\nThe default mode is imageMode(CORNER), which interprets the second and\nthird parameters of image() as the upper-left corner of the image. If\ntwo additional parameters are specified, they are used to set the image's\nwidth and height.\n

\nimageMode(CORNERS) interprets the second and third parameters of image()\nas the location of one corner, and the fourth and fifth parameters as the\nopposite corner.\n

\nimageMode(CENTER) interprets the second and third parameters of image()\nas the image's center point. If two additional parameters are specified,\nthey are used to set the image's width and height.

\n', + itemtype: 'method', + name: 'imageMode', + params: [ + { + name: 'mode', + description: '

either CORNER, CORNERS, or CENTER

\n', + type: 'Constant' + } + ], + example: [ + "\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n imageMode(CORNER);\n image(img, 10, 10, 50, 50);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n imageMode(CORNERS);\n image(img, 10, 10, 90, 40);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n imageMode(CENTER);\n image(img, 50, 50, 80, 80);\n}\n\n
" + ], + alt: + 'small square image of bricks\nhorizontal rectangle image of bricks\nlarge square image of bricks', + class: 'p5', + module: 'Image', + submodule: 'Loading & Displaying' + }, + { + file: 'src/image/p5.Image.js', + line: 9, + description: + '

This module defines the p5.Image class and P5 methods for\ndrawing images to the main display canvas.

\n', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 90, + description: '

Image width.

\n', + itemtype: 'property', + name: 'width', + type: 'Number', + readonly: '', + example: [ + "\n
\nlet img;\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n createCanvas(100, 100);\n image(img, 0, 0);\n for (let i = 0; i < img.width; i++) {\n let c = img.get(i, img.height / 2);\n stroke(c);\n line(i, height / 2, i, height);\n }\n}\n
" + ], + alt: + 'rocky mountains in top and horizontal lines in corresponding colors in bottom.', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 117, + description: '

Image height.

\n', + itemtype: 'property', + name: 'height', + type: 'Number', + readonly: '', + example: [ + "\n
\nlet img;\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n createCanvas(100, 100);\n image(img, 0, 0);\n for (let i = 0; i < img.height; i++) {\n let c = img.get(img.width / 2, i);\n stroke(c);\n line(0, i, width / 2, i);\n }\n}\n
" + ], + alt: + 'rocky mountains on right and vertical lines in corresponding colors on left.', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 153, + description: + '

Array containing the values for all the pixels in the display window.\nThese values are numbers. This array is the size (include an appropriate\nfactor for pixelDensity) of the display window x4,\nrepresenting the R, G, B, A values in order for each pixel, moving from\nleft to right across each row, then down each column. Retina and other\nhigh denisty displays may have more pixels (by a factor of\npixelDensity^2).\nFor example, if the image is 100x100 pixels, there will be 40,000. With\npixelDensity = 2, there will be 160,000. The first four values\n(indices 0-3) in the array will be the R, G, B, A values of the pixel at\n(0, 0). The second four values (indices 4-7) will contain the R, G, B, A\nvalues of the pixel at (1, 0). More generally, to set values for a pixel\nat (x, y):

\n
let d = pixelDensity();\nfor (let i = 0; i < d; i++) {\n  for (let j = 0; j < d; j++) {\n    // loop over\n    index = 4 * ((y * d + j) * width * d + (x * d + i));\n    pixels[index] = r;\n    pixels[index+1] = g;\n    pixels[index+2] = b;\n    pixels[index+3] = a;\n  }\n}\n
\n



\nBefore accessing this array, the data must loaded with the loadPixels()\nfunction. After the array data has been modified, the updatePixels()\nfunction must be run to update the changes.

\n', + itemtype: 'property', + name: 'pixels', + type: 'Number[]', + example: [ + '\n
\n\nlet img = createImage(66, 66);\nimg.loadPixels();\nfor (let i = 0; i < img.width; i++) {\n for (let j = 0; j < img.height; j++) {\n img.set(i, j, color(0, 90, 102));\n }\n}\nimg.updatePixels();\nimage(img, 17, 17);\n\n
\n
\n\nlet pink = color(255, 102, 204);\nlet img = createImage(66, 66);\nimg.loadPixels();\nfor (let i = 0; i < 4 * (width * height / 2); i += 4) {\n img.pixels[i] = red(pink);\n img.pixels[i + 1] = green(pink);\n img.pixels[i + 2] = blue(pink);\n img.pixels[i + 3] = alpha(pink);\n}\nimg.updatePixels();\nimage(img, 17, 17);\n\n
' + ], + alt: + '66x66 turquoise rect in center of canvas\n66x66 pink rect in center of canvas', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 223, + description: '

Helper fxn for sharing pixel methods

\n', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 232, + description: + '

Loads the pixels data for this image into the [pixels] attribute.

\n', + itemtype: 'method', + name: 'loadPixels', + example: [ + "\n
\nlet myImage;\nlet halfImage;\n\nfunction preload() {\n myImage = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n myImage.loadPixels();\n halfImage = 4 * myImage.width * myImage.height / 2;\n for (let i = 0; i < halfImage; i++) {\n myImage.pixels[i + halfImage] = myImage.pixels[i];\n }\n myImage.updatePixels();\n}\n\nfunction draw() {\n image(myImage, 0, 0, width, height);\n}\n
" + ], + alt: '2 images of rocky mountains vertically stacked', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 268, + description: + '

Updates the backing canvas for this image with the contents of\nthe [pixels] array.

\n', + itemtype: 'method', + name: 'updatePixels', + example: [ + "\n
\nlet myImage;\nlet halfImage;\n\nfunction preload() {\n myImage = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n myImage.loadPixels();\n halfImage = 4 * myImage.width * myImage.height / 2;\n for (let i = 0; i < halfImage; i++) {\n myImage.pixels[i + halfImage] = myImage.pixels[i];\n }\n myImage.updatePixels();\n}\n\nfunction draw() {\n image(myImage, 0, 0, width, height);\n}\n
" + ], + alt: '2 images of rocky mountains vertically stacked', + class: 'p5.Image', + module: 'Image', + submodule: 'Image', + overloads: [ + { + line: 268, + params: [ + { + name: 'x', + description: + '

x-offset of the target update area for the\n underlying canvas

\n', + type: 'Integer' + }, + { + name: 'y', + description: + '

y-offset of the target update area for the\n underlying canvas

\n', + type: 'Integer' + }, + { + name: 'w', + description: + '

height of the target update area for the\n underlying canvas

\n', + type: 'Integer' + }, + { + name: 'h', + description: + '

height of the target update area for the\n underlying canvas

\n', + type: 'Integer' + } + ] + }, + { + line: 308, + params: [] + } + ] + }, + { + file: 'src/image/p5.Image.js', + line: 316, + description: + '

Get a region of pixels from an image.

\n

If no params are passed, the whole image is returned.\nIf x and y are the only params passed a single pixel is extracted.\nIf all params are passed a rectangle region is extracted and a p5.Image\nis returned.

\n', + itemtype: 'method', + name: 'get', + return: { + description: 'the rectangle p5.Image', + type: 'p5.Image' + }, + example: [ + "\n
\nlet myImage;\nlet c;\n\nfunction preload() {\n myImage = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n background(myImage);\n noStroke();\n c = myImage.get(60, 90);\n fill(c);\n rect(25, 25, 50, 50);\n}\n\n//get() returns color here\n
" + ], + alt: 'image of rocky mountains with 50x50 green rect in front', + class: 'p5.Image', + module: 'Image', + submodule: 'Image', + overloads: [ + { + line: 316, + params: [ + { + name: 'x', + description: '

x-coordinate of the pixel

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the pixel

\n', + type: 'Number' + }, + { + name: 'w', + description: '

width

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height

\n', + type: 'Number' + } + ], + return: { + description: 'the rectangle p5.Image', + type: 'p5.Image' + } + }, + { + line: 354, + params: [], + return: { + description: 'the whole p5.Image', + type: 'p5.Image' + } + }, + { + line: 358, + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + } + ], + return: { + description: 'color of pixel at x,y in array format [R, G, B, A]', + type: 'Number[]' + } + } + ] + }, + { + file: 'src/image/p5.Image.js', + line: 371, + description: + '

Set the color of a single pixel or write an image into\nthis p5.Image.

\n

Note that for a large number of pixels this will\nbe slower than directly manipulating the pixels array\nand then calling updatePixels().

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'x', + description: '

x-coordinate of the pixel

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the pixel

\n', + type: 'Number' + }, + { + name: 'a', + description: + '

grayscale value | pixel array |\n a p5.Color | image to copy

\n', + type: 'Number|Number[]|Object' + } + ], + example: [ + '\n
\n\nlet img = createImage(66, 66);\nimg.loadPixels();\nfor (let i = 0; i < img.width; i++) {\n for (let j = 0; j < img.height; j++) {\n img.set(i, j, color(0, 90, 102, (i % img.width) * 2));\n }\n}\nimg.updatePixels();\nimage(img, 17, 17);\nimage(img, 34, 34);\n\n
' + ], + alt: + '2 gradated dark turquoise rects fade left. 1 center 1 bottom right of canvas', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 409, + description: + '

Resize the image to a new width and height. To make the image scale\nproportionally, use 0 as the value for the wide or high parameter.\nFor instance, to make the width of an image 150 pixels, and change\nthe height using the same proportion, use resize(150, 0).

\n', + itemtype: 'method', + name: 'resize', + params: [ + { + name: 'width', + description: '

the resized image width

\n', + type: 'Number' + }, + { + name: 'height', + description: '

the resized image height

\n', + type: 'Number' + } + ], + example: [ + "\n
\nlet img;\n\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\n\nfunction draw() {\n image(img, 0, 0);\n}\n\nfunction mousePressed() {\n img.resize(50, 100);\n}\n
" + ], + alt: 'image of rocky mountains. zoomed in', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 494, + description: + '

Copies a region of pixels from one image to another. If no\nsrcImage is specified this is used as the source. If the source\nand destination regions aren't the same size, it will\nautomatically resize source pixels to fit the specified\ntarget region.

\n', + itemtype: 'method', + name: 'copy', + example: [ + "\n
\nlet photo;\nlet bricks;\nlet x;\nlet y;\n\nfunction preload() {\n photo = loadImage('assets/rockies.jpg');\n bricks = loadImage('assets/bricks.jpg');\n}\n\nfunction setup() {\n x = bricks.width / 2;\n y = bricks.height / 2;\n photo.copy(bricks, 0, 0, x, y, 0, 0, x, y);\n image(photo, 0, 0);\n}\n
" + ], + alt: + 'image of rocky mountains and smaller image on top of bricks at top left', + class: 'p5.Image', + module: 'Image', + submodule: 'Image', + overloads: [ + { + line: 494, + params: [ + { + name: 'srcImage', + description: '

source image

\n', + type: 'p5.Image|p5.Element' + }, + { + name: 'sx', + description: + '

X coordinate of the source's upper left corner

\n', + type: 'Integer' + }, + { + name: 'sy', + description: + '

Y coordinate of the source's upper left corner

\n', + type: 'Integer' + }, + { + name: 'sw', + description: '

source image width

\n', + type: 'Integer' + }, + { + name: 'sh', + description: '

source image height

\n', + type: 'Integer' + }, + { + name: 'dx', + description: + '

X coordinate of the destination's upper left corner

\n', + type: 'Integer' + }, + { + name: 'dy', + description: + '

Y coordinate of the destination's upper left corner

\n', + type: 'Integer' + }, + { + name: 'dw', + description: '

destination image width

\n', + type: 'Integer' + }, + { + name: 'dh', + description: '

destination image height

\n', + type: 'Integer' + } + ] + }, + { + line: 535, + params: [ + { + name: 'sx', + description: '', + type: 'Integer' + }, + { + name: 'sy', + description: '', + type: 'Integer' + }, + { + name: 'sw', + description: '', + type: 'Integer' + }, + { + name: 'sh', + description: '', + type: 'Integer' + }, + { + name: 'dx', + description: '', + type: 'Integer' + }, + { + name: 'dy', + description: '', + type: 'Integer' + }, + { + name: 'dw', + description: '', + type: 'Integer' + }, + { + name: 'dh', + description: '', + type: 'Integer' + } + ] + } + ] + }, + { + file: 'src/image/p5.Image.js', + line: 575, + description: + '

Masks part of an image from displaying by loading another\nimage and using it's alpha channel as an alpha channel for\nthis image.

\n', + itemtype: 'method', + name: 'mask', + params: [ + { + name: 'srcImage', + description: '

source image

\n', + type: 'p5.Image' + } + ], + example: [ + "\n
\nlet photo, maskImage;\nfunction preload() {\n photo = loadImage('assets/rockies.jpg');\n maskImage = loadImage('assets/mask2.png');\n}\n\nfunction setup() {\n createCanvas(100, 100);\n photo.mask(maskImage);\n image(photo, 0, 0);\n}\n
" + ], + alt: + 'image of rocky mountains with white at right\n\n\nhttp://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 638, + description: + '

Applies an image filter to a p5.Image

\n', + itemtype: 'method', + name: 'filter', + params: [ + { + name: 'filterType', + description: + '

either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, BLUR, ERODE, DILATE or BLUR.\n See Filters.js for docs on\n each available filter

\n', + type: 'Constant' + }, + { + name: 'filterParam', + description: + '

an optional parameter unique\n to each filter, see above

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nlet photo1;\nlet photo2;\n\nfunction preload() {\n photo1 = loadImage('assets/rockies.jpg');\n photo2 = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n photo2.filter(GRAY);\n image(photo1, 0, 0);\n image(photo2, width / 2, 0);\n}\n
" + ], + alt: + '2 images of rocky mountains left one in color, right in black and white', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/p5.Image.js', + line: 674, + description: + '

Copies a region of pixels from one image to another, using a specified\nblend mode to do the operation.

\n', + itemtype: 'method', + name: 'blend', + example: [ + "\n
\nlet mountains;\nlet bricks;\n\nfunction preload() {\n mountains = loadImage('assets/rockies.jpg');\n bricks = loadImage('assets/bricks_third.jpg');\n}\n\nfunction setup() {\n mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD);\n image(mountains, 0, 0);\n image(bricks, 0, 0);\n}\n
\n
\nlet mountains;\nlet bricks;\n\nfunction preload() {\n mountains = loadImage('assets/rockies.jpg');\n bricks = loadImage('assets/bricks_third.jpg');\n}\n\nfunction setup() {\n mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);\n image(mountains, 0, 0);\n image(bricks, 0, 0);\n}\n
\n
\nlet mountains;\nlet bricks;\n\nfunction preload() {\n mountains = loadImage('assets/rockies.jpg');\n bricks = loadImage('assets/bricks_third.jpg');\n}\n\nfunction setup() {\n mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);\n image(mountains, 0, 0);\n image(bricks, 0, 0);\n}\n
" + ], + alt: + 'image of rocky mountains. Brick images on left and right. Right overexposed\nimage of rockies. Brickwall images on left and right. Right mortar transparent\nimage of rockies. Brickwall images on left and right. Right translucent', + class: 'p5.Image', + module: 'Image', + submodule: 'Image', + overloads: [ + { + line: 674, + params: [ + { + name: 'srcImage', + description: '

source image

\n', + type: 'p5.Image' + }, + { + name: 'sx', + description: + '

X coordinate of the source's upper left corner

\n', + type: 'Integer' + }, + { + name: 'sy', + description: + '

Y coordinate of the source's upper left corner

\n', + type: 'Integer' + }, + { + name: 'sw', + description: '

source image width

\n', + type: 'Integer' + }, + { + name: 'sh', + description: '

source image height

\n', + type: 'Integer' + }, + { + name: 'dx', + description: + '

X coordinate of the destination's upper left corner

\n', + type: 'Integer' + }, + { + name: 'dy', + description: + '

Y coordinate of the destination's upper left corner

\n', + type: 'Integer' + }, + { + name: 'dw', + description: '

destination image width

\n', + type: 'Integer' + }, + { + name: 'dh', + description: '

destination image height

\n', + type: 'Integer' + }, + { + name: 'blendMode', + description: + '

the blend mode. either\n BLEND, DARKEST, LIGHTEST, DIFFERENCE,\n MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.

\n

Available blend modes are: normal | multiply | screen | overlay |\n darken | lighten | color-dodge | color-burn | hard-light |\n soft-light | difference | exclusion | hue | saturation |\n color | luminosity

\n

http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/

\n', + type: 'Constant' + } + ] + }, + { + line: 753, + params: [ + { + name: 'sx', + description: '', + type: 'Integer' + }, + { + name: 'sy', + description: '', + type: 'Integer' + }, + { + name: 'sw', + description: '', + type: 'Integer' + }, + { + name: 'sh', + description: '', + type: 'Integer' + }, + { + name: 'dx', + description: '', + type: 'Integer' + }, + { + name: 'dy', + description: '', + type: 'Integer' + }, + { + name: 'dw', + description: '', + type: 'Integer' + }, + { + name: 'dh', + description: '', + type: 'Integer' + }, + { + name: 'blendMode', + description: '', + type: 'Constant' + } + ] + } + ] + }, + { + file: 'src/image/p5.Image.js', + line: 796, + description: + '

Saves the image to a file and force the browser to download it.\nAccepts two strings for filename and file extension\nSupports png (default) and jpg.

\n', + itemtype: 'method', + name: 'save', + params: [ + { + name: 'filename', + description: '

give your file a name

\n', + type: 'String' + }, + { + name: 'extension', + description: '

'png' or 'jpg'

\n', + type: 'String' + } + ], + example: [ + "\n
\nlet photo;\n\nfunction preload() {\n photo = loadImage('assets/rockies.jpg');\n}\n\nfunction draw() {\n image(photo, 0, 0);\n}\n\nfunction keyTyped() {\n if (key === 's') {\n photo.save('photo', 'png');\n }\n}\n
" + ], + alt: 'image of rocky mountains.', + class: 'p5.Image', + module: 'Image', + submodule: 'Image' + }, + { + file: 'src/image/pixels.js', + line: 14, + description: + '

Uint8ClampedArray\ncontaining the values for all the pixels in the display window.\nThese values are numbers. This array is the size (include an appropriate\nfactor for pixelDensity) of the display window x4,\nrepresenting the R, G, B, A values in order for each pixel, moving from\nleft to right across each row, then down each column. Retina and other\nhigh density displays will have more pixels[] (by a factor of\npixelDensity^2).\nFor example, if the image is 100x100 pixels, there will be 40,000. On a\nretina display, there will be 160,000.\n

\nThe first four values (indices 0-3) in the array will be the R, G, B, A\nvalues of the pixel at (0, 0). The second four values (indices 4-7) will\ncontain the R, G, B, A values of the pixel at (1, 0). More generally, to\nset values for a pixel at (x, y):

\n
let d = pixelDensity();\nfor (let i = 0; i < d; i++) {\n  for (let j = 0; j < d; j++) {\n    // loop over\n    index = 4 * ((y * d + j) * width * d + (x * d + i));\n    pixels[index] = r;\n    pixels[index+1] = g;\n    pixels[index+2] = b;\n    pixels[index+3] = a;\n  }\n}\n
\n

While the above method is complex, it is flexible enough to work with\nany pixelDensity. Note that set() will automatically take care of\nsetting all the appropriate values in pixels[] for a given (x, y) at\nany pixelDensity, but the performance may not be as fast when lots of\nmodifications are made to the pixel array.\n

\nBefore accessing this array, the data must loaded with the loadPixels()\nfunction. After the array data has been modified, the updatePixels()\nfunction must be run to update the changes.\n

\nNote that this is not a standard javascript array. This means that\nstandard javascript functions such as slice() or\narrayCopy() do not\nwork.

', + itemtype: 'property', + name: 'pixels', + type: 'Number[]', + example: [ + '\n
\n\nlet pink = color(255, 102, 204);\nloadPixels();\nlet d = pixelDensity();\nlet halfImage = 4 * (width * d) * (height / 2 * d);\nfor (let i = 0; i < halfImage; i += 4) {\n pixels[i] = red(pink);\n pixels[i + 1] = green(pink);\n pixels[i + 2] = blue(pink);\n pixels[i + 3] = alpha(pink);\n}\nupdatePixels();\n\n
' + ], + alt: 'top half of canvas pink, bottom grey', + class: 'p5', + module: 'Image', + submodule: 'Pixels' + }, + { + file: 'src/image/pixels.js', + line: 83, + description: + '

Copies a region of pixels from one image to another, using a specified\nblend mode to do the operation.

\n', + itemtype: 'method', + name: 'blend', + example: [ + "\n
\nlet img0;\nlet img1;\n\nfunction preload() {\n img0 = loadImage('assets/rockies.jpg');\n img1 = loadImage('assets/bricks_third.jpg');\n}\n\nfunction setup() {\n background(img0);\n image(img1, 0, 0);\n blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);\n}\n
\n
\nlet img0;\nlet img1;\n\nfunction preload() {\n img0 = loadImage('assets/rockies.jpg');\n img1 = loadImage('assets/bricks_third.jpg');\n}\n\nfunction setup() {\n background(img0);\n image(img1, 0, 0);\n blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);\n}\n
\n
\nlet img0;\nlet img1;\n\nfunction preload() {\n img0 = loadImage('assets/rockies.jpg');\n img1 = loadImage('assets/bricks_third.jpg');\n}\n\nfunction setup() {\n background(img0);\n image(img1, 0, 0);\n blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD);\n}\n
" + ], + alt: + 'image of rocky mountains. Brick images on left and right. Right overexposed\nimage of rockies. Brickwall images on left and right. Right mortar transparent\nimage of rockies. Brickwall images on left and right. Right translucent', + class: 'p5', + module: 'Image', + submodule: 'Pixels', + overloads: [ + { + line: 83, + params: [ + { + name: 'srcImage', + description: '

source image

\n', + type: 'p5.Image' + }, + { + name: 'sx', + description: + '

X coordinate of the source's upper left corner

\n', + type: 'Integer' + }, + { + name: 'sy', + description: + '

Y coordinate of the source's upper left corner

\n', + type: 'Integer' + }, + { + name: 'sw', + description: '

source image width

\n', + type: 'Integer' + }, + { + name: 'sh', + description: '

source image height

\n', + type: 'Integer' + }, + { + name: 'dx', + description: + '

X coordinate of the destination's upper left corner

\n', + type: 'Integer' + }, + { + name: 'dy', + description: + '

Y coordinate of the destination's upper left corner

\n', + type: 'Integer' + }, + { + name: 'dw', + description: '

destination image width

\n', + type: 'Integer' + }, + { + name: 'dh', + description: '

destination image height

\n', + type: 'Integer' + }, + { + name: 'blendMode', + description: + '

the blend mode. either\n BLEND, DARKEST, LIGHTEST, DIFFERENCE,\n MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT,\n SOFT_LIGHT, DODGE, BURN, ADD or NORMAL.

\n', + type: 'Constant' + } + ] + }, + { + line: 156, + params: [ + { + name: 'sx', + description: '', + type: 'Integer' + }, + { + name: 'sy', + description: '', + type: 'Integer' + }, + { + name: 'sw', + description: '', + type: 'Integer' + }, + { + name: 'sh', + description: '', + type: 'Integer' + }, + { + name: 'dx', + description: '', + type: 'Integer' + }, + { + name: 'dy', + description: '', + type: 'Integer' + }, + { + name: 'dw', + description: '', + type: 'Integer' + }, + { + name: 'dh', + description: '', + type: 'Integer' + }, + { + name: 'blendMode', + description: '', + type: 'Constant' + } + ] + } + ] + }, + { + file: 'src/image/pixels.js', + line: 177, + description: + '

Copies a region of the canvas to another region of the canvas\nand copies a region of pixels from an image used as the srcImg parameter\ninto the canvas srcImage is specified this is used as the source. If\nthe source and destination regions aren't the same size, it will\nautomatically resize source pixels to fit the specified\ntarget region.

\n', + itemtype: 'method', + name: 'copy', + example: [ + "\n
\nlet img;\n\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n background(img);\n copy(img, 7, 22, 10, 10, 35, 25, 50, 50);\n stroke(255);\n noFill();\n // Rectangle shows area being copied\n rect(7, 22, 10, 10);\n}\n
" + ], + alt: + 'image of rocky mountains. Brick images on left and right. Right overexposed\nimage of rockies. Brickwall images on left and right. Right mortar transparent\nimage of rockies. Brickwall images on left and right. Right translucent', + class: 'p5', + module: 'Image', + submodule: 'Pixels', + overloads: [ + { + line: 177, + params: [ + { + name: 'srcImage', + description: '

source image

\n', + type: 'p5.Image|p5.Element' + }, + { + name: 'sx', + description: + '

X coordinate of the source's upper left corner

\n', + type: 'Integer' + }, + { + name: 'sy', + description: + '

Y coordinate of the source's upper left corner

\n', + type: 'Integer' + }, + { + name: 'sw', + description: '

source image width

\n', + type: 'Integer' + }, + { + name: 'sh', + description: '

source image height

\n', + type: 'Integer' + }, + { + name: 'dx', + description: + '

X coordinate of the destination's upper left corner

\n', + type: 'Integer' + }, + { + name: 'dy', + description: + '

Y coordinate of the destination's upper left corner

\n', + type: 'Integer' + }, + { + name: 'dw', + description: '

destination image width

\n', + type: 'Integer' + }, + { + name: 'dh', + description: '

destination image height

\n', + type: 'Integer' + } + ] + }, + { + line: 220, + params: [ + { + name: 'sx', + description: '', + type: 'Integer' + }, + { + name: 'sy', + description: '', + type: 'Integer' + }, + { + name: 'sw', + description: '', + type: 'Integer' + }, + { + name: 'sh', + description: '', + type: 'Integer' + }, + { + name: 'dx', + description: '', + type: 'Integer' + }, + { + name: 'dy', + description: '', + type: 'Integer' + }, + { + name: 'dw', + description: '', + type: 'Integer' + }, + { + name: 'dh', + description: '', + type: 'Integer' + } + ] + } + ] + }, + { + file: 'src/image/pixels.js', + line: 236, + description: + '

Applies a filter to the canvas.\n

\n

The presets options are:\n

\n

THRESHOLD\nConverts the image to black and white pixels depending if they are above or\nbelow the threshold defined by the level parameter. The parameter must be\nbetween 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.\n

\n

GRAY\nConverts any colors in the image to grayscale equivalents. No parameter\nis used.\n

\n

OPAQUE\nSets the alpha channel to entirely opaque. No parameter is used.\n

\n

INVERT\nSets each pixel to its inverse value. No parameter is used.\n

\n

POSTERIZE\nLimits each channel of the image to the number of colors specified as the\nparameter. The parameter can be set to values between 2 and 255, but\nresults are most noticeable in the lower ranges.\n

\n

BLUR\nExecutes a Gaussian blur with the level parameter specifying the extent\nof the blurring. If no parameter is used, the blur is equivalent to\nGaussian blur of radius 1. Larger values increase the blur.\n

\n

ERODE\nReduces the light areas. No parameter is used.\n

\n

DILATE\nIncreases the light areas. No parameter is used.

\n', + itemtype: 'method', + name: 'filter', + params: [ + { + name: 'filterType', + description: + '

either THRESHOLD, GRAY, OPAQUE, INVERT,\n POSTERIZE, BLUR, ERODE, DILATE or BLUR.\n See Filters.js for docs on\n each available filter

\n', + type: 'Constant' + }, + { + name: 'filterParam', + description: + '

an optional parameter unique\n to each filter, see above

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n filter(THRESHOLD);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n filter(GRAY);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n filter(OPAQUE);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n filter(INVERT);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n filter(POSTERIZE, 3);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n filter(DILATE);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n filter(BLUR, 3);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/bricks.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n filter(ERODE);\n}\n\n
" + ], + alt: + 'black and white image of a brick wall.\ngreyscale image of a brickwall\nimage of a brickwall\njade colored image of a brickwall\nred and pink image of a brickwall\nimage of a brickwall\nblurry image of a brickwall\nimage of a brickwall\nimage of a brickwall with less detail', + class: 'p5', + module: 'Image', + submodule: 'Pixels' + }, + { + file: 'src/image/pixels.js', + line: 415, + description: + '

Get a region of pixels, or a single pixel, from the canvas.

\n

Returns an array of [R,G,B,A] values for any pixel or grabs a section of\nan image. If no parameters are specified, the entire image is returned.\nUse the x and y parameters to get the value of one pixel. Get a section of\nthe display window by specifying additional w and h parameters. When\ngetting an image, the x and y parameters define the coordinates for the\nupper-left corner of the image, regardless of the current imageMode().\n

\nGetting the color of a single pixel with get(x, y) is easy, but not as fast\nas grabbing the data directly from pixels[]. The equivalent statement to\nget(x, y) using pixels[] with pixel density d is

\n
let x, y, d; // set these to the coordinates\nlet off = (y * width + x) * d * 4;\nlet components = [\n  pixels[off],\n  pixels[off + 1],\n  pixels[off + 2],\n  pixels[off + 3]\n];\nprint(components);\n
\n



\n

See the reference for pixels[] for more information.

\n

If you want to extract an array of colors or a subimage from an p5.Image object,\ntake a look at p5.Image.get()

\n', + itemtype: 'method', + name: 'get', + return: { + description: 'the rectangle p5.Image', + type: 'p5.Image' + }, + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n let c = get();\n image(c, width / 2, 0);\n}\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\nfunction setup() {\n image(img, 0, 0);\n let c = get(50, 90);\n fill(c);\n noStroke();\n rect(25, 25, 50, 50);\n}\n\n
" + ], + alt: + '2 images of the rocky mountains, side-by-side\nImage of the rocky mountains with 50x50 green rect in center of canvas', + class: 'p5', + module: 'Image', + submodule: 'Pixels', + overloads: [ + { + line: 415, + params: [ + { + name: 'x', + description: '

x-coordinate of the pixel

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the pixel

\n', + type: 'Number' + }, + { + name: 'w', + description: '

width

\n', + type: 'Number' + }, + { + name: 'h', + description: '

height

\n', + type: 'Number' + } + ], + return: { + description: 'the rectangle p5.Image', + type: 'p5.Image' + } + }, + { + line: 488, + params: [], + return: { + description: 'the whole p5.Image', + type: 'p5.Image' + } + }, + { + line: 492, + params: [ + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + } + ], + return: { + description: 'color of pixel at x,y in array format [R, G, B, A]', + type: 'Number[]' + } + } + ] + }, + { + file: 'src/image/pixels.js', + line: 503, + description: + '

Loads the pixel data for the display window into the pixels[] array. This\nfunction must always be called before reading from or writing to pixels[].\nNote that only changes made with set() or direct manipulation of pixels[]\nwill occur.

\n', + itemtype: 'method', + name: 'loadPixels', + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n image(img, 0, 0, width, height);\n let d = pixelDensity();\n let halfImage = 4 * (width * d) * (height * d / 2);\n loadPixels();\n for (let i = 0; i < halfImage; i++) {\n pixels[i + halfImage] = pixels[i];\n }\n updatePixels();\n}\n\n
" + ], + alt: + 'two images of the rocky mountains. one on top, one on bottom of canvas.', + class: 'p5', + module: 'Image', + submodule: 'Pixels' + }, + { + file: 'src/image/pixels.js', + line: 540, + description: + '

Changes the color of any pixel, or writes an image directly to the\ndisplay window.

\n

The x and y parameters specify the pixel to change and the c parameter\nspecifies the color value. This can be a p5.Color object, or [R, G, B, A]\npixel array. It can also be a single grayscale value.\nWhen setting an image, the x and y parameters define the coordinates for\nthe upper-left corner of the image, regardless of the current imageMode().\n

\n

\nAfter using set(), you must call updatePixels() for your changes to appear.\nThis should be called once all pixels have been set, and must be called before\ncalling .get() or drawing the image.\n

\n

Setting the color of a single pixel with set(x, y) is easy, but not as\nfast as putting the data directly into pixels[]. Setting the pixels[]\nvalues directly may be complicated when working with a retina display,\nbut will perform better when lots of pixels need to be set directly on\nevery loop.

\n

See the reference for pixels[] for more information.

', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'x', + description: '

x-coordinate of the pixel

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of the pixel

\n', + type: 'Number' + }, + { + name: 'c', + description: + '

insert a grayscale value | a pixel array |\n a p5.Color object | a p5.Image to copy

\n', + type: 'Number|Number[]|Object' + } + ], + example: [ + "\n
\n\nlet black = color(0);\nset(30, 20, black);\nset(85, 20, black);\nset(85, 75, black);\nset(30, 75, black);\nupdatePixels();\n\n
\n\n
\n\nfor (let i = 30; i < width - 15; i++) {\n for (let j = 20; j < height - 25; j++) {\n let c = color(204 - j, 153 - i, 0);\n set(i, j, c);\n }\n}\nupdatePixels();\n\n
\n\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n set(0, 0, img);\n updatePixels();\n line(0, 0, width, height);\n line(0, height, width, 0);\n}\n\n
" + ], + alt: + "4 black points in the shape of a square middle-right of canvas.\nsquare with orangey-brown gradient lightening at bottom right.\nimage of the rocky mountains. with lines like an 'x' through the center.", + class: 'p5', + module: 'Image', + submodule: 'Pixels' + }, + { + file: 'src/image/pixels.js', + line: 614, + description: + '

Updates the display window with the data in the pixels[] array.\nUse in conjunction with loadPixels(). If you're only reading pixels from\nthe array, there's no need to call updatePixels() — updating is only\nnecessary to apply changes. updatePixels() should be called anytime the\npixels array is manipulated or set() is called, and only changes made with\nset() or direct changes to pixels[] will occur.

\n', + itemtype: 'method', + name: 'updatePixels', + params: [ + { + name: 'x', + description: + '

x-coordinate of the upper-left corner of region\n to update

\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: + '

y-coordinate of the upper-left corner of region\n to update

\n', + type: 'Number', + optional: true + }, + { + name: 'w', + description: '

width of region to update

\n', + type: 'Number', + optional: true + }, + { + name: 'h', + description: '

height of region to update

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/rockies.jpg');\n}\n\nfunction setup() {\n image(img, 0, 0, width, height);\n let d = pixelDensity();\n let halfImage = 4 * (width * d) * (height * d / 2);\n loadPixels();\n for (let i = 0; i < halfImage; i++) {\n pixels[i + halfImage] = pixels[i];\n }\n updatePixels();\n}\n\n
" + ], + alt: + 'two images of the rocky mountains. one on top, one on bottom of canvas.', + class: 'p5', + module: 'Image', + submodule: 'Pixels' + }, + { + file: 'src/io/files.js', + line: 19, + description: + '

Loads a JSON file from a file or a URL, and returns an Object.\nNote that even if the JSON file contains an Array, an Object will be\nreturned with index numbers as keys.

\n

This method is asynchronous, meaning it may not finish before the next\nline in your sketch is executed. JSONP is supported via a polyfill and you\ncan pass in as the second argument an object with definitions of the json\ncallback following the syntax specified here.

\n

This method is suitable for fetching files up to size of 64MB.

\n', + itemtype: 'method', + name: 'loadJSON', + return: { + description: 'JSON data', + type: 'Object|Array' + }, + example: [ + '\n\n

Calling loadJSON() inside preload() guarantees to complete the\noperation before setup() and draw() are called.

\n\n
\n// Examples use USGS Earthquake API:\n// https://earthquake.usgs.gov/fdsnws/event/1/#methods\nlet earthquakes;\nfunction preload() {\n // Get the most recent earthquake in the database\n let url =\n \'https://earthquake.usgs.gov/earthquakes/feed/v1.0/\' +\n \'summary/all_day.geojson\';\n earthquakes = loadJSON(url);\n}\n\nfunction setup() {\n noLoop();\n}\n\nfunction draw() {\n background(200);\n // Get the magnitude and name of the earthquake out of the loaded JSON\n let earthquakeMag = earthquakes.features[0].properties.mag;\n let earthquakeName = earthquakes.features[0].properties.place;\n ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);\n textAlign(CENTER);\n text(earthquakeName, 0, height - 30, width, 30);\n}\n
\n\n\n

Outside of preload(), you may supply a callback function to handle the\nobject:

\n
\nfunction setup() {\n noLoop();\n let url =\n \'https://earthquake.usgs.gov/earthquakes/feed/v1.0/\' +\n \'summary/all_day.geojson\';\n loadJSON(url, drawEarthquake);\n}\n\nfunction draw() {\n background(200);\n}\n\nfunction drawEarthquake(earthquakes) {\n // Get the magnitude and name of the earthquake out of the loaded JSON\n let earthquakeMag = earthquakes.features[0].properties.mag;\n let earthquakeName = earthquakes.features[0].properties.place;\n ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);\n textAlign(CENTER);\n text(earthquakeName, 0, height - 30, width, 30);\n}\n
' + ], + alt: + '50x50 ellipse that changes from black to white depending on the current humidity\n50x50 ellipse that changes from black to white depending on the current humidity', + class: 'p5', + module: 'IO', + submodule: 'Input', + overloads: [ + { + line: 19, + params: [ + { + name: 'path', + description: '

name of the file or url to load

\n', + type: 'String' + }, + { + name: 'jsonpOptions', + description: '

options object for jsonp related settings

\n', + type: 'Object', + optional: true + }, + { + name: 'datatype', + description: '

"json" or "jsonp"

\n', + type: 'String', + optional: true + }, + { + name: 'callback', + description: + '

function to be executed after\n loadJSON() completes, data is passed\n in as first argument

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to be executed if\n there is an error, response is passed\n in as first argument

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'JSON data', + type: 'Object|Array' + } + }, + { + line: 105, + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'datatype', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'Object|Array' + } + }, + { + line: 113, + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function' + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'Object|Array' + } + } + ] + }, + { + file: 'src/io/files.js', + line: 184, + description: + '

Reads the contents of a file and creates a String array of its individual\nlines. If the name of the file is used as the parameter, as in the above\nexample, the file must be located in the sketch directory/folder.\n

\nAlternatively, the file maybe be loaded from anywhere on the local\ncomputer using an absolute path (something that starts with / on Unix and\nLinux, or a drive letter on Windows), or the filename parameter can be a\nURL for a file found on a network.\n

\nThis method is asynchronous, meaning it may not finish before the next\nline in your sketch is executed.

\n

This method is suitable for fetching files up to size of 64MB.

\n', + itemtype: 'method', + name: 'loadStrings', + params: [ + { + name: 'filename', + description: '

name of the file or url to load

\n', + type: 'String' + }, + { + name: 'callback', + description: + '

function to be executed after loadStrings()\n completes, Array is passed in as first\n argument

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to be executed if\n there is an error, response is passed\n in as first argument

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'Array of Strings', + type: 'String[]' + }, + example: [ + '\n\n

Calling loadStrings() inside preload() guarantees to complete the\noperation before setup() and draw() are called.

\n\n
\nlet result;\nfunction preload() {\n result = loadStrings(\'assets/test.txt\');\n}\n\nfunction setup() {\n background(200);\n let ind = floor(random(result.length));\n text(result[ind], 10, 10, 80, 80);\n}\n
\n\n

Outside of preload(), you may supply a callback function to handle the\nobject:

\n\n
\nfunction setup() {\n loadStrings(\'assets/test.txt\', pickString);\n}\n\nfunction pickString(result) {\n background(200);\n let ind = floor(random(result.length));\n text(result[ind], 10, 10, 80, 80);\n}\n
' + ], + alt: + 'randomly generated text from a file, for example "i smell like butter"\nrandomly generated text from a file, for example "i have three feet"', + class: 'p5', + module: 'IO', + submodule: 'Input' + }, + { + file: 'src/io/files.js', + line: 297, + description: + '

Reads the contents of a file or URL and creates a p5.Table object with\nits values. If a file is specified, it must be located in the sketch's\n"data" folder. The filename parameter can also be a URL to a file found\nonline. By default, the file is assumed to be comma-separated (in CSV\nformat). Table only looks for a header row if the 'header' option is\nincluded.

\n\n

Possible options include:\n

    \n
  • csv - parse the table as comma-separated values
  • \n
  • tsv - parse the table as tab-separated values
  • \n
  • header - this table has a header (title) row
  • \n
\n

\n\n

When passing in multiple options, pass them in as separate parameters,\nseperated by commas. For example:\n

\n\nloadTable('my_csv_file.csv', 'csv', 'header');\n\n

\n\n

All files loaded and saved use UTF-8 encoding.

\n\n

This method is asynchronous, meaning it may not finish before the next\nline in your sketch is executed. Calling loadTable() inside preload()\nguarantees to complete the operation before setup() and draw() are called.\n

Outside of preload(), you may supply a callback function to handle the\nobject:

\n

\n\n

This method is suitable for fetching files up to size of 64MB.

\n', + itemtype: 'method', + name: 'loadTable', + return: { + description: 'Table object containing data', + type: 'Object' + }, + example: [ + '\n
\n\n// Given the following CSV file called "mammals.csv"\n// located in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n //the file can be remote\n //table = loadTable("http://p5js.org/reference/assets/mammals.csv",\n // "csv", "header");\n}\n\nfunction setup() {\n //count the columns\n print(table.getRowCount() + \' total rows in table\');\n print(table.getColumnCount() + \' total columns in table\');\n\n print(table.getColumn(\'name\'));\n //["Goat", "Leopard", "Zebra"]\n\n //cycle through the table\n for (let r = 0; r < table.getRowCount(); r++)\n for (let c = 0; c < table.getColumnCount(); c++) {\n print(table.getString(r, c));\n }\n}\n\n
' + ], + alt: + 'randomly generated text from a file, for example "i smell like butter"\nrandomly generated text from a file, for example "i have three feet"', + class: 'p5', + module: 'IO', + submodule: 'Input', + overloads: [ + { + line: 297, + params: [ + { + name: 'filename', + description: '

name of the file or URL to load

\n', + type: 'String' + }, + { + name: 'options', + description: + '

"header" "csv" "tsv"

\n', + type: 'String' + }, + { + name: 'callback', + description: + '

function to be executed after\n loadTable() completes. On success, the\n Table object is passed in as the\n first argument.

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to be executed if\n there is an error, response is passed\n in as first argument

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'Table object containing data', + type: 'Object' + } + }, + { + line: 387, + params: [ + { + name: 'filename', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'Object' + } + } + ] + }, + { + file: 'src/io/files.js', + line: 607, + description: + '

Reads the contents of a file and creates an XML object with its values.\nIf the name of the file is used as the parameter, as in the above example,\nthe file must be located in the sketch directory/folder.

\n

Alternatively, the file maybe be loaded from anywhere on the local\ncomputer using an absolute path (something that starts with / on Unix and\nLinux, or a drive letter on Windows), or the filename parameter can be a\nURL for a file found on a network.

\n

This method is asynchronous, meaning it may not finish before the next\nline in your sketch is executed. Calling loadXML() inside preload()\nguarantees to complete the operation before setup() and draw() are called.

\n

Outside of preload(), you may supply a callback function to handle the\nobject.

\n

This method is suitable for fetching files up to size of 64MB.

\n', + itemtype: 'method', + name: 'loadXML', + params: [ + { + name: 'filename', + description: '

name of the file or URL to load

\n', + type: 'String' + }, + { + name: 'callback', + description: + '

function to be executed after loadXML()\n completes, XML object is passed in as\n first argument

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to be executed if\n there is an error, response is passed\n in as first argument

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'XML object containing data', + type: 'Object' + }, + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let children = xml.getChildren(\'animal\');\n\n for (let i = 0; i < children.length; i++) {\n let id = children[i].getNum(\'id\');\n let coloring = children[i].getString(\'species\');\n let name = children[i].getContent();\n print(id + \', \' + coloring + \', \' + name);\n }\n}\n\n// Sketch prints:\n// 0, Capra hircus, Goat\n// 1, Panthera pardus, Leopard\n// 2, Equus zebra, Zebra\n
' + ], + alt: 'no image displayed', + class: 'p5', + module: 'IO', + submodule: 'Input' + }, + { + file: 'src/io/files.js', + line: 718, + description: + '

This method is suitable for fetching files up to size of 64MB.

\n', + itemtype: 'method', + name: 'loadBytes', + params: [ + { + name: 'file', + description: '

name of the file or URL to load

\n', + type: 'String' + }, + { + name: 'callback', + description: + '

function to be executed after loadBytes()\n completes

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to be executed if there\n is an error

\n', + type: 'Function', + optional: true + } + ], + return: { + description: "an object whose 'bytes' property will be the loaded buffer", + type: 'Object' + }, + example: [ + "\n
\nlet data;\n\nfunction preload() {\n data = loadBytes('assets/mammals.xml');\n}\n\nfunction setup() {\n for (let i = 0; i < 5; i++) {\n console.log(data.bytes[i].toString(16));\n }\n}\n
" + ], + alt: 'no image displayed', + class: 'p5', + module: 'IO', + submodule: 'Input' + }, + { + file: 'src/io/files.js', + line: 778, + description: + '

Method for executing an HTTP GET request. If data type is not specified,\np5 will try to guess based on the URL, defaulting to text. This is equivalent to\ncalling httpDo(path, 'GET'). The 'binary' datatype will return\na Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer\nwhich can be used to initialize typed arrays (such as Uint8Array).

\n', + itemtype: 'method', + name: 'httpGet', + return: { + description: + 'A promise that resolves with the data when the operation\n completes successfully or rejects with the error after\n one occurs.', + type: 'Promise' + }, + example: [ + "\n
\n// Examples use USGS Earthquake API:\n// https://earthquake.usgs.gov/fdsnws/event/1/#methods\nlet earthquakes;\nfunction preload() {\n // Get the most recent earthquake in the database\n let url =\n 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +\n 'format=geojson&limit=1&orderby=time';\n httpGet(url, 'jsonp', false, function(response) {\n // when the HTTP request completes, populate the variable that holds the\n // earthquake data used in the visualization.\n earthquakes = response;\n });\n}\n\nfunction draw() {\n if (!earthquakes) {\n // Wait until the earthquake data has loaded before drawing.\n return;\n }\n background(200);\n // Get the magnitude and name of the earthquake out of the loaded JSON\n let earthquakeMag = earthquakes.features[0].properties.mag;\n let earthquakeName = earthquakes.features[0].properties.place;\n ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);\n textAlign(CENTER);\n text(earthquakeName, 0, height - 30, width, 30);\n noLoop();\n}\n
" + ], + class: 'p5', + module: 'IO', + submodule: 'Input', + overloads: [ + { + line: 778, + params: [ + { + name: 'path', + description: '

name of the file or url to load

\n', + type: 'String' + }, + { + name: 'datatype', + description: + '

"json", "jsonp", "binary", "arrayBuffer",\n "xml", or "text"

\n', + type: 'String', + optional: true + }, + { + name: 'data', + description: '

param data passed sent with request

\n', + type: 'Object|Boolean', + optional: true + }, + { + name: 'callback', + description: + '

function to be executed after\n httpGet() completes, data is passed in\n as first argument

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to be executed if\n there is an error, response is passed\n in as first argument

\n', + type: 'Function', + optional: true + } + ], + return: { + description: + 'A promise that resolves with the data when the operation\n completes successfully or rejects with the error after\n one occurs.', + type: 'Promise' + } + }, + { + line: 832, + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'data', + description: '', + type: 'Object|Boolean' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'Promise' + } + }, + { + line: 840, + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function' + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'Promise' + } + } + ] + }, + { + file: 'src/io/files.js', + line: 855, + description: + '

Method for executing an HTTP POST request. If data type is not specified,\np5 will try to guess based on the URL, defaulting to text. This is equivalent to\ncalling httpDo(path, 'POST').

\n', + itemtype: 'method', + name: 'httpPost', + return: { + description: + 'A promise that resolves with the data when the operation\n completes successfully or rejects with the error after\n one occurs.', + type: 'Promise' + }, + example: [ + "\n
\n\n// Examples use jsonplaceholder.typicode.com for a Mock Data API\n\nlet url = 'https://jsonplaceholder.typicode.com/posts';\nlet postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is way cool.' };\n\nfunction setup() {\n createCanvas(800, 800);\n}\n\nfunction mousePressed() {\n // Pick new random color values\n let r = random(255);\n let g = random(255);\n let b = random(255);\n\n httpPost(url, 'json', postData, function(result) {\n strokeWeight(2);\n stroke(r, g, b);\n fill(r, g, b, 127);\n ellipse(mouseX, mouseY, 200, 200);\n text(result.body, mouseX, mouseY);\n });\n}\n\n
\n\n\n
\nlet url = 'https://invalidURL'; // A bad URL that will cause errors\nlet postData = { title: 'p5 Clicked!', body: 'p5.js is way cool.' };\n\nfunction setup() {\n createCanvas(800, 800);\n}\n\nfunction mousePressed() {\n // Pick new random color values\n let r = random(255);\n let g = random(255);\n let b = random(255);\n\n httpPost(\n url,\n 'json',\n postData,\n function(result) {\n // ... won't be called\n },\n function(error) {\n strokeWeight(2);\n stroke(r, g, b);\n fill(r, g, b, 127);\n text(error.toString(), mouseX, mouseY);\n }\n );\n}\n
\n" + ], + class: 'p5', + module: 'IO', + submodule: 'Input', + overloads: [ + { + line: 855, + params: [ + { + name: 'path', + description: '

name of the file or url to load

\n', + type: 'String' + }, + { + name: 'datatype', + description: + '

"json", "jsonp", "xml", or "text".\n If omitted, httpPost() will guess.

\n', + type: 'String', + optional: true + }, + { + name: 'data', + description: '

param data passed sent with request

\n', + type: 'Object|Boolean', + optional: true + }, + { + name: 'callback', + description: + '

function to be executed after\n httpPost() completes, data is passed in\n as first argument

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to be executed if\n there is an error, response is passed\n in as first argument

\n', + type: 'Function', + optional: true + } + ], + return: { + description: + 'A promise that resolves with the data when the operation\n completes successfully or rejects with the error after\n one occurs.', + type: 'Promise' + } + }, + { + line: 937, + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'data', + description: '', + type: 'Object|Boolean' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'Promise' + } + }, + { + line: 945, + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'callback', + description: '', + type: 'Function' + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'Promise' + } + } + ] + }, + { + file: 'src/io/files.js', + line: 960, + description: + '

Method for executing an HTTP request. If data type is not specified,\np5 will try to guess based on the URL, defaulting to text.

\nFor more advanced use, you may also pass in the path as the first argument\nand a object as the second argument, the signature follows the one specified\nin the Fetch API specification.\nThis method is suitable for fetching files up to size of 64MB when "GET" is used.

\n', + itemtype: 'method', + name: 'httpDo', + return: { + description: + 'A promise that resolves with the data when the operation\n completes successfully or rejects with the error after\n one occurs.', + type: 'Promise' + }, + example: [ + "\n
\n\n// Examples use USGS Earthquake API:\n// https://earthquake.usgs.gov/fdsnws/event/1/#methods\n\n// displays an animation of all USGS earthquakes\nlet earthquakes;\nlet eqFeatureIndex = 0;\n\nfunction preload() {\n let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';\n httpDo(\n url,\n {\n method: 'GET',\n // Other Request options, like special headers for apis\n headers: { authorization: 'Bearer secretKey' }\n },\n function(res) {\n earthquakes = res;\n }\n );\n}\n\nfunction draw() {\n // wait until the data is loaded\n if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {\n return;\n }\n clear();\n\n let feature = earthquakes.features[eqFeatureIndex];\n let mag = feature.properties.mag;\n let rad = mag / 11 * ((width + height) / 2);\n fill(255, 0, 0, 100);\n ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad);\n\n if (eqFeatureIndex >= earthquakes.features.length) {\n eqFeatureIndex = 0;\n } else {\n eqFeatureIndex += 1;\n }\n}\n\n
" + ], + class: 'p5', + module: 'IO', + submodule: 'Input', + overloads: [ + { + line: 960, + params: [ + { + name: 'path', + description: '

name of the file or url to load

\n', + type: 'String' + }, + { + name: 'method', + description: + '

either "GET", "POST", or "PUT",\n defaults to "GET"

\n', + type: 'String', + optional: true + }, + { + name: 'datatype', + description: + '

"json", "jsonp", "xml", or "text"

\n', + type: 'String', + optional: true + }, + { + name: 'data', + description: '

param data passed sent with request

\n', + type: 'Object', + optional: true + }, + { + name: 'callback', + description: + '

function to be executed after\n httpGet() completes, data is passed in\n as first argument

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to be executed if\n there is an error, response is passed\n in as first argument

\n', + type: 'Function', + optional: true + } + ], + return: { + description: + 'A promise that resolves with the data when the operation\n completes successfully or rejects with the error after\n one occurs.', + type: 'Promise' + } + }, + { + line: 1031, + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'options', + description: + '

Request object options as documented in the\n "fetch" API\nreference

\n', + type: 'Object' + }, + { + name: 'callback', + description: '', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: '', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'Promise' + } + } + ] + }, + { + file: 'src/io/files.js', + line: 1193, + itemtype: 'method', + name: 'createWriter', + params: [ + { + name: 'name', + description: '

name of the file to be created

\n', + type: 'String' + }, + { + name: 'extension', + description: '', + type: 'String', + optional: true + } + ], + return: { + description: '', + type: 'p5.PrintWriter' + }, + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100);\n background(200);\n text('click here to save', 10, 10, 70, 80);\n}\n\nfunction mousePressed() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n var writer = createWriter('squares.txt');\n for (let i = 0; i < 10; i++) {\n writer.print(i * i);\n }\n writer.close();\n writer.clear();\n }\n}\n\n
" + ], + class: 'p5', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/files.js', + line: 1248, + description: '

Writes data to the PrintWriter stream

\n', + itemtype: 'method', + name: 'write', + params: [ + { + name: 'data', + description: '

all data to be written by the PrintWriter

\n', + type: 'Array' + } + ], + example: [ + "\n
\n\n// creates a file called 'newFile.txt'\nlet writer = createWriter('newFile.txt');\n// write 'Hello world!'' to the file\nwriter.write(['Hello world!']);\n// close the PrintWriter and save the file\nwriter.close();\n\n
\n
\n\n// creates a file called 'newFile2.txt'\nlet writer = createWriter('newFile2.txt');\n// write 'apples,bananas,123' to the file\nwriter.write(['apples', 'bananas', 123]);\n// close the PrintWriter and save the file\nwriter.close();\n\n
\n
\n\n// creates a file called 'newFile3.txt'\nlet writer = createWriter('newFile3.txt');\n// write 'My name is: Teddy' to the file\nwriter.write('My name is:');\nwriter.write(' Teddy');\n// close the PrintWriter and save the file\nwriter.close();\n\n
" + ], + class: 'p5.PrintWriter', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/files.js', + line: 1288, + description: + '

Writes data to the PrintWriter stream, and adds a new line at the end

\n', + itemtype: 'method', + name: 'print', + params: [ + { + name: 'data', + description: '

all data to be printed by the PrintWriter

\n', + type: 'Array' + } + ], + example: [ + "\n
\n\n// creates a file called 'newFile.txt'\nlet writer = createWriter('newFile.txt');\n// creates a file containing\n// My name is:\n// Teddy\nwriter.print('My name is:');\nwriter.print('Teddy');\n// close the PrintWriter and save the file\nwriter.close();\n\n
\n
\n\nlet writer;\n\nfunction setup() {\n createCanvas(400, 400);\n // create a PrintWriter\n writer = createWriter('newFile.txt');\n}\n\nfunction draw() {\n // print all mouseX and mouseY coordinates to the stream\n writer.print([mouseX, mouseY]);\n}\n\nfunction mouseClicked() {\n // close the PrintWriter and save the file\n writer.close();\n}\n\n
" + ], + class: 'p5.PrintWriter', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/files.js', + line: 1331, + description: + '

Clears the data already written to the PrintWriter object

\n', + itemtype: 'method', + name: 'clear', + example: [ + "\n
\n// create writer object\nlet writer = createWriter('newFile.txt');\nwriter.write(['clear me']);\n// clear writer object here\nwriter.clear();\n// close writer\nwriter.close();\n
\n" + ], + class: 'p5.PrintWriter', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/files.js', + line: 1349, + description: '

Closes the PrintWriter

\n', + itemtype: 'method', + name: 'close', + example: [ + "\n
\n\n// create a file called 'newFile.txt'\nlet writer = createWriter('newFile.txt');\n// close the PrintWriter and save the file\nwriter.close();\n\n
\n
\n\n// create a file called 'newFile2.txt'\nlet writer = createWriter('newFile2.txt');\n// write some data to the file\nwriter.write([100, 101, 102]);\n// close the PrintWriter and save the file\nwriter.close();\n\n
" + ], + class: 'p5.PrintWriter', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/files.js', + line: 1398, + description: + "

Save an image, text, json, csv, wav, or html. Prompts download to\nthe client's computer. Note that it is not recommended to call save()\nwithin draw if it's looping, as the save() function will open a new save\ndialog every frame.

\n

The default behavior is to save the canvas as an image. You can\noptionally specify a filename.\nFor example:

\n
\n save();\n save('myCanvas.jpg'); // save a specific canvas with a filename\n 
\n\n

Alternately, the first parameter can be a pointer to a canvas\np5.Element, an Array of Strings,\nan Array of JSON, a JSON object, a p5.Table, a p5.Image, or a\np5.SoundFile (requires p5.sound). The second parameter is a filename\n(including extension). The third parameter is for options specific\nto this type of object. This method will save a file that fits the\ngiven parameters. For example:

\n\n
\n // Saves canvas as an image\n save('myCanvas.jpg');\n\n // Saves pImage as a png image\n let img = createImage(10, 10);\n save(img, 'my.png');\n\n // Saves canvas as an image\n let cnv = createCanvas(100, 100);\n save(cnv, 'myCanvas.jpg');\n\n // Saves p5.Renderer object as an image\n let gb = createGraphics(100, 100);\n save(gb, 'myGraphics.jpg');\n\n let myTable = new p5.Table();\n\n // Saves table as html file\n save(myTable, 'myTable.html');\n\n // Comma Separated Values\n save(myTable, 'myTable.csv');\n\n // Tab Separated Values\n save(myTable, 'myTable.tsv');\n\n let myJSON = { a: 1, b: true };\n\n // Saves pretty JSON\n save(myJSON, 'my.json');\n\n // Optimizes JSON filesize\n save(myJSON, 'my.json', true);\n\n // Saves array of strings to a text file with line breaks after each item\n let arrayOfStrings = ['a', 'b'];\n save(arrayOfStrings, 'my.txt');\n 
", + itemtype: 'method', + name: 'save', + params: [ + { + name: 'objectOrFilename', + description: + '

If filename is provided, will\n save canvas as an image with\n either png or jpg extension\n depending on the filename.\n If object is provided, will\n save depending on the object\n and filename (see examples\n above).

\n', + type: 'Object|String', + optional: true + }, + { + name: 'filename', + description: + '

If an object is provided as the first\n parameter, then the second parameter\n indicates the filename,\n and should include an appropriate\n file extension (see examples above).

\n', + type: 'String', + optional: true + }, + { + name: 'options', + description: + '

Additional options depend on\n filetype. For example, when saving JSON,\n true indicates that the\n output will be optimized for filesize,\n rather than readability.

\n', + type: 'Boolean|String', + optional: true + } + ], + class: 'p5', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/files.js', + line: 1526, + description: + '

Writes the contents of an Array or a JSON object to a .json file.\nThe file saving process and location of the saved file will\nvary between web browsers.

\n', + itemtype: 'method', + name: 'saveJSON', + params: [ + { + name: 'json', + description: '', + type: 'Array|Object' + }, + { + name: 'filename', + description: '', + type: 'String' + }, + { + name: 'optimize', + description: + '

If true, removes line breaks\n and spaces from the output\n file to optimize filesize\n (but not readability).

\n', + type: 'Boolean', + optional: true + } + ], + example: [ + '\n
\n let json = {}; // new JSON Object\n\n json.id = 0;\n json.species = \'Panthera leo\';\n json.name = \'Lion\';\n\n function setup() {\n createCanvas(100, 100);\n background(200);\n text(\'click here to save\', 10, 10, 70, 80);\n }\n\n function mousePressed() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n saveJSON(json, \'lion.json\');\n }\n }\n\n // saves the following to a file called "lion.json":\n // {\n // "id": 0,\n // "species": "Panthera leo",\n // "name": "Lion"\n // }\n
' + ], + alt: 'no image displayed', + class: 'p5', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/files.js', + line: 1584, + description: + '

Writes an array of Strings to a text file, one line per String.\nThe file saving process and location of the saved file will\nvary between web browsers.

\n', + itemtype: 'method', + name: 'saveStrings', + params: [ + { + name: 'list', + description: '

string array to be written

\n', + type: 'String[]' + }, + { + name: 'filename', + description: '

filename for output

\n', + type: 'String' + }, + { + name: 'extension', + description: '

the filename's extension

\n', + type: 'String', + optional: true + } + ], + example: [ + "\n
\n let words = 'apple bear cat dog';\n\n // .split() outputs an Array\n let list = split(words, ' ');\n\n function setup() {\n createCanvas(100, 100);\n background(200);\n text('click here to save', 10, 10, 70, 80);\n }\n\n function mousePressed() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n saveStrings(list, 'nouns.txt');\n }\n }\n\n // Saves the following to a file called 'nouns.txt':\n //\n // apple\n // bear\n // cat\n // dog\n
" + ], + alt: 'no image displayed', + class: 'p5', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/files.js', + line: 1652, + description: + '

Writes the contents of a Table object to a file. Defaults to a\ntext file with comma-separated-values ('csv') but can also\nuse tab separation ('tsv'), or generate an HTML table ('html').\nThe file saving process and location of the saved file will\nvary between web browsers.

\n', + itemtype: 'method', + name: 'saveTable', + params: [ + { + name: 'Table', + description: + '

the Table object to save to a file

\n', + type: 'p5.Table' + }, + { + name: 'filename', + description: '

the filename to which the Table should be saved

\n', + type: 'String' + }, + { + name: 'options', + description: + '

can be one of "tsv", "csv", or "html"

\n', + type: 'String', + optional: true + } + ], + example: [ + "\n
\n let table;\n\n function setup() {\n table = new p5.Table();\n\n table.addColumn('id');\n table.addColumn('species');\n table.addColumn('name');\n\n let newRow = table.addRow();\n newRow.setNum('id', table.getRowCount() - 1);\n newRow.setString('species', 'Panthera leo');\n newRow.setString('name', 'Lion');\n\n // To save, un-comment next line then click 'run'\n // saveTable(table, 'new.csv');\n }\n\n // Saves the following to a file called 'new.csv':\n // id,species,name\n // 0,Panthera leo,Lion\n
" + ], + alt: 'no image displayed', + class: 'p5', + module: 'IO', + submodule: 'Output' + }, + { + file: 'src/io/p5.Table.js', + line: 11, + description: + '

Table Options

\n

Generic class for handling tabular data, typically from a\nCSV, TSV, or other sort of spreadsheet file.

\n

CSV files are\n\ncomma separated values, often with the data in quotes. TSV\nfiles use tabs as separators, and usually don't bother with the\nquotes.

\n

File names should end with .csv if they're comma separated.

\n

A rough "spec" for CSV can be found\nhere.

\n

To load files, use the loadTable method.

\n

To save tables to your computer, use the save method\n or the saveTable method.

\n\n

Possible options include:

\n
    \n
  • csv - parse the table as comma-separated values\n
  • tsv - parse the table as tab-separated values\n
  • header - this table has a header (title) row\n
', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 45, + itemtype: 'property', + name: 'columns', + type: 'String[]', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 50, + itemtype: 'property', + name: 'rows', + type: 'p5.TableRow[]', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 56, + description: + '

Use addRow() to add a new row of data to a p5.Table object. By default,\nan empty row is created. Typically, you would store a reference to\nthe new row in a TableRow object (see newRow in the example above),\nand then set individual values using set().

\n

If a p5.TableRow object is included as a parameter, then that row is\nduplicated and added to the table.

\n', + itemtype: 'method', + name: 'addRow', + params: [ + { + name: 'row', + description: '

row to be added to the table

\n', + type: 'p5.TableRow', + optional: true + } + ], + return: { + description: 'the row that was added', + type: 'p5.TableRow' + }, + example: [ + "\n
\n \n // Given the CSV file \"mammals.csv\"\n // in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n //add a row\n let newRow = table.addRow();\n newRow.setString('id', table.getRowCount() - 1);\n newRow.setString('species', 'Canis Lupus');\n newRow.setString('name', 'Wolf');\n\n //print the results\n for (let r = 0; r < table.getRowCount(); r++)\n for (let c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n }\n \n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 120, + description: '

Removes a row from the table object.

\n', + itemtype: 'method', + name: 'removeRow', + params: [ + { + name: 'id', + description: '

ID number of the row to remove

\n', + type: 'Integer' + } + ], + example: [ + '\n
\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n}\n\nfunction setup() {\n //remove the first row\n table.removeRow(0);\n\n //print the results\n for (let r = 0; r < table.getRowCount(); r++)\n for (let c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n}\n\n
' + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 168, + description: + '

Returns a reference to the specified p5.TableRow. The reference\ncan then be used to get and set values of the selected row.

\n', + itemtype: 'method', + name: 'getRow', + params: [ + { + name: 'rowID', + description: '

ID number of the row to get

\n', + type: 'Integer' + } + ], + return: { + description: 'p5.TableRow object', + type: 'p5.TableRow' + }, + example: [ + '\n
\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n}\n\nfunction setup() {\n let row = table.getRow(1);\n //print it column by column\n //note: a row is an object, not an array\n for (let c = 0; c < table.getColumnCount(); c++) {\n print(row.getString(c));\n }\n}\n\n
' + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 214, + description: + '

Gets all rows from the table. Returns an array of p5.TableRows.

\n', + itemtype: 'method', + name: 'getRows', + return: { + description: 'Array of p5.TableRows', + type: 'p5.TableRow[]' + }, + example: [ + "\n
\n \n // Given the CSV file \"mammals.csv\"\n // in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n let rows = table.getRows();\n\n //warning: rows is an array of objects\n for (let r = 0; r < rows.length; r++) {\n rows[r].set('name', 'Unicorn');\n }\n\n //print the results\n for (let r = 0; r < table.getRowCount(); r++)\n for (let c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n }\n \n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 263, + description: + '

Finds the first row in the Table that contains the value\nprovided, and returns a reference to that row. Even if\nmultiple rows are possible matches, only the first matching\nrow is returned. The column to search may be specified by\neither its ID or title.

\n', + itemtype: 'method', + name: 'findRow', + params: [ + { + name: 'value', + description: '

The value to match

\n', + type: 'String' + }, + { + name: 'column', + description: + '

ID number or title of the\n column to search

\n', + type: 'Integer|String' + } + ], + return: { + description: '', + type: 'p5.TableRow' + }, + example: [ + "\n
\n \n // Given the CSV file \"mammals.csv\"\n // in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n //find the animal named zebra\n let row = table.findRow('Zebra', 'name');\n //find the corresponding species\n print(row.getString('species'));\n }\n \n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 328, + description: + '

Finds the rows in the Table that contain the value\nprovided, and returns references to those rows. Returns an\nArray, so for must be used to iterate through all the rows,\nas shown in the example above. The column to search may be\nspecified by either its ID or title.

\n', + itemtype: 'method', + name: 'findRows', + params: [ + { + name: 'value', + description: '

The value to match

\n', + type: 'String' + }, + { + name: 'column', + description: + '

ID number or title of the\n column to search

\n', + type: 'Integer|String' + } + ], + return: { + description: 'An Array of TableRow objects', + type: 'p5.TableRow[]' + }, + example: [ + "\n
\n \n // Given the CSV file \"mammals.csv\"\n // in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n //add another goat\n let newRow = table.addRow();\n newRow.setString('id', table.getRowCount() - 1);\n newRow.setString('species', 'Scape Goat');\n newRow.setString('name', 'Goat');\n\n //find the rows containing animals named Goat\n let rows = table.findRows('Goat', 'name');\n print(rows.length + ' Goats found');\n }\n \n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 397, + description: + '

Finds the first row in the Table that matches the regular\nexpression provided, and returns a reference to that row.\nEven if multiple rows are possible matches, only the first\nmatching row is returned. The column to search may be\nspecified by either its ID or title.

\n', + itemtype: 'method', + name: 'matchRow', + params: [ + { + name: 'regexp', + description: '

The regular expression to match

\n', + type: 'String|RegExp' + }, + { + name: 'column', + description: + '

The column ID (number) or\n title (string)

\n', + type: 'String|Integer' + } + ], + return: { + description: 'TableRow object', + type: 'p5.TableRow' + }, + example: [ + '\n
\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n}\n\nfunction setup() {\n //Search using specified regex on a given column, return TableRow object\n let mammal = table.matchRow(new RegExp(\'ant\'), 1);\n print(mammal.getString(1));\n //Output "Panthera pardus"\n}\n\n
\n' + ], + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 456, + description: + '

Finds the rows in the Table that match the regular expression provided,\nand returns references to those rows. Returns an array, so for must be\nused to iterate through all the rows, as shown in the example. The\ncolumn to search may be specified by either its ID or title.

\n', + itemtype: 'method', + name: 'matchRows', + params: [ + { + name: 'regexp', + description: '

The regular expression to match

\n', + type: 'String' + }, + { + name: 'column', + description: + '

The column ID (number) or\n title (string)

\n', + type: 'String|Integer', + optional: true + } + ], + return: { + description: 'An Array of TableRow objects', + type: 'p5.TableRow[]' + }, + example: [ + "\n
\n\nlet table;\n\nfunction setup() {\n table = new p5.Table();\n\n table.addColumn('name');\n table.addColumn('type');\n\n let newRow = table.addRow();\n newRow.setString('name', 'Lion');\n newRow.setString('type', 'Mammal');\n\n newRow = table.addRow();\n newRow.setString('name', 'Snake');\n newRow.setString('type', 'Reptile');\n\n newRow = table.addRow();\n newRow.setString('name', 'Mosquito');\n newRow.setString('type', 'Insect');\n\n newRow = table.addRow();\n newRow.setString('name', 'Lizard');\n newRow.setString('type', 'Reptile');\n\n let rows = table.matchRows('R.*', 'type');\n for (let i = 0; i < rows.length; i++) {\n print(rows[i].getString('name') + ': ' + rows[i].getString('type'));\n }\n}\n// Sketch prints:\n// Snake: Reptile\n// Lizard: Reptile\n\n
" + ], + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 523, + description: + '

Retrieves all values in the specified column, and returns them\nas an array. The column may be specified by either its ID or title.

\n', + itemtype: 'method', + name: 'getColumn', + params: [ + { + name: 'column', + description: '

String or Number of the column to return

\n', + type: 'String|Number' + } + ], + return: { + description: 'Array of column values', + type: 'Array' + }, + example: [ + '\n
\n \n // Given the CSV file "mammals.csv"\n // in the project\'s "assets" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n }\n\n function setup() {\n //getColumn returns an array that can be printed directly\n print(table.getColumn(\'species\'));\n //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"]\n }\n \n
' + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 576, + description: + '

Removes all rows from a Table. While all rows are removed,\ncolumns and column titles are maintained.

\n', + itemtype: 'method', + name: 'clearRows', + example: [ + "\n
\n \n // Given the CSV file \"mammals.csv\"\n // in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n table.clearRows();\n print(table.getRowCount() + ' total rows in table');\n print(table.getColumnCount() + ' total columns in table');\n }\n \n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 618, + description: + '

Use addColumn() to add a new column to a Table object.\nTypically, you will want to specify a title, so the column\nmay be easily referenced later by name. (If no title is\nspecified, the new column's title will be null.)

\n', + itemtype: 'method', + name: 'addColumn', + params: [ + { + name: 'title', + description: '

title of the given column

\n', + type: 'String', + optional: true + } + ], + example: [ + "\n
\n \n // Given the CSV file \"mammals.csv\"\n // in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n table.addColumn('carnivore');\n table.set(0, 'carnivore', 'no');\n table.set(1, 'carnivore', 'yes');\n table.set(2, 'carnivore', 'no');\n\n //print the results\n for (let r = 0; r < table.getRowCount(); r++)\n for (let c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n }\n \n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 669, + description: '

Returns the total number of columns in a Table.

\n', + itemtype: 'method', + name: 'getColumnCount', + return: { + description: 'Number of columns in this table', + type: 'Integer' + }, + example: [ + "\n
\n \n // given the cvs file \"blobs.csv\" in /assets directory\n // ID, Name, Flavor, Shape, Color\n // Blob1, Blobby, Sweet, Blob, Pink\n // Blob2, Saddy, Savory, Blob, Blue\n\n let table;\n\n function preload() {\n table = loadTable('assets/blobs.csv');\n }\n\n function setup() {\n createCanvas(200, 100);\n textAlign(CENTER);\n background(255);\n }\n\n function draw() {\n let numOfColumn = table.getColumnCount();\n text('There are ' + numOfColumn + ' columns in the table.', 100, 50);\n }\n \n
" + ], + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 705, + description: '

Returns the total number of rows in a Table.

\n', + itemtype: 'method', + name: 'getRowCount', + return: { + description: 'Number of rows in this table', + type: 'Integer' + }, + example: [ + "\n
\n \n // given the cvs file \"blobs.csv\" in /assets directory\n //\n // ID, Name, Flavor, Shape, Color\n // Blob1, Blobby, Sweet, Blob, Pink\n // Blob2, Saddy, Savory, Blob, Blue\n\n let table;\n\n function preload() {\n table = loadTable('assets/blobs.csv');\n }\n\n function setup() {\n createCanvas(200, 100);\n textAlign(CENTER);\n background(255);\n }\n\n function draw() {\n text('There are ' + table.getRowCount() + ' rows in the table.', 100, 50);\n }\n \n
" + ], + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 741, + description: + '

Removes any of the specified characters (or "tokens").

\n\n

If no column is specified, then the values in all columns and\nrows are processed. A specific column may be referenced by\neither its ID or title.

', + itemtype: 'method', + name: 'removeTokens', + params: [ + { + name: 'chars', + description: '

String listing characters to be removed

\n', + type: 'String' + }, + { + name: 'column', + description: + '

Column ID (number)\n or name (string)

\n', + type: 'String|Integer', + optional: true + } + ], + example: [ + "\n
\n function setup() {\n let table = new p5.Table();\n\n table.addColumn('name');\n table.addColumn('type');\n\n let newRow = table.addRow();\n newRow.setString('name', ' $Lion ,');\n newRow.setString('type', ',,,Mammal');\n\n newRow = table.addRow();\n newRow.setString('name', '$Snake ');\n newRow.setString('type', ',,,Reptile');\n\n table.removeTokens(',$ ');\n print(table.getArray());\n }\n\n // prints:\n // 0 \"Lion\" \"Mamal\"\n // 1 \"Snake\" \"Reptile\"\n
" + ], + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 815, + description: + '

Trims leading and trailing whitespace, such as spaces and tabs,\nfrom String table values. If no column is specified, then the\nvalues in all columns and rows are trimmed. A specific column\nmay be referenced by either its ID or title.

\n', + itemtype: 'method', + name: 'trim', + params: [ + { + name: 'column', + description: + '

Column ID (number)\n or name (string)

\n', + type: 'String|Integer', + optional: true + } + ], + example: [ + "\n
\n function setup() {\n let table = new p5.Table();\n\n table.addColumn('name');\n table.addColumn('type');\n\n let newRow = table.addRow();\n newRow.setString('name', ' Lion ,');\n newRow.setString('type', ' Mammal ');\n\n newRow = table.addRow();\n newRow.setString('name', ' Snake ');\n newRow.setString('type', ' Reptile ');\n\n table.trim();\n print(table.getArray());\n }\n\n // prints:\n // 0 \"Lion\" \"Mamal\"\n // 1 \"Snake\" \"Reptile\"\n
" + ], + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 879, + description: + '

Use removeColumn() to remove an existing column from a Table\nobject. The column to be removed may be identified by either\nits title (a String) or its index value (an int).\nremoveColumn(0) would remove the first column, removeColumn(1)\nwould remove the second column, and so on.

\n', + itemtype: 'method', + name: 'removeColumn', + params: [ + { + name: 'column', + description: '

columnName (string) or ID (number)

\n', + type: 'String|Integer' + } + ], + example: [ + "\n
\n \n // Given the CSV file \"mammals.csv\"\n // in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n table.removeColumn('id');\n print(table.getColumnCount());\n }\n \n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 944, + description: + '

Stores a value in the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified\nby either its ID or title.

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'row', + description: '

row ID

\n', + type: 'Integer' + }, + { + name: 'column', + description: + '

column ID (Number)\n or title (String)

\n', + type: 'String|Integer' + }, + { + name: 'value', + description: '

value to assign

\n', + type: 'String|Number' + } + ], + example: [ + "\n
\n\n// Given the CSV file \"mammals.csv\"\n// in the project's \"assets\" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n}\n\nfunction setup() {\n table.set(0, 'species', 'Canis Lupus');\n table.set(0, 'name', 'Wolf');\n\n //print the results\n for (let r = 0; r < table.getRowCount(); r++)\n for (let c = 0; c < table.getColumnCount(); c++)\n print(table.getString(r, c));\n}\n\n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 994, + description: + '

Stores a Float value in the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified\nby either its ID or title.

\n', + itemtype: 'method', + name: 'setNum', + params: [ + { + name: 'row', + description: '

row ID

\n', + type: 'Integer' + }, + { + name: 'column', + description: + '

column ID (Number)\n or title (String)

\n', + type: 'String|Integer' + }, + { + name: 'value', + description: '

value to assign

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n}\n\nfunction setup() {\n table.setNum(1, \'id\', 1);\n\n print(table.getColumn(0));\n //["0", 1, "2"]\n}\n\n
' + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 1040, + description: + '

Stores a String value in the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified\nby either its ID or title.

\n', + itemtype: 'method', + name: 'setString', + params: [ + { + name: 'row', + description: '

row ID

\n', + type: 'Integer' + }, + { + name: 'column', + description: + '

column ID (Number)\n or title (String)

\n', + type: 'String|Integer' + }, + { + name: 'value', + description: '

value to assign

\n', + type: 'String' + } + ], + example: [ + "\n
\n// Given the CSV file \"mammals.csv\" in the project's \"assets\" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n}\n\nfunction setup() {\n //add a row\n let newRow = table.addRow();\n newRow.setString('id', table.getRowCount() - 1);\n newRow.setString('species', 'Canis Lupus');\n newRow.setString('name', 'Wolf');\n\n print(table.getArray());\n}\n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 1085, + description: + '

Retrieves a value from the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified by\neither its ID or title.

\n', + itemtype: 'method', + name: 'get', + params: [ + { + name: 'row', + description: '

row ID

\n', + type: 'Integer' + }, + { + name: 'column', + description: + '

columnName (string) or\n ID (number)

\n', + type: 'String|Integer' + } + ], + return: { + description: '', + type: 'String|Number' + }, + example: [ + "\n
\n\n// Given the CSV file \"mammals.csv\"\n// in the project's \"assets\" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n}\n\nfunction setup() {\n print(table.get(0, 1));\n //Capra hircus\n print(table.get(0, 'species'));\n //Capra hircus\n}\n\n
" + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 1132, + description: + '

Retrieves a Float value from the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified by\neither its ID or title.

\n', + itemtype: 'method', + name: 'getNum', + params: [ + { + name: 'row', + description: '

row ID

\n', + type: 'Integer' + }, + { + name: 'column', + description: + '

columnName (string) or\n ID (number)

\n', + type: 'String|Integer' + } + ], + return: { + description: '', + type: 'Number' + }, + example: [ + '\n
\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n}\n\nfunction setup() {\n print(table.getNum(1, 0) + 100);\n //id 1 + 100 = 101\n}\n\n
' + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 1177, + description: + '

Retrieves a String value from the Table's specified row and column.\nThe row is specified by its ID, while the column may be specified by\neither its ID or title.

\n', + itemtype: 'method', + name: 'getString', + params: [ + { + name: 'row', + description: '

row ID

\n', + type: 'Integer' + }, + { + name: 'column', + description: + '

columnName (string) or\n ID (number)

\n', + type: 'String|Integer' + } + ], + return: { + description: '', + type: 'String' + }, + example: [ + '\n
\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n // table is comma separated value "CSV"\n // and has specifiying header for column labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n}\n\nfunction setup() {\n print(table.getString(0, 0)); // 0\n print(table.getString(0, 1)); // Capra hircus\n print(table.getString(0, 2)); // Goat\n print(table.getString(1, 0)); // 1\n print(table.getString(1, 1)); // Panthera pardus\n print(table.getString(1, 2)); // Leopard\n print(table.getString(2, 0)); // 2\n print(table.getString(2, 1)); // Equus zebra\n print(table.getString(2, 2)); // Zebra\n}\n\n
' + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 1230, + description: + '

Retrieves all table data and returns as an object. If a column name is\npassed in, each row object will be stored with that attribute as its\ntitle.

\n', + itemtype: 'method', + name: 'getObject', + params: [ + { + name: 'headerColumn', + description: + '

Name of the column which should be used to\n title each row object (optional)

\n', + type: 'String', + optional: true + } + ], + return: { + description: '', + type: 'Object' + }, + example: [ + '\n
\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder:\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leopard\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n //my table is comma separated value "csv"\n //and has a header specifying the columns labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n}\n\nfunction setup() {\n let tableObject = table.getObject();\n\n print(tableObject);\n //outputs an object\n}\n\n
' + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.Table.js', + line: 1296, + description: + '

Retrieves all table data and returns it as a multidimensional array.

\n', + itemtype: 'method', + name: 'getArray', + return: { + description: '', + type: 'Array' + }, + example: [ + '\n
\n\n// Given the CSV file "mammals.csv"\n// in the project\'s "assets" folder\n//\n// id,species,name\n// 0,Capra hircus,Goat\n// 1,Panthera pardus,Leoperd\n// 2,Equus zebra,Zebra\n\nlet table;\n\nfunction preload() {\n // table is comma separated value "CSV"\n // and has specifiying header for column labels\n table = loadTable(\'assets/mammals.csv\', \'csv\', \'header\');\n}\n\nfunction setup() {\n let tableArray = table.getArray();\n for (let i = 0; i < tableArray.length; i++) {\n print(tableArray[i]);\n }\n}\n\n
' + ], + alt: 'no image displayed', + class: 'p5.Table', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.TableRow.js', + line: 42, + description: + '

Stores a value in the TableRow's specified column.\nThe column may be specified by either its ID or title.

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'column', + description: + '

Column ID (Number)\n or Title (String)

\n', + type: 'String|Integer' + }, + { + name: 'value', + description: '

The value to be stored

\n', + type: 'String|Number' + } + ], + example: [ + "\n
\n // Given the CSV file \"mammals.csv\" in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n let rows = table.getRows();\n for (let r = 0; r < rows.length; r++) {\n rows[r].set('name', 'Unicorn');\n }\n\n //print the results\n print(table.getArray());\n }\n
" + ], + alt: 'no image displayed', + class: 'p5.TableRow', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.TableRow.js', + line: 106, + description: + '

Stores a Float value in the TableRow's specified column.\nThe column may be specified by either its ID or title.

\n', + itemtype: 'method', + name: 'setNum', + params: [ + { + name: 'column', + description: + '

Column ID (Number)\n or Title (String)

\n', + type: 'String|Integer' + }, + { + name: 'value', + description: + '

The value to be stored\n as a Float

\n', + type: 'Number|String' + } + ], + example: [ + "\n
\n // Given the CSV file \"mammals.csv\" in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n let rows = table.getRows();\n for (let r = 0; r < rows.length; r++) {\n rows[r].setNum('id', r + 10);\n }\n\n print(table.getArray());\n }\n
" + ], + alt: 'no image displayed', + class: 'p5.TableRow', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.TableRow.js', + line: 150, + description: + '

Stores a String value in the TableRow's specified column.\nThe column may be specified by either its ID or title.

\n', + itemtype: 'method', + name: 'setString', + params: [ + { + name: 'column', + description: + '

Column ID (Number)\n or Title (String)

\n', + type: 'String|Integer' + }, + { + name: 'value', + description: + '

The value to be stored\n as a String

\n', + type: 'String|Number|Boolean|Object' + } + ], + example: [ + "\n
\n // Given the CSV file \"mammals.csv\" in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n let rows = table.getRows();\n for (let r = 0; r < rows.length; r++) {\n let name = rows[r].getString('name');\n rows[r].setString('name', 'A ' + name + ' named George');\n }\n\n print(table.getArray());\n }\n
" + ], + alt: 'no image displayed', + class: 'p5.TableRow', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.TableRow.js', + line: 195, + description: + '

Retrieves a value from the TableRow's specified column.\nThe column may be specified by either its ID or title.

\n', + itemtype: 'method', + name: 'get', + params: [ + { + name: 'column', + description: + '

columnName (string) or\n ID (number)

\n', + type: 'String|Integer' + } + ], + return: { + description: '', + type: 'String|Number' + }, + example: [ + "\n
\n // Given the CSV file \"mammals.csv\" in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n let names = [];\n let rows = table.getRows();\n for (let r = 0; r < rows.length; r++) {\n names.push(rows[r].get('name'));\n }\n\n print(names);\n }\n
" + ], + alt: 'no image displayed', + class: 'p5.TableRow', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.TableRow.js', + line: 243, + description: + '

Retrieves a Float value from the TableRow's specified\ncolumn. The column may be specified by either its ID or\ntitle.

\n', + itemtype: 'method', + name: 'getNum', + params: [ + { + name: 'column', + description: + '

columnName (string) or\n ID (number)

\n', + type: 'String|Integer' + } + ], + return: { + description: 'Float Floating point number', + type: 'Number' + }, + example: [ + "\n
\n // Given the CSV file \"mammals.csv\" in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n let rows = table.getRows();\n let minId = Infinity;\n let maxId = -Infinity;\n for (let r = 0; r < rows.length; r++) {\n let id = rows[r].getNum('id');\n minId = min(minId, id);\n maxId = min(maxId, id);\n }\n print('minimum id = ' + minId + ', maximum id = ' + maxId);\n }\n
" + ], + alt: 'no image displayed', + class: 'p5.TableRow', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.TableRow.js', + line: 299, + description: + '

Retrieves an String value from the TableRow's specified\ncolumn. The column may be specified by either its ID or\ntitle.

\n', + itemtype: 'method', + name: 'getString', + params: [ + { + name: 'column', + description: + '

columnName (string) or\n ID (number)

\n', + type: 'String|Integer' + } + ], + return: { + description: 'String', + type: 'String' + }, + example: [ + "\n
\n // Given the CSV file \"mammals.csv\" in the project's \"assets\" folder:\n //\n // id,species,name\n // 0,Capra hircus,Goat\n // 1,Panthera pardus,Leopard\n // 2,Equus zebra,Zebra\n\n let table;\n\n function preload() {\n //my table is comma separated value \"csv\"\n //and has a header specifying the columns labels\n table = loadTable('assets/mammals.csv', 'csv', 'header');\n }\n\n function setup() {\n let rows = table.getRows();\n let longest = '';\n for (let r = 0; r < rows.length; r++) {\n let species = rows[r].getString('species');\n if (longest.length < species.length) {\n longest = species;\n }\n }\n\n print('longest: ' + longest);\n }\n
" + ], + alt: 'no image displayed', + class: 'p5.TableRow', + module: 'IO', + submodule: 'Table' + }, + { + file: 'src/io/p5.XML.js', + line: 65, + description: + '

Gets a copy of the element's parent. Returns the parent as another\np5.XML object.

\n', + itemtype: 'method', + name: 'getParent', + return: { + description: 'element parent', + type: 'p5.XML' + }, + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let children = xml.getChildren(\'animal\');\n let parent = children[1].getParent();\n print(parent.getName());\n}\n\n// Sketch prints:\n// mammals\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 103, + description: + '

Gets the element's full name, which is returned as a String.

\n', + itemtype: 'method', + name: 'getName', + return: { + description: 'the name of the node', + type: 'String' + }, + example: [ + '<animal\n
\n // The following short XML file called "mammals.xml" is parsed\n // in the code below.\n //\n // \n // <mammals>\n // <animal id="0" species="Capra hircus">Goat</animal>\n // <animal id="1" species="Panthera pardus">Leopard</animal>\n // <animal id="2" species="Equus zebra">Zebra</animal>\n // </mammals>\n\n let xml;\n\n function preload() {\n xml = loadXML(\'assets/mammals.xml\');\n }\n\n function setup() {\n print(xml.getName());\n }\n\n // Sketch prints:\n // mammals\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 138, + description: + '

Sets the element's name, which is specified as a String.

\n', + itemtype: 'method', + name: 'setName', + params: [ + { + name: 'the', + description: '

new name of the node

\n', + type: 'String' + } + ], + example: [ + '<animal\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n print(xml.getName());\n xml.setName(\'fish\');\n print(xml.getName());\n}\n\n// Sketch prints:\n// mammals\n// fish\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 184, + description: + '

Checks whether or not the element has any children, and returns the result\nas a boolean.

\n', + itemtype: 'method', + name: 'hasChildren', + return: { + description: '', + type: 'Boolean' + }, + example: [ + '<animal\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n print(xml.hasChildren());\n}\n\n// Sketch prints:\n// true\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 220, + description: + '

Get the names of all of the element's children, and returns the names as an\narray of Strings. This is the same as looping through and calling getName()\non each child element individually.

\n', + itemtype: 'method', + name: 'listChildren', + return: { + description: 'names of the children of the element', + type: 'String[]' + }, + example: [ + '<animal\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n print(xml.listChildren());\n}\n\n// Sketch prints:\n// ["animal", "animal", "animal"]\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 261, + description: + '

Returns all of the element's children as an array of p5.XML objects. When\nthe name parameter is specified, then it will return all children that match\nthat name.

\n', + itemtype: 'method', + name: 'getChildren', + params: [ + { + name: 'name', + description: '

element name

\n', + type: 'String', + optional: true + } + ], + return: { + description: 'children of the element', + type: 'p5.XML[]' + }, + example: [ + '<animal\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let animals = xml.getChildren(\'animal\');\n\n for (let i = 0; i < animals.length; i++) {\n print(animals[i].getContent());\n }\n}\n\n// Sketch prints:\n// "Goat"\n// "Leopard"\n// "Zebra"\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 317, + description: + '

Returns the first of the element's children that matches the name parameter\nor the child of the given index.It returns undefined if no matching\nchild is found.

\n', + itemtype: 'method', + name: 'getChild', + params: [ + { + name: 'name', + description: '

element name or index

\n', + type: 'String|Integer' + } + ], + return: { + description: '', + type: 'p5.XML' + }, + example: [ + '<animal\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.getContent());\n}\n\n// Sketch prints:\n// "Goat"\n
\n
\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let secondChild = xml.getChild(1);\n print(secondChild.getContent());\n}\n\n// Sketch prints:\n// "Leopard"\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 378, + description: + '

Appends a new child to the element. The child can be specified with\neither a String, which will be used as the new tag's name, or as a\nreference to an existing p5.XML object.\nA reference to the newly created child is returned as an p5.XML object.

\n', + itemtype: 'method', + name: 'addChild', + params: [ + { + name: 'node', + description: + '

a p5.XML Object which will be the child to be added

\n', + type: 'p5.XML' + } + ], + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let child = new p5.XML();\n child.setName(\'animal\');\n child.setAttribute(\'id\', \'3\');\n child.setAttribute(\'species\', \'Ornithorhynchus anatinus\');\n child.setContent(\'Platypus\');\n xml.addChild(child);\n\n let animals = xml.getChildren(\'animal\');\n print(animals[animals.length - 1].getContent());\n}\n\n// Sketch prints:\n// "Goat"\n// "Leopard"\n// "Zebra"\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 430, + description: '

Removes the element specified by name or index.

\n', + itemtype: 'method', + name: 'removeChild', + params: [ + { + name: 'name', + description: '

element name or index

\n', + type: 'String|Integer' + } + ], + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n xml.removeChild(\'animal\');\n let children = xml.getChildren();\n for (let i = 0; i < children.length; i++) {\n print(children[i].getContent());\n }\n}\n\n// Sketch prints:\n// "Leopard"\n// "Zebra"\n
\n
\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n xml.removeChild(1);\n let children = xml.getChildren();\n for (let i = 0; i < children.length; i++) {\n print(children[i].getContent());\n }\n}\n\n// Sketch prints:\n// "Goat"\n// "Zebra"\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 502, + description: + '

Counts the specified element's number of attributes, returned as an Number.

\n', + itemtype: 'method', + name: 'getAttributeCount', + return: { + description: '', + type: 'Integer' + }, + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.getAttributeCount());\n}\n\n// Sketch prints:\n// 2\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 538, + description: + '

Gets all of the specified element's attributes, and returns them as an\narray of Strings.

\n', + itemtype: 'method', + name: 'listAttributes', + return: { + description: 'an array of strings containing the names of attributes', + type: 'String[]' + }, + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.listAttributes());\n}\n\n// Sketch prints:\n// ["id", "species"]\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 580, + description: + '

Checks whether or not an element has the specified attribute.

\n', + itemtype: 'method', + name: 'hasAttribute', + params: [ + { + name: 'the', + description: '

attribute to be checked

\n', + type: 'String' + } + ], + return: { + description: 'true if attribute found else false', + type: 'Boolean' + }, + example: [ + '\n
\n // The following short XML file called "mammals.xml" is parsed\n // in the code below.\n //\n // \n // <mammals>\n // <animal id="0" species="Capra hircus">Goat</animal>\n // <animal id="1" species="Panthera pardus">Leopard</animal>\n // <animal id="2" species="Equus zebra">Zebra</animal>\n // </mammals>\n\n let xml;\n\n function preload() {\n xml = loadXML(\'assets/mammals.xml\');\n }\n\n function setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.hasAttribute(\'species\'));\n print(firstChild.hasAttribute(\'color\'));\n }\n\n // Sketch prints:\n // true\n // false\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 624, + description: + '

Returns an attribute value of the element as an Number. If the defaultValue\nparameter is specified and the attribute doesn't exist, then defaultValue\nis returned. If no defaultValue is specified and the attribute doesn't\nexist, the value 0 is returned.

\n', + itemtype: 'method', + name: 'getNum', + params: [ + { + name: 'name', + description: '

the non-null full name of the attribute

\n', + type: 'String' + }, + { + name: 'defaultValue', + description: '

the default value of the attribute

\n', + type: 'Number', + optional: true + } + ], + return: { + description: '', + type: 'Number' + }, + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.getNum(\'id\'));\n}\n\n// Sketch prints:\n// 0\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 670, + description: + '

Returns an attribute value of the element as an String. If the defaultValue\nparameter is specified and the attribute doesn't exist, then defaultValue\nis returned. If no defaultValue is specified and the attribute doesn't\nexist, null is returned.

\n', + itemtype: 'method', + name: 'getString', + params: [ + { + name: 'name', + description: '

the non-null full name of the attribute

\n', + type: 'String' + }, + { + name: 'defaultValue', + description: '

the default value of the attribute

\n', + type: 'Number', + optional: true + } + ], + return: { + description: '', + type: 'String' + }, + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.getString(\'species\'));\n}\n\n// Sketch prints:\n// "Capra hircus"\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 716, + description: + '

Sets the content of an element's attribute. The first parameter specifies\nthe attribute name, while the second specifies the new content.

\n', + itemtype: 'method', + name: 'setAttribute', + params: [ + { + name: 'name', + description: '

the full name of the attribute

\n', + type: 'String' + }, + { + name: 'value', + description: '

the value of the attribute

\n', + type: 'Number|String|Boolean' + } + ], + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.getString(\'species\'));\n firstChild.setAttribute(\'species\', \'Jamides zebra\');\n print(firstChild.getString(\'species\'));\n}\n\n// Sketch prints:\n// "Capra hircus"\n// "Jamides zebra"\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 757, + description: + '

Returns the content of an element. If there is no such content,\ndefaultValue is returned if specified, otherwise null is returned.

\n', + itemtype: 'method', + name: 'getContent', + params: [ + { + name: 'defaultValue', + description: '

value returned if no content is found

\n', + type: 'String', + optional: true + } + ], + return: { + description: '', + type: 'String' + }, + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.getContent());\n}\n\n// Sketch prints:\n// "Goat"\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 798, + description: '

Sets the element's content.

\n', + itemtype: 'method', + name: 'setContent', + params: [ + { + name: 'text', + description: '

the new content

\n', + type: 'String' + } + ], + example: [ + '\n
\n// The following short XML file called "mammals.xml" is parsed\n// in the code below.\n//\n// \n// <mammals>\n// <animal id="0" species="Capra hircus">Goat</animal>\n// <animal id="1" species="Panthera pardus">Leopard</animal>\n// <animal id="2" species="Equus zebra">Zebra</animal>\n// </mammals>\n\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n let firstChild = xml.getChild(\'animal\');\n print(firstChild.getContent());\n firstChild.setContent(\'Mountain Goat\');\n print(firstChild.getContent());\n}\n\n// Sketch prints:\n// "Goat"\n// "Mountain Goat"\n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/io/p5.XML.js', + line: 839, + description: + '

Serializes the element into a string. This function is useful for preparing\nthe content to be sent over a http request or saved to file.

\n', + itemtype: 'method', + name: 'serialize', + return: { + description: 'Serialized string of the element', + type: 'String' + }, + example: [ + '\n
\nlet xml;\n\nfunction preload() {\n xml = loadXML(\'assets/mammals.xml\');\n}\n\nfunction setup() {\n print(xml.serialize());\n}\n\n// Sketch prints:\n// \n// Goat\n// Leopard\n// Zebra\n// \n
' + ], + class: 'p5.XML', + module: 'IO', + submodule: 'XML' + }, + { + file: 'src/math/calculation.js', + line: 12, + description: + '

Calculates the absolute value (magnitude) of a number. Maps to Math.abs().\nThe absolute value of a number is always positive.

\n', + itemtype: 'method', + name: 'abs', + params: [ + { + name: 'n', + description: '

number to compute

\n', + type: 'Number' + } + ], + return: { + description: 'absolute value of given number', + type: 'Number' + }, + example: [ + '\n
\nfunction setup() {\n let x = -3;\n let y = abs(x);\n\n print(x); // -3\n print(y); // 3\n}\n
' + ], + alt: 'no image displayed', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 36, + description: + '

Calculates the closest int value that is greater than or equal to the\nvalue of the parameter. Maps to Math.ceil(). For example, ceil(9.03)\nreturns the value 10.

\n', + itemtype: 'method', + name: 'ceil', + params: [ + { + name: 'n', + description: '

number to round up

\n', + type: 'Number' + } + ], + return: { + description: 'rounded up number', + type: 'Integer' + }, + example: [ + '\n
\nfunction draw() {\n background(200);\n // map, mouseX between 0 and 5.\n let ax = map(mouseX, 0, 100, 0, 5);\n let ay = 66;\n\n //Get the ceiling of the mapped number.\n let bx = ceil(map(mouseX, 0, 100, 0, 5));\n let by = 33;\n\n // Multiply the mapped numbers by 20 to more easily\n // see the changes.\n stroke(0);\n fill(0);\n line(0, ay, ax * 20, ay);\n line(0, by, bx * 20, by);\n\n // Reformat the float returned by map and draw it.\n noStroke();\n text(nfc(ax, 2), ax, ay - 5);\n text(nfc(bx, 1), bx, by - 5);\n}\n
' + ], + alt: + '2 horizontal lines & number sets. increase with mouse x. bottom to 2 decimals', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 76, + description: + '

Constrains a value between a minimum and maximum value.

\n', + itemtype: 'method', + name: 'constrain', + params: [ + { + name: 'n', + description: '

number to constrain

\n', + type: 'Number' + }, + { + name: 'low', + description: '

minimum limit

\n', + type: 'Number' + }, + { + name: 'high', + description: '

maximum limit

\n', + type: 'Number' + } + ], + return: { + description: 'constrained number', + type: 'Number' + }, + example: [ + '\n
\nfunction draw() {\n background(200);\n\n let leftWall = 25;\n let rightWall = 75;\n\n // xm is just the mouseX, while\n // xc is the mouseX, but constrained\n // between the leftWall and rightWall!\n let xm = mouseX;\n let xc = constrain(mouseX, leftWall, rightWall);\n\n // Draw the walls.\n stroke(150);\n line(leftWall, 0, leftWall, height);\n line(rightWall, 0, rightWall, height);\n\n // Draw xm and xc as circles.\n noStroke();\n fill(150);\n ellipse(xm, 33, 9, 9); // Not Constrained\n fill(0);\n ellipse(xc, 66, 9, 9); // Constrained\n}\n
' + ], + alt: + '2 vertical lines. 2 ellipses move with mouse X 1 does not move passed lines', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 121, + description: + '

Calculates the distance between two points, in either two or three dimensions.

\n', + itemtype: 'method', + name: 'dist', + return: { + description: 'distance between the two points', + type: 'Number' + }, + example: [ + "\n
\n// Move your mouse inside the canvas to see the\n// change in distance between two points!\nfunction draw() {\n background(200);\n fill(0);\n\n let x1 = 10;\n let y1 = 90;\n let x2 = mouseX;\n let y2 = mouseY;\n\n line(x1, y1, x2, y2);\n ellipse(x1, y1, 7, 7);\n ellipse(x2, y2, 7, 7);\n\n // d is the length of the line\n // the distance from point 1 to point 2.\n let d = int(dist(x1, y1, x2, y2));\n\n // Let's write d along the line we are drawing!\n push();\n translate((x1 + x2) / 2, (y1 + y2) / 2);\n rotate(atan2(y2 - y1, x2 - x1));\n text(nfc(d, 1), 0, -5);\n pop();\n // Fancy!\n}\n
" + ], + alt: + '2 ellipses joined by line. 1 ellipse moves with mouse X&Y. Distance displayed.', + class: 'p5', + module: 'Math', + submodule: 'Calculation', + overloads: [ + { + line: 121, + params: [ + { + name: 'x1', + description: '

x-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'y1', + description: '

y-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '

x-coordinate of the second point

\n', + type: 'Number' + }, + { + name: 'y2', + description: '

y-coordinate of the second point

\n', + type: 'Number' + } + ], + return: { + description: 'distance between the two points', + type: 'Number' + } + }, + { + line: 165, + params: [ + { + name: 'x1', + description: '', + type: 'Number' + }, + { + name: 'y1', + description: '', + type: 'Number' + }, + { + name: 'z1', + description: '

z-coordinate of the first point

\n', + type: 'Number' + }, + { + name: 'x2', + description: '', + type: 'Number' + }, + { + name: 'y2', + description: '', + type: 'Number' + }, + { + name: 'z2', + description: '

z-coordinate of the second point

\n', + type: 'Number' + } + ], + return: { + description: 'distance between the two points', + type: 'Number' + } + } + ] + }, + { + file: 'src/math/calculation.js', + line: 190, + description: + '

Returns Euler's number e (2.71828...) raised to the power of the n\nparameter. Maps to Math.exp().

\n', + itemtype: 'method', + name: 'exp', + params: [ + { + name: 'n', + description: '

exponent to raise

\n', + type: 'Number' + } + ], + return: { + description: 'e^n', + type: 'Number' + }, + example: [ + "\n
\nfunction draw() {\n background(200);\n\n // Compute the exp() function with a value between 0 and 2\n let xValue = map(mouseX, 0, width, 0, 2);\n let yValue = exp(xValue);\n\n let y = map(yValue, 0, 8, height, 0);\n\n let legend = 'exp (' + nfc(xValue, 3) + ')\\n= ' + nf(yValue, 1, 4);\n stroke(150);\n line(mouseX, y, mouseX, height);\n fill(0);\n text(legend, 5, 15);\n noStroke();\n ellipse(mouseX, y, 7, 7);\n\n // Draw the exp(x) curve,\n // over the domain of x from 0 to 2\n noFill();\n stroke(0);\n beginShape();\n for (let x = 0; x < width; x++) {\n xValue = map(x, 0, width, 0, 2);\n yValue = exp(xValue);\n y = map(yValue, 0, 8, height, 0);\n vertex(x, y);\n }\n\n endShape();\n line(0, 0, 0, height);\n line(0, height - 1, width, height - 1);\n}\n
" + ], + alt: 'ellipse moves along a curve with mouse x. e^n displayed.', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 240, + description: + '

Calculates the closest int value that is less than or equal to the\nvalue of the parameter. Maps to Math.floor().

\n', + itemtype: 'method', + name: 'floor', + params: [ + { + name: 'n', + description: '

number to round down

\n', + type: 'Number' + } + ], + return: { + description: 'rounded down number', + type: 'Integer' + }, + example: [ + '\n
\nfunction draw() {\n background(200);\n //map, mouseX between 0 and 5.\n let ax = map(mouseX, 0, 100, 0, 5);\n let ay = 66;\n\n //Get the floor of the mapped number.\n let bx = floor(map(mouseX, 0, 100, 0, 5));\n let by = 33;\n\n // Multiply the mapped numbers by 20 to more easily\n // see the changes.\n stroke(0);\n fill(0);\n line(0, ay, ax * 20, ay);\n line(0, by, bx * 20, by);\n\n // Reformat the float returned by map and draw it.\n noStroke();\n text(nfc(ax, 2), ax, ay - 5);\n text(nfc(bx, 1), bx, by - 5);\n}\n
' + ], + alt: + '2 horizontal lines & number sets. increase with mouse x. bottom to 2 decimals', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 279, + description: + '

Calculates a number between two numbers at a specific increment. The amt\nparameter is the amount to interpolate between the two values where 0.0\nequal to the first point, 0.1 is very near the first point, 0.5 is\nhalf-way in between, and 1.0 is equal to the second point. If the\nvalue of amt is more than 1.0 or less than 0.0, the number will be\ncalculated accordingly in the ratio of the two given numbers. The lerp\nfunction is convenient for creating motion along a straight\npath and for drawing dotted lines.

\n', + itemtype: 'method', + name: 'lerp', + params: [ + { + name: 'start', + description: '

first value

\n', + type: 'Number' + }, + { + name: 'stop', + description: '

second value

\n', + type: 'Number' + }, + { + name: 'amt', + description: '

number

\n', + type: 'Number' + } + ], + return: { + description: 'lerped value', + type: 'Number' + }, + example: [ + '\n
\nfunction setup() {\n background(200);\n let a = 20;\n let b = 80;\n let c = lerp(a, b, 0.2);\n let d = lerp(a, b, 0.5);\n let e = lerp(a, b, 0.8);\n\n let y = 50;\n\n strokeWeight(5);\n stroke(0); // Draw the original points in black\n point(a, y);\n point(b, y);\n\n stroke(100); // Draw the lerp points in gray\n point(c, y);\n point(d, y);\n point(e, y);\n}\n
' + ], + alt: + '5 points horizontally staggered mid-canvas. mid 3 are grey, outer black', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 327, + description: + '

Calculates the natural logarithm (the base-e logarithm) of a number. This\nfunction expects the n parameter to be a value greater than 0.0. Maps to\nMath.log().

\n', + itemtype: 'method', + name: 'log', + params: [ + { + name: 'n', + description: '

number greater than 0

\n', + type: 'Number' + } + ], + return: { + description: 'natural logarithm of n', + type: 'Number' + }, + example: [ + "\n
\nfunction draw() {\n background(200);\n let maxX = 2.8;\n let maxY = 1.5;\n\n // Compute the natural log of a value between 0 and maxX\n let xValue = map(mouseX, 0, width, 0, maxX);\n let yValue, y;\n if (xValue > 0) {\n // Cannot take the log of a negative number.\n yValue = log(xValue);\n y = map(yValue, -maxY, maxY, height, 0);\n\n // Display the calculation occurring.\n let legend = 'log(' + nf(xValue, 1, 2) + ')\\n= ' + nf(yValue, 1, 3);\n stroke(150);\n line(mouseX, y, mouseX, height);\n fill(0);\n text(legend, 5, 15);\n noStroke();\n ellipse(mouseX, y, 7, 7);\n }\n\n // Draw the log(x) curve,\n // over the domain of x from 0 to maxX\n noFill();\n stroke(0);\n beginShape();\n for (let x = 0; x < width; x++) {\n xValue = map(x, 0, width, 0, maxX);\n yValue = log(xValue);\n y = map(yValue, -maxY, maxY, height, 0);\n vertex(x, y);\n }\n endShape();\n line(0, 0, 0, height);\n line(0, height / 2, width, height / 2);\n}\n
" + ], + alt: + 'ellipse moves along a curve with mouse x. natural logarithm of n displayed.', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 383, + description: + '

Calculates the magnitude (or length) of a vector. A vector is a direction\nin space commonly used in computer graphics and linear algebra. Because it\nhas no "start" position, the magnitude of a vector can be thought of as\nthe distance from the coordinate 0,0 to its x,y value. Therefore, mag() is\na shortcut for writing dist(0, 0, x, y).

\n', + itemtype: 'method', + name: 'mag', + params: [ + { + name: 'a', + description: '

first value

\n', + type: 'Number' + }, + { + name: 'b', + description: '

second value

\n', + type: 'Number' + } + ], + return: { + description: 'magnitude of vector from (0,0) to (a,b)', + type: 'Number' + }, + example: [ + '\n
\nfunction setup() {\n let x1 = 20;\n let x2 = 80;\n let y1 = 30;\n let y2 = 70;\n\n line(0, 0, x1, y1);\n print(mag(x1, y1)); // Prints "36.05551275463989"\n line(0, 0, x2, y1);\n print(mag(x2, y1)); // Prints "85.44003745317531"\n line(0, 0, x1, y2);\n print(mag(x1, y2)); // Prints "72.80109889280519"\n line(0, 0, x2, y2);\n print(mag(x2, y2)); // Prints "106.3014581273465"\n}\n
' + ], + alt: '4 lines of different length radiate from top left of canvas.', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 422, + description: + '

Re-maps a number from one range to another.\n

\nIn the first example above, the number 25 is converted from a value in the\nrange of 0 to 100 into a value that ranges from the left edge of the\nwindow (0) to the right edge (width).

\n', + itemtype: 'method', + name: 'map', + params: [ + { + name: 'value', + description: '

the incoming value to be converted

\n', + type: 'Number' + }, + { + name: 'start1', + description: '

lower bound of the value's current range

\n', + type: 'Number' + }, + { + name: 'stop1', + description: '

upper bound of the value's current range

\n', + type: 'Number' + }, + { + name: 'start2', + description: '

lower bound of the value's target range

\n', + type: 'Number' + }, + { + name: 'stop2', + description: '

upper bound of the value's target range

\n', + type: 'Number' + }, + { + name: 'withinBounds', + description: '

constrain the value to the newly mapped range

\n', + type: 'Boolean', + optional: true + } + ], + return: { + description: 'remapped number', + type: 'Number' + }, + example: [ + '\n
\nlet value = 25;\nlet m = map(value, 0, 100, 0, width);\nellipse(m, 50, 10, 10);\n
\n\n
\nfunction setup() {\n noStroke();\n}\n\nfunction draw() {\n background(204);\n let x1 = map(mouseX, 0, width, 25, 75);\n ellipse(x1, 25, 25, 25);\n //This ellipse is constrained to the 0-100 range\n //after setting withinBounds to true\n let x2 = map(mouseX, 0, width, 0, 100, true);\n ellipse(x2, 75, 25, 25);\n}\n
' + ], + alt: + '10 by 10 white ellipse with in mid left canvas\n2 25 by 25 white ellipses move with mouse x. Bottom has more range from X', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 478, + description: + '

Determines the largest value in a sequence of numbers, and then returns\nthat value. max() accepts any number of Number parameters, or an Array\nof any length.

\n', + itemtype: 'method', + name: 'max', + return: { + description: 'maximum Number', + type: 'Number' + }, + example: [ + "\n
\nfunction setup() {\n // Change the elements in the array and run the sketch\n // to show how max() works!\n let numArray = [2, 1, 5, 4, 8, 9];\n fill(0);\n noStroke();\n text('Array Elements', 0, 10);\n // Draw all numbers in the array\n let spacing = 15;\n let elemsY = 25;\n for (let i = 0; i < numArray.length; i++) {\n text(numArray[i], i * spacing, elemsY);\n }\n let maxX = 33;\n let maxY = 80;\n // Draw the Maximum value in the array.\n textSize(32);\n text(max(numArray), maxX, maxY);\n}\n
" + ], + alt: + 'Small text at top reads: Array Elements 2 1 5 4 8 9. Large text at center: 9', + class: 'p5', + module: 'Math', + submodule: 'Calculation', + overloads: [ + { + line: 478, + params: [ + { + name: 'n0', + description: '

Number to compare

\n', + type: 'Number' + }, + { + name: 'n1', + description: '

Number to compare

\n', + type: 'Number' + } + ], + return: { + description: 'maximum Number', + type: 'Number' + } + }, + { + line: 514, + params: [ + { + name: 'nums', + description: '

Numbers to compare

\n', + type: 'Number[]' + } + ], + return: { + description: '', + type: 'Number' + } + } + ] + }, + { + file: 'src/math/calculation.js', + line: 528, + description: + '

Determines the smallest value in a sequence of numbers, and then returns\nthat value. min() accepts any number of Number parameters, or an Array\nof any length.

\n', + itemtype: 'method', + name: 'min', + return: { + description: 'minimum Number', + type: 'Number' + }, + example: [ + "\n
\nfunction setup() {\n // Change the elements in the array and run the sketch\n // to show how min() works!\n let numArray = [2, 1, 5, 4, 8, 9];\n fill(0);\n noStroke();\n text('Array Elements', 0, 10);\n // Draw all numbers in the array\n let spacing = 15;\n let elemsY = 25;\n for (let i = 0; i < numArray.length; i++) {\n text(numArray[i], i * spacing, elemsY);\n }\n let maxX = 33;\n let maxY = 80;\n // Draw the Minimum value in the array.\n textSize(32);\n text(min(numArray), maxX, maxY);\n}\n
" + ], + alt: + 'Small text at top reads: Array Elements 2 1 5 4 8 9. Large text at center: 1', + class: 'p5', + module: 'Math', + submodule: 'Calculation', + overloads: [ + { + line: 528, + params: [ + { + name: 'n0', + description: '

Number to compare

\n', + type: 'Number' + }, + { + name: 'n1', + description: '

Number to compare

\n', + type: 'Number' + } + ], + return: { + description: 'minimum Number', + type: 'Number' + } + }, + { + line: 564, + params: [ + { + name: 'nums', + description: '

Numbers to compare

\n', + type: 'Number[]' + } + ], + return: { + description: '', + type: 'Number' + } + } + ] + }, + { + file: 'src/math/calculation.js', + line: 578, + description: + '

Normalizes a number from another range into a value between 0 and 1.\nIdentical to map(value, low, high, 0, 1).\nNumbers outside of the range are not clamped to 0 and 1, because\nout-of-range values are often intentional and useful. (See the example above.)

\n', + itemtype: 'method', + name: 'norm', + params: [ + { + name: 'value', + description: '

incoming value to be normalized

\n', + type: 'Number' + }, + { + name: 'start', + description: '

lower bound of the value's current range

\n', + type: 'Number' + }, + { + name: 'stop', + description: '

upper bound of the value's current range

\n', + type: 'Number' + } + ], + return: { + description: 'normalized number', + type: 'Number' + }, + example: [ + "\n
\nfunction draw() {\n background(200);\n let currentNum = mouseX;\n let lowerBound = 0;\n let upperBound = width; //100;\n let normalized = norm(currentNum, lowerBound, upperBound);\n let lineY = 70;\n stroke(3);\n line(0, lineY, width, lineY);\n //Draw an ellipse mapped to the non-normalized value.\n noStroke();\n fill(50);\n let s = 7; // ellipse size\n ellipse(currentNum, lineY, s, s);\n\n // Draw the guide\n let guideY = lineY + 15;\n text('0', 0, guideY);\n textAlign(RIGHT);\n text('100', width, guideY);\n\n // Draw the normalized value\n textAlign(LEFT);\n fill(0);\n textSize(32);\n let normalY = 40;\n let normalX = 20;\n text(normalized, normalX, normalY);\n}\n
" + ], + alt: + 'ellipse moves with mouse. 0 shown left & 100 right and updating values center', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 631, + description: + '

Facilitates exponential expressions. The pow() function is an efficient\nway of multiplying numbers by themselves (or their reciprocals) in large\nquantities. For example, pow(3, 5) is equivalent to the expression\n33333 and pow(3, -5) is equivalent to 1 / 33333. Maps to\nMath.pow().

\n', + itemtype: 'method', + name: 'pow', + params: [ + { + name: 'n', + description: '

base of the exponential expression

\n', + type: 'Number' + }, + { + name: 'e', + description: '

power by which to raise the base

\n', + type: 'Number' + } + ], + return: { + description: 'n^e', + type: 'Number' + }, + example: [ + '\n
\nfunction setup() {\n //Exponentially increase the size of an ellipse.\n let eSize = 3; // Original Size\n let eLoc = 10; // Original Location\n\n ellipse(eLoc, eLoc, eSize, eSize);\n\n ellipse(eLoc * 2, eLoc * 2, pow(eSize, 2), pow(eSize, 2));\n\n ellipse(eLoc * 4, eLoc * 4, pow(eSize, 3), pow(eSize, 3));\n\n ellipse(eLoc * 8, eLoc * 8, pow(eSize, 4), pow(eSize, 4));\n}\n
' + ], + alt: 'small to large ellipses radiating from top left of canvas', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 665, + description: + '

Calculates the integer closest to the n parameter. For example,\nround(133.8) returns the value 134. Maps to Math.round().

\n', + itemtype: 'method', + name: 'round', + params: [ + { + name: 'n', + description: '

number to round

\n', + type: 'Number' + } + ], + return: { + description: 'rounded number', + type: 'Integer' + }, + example: [ + '\n
\nfunction draw() {\n background(200);\n //map, mouseX between 0 and 5.\n let ax = map(mouseX, 0, 100, 0, 5);\n let ay = 66;\n\n // Round the mapped number.\n let bx = round(map(mouseX, 0, 100, 0, 5));\n let by = 33;\n\n // Multiply the mapped numbers by 20 to more easily\n // see the changes.\n stroke(0);\n fill(0);\n line(0, ay, ax * 20, ay);\n line(0, by, bx * 20, by);\n\n // Reformat the float returned by map and draw it.\n noStroke();\n text(nfc(ax, 2), ax, ay - 5);\n text(nfc(bx, 1), bx, by - 5);\n}\n
' + ], + alt: + 'horizontal center line squared values displayed on top and regular on bottom.', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 704, + description: + '

Squares a number (multiplies a number by itself). The result is always a\npositive number, as multiplying two negative numbers always yields a\npositive result. For example, -1 * -1 = 1.

\n', + itemtype: 'method', + name: 'sq', + params: [ + { + name: 'n', + description: '

number to square

\n', + type: 'Number' + } + ], + return: { + description: 'squared number', + type: 'Number' + }, + example: [ + "\n
\nfunction draw() {\n background(200);\n let eSize = 7;\n let x1 = map(mouseX, 0, width, 0, 10);\n let y1 = 80;\n let x2 = sq(x1);\n let y2 = 20;\n\n // Draw the non-squared.\n line(0, y1, width, y1);\n ellipse(x1, y1, eSize, eSize);\n\n // Draw the squared.\n line(0, y2, width, y2);\n ellipse(x2, y2, eSize, eSize);\n\n // Draw dividing line.\n stroke(100);\n line(0, height / 2, width, height / 2);\n\n // Draw text.\n let spacing = 15;\n noStroke();\n fill(0);\n text('x = ' + x1, 0, y1 + spacing);\n text('sq(x) = ' + x2, 0, y2 + spacing);\n}\n
" + ], + alt: + 'horizontal center line squared values displayed on top and regular on bottom.', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/calculation.js', + line: 751, + description: + '

Calculates the square root of a number. The square root of a number is\nalways positive, even though there may be a valid negative root. The\nsquare root s of number a is such that s*s = a. It is the opposite of\nsquaring. Maps to Math.sqrt().

\n', + itemtype: 'method', + name: 'sqrt', + params: [ + { + name: 'n', + description: '

non-negative number to square root

\n', + type: 'Number' + } + ], + return: { + description: 'square root of number', + type: 'Number' + }, + example: [ + "\n
\nfunction draw() {\n background(200);\n let eSize = 7;\n let x1 = mouseX;\n let y1 = 80;\n let x2 = sqrt(x1);\n let y2 = 20;\n\n // Draw the non-squared.\n line(0, y1, width, y1);\n ellipse(x1, y1, eSize, eSize);\n\n // Draw the squared.\n line(0, y2, width, y2);\n ellipse(x2, y2, eSize, eSize);\n\n // Draw dividing line.\n stroke(100);\n line(0, height / 2, width, height / 2);\n\n // Draw text.\n noStroke();\n fill(0);\n let spacing = 15;\n text('x = ' + x1, 0, y1 + spacing);\n text('sqrt(x) = ' + x2, 0, y2 + spacing);\n}\n
" + ], + alt: + 'horizontal center line squareroot values displayed on top and regular on bottom.', + class: 'p5', + module: 'Math', + submodule: 'Calculation' + }, + { + file: 'src/math/math.js', + line: 12, + description: + '

Creates a new p5.Vector (the datatype for storing vectors). This provides a\ntwo or three dimensional vector, specifically a Euclidean (also known as\ngeometric) vector. A vector is an entity that has both magnitude and\ndirection.

\n', + itemtype: 'method', + name: 'createVector', + params: [ + { + name: 'x', + description: '

x component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: '

y component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

z component of the vector

\n', + type: 'Number', + optional: true + } + ], + return: { + description: '', + type: 'p5.Vector' + }, + example: [ + "\n
\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n noStroke();\n fill(255, 102, 204);\n}\n\nfunction draw() {\n background(255);\n pointLight(color(255), createVector(sin(millis() / 1000) * 20, -40, -10));\n scale(0.75);\n sphere();\n}\n
" + ], + alt: 'a purple sphere lit by a point light oscillating horizontally', + class: 'p5', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/noise.js', + line: 40, + description: + '

Returns the Perlin noise value at specified coordinates. Perlin noise is\na random sequence generator producing a more natural ordered, harmonic\nsuccession of numbers compared to the standard random() function.\nIt was invented by Ken Perlin in the 1980s and been used since in\ngraphical applications to produce procedural textures, natural motion,\nshapes, terrains etc.

The main difference to the\nrandom() function is that Perlin noise is defined in an infinite\nn-dimensional space where each pair of coordinates corresponds to a\nfixed semi-random value (fixed only for the lifespan of the program; see\nthe noiseSeed() function). p5.js can compute 1D, 2D and 3D noise,\ndepending on the number of coordinates given. The resulting value will\nalways be between 0.0 and 1.0. The noise value can be animated by moving\nthrough the noise space as demonstrated in the example above. The 2nd\nand 3rd dimension can also be interpreted as time.

The actual\nnoise is structured similar to an audio signal, in respect to the\nfunction's use of frequencies. Similar to the concept of harmonics in\nphysics, perlin noise is computed over several octaves which are added\ntogether for the final result.

Another way to adjust the\ncharacter of the resulting sequence is the scale of the input\ncoordinates. As the function works within an infinite space the value of\nthe coordinates doesn't matter as such, only the distance between\nsuccessive coordinates does (eg. when using noise() within a\nloop). As a general rule the smaller the difference between coordinates,\nthe smoother the resulting noise sequence will be. Steps of 0.005-0.03\nwork best for most applications, but this will differ depending on use.

\n', + itemtype: 'method', + name: 'noise', + params: [ + { + name: 'x', + description: '

x-coordinate in noise space

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate in noise space

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

z-coordinate in noise space

\n', + type: 'Number', + optional: true + } + ], + return: { + description: + 'Perlin noise value (between 0 and 1) at specified\n coordinates', + type: 'Number' + }, + example: [ + '\n
\n\nlet xoff = 0.0;\n\nfunction draw() {\n background(204);\n xoff = xoff + 0.01;\n let n = noise(xoff) * width;\n line(n, 0, n, height);\n}\n\n
\n
\nlet noiseScale=0.02;\n\nfunction draw() {\n background(0);\n for (let x=0; x < width; x++) {\n let noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale);\n stroke(noiseVal*255);\n line(x, mouseY+noiseVal*80, x, height);\n }\n}\n\n
' + ], + alt: + 'vertical line moves left to right with updating noise values.\nhorizontal wave pattern effected by mouse x-position & updating noise values.', + class: 'p5', + module: 'Math', + submodule: 'Noise' + }, + { + file: 'src/math/noise.js', + line: 187, + description: + '

Adjusts the character and level of detail produced by the Perlin noise\n function. Similar to harmonics in physics, noise is computed over\n several octaves. Lower octaves contribute more to the output signal and\n as such define the overall intensity of the noise, whereas higher octaves\n create finer grained details in the noise sequence.\n

\n By default, noise is computed over 4 octaves with each octave contributing\n exactly half than its predecessor, starting at 50% strength for the 1st\n octave. This falloff amount can be changed by adding an additional function\n parameter. Eg. a falloff factor of 0.75 means each octave will now have\n 75% impact (25% less) of the previous lower octave. Any value between\n 0.0 and 1.0 is valid, however note that values greater than 0.5 might\n result in greater than 1.0 values returned by noise().\n

\n By changing these parameters, the signal created by the noise()\n function can be adapted to fit very specific needs and characteristics.

\n', + itemtype: 'method', + name: 'noiseDetail', + params: [ + { + name: 'lod', + description: '

number of octaves to be used by the noise

\n', + type: 'Number' + }, + { + name: 'falloff', + description: '

falloff factor for each octave

\n', + type: 'Number' + } + ], + example: [ + '\n
\n \n let noiseVal;\n let noiseScale = 0.02;\nfunction setup() {\n createCanvas(100, 100);\n }\nfunction draw() {\n background(0);\n for (let y = 0; y < height; y++) {\n for (let x = 0; x < width / 2; x++) {\n noiseDetail(2, 0.2);\n noiseVal = noise((mouseX + x) * noiseScale, (mouseY + y) * noiseScale);\n stroke(noiseVal * 255);\n point(x, y);\n noiseDetail(8, 0.65);\n noiseVal = noise(\n (mouseX + x + width / 2) * noiseScale,\n (mouseY + y) * noiseScale\n );\n stroke(noiseVal * 255);\n point(x + width / 2, y);\n }\n }\n }\n \n
' + ], + alt: + '2 vertical grey smokey patterns affected my mouse x-position and noise.', + class: 'p5', + module: 'Math', + submodule: 'Noise' + }, + { + file: 'src/math/noise.js', + line: 253, + description: + '

Sets the seed value for noise(). By default, noise()\nproduces different results each time the program is run. Set the\nvalue parameter to a constant to return the same pseudo-random\nnumbers each time the software is run.

\n', + itemtype: 'method', + name: 'noiseSeed', + params: [ + { + name: 'seed', + description: '

the seed value

\n', + type: 'Number' + } + ], + example: [ + '\n
\nlet xoff = 0.0;\n\nfunction setup() {\n noiseSeed(99);\n stroke(0, 10);\n}\n\nfunction draw() {\n xoff = xoff + .01;\n let n = noise(xoff) * width;\n line(n, 0, n, height);\n}\n\n
' + ], + alt: 'vertical grey lines drawing in pattern affected by noise.', + class: 'p5', + module: 'Math', + submodule: 'Noise' + }, + { + file: 'src/math/p5.Vector.js', + line: 67, + description: '

The x component of the vector

\n', + itemtype: 'property', + name: 'x', + type: 'Number', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 72, + description: '

The y component of the vector

\n', + itemtype: 'property', + name: 'y', + type: 'Number', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 77, + description: '

The z component of the vector

\n', + itemtype: 'property', + name: 'z', + type: 'Number', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 84, + description: + '

Returns a string representation of a vector v by calling String(v)\nor v.toString(). This method is useful for logging vectors in the\nconsole.

\n', + itemtype: 'method', + name: 'toString', + return: { + description: '', + type: 'String' + }, + example: [ + '\n
\n\nfunction setup() {\n let v = createVector(20, 30);\n print(String(v)); // prints "p5.Vector Object : [20, 30, 0]"\n}\n\n
\n\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(0, 0);\n let v1 = createVector(mouseX, mouseY);\n drawArrow(v0, v1, \'black\');\n\n noStroke();\n text(v1.toString(), 10, 25, 90, 75);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 134, + description: + '

Sets the x, y, and z component of the vector using two or three separate\nvariables, the data from a p5.Vector, or the values from a float array.

\n', + itemtype: 'method', + name: 'set', + chainable: 1, + example: [ + "\n
\n\nfunction setup() {\n let v = createVector(1, 2, 3);\n v.set(4, 5, 6); // Sets vector to [4, 5, 6]\n\n let v1 = createVector(0, 0, 0);\n let arr = [1, 2, 3];\n v1.set(arr); // Sets vector to [1, 2, 3]\n}\n\n
\n\n
\n\nlet v0, v1;\nfunction setup() {\n createCanvas(100, 100);\n\n v0 = createVector(0, 0);\n v1 = createVector(50, 50);\n}\n\nfunction draw() {\n background(240);\n\n drawArrow(v0, v1, 'black');\n v1.set(v1.x + random(-1, 1), v1.y + random(-1, 1));\n\n noStroke();\n text('x: ' + round(v1.x) + ' y: ' + round(v1.y), 20, 90);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 134, + params: [ + { + name: 'x', + description: '

the x component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: '

the y component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

the z component of the vector

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 193, + params: [ + { + name: 'value', + description: '

the vector to set

\n', + type: 'p5.Vector|Number[]' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 217, + description: + '

Gets a copy of the vector, returns a p5.Vector object.

\n', + itemtype: 'method', + name: 'copy', + return: { + description: 'the copy of the p5.Vector object', + type: 'p5.Vector' + }, + example: [ + '\n
\n\nlet v1 = createVector(1, 2, 3);\nlet v2 = v1.copy();\nprint(v1.x === v2.x && v1.y === v2.y && v1.z === v2.z);\n// Prints "true"\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 240, + description: + '

Adds x, y, and z components to a vector, adds one vector to another, or\nadds two independent vectors together. The version of the method that adds\ntwo vectors together is a static method and returns a p5.Vector, the others\nacts directly on the vector. See the examples for more context.

\n', + itemtype: 'method', + name: 'add', + chainable: 1, + example: [ + "\n
\n\nlet v = createVector(1, 2, 3);\nv.add(4, 5, 6);\n// v's components are set to [5, 7, 9]\n\n
\n\n
\n\n// Static method\nlet v1 = createVector(1, 2, 3);\nlet v2 = createVector(2, 3, 4);\n\nlet v3 = p5.Vector.add(v1, v2);\n// v3 has components [3, 5, 7]\nprint(v3);\n\n
\n\n
\n\n// red vector + blue vector = purple vector\nfunction draw() {\n background(240);\n\n let v0 = createVector(0, 0);\n let v1 = createVector(mouseX, mouseY);\n drawArrow(v0, v1, 'red');\n\n let v2 = createVector(-30, 20);\n drawArrow(v1, v2, 'blue');\n\n let v3 = p5.Vector.add(v1, v2);\n drawArrow(v0, v3, 'purple');\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 240, + params: [ + { + name: 'x', + description: '

the x component of the vector to be added

\n', + type: 'Number' + }, + { + name: 'y', + description: '

the y component of the vector to be added

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

the z component of the vector to be added

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 306, + params: [ + { + name: 'value', + description: '

the vector to add

\n', + type: 'p5.Vector|Number[]' + } + ], + chainable: 1 + }, + { + line: 1555, + params: [ + { + name: 'v1', + description: + '

a p5.Vector to add

\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + '

a p5.Vector to add

\n', + type: 'p5.Vector' + }, + { + name: 'target', + description: '

the vector to receive the result

\n', + type: 'p5.Vector' + } + ], + static: 1 + }, + { + line: 1562, + params: [ + { + name: 'v1', + description: '', + type: 'p5.Vector' + }, + { + name: 'v2', + description: '', + type: 'p5.Vector' + } + ], + static: 1, + return: { + description: 'the resulting p5.Vector', + type: 'p5.Vector' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 330, + description: + '

Subtracts x, y, and z components from a vector, subtracts one vector from\nanother, or subtracts two independent vectors. The version of the method\nthat subtracts two vectors is a static method and returns a p5.Vector, the\nother acts directly on the vector. See the examples for more context.

\n', + itemtype: 'method', + name: 'sub', + chainable: 1, + example: [ + "\n
\n\nlet v = createVector(4, 5, 6);\nv.sub(1, 1, 1);\n// v's components are set to [3, 4, 5]\n\n
\n\n
\n\n// Static method\nlet v1 = createVector(2, 3, 4);\nlet v2 = createVector(1, 2, 3);\n\nlet v3 = p5.Vector.sub(v1, v2);\n// v3 has components [1, 1, 1]\nprint(v3);\n\n
\n\n
\n\n// red vector - blue vector = purple vector\nfunction draw() {\n background(240);\n\n let v0 = createVector(0, 0);\n let v1 = createVector(70, 50);\n drawArrow(v0, v1, 'red');\n\n let v2 = createVector(mouseX, mouseY);\n drawArrow(v0, v2, 'blue');\n\n let v3 = p5.Vector.sub(v1, v2);\n drawArrow(v2, v3, 'purple');\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 330, + params: [ + { + name: 'x', + description: '

the x component of the vector to subtract

\n', + type: 'Number' + }, + { + name: 'y', + description: '

the y component of the vector to subtract

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

the z component of the vector to subtract

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 396, + params: [ + { + name: 'value', + description: '

the vector to subtract

\n', + type: 'p5.Vector|Number[]' + } + ], + chainable: 1 + }, + { + line: 1585, + params: [ + { + name: 'v1', + description: + '

a p5.Vector to subtract from

\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + '

a p5.Vector to subtract

\n', + type: 'p5.Vector' + }, + { + name: 'target', + description: '

if undefined a new vector will be created

\n', + type: 'p5.Vector' + } + ], + static: 1 + }, + { + line: 1592, + params: [ + { + name: 'v1', + description: '', + type: 'p5.Vector' + }, + { + name: 'v2', + description: '', + type: 'p5.Vector' + } + ], + static: 1, + return: { + description: 'the resulting p5.Vector', + type: 'p5.Vector' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 420, + description: + '

Multiply the vector by a scalar. The static version of this method\ncreates a new p5.Vector while the non static version acts on the vector\ndirectly. See the examples for more context.

\n', + itemtype: 'method', + name: 'mult', + chainable: 1, + example: [ + "\n
\n\nlet v = createVector(1, 2, 3);\nv.mult(2);\n// v's components are set to [2, 4, 6]\n\n
\n\n
\n\n// Static method\nlet v1 = createVector(1, 2, 3);\nlet v2 = p5.Vector.mult(v1, 2);\n// v2 has components [2, 4, 6]\nprint(v2);\n\n
\n\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(50, 50);\n let v1 = createVector(25, -25);\n drawArrow(v0, v1, 'red');\n\n let num = map(mouseX, 0, width, -2, 2, true);\n let v2 = p5.Vector.mult(v1, num);\n drawArrow(v0, v2, 'blue');\n\n noStroke();\n text('multiplied by ' + num.toFixed(2), 5, 90);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 420, + params: [ + { + name: 'n', + description: '

the number to multiply with the vector

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 1613, + params: [ + { + name: 'v', + description: '

the vector to multiply

\n', + type: 'p5.Vector' + }, + { + name: 'n', + description: '', + type: 'Number' + }, + { + name: 'target', + description: '

if undefined a new vector will be created

\n', + type: 'p5.Vector' + } + ], + static: 1 + }, + { + line: 1620, + params: [ + { + name: 'v', + description: '', + type: 'p5.Vector' + }, + { + name: 'n', + description: '', + type: 'Number' + } + ], + static: 1, + return: { + description: 'the resulting new p5.Vector', + type: 'p5.Vector' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 495, + description: + '

Divide the vector by a scalar. The static version of this method creates a\nnew p5.Vector while the non static version acts on the vector directly.\nSee the examples for more context.

\n', + itemtype: 'method', + name: 'div', + chainable: 1, + example: [ + "\n
\n\nlet v = createVector(6, 4, 2);\nv.div(2); //v's components are set to [3, 2, 1]\n\n
\n\n
\n\n// Static method\nlet v1 = createVector(6, 4, 2);\nlet v2 = p5.Vector.div(v1, 2);\n// v2 has components [3, 2, 1]\nprint(v2);\n\n
\n\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(0, 100);\n let v1 = createVector(50, -50);\n drawArrow(v0, v1, 'red');\n\n let num = map(mouseX, 0, width, 10, 0.5, true);\n let v2 = p5.Vector.div(v1, num);\n drawArrow(v0, v2, 'blue');\n\n noStroke();\n text('divided by ' + num.toFixed(2), 10, 90);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 495, + params: [ + { + name: 'n', + description: '

the number to divide the vector by

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 1640, + params: [ + { + name: 'v', + description: '

the vector to divide

\n', + type: 'p5.Vector' + }, + { + name: 'n', + description: '', + type: 'Number' + }, + { + name: 'target', + description: '

if undefined a new vector will be created

\n', + type: 'p5.Vector' + } + ], + static: 1 + }, + { + line: 1647, + params: [ + { + name: 'v', + description: '', + type: 'p5.Vector' + }, + { + name: 'n', + description: '', + type: 'Number' + } + ], + static: 1, + return: { + description: 'the resulting new p5.Vector', + type: 'p5.Vector' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 573, + description: + '

Calculates the magnitude (length) of the vector and returns the result as\na float (this is simply the equation sqrt(xx + yy + z*z).)

\n', + itemtype: 'method', + name: 'mag', + return: { + description: 'magnitude of the vector', + type: 'Number' + }, + example: [ + '\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(0, 0);\n let v1 = createVector(mouseX, mouseY);\n drawArrow(v0, v1, \'black\');\n\n noStroke();\n text(\'vector length: \' + v1.mag().toFixed(2), 10, 70, 90, 30);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
\n
\n\nlet v = createVector(20.0, 30.0, 40.0);\nlet m = v.mag();\nprint(m); // Prints "53.85164807134504"\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 573, + params: [], + return: { + description: 'magnitude of the vector', + type: 'Number' + } + }, + { + line: 1737, + params: [ + { + name: 'vecT', + description: '

the vector to return the magnitude of

\n', + type: 'p5.Vector' + } + ], + static: 1, + return: { + description: 'the magnitude of vecT', + type: 'Number' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 621, + description: + '

Calculates the squared magnitude of the vector and returns the result\nas a float (this is simply the equation (xx + yy + z*z).)\nFaster if the real length is not required in the\ncase of comparing vectors, etc.

\n', + itemtype: 'method', + name: 'magSq', + return: { + description: 'squared magnitude of the vector', + type: 'Number' + }, + example: [ + '\n
\n\n// Static method\nlet v1 = createVector(6, 4, 2);\nprint(v1.magSq()); // Prints "56"\n\n
\n\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(0, 0);\n let v1 = createVector(mouseX, mouseY);\n drawArrow(v0, v1, \'black\');\n\n noStroke();\n text(\'vector length squared: \' + v1.magSq().toFixed(2), 10, 45, 90, 55);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 675, + description: + '

Calculates the dot product of two vectors. The version of the method\nthat computes the dot product of two independent vectors is a static\nmethod. See the examples for more context.

\n', + itemtype: 'method', + name: 'dot', + return: { + description: 'the dot product', + type: 'Number' + }, + example: [ + '\n
\n\nlet v1 = createVector(1, 2, 3);\nlet v2 = createVector(2, 3, 4);\n\nprint(v1.dot(v2)); // Prints "20"\n\n
\n\n
\n\n//Static method\nlet v1 = createVector(1, 2, 3);\nlet v2 = createVector(3, 2, 1);\nprint(p5.Vector.dot(v1, v2)); // Prints "10"\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 675, + params: [ + { + name: 'x', + description: '

x component of the vector

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

z component of the vector

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'the dot product', + type: 'Number' + } + }, + { + line: 706, + params: [ + { + name: 'value', + description: + '

value component of the vector or a p5.Vector

\n', + type: 'p5.Vector' + } + ], + return: { + description: '', + type: 'Number' + } + }, + { + line: 1667, + params: [ + { + name: 'v1', + description: + '

the first p5.Vector

\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + '

the second p5.Vector

\n', + type: 'p5.Vector' + } + ], + static: 1, + return: { + description: 'the dot product', + type: 'Number' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 718, + description: + '

Calculates and returns a vector composed of the cross product between\ntwo vectors. Both the static and non static methods return a new p5.Vector.\nSee the examples for more context.

\n', + itemtype: 'method', + name: 'cross', + return: { + description: + 'p5.Vector composed of cross product', + type: 'p5.Vector' + }, + example: [ + '\n
\n\nlet v1 = createVector(1, 2, 3);\nlet v2 = createVector(1, 2, 3);\n\nv1.cross(v2); // v\'s components are [0, 0, 0]\n\n
\n\n
\n\n// Static method\nlet v1 = createVector(1, 0, 0);\nlet v2 = createVector(0, 1, 0);\n\nlet crossProduct = p5.Vector.cross(v1, v2);\n// crossProduct has components [0, 0, 1]\nprint(crossProduct);\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 718, + params: [ + { + name: 'v', + description: + '

p5.Vector to be crossed

\n', + type: 'p5.Vector' + } + ], + return: { + description: + 'p5.Vector composed of cross product', + type: 'p5.Vector' + } + }, + { + line: 1681, + params: [ + { + name: 'v1', + description: + '

the first p5.Vector

\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + '

the second p5.Vector

\n', + type: 'p5.Vector' + } + ], + static: 1, + return: { + description: 'the cross product', + type: 'Number' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 759, + description: + '

Calculates the Euclidean distance between two points (considering a\npoint as a vector object).

\n', + itemtype: 'method', + name: 'dist', + return: { + description: 'the distance', + type: 'Number' + }, + example: [ + "\n
\n\nlet v1 = createVector(1, 0, 0);\nlet v2 = createVector(0, 1, 0);\n\nlet distance = v1.dist(v2); // distance is 1.4142...\nprint(distance);\n\n
\n\n
\n\n// Static method\nlet v1 = createVector(1, 0, 0);\nlet v2 = createVector(0, 1, 0);\n\nlet distance = p5.Vector.dist(v1, v2);\n// distance is 1.4142...\nprint(distance);\n\n
\n\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(0, 0);\n\n let v1 = createVector(70, 50);\n drawArrow(v0, v1, 'red');\n\n let v2 = createVector(mouseX, mouseY);\n drawArrow(v0, v2, 'blue');\n\n noStroke();\n text('distance between vectors: ' + v2.dist(v1).toFixed(2), 5, 50, 95, 50);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 759, + params: [ + { + name: 'v', + description: + '

the x, y, and z coordinates of a p5.Vector

\n', + type: 'p5.Vector' + } + ], + return: { + description: 'the distance', + type: 'Number' + } + }, + { + line: 1696, + params: [ + { + name: 'v1', + description: + '

the first p5.Vector

\n', + type: 'p5.Vector' + }, + { + name: 'v2', + description: + '

the second p5.Vector

\n', + type: 'p5.Vector' + } + ], + static: 1, + return: { + description: 'the distance', + type: 'Number' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 830, + description: + '

Normalize the vector to length 1 (make it a unit vector).

\n', + itemtype: 'method', + name: 'normalize', + return: { + description: 'normalized p5.Vector', + type: 'p5.Vector' + }, + example: [ + "\n
\n\nlet v = createVector(10, 20, 2);\n// v has components [10.0, 20.0, 2.0]\nv.normalize();\n// v's components are set to\n// [0.4454354, 0.8908708, 0.089087084]\n\n
\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(50, 50);\n let v1 = createVector(mouseX - 50, mouseY - 50);\n\n drawArrow(v0, v1, 'red');\n v1.normalize();\n drawArrow(v0, v1.mult(35), 'blue');\n\n noFill();\n ellipse(50, 50, 35 * 2);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 886, + description: + '

Limit the magnitude of this vector to the value used for the max\nparameter.

\n', + itemtype: 'method', + name: 'limit', + params: [ + { + name: 'max', + description: '

the maximum magnitude for the vector

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nlet v = createVector(10, 20, 2);\n// v has components [10.0, 20.0, 2.0]\nv.limit(5);\n// v's components are set to\n// [2.2271771, 4.4543543, 0.4454354]\n\n
\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(50, 50);\n let v1 = createVector(mouseX - 50, mouseY - 50);\n\n drawArrow(v0, v1, 'red');\n drawArrow(v0, v1.limit(35), 'blue');\n\n noFill();\n ellipse(50, 50, 35 * 2);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 944, + description: + '

Set the magnitude of this vector to the value used for the len\nparameter.

\n', + itemtype: 'method', + name: 'setMag', + params: [ + { + name: 'len', + description: '

the new length for this vector

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nlet v = createVector(10, 20, 2);\n// v has components [10.0, 20.0, 2.0]\nv.setMag(10);\n// v's components are set to [6.0, 8.0, 0.0]\n\n
\n\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(0, 0);\n let v1 = createVector(50, 50);\n\n drawArrow(v0, v1, 'red');\n\n let length = map(mouseX, 0, width, 0, 141, true);\n v1.setMag(length);\n drawArrow(v0, v1, 'blue');\n\n noStroke();\n text('magnitude set to: ' + length.toFixed(2), 10, 70, 90, 30);\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1000, + description: + '

Calculate the angle of rotation for this vector (only 2D vectors)

\n', + itemtype: 'method', + name: 'heading', + return: { + description: 'the angle of rotation', + type: 'Number' + }, + example: [ + "\n
\n\nfunction setup() {\n let v1 = createVector(30, 50);\n print(v1.heading()); // 1.0303768265243125\n\n v1 = createVector(40, 50);\n print(v1.heading()); // 0.8960553845713439\n\n v1 = createVector(30, 70);\n print(v1.heading()); // 1.1659045405098132\n}\n\n
\n\n
\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(50, 50);\n let v1 = createVector(mouseX - 50, mouseY - 50);\n\n drawArrow(v0, v1, 'black');\n\n let myHeading = v1.heading();\n noStroke();\n text(\n 'vector heading: ' +\n myHeading.toFixed(2) +\n ' radians or ' +\n degrees(myHeading).toFixed(2) +\n ' degrees',\n 10,\n 50,\n 90,\n 50\n );\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1069, + description: + '

Rotate the vector by an angle (only 2D vectors), magnitude remains the\nsame

\n', + itemtype: 'method', + name: 'rotate', + params: [ + { + name: 'angle', + description: '

the angle of rotation

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + "\n
\n\nlet v = createVector(10.0, 20.0);\n// v has components [10.0, 20.0, 0.0]\nv.rotate(HALF_PI);\n// v's components are set to [-20.0, 9.999999, 0.0]\n\n
\n\n
\n\nlet angle = 0;\nfunction draw() {\n background(240);\n\n let v0 = createVector(50, 50);\n let v1 = createVector(50, 0);\n\n drawArrow(v0, v1.rotate(angle), 'black');\n angle += 0.01;\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1125, + description: + '

Calculates and returns the angle (in radians) between two vectors.

\n', + itemtype: 'method', + name: 'angleBetween', + params: [ + { + name: 'value', + description: + '

the x, y, and z components of a p5.Vector

\n', + type: 'p5.Vector' + } + ], + return: { + description: 'the angle between (in radians)', + type: 'Number' + }, + example: [ + "\n
\n\nlet v1 = createVector(1, 0, 0);\nlet v2 = createVector(0, 1, 0);\n\nlet angle = v1.angleBetween(v2);\n// angle is PI/2\nprint(angle);\n\n
\n\n
\n\nfunction draw() {\n background(240);\n let v0 = createVector(50, 50);\n\n let v1 = createVector(50, 0);\n drawArrow(v0, v1, 'red');\n\n let v2 = createVector(mouseX - 50, mouseY - 50);\n drawArrow(v0, v2, 'blue');\n\n let angleBetween = v1.angleBetween(v2);\n noStroke();\n text(\n 'angle between: ' +\n angleBetween.toFixed(2) +\n ' radians or ' +\n degrees(angleBetween).toFixed(2) +\n ' degrees',\n 10,\n 50,\n 90,\n 50\n );\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1198, + description: '

Linear interpolate the vector to another vector

\n', + itemtype: 'method', + name: 'lerp', + chainable: 1, + example: [ + "\n
\n\nlet v = createVector(1, 1, 0);\n\nv.lerp(3, 3, 0, 0.5); // v now has components [2,2,0]\n\n
\n\n
\n\nlet v1 = createVector(0, 0, 0);\nlet v2 = createVector(100, 100, 0);\n\nlet v3 = p5.Vector.lerp(v1, v2, 0.5);\n// v3 has components [50,50,0]\nprint(v3);\n\n
\n\n
\n\nlet step = 0.01;\nlet amount = 0;\n\nfunction draw() {\n background(240);\n let v0 = createVector(0, 0);\n\n let v1 = createVector(mouseX, mouseY);\n drawArrow(v0, v1, 'red');\n\n let v2 = createVector(90, 90);\n drawArrow(v0, v2, 'blue');\n\n if (amount > 1 || amount < 0) {\n step *= -1;\n }\n amount += step;\n let v3 = p5.Vector.lerp(v1, v2, amount);\n\n drawArrow(v0, v3, 'purple');\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 1198, + params: [ + { + name: 'x', + description: '

the x component

\n', + type: 'Number' + }, + { + name: 'y', + description: '

the y component

\n', + type: 'Number' + }, + { + name: 'z', + description: '

the z component

\n', + type: 'Number' + }, + { + name: 'amt', + description: + '

the amount of interpolation; some value between 0.0\n (old vector) and 1.0 (new vector). 0.9 is very near\n the new vector. 0.5 is halfway in between.

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 1271, + params: [ + { + name: 'v', + description: + '

the p5.Vector to lerp to

\n', + type: 'p5.Vector' + }, + { + name: 'amt', + description: '', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 1711, + params: [ + { + name: 'v1', + description: '', + type: 'p5.Vector' + }, + { + name: 'v2', + description: '', + type: 'p5.Vector' + }, + { + name: 'amt', + description: '', + type: 'Number' + }, + { + name: 'target', + description: '

if undefined a new vector will be created

\n', + type: 'p5.Vector' + } + ], + static: 1 + }, + { + line: 1719, + params: [ + { + name: 'v1', + description: '', + type: 'p5.Vector' + }, + { + name: 'v2', + description: '', + type: 'p5.Vector' + }, + { + name: 'amt', + description: '', + type: 'Number' + } + ], + static: 1, + return: { + description: 'the lerped value', + type: 'Number' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 1287, + description: + '

Return a representation of this vector as a float array. This is only\nfor temporary use. If used in any other fashion, the contents should be\ncopied by using the p5.Vector.copy() method to copy into your own\narray.

\n', + itemtype: 'method', + name: 'array', + return: { + description: 'an Array with the 3 values', + type: 'Number[]' + }, + example: [ + '\n
\n\nfunction setup() {\n let v = createVector(20, 30);\n print(v.array()); // Prints : Array [20, 30, 0]\n}\n\n
\n\n
\n\nlet v = createVector(10.0, 20.0, 30.0);\nlet f = v.array();\nprint(f[0]); // Prints "10.0"\nprint(f[1]); // Prints "20.0"\nprint(f[2]); // Prints "30.0"\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1319, + description: + '

Equality check against a p5.Vector

\n', + itemtype: 'method', + name: 'equals', + return: { + description: 'whether the vectors are equals', + type: 'Boolean' + }, + example: [ + '\n
\n\nlet v1 = createVector(5, 10, 20);\nlet v2 = createVector(5, 10, 20);\nlet v3 = createVector(13, 10, 19);\n\nprint(v1.equals(v2.x, v2.y, v2.z)); // true\nprint(v1.equals(v3.x, v3.y, v3.z)); // false\n\n
\n\n
\n\nlet v1 = createVector(10.0, 20.0, 30.0);\nlet v2 = createVector(10.0, 20.0, 30.0);\nlet v3 = createVector(0.0, 0.0, 0.0);\nprint(v1.equals(v2)); // true\nprint(v1.equals(v3)); // false\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math', + overloads: [ + { + line: 1319, + params: [ + { + name: 'x', + description: '

the x component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: '

the y component of the vector

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

the z component of the vector

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'whether the vectors are equals', + type: 'Boolean' + } + }, + { + line: 1349, + params: [ + { + name: 'value', + description: '

the vector to compare

\n', + type: 'p5.Vector|Array' + } + ], + return: { + description: '', + type: 'Boolean' + } + } + ] + }, + { + file: 'src/math/p5.Vector.js', + line: 1374, + description: '

Make a new 2D vector from an angle

\n', + itemtype: 'method', + name: 'fromAngle', + static: 1, + params: [ + { + name: 'angle', + description: + '

the desired angle, in radians (unaffected by angleMode)

\n', + type: 'Number' + }, + { + name: 'length', + description: '

the length of the new vector (defaults to 1)

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'the new p5.Vector object', + type: 'p5.Vector' + }, + example: [ + "\n
\n\nfunction draw() {\n background(200);\n\n // Create a variable, proportional to the mouseX,\n // varying from 0-360, to represent an angle in degrees.\n let myDegrees = map(mouseX, 0, width, 0, 360);\n\n // Display that variable in an onscreen text.\n // (Note the nfc() function to truncate additional decimal places,\n // and the \"\\xB0\" character for the degree symbol.)\n let readout = 'angle = ' + nfc(myDegrees, 1) + '\\xB0';\n noStroke();\n fill(0);\n text(readout, 5, 15);\n\n // Create a p5.Vector using the fromAngle function,\n // and extract its x and y components.\n let v = p5.Vector.fromAngle(radians(myDegrees), 30);\n let vx = v.x;\n let vy = v.y;\n\n push();\n translate(width / 2, height / 2);\n noFill();\n stroke(150);\n line(0, 0, 30, 0);\n stroke(0);\n line(0, 0, vx, vy);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1425, + description: + '

Make a new 3D vector from a pair of ISO spherical angles

\n', + itemtype: 'method', + name: 'fromAngles', + static: 1, + params: [ + { + name: 'theta', + description: '

the polar angle, in radians (zero is up)

\n', + type: 'Number' + }, + { + name: 'phi', + description: + '

the azimuthal angle, in radians\n (zero is out of the screen)

\n', + type: 'Number' + }, + { + name: 'length', + description: '

the length of the new vector (defaults to 1)

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'the new p5.Vector object', + type: 'p5.Vector' + }, + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n fill(255);\n noStroke();\n}\nfunction draw() {\n background(255);\n\n let t = millis() / 1000;\n\n // add three point lights\n pointLight(color('#f00'), p5.Vector.fromAngles(t * 1.0, t * 1.3, 100));\n pointLight(color('#0f0'), p5.Vector.fromAngles(t * 1.1, t * 1.2, 100));\n pointLight(color('#00f'), p5.Vector.fromAngles(t * 1.2, t * 1.1, 100));\n\n sphere(35);\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1474, + description: '

Make a new 2D unit vector from a random angle

\n', + itemtype: 'method', + name: 'random2D', + static: 1, + return: { + description: 'the new p5.Vector object', + type: 'p5.Vector' + }, + example: [ + "\n
\n\nlet v = p5.Vector.random2D();\n// May make v's attributes something like:\n// [0.61554617, -0.51195765, 0.0] or\n// [-0.4695841, -0.14366731, 0.0] or\n// [0.6091097, -0.22805278, 0.0]\nprint(v);\n\n
\n\n
\n\nfunction setup() {\n frameRate(1);\n}\n\nfunction draw() {\n background(240);\n\n let v0 = createVector(50, 50);\n let v1 = p5.Vector.random2D();\n drawArrow(v0, v1.mult(50), 'black');\n}\n\n// draw an arrow for a vector at a given base position\nfunction drawArrow(base, vec, myColor) {\n push();\n stroke(myColor);\n strokeWeight(3);\n fill(myColor);\n translate(base.x, base.y);\n line(0, 0, vec.x, vec.y);\n rotate(vec.heading());\n let arrowSize = 7;\n translate(vec.mag() - arrowSize, 0);\n triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0);\n pop();\n}\n\n
" + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1527, + description: '

Make a new random 3D unit vector.

\n', + itemtype: 'method', + name: 'random3D', + static: 1, + return: { + description: 'the new p5.Vector object', + type: 'p5.Vector' + }, + example: [ + '\n
\n\nlet v = p5.Vector.random3D();\n// May make v\'s attributes something like:\n// [0.61554617, -0.51195765, 0.599168] or\n// [-0.4695841, -0.14366731, -0.8711202] or\n// [0.6091097, -0.22805278, -0.7595902]\nprint(v);\n\n
' + ], + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1610, + description: + '

Multiplies a vector by a scalar and returns a new vector.

\n', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1637, + description: + '

Divides a vector by a scalar and returns a new vector.

\n', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1664, + description: '

Calculates the dot product of two vectors.

\n', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1678, + description: '

Calculates the cross product of two vectors.

\n', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1692, + description: + '

Calculates the Euclidean distance between two points (considering a\npoint as a vector object).

\n', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/p5.Vector.js', + line: 1707, + description: + '

Linear interpolate a vector to another vector and return the result as a\nnew vector.

\n', + class: 'p5.Vector', + module: 'Math', + submodule: 'Math' + }, + { + file: 'src/math/random.js', + line: 48, + description: + '

Sets the seed value for random().

\n

By default, random() produces different results each time the program\nis run. Set the seed parameter to a constant to return the same\npseudo-random numbers each time the software is run.

\n', + itemtype: 'method', + name: 'randomSeed', + params: [ + { + name: 'seed', + description: '

the seed value

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\nrandomSeed(99);\nfor (let i = 0; i < 100; i++) {\n let r = random(0, 255);\n stroke(r);\n line(i, 0, i, 100);\n}\n\n
' + ], + alt: 'many vertical lines drawn in white, black or grey.', + class: 'p5', + module: 'Math', + submodule: 'Random' + }, + { + file: 'src/math/random.js', + line: 79, + description: + '

Return a random floating-point number.

\n

Takes either 0, 1 or 2 arguments.

\n

If no argument is given, returns a random number from 0\nup to (but not including) 1.

\n

If one argument is given and it is a number, returns a random number from 0\nup to (but not including) the number.

\n

If one argument is given and it is an array, returns a random element from\nthat array.

\n

If two arguments are given, returns a random number from the\nfirst argument up to (but not including) the second argument.

\n', + itemtype: 'method', + name: 'random', + return: { + description: 'the random number', + type: 'Number' + }, + example: [ + "\n
\n\nfor (let i = 0; i < 100; i++) {\n let r = random(50);\n stroke(r * 5);\n line(50, i, 50 + r, i);\n}\n\n
\n
\n\nfor (let i = 0; i < 100; i++) {\n let r = random(-50, 50);\n line(50, i, 50 + r, i);\n}\n\n
\n
\n\n// Get a random element from an array using the random(Array) syntax\nlet words = ['apple', 'bear', 'cat', 'dog'];\nlet word = random(words); // select random word\ntext(word, 10, 50); // draw the word\n\n
" + ], + alt: + '100 horizontal lines from center canvas to right. size+fill change each time\n100 horizontal lines from center of canvas. height & side change each render\nword displayed at random. Either apple, bear, cat, or dog', + class: 'p5', + module: 'Math', + submodule: 'Random', + overloads: [ + { + line: 79, + params: [ + { + name: 'min', + description: '

the lower bound (inclusive)

\n', + type: 'Number', + optional: true + }, + { + name: 'max', + description: '

the upper bound (exclusive)

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'the random number', + type: 'Number' + } + }, + { + line: 133, + params: [ + { + name: 'choices', + description: '

the array to choose from

\n', + type: 'Array' + } + ], + return: { + description: 'the random element from the array', + type: '*' + } + } + ] + }, + { + file: 'src/math/random.js', + line: 166, + description: + '

Returns a random number fitting a Gaussian, or\n normal, distribution. There is theoretically no minimum or maximum\n value that randomGaussian() might return. Rather, there is\n just a very low probability that values far from the mean will be\n returned; and a higher probability that numbers near the mean will\n be returned.\n

\n Takes either 0, 1 or 2 arguments.
\n If no args, returns a mean of 0 and standard deviation of 1.
\n If one arg, that arg is the mean (standard deviation is 1).
\n If two args, first is mean, second is standard deviation.

\n', + itemtype: 'method', + name: 'randomGaussian', + params: [ + { + name: 'mean', + description: '

the mean

\n', + type: 'Number' + }, + { + name: 'sd', + description: '

the standard deviation

\n', + type: 'Number' + } + ], + return: { + description: 'the random number', + type: 'Number' + }, + example: [ + '\n
\n \n for (let y = 0; y < 100; y++) {\n let x = randomGaussian(50, 15);\n line(50, y, x, y);\n }\n \n
\n
\n \n let distribution = new Array(360);\nfunction setup() {\n createCanvas(100, 100);\n for (let i = 0; i < distribution.length; i++) {\n distribution[i] = floor(randomGaussian(0, 15));\n }\n }\nfunction draw() {\n background(204);\n translate(width / 2, width / 2);\n for (let i = 0; i < distribution.length; i++) {\n rotate(TWO_PI / distribution.length);\n stroke(0);\n let dist = abs(distribution[i]);\n line(0, 0, dist, 0);\n }\n }\n \n
' + ], + alt: + '100 horizontal lines from center of canvas. height & side change each render\n black lines radiate from center of canvas. size determined each render', + class: 'p5', + module: 'Math', + submodule: 'Random' + }, + { + file: 'src/math/trigonometry.js', + line: 20, + description: + '

The inverse of cos(), returns the arc cosine of a value. This function\nexpects the values in the range of -1 to 1 and values are returned in\nthe range 0 to PI (3.1415927).

\n', + itemtype: 'method', + name: 'acos', + params: [ + { + name: 'value', + description: '

the value whose arc cosine is to be returned

\n', + type: 'Number' + } + ], + return: { + description: 'the arc cosine of the given value', + type: 'Number' + }, + example: [ + "\n
\n\nlet a = PI;\nlet c = cos(a);\nlet ac = acos(c);\n// Prints: \"3.1415927 : -1.0 : 3.1415927\"\nprint(a + ' : ' + c + ' : ' + ac);\n\n
\n\n
\n\nlet a = PI + PI / 4.0;\nlet c = cos(a);\nlet ac = acos(c);\n// Prints: \"3.926991 : -0.70710665 : 2.3561943\"\nprint(a + ' : ' + c + ' : ' + ac);\n\n
" + ], + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 54, + description: + '

The inverse of sin(), returns the arc sine of a value. This function\nexpects the values in the range of -1 to 1 and values are returned\nin the range -PI/2 to PI/2.

\n', + itemtype: 'method', + name: 'asin', + params: [ + { + name: 'value', + description: '

the value whose arc sine is to be returned

\n', + type: 'Number' + } + ], + return: { + description: 'the arc sine of the given value', + type: 'Number' + }, + example: [ + "\n
\n\nlet a = PI + PI / 3;\nlet s = sin(a);\nlet as = asin(s);\n// Prints: \"1.0471976 : 0.86602545 : 1.0471976\"\nprint(a + ' : ' + s + ' : ' + as);\n\n
\n\n
\n\nlet a = PI + PI / 3.0;\nlet s = sin(a);\nlet as = asin(s);\n// Prints: \"4.1887903 : -0.86602545 : -1.0471976\"\nprint(a + ' : ' + s + ' : ' + as);\n\n
\n" + ], + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 89, + description: + '

The inverse of tan(), returns the arc tangent of a value. This function\nexpects the values in the range of -Infinity to Infinity (exclusive) and\nvalues are returned in the range -PI/2 to PI/2.

\n', + itemtype: 'method', + name: 'atan', + params: [ + { + name: 'value', + description: '

the value whose arc tangent is to be returned

\n', + type: 'Number' + } + ], + return: { + description: 'the arc tangent of the given value', + type: 'Number' + }, + example: [ + "\n
\n\nlet a = PI + PI / 3;\nlet t = tan(a);\nlet at = atan(t);\n// Prints: \"1.0471976 : 1.7320509 : 1.0471976\"\nprint(a + ' : ' + t + ' : ' + at);\n\n
\n\n
\n\nlet a = PI + PI / 3.0;\nlet t = tan(a);\nlet at = atan(t);\n// Prints: \"4.1887903 : 1.7320513 : 1.0471977\"\nprint(a + ' : ' + t + ' : ' + at);\n\n
\n" + ], + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 124, + description: + '

Calculates the angle (in radians) from a specified point to the coordinate\norigin as measured from the positive x-axis. Values are returned as a\nfloat in the range from PI to -PI. The atan2() function is most often used\nfor orienting geometry to the position of the cursor.\n

\nNote: The y-coordinate of the point is the first parameter, and the\nx-coordinate is the second parameter, due the the structure of calculating\nthe tangent.

\n', + itemtype: 'method', + name: 'atan2', + params: [ + { + name: 'y', + description: '

y-coordinate of the point

\n', + type: 'Number' + }, + { + name: 'x', + description: '

x-coordinate of the point

\n', + type: 'Number' + } + ], + return: { + description: 'the arc tangent of the given point', + type: 'Number' + }, + example: [ + '\n
\n\nfunction draw() {\n background(204);\n translate(width / 2, height / 2);\n let a = atan2(mouseY - height / 2, mouseX - width / 2);\n rotate(a);\n rect(-30, -5, 60, 10);\n}\n\n
' + ], + alt: '60 by 10 rect at center of canvas rotates with mouse movements', + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 160, + description: + '

Calculates the cosine of an angle. This function takes into account the\ncurrent angleMode. Values are returned in the range -1 to 1.

\n', + itemtype: 'method', + name: 'cos', + params: [ + { + name: 'angle', + description: '

the angle

\n', + type: 'Number' + } + ], + return: { + description: 'the cosine of the angle', + type: 'Number' + }, + example: [ + '\n
\n\nlet a = 0.0;\nlet inc = TWO_PI / 25.0;\nfor (let i = 0; i < 25; i++) {\n line(i * 4, 50, i * 4, 50 + cos(a) * 40.0);\n a = a + inc;\n}\n\n
' + ], + alt: + 'vertical black lines form wave patterns, extend-down on left and right side', + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 188, + description: + '

Calculates the sine of an angle. This function takes into account the\ncurrent angleMode. Values are returned in the range -1 to 1.

\n', + itemtype: 'method', + name: 'sin', + params: [ + { + name: 'angle', + description: '

the angle

\n', + type: 'Number' + } + ], + return: { + description: 'the sine of the angle', + type: 'Number' + }, + example: [ + '\n
\n\nlet a = 0.0;\nlet inc = TWO_PI / 25.0;\nfor (let i = 0; i < 25; i++) {\n line(i * 4, 50, i * 4, 50 + sin(a) * 40.0);\n a = a + inc;\n}\n\n
' + ], + alt: + 'vertical black lines extend down and up from center to form wave pattern', + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 216, + description: + '

Calculates the tangent of an angle. This function takes into account\nthe current angleMode. Values are returned in the range -1 to 1.

\n', + itemtype: 'method', + name: 'tan', + params: [ + { + name: 'angle', + description: '

the angle

\n', + type: 'Number' + } + ], + return: { + description: 'the tangent of the angle', + type: 'Number' + }, + example: [ + '\n
\n\nlet a = 0.0;\nlet inc = TWO_PI / 50.0;\nfor (let i = 0; i < 100; i = i + 2) {\n line(i, 50, i, 50 + tan(a) * 2.0);\n a = a + inc;\n}\n' + ], + alt: + 'vertical black lines end down and up from center to form spike pattern', + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 244, + description: + '

Converts a radian measurement to its corresponding value in degrees.\nRadians and degrees are two ways of measuring the same thing. There are\n360 degrees in a circle and 2*PI radians in a circle. For example,\n90° = PI/2 = 1.5707964. This function does not take into account the\ncurrent angleMode.

\n', + itemtype: 'method', + name: 'degrees', + params: [ + { + name: 'radians', + description: '

the radians value to convert to degrees

\n', + type: 'Number' + } + ], + return: { + description: 'the converted angle', + type: 'Number' + }, + example: [ + "\n
\n\nlet rad = PI / 4;\nlet deg = degrees(rad);\nprint(rad + ' radians is ' + deg + ' degrees');\n// Prints: 0.7853981633974483 radians is 45 degrees\n\n
\n" + ], + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 271, + description: + '

Converts a degree measurement to its corresponding value in radians.\nRadians and degrees are two ways of measuring the same thing. There are\n360 degrees in a circle and 2*PI radians in a circle. For example,\n90° = PI/2 = 1.5707964. This function does not take into account the\ncurrent angleMode.

\n', + itemtype: 'method', + name: 'radians', + params: [ + { + name: 'degrees', + description: '

the degree value to convert to radians

\n', + type: 'Number' + } + ], + return: { + description: 'the converted angle', + type: 'Number' + }, + example: [ + "\n
\n\nlet deg = 45.0;\nlet rad = radians(deg);\nprint(deg + ' degrees is ' + rad + ' radians');\n// Prints: 45 degrees is 0.7853981633974483 radians\n\n
" + ], + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/math/trigonometry.js', + line: 296, + description: + '

Sets the current mode of p5 to given mode. Default mode is RADIANS.

\n', + itemtype: 'method', + name: 'angleMode', + params: [ + { + name: 'mode', + description: '

either RADIANS or DEGREES

\n', + type: 'Constant' + } + ], + example: [ + '\n
\n\nfunction draw() {\n background(204);\n angleMode(DEGREES); // Change the mode to DEGREES\n let a = atan2(mouseY - height / 2, mouseX - width / 2);\n translate(width / 2, height / 2);\n push();\n rotate(a);\n rect(-20, -5, 40, 10); // Larger rectangle is rotating in degrees\n pop();\n angleMode(RADIANS); // Change the mode to RADIANS\n rotate(a); // variable a stays the same\n rect(-40, -5, 20, 10); // Smaller rectangle is rotating in radians\n}\n\n
' + ], + alt: + '40 by 10 rect in center rotates with mouse moves. 20 by 10 rect moves faster.', + class: 'p5', + module: 'Math', + submodule: 'Trigonometry' + }, + { + file: 'src/typography/attributes.js', + line: 13, + description: + '

Sets the current alignment for drawing text. Accepts two\narguments: horizAlign (LEFT, CENTER, or RIGHT) and\nvertAlign (TOP, BOTTOM, CENTER, or BASELINE).

\n

The horizAlign parameter is in reference to the x value\nof the text() function, while the vertAlign parameter is\nin reference to the y value.

\n

So if you write textAlign(LEFT), you are aligning the left\nedge of your text to the x value you give in text(). If you\nwrite textAlign(RIGHT, TOP), you are aligning the right edge\nof your text to the x value and the top of edge of the text\nto the y value.

\n', + itemtype: 'method', + name: 'textAlign', + chainable: 1, + example: [ + "\n
\n\ntextSize(16);\ntextAlign(RIGHT);\ntext('ABCD', 50, 30);\ntextAlign(CENTER);\ntext('EFGH', 50, 50);\ntextAlign(LEFT);\ntext('IJKL', 50, 70);\n\n
\n\n
\n\ntextSize(16);\nstrokeWeight(0.5);\n\nline(0, 12, width, 12);\ntextAlign(CENTER, TOP);\ntext('TOP', 0, 12, width);\n\nline(0, 37, width, 37);\ntextAlign(CENTER, CENTER);\ntext('CENTER', 0, 37, width);\n\nline(0, 62, width, 62);\ntextAlign(CENTER, BASELINE);\ntext('BASELINE', 0, 62, width);\n\nline(0, 87, width, 87);\ntextAlign(CENTER, BOTTOM);\ntext('BOTTOM', 0, 87, width);\n\n
" + ], + alt: + "Letters ABCD displayed at top right, EFGH at center and IJKL at bottom left.\nThe names of the four vertical alignments rendered each showing that alignment's placement relative to a horizontal line.", + class: 'p5', + module: 'Typography', + submodule: 'Attributes', + overloads: [ + { + line: 13, + params: [ + { + name: 'horizAlign', + description: + '

horizontal alignment, either LEFT,\n CENTER, or RIGHT

\n', + type: 'Constant' + }, + { + name: 'vertAlign', + description: + '

vertical alignment, either TOP,\n BOTTOM, CENTER, or BASELINE

\n', + type: 'Constant', + optional: true + } + ], + chainable: 1 + }, + { + line: 75, + params: [], + return: { + description: '', + type: 'Object' + } + } + ] + }, + { + file: 'src/typography/attributes.js', + line: 84, + description: + '

Sets/gets the spacing, in pixels, between lines of text. This\nsetting will be used in all subsequent calls to the text() function.

\n', + itemtype: 'method', + name: 'textLeading', + chainable: 1, + example: [ + '\n
\n\n// Text to display. The "\\n" is a "new line" character\nlet lines = \'L1\\nL2\\nL3\';\ntextSize(12);\n\ntextLeading(10); // Set leading to 10\ntext(lines, 10, 25);\n\ntextLeading(20); // Set leading to 20\ntext(lines, 40, 25);\n\ntextLeading(30); // Set leading to 30\ntext(lines, 70, 25);\n\n
' + ], + alt: + 'set L1 L2 & L3 displayed vertically 3 times. spacing increases for each set', + class: 'p5', + module: 'Typography', + submodule: 'Attributes', + overloads: [ + { + line: 84, + params: [ + { + name: 'leading', + description: + '

the size in pixels for spacing between lines

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 113, + params: [], + return: { + description: '', + type: 'Number' + } + } + ] + }, + { + file: 'src/typography/attributes.js', + line: 122, + description: + '

Sets/gets the current font size. This size will be used in all subsequent\ncalls to the text() function. Font size is measured in pixels.

\n', + itemtype: 'method', + name: 'textSize', + chainable: 1, + example: [ + "\n
\n\ntextSize(12);\ntext('Font Size 12', 10, 30);\ntextSize(14);\ntext('Font Size 14', 10, 60);\ntextSize(16);\ntext('Font Size 16', 10, 90);\n\n
" + ], + alt: + 'Font Size 12 displayed small, Font Size 14 medium & Font Size 16 large', + class: 'p5', + module: 'Typography', + submodule: 'Attributes', + overloads: [ + { + line: 122, + params: [ + { + name: 'theSize', + description: '

the size of the letters in units of pixels

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 145, + params: [], + return: { + description: '', + type: 'Number' + } + } + ] + }, + { + file: 'src/typography/attributes.js', + line: 154, + description: + '

Sets/gets the style of the text for system fonts to NORMAL, ITALIC, BOLD or BOLDITALIC.\nNote: this may be is overridden by CSS styling. For non-system fonts\n(opentype, truetype, etc.) please load styled fonts instead.

\n', + itemtype: 'method', + name: 'textStyle', + chainable: 1, + example: [ + "\n
\n\nstrokeWeight(0);\ntextSize(12);\ntextStyle(NORMAL);\ntext('Font Style Normal', 10, 15);\ntextStyle(ITALIC);\ntext('Font Style Italic', 10, 40);\ntextStyle(BOLD);\ntext('Font Style Bold', 10, 65);\ntextStyle(BOLDITALIC);\ntext('Font Style Bold Italic', 10, 90);\n\n
" + ], + alt: + 'words Font Style Normal displayed normally, Italic in italic, bold in bold and bold italic in bold italics.', + class: 'p5', + module: 'Typography', + submodule: 'Attributes', + overloads: [ + { + line: 154, + params: [ + { + name: 'theStyle', + description: + '

styling for text, either NORMAL,\n ITALIC, BOLD or BOLDITALIC

\n', + type: 'Constant' + } + ], + chainable: 1 + }, + { + line: 182, + params: [], + return: { + description: '', + type: 'String' + } + } + ] + }, + { + file: 'src/typography/attributes.js', + line: 191, + description: + '

Calculates and returns the width of any character or text string.

\n', + itemtype: 'method', + name: 'textWidth', + params: [ + { + name: 'theText', + description: '

the String of characters to measure

\n', + type: 'String' + } + ], + return: { + description: '', + type: 'Number' + }, + example: [ + "\n
\n\ntextSize(28);\n\nlet aChar = 'P';\nlet cWidth = textWidth(aChar);\ntext(aChar, 0, 40);\nline(cWidth, 0, cWidth, 50);\n\nlet aString = 'p5.js';\nlet sWidth = textWidth(aString);\ntext(aString, 0, 85);\nline(sWidth, 50, sWidth, 100);\n\n
" + ], + alt: + 'Letter P and p5.js are displayed with vertical lines at end. P is wide', + class: 'p5', + module: 'Typography', + submodule: 'Attributes' + }, + { + file: 'src/typography/attributes.js', + line: 226, + description: + '

Returns the ascent of the current font at its current size. The ascent\nrepresents the distance, in pixels, of the tallest character above\nthe baseline.

\n', + itemtype: 'method', + name: 'textAscent', + return: { + description: '', + type: 'Number' + }, + example: [ + "\n
\n\nlet base = height * 0.75;\nlet scalar = 0.8; // Different for each font\n\ntextSize(32); // Set initial text size\nlet asc = textAscent() * scalar; // Calc ascent\nline(0, base - asc, width, base - asc);\ntext('dp', 0, base); // Draw text on baseline\n\ntextSize(64); // Increase text size\nasc = textAscent() * scalar; // Recalc ascent\nline(40, base - asc, width, base - asc);\ntext('dp', 40, base); // Draw text on baseline\n\n
" + ], + class: 'p5', + module: 'Typography', + submodule: 'Attributes' + }, + { + file: 'src/typography/attributes.js', + line: 255, + description: + '

Returns the descent of the current font at its current size. The descent\nrepresents the distance, in pixels, of the character with the longest\ndescender below the baseline.

\n', + itemtype: 'method', + name: 'textDescent', + return: { + description: '', + type: 'Number' + }, + example: [ + "\n
\n\nlet base = height * 0.75;\nlet scalar = 0.8; // Different for each font\n\ntextSize(32); // Set initial text size\nlet desc = textDescent() * scalar; // Calc ascent\nline(0, base + desc, width, base + desc);\ntext('dp', 0, base); // Draw text on baseline\n\ntextSize(64); // Increase text size\ndesc = textDescent() * scalar; // Recalc ascent\nline(40, base + desc, width, base + desc);\ntext('dp', 40, base); // Draw text on baseline\n\n
" + ], + class: 'p5', + module: 'Typography', + submodule: 'Attributes' + }, + { + file: 'src/typography/attributes.js', + line: 284, + description: '

Helper function to measure ascent and descent.

\n', + class: 'p5', + module: 'Typography', + submodule: 'Attributes' + }, + { + file: 'src/typography/loading_displaying.js', + line: 16, + description: + '

Loads an opentype font file (.otf, .ttf) from a file or a URL,\nand returns a PFont Object. This method is asynchronous,\nmeaning it may not finish before the next line in your sketch\nis executed.\n

\nThe path to the font should be relative to the HTML file\nthat links in your sketch. Loading fonts from a URL or other\nremote location may be blocked due to your browser's built-in\nsecurity.

\n', + itemtype: 'method', + name: 'loadFont', + params: [ + { + name: 'path', + description: '

name of the file or url to load

\n', + type: 'String' + }, + { + name: 'callback', + description: + '

function to be executed after\n loadFont() completes

\n', + type: 'Function', + optional: true + }, + { + name: 'onError', + description: + '

function to be executed if\n an error occurs

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'p5.Font object', + type: 'p5.Font' + }, + example: [ + "\n\n

Calling loadFont() inside preload() guarantees that the load\noperation will have completed before setup() and draw() are called.

\n\n
\nlet myFont;\nfunction preload() {\n myFont = loadFont('assets/inconsolata.otf');\n}\n\nfunction setup() {\n fill('#ED225D');\n textFont(myFont);\n textSize(36);\n text('p5*js', 10, 50);\n}\n
\n\nOutside of preload(), you may supply a callback function to handle the\nobject:\n\n
\nfunction setup() {\n loadFont('assets/inconsolata.otf', drawText);\n}\n\nfunction drawText(font) {\n fill('#ED225D');\n textFont(font, 36);\n text('p5*js', 10, 50);\n}\n
\n\n

You can also use the font filename string (without the file extension) to style other HTML\nelements.

\n\n
\nfunction preload() {\n loadFont('assets/inconsolata.otf');\n}\n\nfunction setup() {\n let myDiv = createDiv('hello there');\n myDiv.style('font-family', 'Inconsolata');\n}\n
" + ], + alt: "p5*js in p5's theme dark pink\np5*js in p5's theme dark pink", + class: 'p5', + module: 'Typography', + submodule: 'Loading & Displaying' + }, + { + file: 'src/typography/loading_displaying.js', + line: 143, + description: + '

Draws text to the screen. Displays the information specified in the first\nparameter on the screen in the position specified by the additional\nparameters. A default font will be used unless a font is set with the\ntextFont() function and a default size will be used unless a font is set\nwith textSize(). Change the color of the text with the fill() function.\nChange the outline of the text with the stroke() and strokeWeight()\nfunctions.\n

\nThe text displays in relation to the textAlign() function, which gives the\noption to draw to the left, right, and center of the coordinates.\n

\nThe x2 and y2 parameters define a rectangular area to display within and\nmay only be used with string data. When these parameters are specified,\nthey are interpreted based on the current rectMode() setting. Text that\ndoes not fit completely within the rectangle specified will not be drawn\nto the screen. If x2 and y2 are not specified, the baseline alignment is the\ndefault, which means that the text will be drawn upwards from x and y.\n

\nWEBGL: Only opentype/truetype fonts are supported. You must load a font using the\nloadFont() method (see the example above).\nstroke() currently has no effect in webgl mode.

\n', + itemtype: 'method', + name: 'text', + params: [ + { + name: 'str', + description: + '

the alphanumeric\n symbols to be displayed

\n', + type: 'String|Object|Array|Number|Boolean' + }, + { + name: 'x', + description: '

x-coordinate of text

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-coordinate of text

\n', + type: 'Number' + }, + { + name: 'x2', + description: + '

by default, the width of the text box,\n see rectMode() for more info

\n', + type: 'Number', + optional: true + }, + { + name: 'y2', + description: + '

by default, the height of the text box,\n see rectMode() for more info

\n', + type: 'Number', + optional: true + } + ], + chainable: 1, + example: [ + "\n
\n\ntextSize(32);\ntext('word', 10, 30);\nfill(0, 102, 153);\ntext('word', 10, 60);\nfill(0, 102, 153, 51);\ntext('word', 10, 90);\n\n
\n
\n\nlet s = 'The quick brown fox jumped over the lazy dog.';\nfill(50);\ntext(s, 10, 10, 70, 80); // Text wraps within text box\n\n
\n\n
\n\nlet inconsolata;\nfunction preload() {\n inconsolata = loadFont('assets/inconsolata.otf');\n}\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n textFont(inconsolata);\n textSize(width / 3);\n textAlign(CENTER, CENTER);\n}\nfunction draw() {\n background(0);\n let time = millis();\n rotateX(time / 1000);\n rotateZ(time / 1234);\n text('p5.js', 0, 0);\n}\n\n
" + ], + alt: + "'word' displayed 3 times going from black, blue to translucent blue\nThe quick brown fox jumped over the lazy dog.\nthe text 'p5.js' spinning in 3d", + class: 'p5', + module: 'Typography', + submodule: 'Loading & Displaying' + }, + { + file: 'src/typography/loading_displaying.js', + line: 230, + description: + '

Sets the current font that will be drawn with the text() function.\n

\nWEBGL: Only fonts loaded via loadFont() are supported.

\n', + itemtype: 'method', + name: 'textFont', + return: { + description: 'the current font', + type: 'Object' + }, + example: [ + "\n
\n\nfill(0);\ntextSize(12);\ntextFont('Georgia');\ntext('Georgia', 12, 30);\ntextFont('Helvetica');\ntext('Helvetica', 12, 60);\n\n
\n
\n\nlet fontRegular, fontItalic, fontBold;\nfunction preload() {\n fontRegular = loadFont('assets/Regular.otf');\n fontItalic = loadFont('assets/Italic.ttf');\n fontBold = loadFont('assets/Bold.ttf');\n}\nfunction setup() {\n background(210);\n fill(0)\n .strokeWeight(0)\n .textSize(10);\n textFont(fontRegular);\n text('Font Style Normal', 10, 30);\n textFont(fontItalic);\n text('Font Style Italic', 10, 50);\n textFont(fontBold);\n text('Font Style Bold', 10, 70);\n}\n\n
" + ], + alt: + 'words Font Style Normal displayed normally, Italic in italic and bold in bold', + class: 'p5', + module: 'Typography', + submodule: 'Loading & Displaying', + overloads: [ + { + line: 230, + params: [], + return: { + description: 'the current font', + type: 'Object' + } + }, + { + line: 275, + params: [ + { + name: 'font', + description: + '

a font loaded via loadFont(), or a String\nrepresenting a web safe font (a font\nthat is generally available across all systems)

\n', + type: 'Object|String' + }, + { + name: 'size', + description: '

the font size to use

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/typography/p5.Font.js', + line: 25, + description: '

Underlying opentype font implementation

\n', + itemtype: 'property', + name: 'font', + class: 'p5.Font', + module: 'Typography', + submodule: 'Font' + }, + { + file: 'src/typography/p5.Font.js', + line: 32, + description: + '

Returns a tight bounding box for the given text string using this\nfont (currently only supports single lines)

\n', + itemtype: 'method', + name: 'textBounds', + params: [ + { + name: 'line', + description: '

a line of text

\n', + type: 'String' + }, + { + name: 'x', + description: '

x-position

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-position

\n', + type: 'Number' + }, + { + name: 'fontSize', + description: '

font size to use (optional) Default is 12.

\n', + type: 'Number', + optional: true + }, + { + name: 'options', + description: + '

opentype options (optional)\n opentype fonts contains alignment and baseline options.\n Default is 'LEFT' and 'alphabetic'

\n', + type: 'Object', + optional: true + } + ], + return: { + description: 'a rectangle object with properties: x, y, w, h', + type: 'Object' + }, + example: [ + "\n
\n\nlet font;\nlet textString = 'Lorem ipsum dolor sit amet.';\nfunction preload() {\n font = loadFont('./assets/Regular.otf');\n}\nfunction setup() {\n background(210);\n\n let bbox = font.textBounds(textString, 10, 30, 12);\n fill(255);\n stroke(0);\n rect(bbox.x, bbox.y, bbox.w, bbox.h);\n fill(0);\n noStroke();\n\n textFont(font);\n textSize(12);\n text(textString, 10, 30);\n}\n\n
" + ], + alt: + 'words Lorem ipsum dol go off canvas and contained by white bounding box', + class: 'p5.Font', + module: 'Typography', + submodule: 'Font' + }, + { + file: 'src/typography/p5.Font.js', + line: 156, + description: + '

Computes an array of points following the path for specified text

\n', + itemtype: 'method', + name: 'textToPoints', + params: [ + { + name: 'txt', + description: '

a line of text

\n', + type: 'String' + }, + { + name: 'x', + description: '

x-position

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y-position

\n', + type: 'Number' + }, + { + name: 'fontSize', + description: '

font size to use (optional)

\n', + type: 'Number' + }, + { + name: 'options', + description: + '

an (optional) object that can contain:

\n


sampleFactor - the ratio of path-length to number of samples\n(default=.1); higher values yield more points and are therefore\nmore precise

\n


simplifyThreshold - if set to a non-zero value, collinear points will be\nbe removed from the polygon; the value represents the threshold angle to use\nwhen determining whether two edges are collinear

\n', + type: 'Object', + optional: true + } + ], + return: { + description: 'an array of points, each with x, y, alpha (the path angle)', + type: 'Array' + }, + example: [ + "\n
\n\nlet font;\nfunction preload() {\n font = loadFont('assets/inconsolata.otf');\n}\n\nlet points;\nlet bounds;\nfunction setup() {\n createCanvas(100, 100);\n stroke(0);\n fill(255, 104, 204);\n\n points = font.textToPoints('p5', 0, 0, 10, {\n sampleFactor: 5,\n simplifyThreshold: 0\n });\n bounds = font.textBounds(' p5 ', 0, 0, 10);\n}\n\nfunction draw() {\n background(255);\n beginShape();\n translate(-bounds.x * width / bounds.w, -bounds.y * height / bounds.h);\n for (let i = 0; i < points.length; i++) {\n let p = points[i];\n vertex(\n p.x * width / bounds.w +\n sin(20 * p.y / bounds.h + millis() / 1000) * width / 30,\n p.y * height / bounds.h\n );\n }\n endShape(CLOSE);\n}\n\n
\n" + ], + class: 'p5.Font', + module: 'Typography', + submodule: 'Font' + }, + { + file: 'src/utilities/array_functions.js', + line: 12, + description: + '

Adds a value to the end of an array. Extends the length of\nthe array by one. Maps to Array.push().

\n', + itemtype: 'method', + name: 'append', + deprecated: true, + deprecationMessage: + 'Use array.push(value) instead.', + params: [ + { + name: 'array', + description: '

Array to append

\n', + type: 'Array' + }, + { + name: 'value', + description: '

to be added to the Array

\n', + type: 'Any' + } + ], + return: { + description: 'the array that was appended to', + type: 'Array' + }, + example: [ + "\n
\nfunction setup() {\n var myArray = ['Mango', 'Apple', 'Papaya'];\n print(myArray); // ['Mango', 'Apple', 'Papaya']\n\n append(myArray, 'Peach');\n print(myArray); // ['Mango', 'Apple', 'Papaya', 'Peach']\n}\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions' + }, + { + file: 'src/utilities/array_functions.js', + line: 37, + description: + '

Copies an array (or part of an array) to another array. The src array is\ncopied to the dst array, beginning at the position specified by\nsrcPosition and into the position specified by dstPosition. The number of\nelements to copy is determined by length. Note that copying values\noverwrites existing values in the destination array. To append values\ninstead of overwriting them, use concat().\n

\nThe simplified version with only two arguments, arrayCopy(src, dst),\ncopies an entire array to another of the same size. It is equivalent to\narrayCopy(src, 0, dst, 0, src.length).\n

\nUsing this function is far more efficient for copying array data than\niterating through a for() loop and copying each element individually.

\n', + itemtype: 'method', + name: 'arrayCopy', + deprecated: true, + example: [ + "\n
\nvar src = ['A', 'B', 'C'];\nvar dst = [1, 2, 3];\nvar srcPosition = 1;\nvar dstPosition = 0;\nvar length = 2;\n\nprint(src); // ['A', 'B', 'C']\nprint(dst); // [ 1 , 2 , 3 ]\n\narrayCopy(src, srcPosition, dst, dstPosition, length);\nprint(dst); // ['B', 'C', 3]\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions', + overloads: [ + { + line: 37, + params: [ + { + name: 'src', + description: '

the source Array

\n', + type: 'Array' + }, + { + name: 'srcPosition', + description: '

starting position in the source Array

\n', + type: 'Integer' + }, + { + name: 'dst', + description: '

the destination Array

\n', + type: 'Array' + }, + { + name: 'dstPosition', + description: '

starting position in the destination Array

\n', + type: 'Integer' + }, + { + name: 'length', + description: '

number of Array elements to be copied

\n', + type: 'Integer' + } + ] + }, + { + line: 75, + params: [ + { + name: 'src', + description: '', + type: 'Array' + }, + { + name: 'dst', + description: '', + type: 'Array' + }, + { + name: 'length', + description: '', + type: 'Integer', + optional: true + } + ] + } + ] + }, + { + file: 'src/utilities/array_functions.js', + line: 114, + description: + '

Concatenates two arrays, maps to Array.concat(). Does not modify the\ninput arrays.

\n', + itemtype: 'method', + name: 'concat', + deprecated: true, + deprecationMessage: + 'Use arr1.concat(arr2) instead.', + params: [ + { + name: 'a', + description: '

first Array to concatenate

\n', + type: 'Array' + }, + { + name: 'b', + description: '

second Array to concatenate

\n', + type: 'Array' + } + ], + return: { + description: 'concatenated array', + type: 'Array' + }, + example: [ + "\n
\nfunction setup() {\n var arr1 = ['A', 'B', 'C'];\n var arr2 = [1, 2, 3];\n\n print(arr1); // ['A','B','C']\n print(arr2); // [1,2,3]\n\n var arr3 = concat(arr1, arr2);\n\n print(arr1); // ['A','B','C']\n print(arr2); // [1, 2, 3]\n print(arr3); // ['A','B','C', 1, 2, 3]\n}\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions' + }, + { + file: 'src/utilities/array_functions.js', + line: 145, + description: + '

Reverses the order of an array, maps to Array.reverse()

\n', + itemtype: 'method', + name: 'reverse', + deprecated: true, + deprecationMessage: + 'Use array.reverse() instead.', + params: [ + { + name: 'list', + description: '

Array to reverse

\n', + type: 'Array' + } + ], + return: { + description: 'the reversed list', + type: 'Array' + }, + example: [ + "\n
\nfunction setup() {\n var myArray = ['A', 'B', 'C'];\n print(myArray); // ['A','B','C']\n\n reverse(myArray);\n print(myArray); // ['C','B','A']\n}\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions' + }, + { + file: 'src/utilities/array_functions.js', + line: 167, + description: + '

Decreases an array by one element and returns the shortened array,\nmaps to Array.pop().

\n', + itemtype: 'method', + name: 'shorten', + deprecated: true, + deprecationMessage: + 'Use array.pop() instead.', + params: [ + { + name: 'list', + description: '

Array to shorten

\n', + type: 'Array' + } + ], + return: { + description: 'shortened Array', + type: 'Array' + }, + example: [ + "\n
\nfunction setup() {\n var myArray = ['A', 'B', 'C'];\n print(myArray); // ['A', 'B', 'C']\n var newArray = shorten(myArray);\n print(myArray); // ['A','B','C']\n print(newArray); // ['A','B']\n}\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions' + }, + { + file: 'src/utilities/array_functions.js', + line: 191, + description: + "

Randomizes the order of the elements of an array. Implements\n\nFisher-Yates Shuffle Algorithm.

\n", + itemtype: 'method', + name: 'shuffle', + params: [ + { + name: 'array', + description: '

Array to shuffle

\n', + type: 'Array' + }, + { + name: 'bool', + description: '

modify passed array

\n', + type: 'Boolean', + optional: true + } + ], + return: { + description: 'shuffled Array', + type: 'Array' + }, + example: [ + "\n
\nfunction setup() {\n var regularArr = ['ABC', 'def', createVector(), TAU, Math.E];\n print(regularArr);\n shuffle(regularArr, true); // force modifications to passed array\n print(regularArr);\n\n // By default shuffle() returns a shuffled cloned array:\n var newArr = shuffle(regularArr);\n print(regularArr);\n print(newArr);\n}\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions' + }, + { + file: 'src/utilities/array_functions.js', + line: 233, + description: + '

Sorts an array of numbers from smallest to largest, or puts an array of\nwords in alphabetical order. The original array is not modified; a\nre-ordered array is returned. The count parameter states the number of\nelements to sort. For example, if there are 12 elements in an array and\ncount is set to 5, only the first 5 elements in the array will be sorted.

\n', + itemtype: 'method', + name: 'sort', + deprecated: true, + deprecationMessage: + 'Use array.sort() instead.', + params: [ + { + name: 'list', + description: '

Array to sort

\n', + type: 'Array' + }, + { + name: 'count', + description: '

number of elements to sort, starting from 0

\n', + type: 'Integer', + optional: true + } + ], + return: { + description: 'the sorted list', + type: 'Array' + }, + example: [ + "\n
\nfunction setup() {\n var words = ['banana', 'apple', 'pear', 'lime'];\n print(words); // ['banana', 'apple', 'pear', 'lime']\n var count = 4; // length of array\n\n words = sort(words, count);\n print(words); // ['apple', 'banana', 'lime', 'pear']\n}\n
\n
\nfunction setup() {\n var numbers = [2, 6, 1, 5, 14, 9, 8, 12];\n print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12]\n var count = 5; // Less than the length of the array\n\n numbers = sort(numbers, count);\n print(numbers); // [1,2,5,6,14,9,8,12]\n}\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions' + }, + { + file: 'src/utilities/array_functions.js', + line: 281, + description: + '

Inserts a value or an array of values into an existing array. The first\nparameter specifies the initial array to be modified, and the second\nparameter defines the data to be inserted. The third parameter is an index\nvalue which specifies the array position from which to insert data.\n(Remember that array index numbering starts at zero, so the first position\nis 0, the second position is 1, and so on.)

\n', + itemtype: 'method', + name: 'splice', + deprecated: true, + deprecationMessage: + 'Use array.splice() instead.', + params: [ + { + name: 'list', + description: '

Array to splice into

\n', + type: 'Array' + }, + { + name: 'value', + description: '

value to be spliced in

\n', + type: 'Any' + }, + { + name: 'position', + description: '

in the array from which to insert data

\n', + type: 'Integer' + } + ], + return: { + description: 'the list', + type: 'Array' + }, + example: [ + "\n
\nfunction setup() {\n var myArray = [0, 1, 2, 3, 4];\n var insArray = ['A', 'B', 'C'];\n print(myArray); // [0, 1, 2, 3, 4]\n print(insArray); // ['A','B','C']\n\n splice(myArray, insArray, 3);\n print(myArray); // [0,1,2,'A','B','C',3,4]\n}\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions' + }, + { + file: 'src/utilities/array_functions.js', + line: 316, + description: + '

Extracts an array of elements from an existing array. The list parameter\ndefines the array from which the elements will be copied, and the start\nand count parameters specify which elements to extract. If no count is\ngiven, elements will be extracted from the start to the end of the array.\nWhen specifying the start, remember that the first array element is 0.\nThis function does not change the source array.

\n', + itemtype: 'method', + name: 'subset', + deprecated: true, + deprecationMessage: + 'Use array.slice() instead.', + params: [ + { + name: 'list', + description: '

Array to extract from

\n', + type: 'Array' + }, + { + name: 'start', + description: '

position to begin

\n', + type: 'Integer' + }, + { + name: 'count', + description: '

number of values to extract

\n', + type: 'Integer', + optional: true + } + ], + return: { + description: 'Array of extracted elements', + type: 'Array' + }, + example: [ + "\n
\nfunction setup() {\n var myArray = [1, 2, 3, 4, 5];\n print(myArray); // [1, 2, 3, 4, 5]\n\n var sub1 = subset(myArray, 0, 3);\n var sub2 = subset(myArray, 2, 2);\n print(sub1); // [1,2,3]\n print(sub2); // [3,4]\n}\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Array Functions' + }, + { + file: 'src/utilities/conversion.js', + line: 12, + description: + '

Converts a string to its floating point representation. The contents of a\nstring must resemble a number, or NaN (not a number) will be returned.\nFor example, float("1234.56") evaluates to 1234.56, but float("giraffe")\nwill return NaN.

\n

When an array of values is passed in, then an array of floats of the same\nlength is returned.

\n', + itemtype: 'method', + name: 'float', + params: [ + { + name: 'str', + description: '

float string to parse

\n', + type: 'String' + } + ], + return: { + description: 'floating point representation of string', + type: 'Number' + }, + example: [ + "\n
\nvar str = '20';\nvar diameter = float(str);\nellipse(width / 2, height / 2, diameter, diameter);\n
\n
\nprint(float('10.31')); // 10.31\nprint(float('Infinity')); // Infinity\nprint(float('-Infinity')); // -Infinity\n
" + ], + alt: '20 by 20 white ellipse in the center of the canvas', + class: 'p5', + module: 'Data', + submodule: 'Conversion' + }, + { + file: 'src/utilities/conversion.js', + line: 47, + description: + '

Converts a boolean, string, or float to its integer representation.\nWhen an array of values is passed in, then an int array of the same length\nis returned.

\n', + itemtype: 'method', + name: 'int', + return: { + description: 'integer representation of value', + type: 'Number' + }, + example: [ + "\n
\nprint(int('10')); // 10\nprint(int(10.31)); // 10\nprint(int(-10)); // -10\nprint(int(true)); // 1\nprint(int(false)); // 0\nprint(int([false, true, '10.3', 9.8])); // [0, 1, 10, 9]\nprint(int(Infinity)); // Infinity\nprint(int('-Infinity')); // -Infinity\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Conversion', + overloads: [ + { + line: 47, + params: [ + { + name: 'n', + description: '

value to parse

\n', + type: 'String|Boolean|Number' + }, + { + name: 'radix', + description: '

the radix to convert to (default: 10)

\n', + type: 'Integer', + optional: true + } + ], + return: { + description: 'integer representation of value', + type: 'Number' + } + }, + { + line: 69, + params: [ + { + name: 'ns', + description: '

values to parse

\n', + type: 'Array' + } + ], + return: { + description: 'integer representation of values', + type: 'Number[]' + } + } + ] + }, + { + file: 'src/utilities/conversion.js', + line: 93, + description: + '

Converts a boolean, string or number to its string representation.\nWhen an array of values is passed in, then an array of strings of the same\nlength is returned.

\n', + itemtype: 'method', + name: 'str', + params: [ + { + name: 'n', + description: '

value to parse

\n', + type: 'String|Boolean|Number|Array' + } + ], + return: { + description: 'string representation of value', + type: 'String' + }, + example: [ + '\n
\nprint(str(\'10\')); // "10"\nprint(str(10.31)); // "10.31"\nprint(str(-10)); // "-10"\nprint(str(true)); // "true"\nprint(str(false)); // "false"\nprint(str([true, \'10.3\', 9.8])); // [ "true", "10.3", "9.8" ]\n
' + ], + class: 'p5', + module: 'Data', + submodule: 'Conversion' + }, + { + file: 'src/utilities/conversion.js', + line: 119, + description: + '

Converts a number or string to its boolean representation.\nFor a number, any non-zero value (positive or negative) evaluates to true,\nwhile zero evaluates to false. For a string, the value "true" evaluates to\ntrue, while any other value evaluates to false. When an array of number or\nstring values is passed in, then a array of booleans of the same length is\nreturned.

\n', + itemtype: 'method', + name: 'boolean', + params: [ + { + name: 'n', + description: '

value to parse

\n', + type: 'String|Boolean|Number|Array' + } + ], + return: { + description: 'boolean representation of value', + type: 'Boolean' + }, + example: [ + "\n
\nprint(boolean(0)); // false\nprint(boolean(1)); // true\nprint(boolean('true')); // true\nprint(boolean('abcd')); // false\nprint(boolean([0, 12, 'true'])); // [false, true, true]\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Conversion' + }, + { + file: 'src/utilities/conversion.js', + line: 151, + description: + '

Converts a number, string representation of a number, or boolean to its byte\nrepresentation. A byte can be only a whole number between -128 and 127, so\nwhen a value outside of this range is converted, it wraps around to the\ncorresponding byte representation. When an array of number, string or boolean\nvalues is passed in, then an array of bytes the same length is returned.

\n', + itemtype: 'method', + name: 'byte', + return: { + description: 'byte representation of value', + type: 'Number' + }, + example: [ + "\n
\nprint(byte(127)); // 127\nprint(byte(128)); // -128\nprint(byte(23.4)); // 23\nprint(byte('23.4')); // 23\nprint(byte('hello')); // NaN\nprint(byte(true)); // 1\nprint(byte([0, 255, '100'])); // [0, -1, 100]\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Conversion', + overloads: [ + { + line: 151, + params: [ + { + name: 'n', + description: '

value to parse

\n', + type: 'String|Boolean|Number' + } + ], + return: { + description: 'byte representation of value', + type: 'Number' + } + }, + { + line: 173, + params: [ + { + name: 'ns', + description: '

values to parse

\n', + type: 'Array' + } + ], + return: { + description: 'array of byte representation of values', + type: 'Number[]' + } + } + ] + }, + { + file: 'src/utilities/conversion.js', + line: 187, + description: + '

Converts a number or string to its corresponding single-character\nstring representation. If a string parameter is provided, it is first\nparsed as an integer and then translated into a single-character string.\nWhen an array of number or string values is passed in, then an array of\nsingle-character strings of the same length is returned.

\n', + itemtype: 'method', + name: 'char', + return: { + description: 'string representation of value', + type: 'String' + }, + example: [ + '\n
\nprint(char(65)); // "A"\nprint(char(\'65\')); // "A"\nprint(char([65, 66, 67])); // [ "A", "B", "C" ]\nprint(join(char([65, 66, 67]), \'\')); // "ABC"\n
' + ], + class: 'p5', + module: 'Data', + submodule: 'Conversion', + overloads: [ + { + line: 187, + params: [ + { + name: 'n', + description: '

value to parse

\n', + type: 'String|Number' + } + ], + return: { + description: 'string representation of value', + type: 'String' + } + }, + { + line: 206, + params: [ + { + name: 'ns', + description: '

values to parse

\n', + type: 'Array' + } + ], + return: { + description: 'array of string representation of values', + type: 'String[]' + } + } + ] + }, + { + file: 'src/utilities/conversion.js', + line: 221, + description: + '

Converts a single-character string to its corresponding integer\nrepresentation. When an array of single-character string values is passed\nin, then an array of integers of the same length is returned.

\n', + itemtype: 'method', + name: 'unchar', + return: { + description: 'integer representation of value', + type: 'Number' + }, + example: [ + "\n
\nprint(unchar('A')); // 65\nprint(unchar(['A', 'B', 'C'])); // [ 65, 66, 67 ]\nprint(unchar(split('ABC', ''))); // [ 65, 66, 67 ]\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Conversion', + overloads: [ + { + line: 221, + params: [ + { + name: 'n', + description: '

value to parse

\n', + type: 'String' + } + ], + return: { + description: 'integer representation of value', + type: 'Number' + } + }, + { + line: 237, + params: [ + { + name: 'ns', + description: '

values to parse

\n', + type: 'Array' + } + ], + return: { + description: 'integer representation of values', + type: 'Number[]' + } + } + ] + }, + { + file: 'src/utilities/conversion.js', + line: 250, + description: + '

Converts a number to a string in its equivalent hexadecimal notation. If a\nsecond parameter is passed, it is used to set the number of characters to\ngenerate in the hexadecimal notation. When an array is passed in, an\narray of strings in hexadecimal notation of the same length is returned.

\n', + itemtype: 'method', + name: 'hex', + return: { + description: 'hexadecimal string representation of value', + type: 'String' + }, + example: [ + '\n
\nprint(hex(255)); // "000000FF"\nprint(hex(255, 6)); // "0000FF"\nprint(hex([0, 127, 255], 6)); // [ "000000", "00007F", "0000FF" ]\nprint(Infinity); // "FFFFFFFF"\nprint(-Infinity); // "00000000"\n
' + ], + class: 'p5', + module: 'Data', + submodule: 'Conversion', + overloads: [ + { + line: 250, + params: [ + { + name: 'n', + description: '

value to parse

\n', + type: 'Number' + }, + { + name: 'digits', + description: '', + type: 'Number', + optional: true + } + ], + return: { + description: 'hexadecimal string representation of value', + type: 'String' + } + }, + { + line: 270, + params: [ + { + name: 'ns', + description: '

array of values to parse

\n', + type: 'Number[]' + }, + { + name: 'digits', + description: '', + type: 'Number', + optional: true + } + ], + return: { + description: 'hexadecimal string representation of values', + type: 'String[]' + } + } + ] + }, + { + file: 'src/utilities/conversion.js', + line: 302, + description: + '

Converts a string representation of a hexadecimal number to its equivalent\ninteger value. When an array of strings in hexadecimal notation is passed\nin, an array of integers of the same length is returned.

\n', + itemtype: 'method', + name: 'unhex', + return: { + description: 'integer representation of hexadecimal value', + type: 'Number' + }, + example: [ + "\n
\nprint(unhex('A')); // 10\nprint(unhex('FF')); // 255\nprint(unhex(['FF', 'AA', '00'])); // [ 255, 170, 0 ]\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'Conversion', + overloads: [ + { + line: 302, + params: [ + { + name: 'n', + description: '

value to parse

\n', + type: 'String' + } + ], + return: { + description: 'integer representation of hexadecimal value', + type: 'Number' + } + }, + { + line: 318, + params: [ + { + name: 'ns', + description: '

values to parse

\n', + type: 'Array' + } + ], + return: { + description: 'integer representations of hexadecimal value', + type: 'Number[]' + } + } + ] + }, + { + file: 'src/utilities/string_functions.js', + line: 15, + description: + '

Combines an array of Strings into one String, each separated by the\ncharacter(s) used for the separator parameter. To join arrays of ints or\nfloats, it's necessary to first convert them to Strings using nf() or\nnfs().

\n', + itemtype: 'method', + name: 'join', + params: [ + { + name: 'list', + description: '

array of Strings to be joined

\n', + type: 'Array' + }, + { + name: 'separator', + description: '

String to be placed between each item

\n', + type: 'String' + } + ], + return: { + description: 'joined String', + type: 'String' + }, + example: [ + "\n
\n\nvar array = ['Hello', 'world!'];\nvar separator = ' ';\nvar message = join(array, separator);\ntext(message, 5, 50);\n\n
" + ], + alt: '"hello world!" displayed middle left of canvas.', + class: 'p5', + module: 'Data', + submodule: 'String Functions' + }, + { + file: 'src/utilities/string_functions.js', + line: 44, + description: + '

This function is used to apply a regular expression to a piece of text,\nand return matching groups (elements found inside parentheses) as a\nString array. If there are no matches, a null value will be returned.\nIf no groups are specified in the regular expression, but the sequence\nmatches, an array of length 1 (with the matched text as the first element\nof the array) will be returned.\n

\nTo use the function, first check to see if the result is null. If the\nresult is null, then the sequence did not match at all. If the sequence\ndid match, an array is returned.\n

\nIf there are groups (specified by sets of parentheses) in the regular\nexpression, then the contents of each will be returned in the array.\nElement [0] of a regular expression match returns the entire matching\nstring, and the match groups start at element [1] (the first group is [1],\nthe second [2], and so on).

\n', + itemtype: 'method', + name: 'match', + params: [ + { + name: 'str', + description: '

the String to be searched

\n', + type: 'String' + }, + { + name: 'regexp', + description: '

the regexp to be used for matching

\n', + type: 'String' + } + ], + return: { + description: 'Array of Strings found', + type: 'String[]' + }, + example: [ + "\n
\n\nvar string = 'Hello p5js*!';\nvar regexp = 'p5js\\\\*';\nvar m = match(string, regexp);\ntext(m, 5, 50);\n\n
" + ], + alt: '"p5js*" displayed middle left of canvas.', + class: 'p5', + module: 'Data', + submodule: 'String Functions' + }, + { + file: 'src/utilities/string_functions.js', + line: 85, + description: + '

This function is used to apply a regular expression to a piece of text,\nand return a list of matching groups (elements found inside parentheses)\nas a two-dimensional String array. If there are no matches, a null value\nwill be returned. If no groups are specified in the regular expression,\nbut the sequence matches, a two dimensional array is still returned, but\nthe second dimension is only of length one.\n

\nTo use the function, first check to see if the result is null. If the\nresult is null, then the sequence did not match at all. If the sequence\ndid match, a 2D array is returned.\n

\nIf there are groups (specified by sets of parentheses) in the regular\nexpression, then the contents of each will be returned in the array.\nAssuming a loop with counter variable i, element [i][0] of a regular\nexpression match returns the entire matching string, and the match groups\nstart at element [i][1] (the first group is [i][1], the second [i][2],\nand so on).

\n', + itemtype: 'method', + name: 'matchAll', + params: [ + { + name: 'str', + description: '

the String to be searched

\n', + type: 'String' + }, + { + name: 'regexp', + description: '

the regexp to be used for matching

\n', + type: 'String' + } + ], + return: { + description: '2d Array of Strings found', + type: 'String[]' + }, + example: [ + "\n
\n\nvar string = 'Hello p5js*! Hello world!';\nvar regexp = 'Hello';\nmatchAll(string, regexp);\n\n
" + ], + class: 'p5', + module: 'Data', + submodule: 'String Functions' + }, + { + file: 'src/utilities/string_functions.js', + line: 132, + description: + '

Utility function for formatting numbers into strings. There are two\nversions: one for formatting floats, and one for formatting ints.\nThe values for the digits, left, and right parameters should always\nbe positive integers.\n(NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter\nif greater than the current length of the number.\nFor example if number is 123.2 and left parameter passed is 4 which is greater than length of 123\n(integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than\nthe result will be 123.200.

\n', + itemtype: 'method', + name: 'nf', + return: { + description: 'formatted String', + type: 'String' + }, + example: [ + "\n
\n\nvar myFont;\nfunction preload() {\n myFont = loadFont('assets/fonts/inconsolata.ttf');\n}\nfunction setup() {\n background(200);\n var num1 = 321;\n var num2 = -1321;\n\n noStroke();\n fill(0);\n textFont(myFont);\n textSize(22);\n\n text(nf(num1, 4, 2), 10, 30);\n text(nf(num2, 4, 2), 10, 80);\n // Draw dividing line\n stroke(120);\n line(0, 50, width, 50);\n}\n\n
" + ], + alt: '"0321.00" middle top, -1321.00" middle bottom canvas', + class: 'p5', + module: 'Data', + submodule: 'String Functions', + overloads: [ + { + line: 132, + params: [ + { + name: 'num', + description: '

the Number to format

\n', + type: 'Number|String' + }, + { + name: 'left', + description: + '

number of digits to the left of the\n decimal point

\n', + type: 'Integer|String', + optional: true + }, + { + name: 'right', + description: + '

number of digits to the right of the\n decimal point

\n', + type: 'Integer|String', + optional: true + } + ], + return: { + description: 'formatted String', + type: 'String' + } + }, + { + line: 180, + params: [ + { + name: 'nums', + description: '

the Numbers to format

\n', + type: 'Array' + }, + { + name: 'left', + description: '', + type: 'Integer|String', + optional: true + }, + { + name: 'right', + description: '', + type: 'Integer|String', + optional: true + } + ], + return: { + description: 'formatted Strings', + type: 'String[]' + } + } + ] + }, + { + file: 'src/utilities/string_functions.js', + line: 243, + description: + '

Utility function for formatting numbers into strings and placing\nappropriate commas to mark units of 1000. There are two versions: one\nfor formatting ints, and one for formatting an array of ints. The value\nfor the right parameter should always be a positive integer.

\n', + itemtype: 'method', + name: 'nfc', + return: { + description: 'formatted String', + type: 'String' + }, + example: [ + '\n
\n\nfunction setup() {\n background(200);\n var num = 11253106.115;\n var numArr = [1, 1, 2];\n\n noStroke();\n fill(0);\n textSize(12);\n\n // Draw formatted numbers\n text(nfc(num, 4), 10, 30);\n text(nfc(numArr, 2), 10, 80);\n\n // Draw dividing line\n stroke(120);\n line(0, 50, width, 50);\n}\n\n
' + ], + alt: + '"11,253,106.115" top middle and "1.00,1.00,2.00" displayed bottom mid', + class: 'p5', + module: 'Data', + submodule: 'String Functions', + overloads: [ + { + line: 243, + params: [ + { + name: 'num', + description: '

the Number to format

\n', + type: 'Number|String' + }, + { + name: 'right', + description: + '

number of digits to the right of the\n decimal point

\n', + type: 'Integer|String', + optional: true + } + ], + return: { + description: 'formatted String', + type: 'String' + } + }, + { + line: 281, + params: [ + { + name: 'nums', + description: '

the Numbers to format

\n', + type: 'Array' + }, + { + name: 'right', + description: '', + type: 'Integer|String', + optional: true + } + ], + return: { + description: 'formatted Strings', + type: 'String[]' + } + } + ] + }, + { + file: 'src/utilities/string_functions.js', + line: 319, + description: + '

Utility function for formatting numbers into strings. Similar to nf() but\nputs a "+" in front of positive numbers and a "-" in front of negative\nnumbers. There are two versions: one for formatting floats, and one for\nformatting ints. The values for left, and right parameters\nshould always be positive integers.

\n', + itemtype: 'method', + name: 'nfp', + return: { + description: 'formatted String', + type: 'String' + }, + example: [ + '\n
\n\nfunction setup() {\n background(200);\n var num1 = 11253106.115;\n var num2 = -11253106.115;\n\n noStroke();\n fill(0);\n textSize(12);\n\n // Draw formatted numbers\n text(nfp(num1, 4, 2), 10, 30);\n text(nfp(num2, 4, 2), 10, 80);\n\n // Draw dividing line\n stroke(120);\n line(0, 50, width, 50);\n}\n\n
' + ], + alt: '"+11253106.11" top middle and "-11253106.11" displayed bottom middle', + class: 'p5', + module: 'Data', + submodule: 'String Functions', + overloads: [ + { + line: 319, + params: [ + { + name: 'num', + description: '

the Number to format

\n', + type: 'Number' + }, + { + name: 'left', + description: + '

number of digits to the left of the decimal\n point

\n', + type: 'Integer', + optional: true + }, + { + name: 'right', + description: + '

number of digits to the right of the\n decimal point

\n', + type: 'Integer', + optional: true + } + ], + return: { + description: 'formatted String', + type: 'String' + } + }, + { + line: 360, + params: [ + { + name: 'nums', + description: '

the Numbers to format

\n', + type: 'Number[]' + }, + { + name: 'left', + description: '', + type: 'Integer', + optional: true + }, + { + name: 'right', + description: '', + type: 'Integer', + optional: true + } + ], + return: { + description: 'formatted Strings', + type: 'String[]' + } + } + ] + }, + { + file: 'src/utilities/string_functions.js', + line: 381, + description: + '

Utility function for formatting numbers into strings. Similar to nf() but\nputs an additional "_" (space) in front of positive numbers just in case to align it with negative\nnumbers which includes "-" (minus) sign.\nThe main usecase of nfs() can be seen when one wants to align the digits (place values) of a non-negative\nnumber with some negative number (See the example to get a clear picture).\nThere are two versions: one for formatting float, and one for formatting int.\nThe values for the digits, left, and right parameters should always be positive integers.\n(IMP): The result on the canvas basically the expected alignment can vary based on the typeface you are using.\n(NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter\nif greater than the current length of the number.\nFor example if number is 123.2 and left parameter passed is 4 which is greater than length of 123\n(integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than\nthe result will be 123.200.

\n', + itemtype: 'method', + name: 'nfs', + return: { + description: 'formatted String', + type: 'String' + }, + example: [ + "\n
\n\nvar myFont;\nfunction preload() {\n myFont = loadFont('assets/fonts/inconsolata.ttf');\n}\nfunction setup() {\n background(200);\n var num1 = 321;\n var num2 = -1321;\n\n noStroke();\n fill(0);\n textFont(myFont);\n textSize(22);\n\n // nfs() aligns num1 (positive number) with num2 (negative number) by\n // adding a blank space in front of the num1 (positive number)\n // [left = 4] in num1 add one 0 in front, to align the digits with num2\n // [right = 2] in num1 and num2 adds two 0's after both numbers\n // To see the differences check the example of nf() too.\n text(nfs(num1, 4, 2), 10, 30);\n text(nfs(num2, 4, 2), 10, 80);\n // Draw dividing line\n stroke(120);\n line(0, 50, width, 50);\n}\n\n
" + ], + alt: '"0321.00" top middle and "-1321.00" displayed bottom middle', + class: 'p5', + module: 'Data', + submodule: 'String Functions', + overloads: [ + { + line: 381, + params: [ + { + name: 'num', + description: '

the Number to format

\n', + type: 'Number' + }, + { + name: 'left', + description: + '

number of digits to the left of the decimal\n point

\n', + type: 'Integer', + optional: true + }, + { + name: 'right', + description: + '

number of digits to the right of the\n decimal point

\n', + type: 'Integer', + optional: true + } + ], + return: { + description: 'formatted String', + type: 'String' + } + }, + { + line: 438, + params: [ + { + name: 'nums', + description: '

the Numbers to format

\n', + type: 'Array' + }, + { + name: 'left', + description: '', + type: 'Integer', + optional: true + }, + { + name: 'right', + description: '', + type: 'Integer', + optional: true + } + ], + return: { + description: 'formatted Strings', + type: 'String[]' + } + } + ] + }, + { + file: 'src/utilities/string_functions.js', + line: 459, + description: + '

The split() function maps to String.split(), it breaks a String into\npieces using a character or string as the delimiter. The delim parameter\nspecifies the character or characters that mark the boundaries between\neach piece. A String[] array is returned that contains each of the pieces.

\n

The splitTokens() function works in a similar fashion, except that it\nsplits using a range of characters instead of a specific character or\nsequence.

\n', + itemtype: 'method', + name: 'split', + params: [ + { + name: 'value', + description: '

the String to be split

\n', + type: 'String' + }, + { + name: 'delim', + description: '

the String used to separate the data

\n', + type: 'String' + } + ], + return: { + description: 'Array of Strings', + type: 'String[]' + }, + example: [ + "\n
\n\nvar names = 'Pat,Xio,Alex';\nvar splitString = split(names, ',');\ntext(splitString[0], 5, 30);\ntext(splitString[1], 5, 50);\ntext(splitString[2], 5, 70);\n\n
" + ], + alt: '"pat" top left, "Xio" mid left and "Alex" displayed bottom left', + class: 'p5', + module: 'Data', + submodule: 'String Functions' + }, + { + file: 'src/utilities/string_functions.js', + line: 493, + description: + '

The splitTokens() function splits a String at one or many character\ndelimiters or "tokens." The delim parameter specifies the character or\ncharacters to be used as a boundary.\n

\nIf no delim characters are specified, any whitespace character is used to\nsplit. Whitespace characters include tab (\\t), line feed (\\n), carriage\nreturn (\\r), form feed (\\f), and space.

\n', + itemtype: 'method', + name: 'splitTokens', + params: [ + { + name: 'value', + description: '

the String to be split

\n', + type: 'String' + }, + { + name: 'delim', + description: + '

list of individual Strings that will be used as\n separators

\n', + type: 'String', + optional: true + } + ], + return: { + description: 'Array of Strings', + type: 'String[]' + }, + example: [ + '\n
\n\nfunction setup() {\n var myStr = \'Mango, Banana, Lime\';\n var myStrArr = splitTokens(myStr, \',\');\n\n print(myStrArr); // prints : ["Mango"," Banana"," Lime"]\n}\n\n
' + ], + class: 'p5', + module: 'Data', + submodule: 'String Functions' + }, + { + file: 'src/utilities/string_functions.js', + line: 548, + description: + '

Removes whitespace characters from the beginning and end of a String. In\naddition to standard whitespace characters such as space, carriage return,\nand tab, this function also removes the Unicode "nbsp" character.

\n', + itemtype: 'method', + name: 'trim', + return: { + description: 'a trimmed String', + type: 'String' + }, + example: [ + "\n
\n\nvar string = trim(' No new lines\\n ');\ntext(string + ' here', 2, 50);\n\n
" + ], + alt: '"No new lines here" displayed center canvas', + class: 'p5', + module: 'Data', + submodule: 'String Functions', + overloads: [ + { + line: 548, + params: [ + { + name: 'str', + description: '

a String to be trimmed

\n', + type: 'String' + } + ], + return: { + description: 'a trimmed String', + type: 'String' + } + }, + { + line: 568, + params: [ + { + name: 'strs', + description: '

an Array of Strings to be trimmed

\n', + type: 'Array' + } + ], + return: { + description: 'an Array of trimmed Strings', + type: 'String[]' + } + } + ] + }, + { + file: 'src/utilities/time_date.js', + line: 12, + description: + '

p5.js communicates with the clock on your computer. The day() function\nreturns the current day as a value from 1 - 31.

\n', + itemtype: 'method', + name: 'day', + return: { + description: 'the current day', + type: 'Integer' + }, + example: [ + "\n
\n\nvar d = day();\ntext('Current day: \\n' + d, 5, 50);\n\n
" + ], + alt: 'Current day is displayed', + class: 'p5', + module: 'IO', + submodule: 'Time & Date' + }, + { + file: 'src/utilities/time_date.js', + line: 34, + description: + '

p5.js communicates with the clock on your computer. The hour() function\nreturns the current hour as a value from 0 - 23.

\n', + itemtype: 'method', + name: 'hour', + return: { + description: 'the current hour', + type: 'Integer' + }, + example: [ + "\n
\n\nvar h = hour();\ntext('Current hour:\\n' + h, 5, 50);\n\n
" + ], + alt: 'Current hour is displayed', + class: 'p5', + module: 'IO', + submodule: 'Time & Date' + }, + { + file: 'src/utilities/time_date.js', + line: 56, + description: + '

p5.js communicates with the clock on your computer. The minute() function\nreturns the current minute as a value from 0 - 59.

\n', + itemtype: 'method', + name: 'minute', + return: { + description: 'the current minute', + type: 'Integer' + }, + example: [ + "\n
\n\nvar m = minute();\ntext('Current minute: \\n' + m, 5, 50);\n\n
" + ], + alt: 'Current minute is displayed', + class: 'p5', + module: 'IO', + submodule: 'Time & Date' + }, + { + file: 'src/utilities/time_date.js', + line: 78, + description: + '

Returns the number of milliseconds (thousandths of a second) since\nstarting the program. This information is often used for timing events and\nanimation sequences.

\n', + itemtype: 'method', + name: 'millis', + return: { + description: 'the number of milliseconds since starting the program', + type: 'Number' + }, + example: [ + "\n
\n\nvar millisecond = millis();\ntext('Milliseconds \\nrunning: \\n' + millisecond, 5, 40);\n\n
" + ], + alt: 'number of milliseconds since program has started displayed', + class: 'p5', + module: 'IO', + submodule: 'Time & Date' + }, + { + file: 'src/utilities/time_date.js', + line: 101, + description: + '

p5.js communicates with the clock on your computer. The month() function\nreturns the current month as a value from 1 - 12.

\n', + itemtype: 'method', + name: 'month', + return: { + description: 'the current month', + type: 'Integer' + }, + example: [ + "\n
\n\nvar m = month();\ntext('Current month: \\n' + m, 5, 50);\n\n
" + ], + alt: 'Current month is displayed', + class: 'p5', + module: 'IO', + submodule: 'Time & Date' + }, + { + file: 'src/utilities/time_date.js', + line: 123, + description: + '

p5.js communicates with the clock on your computer. The second() function\nreturns the current second as a value from 0 - 59.

\n', + itemtype: 'method', + name: 'second', + return: { + description: 'the current second', + type: 'Integer' + }, + example: [ + "\n
\n\nvar s = second();\ntext('Current second: \\n' + s, 5, 50);\n\n
" + ], + alt: 'Current second is displayed', + class: 'p5', + module: 'IO', + submodule: 'Time & Date' + }, + { + file: 'src/utilities/time_date.js', + line: 145, + description: + '

p5.js communicates with the clock on your computer. The year() function\nreturns the current year as an integer (2014, 2015, 2016, etc).

\n', + itemtype: 'method', + name: 'year', + return: { + description: 'the current year', + type: 'Integer' + }, + example: [ + "\n
\n\nvar y = year();\ntext('Current year: \\n' + y, 5, 50);\n\n
" + ], + alt: 'Current year is displayed', + class: 'p5', + module: 'IO', + submodule: 'Time & Date' + }, + { + file: 'src/webgl/3d_primitives.js', + line: 14, + description: '

Draw a plane with given a width and height

\n', + itemtype: 'method', + name: 'plane', + params: [ + { + name: 'width', + description: '

width of the plane

\n', + type: 'Number', + optional: true + }, + { + name: 'height', + description: '

height of the plane

\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + '

Optional number of triangle\n subdivisions in x-dimension

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + '

Optional number of triangle\n subdivisions in y-dimension

\n', + type: 'Integer', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\n// draw a plane\n// with width 50 and height 50\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n plane(50, 50);\n}\n\n
' + ], + alt: + 'Nothing displayed on canvas\nRotating interior view of a box with sides that change color.\n3d red and green gradient.\nRotating interior view of a cylinder with sides that change color.\nRotating view of a cylinder with sides that change color.\n3d red and green gradient.\nrotating view of a multi-colored cylinder with concave sides.', + class: 'p5', + module: 'Shape', + submodule: '3D Primitives' + }, + { + file: 'src/webgl/3d_primitives.js', + line: 98, + description: '

Draw a box with given width, height and depth

\n', + itemtype: 'method', + name: 'box', + params: [ + { + name: 'width', + description: '

width of the box

\n', + type: 'Number', + optional: true + }, + { + name: 'Height', + description: '

height of the box

\n', + type: 'Number', + optional: true + }, + { + name: 'depth', + description: '

depth of the box

\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + '

Optional number of triangle\n subdivisions in x-dimension

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + '

Optional number of triangle\n subdivisions in y-dimension

\n', + type: 'Integer', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\n// draw a spinning box\n// with width, height and depth of 50\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n box(50);\n}\n\n
' + ], + class: 'p5', + module: 'Shape', + submodule: '3D Primitives' + }, + { + file: 'src/webgl/3d_primitives.js', + line: 216, + description: '

Draw a sphere with given radius

\n', + itemtype: 'method', + name: 'sphere', + params: [ + { + name: 'radius', + description: '

radius of circle

\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + '

number of segments,\n the more segments the smoother geometry\n default is 24

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + '

number of segments,\n the more segments the smoother geometry\n default is 16

\n', + type: 'Integer', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\n// draw a sphere with radius 40\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n sphere(40);\n}\n\n
' + ], + class: 'p5', + module: 'Shape', + submodule: '3D Primitives' + }, + { + file: 'src/webgl/3d_primitives.js', + line: 378, + description: '

Draw a cylinder with given radius and height

\n', + itemtype: 'method', + name: 'cylinder', + params: [ + { + name: 'radius', + description: '

radius of the surface

\n', + type: 'Number', + optional: true + }, + { + name: 'height', + description: '

height of the cylinder

\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + '

number of segments,\n the more segments the smoother geometry\n default is 24

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + '

number of segments in y-dimension,\n the more segments the smoother geometry\n default is 1

\n', + type: 'Integer', + optional: true + }, + { + name: 'bottomCap', + description: '

whether to draw the bottom of the cylinder

\n', + type: 'Boolean', + optional: true + }, + { + name: 'topCap', + description: '

whether to draw the top of the cylinder

\n', + type: 'Boolean', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\n// draw a spinning cylinder\n// with radius 20 and height 50\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n rotateX(frameCount * 0.01);\n rotateZ(frameCount * 0.01);\n cylinder(20, 50);\n}\n\n
' + ], + class: 'p5', + module: 'Shape', + submodule: '3D Primitives' + }, + { + file: 'src/webgl/3d_primitives.js', + line: 470, + description: '

Draw a cone with given radius and height

\n', + itemtype: 'method', + name: 'cone', + params: [ + { + name: 'radius', + description: '

radius of the bottom surface

\n', + type: 'Number', + optional: true + }, + { + name: 'height', + description: '

height of the cone

\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + '

number of segments,\n the more segments the smoother geometry\n default is 24

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + '

number of segments,\n the more segments the smoother geometry\n default is 1

\n', + type: 'Integer', + optional: true + }, + { + name: 'cap', + description: '

whether to draw the base of the cone

\n', + type: 'Boolean', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\n// draw a spinning cone\n// with radius 40 and height 70\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n rotateX(frameCount * 0.01);\n rotateZ(frameCount * 0.01);\n cone(40, 70);\n}\n\n
' + ], + class: 'p5', + module: 'Shape', + submodule: '3D Primitives' + }, + { + file: 'src/webgl/3d_primitives.js', + line: 540, + description: '

Draw an ellipsoid with given radius

\n', + itemtype: 'method', + name: 'ellipsoid', + params: [ + { + name: 'radiusx', + description: '

x-radius of ellipsoid

\n', + type: 'Number', + optional: true + }, + { + name: 'radiusy', + description: '

y-radius of ellipsoid

\n', + type: 'Number', + optional: true + }, + { + name: 'radiusz', + description: '

z-radius of ellipsoid

\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + '

number of segments,\n the more segments the smoother geometry\n default is 24. Avoid detail number above\n 150, it may crash the browser.

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + '

number of segments,\n the more segments the smoother geometry\n default is 16. Avoid detail number above\n 150, it may crash the browser.

\n', + type: 'Integer', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\n// draw an ellipsoid\n// with radius 30, 40 and 40.\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n ellipsoid(30, 40, 40);\n}\n\n
' + ], + class: 'p5', + module: 'Shape', + submodule: '3D Primitives' + }, + { + file: 'src/webgl/3d_primitives.js', + line: 631, + description: '

Draw a torus with given radius and tube radius

\n', + itemtype: 'method', + name: 'torus', + params: [ + { + name: 'radius', + description: '

radius of the whole ring

\n', + type: 'Number', + optional: true + }, + { + name: 'tubeRadius', + description: '

radius of the tube

\n', + type: 'Number', + optional: true + }, + { + name: 'detailX', + description: + '

number of segments in x-dimension,\n the more segments the smoother geometry\n default is 24

\n', + type: 'Integer', + optional: true + }, + { + name: 'detailY', + description: + '

number of segments in y-dimension,\n the more segments the smoother geometry\n default is 16

\n', + type: 'Integer', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\n// draw a spinning torus\n// with ring radius 30 and tube radius 15\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n torus(30, 15);\n}\n\n
' + ], + class: 'p5', + module: 'Shape', + submodule: '3D Primitives' + }, + { + file: 'src/webgl/interaction.js', + line: 13, + description: + '

Allows movement around a 3D sketch using a mouse or trackpad. Left-clicking\nand dragging will rotate the camera position about the center of the sketch,\nright-clicking and dragging will pan the camera position without rotation,\nand using the mouse wheel (scrolling) will move the camera closer or further\nfrom the center of the sketch. This function can be called with parameters\ndictating sensitivity to mouse movement along the X and Y axes. Calling\nthis function without parameters is equivalent to calling orbitControl(1,1).\nTo reverse direction of movement in either axis, enter a negative number\nfor sensitivity.

\n', + itemtype: 'method', + name: 'orbitControl', + params: [ + { + name: 'sensitivityX', + description: '

sensitivity to mouse movement along X axis

\n', + type: 'Number', + optional: true + }, + { + name: 'sensitivityY', + description: '

sensitivity to mouse movement along Y axis

\n', + type: 'Number', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n normalMaterial();\n}\nfunction draw() {\n background(200);\n orbitControl();\n rotateY(0.5);\n box(30, 50);\n}\n\n
' + ], + alt: 'Camera orbits around a box when mouse is hold-clicked & then moved.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Interaction' + }, + { + file: 'src/webgl/interaction.js', + line: 146, + description: + '

debugMode() helps visualize 3D space by adding a grid to indicate where the\n‘ground’ is in a sketch and an axes icon which indicates the +X, +Y, and +Z\ndirections. This function can be called without parameters to create a\ndefault grid and axes icon, or it can be called according to the examples\nabove to customize the size and position of the grid and/or axes icon. The\ngrid is drawn using the most recently set stroke color and weight. To\nspecify these parameters, add a call to stroke() and strokeWeight()\njust before the end of the draw() loop.

\n

By default, the grid will run through the origin (0,0,0) of the sketch\nalong the XZ plane\nand the axes icon will be offset from the origin. Both the grid and axes\nicon will be sized according to the current canvas size. Note that because the\ngrid runs parallel to the default camera view, it is often helpful to use\ndebugMode along with orbitControl to allow full view of the grid.

\n', + itemtype: 'method', + name: 'debugMode', + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n camera(0, -30, 100, 0, 0, 0, 0, 1, 0);\n normalMaterial();\n debugMode();\n}\n\nfunction draw() {\n background(200);\n orbitControl();\n box(15, 30);\n // Press the spacebar to turn debugMode off!\n if (keyIsDown(32)) {\n noDebugMode();\n }\n}\n\n
', + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n camera(0, -30, 100, 0, 0, 0, 0, 1, 0);\n normalMaterial();\n debugMode(GRID);\n}\n\nfunction draw() {\n background(200);\n orbitControl();\n box(15, 30);\n}\n\n
', + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n camera(0, -30, 100, 0, 0, 0, 0, 1, 0);\n normalMaterial();\n debugMode(AXES);\n}\n\nfunction draw() {\n background(200);\n orbitControl();\n box(15, 30);\n}\n\n
', + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n camera(0, -30, 100, 0, 0, 0, 0, 1, 0);\n normalMaterial();\n debugMode(GRID, 100, 10, 0, 0, 0);\n}\n\nfunction draw() {\n background(200);\n orbitControl();\n box(15, 30);\n}\n\n
', + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n camera(0, -30, 100, 0, 0, 0, 0, 1, 0);\n normalMaterial();\n debugMode(100, 10, 0, 0, 0, 20, 0, -40, 0);\n}\n\nfunction draw() {\n noStroke();\n background(200);\n orbitControl();\n box(15, 30);\n // set the stroke color and weight for the grid!\n stroke(255, 0, 150);\n strokeWeight(0.8);\n}\n\n
' + ], + alt: + 'a 3D box is centered on a grid in a 3D sketch. an icon\nindicates the direction of each axis: a red line points +X,\na green line +Y, and a blue line +Z.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Interaction', + overloads: [ + { + line: 146, + params: [] + }, + { + line: 279, + params: [ + { + name: 'mode', + description: '

either GRID or AXES

\n', + type: 'Constant' + } + ] + }, + { + line: 284, + params: [ + { + name: 'mode', + description: '', + type: 'Constant' + }, + { + name: 'gridSize', + description: '

size of one side of the grid

\n', + type: 'Number', + optional: true + }, + { + name: 'gridDivisions', + description: '

number of divisions in the grid

\n', + type: 'Number', + optional: true + }, + { + name: 'xOff', + description: '

X axis offset from origin (0,0,0)

\n', + type: 'Number', + optional: true + }, + { + name: 'yOff', + description: '

Y axis offset from origin (0,0,0)

\n', + type: 'Number', + optional: true + }, + { + name: 'zOff', + description: '

Z axis offset from origin (0,0,0)

\n', + type: 'Number', + optional: true + } + ] + }, + { + line: 294, + params: [ + { + name: 'mode', + description: '', + type: 'Constant' + }, + { + name: 'axesSize', + description: '

size of axes icon

\n', + type: 'Number', + optional: true + }, + { + name: 'xOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'yOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'zOff', + description: '', + type: 'Number', + optional: true + } + ] + }, + { + line: 303, + params: [ + { + name: 'gridSize', + description: '', + type: 'Number', + optional: true + }, + { + name: 'gridDivisions', + description: '', + type: 'Number', + optional: true + }, + { + name: 'gridXOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'gridYOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'gridZOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'axesSize', + description: '', + type: 'Number', + optional: true + }, + { + name: 'axesXOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'axesYOff', + description: '', + type: 'Number', + optional: true + }, + { + name: 'axesZOff', + description: '', + type: 'Number', + optional: true + } + ] + } + ] + }, + { + file: 'src/webgl/interaction.js', + line: 380, + description: '

Turns off debugMode() in a 3D sketch.

\n', + itemtype: 'method', + name: 'noDebugMode', + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n camera(0, -30, 100, 0, 0, 0, 0, 1, 0);\n normalMaterial();\n debugMode();\n}\n\nfunction draw() {\n background(200);\n orbitControl();\n box(15, 30);\n // Press the spacebar to turn debugMode off!\n if (keyIsDown(32)) {\n noDebugMode();\n }\n}\n\n
' + ], + alt: + 'a 3D box is centered on a grid in a 3D sketch. an icon\nindicates the direction of each axis: a red line points +X,\na green line +Y, and a blue line +Z. the grid and icon disappear when the\nspacebar is pressed.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Interaction' + }, + { + file: 'src/webgl/light.js', + line: 12, + description: '

Creates an ambient light with a color

\n', + itemtype: 'method', + name: 'ambientLight', + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(0);\n ambientLight(150);\n ambientMaterial(250);\n noStroke();\n sphere(40);\n}\n\n
' + ], + alt: 'evenly distributed light across a sphere', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Lights', + overloads: [ + { + line: 12, + params: [ + { + name: 'v1', + description: + '

red or hue value relative to\n the current color range

\n', + type: 'Number' + }, + { + name: 'v2', + description: + '

green or saturation value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'v3', + description: + '

blue or brightness value\n relative to the current color range

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '

the alpha value

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 46, + params: [ + { + name: 'value', + description: '

a color string

\n', + type: 'String' + } + ], + chainable: 1 + }, + { + line: 52, + params: [ + { + name: 'gray', + description: '

a gray value

\n', + type: 'Number' + }, + { + name: 'alpha', + description: '', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 59, + params: [ + { + name: 'values', + description: + '

an array containing the red,green,blue &\n and alpha components of the color

\n', + type: 'Number[]' + } + ], + chainable: 1 + }, + { + line: 66, + params: [ + { + name: 'color', + description: '

the ambient light color

\n', + type: 'p5.Color' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/webgl/light.js', + line: 87, + description: + '

Creates a directional light with a color and a direction

\n', + itemtype: 'method', + name: 'directionalLight', + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(0);\n //move your mouse to change light direction\n let dirX = (mouseX / width - 0.5) * 2;\n let dirY = (mouseY / height - 0.5) * 2;\n directionalLight(250, 250, 250, -dirX, -dirY, -1);\n noStroke();\n sphere(40);\n}\n\n
' + ], + alt: 'light source on canvas changeable with mouse position', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Lights', + overloads: [ + { + line: 87, + params: [ + { + name: 'v1', + description: + '

red or hue value (depending on the current\ncolor mode),

\n', + type: 'Number' + }, + { + name: 'v2', + description: '

green or saturation value

\n', + type: 'Number' + }, + { + name: 'v3', + description: '

blue or brightness value

\n', + type: 'Number' + }, + { + name: 'position', + description: '

the direction of the light

\n', + type: 'p5.Vector' + } + ], + chainable: 1 + }, + { + line: 119, + params: [ + { + name: 'color', + description: + '

color Array, CSS color string,\n or p5.Color value

\n', + type: 'Number[]|String|p5.Color' + }, + { + name: 'x', + description: '

x axis direction

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y axis direction

\n', + type: 'Number' + }, + { + name: 'z', + description: '

z axis direction

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 129, + params: [ + { + name: 'color', + description: '', + type: 'Number[]|String|p5.Color' + }, + { + name: 'position', + description: '', + type: 'p5.Vector' + } + ], + chainable: 1 + }, + { + line: 136, + params: [ + { + name: 'v1', + description: '', + type: 'Number' + }, + { + name: 'v2', + description: '', + type: 'Number' + }, + { + name: 'v3', + description: '', + type: 'Number' + }, + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/webgl/light.js', + line: 185, + description: + '

Creates a point light with a color and a light position

\n', + itemtype: 'method', + name: 'pointLight', + chainable: 1, + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(0);\n //move your mouse to change light position\n let locX = mouseX - width / 2;\n let locY = mouseY - height / 2;\n // to set the light position,\n // think of the world's coordinate as:\n // -width/2,-height/2 -------- width/2,-height/2\n // | |\n // | 0,0 |\n // | |\n // -width/2,height/2--------width/2,height/2\n pointLight(250, 250, 250, locX, locY, 50);\n noStroke();\n sphere(40);\n}\n\n
" + ], + alt: 'spot light on canvas changes position with mouse', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Lights', + overloads: [ + { + line: 185, + params: [ + { + name: 'v1', + description: + '

red or hue value (depending on the current\ncolor mode),

\n', + type: 'Number' + }, + { + name: 'v2', + description: '

green or saturation value

\n', + type: 'Number' + }, + { + name: 'v3', + description: '

blue or brightness value

\n', + type: 'Number' + }, + { + name: 'x', + description: '

x axis position

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y axis position

\n', + type: 'Number' + }, + { + name: 'z', + description: '

z axis position

\n', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 226, + params: [ + { + name: 'v1', + description: '', + type: 'Number' + }, + { + name: 'v2', + description: '', + type: 'Number' + }, + { + name: 'v3', + description: '', + type: 'Number' + }, + { + name: 'position', + description: '

the position of the light

\n', + type: 'p5.Vector' + } + ], + chainable: 1 + }, + { + line: 235, + params: [ + { + name: 'color', + description: + '

color Array, CSS color string,\nor p5.Color value

\n', + type: 'Number[]|String|p5.Color' + }, + { + name: 'x', + description: '', + type: 'Number' + }, + { + name: 'y', + description: '', + type: 'Number' + }, + { + name: 'z', + description: '', + type: 'Number' + } + ], + chainable: 1 + }, + { + line: 245, + params: [ + { + name: 'color', + description: '', + type: 'Number[]|String|p5.Color' + }, + { + name: 'position', + description: '', + type: 'p5.Vector' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/webgl/light.js', + line: 287, + description: + '

Sets the default ambient and directional light. The defaults are ambientLight(128, 128, 128) and directionalLight(128, 128, 128, 0, 0, -1). Lights need to be included in the draw() to remain persistent in a looping program. Placing them in the setup() of a looping program will cause them to only have an effect the first time through the loop.

\n', + itemtype: 'method', + name: 'lights', + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(0);\n lights();\n rotateX(millis() / 1000);\n rotateY(millis() / 1000);\n rotateZ(millis() / 1000);\n box();\n}\n\n
' + ], + alt: 'the light is partially ambient and partially directional', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Lights' + }, + { + file: 'src/webgl/light.js', + line: 318, + description: + '

Sets the falloff rates for point lights. It affects only the elements which are created after it in the code.\nThe default value is lightFalloff(1.0, 0.0, 0.0), and the parameters are used to calculate the falloff with the following equation:

\n

d = distance from light position to vertex position

\n

falloff = 1 / (CONSTANT + d * LINEAR + ( d * d ) * QUADRATIC)

\n', + itemtype: 'method', + name: 'lightFalloff', + params: [ + { + name: 'constant', + description: '

constant value for determining falloff

\n', + type: 'Number' + }, + { + name: 'linear', + description: '

linear value for determining falloff

\n', + type: 'Number' + }, + { + name: 'quadratic', + description: '

quadratic value for determining falloff

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n noStroke();\n}\nfunction draw() {\n background(0);\n let locX = mouseX - width / 2;\n let locY = mouseY - height / 2;\n translate(-25, 0, 0);\n lightFalloff(1, 0, 0);\n pointLight(250, 250, 250, locX, locY, 50);\n sphere(20);\n translate(50, 0, 0);\n lightFalloff(0.9, 0.01, 0);\n pointLight(250, 250, 250, locX, locY, 50);\n sphere(20);\n}\n\n
' + ], + alt: + 'Two spheres with different falloff values show different intensity of light', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Lights' + }, + { + file: 'src/webgl/loading.js', + line: 14, + description: + '

Load a 3d model from an OBJ or STL file.\n

\nOne of the limitations of the OBJ and STL format is that it doesn't have a built-in\nsense of scale. This means that models exported from different programs might\nbe very different sizes. If your model isn't displaying, try calling\nloadModel() with the normalized parameter set to true. This will resize the\nmodel to a scale appropriate for p5. You can also make additional changes to\nthe final size of your model with the scale() function.

\n

Also, the support for colored STL files is not present. STL files with color will be\nrendered without color properties.

\n', + itemtype: 'method', + name: 'loadModel', + return: { + description: 'the p5.Geometry object', + type: 'p5.Geometry' + }, + example: [ + "\n
\n\n//draw a spinning octahedron\nlet octahedron;\n\nfunction preload() {\n octahedron = loadModel('assets/octahedron.obj');\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n model(octahedron);\n}\n\n
", + "\n
\n\n//draw a spinning teapot\nlet teapot;\n\nfunction preload() {\n // Load model with normalise parameter set to true\n teapot = loadModel('assets/teapot.obj', true);\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n scale(0.4); // Scaled to make model fit into canvas\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n normalMaterial(); // For effect\n model(teapot);\n}\n\n
" + ], + alt: 'Vertically rotating 3-d teapot with red, green and blue gradient.', + class: 'p5', + module: 'Shape', + submodule: '3D Models', + overloads: [ + { + line: 14, + params: [ + { + name: 'path', + description: '

Path of the model to be loaded

\n', + type: 'String' + }, + { + name: 'normalize', + description: + '

If true, scale the model to a\n standardized size when loading

\n', + type: 'Boolean' + }, + { + name: 'successCallback', + description: + '

Function to be called\n once the model is loaded. Will be passed\n the 3D model object.

\n', + type: 'function(p5.Geometry)', + optional: true + }, + { + name: 'failureCallback', + description: + '

called with event error if\n the model fails to load.

\n', + type: 'Function(Event)', + optional: true + } + ], + return: { + description: 'the p5.Geometry object', + type: 'p5.Geometry' + } + }, + { + line: 93, + params: [ + { + name: 'path', + description: '', + type: 'String' + }, + { + name: 'successCallback', + description: '', + type: 'function(p5.Geometry)', + optional: true + }, + { + name: 'failureCallback', + description: '', + type: 'Function(Event)', + optional: true + } + ], + return: { + description: 'the p5.Geometry object', + type: 'p5.Geometry' + } + } + ] + }, + { + file: 'src/webgl/loading.js', + line: 169, + description: + '

Parse OBJ lines into model. For reference, this is what a simple model of a\nsquare might look like:

\n

v -0.5 -0.5 0.5\nv -0.5 -0.5 -0.5\nv -0.5 0.5 -0.5\nv -0.5 0.5 0.5

\n

f 4 3 2 1

\n', + class: 'p5', + module: 'Shape', + submodule: '3D Models' + }, + { + file: 'src/webgl/loading.js', + line: 278, + description: + '

STL files can be of two types, ASCII and Binary,

\n

We need to convert the arrayBuffer to an array of strings,\nto parse it as an ASCII file.

\n', + class: 'p5', + module: 'Shape', + submodule: '3D Models' + }, + { + file: 'src/webgl/loading.js', + line: 305, + description: + '

This function checks if the file is in ASCII format or in Binary format

\n

It is done by searching keyword solid at the start of the file.

\n

An ASCII STL data must begin with solid as the first six bytes.\nHowever, ASCII STLs lacking the SPACE after the d are known to be\nplentiful. So, check the first 5 bytes for solid.

\n

Several encodings, such as UTF-8, precede the text with up to 5 bytes:\nhttps://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding\nSearch for solid to start anywhere after those prefixes.

\n', + class: 'p5', + module: 'Shape', + submodule: '3D Models' + }, + { + file: 'src/webgl/loading.js', + line: 332, + description: + '

This function matches the query at the provided offset

\n', + class: 'p5', + module: 'Shape', + submodule: '3D Models' + }, + { + file: 'src/webgl/loading.js', + line: 344, + description: + '

This function parses the Binary STL files.\nhttps://en.wikipedia.org/wiki/STL_%28file_format%29#Binary_STL

\n

Currently there is no support for the colors provided in STL files.

\n', + class: 'p5', + module: 'Shape', + submodule: '3D Models' + }, + { + file: 'src/webgl/loading.js', + line: 433, + description: + '

ASCII STL file starts with solid 'nameOfFile'\nThen contain the normal of the face, starting with facet normal\nNext contain a keyword indicating the start of face vertex, outer loop\nNext comes the three vertex, starting with vertex x y z\nVertices ends with endloop\nFace ends with endfacet\nNext face starts with facet normal\nThe end of the file is indicated by endsolid

\n', + class: 'p5', + module: 'Shape', + submodule: '3D Models' + }, + { + file: 'src/webgl/loading.js', + line: 580, + description: '

Render a 3d model to the screen.

\n', + itemtype: 'method', + name: 'model', + params: [ + { + name: 'model', + description: '

Loaded 3d model to be rendered

\n', + type: 'p5.Geometry' + } + ], + example: [ + "\n
\n\n//draw a spinning octahedron\nlet octahedron;\n\nfunction preload() {\n octahedron = loadModel('assets/octahedron.obj');\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n model(octahedron);\n}\n\n
" + ], + alt: 'Vertically rotating 3-d octahedron.', + class: 'p5', + module: 'Shape', + submodule: '3D Models' + }, + { + file: 'src/webgl/material.js', + line: 14, + description: + '

Loads a custom shader from the provided vertex and fragment\nshader paths. The shader files are loaded asynchronously in the\nbackground, so this method should be used in preload().

\n

For now, there are three main types of shaders. p5 will automatically\nsupply appropriate vertices, normals, colors, and lighting attributes\nif the parameters defined in the shader match the names.

\n', + itemtype: 'method', + name: 'loadShader', + params: [ + { + name: 'vertFilename', + description: + '

path to file containing vertex shader\nsource code

\n', + type: 'String' + }, + { + name: 'fragFilename', + description: + '

path to file containing fragment shader\nsource code

\n', + type: 'String' + }, + { + name: 'callback', + description: + '

callback to be executed after loadShader\ncompletes. On success, the Shader object is passed as the first argument.

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

callback to be executed when an error\noccurs inside loadShader. On error, the error is passed as the first\nargument.

\n', + type: 'Function', + optional: true + } + ], + return: { + description: + 'a shader object created from the provided\nvertex and fragment shader files.', + type: 'p5.Shader' + }, + example: [ + "\n
\n\nlet mandel;\nfunction preload() {\n // load the shader definitions from files\n mandel = loadShader('assets/shader.vert', 'assets/shader.frag');\n}\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n // use the shader\n shader(mandel);\n noStroke();\n mandel.setUniform('p', [-0.74364388703, 0.13182590421]);\n}\n\nfunction draw() {\n mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000))));\n quad(-1, -1, 1, -1, 1, 1, -1, 1);\n}\n\n
" + ], + alt: 'zooming Mandelbrot set. a colorful, infinitely detailed fractal.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/material.js', + line: 113, + itemtype: 'method', + name: 'createShader', + params: [ + { + name: 'vertSrc', + description: '

source code for the vertex shader

\n', + type: 'String' + }, + { + name: 'fragSrc', + description: '

source code for the fragment shader

\n', + type: 'String' + } + ], + return: { + description: + 'a shader object created from the provided\nvertex and fragment shaders.', + type: 'p5.Shader' + }, + example: [ + "\n
\n\n// the 'varying's are shared between both vertex & fragment shaders\nlet varying = 'precision highp float; varying vec2 vPos;';\n\n// the vertex shader is called for each vertex\nlet vs =\n varying +\n 'attribute vec3 aPosition;' +\n 'void main() { vPos = (gl_Position = vec4(aPosition,1.0)).xy; }';\n\n// the fragment shader is called for each pixel\nlet fs =\n varying +\n 'uniform vec2 p;' +\n 'uniform float r;' +\n 'const int I = 500;' +\n 'void main() {' +\n ' vec2 c = p + vPos * r, z = c;' +\n ' float n = 0.0;' +\n ' for (int i = I; i > 0; i --) {' +\n ' if(z.x*z.x+z.y*z.y > 4.0) {' +\n ' n = float(i)/float(I);' +\n ' break;' +\n ' }' +\n ' z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c;' +\n ' }' +\n ' gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0);' +\n '}';\n\nlet mandel;\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n\n // create and initialize the shader\n mandel = createShader(vs, fs);\n shader(mandel);\n noStroke();\n\n // 'p' is the center point of the Mandelbrot image\n mandel.setUniform('p', [-0.74364388703, 0.13182590421]);\n}\n\nfunction draw() {\n // 'r' is the size of the image in Mandelbrot-space\n mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000))));\n quad(-1, -1, 1, -1, 1, 1, -1, 1);\n}\n\n
" + ], + alt: 'zooming Mandelbrot set. a colorful, infinitely detailed fractal.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/material.js', + line: 181, + description: + '

The shader() function lets the user provide a custom shader\nto fill in shapes in WEBGL mode. Users can create their\nown shaders by loading vertex and fragment shaders with\nloadShader().

\n', + itemtype: 'method', + name: 'shader', + chainable: 1, + params: [ + { + name: 's', + description: + '

the desired p5.Shader to use for rendering\nshapes.

\n', + type: 'p5.Shader', + optional: true + } + ], + example: [ + "\n
\n\n// Click within the image to toggle\n// the shader used by the quad shape\n// Note: for an alternative approach to the same example,\n// involving changing uniforms please refer to:\n// https://p5js.org/reference/#/p5.Shader/setUniform\n\nlet redGreen;\nlet orangeBlue;\nlet showRedGreen = false;\n\nfunction preload() {\n // note that we are using two instances\n // of the same vertex and fragment shaders\n redGreen = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');\n orangeBlue = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n\n // initialize the colors for redGreen shader\n shader(redGreen);\n redGreen.setUniform('colorCenter', [1.0, 0.0, 0.0]);\n redGreen.setUniform('colorBackground', [0.0, 1.0, 0.0]);\n\n // initialize the colors for orangeBlue shader\n shader(orangeBlue);\n orangeBlue.setUniform('colorCenter', [1.0, 0.5, 0.0]);\n orangeBlue.setUniform('colorBackground', [0.226, 0.0, 0.615]);\n\n noStroke();\n}\n\nfunction draw() {\n // update the offset values for each shader,\n // moving orangeBlue in vertical and redGreen\n // in horizontal direction\n orangeBlue.setUniform('offset', [0, sin(millis() / 2000) + 1]);\n redGreen.setUniform('offset', [sin(millis() / 2000), 1]);\n\n if (showRedGreen === true) {\n shader(redGreen);\n } else {\n shader(orangeBlue);\n }\n quad(-1, -1, 1, -1, 1, 1, -1, 1);\n}\n\nfunction mouseClicked() {\n showRedGreen = !showRedGreen;\n}\n\n
" + ], + alt: + 'canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/material.js', + line: 272, + description: + '

This function restores the default shaders in WEBGL mode. Code that runs\nafter resetShader() will not be affected by previously defined\nshaders. Should be run after shader().

\n', + itemtype: 'method', + name: 'resetShader', + chainable: 1, + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/material.js', + line: 285, + description: + '

Normal material for geometry. You can view all\npossible materials in this\nexample.

\n', + itemtype: 'method', + name: 'normalMaterial', + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(200);\n normalMaterial();\n sphere(40);\n}\n\n
' + ], + alt: 'Red, green and blue gradient.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/material.js', + line: 322, + description: + '

Texture for geometry. You can view other possible materials in this\nexample.

\n', + itemtype: 'method', + name: 'texture', + params: [ + { + name: 'tex', + description: + '

2-dimensional graphics\n to render as texture

\n', + type: 'p5.Image|p5.MediaElement|p5.Graphics' + } + ], + chainable: 1, + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/laDefense.jpg');\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(0);\n rotateZ(frameCount * 0.01);\n rotateX(frameCount * 0.01);\n rotateY(frameCount * 0.01);\n //pass image as texture\n texture(img);\n box(200, 200, 200);\n}\n\n
\n\n
\n\nlet pg;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n pg = createGraphics(200, 200);\n pg.textSize(75);\n}\n\nfunction draw() {\n background(0);\n pg.background(255);\n pg.text('hello!', 0, 100);\n //pass image as texture\n texture(pg);\n rotateX(0.5);\n noStroke();\n plane(50);\n}\n\n
\n\n
\n\nlet vid;\nfunction preload() {\n vid = createVideo('assets/fingers.mov');\n vid.hide();\n}\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(0);\n //pass video frame as texture\n texture(vid);\n rect(-40, -40, 80, 80);\n}\n\nfunction mousePressed() {\n vid.loop();\n}\n\n
" + ], + alt: + 'Rotating view of many images umbrella and grid roof on a 3d plane\nblack canvas\nblack canvas', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/material.js', + line: 419, + description: + '

Sets the coordinate space for texture mapping. The default mode is IMAGE\nwhich refers to the actual coordinates of the image.\nNORMAL refers to a normalized space of values ranging from 0 to 1.\nThis function only works in WEBGL mode.

\n

With IMAGE, if an image is 100 x 200 pixels, mapping the image onto the entire\nsize of a quad would require the points (0,0) (100, 0) (100,200) (0,200).\nThe same mapping in NORMAL is (0,0) (1,0) (1,1) (0,1).

\n', + itemtype: 'method', + name: 'textureMode', + params: [ + { + name: 'mode', + description: '

either IMAGE or NORMAL

\n', + type: 'Constant' + } + ], + example: [ + "\n
\n\nlet img;\n\nfunction preload() {\n img = loadImage('assets/laDefense.jpg');\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n texture(img);\n textureMode(NORMAL);\n beginShape();\n vertex(-50, -50, 0, 0);\n vertex(50, -50, 1, 0);\n vertex(50, 50, 1, 1);\n vertex(-50, 50, 0, 1);\n endShape();\n}\n\n
" + ], + alt: 'the underside of a white umbrella and gridded ceiling above', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/material.js', + line: 498, + description: + '

Sets the global texture wrapping mode. This controls how textures behave\nwhen their uv's go outside of the 0 - 1 range. There are three options:\nCLAMP, REPEAT, and MIRROR.

\n

CLAMP causes the pixels at the edge of the texture to extend to the bounds\nREPEAT causes the texture to tile repeatedly until reaching the bounds\nMIRROR works similarly to REPEAT but it flips the texture with every new tile

\n

REPEAT & MIRROR are only available if the texture\nis a power of two size (128, 256, 512, 1024, etc.).

\n

This method will affect all textures in your sketch until a subsequent\ntextureWrap call is made.

\n

If only one argument is provided, it will be applied to both the\nhorizontal and vertical axes.

\n', + itemtype: 'method', + name: 'textureWrap', + params: [ + { + name: 'wrapX', + description: '

either CLAMP, REPEAT, or MIRROR

\n', + type: 'Constant' + }, + { + name: 'wrapY', + description: '

either CLAMP, REPEAT, or MIRROR

\n', + type: 'Constant', + optional: true + } + ], + example: [ + "\n
\n\nlet img;\nfunction preload() {\n img = loadImage('assets/rockies128.jpg');\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n textureWrap(MIRROR);\n}\n\nfunction draw() {\n background(0);\n\n let dX = mouseX;\n let dY = mouseY;\n\n let u = lerp(1.0, 2.0, dX);\n let v = lerp(1.0, 2.0, dY);\n\n scale(width / 2);\n\n texture(img);\n\n beginShape(TRIANGLES);\n vertex(-1, -1, 0, 0, 0);\n vertex(1, -1, 0, u, 0);\n vertex(1, 1, 0, u, v);\n\n vertex(1, 1, 0, u, v);\n vertex(-1, 1, 0, 0, v);\n vertex(-1, -1, 0, 0, 0);\n endShape();\n}\n\n
" + ], + alt: 'an image of the rocky mountains repeated in mirrored tiles', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/material.js', + line: 573, + description: + '

Ambient material for geometry with a given color. You can view all\npossible materials in this\nexample.

\n', + itemtype: 'method', + name: 'ambientMaterial', + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(0);\n noStroke();\n ambientLight(200);\n ambientMaterial(70, 130, 230);\n sphere(40);\n}\n\n
' + ], + alt: 'radiating light source from top right of canvas', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material', + overloads: [ + { + line: 573, + params: [ + { + name: 'v1', + description: + '

gray value, red or hue value\n (depending on the current color mode),

\n', + type: 'Number' + }, + { + name: 'v2', + description: '

green or saturation value

\n', + type: 'Number', + optional: true + }, + { + name: 'v3', + description: '

blue or brightness value

\n', + type: 'Number', + optional: true + }, + { + name: 'a', + description: '

opacity

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 604, + params: [ + { + name: 'color', + description: '

color, color Array, or CSS color string

\n', + type: 'Number[]|String|p5.Color' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/webgl/material.js', + line: 623, + description: + '

Specular material for geometry with a given color. You can view all\npossible materials in this\nexample.

\n', + itemtype: 'method', + name: 'specularMaterial', + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(0);\n noStroke();\n ambientLight(50);\n pointLight(250, 250, 250, 100, 100, 30);\n specularMaterial(250);\n sphere(40);\n}\n\n
' + ], + alt: 'diffused radiating light source from top right of canvas', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material', + overloads: [ + { + line: 623, + params: [ + { + name: 'v1', + description: + '

gray value, red or hue value\n (depending on the current color mode),

\n', + type: 'Number' + }, + { + name: 'v2', + description: '

green or saturation value

\n', + type: 'Number', + optional: true + }, + { + name: 'v3', + description: '

blue or brightness value

\n', + type: 'Number', + optional: true + }, + { + name: 'a', + description: '

opacity

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + }, + { + line: 655, + params: [ + { + name: 'color', + description: '

color Array, or CSS color string

\n', + type: 'Number[]|String|p5.Color' + } + ], + chainable: 1 + } + ] + }, + { + file: 'src/webgl/material.js', + line: 674, + description: + '

Sets the amount of gloss in the surface of shapes.\nUsed in combination with specularMaterial() in setting\nthe material properties of shapes. The default and minimum value is 1.

\n', + itemtype: 'method', + name: 'shininess', + params: [ + { + name: 'shine', + description: + '

Degree of Shininess.\n Defaults to 1.

\n', + type: 'Number' + } + ], + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(0);\n noStroke();\n let locX = mouseX - width / 2;\n let locY = mouseY - height / 2;\n ambientLight(60, 60, 60);\n pointLight(255, 255, 255, locX, locY, 50);\n specularMaterial(250);\n translate(-25, 0, 0);\n shininess(1);\n sphere(20);\n translate(50, 0, 0);\n shininess(20);\n sphere(20);\n}\n\n
' + ], + alt: 'Shininess on Camera changes position with mouse', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Material' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 15, + description: + '

Sets the camera position for a 3D sketch. Parameters for this function define\nthe position for the camera, the center of the sketch (where the camera is\npointing), and an up direction (the orientation of the camera).

\n

When called with no arguments, this function creates a default camera\nequivalent to\ncamera(0, 0, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0);

\n', + itemtype: 'method', + name: 'camera', + params: [ + { + name: 'x', + description: '

camera position value on x axis

\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: '

camera position value on y axis

\n', + type: 'Number', + optional: true + }, + { + name: 'z', + description: '

camera position value on z axis

\n', + type: 'Number', + optional: true + }, + { + name: 'centerX', + description: '

x coordinate representing center of the sketch

\n', + type: 'Number', + optional: true + }, + { + name: 'centerY', + description: '

y coordinate representing center of the sketch

\n', + type: 'Number', + optional: true + }, + { + name: 'centerZ', + description: '

z coordinate representing center of the sketch

\n', + type: 'Number', + optional: true + }, + { + name: 'upX', + description: + '

x component of direction 'up' from camera

\n', + type: 'Number', + optional: true + }, + { + name: 'upY', + description: + '

y component of direction 'up' from camera

\n', + type: 'Number', + optional: true + }, + { + name: 'upZ', + description: + '

z component of direction 'up' from camera

\n', + type: 'Number', + optional: true + } + ], + chainable: 1, + example: [ + '\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\nfunction draw() {\n background(204);\n //move the camera away from the plane by a sin wave\n camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0);\n plane(10, 10);\n}\n\n
' + ], + alt: 'White square repeatedly grows to fill canvas and then shrinks.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 61, + description: + '

Sets a perspective projection for the camera in a 3D sketch. This projection\nrepresents depth through foreshortening: objects that are close to the camera\nappear their actual size while those that are further away from the camera\nappear smaller. The parameters to this function define the viewing frustum\n(the truncated pyramid within which objects are seen by the camera) through\nvertical field of view, aspect ratio (usually width/height), and near and far\nclipping planes.

\n

When called with no arguments, the defaults\nprovided are equivalent to\nperspective(PI/3.0, width/height, eyeZ/10.0, eyeZ10.0), where eyeZ\nis equal to ((height/2.0) / tan(PI60.0/360.0));

\n', + itemtype: 'method', + name: 'perspective', + params: [ + { + name: 'fovy', + description: + '

camera frustum vertical field of view,\n from bottom to top of view, in angleMode units

\n', + type: 'Number', + optional: true + }, + { + name: 'aspect', + description: '

camera frustum aspect ratio

\n', + type: 'Number', + optional: true + }, + { + name: 'near', + description: '

frustum near plane length

\n', + type: 'Number', + optional: true + }, + { + name: 'far', + description: '

frustum far plane length

\n', + type: 'Number', + optional: true + } + ], + chainable: 1, + example: [ + "\n
\n\n//drag the mouse to look around!\n//you will see there's a vanishing point\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n perspective(PI / 3.0, width / height, 0.1, 500);\n}\nfunction draw() {\n background(200);\n orbitControl();\n normalMaterial();\n\n rotateX(-0.3);\n rotateY(-0.2);\n translate(0, 0, -50);\n\n push();\n translate(-15, 0, sin(frameCount / 30) * 95);\n box(30);\n pop();\n push();\n translate(15, 0, sin(frameCount / 30 + PI) * 95);\n box(30);\n pop();\n}\n\n
" + ], + alt: + 'two colored 3D boxes move back and forth, rotating as mouse is dragged.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 126, + description: + '

Sets an orthographic projection for the camera in a 3D sketch and defines a\nbox-shaped viewing frustum within which objects are seen. In this projection,\nall objects with the same dimension appear the same size, regardless of\nwhether they are near or far from the camera. The parameters to this\nfunction specify the viewing frustum where left and right are the minimum and\nmaximum x values, top and bottom are the minimum and maximum y values, and near\nand far are the minimum and maximum z values. If no parameters are given, the\ndefault is used: ortho(-width/2, width/2, -height/2, height/2).

\n', + itemtype: 'method', + name: 'ortho', + params: [ + { + name: 'left', + description: '

camera frustum left plane

\n', + type: 'Number', + optional: true + }, + { + name: 'right', + description: '

camera frustum right plane

\n', + type: 'Number', + optional: true + }, + { + name: 'bottom', + description: '

camera frustum bottom plane

\n', + type: 'Number', + optional: true + }, + { + name: 'top', + description: '

camera frustum top plane

\n', + type: 'Number', + optional: true + }, + { + name: 'near', + description: '

camera frustum near plane

\n', + type: 'Number', + optional: true + }, + { + name: 'far', + description: '

camera frustum far plane

\n', + type: 'Number', + optional: true + } + ], + chainable: 1, + example: [ + "\n
\n\n//drag the mouse to look around!\n//there's no vanishing point\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500);\n}\nfunction draw() {\n background(200);\n orbitControl();\n normalMaterial();\n\n rotateX(0.2);\n rotateY(-0.2);\n push();\n translate(-15, 0, sin(frameCount / 30) * 65);\n box(30);\n pop();\n push();\n translate(15, 0, sin(frameCount / 30 + PI) * 65);\n box(30);\n pop();\n}\n\n
" + ], + alt: + 'two 3D boxes move back and forth along same plane, rotating as mouse is dragged.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 187, + description: + '

Creates a new p5.Camera object and tells the\nrenderer to use that camera.\nReturns the p5.Camera object.

\n', + itemtype: 'method', + name: 'createCamera', + return: { + description: 'The newly created camera object.', + type: 'p5.Camera' + }, + class: 'p5', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 298, + description: + '

Sets a perspective projection for a p5.Camera object and sets parameters\nfor that projection according to perspective()\nsyntax.

\n', + itemtype: 'method', + name: 'perspective', + class: 'p5.Camera', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 379, + description: + '

Sets an orthographic projection for a p5.Camera object and sets parameters\nfor that projection according to ortho() syntax.

\n', + itemtype: 'method', + name: 'ortho', + class: 'p5.Camera', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 486, + description: + '

Panning rotates the camera view to the left and right.

\n', + itemtype: 'method', + name: 'pan', + params: [ + { + name: 'angle', + description: + '

amount to rotate camera in current\nangleMode units.\nGreater than 0 values rotate counterclockwise (to the left).

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\nlet cam;\nlet delta = 0.01;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n normalMaterial();\n cam = createCamera();\n // set initial pan angle\n cam.pan(-0.8);\n}\n\nfunction draw() {\n background(200);\n\n // pan camera according to angle 'delta'\n cam.pan(delta);\n\n // every 160 frames, switch direction\n if (frameCount % 160 === 0) {\n delta *= -1;\n }\n\n rotateX(frameCount * 0.01);\n translate(-100, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n}\n\n
" + ], + alt: + 'camera view pans left and right across a series of rotating 3D boxes.', + class: 'p5.Camera', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 545, + description: '

Tilting rotates the camera view up and down.

\n', + itemtype: 'method', + name: 'tilt', + params: [ + { + name: 'angle', + description: + '

amount to rotate camera in current\nangleMode units.\nGreater than 0 values rotate counterclockwise (to the left).

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\nlet cam;\nlet delta = 0.01;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n normalMaterial();\n cam = createCamera();\n // set initial tilt\n cam.tilt(-0.8);\n}\n\nfunction draw() {\n background(200);\n\n // pan camera according to angle 'delta'\n cam.tilt(delta);\n\n // every 160 frames, switch direction\n if (frameCount % 160 === 0) {\n delta *= -1;\n }\n\n rotateY(frameCount * 0.01);\n translate(0, -100, 0);\n box(20);\n translate(0, 35, 0);\n box(20);\n translate(0, 35, 0);\n box(20);\n translate(0, 35, 0);\n box(20);\n translate(0, 35, 0);\n box(20);\n translate(0, 35, 0);\n box(20);\n translate(0, 35, 0);\n box(20);\n}\n\n
" + ], + alt: 'camera view tilts up and down across a series of rotating 3D boxes.', + class: 'p5.Camera', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 603, + description: + '

Reorients the camera to look at a position in world space.

\n', + itemtype: 'method', + name: 'lookAt', + params: [ + { + name: 'x', + description: '

x position of a point in world space

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y position of a point in world space

\n', + type: 'Number' + }, + { + name: 'z', + description: '

z position of a point in world space

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\nlet cam;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n normalMaterial();\n cam = createCamera();\n}\n\nfunction draw() {\n background(200);\n\n // look at a new random point every 60 frames\n if (frameCount % 60 === 0) {\n cam.lookAt(random(-100, 100), random(-50, 50), 0);\n }\n\n rotateX(frameCount * 0.01);\n translate(-100, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n}\n\n
' + ], + alt: + 'camera view of rotating 3D cubes changes to look at a new random\npoint every second .', + class: 'p5.Camera', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 670, + description: + '

Sets a camera's position and orientation. This is equivalent to calling\ncamera() on a p5.Camera object.

\n', + itemtype: 'method', + name: 'camera', + class: 'p5.Camera', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 751, + description: + '

Move camera along its local axes while maintaining current camera orientation.

\n', + itemtype: 'method', + name: 'move', + params: [ + { + name: 'x', + description: + '

amount to move along camera's left-right axis

\n', + type: 'Number' + }, + { + name: 'y', + description: '

amount to move along camera's up-down axis

\n', + type: 'Number' + }, + { + name: 'z', + description: + '

amount to move along camera's forward-backward axis

\n', + type: 'Number' + } + ], + example: [ + '\n
\n\n// see the camera move along its own axes while maintaining its orientation\nlet cam;\nlet delta = 0.5;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n normalMaterial();\n cam = createCamera();\n}\n\nfunction draw() {\n background(200);\n\n // move the camera along its local axes\n cam.move(delta, delta, 0);\n\n // every 100 frames, switch direction\n if (frameCount % 150 === 0) {\n delta *= -1;\n }\n\n translate(-10, -10, 0);\n box(50, 8, 50);\n translate(15, 15, 0);\n box(50, 8, 50);\n translate(15, 15, 0);\n box(50, 8, 50);\n translate(15, 15, 0);\n box(50, 8, 50);\n translate(15, 15, 0);\n box(50, 8, 50);\n translate(15, 15, 0);\n box(50, 8, 50);\n}\n\n
' + ], + alt: + 'camera view moves along a series of 3D boxes, maintaining the same\norientation throughout the move', + class: 'p5.Camera', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 823, + description: + '

Set camera position in world-space while maintaining current camera\norientation.

\n', + itemtype: 'method', + name: 'setPosition', + params: [ + { + name: 'x', + description: '

x position of a point in world space

\n', + type: 'Number' + }, + { + name: 'y', + description: '

y position of a point in world space

\n', + type: 'Number' + }, + { + name: 'z', + description: '

z position of a point in world space

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\n// press '1' '2' or '3' keys to set camera position\n\nlet cam;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n normalMaterial();\n cam = createCamera();\n}\n\nfunction draw() {\n background(200);\n\n // '1' key\n if (keyIsDown(49)) {\n cam.setPosition(30, 0, 80);\n }\n // '2' key\n if (keyIsDown(50)) {\n cam.setPosition(0, 0, 80);\n }\n // '3' key\n if (keyIsDown(51)) {\n cam.setPosition(-30, 0, 80);\n }\n\n box(20);\n}\n\n
" + ], + alt: + 'camera position changes as the user presses keys, altering view of a 3D box', + class: 'p5.Camera', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Camera.js', + line: 1088, + description: + '

Sets rendererGL's current camera to a p5.Camera object. Allows switching\nbetween multiple cameras.

\n', + itemtype: 'method', + name: 'setCamera', + params: [ + { + name: 'cam', + description: '

p5.Camera object

\n', + type: 'p5.Camera' + } + ], + example: [ + '\n
\n\nlet cam1, cam2;\nlet currentCamera;\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n normalMaterial();\n\n cam1 = createCamera();\n cam2 = createCamera();\n cam2.setPosition(30, 0, 50);\n cam2.lookAt(0, 0, 0);\n cam2.ortho();\n\n // set variable for previously active camera:\n currentCamera = 1;\n}\n\nfunction draw() {\n background(200);\n\n // camera 1:\n cam1.lookAt(0, 0, 0);\n cam1.setPosition(sin(frameCount / 60) * 200, 0, 100);\n\n // every 100 frames, switch between the two cameras\n if (frameCount % 100 === 0) {\n if (currentCamera === 1) {\n setCamera(cam1);\n currentCamera = 0;\n } else {\n setCamera(cam2);\n currentCamera = 1;\n }\n }\n\n drawBoxes();\n}\n\nfunction drawBoxes() {\n rotateX(frameCount * 0.01);\n translate(-100, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n translate(35, 0, 0);\n box(20);\n}\n\n
' + ], + alt: + 'Canvas switches between two camera views, each showing a series of spinning\n3D boxes.', + class: 'p5', + module: 'Lights, Camera', + submodule: 'Camera' + }, + { + file: 'src/webgl/p5.Geometry.js', + line: 66, + itemtype: 'method', + name: 'computeFaces', + chainable: 1, + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + { + file: 'src/webgl/p5.Geometry.js', + line: 108, + description: + '

computes smooth normals per vertex as an average of each\nface.

\n', + itemtype: 'method', + name: 'computeNormals', + chainable: 1, + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + { + file: 'src/webgl/p5.Geometry.js', + line: 147, + description: + '

Averages the vertex normals. Used in curved\nsurfaces

\n', + itemtype: 'method', + name: 'averageNormals', + chainable: 1, + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + { + file: 'src/webgl/p5.Geometry.js', + line: 168, + description: + '

Averages pole normals. Used in spherical primitives

\n', + itemtype: 'method', + name: 'averagePoleNormals', + chainable: 1, + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + { + file: 'src/webgl/p5.Geometry.js', + line: 261, + description: + '

Modifies all vertices to be centered within the range -100 to 100.

\n', + itemtype: 'method', + name: 'normalize', + chainable: 1, + class: 'p5.Geometry', + module: 'Lights, Camera' + }, + { + file: 'src/webgl/p5.RendererGL.js', + line: 263, + description: + '

Set attributes for the WebGL Drawing context.\nThis is a way of adjusting how the WebGL\nrenderer works to fine-tune the display and performance.\n

\nNote that this will reinitialize the drawing context\nif called after the WebGL canvas is made.\n

\nIf an object is passed as the parameter, all attributes\nnot declared in the object will be set to defaults.\n

\nThe available attributes are:\n
\nalpha - indicates if the canvas contains an alpha buffer\ndefault is true\n

\ndepth - indicates whether the drawing buffer has a depth buffer\nof at least 16 bits - default is true\n

\nstencil - indicates whether the drawing buffer has a stencil buffer\nof at least 8 bits\n

\nantialias - indicates whether or not to perform anti-aliasing\ndefault is false\n

\npremultipliedAlpha - indicates that the page compositor will assume\nthe drawing buffer contains colors with pre-multiplied alpha\ndefault is false\n

\npreserveDrawingBuffer - if true the buffers will not be cleared and\nand will preserve their values until cleared or overwritten by author\n(note that p5 clears automatically on draw loop)\ndefault is true\n

\nperPixelLighting - if true, per-pixel lighting will be used in the\nlighting shader.\ndefault is false\n

\n', + itemtype: 'method', + name: 'setAttributes', + example: [ + "\n
\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(255);\n push();\n rotateZ(frameCount * 0.02);\n rotateX(frameCount * 0.02);\n rotateY(frameCount * 0.02);\n fill(0, 0, 0);\n box(50);\n pop();\n}\n\n
\n
\nNow with the antialias attribute set to true.\n
\n
\n\nfunction setup() {\n setAttributes('antialias', true);\n createCanvas(100, 100, WEBGL);\n}\n\nfunction draw() {\n background(255);\n push();\n rotateZ(frameCount * 0.02);\n rotateX(frameCount * 0.02);\n rotateY(frameCount * 0.02);\n fill(0, 0, 0);\n box(50);\n pop();\n}\n\n
\n\n
\n\n// press the mouse button to enable perPixelLighting\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n noStroke();\n fill(255);\n}\n\nvar lights = [\n { c: '#f00', t: 1.12, p: 1.91, r: 0.2 },\n { c: '#0f0', t: 1.21, p: 1.31, r: 0.2 },\n { c: '#00f', t: 1.37, p: 1.57, r: 0.2 },\n { c: '#ff0', t: 1.12, p: 1.91, r: 0.7 },\n { c: '#0ff', t: 1.21, p: 1.31, r: 0.7 },\n { c: '#f0f', t: 1.37, p: 1.57, r: 0.7 }\n];\n\nfunction draw() {\n var t = millis() / 1000 + 1000;\n background(0);\n directionalLight(color('#222'), 1, 1, 1);\n\n for (var i = 0; i < lights.length; i++) {\n var light = lights[i];\n pointLight(\n color(light.c),\n p5.Vector.fromAngles(t * light.t, t * light.p, width * light.r)\n );\n }\n\n specularMaterial(255);\n sphere(width * 0.1);\n\n rotateX(t * 0.77);\n rotateY(t * 0.83);\n rotateZ(t * 0.91);\n torus(width * 0.3, width * 0.07, 24, 10);\n}\n\nfunction mousePressed() {\n setAttributes('perPixelLighting', true);\n noStroke();\n fill(255);\n}\nfunction mouseReleased() {\n setAttributes('perPixelLighting', false);\n noStroke();\n fill(255);\n}\n\n
" + ], + alt: 'a rotating cube with smoother edges', + class: 'p5', + module: 'Rendering', + submodule: 'Rendering', + overloads: [ + { + line: 263, + params: [ + { + name: 'key', + description: '

Name of attribute

\n', + type: 'String' + }, + { + name: 'value', + description: '

New value of named attribute

\n', + type: 'Boolean' + } + ] + }, + { + line: 402, + params: [ + { + name: 'obj', + description: '

object with key-value pairs

\n', + type: 'Object' + } + ] + } + ] + }, + { + file: 'src/webgl/p5.Shader.js', + line: 269, + description: + '

Wrapper around gl.uniform functions.\nAs we store uniform info in the shader we can use that\nto do type checking on the supplied data and call\nthe appropriate function.

\n', + itemtype: 'method', + name: 'setUniform', + chainable: 1, + params: [ + { + name: 'uniformName', + description: '

the name of the uniform in the\nshader program

\n', + type: 'String' + }, + { + name: 'data', + description: + '

the data to be associated\nwith that uniform; type varies (could be a single numerical value, array,\nmatrix, or texture / sampler reference)

\n', + type: 'Object|Number|Boolean|Number[]' + } + ], + example: [ + "\n
\n\n// Click within the image to toggle the value of uniforms\n// Note: for an alternative approach to the same example,\n// involving toggling between shaders please refer to:\n// https://p5js.org/reference/#/p5/shader\n\nlet grad;\nlet showRedGreen = false;\n\nfunction preload() {\n // note that we are using two instances\n // of the same vertex and fragment shaders\n grad = loadShader('assets/shader.vert', 'assets/shader-gradient.frag');\n}\n\nfunction setup() {\n createCanvas(100, 100, WEBGL);\n shader(grad);\n noStroke();\n}\n\nfunction draw() {\n // update the offset values for each scenario,\n // moving the \"grad\" shader in either vertical or\n // horizontal direction each with differing colors\n\n if (showRedGreen === true) {\n grad.setUniform('colorCenter', [1, 0, 0]);\n grad.setUniform('colorBackground', [0, 1, 0]);\n grad.setUniform('offset', [sin(millis() / 2000), 1]);\n } else {\n grad.setUniform('colorCenter', [1, 0.5, 0]);\n grad.setUniform('colorBackground', [0.226, 0, 0.615]);\n grad.setUniform('offset', [0, sin(millis() / 2000) + 1]);\n }\n quad(-1, -1, 1, -1, 1, 1, -1, 1);\n}\n\nfunction mouseClicked() {\n showRedGreen = !showRedGreen;\n}\n\n
" + ], + alt: + 'canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed.', + class: 'p5.Shader', + module: 'Lights, Camera', + submodule: 'Shaders' + }, + { + file: 'lib/addons/p5.dom.js', + line: 40, + description: + '

Searches the page for an element with the given ID, class, or tag name (using the '#' or '.'\nprefixes to specify an ID or class respectively, and none for a tag) and returns it as\na p5.Element. If a class or tag name is given with more than 1 element,\nonly the first element will be returned.\nThe DOM node itself can be accessed with .elt.\nReturns null if none found. You can also specify a container to search within.

\n', + itemtype: 'method', + name: 'select', + params: [ + { + name: 'name', + description: '

id, class, or tag name of element to search for

\n', + type: 'String' + }, + { + name: 'container', + description: + '

id, p5.Element, or\n HTML element to search within

\n', + type: 'String|p5.Element|HTMLElement', + optional: true + } + ], + return: { + description: + 'p5.Element containing node found', + type: 'p5.Element|null' + }, + example: [ + "\n
\nfunction setup() {\n createCanvas(100, 100);\n //translates canvas 50px down\n select('canvas').position(100, 100);\n}\n
\n
\n// these are all valid calls to select()\nvar a = select('#moo');\nvar b = select('#blah', '#myContainer');\nvar c, e;\nif (b) {\n c = select('#foo', b);\n}\nvar d = document.getElementById('beep');\nif (d) {\n e = select('p', d);\n}\n[a, b, c, d, e]; // unused\n
\n" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 107, + description: + '

Searches the page for elements with the given class or tag name (using the '.' prefix\nto specify a class and no prefix for a tag) and returns them as p5.Elements\nin an array.\nThe DOM node itself can be accessed with .elt.\nReturns an empty array if none found.\nYou can also specify a container to search within.

\n', + itemtype: 'method', + name: 'selectAll', + params: [ + { + name: 'name', + description: '

class or tag name of elements to search for

\n', + type: 'String' + }, + { + name: 'container', + description: + '

id, p5.Element, or HTML element to search within

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'Array of p5.Elements containing nodes found', + type: 'p5.Element[]' + }, + example: [ + "\n
\nfunction setup() {\n createButton('btn');\n createButton('2nd btn');\n createButton('3rd btn');\n var buttons = selectAll('button');\n\n for (var i = 0; i < buttons.length; i++) {\n buttons[i].size(100, 100);\n }\n}\n
\n
\n// these are all valid calls to selectAll()\nvar a = selectAll('.moo');\na = selectAll('div');\na = selectAll('button', '#myContainer');\n\nvar d = select('#container');\na = selectAll('p', d);\n\nvar f = document.getElementById('beep');\na = select('.blah', f);\n\na; // unused\n
\n" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 168, + description: '

Helper function for select and selectAll

\n', + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 184, + description: '

Helper function for getElement and getElements.

\n', + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 218, + description: + '

Removes all elements created by p5, except any canvas / graphics\nelements created by createCanvas or createGraphics.\nEvent handlers are removed, and element is removed from the DOM.

\n', + itemtype: 'method', + name: 'removeElements', + example: [ + "\n
\nfunction setup() {\n createCanvas(100, 100);\n createDiv('this is some text');\n createP('this is a paragraph');\n}\nfunction mousePressed() {\n removeElements(); // this will remove the div and p, not canvas\n}\n
\n" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 245, + description: + '

The .changed() function is called when the value of an\nelement changes.\nThis can be used to attach an element specific event listener.

\n', + itemtype: 'method', + name: 'changed', + params: [ + { + name: 'fxn', + description: + '

function to be fired when the value of\n an element changes.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\nvar sel;\n\nfunction setup() {\n textAlign(CENTER);\n background(200);\n sel = createSelect();\n sel.position(10, 10);\n sel.option('pear');\n sel.option('kiwi');\n sel.option('grape');\n sel.changed(mySelectEvent);\n}\n\nfunction mySelectEvent() {\n var item = sel.value();\n background(200);\n text(\"it's a \" + item + '!', 50, 50);\n}\n
\n\n
\nvar checkbox;\nvar cnv;\n\nfunction setup() {\n checkbox = createCheckbox(' fill');\n checkbox.changed(changeFill);\n cnv = createCanvas(100, 100);\n cnv.position(0, 30);\n noFill();\n}\n\nfunction draw() {\n background(200);\n ellipse(50, 50, 50, 50);\n}\n\nfunction changeFill() {\n if (checkbox.checked()) {\n fill(0);\n } else {\n noFill();\n }\n}\n
" + ], + alt: + 'dropdown: pear, kiwi, grape. When selected text "its a" + selection shown.', + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 313, + description: + '

The .input() function is called when any user input is\ndetected with an element. The input event is often used\nto detect keystrokes in a input element, or changes on a\nslider element. This can be used to attach an element specific\nevent listener.

\n', + itemtype: 'method', + name: 'input', + params: [ + { + name: 'fxn', + description: + '

function to be fired when any user input is\n detected within the element.\n if false is passed instead, the previously\n firing function will no longer fire.

\n', + type: 'Function|Boolean' + } + ], + chainable: 1, + example: [ + "\n
\n// Open your console to see the output\nfunction setup() {\n var inp = createInput('');\n inp.input(myInputEvent);\n}\n\nfunction myInputEvent() {\n console.log('you are typing: ', this.value());\n}\n
" + ], + alt: 'no display.', + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 348, + description: '

Helpers for create methods.

\n', + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 361, + description: + '

Creates a <div></div> element in the DOM with given inner HTML.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createDiv', + params: [ + { + name: 'html', + description: '

inner HTML for element created

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\ncreateDiv('this is some text');\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 375, + description: + '

Creates a <p></p> element in the DOM with given inner HTML. Used\nfor paragraph length text.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createP', + params: [ + { + name: 'html', + description: '

inner HTML for element created

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\ncreateP('this is some text');\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 390, + description: + '

Creates a <span></span> element in the DOM with given inner HTML.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createSpan', + params: [ + { + name: 'html', + description: '

inner HTML for element created

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\ncreateSpan('this is some text');\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 413, + description: + '

Creates an <img> element in the DOM with given src and\nalternate text.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createImg', + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\ncreateImg('http://p5js.org/img/asterisk-01.png');\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 413, + params: [ + { + name: 'src', + description: '

src path or url for image

\n', + type: 'String' + }, + { + name: 'alt', + description: + '

alternate text to be used if image does not load

\n', + type: 'String', + optional: true + }, + { + name: 'successCallback', + description: + '

callback to be called once image data is loaded

\n', + type: 'Function', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + } + }, + { + line: 429, + params: [ + { + name: 'src', + description: '', + type: 'String' + }, + { + name: 'successCallback', + description: '', + type: 'Function' + } + ], + return: { + description: '', + type: 'Object|p5.Element' + } + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 463, + description: + '

Creates an <a></a> element in the DOM for including a hyperlink.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createA', + params: [ + { + name: 'href', + description: '

url of page to link to

\n', + type: 'String' + }, + { + name: 'html', + description: '

inner html of link element to display

\n', + type: 'String' + }, + { + name: 'target', + description: + '

target where new link should open,\n could be _blank, _self, _parent, _top.

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\ncreateA('http://p5js.org/', 'this is a link');\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 488, + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 490, + description: + '

Creates a slider <input></input> element in the DOM.\nUse .size() to set the display length of the slider.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createSlider', + params: [ + { + name: 'min', + description: '

minimum value of the slider

\n', + type: 'Number' + }, + { + name: 'max', + description: '

maximum value of the slider

\n', + type: 'Number' + }, + { + name: 'value', + description: '

default value of the slider

\n', + type: 'Number', + optional: true + }, + { + name: 'step', + description: + '

step size for each tick of the slider (if step is set to 0, the slider will move continuously from the minimum to the maximum value)

\n', + type: 'Number', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\nvar slider;\nfunction setup() {\n slider = createSlider(0, 255, 100);\n slider.position(10, 10);\n slider.style('width', '80px');\n}\n\nfunction draw() {\n var val = slider.value();\n background(val);\n}\n
\n\n
\nvar slider;\nfunction setup() {\n colorMode(HSB);\n slider = createSlider(0, 360, 60, 40);\n slider.position(10, 10);\n slider.style('width', '80px');\n}\n\nfunction draw() {\n var val = slider.value();\n background(val, 100, 100, 1);\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 547, + description: + '

Creates a <button></button> element in the DOM.\nUse .size() to set the display size of the button.\nUse .mousePressed() to specify behavior on press.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createButton', + params: [ + { + name: 'label', + description: '

label displayed on the button

\n', + type: 'String' + }, + { + name: 'value', + description: '

value of the button

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\nvar button;\nfunction setup() {\n createCanvas(100, 100);\n background(0);\n button = createButton('click me');\n button.position(19, 19);\n button.mousePressed(changeBG);\n}\n\nfunction changeBG() {\n var val = random(255);\n background(val);\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 583, + description: + '

Creates a checkbox <input></input> element in the DOM.\nCalling .checked() on a checkbox returns if it is checked or not

\n', + itemtype: 'method', + name: 'createCheckbox', + params: [ + { + name: 'label', + description: '

label displayed after checkbox

\n', + type: 'String', + optional: true + }, + { + name: 'value', + description: + '

value of the checkbox; checked is true, unchecked is false

\n', + type: 'Boolean', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\nvar checkbox;\n\nfunction setup() {\n checkbox = createCheckbox('label', false);\n checkbox.changed(myCheckedEvent);\n}\n\nfunction myCheckedEvent() {\n if (this.checked()) {\n console.log('Checking!');\n } else {\n console.log('Unchecking!');\n }\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 651, + description: + '

Creates a dropdown menu <select></select> element in the DOM.\nIt also helps to assign select-box methods to p5.Element when selecting existing select box

\n', + itemtype: 'method', + name: 'createSelect', + return: { + description: '', + type: 'p5.Element' + }, + example: [ + "\n
\nvar sel;\n\nfunction setup() {\n textAlign(CENTER);\n background(200);\n sel = createSelect();\n sel.position(10, 10);\n sel.option('pear');\n sel.option('kiwi');\n sel.option('grape');\n sel.changed(mySelectEvent);\n}\n\nfunction mySelectEvent() {\n var item = sel.value();\n background(200);\n text('It is a ' + item + '!', 50, 50);\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 651, + params: [ + { + name: 'multiple', + description: + '

true if dropdown should support multiple selections

\n', + type: 'Boolean', + optional: true + } + ], + return: { + description: '', + type: 'p5.Element' + } + }, + { + line: 679, + params: [ + { + name: 'existing', + description: '

DOM select element

\n', + type: 'Object' + } + ], + return: { + description: '', + type: 'p5.Element' + } + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 755, + description: + '

Creates a radio button <input></input> element in the DOM.\nThe .option() method can be used to set options for the radio after it is\ncreated. The .value() method will return the currently selected option.

\n', + itemtype: 'method', + name: 'createRadio', + params: [ + { + name: 'divId', + description: + '

the id and name of the created div and input field respectively

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\nvar radio;\n\nfunction setup() {\n radio = createRadio();\n radio.option('black');\n radio.option('white');\n radio.option('gray');\n radio.style('width', '60px');\n textAlign(CENTER);\n fill(255, 0, 0);\n}\n\nfunction draw() {\n var val = radio.value();\n background(val);\n text(val, width / 2, height / 2);\n}\n
\n
\nvar radio;\n\nfunction setup() {\n radio = createRadio();\n radio.option('apple', 1);\n radio.option('bread', 2);\n radio.option('juice', 3);\n radio.style('width', '60px');\n textAlign(CENTER);\n}\n\nfunction draw() {\n background(200);\n var val = radio.value();\n if (val) {\n text('item cost is $' + val, width / 2, height / 2);\n }\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 893, + description: + '

Creates a colorPicker element in the DOM for color input.\nThe .value() method will return a hex string (#rrggbb) of the color.\nThe .color() method will return a p5.Color object with the current chosen color.

\n', + itemtype: 'method', + name: 'createColorPicker', + params: [ + { + name: 'value', + description: '

default color of element

\n', + type: 'String|p5.Color', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\n\nvar inp1, inp2;\nfunction setup() {\n createCanvas(100, 100);\n background('grey');\n inp1 = createColorPicker('#ff0000');\n inp2 = createColorPicker(color('yellow'));\n inp1.input(setShade1);\n inp2.input(setShade2);\n setMidShade();\n}\n\nfunction setMidShade() {\n // Finding a shade between the two\n var commonShade = lerpColor(inp1.color(), inp2.color(), 0.5);\n fill(commonShade);\n rect(20, 20, 60, 60);\n}\n\nfunction setShade1() {\n setMidShade();\n console.log('You are choosing shade 1 to be : ', this.value());\n}\nfunction setShade2() {\n setMidShade();\n console.log('You are choosing shade 2 to be : ', this.value());\n}\n\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 967, + description: + '

Creates an <input></input> element in the DOM for text input.\nUse .size() to set the display length of the box.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createInput', + params: [ + { + name: 'value', + description: '

default value of the input box

\n', + type: 'String', + optional: true + }, + { + name: 'type', + description: + '

type of text, ie text, password etc. Defaults to text

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\nfunction setup() {\n var inp = createInput('');\n inp.input(myInputEvent);\n}\n\nfunction myInputEvent() {\n console.log('you are typing: ', this.value());\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 997, + description: + '

Creates an <input></input> element in the DOM of type 'file'.\nThis allows users to select local files for use in a sketch.

\n', + itemtype: 'method', + name: 'createFileInput', + params: [ + { + name: 'callback', + description: '

callback function for when a file loaded

\n', + type: 'Function', + optional: true + }, + { + name: 'multiple', + description: '

optional to allow multiple files selected

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created DOM element', + type: 'p5.Element' + }, + example: [ + "\n
\nlet input;\nlet img;\n\nfunction setup() {\n input = createFileInput(handleFile);\n input.position(0, 0);\n}\n\nfunction draw() {\n background(255);\n if (img) {\n image(img, 0, 0, width, height);\n }\n}\n\nfunction handleFile(file) {\n print(file);\n if (file.type === 'image') {\n img = createImg(file.data);\n img.hide();\n } else {\n img = null;\n }\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1070, + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1112, + description: + '

Creates an HTML5 <video> element in the DOM for simple playback\nof audio/video. Shown by default, can be hidden with .hide()\nand drawn into canvas using video(). Appends to the container\nnode if one is specified, otherwise appends to body. The first parameter\ncan be either a single string path to a video file, or an array of string\npaths to different formats of the same video. This is useful for ensuring\nthat your video can play across different browsers, as each supports\ndifferent formats. See this\npage for further information about supported formats.

\n', + itemtype: 'method', + name: 'createVideo', + params: [ + { + name: 'src', + description: + '

path to a video file, or array of paths for\n supporting different browsers

\n', + type: 'String|String[]' + }, + { + name: 'callback', + description: + '

callback function to be called upon\n 'canplaythrough' event fire, that is, when the\n browser can play the media, and estimates that\n enough data has been loaded to play the media\n up to its end without having to stop for\n further buffering of content

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'pointer to video p5.Element', + type: 'p5.MediaElement' + }, + example: [ + "\n
\nvar vid;\nfunction setup() {\n noCanvas();\n\n vid = createVideo(\n ['assets/small.mp4', 'assets/small.ogv', 'assets/small.webm'],\n vidLoad\n );\n\n vid.size(100, 100);\n}\n\n// This function is called when the video loads\nfunction vidLoad() {\n vid.loop();\n vid.volume(0);\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1159, + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1161, + description: + "

Creates a hidden HTML5 <audio> element in the DOM for simple audio\nplayback. Appends to the container node if one is specified,\notherwise appends to body. The first parameter\ncan be either a single string path to a audio file, or an array of string\npaths to different formats of the same audio. This is useful for ensuring\nthat your audio can play across different browsers, as each supports\ndifferent formats. See this\npage for further information about supported formats.

\n", + itemtype: 'method', + name: 'createAudio', + params: [ + { + name: 'src', + description: + '

path to an audio file, or array of paths\n for supporting different browsers

\n', + type: 'String|String[]', + optional: true + }, + { + name: 'callback', + description: + '

callback function to be called upon\n 'canplaythrough' event fire, that is, when the\n browser can play the media, and estimates that\n enough data has been loaded to play the media\n up to its end without having to stop for\n further buffering of content

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'pointer to audio p5.Element', + type: 'p5.MediaElement' + }, + example: [ + "\n
\nvar ele;\nfunction setup() {\n ele = createAudio('assets/beat.mp3');\n\n // here we set the element to autoplay\n // The element will play as soon\n // as it is able to do so.\n ele.autoplay(true);\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1199, + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1201, + itemtype: 'property', + name: 'VIDEO', + type: 'String', + final: 1, + category: ['Constants'], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1207, + itemtype: 'property', + name: 'AUDIO', + type: 'String', + final: 1, + category: ['Constants'], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1244, + description: + '

Creates a new HTML5 <video> element that contains the audio/video\nfeed from a webcam. The element is separate from the canvas and is\ndisplayed by default. The element can be hidden using .hide(). The feed\ncan be drawn onto the canvas using image(). The loadedmetadata property can\nbe used to detect when the element has fully loaded (see second example).

\n

More specific properties of the feed can be passing in a Constraints object.\nSee the\n W3C\nspec for possible properties. Note that not all of these are supported\nby all browsers.

\n

Security note: A new browser security specification requires that getUserMedia,\nwhich is behind createCapture(), only works when you're running the code locally,\nor on HTTPS. Learn more here\nand here.

', + itemtype: 'method', + name: 'createCapture', + params: [ + { + name: 'type', + description: + '

type of capture, either VIDEO or\n AUDIO if none specified, default both,\n or a Constraints object

\n', + type: 'String|Constant|Object' + }, + { + name: 'callback', + description: + '

function to be called once\n stream has loaded

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'capture video p5.Element', + type: 'p5.Element' + }, + example: [ + "\n
\nvar capture;\n\nfunction setup() {\n createCanvas(480, 480);\n capture = createCapture(VIDEO);\n capture.hide();\n}\n\nfunction draw() {\n image(capture, 0, 0, width, width * capture.height / capture.width);\n filter(INVERT);\n}\n
\n
\nfunction setup() {\n createCanvas(480, 120);\n var constraints = {\n video: {\n mandatory: {\n minWidth: 1280,\n minHeight: 720\n },\n optional: [{ maxFrameRate: 10 }]\n },\n audio: true\n };\n createCapture(constraints, function(stream) {\n console.log(stream);\n });\n}\n
\n
\nvar capture;\n\nfunction setup() {\n createCanvas(640, 480);\n capture = createCapture(VIDEO);\n}\nfunction draw() {\n background(0);\n if (capture.loadedmetadata) {\n var c = capture.get(0, 0, 100, 100);\n image(c, 0, 0);\n }\n}\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1381, + description: + '

Creates element with given tag in the DOM with given content.\nAppends to the container node if one is specified, otherwise\nappends to body.

\n', + itemtype: 'method', + name: 'createElement', + params: [ + { + name: 'tag', + description: '

tag for the new element

\n', + type: 'String' + }, + { + name: 'content', + description: '

html content to be inserted into the element

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'pointer to p5.Element holding created node', + type: 'p5.Element' + }, + example: [ + "\n
\ncreateElement('h2', 'im an h2 p5.element!');\n
" + ], + class: 'p5', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1407, + description: '

Adds specified class to the element.

\n', + itemtype: 'method', + name: 'addClass', + params: [ + { + name: 'class', + description: '

name of class to add

\n', + type: 'String' + } + ], + chainable: 1, + example: [ + "\n
\n var div = createDiv('div');\n div.addClass('myClass');\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1432, + description: '

Removes specified class from the element.

\n', + itemtype: 'method', + name: 'removeClass', + params: [ + { + name: 'class', + description: '

name of class to remove

\n', + type: 'String' + } + ], + chainable: 1, + example: [ + "\n
\n // In this example, a class is set when the div is created\n // and removed when mouse is pressed. This could link up\n // with a CSS style rule to toggle style properties.\nvar div;\nfunction setup() {\n div = createDiv('div');\n div.addClass('myClass');\n }\nfunction mousePressed() {\n div.removeClass('myClass');\n }\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1463, + description: '

Checks if specified class already set to element

\n', + itemtype: 'method', + name: 'hasClass', + return: { + description: 'a boolean value if element has specified class', + type: 'Boolean' + }, + params: [ + { + name: 'c', + description: '

class name of class to check

\n', + type: 'String' + } + ], + example: [ + "\n
\n var div;\nfunction setup() {\n div = createDiv('div');\n div.addClass('show');\n }\nfunction mousePressed() {\n if (div.hasClass('show')) {\n div.addClass('show');\n } else {\n div.removeClass('show');\n }\n }\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1492, + description: '

Toggles element class

\n', + itemtype: 'method', + name: 'toggleClass', + params: [ + { + name: 'c', + description: '

class name to toggle

\n', + type: 'String' + } + ], + chainable: 1, + example: [ + "\n
\n var div;\nfunction setup() {\n div = createDiv('div');\n div.addClass('show');\n }\nfunction mousePressed() {\n div.toggleClass('show');\n }\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1525, + description: + '

Attaches the element as a child to the parent specified.\n Accepts either a string ID, DOM node, or p5.Element.\n If no argument is specified, an array of children DOM nodes is returned.

\n', + itemtype: 'method', + name: 'child', + return: { + description: 'an array of child nodes', + type: 'Node[]' + }, + example: [ + "\n
\n var div0 = createDiv('this is the parent');\n var div1 = createDiv('this is the child');\n div0.child(div1); // use p5.Element\n
\n
\n var div0 = createDiv('this is the parent');\n var div1 = createDiv('this is the child');\n div1.id('apples');\n div0.child('apples'); // use id\n
\n
\n // this example assumes there is a div already on the page\n // with id \"myChildDiv\"\n var div0 = createDiv('this is the parent');\n var elt = document.getElementById('myChildDiv');\n div0.child(elt); // use element from page\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 1525, + params: [], + return: { + description: 'an array of child nodes', + type: 'Node[]' + } + }, + { + line: 1553, + params: [ + { + name: 'child', + description: + '

the ID, DOM node, or p5.Element\n to add to the current element

\n', + type: 'String|p5.Element', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 1575, + description: + '

Centers a p5 Element either vertically, horizontally,\nor both, relative to its parent or according to\nthe body if the Element has no parent. If no argument is passed\nthe Element is aligned both vertically and horizontally.

\n', + itemtype: 'method', + name: 'center', + params: [ + { + name: 'align', + description: + '

passing 'vertical', 'horizontal' aligns element accordingly

\n', + type: 'String', + optional: true + } + ], + chainable: 1, + example: [ + "\n
\nfunction setup() {\n var div = createDiv('').size(10, 10);\n div.style('background-color', 'orange');\n div.center();\n}\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1629, + description: + '

If an argument is given, sets the inner HTML of the element,\n replacing any existing html. If true is included as a second\n argument, html is appended instead of replacing existing html.\n If no arguments are given, returns\n the inner HTML of the element.

\n', + itemtype: 'method', + name: 'html', + return: { + description: 'the inner HTML of the element', + type: 'String' + }, + example: [ + "\n
\n var div = createDiv('').size(100, 100);\n div.html('hi');\n
\n
\n var div = createDiv('Hello ').size(100, 100);\n div.html('World', true);\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 1629, + params: [], + return: { + description: 'the inner HTML of the element', + type: 'String' + } + }, + { + line: 1650, + params: [ + { + name: 'html', + description: '

the HTML to be placed inside the element

\n', + type: 'String', + optional: true + }, + { + name: 'append', + description: '

whether to append HTML to existing

\n', + type: 'Boolean', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 1668, + description: + '

Sets the position of the element relative to (0, 0) of the\n window. Essentially, sets position:absolute and left and top\n properties of style. If no arguments given returns the x and y position\n of the element in an object.

\n', + itemtype: 'method', + name: 'position', + return: { + description: 'the x and y position of the element in an object', + type: 'Object' + }, + example: [ + "\n
\n function setup() {\n var cnv = createCanvas(100, 100);\n // positions canvas 50px to the right and 100px\n // below upper left corner of the window\n cnv.position(50, 100);\n }\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 1668, + params: [], + return: { + description: 'the x and y position of the element in an object', + type: 'Object' + } + }, + { + line: 1687, + params: [ + { + name: 'x', + description: '

x-position relative to upper left of window

\n', + type: 'Number', + optional: true + }, + { + name: 'y', + description: '

y-position relative to upper left of window

\n', + type: 'Number', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 1762, + description: + '

Sets the given style (css) property (1st arg) of the element with the\ngiven value (2nd arg). If a single argument is given, .style()\nreturns the value of the given property; however, if the single argument\nis given in css syntax ('text-align:center'), .style() sets the css\nappropriately.

\n', + itemtype: 'method', + name: 'style', + return: { + description: 'value of property', + type: 'String' + }, + example: [ + "\n
\nvar myDiv = createDiv('I like pandas.');\nmyDiv.style('font-size', '18px');\nmyDiv.style('color', '#ff0000');\n
\n
\nvar col = color(25, 23, 200, 50);\nvar button = createButton('button');\nbutton.style('background-color', col);\nbutton.position(10, 10);\n
\n
\nvar myDiv;\nfunction setup() {\n background(200);\n myDiv = createDiv('I like gray.');\n myDiv.position(20, 20);\n}\n\nfunction draw() {\n myDiv.style('font-size', mouseX + 'px');\n}\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 1762, + params: [ + { + name: 'property', + description: '

property to be set

\n', + type: 'String' + } + ], + return: { + description: 'value of property', + type: 'String' + } + }, + { + line: 1797, + params: [ + { + name: 'property', + description: '', + type: 'String' + }, + { + name: 'value', + description: '

value to assign to property

\n', + type: 'String|Number|p5.Color' + } + ], + chainable: 1, + return: { + description: + 'current value of property, if no value is given as second argument', + type: 'String' + } + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 1851, + description: + '

Adds a new attribute or changes the value of an existing attribute\n on the specified element. If no value is specified, returns the\n value of the given attribute, or null if attribute is not set.

\n', + itemtype: 'method', + name: 'attribute', + return: { + description: 'value of attribute', + type: 'String' + }, + example: [ + "\n
\n var myDiv = createDiv('I like pandas.');\n myDiv.attribute('align', 'center');\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 1851, + params: [], + return: { + description: 'value of attribute', + type: 'String' + } + }, + { + line: 1866, + params: [ + { + name: 'attr', + description: '

attribute to set

\n', + type: 'String' + }, + { + name: 'value', + description: '

value to assign to attribute

\n', + type: 'String' + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 1895, + description: '

Removes an attribute on the specified element.

\n', + itemtype: 'method', + name: 'removeAttribute', + params: [ + { + name: 'attr', + description: '

attribute to remove

\n', + type: 'String' + } + ], + chainable: 1, + example: [ + "\n
\n var button;\n var checkbox;\nfunction setup() {\n checkbox = createCheckbox('enable', true);\n checkbox.changed(enableButton);\n button = createButton('button');\n button.position(10, 10);\n }\nfunction enableButton() {\n if (this.checked()) {\n // Re-enable the button\n button.removeAttribute('disabled');\n } else {\n // Disable the button\n button.attribute('disabled', '');\n }\n }\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 1940, + description: + '

Either returns the value of the element if no arguments\ngiven, or sets the value of the element.

\n', + itemtype: 'method', + name: 'value', + return: { + description: 'value of the element', + type: 'String|Number' + }, + example: [ + "\n
\n// gets the value\nvar inp;\nfunction setup() {\n inp = createInput('');\n}\n\nfunction mousePressed() {\n print(inp.value());\n}\n
\n
\n// sets the value\nvar inp;\nfunction setup() {\n inp = createInput('myValue');\n}\n\nfunction mousePressed() {\n inp.value('myValue');\n}\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 1940, + params: [], + return: { + description: 'value of the element', + type: 'String|Number' + } + }, + { + line: 1970, + params: [ + { + name: 'value', + description: '', + type: 'String|Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 1986, + description: + '

Shows the current element. Essentially, setting display:block for the style.

\n', + itemtype: 'method', + name: 'show', + chainable: 1, + example: [ + "\n
\n var div = createDiv('div');\n div.style('display', 'none');\n div.show(); // turns display to block\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2004, + description: + '

Hides the current element. Essentially, setting display:none for the style.

\n', + itemtype: 'method', + name: 'hide', + chainable: 1, + example: [ + "\n
\nvar div = createDiv('this is a div');\ndiv.hide();\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2020, + description: + '

Sets the width and height of the element. AUTO can be used to\n only adjust one dimension at a time. If no arguments are given, it\n returns the width and height of the element in an object. In case of\n elements which need to be loaded, such as images, it is recommended\n to call the function after the element has finished loading.

\n', + itemtype: 'method', + name: 'size', + return: { + description: 'the width and height of the element in an object', + type: 'Object' + }, + example: [ + "\n
\n let div = createDiv('this is a div');\n div.size(100, 100);\n let img = createImg('assets/laDefense.jpg', () => {\n img.size(10, AUTO);\n });\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 2020, + params: [], + return: { + description: 'the width and height of the element in an object', + type: 'Object' + } + }, + { + line: 2039, + params: [ + { + name: 'w', + description: + '

width of the element, either AUTO, or a number

\n', + type: 'Number|Constant' + }, + { + name: 'h', + description: + '

height of the element, either AUTO, or a number

\n', + type: 'Number|Constant', + optional: true + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 2099, + description: '

Removes the element and deregisters all listeners.

\n', + itemtype: 'method', + name: 'remove', + example: [ + "\n
\nvar myDiv = createDiv('this is some text');\nmyDiv.remove();\n
" + ], + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2119, + description: + '

Registers a callback that gets called every time a file that is\ndropped on the element has been loaded.\np5 will load every dropped file into memory and pass it as a p5.File object to the callback.\nMultiple files dropped at the same time will result in multiple calls to the callback.

\n

You can optionally pass a second callback which will be registered to the raw\ndrop event.\nThe callback will thus be provided the original\nDragEvent.\nDropping multiple files at the same time will trigger the second callback once per drop,\nwhereas the first callback will trigger for each loaded file.

\n', + itemtype: 'method', + name: 'drop', + params: [ + { + name: 'callback', + description: + '

callback to receive loaded file, called for each file dropped.

\n', + type: 'Function' + }, + { + name: 'fxn', + description: + '

callback triggered once when files are dropped with the drop event.

\n', + type: 'Function', + optional: true + } + ], + chainable: 1, + example: [ + "\n
\nfunction setup() {\n var c = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('drop file', width / 2, height / 2);\n c.drop(gotFile);\n}\n\nfunction gotFile(file) {\n background(200);\n text('received file:', width / 2, height / 2);\n text(file.name, width / 2, height / 2 + 50);\n}\n
\n\n
\nvar img;\n\nfunction setup() {\n var c = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('drop image', width / 2, height / 2);\n c.drop(gotFile);\n}\n\nfunction draw() {\n if (img) {\n image(img, 0, 0, width, height);\n }\n}\n\nfunction gotFile(file) {\n img = createImg(file.data).hide();\n}\n
" + ], + alt: 'Canvas turns into whatever image is dragged/dropped onto it.', + class: 'p5.Element', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2253, + description: '

Path to the media element source.

\n', + itemtype: 'property', + name: 'src', + return: { + description: 'src', + type: 'String' + }, + example: [ + "\n
\nvar ele;\n\nfunction setup() {\n background(250);\n\n //p5.MediaElement objects are usually created\n //by calling the createAudio(), createVideo(),\n //and createCapture() functions.\n\n //In this example we create\n //a new p5.MediaElement via createAudio().\n ele = createAudio('assets/beat.mp3');\n\n //We'll set up our example so that\n //when you click on the text,\n //an alert box displays the MediaElement's\n //src field.\n textAlign(CENTER);\n text('Click Me!', width / 2, height / 2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it's clicked\n if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {\n //Show our p5.MediaElement's src field\n alert(ele.src);\n }\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2319, + description: '

Play an HTML5 media element.

\n', + itemtype: 'method', + name: 'play', + chainable: 1, + example: [ + "\n
\nvar ele;\n\nfunction setup() {\n //p5.MediaElement objects are usually created\n //by calling the createAudio(), createVideo(),\n //and createCapture() functions.\n\n //In this example we create\n //a new p5.MediaElement via createAudio().\n ele = createAudio('assets/beat.mp3');\n\n background(250);\n textAlign(CENTER);\n text('Click to Play!', width / 2, height / 2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it's clicked\n if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {\n //Here we call the play() function on\n //the p5.MediaElement we created above.\n //This will start the audio sample.\n ele.play();\n\n background(200);\n text('You clicked Play!', width / 2, height / 2);\n }\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2380, + description: + '

Stops an HTML5 media element (sets current time to zero).

\n', + itemtype: 'method', + name: 'stop', + chainable: 1, + example: [ + "\n
\n//This example both starts\n//and stops a sound sample\n//when the user clicks the canvas\n\n//We will store the p5.MediaElement\n//object in here\nvar ele;\n\n//while our audio is playing,\n//this will be set to true\nvar sampleIsPlaying = false;\n\nfunction setup() {\n //Here we create a p5.MediaElement object\n //using the createAudio() function.\n ele = createAudio('assets/beat.mp3');\n background(200);\n textAlign(CENTER);\n text('Click to play!', width / 2, height / 2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it's clicked\n if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {\n background(200);\n\n if (sampleIsPlaying) {\n //if the sample is currently playing\n //calling the stop() function on\n //our p5.MediaElement will stop\n //it and reset its current\n //time to 0 (i.e. it will start\n //at the beginning the next time\n //you play it)\n ele.stop();\n\n sampleIsPlaying = false;\n text('Click to play!', width / 2, height / 2);\n } else {\n //loop our sound element until we\n //call ele.stop() on it.\n ele.loop();\n\n sampleIsPlaying = true;\n text('Click to stop!', width / 2, height / 2);\n }\n }\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2444, + description: '

Pauses an HTML5 media element.

\n', + itemtype: 'method', + name: 'pause', + chainable: 1, + example: [ + "\n
\n//This example both starts\n//and pauses a sound sample\n//when the user clicks the canvas\n\n//We will store the p5.MediaElement\n//object in here\nvar ele;\n\n//while our audio is playing,\n//this will be set to true\nvar sampleIsPlaying = false;\n\nfunction setup() {\n //Here we create a p5.MediaElement object\n //using the createAudio() function.\n ele = createAudio('assets/lucky_dragons.mp3');\n background(200);\n textAlign(CENTER);\n text('Click to play!', width / 2, height / 2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it's clicked\n if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {\n background(200);\n\n if (sampleIsPlaying) {\n //Calling pause() on our\n //p5.MediaElement will stop it\n //playing, but when we call the\n //loop() or play() functions\n //the sample will start from\n //where we paused it.\n ele.pause();\n\n sampleIsPlaying = false;\n text('Click to resume!', width / 2, height / 2);\n } else {\n //loop our sound element until we\n //call ele.pause() on it.\n ele.loop();\n\n sampleIsPlaying = true;\n text('Click to pause!', width / 2, height / 2);\n }\n }\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2506, + description: + '

Set 'loop' to true for an HTML5 media element, and starts playing.

\n', + itemtype: 'method', + name: 'loop', + chainable: 1, + example: [ + "\n
\n//Clicking the canvas will loop\n//the audio sample until the user\n//clicks again to stop it\n\n//We will store the p5.MediaElement\n//object in here\nvar ele;\n\n//while our audio is playing,\n//this will be set to true\nvar sampleIsLooping = false;\n\nfunction setup() {\n //Here we create a p5.MediaElement object\n //using the createAudio() function.\n ele = createAudio('assets/lucky_dragons.mp3');\n background(200);\n textAlign(CENTER);\n text('Click to loop!', width / 2, height / 2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it's clicked\n if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {\n background(200);\n\n if (!sampleIsLooping) {\n //loop our sound element until we\n //call ele.stop() on it.\n ele.loop();\n\n sampleIsLooping = true;\n text('Click to stop!', width / 2, height / 2);\n } else {\n ele.stop();\n\n sampleIsLooping = false;\n text('Click to loop!', width / 2, height / 2);\n }\n }\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2562, + description: + '

Set 'loop' to false for an HTML5 media element. Element will stop\nwhen it reaches the end.

\n', + itemtype: 'method', + name: 'noLoop', + chainable: 1, + example: [ + "\n
\n//This example both starts\n//and stops loop of sound sample\n//when the user clicks the canvas\n\n//We will store the p5.MediaElement\n//object in here\nvar ele;\n//while our audio is playing,\n//this will be set to true\nvar sampleIsPlaying = false;\n\nfunction setup() {\n //Here we create a p5.MediaElement object\n //using the createAudio() function.\n ele = createAudio('assets/beat.mp3');\n background(200);\n textAlign(CENTER);\n text('Click to play!', width / 2, height / 2);\n}\n\nfunction mouseClicked() {\n //here we test if the mouse is over the\n //canvas element when it's clicked\n if (mouseX >= 0 && mouseX <= width && mouseY >= 0 && mouseY <= height) {\n background(200);\n\n if (sampleIsPlaying) {\n ele.noLoop();\n text('No more Loops!', width / 2, height / 2);\n } else {\n ele.loop();\n sampleIsPlaying = true;\n text('Click to stop looping!', width / 2, height / 2);\n }\n }\n}\n
\n" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2614, + description: '

Set HTML5 media element to autoplay or not.

\n', + itemtype: 'method', + name: 'autoplay', + params: [ + { + name: 'autoplay', + description: '

whether the element should autoplay

\n', + type: 'Boolean' + } + ], + chainable: 1, + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2626, + description: + '

Sets volume for this HTML5 media element. If no argument is given,\nreturns the current volume.

\n', + itemtype: 'method', + name: 'volume', + return: { + description: 'current volume', + type: 'Number' + }, + example: [ + "\n
\nvar ele;\nfunction setup() {\n // p5.MediaElement objects are usually created\n // by calling the createAudio(), createVideo(),\n // and createCapture() functions.\n // In this example we create\n // a new p5.MediaElement via createAudio().\n ele = createAudio('assets/lucky_dragons.mp3');\n background(250);\n textAlign(CENTER);\n text('Click to Play!', width / 2, height / 2);\n}\nfunction mouseClicked() {\n // Here we call the volume() function\n // on the sound element to set its volume\n // Volume must be between 0.0 and 1.0\n ele.volume(0.2);\n ele.play();\n background(200);\n text('You clicked Play!', width / 2, height / 2);\n}\n
\n
\nvar audio;\nvar counter = 0;\n\nfunction loaded() {\n audio.play();\n}\n\nfunction setup() {\n audio = createAudio('assets/lucky_dragons.mp3', loaded);\n textAlign(CENTER);\n}\n\nfunction draw() {\n if (counter === 0) {\n background(0, 255, 0);\n text('volume(0.9)', width / 2, height / 2);\n } else if (counter === 1) {\n background(255, 255, 0);\n text('volume(0.5)', width / 2, height / 2);\n } else if (counter === 2) {\n background(255, 0, 0);\n text('volume(0.1)', width / 2, height / 2);\n }\n}\n\nfunction mousePressed() {\n counter++;\n if (counter === 0) {\n audio.volume(0.9);\n } else if (counter === 1) {\n audio.volume(0.5);\n } else if (counter === 2) {\n audio.volume(0.1);\n } else {\n counter = 0;\n audio.volume(0.9);\n }\n}\n\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 2626, + params: [], + return: { + description: 'current volume', + type: 'Number' + } + }, + { + line: 2699, + params: [ + { + name: 'val', + description: '

volume between 0.0 and 1.0

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 2712, + description: + '

If no arguments are given, returns the current playback speed of the\nelement. The speed parameter sets the speed where 2.0 will play the\nelement twice as fast, 0.5 will play at half the speed, and -1 will play\nthe element in normal speed in reverse.(Note that not all browsers support\nbackward playback and even if they do, playback might not be smooth.)

\n', + itemtype: 'method', + name: 'speed', + return: { + description: 'current playback speed of the element', + type: 'Number' + }, + example: [ + "\n
\n//Clicking the canvas will loop\n//the audio sample until the user\n//clicks again to stop it\n\n//We will store the p5.MediaElement\n//object in here\nvar ele;\nvar button;\n\nfunction setup() {\n createCanvas(710, 400);\n //Here we create a p5.MediaElement object\n //using the createAudio() function.\n ele = createAudio('assets/beat.mp3');\n ele.loop();\n background(200);\n\n button = createButton('2x speed');\n button.position(100, 68);\n button.mousePressed(twice_speed);\n\n button = createButton('half speed');\n button.position(200, 68);\n button.mousePressed(half_speed);\n\n button = createButton('reverse play');\n button.position(300, 68);\n button.mousePressed(reverse_speed);\n\n button = createButton('STOP');\n button.position(400, 68);\n button.mousePressed(stop_song);\n\n button = createButton('PLAY!');\n button.position(500, 68);\n button.mousePressed(play_speed);\n}\n\nfunction twice_speed() {\n ele.speed(2);\n}\n\nfunction half_speed() {\n ele.speed(0.5);\n}\n\nfunction reverse_speed() {\n ele.speed(-1);\n}\n\nfunction stop_song() {\n ele.stop();\n}\n\nfunction play_speed() {\n ele.play();\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 2712, + params: [], + return: { + description: 'current playback speed of the element', + type: 'Number' + } + }, + { + line: 2783, + params: [ + { + name: 'speed', + description: '

speed multiplier for element playback

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 2800, + description: + '

If no arguments are given, returns the current time of the element.\nIf an argument is given the current time of the element is set to it.

\n', + itemtype: 'method', + name: 'time', + return: { + description: 'current time (in seconds)', + type: 'Number' + }, + example: [ + "\n
\nvar ele;\nvar beginning = true;\nfunction setup() {\n //p5.MediaElement objects are usually created\n //by calling the createAudio(), createVideo(),\n //and createCapture() functions.\n\n //In this example we create\n //a new p5.MediaElement via createAudio().\n ele = createAudio('assets/lucky_dragons.mp3');\n background(250);\n textAlign(CENTER);\n text('start at beginning', width / 2, height / 2);\n}\n\n// this function fires with click anywhere\nfunction mousePressed() {\n if (beginning === true) {\n // here we start the sound at the beginning\n // time(0) is not necessary here\n // as this produces the same result as\n // play()\n ele.play().time(0);\n background(200);\n text('jump 2 sec in', width / 2, height / 2);\n beginning = false;\n } else {\n // here we jump 2 seconds into the sound\n ele.play().time(2);\n background(250);\n text('start at beginning', width / 2, height / 2);\n beginning = true;\n }\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom', + overloads: [ + { + line: 2800, + params: [], + return: { + description: 'current time (in seconds)', + type: 'Number' + } + }, + { + line: 2845, + params: [ + { + name: 'time', + description: '

time to jump to (in seconds)

\n', + type: 'Number' + } + ], + chainable: 1 + } + ] + }, + { + file: 'lib/addons/p5.dom.js', + line: 2859, + description: '

Returns the duration of the HTML5 media element.

\n', + itemtype: 'method', + name: 'duration', + return: { + description: 'duration', + type: 'Number' + }, + example: [ + "\n
\nvar ele;\nfunction setup() {\n //p5.MediaElement objects are usually created\n //by calling the createAudio(), createVideo(),\n //and createCapture() functions.\n //In this example we create\n //a new p5.MediaElement via createAudio().\n ele = createAudio('assets/doorbell.mp3');\n background(250);\n textAlign(CENTER);\n text('Click to know the duration!', 10, 25, 70, 80);\n}\nfunction mouseClicked() {\n ele.play();\n background(200);\n //ele.duration dislpays the duration\n text(ele.duration() + ' seconds', width / 2, height / 2);\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 2990, + description: + '

Schedule an event to be called when the audio or video\nelement reaches the end. If the element is looping,\nthis will not be called. The element is passed in\nas the argument to the onended callback.

\n', + itemtype: 'method', + name: 'onended', + params: [ + { + name: 'callback', + description: + '

function to call when the\n soundfile has ended. The\n media element will be passed\n in as the argument to the\n callback.

\n', + type: 'Function' + } + ], + chainable: 1, + example: [ + "\n
\nfunction setup() {\n var audioEl = createAudio('assets/beat.mp3');\n audioEl.showControls();\n audioEl.onended(sayDone);\n}\n\nfunction sayDone(elt) {\n alert('done playing ' + elt.src);\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3021, + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3023, + description: + '

Send the audio output of this element to a specified audioNode or\np5.sound object. If no element is provided, connects to p5's master\noutput. That connection is established when this method is first called.\nAll connections are removed by the .disconnect() method.

\n

This method is meant to be used with the p5.sound.js addon library.

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'audioNode', + description: + '

AudioNode from the Web Audio API,\nor an object from the p5.sound library

\n', + type: 'AudioNode|Object' + } + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3072, + description: + '

Disconnect all Web Audio routing, including to master output.\nThis is useful if you want to re-route the output through\naudio effects, for example.

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3087, + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3089, + description: + '

Show the default MediaElement controls, as determined by the web browser.

\n', + itemtype: 'method', + name: 'showControls', + example: [ + "\n
\nvar ele;\nfunction setup() {\n //p5.MediaElement objects are usually created\n //by calling the createAudio(), createVideo(),\n //and createCapture() functions.\n //In this example we create\n //a new p5.MediaElement via createAudio()\n ele = createAudio('assets/lucky_dragons.mp3');\n background(200);\n textAlign(CENTER);\n text('Click to Show Controls!', 10, 25, 70, 80);\n}\nfunction mousePressed() {\n ele.showControls();\n background(200);\n text('Controls Shown', width / 2, height / 2);\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3120, + description: '

Hide the default mediaElement controls.

\n', + itemtype: 'method', + name: 'hideControls', + example: [ + "\n
\nvar ele;\nfunction setup() {\n //p5.MediaElement objects are usually created\n //by calling the createAudio(), createVideo(),\n //and createCapture() functions.\n //In this example we create\n //a new p5.MediaElement via createAudio()\n ele = createAudio('assets/lucky_dragons.mp3');\n ele.showControls();\n background(200);\n textAlign(CENTER);\n text('Click to hide Controls!', 10, 25, 70, 80);\n}\nfunction mousePressed() {\n ele.hideControls();\n background(200);\n text('Controls hidden', width / 2, height / 2);\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3149, + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3160, + description: + '

Schedule events to trigger every time a MediaElement\n(audio/video) reaches a playback cue point.

\n

Accepts a callback function, a time (in seconds) at which to trigger\nthe callback, and an optional parameter for the callback.

\n

Time will be passed as the first parameter to the callback function,\nand param will be the second parameter.

\n', + itemtype: 'method', + name: 'addCue', + params: [ + { + name: 'time', + description: + '

Time in seconds, relative to this media\n element's playback. For example, to trigger\n an event every time playback reaches two\n seconds, pass in the number 2. This will be\n passed as the first parameter to\n the callback function.

\n', + type: 'Number' + }, + { + name: 'callback', + description: + '

Name of a function that will be\n called at the given time. The callback will\n receive time and (optionally) param as its\n two parameters.

\n', + type: 'Function' + }, + { + name: 'value', + description: + '

An object to be passed as the\n second parameter to the\n callback function.

\n', + type: 'Object', + optional: true + } + ], + return: { + description: + 'id ID of this cue,\n useful for removeCue(id)', + type: 'Number' + }, + example: [ + "\n
\n//\n//\nfunction setup() {\n noCanvas();\n\n var audioEl = createAudio('assets/beat.mp3');\n audioEl.showControls();\n\n // schedule three calls to changeBackground\n audioEl.addCue(0.5, changeBackground, color(255, 0, 0));\n audioEl.addCue(1.0, changeBackground, color(0, 255, 0));\n audioEl.addCue(2.5, changeBackground, color(0, 0, 255));\n audioEl.addCue(3.0, changeBackground, color(0, 255, 255));\n audioEl.addCue(4.2, changeBackground, color(255, 255, 0));\n audioEl.addCue(5.0, changeBackground, color(255, 255, 0));\n}\n\nfunction changeBackground(val) {\n background(val);\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3224, + description: + '

Remove a callback based on its ID. The ID is returned by the\naddCue method.

\n', + itemtype: 'method', + name: 'removeCue', + params: [ + { + name: 'id', + description: '

ID of the cue, as returned by addCue

\n', + type: 'Number' + } + ], + example: [ + "\n
\nvar audioEl, id1, id2;\nfunction setup() {\n background(255, 255, 255);\n audioEl = createAudio('assets/beat.mp3');\n audioEl.showControls();\n // schedule five calls to changeBackground\n id1 = audioEl.addCue(0.5, changeBackground, color(255, 0, 0));\n audioEl.addCue(1.0, changeBackground, color(0, 255, 0));\n audioEl.addCue(2.5, changeBackground, color(0, 0, 255));\n audioEl.addCue(3.0, changeBackground, color(0, 255, 255));\n id2 = audioEl.addCue(4.2, changeBackground, color(255, 255, 0));\n text('Click to remove first and last Cue!', 10, 25, 70, 80);\n}\nfunction mousePressed() {\n audioEl.removeCue(id1);\n audioEl.removeCue(id2);\n}\nfunction changeBackground(val) {\n background(val);\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3266, + description: + '

Remove all of the callbacks that had originally been scheduled\nvia the addCue method.

\n', + itemtype: 'method', + name: 'clearCues', + params: [ + { + name: 'id', + description: '

ID of the cue, as returned by addCue

\n', + type: 'Number' + } + ], + example: [ + "\n
\nvar audioEl;\nfunction setup() {\n background(255, 255, 255);\n audioEl = createAudio('assets/beat.mp3');\n //Show the default MediaElement controls, as determined by the web browser\n audioEl.showControls();\n // schedule calls to changeBackground\n background(200);\n text('Click to change Cue!', 10, 25, 70, 80);\n audioEl.addCue(0.5, changeBackground, color(255, 0, 0));\n audioEl.addCue(1.0, changeBackground, color(0, 255, 0));\n audioEl.addCue(2.5, changeBackground, color(0, 0, 255));\n audioEl.addCue(3.0, changeBackground, color(0, 255, 255));\n audioEl.addCue(4.2, changeBackground, color(255, 255, 0));\n}\nfunction mousePressed() {\n // here we clear the scheduled callbacks\n audioEl.clearCues();\n // then we add some more callbacks\n audioEl.addCue(1, changeBackground, color(2, 2, 2));\n audioEl.addCue(3, changeBackground, color(255, 255, 0));\n}\nfunction changeBackground(val) {\n background(val);\n}\n
" + ], + class: 'p5.MediaElement', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3332, + description: + '

Underlying File object. All normal File methods can be called on this.

\n', + itemtype: 'property', + name: 'file', + class: 'p5.File', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3344, + description: '

File type (image, text, etc.)

\n', + itemtype: 'property', + name: 'type', + class: 'p5.File', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3350, + description: + '

File subtype (usually the file extension jpg, png, xml, etc.)

\n', + itemtype: 'property', + name: 'subtype', + class: 'p5.File', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3356, + description: '

File name

\n', + itemtype: 'property', + name: 'name', + class: 'p5.File', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3362, + description: '

File size

\n', + itemtype: 'property', + name: 'size', + class: 'p5.File', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.dom.js', + line: 3369, + description: '

URL string containing image data.

\n', + itemtype: 'property', + name: 'data', + class: 'p5.File', + module: 'p5.dom', + submodule: 'p5.dom' + }, + { + file: 'lib/addons/p5.sound.js', + line: 46, + description: + '

p5.sound \nhttps://p5js.org/reference/#/libraries/p5.sound

\n

From the Processing Foundation and contributors\nhttps://github.com/processing/p5.js-sound/graphs/contributors

\n

MIT License (MIT)\nhttps://github.com/processing/p5.js-sound/blob/master/LICENSE

\n

Some of the many audio libraries & resources that inspire p5.sound:

\n\n', + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 214, + description: + '

Determine which filetypes are supported (inspired by buzz.js)\nThe audio element (el) will only be used to test browser support for various audio formats

\n', + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 363, + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 740, + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 810, + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1005, + description: + "

Returns the Audio Context for this sketch. Useful for users\nwho would like to dig deeper into the Web Audio API\n.

\n\n

Some browsers require users to startAudioContext\nwith a user gesture, such as touchStarted in the example below.

", + itemtype: 'method', + name: 'getAudioContext', + return: { + description: 'AudioContext for this sketch', + type: 'Object' + }, + example: [ + "\n
\n function draw() {\n background(255);\n textAlign(CENTER);\n\n if (getAudioContext().state !== 'running') {\n text('click to start audio', width/2, height/2);\n } else {\n text('audio is enabled', width/2, height/2);\n }\n }\n\n function touchStarted() {\n if (getAudioContext().state !== 'running') {\n getAudioContext().resume();\n }\n var synth = new p5.MonoSynth();\n synth.play('A4', 0.5, 0, 0.2);\n }\n\n
" + ], + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1042, + description: + '

It is a good practice to give users control over starting audio playback.\nThis practice is enforced by Google Chrome's autoplay policy as of r70\n(info), iOS Safari, and other browsers.\n

\n\n

\nuserStartAudio() starts the Audio Context on a user gesture. It utilizes\nthe StartAudioContext library by\nYotam Mann (MIT Licence, 2016). Read more at https://github.com/tambien/StartAudioContext.\n

\n\n

Starting the audio context on a user gesture can be as simple as userStartAudio().\nOptional parameters let you decide on a specific element that will start the audio context,\nand/or call a function once the audio context is started.

', + params: [ + { + name: 'element(s)', + description: + '

This argument can be an Element,\n Selector String, NodeList, p5.Element,\n jQuery Element, or an Array of any of those.

\n', + type: 'Element|Array', + optional: true + }, + { + name: 'callback', + description: + '

Callback to invoke when the AudioContext has started

\n', + type: 'Function', + optional: true + } + ], + return: { + description: + "Returns a Promise which is resolved when\n the AudioContext state is 'running'", + type: 'Promise' + }, + itemtype: 'method', + name: 'userStartAudio', + example: [ + "\n
\nfunction setup() {\n var myDiv = createDiv('click to start audio');\n myDiv.position(0, 0);\n\n var mySynth = new p5.MonoSynth();\n\n // This won't play until the context has started\n mySynth.play('A6');\n\n // Start the audio context on a click/touch event\n userStartAudio().then(function() {\n myDiv.remove();\n });\n}\n
" + ], + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1099, + description: + '

Master contains AudioContext and the master sound output.

\n', + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1132, + description: + '

Returns a number representing the master amplitude (volume) for sound\nin this sketch.

\n', + itemtype: 'method', + name: 'getMasterVolume', + return: { + description: + 'Master amplitude (volume) for sound in this sketch.\n Should be between 0.0 (silence) and 1.0.', + type: 'Number' + }, + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1143, + description: + '

Scale the output of all sound in this sketch

\nScaled between 0.0 (silence) and 1.0 (full volume).\n1.0 is the maximum amplitude of a digital sound, so multiplying\nby greater than 1.0 may cause digital distortion. To\nfade, provide a rampTime parameter. For more\ncomplex fades, see the Envelope class.\n\nAlternately, you can pass in a signal source such as an\noscillator to modulate the amplitude with an audio signal.\n\n

How This Works: When you load the p5.sound module, it\ncreates a single instance of p5sound. All sound objects in this\nmodule output to p5sound before reaching your computer's output.\nSo if you change the amplitude of p5sound, it impacts all of the\nsound in this module.

\n\n

If no value is provided, returns a Web Audio API Gain Node

', + itemtype: 'method', + name: 'masterVolume', + params: [ + { + name: 'volume', + description: + '

Volume (amplitude) between 0.0\n and 1.0 or modulating signal/oscillator

\n', + type: 'Number|Object' + }, + { + name: 'rampTime', + description: '

Fade for t seconds

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

Schedule this event to happen at\n t seconds in the future

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1185, + description: + '

p5.soundOut is the p5.sound master output. It sends output to\nthe destination of this window's web audio context. It contains\nWeb Audio API nodes including a dyanmicsCompressor (.limiter),\nand Gain Nodes for .input and .output.

\n', + itemtype: 'property', + name: 'soundOut', + type: 'Object', + class: 'p5.sound', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1210, + class: 'p5', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1213, + description: + '

Returns a number representing the sample rate, in samples per second,\nof all sound objects in this audio context. It is determined by the\nsampling rate of your operating system's sound card, and it is not\ncurrently possile to change.\nIt is often 44100, or twice the range of human hearing.

\n', + itemtype: 'method', + name: 'sampleRate', + return: { + description: 'samplerate samples per second', + type: 'Number' + }, + class: 'p5', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1226, + description: + '

Returns the closest MIDI note value for\na given frequency.

\n', + itemtype: 'method', + name: 'freqToMidi', + params: [ + { + name: 'frequency', + description: + '

A freqeuncy, for example, the "A"\n above Middle C is 440Hz

\n', + type: 'Number' + } + ], + return: { + description: 'MIDI note value', + type: 'Number' + }, + class: 'p5', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1240, + description: + '

Returns the frequency value of a MIDI note value.\nGeneral MIDI treats notes as integers where middle C\nis 60, C# is 61, D is 62 etc. Useful for generating\nmusical frequencies with oscillators.

\n', + itemtype: 'method', + name: 'midiToFreq', + params: [ + { + name: 'midiNote', + description: '

The number of a MIDI note

\n', + type: 'Number' + } + ], + return: { + description: 'Frequency value of the given MIDI note', + type: 'Number' + }, + example: [ + "\n
\nvar notes = [60, 64, 67, 72];\nvar i = 0;\n\nfunction setup() {\n osc = new p5.Oscillator('Triangle');\n osc.start();\n frameRate(1);\n}\n\nfunction draw() {\n var freq = midiToFreq(notes[i]);\n osc.freq(freq);\n i++;\n if (i >= notes.length){\n i = 0;\n }\n}\n
" + ], + class: 'p5', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1302, + description: + '

List the SoundFile formats that you will include. LoadSound\nwill search your directory for these extensions, and will pick\na format that is compatable with the client's web browser.\nHere is a free online file\nconverter.

\n', + itemtype: 'method', + name: 'soundFormats', + params: [ + { + name: 'formats', + description: + '

i.e. 'mp3', 'wav', 'ogg'

\n', + type: 'String', + optional: true, + multiple: true + } + ], + example: [ + "\n
\nfunction preload() {\n // set the global sound formats\n soundFormats('mp3', 'ogg');\n\n // load either beatbox.mp3, or .ogg, depending on browser\n mySound = loadSound('assets/beatbox.mp3');\n}\n\nfunction setup() {\n mySound.play();\n}\n
" + ], + class: 'p5', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1415, + description: '

Used by Osc and Envelope to chain signal math

\n', + class: 'p5', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1763, + description: + '

loadSound() returns a new p5.SoundFile from a specified\npath. If called during preload(), the p5.SoundFile will be ready\nto play in time for setup() and draw(). If called outside of\npreload, the p5.SoundFile will not be ready immediately, so\nloadSound accepts a callback as the second parameter. Using a\n\nlocal server is recommended when loading external files.

\n', + itemtype: 'method', + name: 'loadSound', + params: [ + { + name: 'path', + description: + '

Path to the sound file, or an array with\n paths to soundfiles in multiple formats\n i.e. ['sound.ogg', 'sound.mp3'].\n Alternately, accepts an object: either\n from the HTML5 File API, or a p5.File.

\n', + type: 'String|Array' + }, + { + name: 'successCallback', + description: '

Name of a function to call once file loads

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

Name of a function to call if there is\n an error loading the file.

\n', + type: 'Function', + optional: true + }, + { + name: 'whileLoading', + description: + '

Name of a function to call while file is loading.\n This function will receive the percentage loaded\n so far, from 0.0 to 1.0.

\n', + type: 'Function', + optional: true + } + ], + return: { + description: 'Returns a p5.SoundFile', + type: 'SoundFile' + }, + example: [ + "\n
\nfunction preload() {\n mySound = loadSound('assets/doorbell.mp3');\n}\n\nfunction setup() {\n mySound.setVolume(0.1);\n mySound.play();\n}\n
" + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1919, + description: + '

Returns true if the sound file finished loading successfully.

\n', + itemtype: 'method', + name: 'isLoaded', + return: { + description: '', + type: 'Boolean' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 1932, + description: '

Play the p5.SoundFile

\n', + itemtype: 'method', + name: 'play', + params: [ + { + name: 'startTime', + description: + '

(optional) schedule playback to start (in seconds from now).

\n', + type: 'Number', + optional: true + }, + { + name: 'rate', + description: '

(optional) playback rate

\n', + type: 'Number', + optional: true + }, + { + name: 'amp', + description: + '

(optional) amplitude (volume)\n of playback

\n', + type: 'Number', + optional: true + }, + { + name: 'cueStart', + description: '

(optional) cue start time in seconds

\n', + type: 'Number', + optional: true + }, + { + name: 'duration', + description: '

(optional) duration of playback in seconds

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2022, + description: + '

p5.SoundFile has two play modes: restart and\nsustain. Play Mode determines what happens to a\np5.SoundFile if it is triggered while in the middle of playback.\nIn sustain mode, playback will continue simultaneous to the\nnew playback. In restart mode, play() will stop playback\nand start over. With untilDone, a sound will play only if it's\nnot already playing. Sustain is the default mode.

\n', + itemtype: 'method', + name: 'playMode', + params: [ + { + name: 'str', + description: + '

'restart' or 'sustain' or 'untilDone'

\n', + type: 'String' + } + ], + example: [ + "\n
\nvar mySound;\nfunction preload(){\n mySound = loadSound('assets/Damscray_DancingTiger.mp3');\n}\nfunction mouseClicked() {\n mySound.playMode('sustain');\n mySound.play();\n}\nfunction keyPressed() {\n mySound.playMode('restart');\n mySound.play();\n}\n\n
" + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2066, + description: + '

Pauses a file that is currently playing. If the file is not\nplaying, then nothing will happen.

\n

After pausing, .play() will resume from the paused\nposition.\nIf p5.SoundFile had been set to loop before it was paused,\nit will continue to loop after it is unpaused with .play().

\n', + itemtype: 'method', + name: 'pause', + params: [ + { + name: 'startTime', + description: + '

(optional) schedule event to occur\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nvar soundFile;\n\nfunction preload() {\n soundFormats('ogg', 'mp3');\n soundFile = loadSound('assets/Damscray_-_Dancing_Tiger_02.mp3');\n}\nfunction setup() {\n background(0, 255, 0);\n soundFile.setVolume(0.1);\n soundFile.loop();\n}\nfunction keyTyped() {\n if (key == 'p') {\n soundFile.pause();\n background(255, 0, 0);\n }\n}\n\nfunction keyReleased() {\n if (key == 'p') {\n soundFile.play();\n background(0, 255, 0);\n }\n}\n\n
" + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2122, + description: + '

Loop the p5.SoundFile. Accepts optional parameters to set the\nplayback rate, playback volume, loopStart, loopEnd.

\n', + itemtype: 'method', + name: 'loop', + params: [ + { + name: 'startTime', + description: + '

(optional) schedule event to occur\n seconds from now

\n', + type: 'Number', + optional: true + }, + { + name: 'rate', + description: '

(optional) playback rate

\n', + type: 'Number', + optional: true + }, + { + name: 'amp', + description: '

(optional) playback volume

\n', + type: 'Number', + optional: true + }, + { + name: 'cueLoopStart', + description: '

(optional) startTime in seconds

\n', + type: 'Number', + optional: true + }, + { + name: 'duration', + description: '

(optional) loop duration in seconds

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2138, + description: + '

Set a p5.SoundFile's looping flag to true or false. If the sound\nis currently playing, this change will take effect when it\nreaches the end of the current playback.

\n', + itemtype: 'method', + name: 'setLoop', + params: [ + { + name: 'Boolean', + description: '

set looping to true or false

\n', + type: 'Boolean' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2159, + description: + '

Returns 'true' if a p5.SoundFile is currently looping and playing, 'false' if not.

\n', + itemtype: 'method', + name: 'isLooping', + return: { + description: '', + type: 'Boolean' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2174, + description: + '

Returns true if a p5.SoundFile is playing, false if not (i.e.\npaused or stopped).

\n', + itemtype: 'method', + name: 'isPlaying', + return: { + description: '', + type: 'Boolean' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2184, + description: + '

Returns true if a p5.SoundFile is paused, false if not (i.e.\nplaying or stopped).

\n', + itemtype: 'method', + name: 'isPaused', + return: { + description: '', + type: 'Boolean' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2194, + description: '

Stop soundfile playback.

\n', + itemtype: 'method', + name: 'stop', + params: [ + { + name: 'startTime', + description: + '

(optional) schedule event to occur\n in seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2239, + description: + '

Multiply the output volume (amplitude) of a sound file\nbetween 0.0 (silence) and 1.0 (full volume).\n1.0 is the maximum amplitude of a digital sound, so multiplying\nby greater than 1.0 may cause digital distortion. To\nfade, provide a rampTime parameter. For more\ncomplex fades, see the Envelope class.

\n

Alternately, you can pass in a signal source such as an\noscillator to modulate the amplitude with an audio signal.

\n', + itemtype: 'method', + name: 'setVolume', + params: [ + { + name: 'volume', + description: + '

Volume (amplitude) between 0.0\n and 1.0 or modulating signal/oscillator

\n', + type: 'Number|Object' + }, + { + name: 'rampTime', + description: '

Fade for t seconds

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

Schedule this event to happen at\n t seconds in the future

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2280, + description: + '

Set the stereo panning of a p5.sound object to\na floating point number between -1.0 (left) and 1.0 (right).\nDefault is 0.0 (center).

\n', + itemtype: 'method', + name: 'pan', + params: [ + { + name: 'panValue', + description: '

Set the stereo panner

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\n\n var ball = {};\n var soundFile;\n\n function preload() {\n soundFormats('ogg', 'mp3');\n soundFile = loadSound('assets/beatbox.mp3');\n }\n\n function draw() {\n background(0);\n ball.x = constrain(mouseX, 0, width);\n ellipse(ball.x, height/2, 20, 20)\n }\n\n function mousePressed(){\n // map the ball's x location to a panning degree\n // between -1.0 (left) and 1.0 (right)\n var panning = map(ball.x, 0., width,-1.0, 1.0);\n soundFile.pan(panning);\n soundFile.play();\n }\n
" + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2319, + description: + '

Returns the current stereo pan position (-1.0 to 1.0)

\n', + itemtype: 'method', + name: 'getPan', + return: { + description: + 'Returns the stereo pan setting of the Oscillator\n as a number between -1.0 (left) and 1.0 (right).\n 0.0 is center and default.', + type: 'Number' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2330, + description: + '

Set the playback rate of a sound file. Will change the speed and the pitch.\nValues less than zero will reverse the audio buffer.

\n', + itemtype: 'method', + name: 'rate', + params: [ + { + name: 'playbackRate', + description: + '

Set the playback rate. 1.0 is normal,\n .5 is half-speed, 2.0 is twice as fast.\n Values less than zero play backwards.

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nvar song;\n\nfunction preload() {\n song = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup() {\n song.loop();\n}\n\nfunction draw() {\n background(200);\n\n // Set the rate to a range between 0.1 and 4\n // Changing the rate also alters the pitch\n var speed = map(mouseY, 0.1, height, 0, 2);\n speed = constrain(speed, 0.01, 4);\n song.rate(speed);\n\n // Draw a circle to show what is going on\n stroke(0);\n fill(51, 100);\n ellipse(mouseX, 100, 48, 48);\n}\n\n \n
\n" + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2403, + description: '

Returns the duration of a sound file in seconds.

\n', + itemtype: 'method', + name: 'duration', + return: { + description: 'The duration of the soundFile in seconds.', + type: 'Number' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2417, + description: + '

Return the current position of the p5.SoundFile playhead, in seconds.\nTime is relative to the normal buffer direction, so if reverseBuffer\nhas been called, currentTime will count backwards.

\n', + itemtype: 'method', + name: 'currentTime', + return: { + description: 'currentTime of the soundFile in seconds.', + type: 'Number' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2428, + description: + '

Move the playhead of the song to a position, in seconds. Start timing\nand playback duration. If none are given, will reset the file to play\nentire duration from start to finish.

\n', + itemtype: 'method', + name: 'jump', + params: [ + { + name: 'cueTime', + description: '

cueTime of the soundFile in seconds.

\n', + type: 'Number' + }, + { + name: 'duration', + description: '

duration in seconds.

\n', + type: 'Number' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2451, + description: + '

Return the number of channels in a sound file.\nFor example, Mono = 1, Stereo = 2.

\n', + itemtype: 'method', + name: 'channels', + return: { + description: '[channels]', + type: 'Number' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2461, + description: '

Return the sample rate of the sound file.

\n', + itemtype: 'method', + name: 'sampleRate', + return: { + description: '[sampleRate]', + type: 'Number' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2470, + description: + '

Return the number of samples in a sound file.\nEqual to sampleRate * duration.

\n', + itemtype: 'method', + name: 'frames', + return: { + description: '[sampleCount]', + type: 'Number' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2480, + description: + '

Returns an array of amplitude peaks in a p5.SoundFile that can be\nused to draw a static waveform. Scans through the p5.SoundFile's\naudio buffer to find the greatest amplitudes. Accepts one\nparameter, 'length', which determines size of the array.\nLarger arrays result in more precise waveform visualizations.

\n

Inspired by Wavesurfer.js.

\n', + itemtype: 'method', + name: 'getPeaks', + params: [ + { + name: 'length', + description: + '

length is the size of the returned array.\n Larger length results in more precision.\n Defaults to 5*width of the browser window.

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'Array of peaks.', + type: 'Float32Array' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2532, + description: + '

Reverses the p5.SoundFile's buffer source.\nPlayback must be handled separately (see example).

\n', + itemtype: 'method', + name: 'reverseBuffer', + example: [ + "\n
\nvar drum;\n\nfunction preload() {\n drum = loadSound('assets/drum.mp3');\n}\n\nfunction setup() {\n drum.reverseBuffer();\n drum.play();\n}\n\n \n
" + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2572, + description: + '

Schedule an event to be called when the soundfile\nreaches the end of a buffer. If the soundfile is\nplaying through once, this will be called when it\nends. If it is looping, it will be called when\nstop is called.

\n', + itemtype: 'method', + name: 'onended', + params: [ + { + name: 'callback', + description: + '

function to call when the\n soundfile has ended.

\n', + type: 'Function' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2625, + description: + '

Connects the output of a p5sound object to input of another\np5.sound object. For example, you may connect a p5.SoundFile to an\nFFT or an Effect. If no parameter is given, it will connect to\nthe master output. Most p5sound objects connect to the master\noutput when they are created.

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'object', + description: '

Audio object that accepts an input

\n', + type: 'Object', + optional: true + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2646, + description: '

Disconnects the output of this p5sound object.

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2656, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2661, + description: + '

Reset the source for this SoundFile to a\nnew path (URL).

\n', + itemtype: 'method', + name: 'setPath', + params: [ + { + name: 'path', + description: '

path to audio file

\n', + type: 'String' + }, + { + name: 'callback', + description: '

Callback

\n', + type: 'Function' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2674, + description: '

Replace the current Audio Buffer with a new Buffer.

\n', + itemtype: 'method', + name: 'setBuffer', + params: [ + { + name: 'buf', + description: + '

Array of Float32 Array(s). 2 Float32 Arrays\n will create a stereo source. 1 will create\n a mono source.

\n', + type: 'Array' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2741, + description: + '

processPeaks returns an array of timestamps where it thinks there is a beat.

\n

This is an asynchronous function that processes the soundfile in an offline audio context,\nand sends the results to your callback function.

\n

The process involves running the soundfile through a lowpass filter, and finding all of the\npeaks above the initial threshold. If the total number of peaks are below the minimum number of peaks,\nit decreases the threshold and re-runs the analysis until either minPeaks or minThreshold are reached.

\n', + itemtype: 'method', + name: 'processPeaks', + params: [ + { + name: 'callback', + description: '

a function to call once this data is returned

\n', + type: 'Function' + }, + { + name: 'initThreshold', + description: '

initial threshold defaults to 0.9

\n', + type: 'Number', + optional: true + }, + { + name: 'minThreshold', + description: '

minimum threshold defaults to 0.22

\n', + type: 'Number', + optional: true + }, + { + name: 'minPeaks', + description: '

minimum number of peaks defaults to 200

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'Array of timestamped peaks', + type: 'Array' + }, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2934, + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 2943, + description: + '

Schedule events to trigger every time a MediaElement\n(audio/video) reaches a playback cue point.

\n

Accepts a callback function, a time (in seconds) at which to trigger\nthe callback, and an optional parameter for the callback.

\n

Time will be passed as the first parameter to the callback function,\nand param will be the second parameter.

\n', + itemtype: 'method', + name: 'addCue', + params: [ + { + name: 'time', + description: + '

Time in seconds, relative to this media\n element's playback. For example, to trigger\n an event every time playback reaches two\n seconds, pass in the number 2. This will be\n passed as the first parameter to\n the callback function.

\n', + type: 'Number' + }, + { + name: 'callback', + description: + '

Name of a function that will be\n called at the given time. The callback will\n receive time and (optionally) param as its\n two parameters.

\n', + type: 'Function' + }, + { + name: 'value', + description: + '

An object to be passed as the\n second parameter to the\n callback function.

\n', + type: 'Object', + optional: true + } + ], + return: { + description: + 'id ID of this cue,\n useful for removeCue(id)', + type: 'Number' + }, + example: [ + '\n
\nvar mySound;\nfunction preload() {\n mySound = loadSound(\'assets/beat.mp3\');\n}\n\nfunction setup() {\n background(0);\n noStroke();\n fill(255);\n textAlign(CENTER);\n text(\'click to play\', width/2, height/2);\n\n // schedule calls to changeText\n mySound.addCue(0.50, changeText, "hello" );\n mySound.addCue(1.00, changeText, "p5" );\n mySound.addCue(1.50, changeText, "what" );\n mySound.addCue(2.00, changeText, "do" );\n mySound.addCue(2.50, changeText, "you" );\n mySound.addCue(3.00, changeText, "want" );\n mySound.addCue(4.00, changeText, "to" );\n mySound.addCue(5.00, changeText, "make" );\n mySound.addCue(6.00, changeText, "?" );\n}\n\nfunction changeText(val) {\n background(0);\n text(val, width/2, height/2);\n}\n\nfunction mouseClicked() {\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n if (mySound.isPlaying() ) {\n mySound.stop();\n } else {\n mySound.play();\n }\n }\n}\n
' + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3021, + description: + '

Remove a callback based on its ID. The ID is returned by the\naddCue method.

\n', + itemtype: 'method', + name: 'removeCue', + params: [ + { + name: 'id', + description: '

ID of the cue, as returned by addCue

\n', + type: 'Number' + } + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3040, + description: + '

Remove all of the callbacks that had originally been scheduled\nvia the addCue method.

\n', + itemtype: 'method', + name: 'clearCues', + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3065, + description: + '

Save a p5.SoundFile as a .wav file. The browser will prompt the user\nto download the file to their device. To upload a file to a server, see\ngetBlob

\n', + itemtype: 'method', + name: 'save', + params: [ + { + name: 'fileName', + description: '

name of the resulting .wav file.

\n', + type: 'String', + optional: true + } + ], + example: [ + "\n
\n var inp, button, mySound;\n var fileName = 'cool';\n function preload() {\n mySound = loadSound('assets/doorbell.mp3');\n }\n function setup() {\n btn = createButton('click to save file');\n btn.position(0, 0);\n btn.mouseClicked(handleMouseClick);\n }\n\n function handleMouseClick() {\n mySound.save(fileName);\n }\n
" + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3094, + description: + '

This method is useful for sending a SoundFile to a server. It returns the\n.wav-encoded audio data as a "Blob".\nA Blob is a file-like data object that can be uploaded to a server\nwith an http request. We'll\nuse the httpDo options object to send a POST request with some\nspecific options: we encode the request as multipart/form-data,\nand attach the blob as one of the form values using FormData.

\n', + itemtype: 'method', + name: 'getBlob', + return: { + description: 'A file-like data object', + type: 'Blob' + }, + example: [ + "\n
\n\n function preload() {\n mySound = loadSound('assets/doorbell.mp3');\n }\n\n function setup() {\n noCanvas();\n var soundBlob = mySound.getBlob();\n\n // Now we can send the blob to a server...\n var serverUrl = 'https://jsonplaceholder.typicode.com/posts';\n var httpRequestOptions = {\n method: 'POST',\n body: new FormData().append('soundBlob', soundBlob),\n headers: new Headers({\n 'Content-Type': 'multipart/form-data'\n })\n };\n httpDo(serverUrl, httpRequestOptions);\n\n // We can also create an `ObjectURL` pointing to the Blob\n var blobUrl = URL.createObjectURL(soundBlob);\n\n // The `
" + ], + class: 'p5.SoundFile', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3257, + description: + '

Connects to the p5sound instance (master output) by default.\nOptionally, you can pass in a specific source (i.e. a soundfile).

\n', + itemtype: 'method', + name: 'setInput', + params: [ + { + name: 'snd', + description: + '

set the sound source\n (optional, defaults to\n master output)

\n', + type: 'SoundObject|undefined', + optional: true + }, + { + name: 'smoothing', + description: + '

a range between 0.0 and 1.0\n to smooth amplitude readings

\n', + type: 'Number|undefined', + optional: true + } + ], + example: [ + "\n
\nfunction preload(){\n sound1 = loadSound('assets/beat.mp3');\n sound2 = loadSound('assets/drum.mp3');\n}\nfunction setup(){\n amplitude = new p5.Amplitude();\n sound1.play();\n sound2.play();\n amplitude.setInput(sound2);\n}\nfunction draw() {\n background(0);\n fill(255);\n var level = amplitude.getLevel();\n var size = map(level, 0, 1, 0, 200);\n ellipse(width/2, height/2, size, size);\n}\nfunction mouseClicked(){\n sound1.stop();\n sound2.stop();\n}\n
" + ], + class: 'p5.Amplitude', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3364, + description: + '

Returns a single Amplitude reading at the moment it is called.\nFor continuous readings, run in the draw loop.

\n', + itemtype: 'method', + name: 'getLevel', + params: [ + { + name: 'channel', + description: + '

Optionally return only channel 0 (left) or 1 (right)

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'Amplitude as a number between 0.0 and 1.0', + type: 'Number' + }, + example: [ + "\n
\nfunction preload(){\n sound = loadSound('assets/beat.mp3');\n}\nfunction setup() {\n amplitude = new p5.Amplitude();\n sound.play();\n}\nfunction draw() {\n background(0);\n fill(255);\n var level = amplitude.getLevel();\n var size = map(level, 0, 1, 0, 200);\n ellipse(width/2, height/2, size, size);\n}\nfunction mouseClicked(){\n sound.stop();\n}\n
" + ], + class: 'p5.Amplitude', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3405, + description: + '

Determines whether the results of Amplitude.process() will be\nNormalized. To normalize, Amplitude finds the difference the\nloudest reading it has processed and the maximum amplitude of\n1.0. Amplitude adds this difference to all values to produce\nresults that will reliably map between 0.0 and 1.0. However,\nif a louder moment occurs, the amount that Normalize adds to\nall the values will change. Accepts an optional boolean parameter\n(true or false). Normalizing is off by default.

\n', + itemtype: 'method', + name: 'toggleNormalize', + params: [ + { + name: 'boolean', + description: '

set normalize to true (1) or false (0)

\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5.Amplitude', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3425, + description: + '

Smooth Amplitude analysis by averaging with the last analysis\nframe. Off by default.

\n', + itemtype: 'method', + name: 'smooth', + params: [ + { + name: 'set', + description: '

smoothing from 0.0 <= 1

\n', + type: 'Number' + } + ], + class: 'p5.Amplitude', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3599, + description: + '

Set the input source for the FFT analysis. If no source is\nprovided, FFT will analyze all sound in the sketch.

\n', + itemtype: 'method', + name: 'setInput', + params: [ + { + name: 'source', + description: '

p5.sound object (or web audio API source node)

\n', + type: 'Object', + optional: true + } + ], + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3618, + description: + '

Returns an array of amplitude values (between -1.0 and +1.0) that represent\na snapshot of amplitude readings in a single buffer. Length will be\nequal to bins (defaults to 1024). Can be used to draw the waveform\nof a sound.

\n', + itemtype: 'method', + name: 'waveform', + params: [ + { + name: 'bins', + description: + '

Must be a power of two between\n 16 and 1024. Defaults to 1024.

\n', + type: 'Number', + optional: true + }, + { + name: 'precision', + description: + '

If any value is provided, will return results\n in a Float32 Array which is more precise\n than a regular array.

\n', + type: 'String', + optional: true + } + ], + return: { + description: + 'Array Array of amplitude values (-1 to 1)\n over time. Array length = bins.', + type: 'Array' + }, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3661, + description: + '

Returns an array of amplitude values (between 0 and 255)\nacross the frequency spectrum. Length is equal to FFT bins\n(1024 by default). The array indices correspond to frequencies\n(i.e. pitches), from the lowest to the highest that humans can\nhear. Each value represents amplitude at that slice of the\nfrequency spectrum. Must be called prior to using\ngetEnergy().

\n', + itemtype: 'method', + name: 'analyze', + params: [ + { + name: 'bins', + description: + '

Must be a power of two between\n 16 and 1024. Defaults to 1024.

\n', + type: 'Number', + optional: true + }, + { + name: 'scale', + description: + '

If "dB," returns decibel\n float measurements between\n -140 and 0 (max).\n Otherwise returns integers from 0-255.

\n', + type: 'Number', + optional: true + } + ], + return: { + description: + 'spectrum Array of energy (amplitude/volume)\n values across the frequency spectrum.\n Lowest energy (silence) = 0, highest\n possible is 255.', + type: 'Array' + }, + example: [ + "\n
\nvar osc;\nvar fft;\n\nfunction setup(){\n createCanvas(100,100);\n osc = new p5.Oscillator();\n osc.amp(0);\n osc.start();\n fft = new p5.FFT();\n}\n\nfunction draw(){\n background(0);\n\n var freq = map(mouseX, 0, 800, 20, 15000);\n freq = constrain(freq, 1, 20000);\n osc.freq(freq);\n\n var spectrum = fft.analyze();\n noStroke();\n fill(0,255,0); // spectrum is green\n for (var i = 0; i< spectrum.length; i++){\n var x = map(i, 0, spectrum.length, 0, width);\n var h = -height + map(spectrum[i], 0, 255, height, 0);\n rect(x, height, width / spectrum.length, h );\n }\n\n stroke(255);\n text('Freq: ' + round(freq)+'Hz', 10, 10);\n\n isMouseOverCanvas();\n}\n\n// only play sound when mouse is over canvas\nfunction isMouseOverCanvas() {\n var mX = mouseX, mY = mouseY;\n if (mX > 0 && mX < width && mY < height && mY > 0) {\n osc.amp(0.5, 0.2);\n } else {\n osc.amp(0, 0.2);\n }\n}\n
\n\n" + ], + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3753, + description: + '

Returns the amount of energy (volume) at a specific\n\nfrequency, or the average amount of energy between two\nfrequencies. Accepts Number(s) corresponding\nto frequency (in Hz), or a String corresponding to predefined\nfrequency ranges ("bass", "lowMid", "mid", "highMid", "treble").\nReturns a range between 0 (no energy/volume at that frequency) and\n255 (maximum energy).\nNOTE: analyze() must be called prior to getEnergy(). Analyze()\ntells the FFT to analyze frequency data, and getEnergy() uses\nthe results determine the value at a specific frequency or\nrange of frequencies.

\n', + itemtype: 'method', + name: 'getEnergy', + params: [ + { + name: 'frequency1', + description: + '

Will return a value representing\n energy at this frequency. Alternately,\n the strings "bass", "lowMid" "mid",\n "highMid", and "treble" will return\n predefined frequency ranges.

\n', + type: 'Number|String' + }, + { + name: 'frequency2', + description: + '

If a second frequency is given,\n will return average amount of\n energy that exists between the\n two frequencies.

\n', + type: 'Number', + optional: true + } + ], + return: { + description: + 'Energy Energy (volume/amplitude) from\n 0 and 255.', + type: 'Number' + }, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3835, + description: + '

Returns the\n\nspectral centroid of the input signal.\nNOTE: analyze() must be called prior to getCentroid(). Analyze()\ntells the FFT to analyze frequency data, and getCentroid() uses\nthe results determine the spectral centroid.

\n', + itemtype: 'method', + name: 'getCentroid', + return: { + description: + 'Spectral Centroid Frequency Frequency of the spectral centroid in Hz.', + type: 'Number' + }, + example: [ + '\n
\n\n\nfunction setup(){\ncnv = createCanvas(100,100);\nsound = new p5.AudioIn();\nsound.start();\nfft = new p5.FFT();\nsound.connect(fft);\n}\n\n\nfunction draw(){\n\nvar centroidplot = 0.0;\nvar spectralCentroid = 0;\n\n\nbackground(0);\nstroke(0,255,0);\nvar spectrum = fft.analyze();\nfill(0,255,0); // spectrum is green\n\n//draw the spectrum\nfor (var i = 0; i< spectrum.length; i++){\n var x = map(log(i), 0, log(spectrum.length), 0, width);\n var h = map(spectrum[i], 0, 255, 0, height);\n var rectangle_width = (log(i+1)-log(i))*(width/log(spectrum.length));\n rect(x, height, rectangle_width, -h )\n}\n\nvar nyquist = 22050;\n\n// get the centroid\nspectralCentroid = fft.getCentroid();\n\n// the mean_freq_index calculation is for the display.\nvar mean_freq_index = spectralCentroid/(nyquist/spectrum.length);\n\ncentroidplot = map(log(mean_freq_index), 0, log(spectrum.length), 0, width);\n\n\nstroke(255,0,0); // the line showing where the centroid is will be red\n\nrect(centroidplot, 0, width / spectrum.length, height)\nnoStroke();\nfill(255,255,255); // text is white\ntext("centroid: ", 10, 20);\ntext(round(spectralCentroid)+" Hz", 10, 40);\n}\n
' + ], + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3915, + description: + '

Smooth FFT analysis by averaging with the last analysis frame.

\n', + itemtype: 'method', + name: 'smooth', + params: [ + { + name: 'smoothing', + description: + '

0.0 < smoothing < 1.0.\n Defaults to 0.8.

\n', + type: 'Number' + } + ], + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3937, + description: + '

Returns an array of average amplitude values for a given number\nof frequency bands split equally. N defaults to 16.\nNOTE: analyze() must be called prior to linAverages(). Analyze()\ntells the FFT to analyze frequency data, and linAverages() uses\nthe results to group them into a smaller set of averages.

\n', + itemtype: 'method', + name: 'linAverages', + params: [ + { + name: 'N', + description: '

Number of returned frequency groups

\n', + type: 'Number' + } + ], + return: { + description: + 'linearAverages Array of average amplitude values for each group', + type: 'Array' + }, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3967, + description: + '

Returns an array of average amplitude values of the spectrum, for a given\nset of \nOctave Bands\nNOTE: analyze() must be called prior to logAverages(). Analyze()\ntells the FFT to analyze frequency data, and logAverages() uses\nthe results to group them into a smaller set of averages.

\n', + itemtype: 'method', + name: 'logAverages', + params: [ + { + name: 'octaveBands', + description: '

Array of Octave Bands objects for grouping

\n', + type: 'Array' + } + ], + return: { + description: + 'logAverages Array of average amplitude values for each group', + type: 'Array' + }, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 3997, + description: + '

Calculates and Returns the 1/N\nOctave Bands\nN defaults to 3 and minimum central frequency to 15.625Hz.\n(1/3 Octave Bands ~= 31 Frequency Bands)\nSetting fCtr0 to a central value of a higher octave will ignore the lower bands\nand produce less frequency groups.

\n', + itemtype: 'method', + name: 'getOctaveBands', + params: [ + { + name: 'N', + description: + '

Specifies the 1/N type of generated octave bands

\n', + type: 'Number' + }, + { + name: 'fCtr0', + description: '

Minimum central frequency for the lowest band

\n', + type: 'Number' + } + ], + return: { + description: + 'octaveBands Array of octave band objects with their bounds', + type: 'Array' + }, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 4055, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 4076, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 4135, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 4453, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 4625, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 4783, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 4824, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 4881, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5049, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5097, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5128, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5149, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5169, + class: 'p5.FFT', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5268, + description: '

Fade to value, for smooth transitions

\n', + itemtype: 'method', + name: 'fade', + params: [ + { + name: 'value', + description: '

Value to set this signal

\n', + type: 'Number' + }, + { + name: 'secondsFromNow', + description: '

Length of fade, in seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Signal', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5279, + description: + '

Connect a p5.sound object or Web Audio node to this\np5.Signal so that its amplitude values can be scaled.

\n', + itemtype: 'method', + name: 'setInput', + params: [ + { + name: 'input', + description: '', + type: 'Object' + } + ], + class: 'p5.Signal', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5293, + description: + '

Add a constant value to this audio signal,\nand return the resulting audio signal. Does\nnot change the value of the original signal,\ninstead it returns a new p5.SignalAdd.

\n', + itemtype: 'method', + name: 'add', + params: [ + { + name: 'number', + description: '', + type: 'Number' + } + ], + return: { + description: 'object', + type: 'p5.Signal' + }, + class: 'p5.Signal', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5312, + description: + '

Multiply this signal by a constant value,\nand return the resulting audio signal. Does\nnot change the value of the original signal,\ninstead it returns a new p5.SignalMult.

\n', + itemtype: 'method', + name: 'mult', + params: [ + { + name: 'number', + description: '

to multiply

\n', + type: 'Number' + } + ], + return: { + description: 'object', + type: 'p5.Signal' + }, + class: 'p5.Signal', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5331, + description: + '

Scale this signal value to a given range,\nand return the result as an audio signal. Does\nnot change the value of the original signal,\ninstead it returns a new p5.SignalScale.

\n', + itemtype: 'method', + name: 'scale', + params: [ + { + name: 'number', + description: '

to multiply

\n', + type: 'Number' + }, + { + name: 'inMin', + description: '

input range minumum

\n', + type: 'Number' + }, + { + name: 'inMax', + description: '

input range maximum

\n', + type: 'Number' + }, + { + name: 'outMin', + description: '

input range minumum

\n', + type: 'Number' + }, + { + name: 'outMax', + description: '

input range maximum

\n', + type: 'Number' + } + ], + return: { + description: 'object', + type: 'p5.Signal' + }, + class: 'p5.Signal', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5465, + description: + '

Start an oscillator. Accepts an optional parameter to\ndetermine how long (in seconds from now) until the\noscillator starts.

\n', + itemtype: 'method', + name: 'start', + params: [ + { + name: 'time', + description: '

startTime in seconds from now.

\n', + type: 'Number', + optional: true + }, + { + name: 'frequency', + description: '

frequency in Hz.

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5505, + description: + '

Stop an oscillator. Accepts an optional parameter\nto determine how long (in seconds from now) until the\noscillator stops.

\n', + itemtype: 'method', + name: 'stop', + params: [ + { + name: 'secondsFromNow', + description: '

Time, in seconds from now.

\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5521, + description: + '

Set the amplitude between 0 and 1.0. Or, pass in an object\nsuch as an oscillator to modulate amplitude with an audio signal.

\n', + itemtype: 'method', + name: 'amp', + params: [ + { + name: 'vol', + description: + '

between 0 and 1.0\n or a modulating signal/oscillator

\n', + type: 'Number|Object' + }, + { + name: 'rampTime', + description: '

create a fade that lasts rampTime

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + return: { + description: + "gain If no value is provided,\n returns the Web Audio API\n AudioParam that controls\n this oscillator's\n gain/amplitude/volume)", + type: 'AudioParam' + }, + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5556, + description: + '

Set frequency of an oscillator to a value. Or, pass in an object\nsuch as an oscillator to modulate the frequency with an audio signal.

\n', + itemtype: 'method', + name: 'freq', + params: [ + { + name: 'Frequency', + description: + '

Frequency in Hz\n or modulating signal/oscillator

\n', + type: 'Number|Object' + }, + { + name: 'rampTime', + description: '

Ramp time (in seconds)

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

Schedule this event to happen\n at x seconds from now

\n', + type: 'Number', + optional: true + } + ], + return: { + description: + "Frequency If no value is provided,\n returns the Web Audio API\n AudioParam that controls\n this oscillator's frequency", + type: 'AudioParam' + }, + example: [ + '\n
\nvar osc = new p5.Oscillator(300);\nosc.start();\nosc.freq(40, 10);\n
' + ], + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5615, + description: + '

Set type to 'sine', 'triangle', 'sawtooth' or 'square'.

\n', + itemtype: 'method', + name: 'setType', + params: [ + { + name: 'type', + description: + '

'sine', 'triangle', 'sawtooth' or 'square'.

\n', + type: 'String' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5627, + description: '

Connect to a p5.sound / Web Audio object.

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: '

A p5.sound or Web Audio object

\n', + type: 'Object' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5644, + description: '

Disconnect all outputs

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5661, + description: '

Pan between Left (-1) and Right (1)

\n', + itemtype: 'method', + name: 'pan', + params: [ + { + name: 'panning', + description: '

Number between -1 and 1

\n', + type: 'Number' + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5693, + description: + '

Set the phase of an oscillator between 0.0 and 1.0.\nIn this implementation, phase is a delay time\nbased on the oscillator's current frequency.

\n', + itemtype: 'method', + name: 'phase', + params: [ + { + name: 'phase', + description: '

float between 0.0 and 1.0

\n', + type: 'Number' + } + ], + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5747, + description: + '

Add a value to the p5.Oscillator's output amplitude,\nand return the oscillator. Calling this method again\nwill override the initial add() with a new value.

\n', + itemtype: 'method', + name: 'add', + params: [ + { + name: 'number', + description: '

Constant number to add

\n', + type: 'Number' + } + ], + return: { + description: + 'Oscillator Returns this oscillator\n with scaled output', + type: 'p5.Oscillator' + }, + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5764, + description: + '

Multiply the p5.Oscillator's output amplitude\nby a fixed value (i.e. turn it up!). Calling this method\nagain will override the initial mult() with a new value.

\n', + itemtype: 'method', + name: 'mult', + params: [ + { + name: 'number', + description: '

Constant number to multiply

\n', + type: 'Number' + } + ], + return: { + description: + 'Oscillator Returns this oscillator\n with multiplied output', + type: 'p5.Oscillator' + }, + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5780, + description: + '

Scale this oscillator's amplitude values to a given\nrange, and return the oscillator. Calling this method\nagain will override the initial scale() with new values.

\n', + itemtype: 'method', + name: 'scale', + params: [ + { + name: 'inMin', + description: '

input range minumum

\n', + type: 'Number' + }, + { + name: 'inMax', + description: '

input range maximum

\n', + type: 'Number' + }, + { + name: 'outMin', + description: '

input range minumum

\n', + type: 'Number' + }, + { + name: 'outMax', + description: '

input range maximum

\n', + type: 'Number' + } + ], + return: { + description: + 'Oscillator Returns this oscillator\n with scaled output', + type: 'p5.Oscillator' + }, + class: 'p5.Oscillator', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 5879, + class: 'p5.SqrOsc', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6082, + class: 'p5.SqrOsc', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6369, + description: '

Time until envelope reaches attackLevel

\n', + itemtype: 'property', + name: 'attackTime', + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6374, + description: '

Level once attack is complete.

\n', + itemtype: 'property', + name: 'attackLevel', + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6379, + description: '

Time until envelope reaches decayLevel.

\n', + itemtype: 'property', + name: 'decayTime', + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6384, + description: + '

Level after decay. The envelope will sustain here until it is released.

\n', + itemtype: 'property', + name: 'decayLevel', + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6389, + description: '

Duration of the release portion of the envelope.

\n', + itemtype: 'property', + name: 'releaseTime', + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6394, + description: '

Level at the end of the release.

\n', + itemtype: 'property', + name: 'releaseLevel', + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6430, + description: + '

Reset the envelope with a series of time/value pairs.

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'attackTime', + description: + '

Time (in seconds) before level\n reaches attackLevel

\n', + type: 'Number' + }, + { + name: 'attackLevel', + description: + '

Typically an amplitude between\n 0.0 and 1.0

\n', + type: 'Number' + }, + { + name: 'decayTime', + description: '

Time

\n', + type: 'Number' + }, + { + name: 'decayLevel', + description: + '

Amplitude (In a standard ADSR envelope,\n decayLevel = sustainLevel)

\n', + type: 'Number' + }, + { + name: 'releaseTime', + description: '

Release Time (in seconds)

\n', + type: 'Number' + }, + { + name: 'releaseLevel', + description: '

Amplitude

\n', + type: 'Number' + } + ], + example: [ + "\n
\nvar t1 = 0.1; // attack time in seconds\nvar l1 = 0.7; // attack level 0.0 to 1.0\nvar t2 = 0.3; // decay time in seconds\nvar l2 = 0.1; // decay level 0.0 to 1.0\nvar t3 = 0.2; // sustain time in seconds\nvar l3 = 0.5; // sustain level 0.0 to 1.0\n// release level defaults to zero\n\nvar env;\nvar triOsc;\n\nfunction setup() {\n background(0);\n noStroke();\n fill(255);\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Envelope(t1, l1, t2, l2, t3, l3);\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env); // give the env control of the triOsc's amp\n triOsc.start();\n}\n\n// mouseClick triggers envelope if over canvas\nfunction mouseClicked() {\n // is mouse over canvas?\n if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {\n env.play(triOsc);\n }\n}\n
\n" + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6489, + description: + '

Set values like a traditional\n\nADSR envelope\n.

\n', + itemtype: 'method', + name: 'setADSR', + params: [ + { + name: 'attackTime', + description: + '

Time (in seconds before envelope\n reaches Attack Level

\n', + type: 'Number' + }, + { + name: 'decayTime', + description: + '

Time (in seconds) before envelope\n reaches Decay/Sustain Level

\n', + type: 'Number', + optional: true + }, + { + name: 'susRatio', + description: + '

Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using setRange),\n then decayLevel would increase proportionally, to become 0.5.

\n', + type: 'Number', + optional: true + }, + { + name: 'releaseTime', + description: '

Time in seconds from now (defaults to 0)

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001;\nvar decayTime = 0.2;\nvar susPercent = 0.2;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Envelope();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(playEnv);\n}\n\nfunction playEnv() {\n env.play();\n}\n
" + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6554, + description: + '

Set max (attackLevel) and min (releaseLevel) of envelope.

\n', + itemtype: 'method', + name: 'setRange', + params: [ + { + name: 'aLevel', + description: '

attack level (defaults to 1)

\n', + type: 'Number' + }, + { + name: 'rLevel', + description: '

release level (defaults to 0)

\n', + type: 'Number' + } + ], + example: [ + "\n
\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001;\nvar decayTime = 0.2;\nvar susPercent = 0.2;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Envelope();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(playEnv);\n}\n\nfunction playEnv() {\n env.play();\n}\n
" + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6633, + description: + '

Assign a parameter to be controlled by this envelope.\nIf a p5.Sound object is given, then the p5.Envelope will control its\noutput gain. If multiple inputs are provided, the env will\ncontrol all of them.

\n', + itemtype: 'method', + name: 'setInput', + params: [ + { + name: 'inputs', + description: + '

A p5.sound object or\n Web Audio Param.

\n', + type: 'Object', + optional: true, + multiple: true + } + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6648, + description: + '

Set whether the envelope ramp is linear (default) or exponential.\nExponential ramps can be useful because we perceive amplitude\nand frequency logarithmically.

\n', + itemtype: 'method', + name: 'setExp', + params: [ + { + name: 'isExp', + description: '

true is exponential, false is linear

\n', + type: 'Boolean' + } + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6666, + description: + '

Play tells the envelope to start acting on a given input.\nIf the input is a p5.sound object (i.e. AudioIn, Oscillator,\nSoundFile), then Envelope will control its output volume.\nEnvelopes can also be used to control any \nWeb Audio Audio Param.

\n', + itemtype: 'method', + name: 'play', + params: [ + { + name: 'unit', + description: + '

A p5.sound object or\n Web Audio Param.

\n', + type: 'Object' + }, + { + name: 'startTime', + description: '

time from now (in seconds) at which to play

\n', + type: 'Number', + optional: true + }, + { + name: 'sustainTime', + description: '

time to sustain before releasing the envelope

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001;\nvar decayTime = 0.2;\nvar susPercent = 0.2;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Envelope();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(playEnv);\n}\n\nfunction playEnv() {\n // trigger env on triOsc, 0 seconds from now\n // After decay, sustain for 0.2 seconds before release\n env.play(triOsc, 0, 0.2);\n}\n
" + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6727, + description: + '

Trigger the Attack, and Decay portion of the Envelope.\nSimilar to holding down a key on a piano, but it will\nhold the sustain level until you let go. Input can be\nany p5.sound object, or a \nWeb Audio Param.

\n', + itemtype: 'method', + name: 'triggerAttack', + params: [ + { + name: 'unit', + description: '

p5.sound Object or Web Audio Param

\n', + type: 'Object' + }, + { + name: 'secondsFromNow', + description: '

time from now (in seconds)

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001;\nvar decayTime = 0.3;\nvar susPercent = 0.4;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Envelope();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(envAttack);\n}\n\nfunction envAttack() {\n console.log('trigger attack');\n env.triggerAttack();\n\n background(0,255,0);\n text('attack!', width/2, height/2);\n}\n\nfunction mouseReleased() {\n env.triggerRelease();\n\n background(200);\n text('click to play', width/2, height/2);\n}\n
" + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6834, + description: + '

Trigger the Release of the Envelope. This is similar to releasing\nthe key on a piano and letting the sound fade according to the\nrelease level and release time.

\n', + itemtype: 'method', + name: 'triggerRelease', + params: [ + { + name: 'unit', + description: '

p5.sound Object or Web Audio Param

\n', + type: 'Object' + }, + { + name: 'secondsFromNow', + description: '

time to trigger the release

\n', + type: 'Number' + } + ], + example: [ + "\n
\n\nvar attackLevel = 1.0;\nvar releaseLevel = 0;\n\nvar attackTime = 0.001;\nvar decayTime = 0.3;\nvar susPercent = 0.4;\nvar releaseTime = 0.5;\n\nvar env, triOsc;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n background(200);\n textAlign(CENTER);\n text('click to play', width/2, height/2);\n\n env = new p5.Envelope();\n env.setADSR(attackTime, decayTime, susPercent, releaseTime);\n env.setRange(attackLevel, releaseLevel);\n\n triOsc = new p5.Oscillator('triangle');\n triOsc.amp(env);\n triOsc.start();\n triOsc.freq(220);\n\n cnv.mousePressed(envAttack);\n}\n\nfunction envAttack() {\n console.log('trigger attack');\n env.triggerAttack();\n\n background(0,255,0);\n text('attack!', width/2, height/2);\n}\n\nfunction mouseReleased() {\n env.triggerRelease();\n\n background(200);\n text('click to play', width/2, height/2);\n}\n
" + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 6931, + description: + '

Exponentially ramp to a value using the first two\nvalues from setADSR(attackTime, decayTime)\nas \ntime constants for simple exponential ramps.\nIf the value is higher than current value, it uses attackTime,\nwhile a decrease uses decayTime.

\n', + itemtype: 'method', + name: 'ramp', + params: [ + { + name: 'unit', + description: '

p5.sound Object or Web Audio Param

\n', + type: 'Object' + }, + { + name: 'secondsFromNow', + description: '

When to trigger the ramp

\n', + type: 'Number' + }, + { + name: 'v', + description: '

Target value

\n', + type: 'Number' + }, + { + name: 'v2', + description: '

Second target value (optional)

\n', + type: 'Number', + optional: true + } + ], + example: [ + "\n
\nvar env, osc, amp, cnv;\n\nvar attackTime = 0.001;\nvar decayTime = 0.2;\nvar attackLevel = 1;\nvar decayLevel = 0;\n\nfunction setup() {\n cnv = createCanvas(100, 100);\n fill(0,255,0);\n noStroke();\n\n env = new p5.Envelope();\n env.setADSR(attackTime, decayTime);\n\n osc = new p5.Oscillator();\n osc.amp(env);\n osc.start();\n\n amp = new p5.Amplitude();\n\n cnv.mousePressed(triggerRamp);\n}\n\nfunction triggerRamp() {\n env.ramp(osc, 0, attackLevel, decayLevel);\n}\n\nfunction draw() {\n background(20,20,20);\n text('click me', 10, 20);\n var h = map(amp.getLevel(), 0, 0.4, 0, height);;\n\n rect(0, height, width, -h);\n}\n
" + ], + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7038, + description: + '

Add a value to the p5.Oscillator's output amplitude,\nand return the oscillator. Calling this method\nagain will override the initial add() with new values.

\n', + itemtype: 'method', + name: 'add', + params: [ + { + name: 'number', + description: '

Constant number to add

\n', + type: 'Number' + } + ], + return: { + description: + 'Envelope Returns this envelope\n with scaled output', + type: 'p5.Envelope' + }, + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7054, + description: + '

Multiply the p5.Envelope's output amplitude\nby a fixed value. Calling this method\nagain will override the initial mult() with new values.

\n', + itemtype: 'method', + name: 'mult', + params: [ + { + name: 'number', + description: '

Constant number to multiply

\n', + type: 'Number' + } + ], + return: { + description: + 'Envelope Returns this envelope\n with scaled output', + type: 'p5.Envelope' + }, + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7070, + description: + '

Scale this envelope's amplitude values to a given\nrange, and return the envelope. Calling this method\nagain will override the initial scale() with new values.

\n', + itemtype: 'method', + name: 'scale', + params: [ + { + name: 'inMin', + description: '

input range minumum

\n', + type: 'Number' + }, + { + name: 'inMax', + description: '

input range maximum

\n', + type: 'Number' + }, + { + name: 'outMin', + description: '

input range minumum

\n', + type: 'Number' + }, + { + name: 'outMax', + description: '

input range maximum

\n', + type: 'Number' + } + ], + return: { + description: + 'Envelope Returns this envelope\n with scaled output', + type: 'p5.Envelope' + }, + class: 'p5.Envelope', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7178, + description: + '

Set the width of a Pulse object (an oscillator that implements\nPulse Width Modulation).

\n', + itemtype: 'method', + name: 'width', + params: [ + { + name: 'width', + description: + '

Width between the pulses (0 to 1.0,\n defaults to 0)

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Pulse', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7365, + description: + '

Set type of noise to 'white', 'pink' or 'brown'.\nWhite is the default.

\n', + itemtype: 'method', + name: 'setType', + params: [ + { + name: 'type', + description: + '

'white', 'pink' or 'brown'

\n', + type: 'String', + optional: true + } + ], + class: 'p5.Noise', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7478, + itemtype: 'property', + name: 'input', + type: 'GainNode', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7482, + itemtype: 'property', + name: 'output', + type: 'GainNode', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7486, + itemtype: 'property', + name: 'stream', + type: 'MediaStream|null', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7490, + itemtype: 'property', + name: 'mediaStream', + type: 'MediaStreamAudioSourceNode|null', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7494, + itemtype: 'property', + name: 'currentSource', + type: 'Number|null', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7498, + description: + '

Client must allow browser to access their microphone / audioin source.\nDefault: false. Will become true when the client enables acces.

\n', + itemtype: 'property', + name: 'enabled', + type: 'Boolean', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7505, + description: + '

Input amplitude, connect to it by default but not to master out

\n', + itemtype: 'property', + name: 'amplitude', + type: 'p5.Amplitude', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7518, + description: + '

Start processing audio input. This enables the use of other\nAudioIn methods like getLevel(). Note that by default, AudioIn\nis not connected to p5.sound's output. So you won't hear\nanything unless you use the connect() method.

\n

Certain browsers limit access to the user's microphone. For example,\nChrome only allows access from localhost and over https. For this reason,\nyou may want to include an errorCallback—a function that is called in case\nthe browser won't provide mic access.

\n', + itemtype: 'method', + name: 'start', + params: [ + { + name: 'successCallback', + description: + '

Name of a function to call on\n success.

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

Name of a function to call if\n there was an error. For example,\n some browsers do not support\n getUserMedia.

\n', + type: 'Function', + optional: true + } + ], + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7571, + description: + '

Turn the AudioIn off. If the AudioIn is stopped, it cannot getLevel().\nIf re-starting, the user may be prompted for permission access.

\n', + itemtype: 'method', + name: 'stop', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7587, + description: + '

Connect to an audio unit. If no parameter is provided, will\nconnect to the master output (i.e. your speakers).

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: + '

An object that accepts audio input,\n such as an FFT

\n', + type: 'Object', + optional: true + } + ], + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7608, + description: + '

Disconnect the AudioIn from all audio units. For example, if\nconnect() had been called, disconnect() will stop sending\nsignal to your speakers.

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7622, + description: + '

Read the Amplitude (volume level) of an AudioIn. The AudioIn\nclass contains its own instance of the Amplitude class to help\nmake it easy to get a microphone's volume level. Accepts an\noptional smoothing value (0.0 < 1.0). NOTE: AudioIn must\n.start() before using .getLevel().

\n', + itemtype: 'method', + name: 'getLevel', + params: [ + { + name: 'smoothing', + description: + '

Smoothing is 0.0 by default.\n Smooths values based on previous values.

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'Volume level (between 0.0 and 1.0)', + type: 'Number' + }, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7640, + description: + '

Set amplitude (volume) of a mic input between 0 and 1.0.

\n', + itemtype: 'method', + name: 'amp', + params: [ + { + name: 'vol', + description: '

between 0 and 1.0

\n', + type: 'Number' + }, + { + name: 'time', + description: '

ramp time (optional)

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7659, + description: + '

Returns a list of available input sources. This is a wrapper\nfor <a title="MediaDevices.enumerateDevices() - Web APIs | MDN" target="_blank" href=\n "https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices"

\n
\n

and it returns a Promise.

\n
\n', + itemtype: 'method', + name: 'getSources', + params: [ + { + name: 'successCallback', + description: + '

This callback function handles the sources when they\n have been enumerated. The callback function\n receives the deviceList array as its only argument

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

This optional callback receives the error\n message as its argument.

\n', + type: 'Function', + optional: true + } + ], + return: { + description: + 'Returns a Promise that can be used in place of the callbacks, similar\n to the enumerateDevices() method', + type: 'Promise' + }, + example: [ + '\n
\n var audiograb;\n\n function setup(){\n //new audioIn\n audioGrab = new p5.AudioIn();\n\n audioGrab.getSources(function(deviceList) {\n //print out the array of available sources\n console.log(deviceList);\n //set the source to the first item in the deviceList array\n audioGrab.setSource(0);\n });\n }\n
' + ], + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7710, + description: + '

Set the input source. Accepts a number representing a\nposition in the array returned by getSources().\nThis is only available in browsers that support\n<a title="MediaDevices.enumerateDevices() - Web APIs | MDN" target="_blank" href=\n"https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices"

\n
\n

navigator.mediaDevices.enumerateDevices().

\n
\n', + itemtype: 'method', + name: 'setSource', + params: [ + { + name: 'num', + description: '

position of input source in the array

\n', + type: 'Number' + } + ], + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7750, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7766, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7790, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7816, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7838, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7860, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7906, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7937, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 7955, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8292, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8314, + class: 'p5.AudioIn', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8390, + description: + '

In classes that extend\np5.Effect, connect effect nodes\nto the wet parameter

\n', + class: 'p5.Effect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8403, + description: '

Set the output volume of the filter.

\n', + itemtype: 'method', + name: 'amp', + params: [ + { + name: 'vol', + description: '

amplitude between 0 and 1.0

\n', + type: 'Number', + optional: true + }, + { + name: 'rampTime', + description: '

create a fade that lasts until rampTime

\n', + type: 'Number', + optional: true + }, + { + name: 'tFromNow', + description: + '

schedule this event to happen in tFromNow seconds

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Effect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8420, + description: + '

Link effects together in a chain
Example usage: filter.chain(reverb, delay, panner);\nMay be used with an open-ended number of arguments

\n', + itemtype: 'method', + name: 'chain', + params: [ + { + name: 'arguments', + description: '

Chain together multiple sound objects

\n', + type: 'Object', + optional: true + } + ], + class: 'p5.Effect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8437, + description: '

Adjust the dry/wet value.

\n', + itemtype: 'method', + name: 'drywet', + params: [ + { + name: 'fade', + description: '

The desired drywet value (0 - 1.0)

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Effect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8449, + description: + '

Send output to a p5.js-sound, Web Audio Node, or use signal to\ncontrol an AudioParam

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.Effect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8460, + description: '

Disconnect all output.

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.Effect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8578, + description: + '

The p5.Filter is built with a\n\nWeb Audio BiquadFilter Node.

\n', + itemtype: 'property', + name: 'biquadFilter', + type: 'DelayNode', + class: 'p5.Filter', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8596, + description: + '

Filter an audio signal according to a set\nof filter parameters.

\n', + itemtype: 'method', + name: 'process', + params: [ + { + name: 'Signal', + description: '

An object that outputs audio

\n', + type: 'Object' + }, + { + name: 'freq', + description: '

Frequency in Hz, from 10 to 22050

\n', + type: 'Number', + optional: true + }, + { + name: 'res', + description: + '

Resonance/Width of the filter frequency\n from 0.001 to 1000

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Filter', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8610, + description: '

Set the frequency and the resonance of the filter.

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'freq', + description: '

Frequency in Hz, from 10 to 22050

\n', + type: 'Number', + optional: true + }, + { + name: 'res', + description: '

Resonance (Q) from 0.001 to 1000

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Filter', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8627, + description: + '

Set the filter frequency, in Hz, from 10 to 22050 (the range of\nhuman hearing, although in reality most people hear in a narrower\nrange).

\n', + itemtype: 'method', + name: 'freq', + params: [ + { + name: 'freq', + description: '

Filter Frequency

\n', + type: 'Number' + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'value Returns the current frequency value', + type: 'Number' + }, + class: 'p5.Filter', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8651, + description: + '

Controls either width of a bandpass frequency,\nor the resonance of a low/highpass cutoff frequency.

\n', + itemtype: 'method', + name: 'res', + params: [ + { + name: 'res', + description: + '

Resonance/Width of filter freq\n from 0.001 to 1000

\n', + type: 'Number' + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'value Returns the current res value', + type: 'Number' + }, + class: 'p5.Filter', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8673, + description: + '

Controls the gain attribute of a Biquad Filter.\nThis is distinctly different from .amp() which is inherited from p5.Effect\n.amp() controls the volume via the output gain node\np5.Filter.gain() controls the gain parameter of a Biquad Filter node.

\n', + itemtype: 'method', + name: 'gain', + params: [ + { + name: 'gain', + description: '', + type: 'Number' + } + ], + return: { + description: 'Returns the current or updated gain value', + type: 'Number' + }, + class: 'p5.Filter', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8694, + description: + '

Toggle function. Switches between the specified type and allpass

\n', + itemtype: 'method', + name: 'toggle', + return: { + description: '[Toggle value]', + type: 'Boolean' + }, + class: 'p5.Filter', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8709, + description: + '

Set the type of a p5.Filter. Possible types include:\n"lowpass" (default), "highpass", "bandpass",\n"lowshelf", "highshelf", "peaking", "notch",\n"allpass".

\n', + itemtype: 'method', + name: 'setType', + params: [ + { + name: 't', + description: '', + type: 'String' + } + ], + class: 'p5.Filter', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8916, + description: + '

The p5.EQ is built with abstracted p5.Filter objects.\nTo modify any bands, use methods of the \np5.Filter API, especially gain and freq.\nBands are stored in an array, with indices 0 - 3, or 0 - 7

\n', + itemtype: 'property', + name: 'bands', + type: 'Array', + class: 'p5.EQ', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 8951, + description: '

Process an input by connecting it to the EQ

\n', + itemtype: 'method', + name: 'process', + params: [ + { + name: 'src', + description: '

Audio source

\n', + type: 'Object' + } + ], + class: 'p5.EQ', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9039, + description: + '

\nWeb Audio Spatial Panner Node

\n

Properties include

\n\n', + itemtype: 'property', + name: 'panner', + type: 'AudioNode', + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9062, + description: '

Connect an audio sorce

\n', + itemtype: 'method', + name: 'process', + params: [ + { + name: 'src', + description: '

Input source

\n', + type: 'Object' + } + ], + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9071, + description: '

Set the X,Y,Z position of the Panner

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'xVal', + description: '', + type: 'Number' + }, + { + name: 'yVal', + description: '', + type: 'Number' + }, + { + name: 'zVal', + description: '', + type: 'Number' + }, + { + name: 'time', + description: '', + type: 'Number' + } + ], + return: { + description: 'Updated x, y, z values as an array', + type: 'Array' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9090, + description: '

Getter and setter methods for position coordinates

\n', + itemtype: 'method', + name: 'positionX', + return: { + description: 'updated coordinate value', + type: 'Number' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9095, + description: '

Getter and setter methods for position coordinates

\n', + itemtype: 'method', + name: 'positionY', + return: { + description: 'updated coordinate value', + type: 'Number' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9100, + description: '

Getter and setter methods for position coordinates

\n', + itemtype: 'method', + name: 'positionZ', + return: { + description: 'updated coordinate value', + type: 'Number' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9138, + description: '

Set the X,Y,Z position of the Panner

\n', + itemtype: 'method', + name: 'orient', + params: [ + { + name: 'xVal', + description: '', + type: 'Number' + }, + { + name: 'yVal', + description: '', + type: 'Number' + }, + { + name: 'zVal', + description: '', + type: 'Number' + }, + { + name: 'time', + description: '', + type: 'Number' + } + ], + return: { + description: 'Updated x, y, z values as an array', + type: 'Array' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9157, + description: '

Getter and setter methods for orient coordinates

\n', + itemtype: 'method', + name: 'orientX', + return: { + description: 'updated coordinate value', + type: 'Number' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9162, + description: '

Getter and setter methods for orient coordinates

\n', + itemtype: 'method', + name: 'orientY', + return: { + description: 'updated coordinate value', + type: 'Number' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9167, + description: '

Getter and setter methods for orient coordinates

\n', + itemtype: 'method', + name: 'orientZ', + return: { + description: 'updated coordinate value', + type: 'Number' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9205, + description: '

Set the rolloff factor and max distance

\n', + itemtype: 'method', + name: 'setFalloff', + params: [ + { + name: 'maxDistance', + description: '', + type: 'Number', + optional: true + }, + { + name: 'rolloffFactor', + description: '', + type: 'Number', + optional: true + } + ], + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9215, + description: '

Maxium distance between the source and the listener

\n', + itemtype: 'method', + name: 'maxDist', + params: [ + { + name: 'maxDistance', + description: '', + type: 'Number' + } + ], + return: { + description: 'updated value', + type: 'Number' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9227, + description: + '

How quickly the volume is reduced as the source moves away from the listener

\n', + itemtype: 'method', + name: 'rollof', + params: [ + { + name: 'rolloffFactor', + description: '', + type: 'Number' + } + ], + return: { + description: 'updated value', + type: 'Number' + }, + class: 'p5.Panner3D', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9532, + description: + '

The p5.Delay is built with two\n\nWeb Audio Delay Nodes, one for each stereo channel.

\n', + itemtype: 'property', + name: 'leftDelay', + type: 'DelayNode', + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9540, + description: + '

The p5.Delay is built with two\n\nWeb Audio Delay Nodes, one for each stereo channel.

\n', + itemtype: 'property', + name: 'rightDelay', + type: 'DelayNode', + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9572, + description: + '

Add delay to an audio signal according to a set\nof delay parameters.

\n', + itemtype: 'method', + name: 'process', + params: [ + { + name: 'Signal', + description: '

An object that outputs audio

\n', + type: 'Object' + }, + { + name: 'delayTime', + description: + '

Time (in seconds) of the delay/echo.\n Some browsers limit delayTime to\n 1 second.

\n', + type: 'Number', + optional: true + }, + { + name: 'feedback', + description: + '

sends the delay back through itself\n in a loop that decreases in volume\n each time.

\n', + type: 'Number', + optional: true + }, + { + name: 'lowPass', + description: + '

Cutoff frequency. Only frequencies\n below the lowPass will be part of the\n delay.

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9607, + description: + '

Set the delay (echo) time, in seconds. Usually this value will be\na floating point number between 0.0 and 1.0.

\n', + itemtype: 'method', + name: 'delayTime', + params: [ + { + name: 'delayTime', + description: '

Time (in seconds) of the delay

\n', + type: 'Number' + } + ], + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9626, + description: + '

Feedback occurs when Delay sends its signal back through its input\nin a loop. The feedback amount determines how much signal to send each\ntime through the loop. A feedback greater than 1.0 is not desirable because\nit will increase the overall output each time through the loop,\ncreating an infinite feedback loop. The default value is 0.5

\n', + itemtype: 'method', + name: 'feedback', + params: [ + { + name: 'feedback', + description: + '

0.0 to 1.0, or an object such as an\n Oscillator that can be used to\n modulate this param

\n', + type: 'Number|Object' + } + ], + return: { + description: 'Feedback value', + type: 'Number' + }, + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9654, + description: + '

Set a lowpass filter frequency for the delay. A lowpass filter\nwill cut off any frequencies higher than the filter frequency.

\n', + itemtype: 'method', + name: 'filter', + params: [ + { + name: 'cutoffFreq', + description: + '

A lowpass filter will cut off any\n frequencies higher than the filter frequency.

\n', + type: 'Number|Object' + }, + { + name: 'res', + description: + '

Resonance of the filter frequency\n cutoff, or an object (i.e. a p5.Oscillator)\n that can be used to modulate this parameter.\n High numbers (i.e. 15) will produce a resonance,\n low numbers (i.e. .2) will produce a slope.

\n', + type: 'Number|Object' + } + ], + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9671, + description: + '

Choose a preset type of delay. 'pingPong' bounces the signal\nfrom the left to the right channel to produce a stereo effect.\nAny other parameter will revert to the default delay setting.

\n', + itemtype: 'method', + name: 'setType', + params: [ + { + name: 'type', + description: '

'pingPong' (1) or 'default' (0)

\n', + type: 'String|Number' + } + ], + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9704, + description: '

Set the output level of the delay effect.

\n', + itemtype: 'method', + name: 'amp', + params: [ + { + name: 'volume', + description: '

amplitude between 0 and 1.0

\n', + type: 'Number' + }, + { + name: 'rampTime', + description: '

create a fade that lasts rampTime

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9713, + description: '

Send output to a p5.sound or web audio object

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9719, + description: '

Disconnect all output.

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.Delay', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9812, + description: + '

Connect a source to the reverb, and assign reverb parameters.

\n', + itemtype: 'method', + name: 'process', + params: [ + { + name: 'src', + description: + '

p5.sound / Web Audio object with a sound\n output.

\n', + type: 'Object' + }, + { + name: 'seconds', + description: + '

Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.

\n', + type: 'Number', + optional: true + }, + { + name: 'decayRate', + description: + '

Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.

\n', + type: 'Number', + optional: true + }, + { + name: 'reverse', + description: '

Play the reverb backwards or forwards.

\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5.Reverb', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9841, + description: + '

Set the reverb settings. Similar to .process(), but without\nassigning a new input.

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'seconds', + description: + '

Duration of the reverb, in seconds.\n Min: 0, Max: 10. Defaults to 3.

\n', + type: 'Number', + optional: true + }, + { + name: 'decayRate', + description: + '

Percentage of decay with each echo.\n Min: 0, Max: 100. Defaults to 2.

\n', + type: 'Number', + optional: true + }, + { + name: 'reverse', + description: '

Play the reverb backwards or forwards.

\n', + type: 'Boolean', + optional: true + } + ], + class: 'p5.Reverb', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9869, + description: '

Set the output level of the reverb effect.

\n', + itemtype: 'method', + name: 'amp', + params: [ + { + name: 'volume', + description: '

amplitude between 0 and 1.0

\n', + type: 'Number' + }, + { + name: 'rampTime', + description: '

create a fade that lasts rampTime

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Reverb', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9878, + description: '

Send output to a p5.sound or web audio object

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.Reverb', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9884, + description: '

Disconnect all output.

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.Reverb', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9975, + description: + '

Internally, the p5.Convolver uses the a\n\nWeb Audio Convolver Node.

\n', + itemtype: 'property', + name: 'convolverNode', + type: 'ConvolverNode', + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 9998, + description: + '

Create a p5.Convolver. Accepts a path to a soundfile\nthat will be used to generate an impulse response.

\n', + itemtype: 'method', + name: 'createConvolver', + params: [ + { + name: 'path', + description: '

path to a sound file

\n', + type: 'String' + }, + { + name: 'callback', + description: + '

function to call if loading is successful.\n The object will be passed in as the argument\n to the callback function.

\n', + type: 'Function', + optional: true + }, + { + name: 'errorCallback', + description: + '

function to call if loading is not successful.\n A custom error will be passed in as the argument\n to the callback function.

\n', + type: 'Function', + optional: true + } + ], + return: { + description: '', + type: 'p5.Convolver' + }, + example: [ + "\n
\nvar cVerb, sound;\nfunction preload() {\n // We have both MP3 and OGG versions of all sound assets\n soundFormats('ogg', 'mp3');\n\n // Try replacing 'bx-spring' with other soundfiles like\n // 'concrete-tunnel' 'small-plate' 'drum' 'beatbox'\n cVerb = createConvolver('assets/bx-spring.mp3');\n\n // Try replacing 'Damscray_DancingTiger' with\n // 'beat', 'doorbell', lucky_dragons_-_power_melody'\n sound = loadSound('assets/Damscray_DancingTiger.mp3');\n}\n\nfunction setup() {\n // disconnect from master output...\n sound.disconnect();\n\n // ...and process with cVerb\n // so that we only hear the convolution\n cVerb.process(sound);\n\n sound.play();\n}\n
" + ], + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10122, + description: + '

Connect a source to the reverb, and assign reverb parameters.

\n', + itemtype: 'method', + name: 'process', + params: [ + { + name: 'src', + description: + '

p5.sound / Web Audio object with a sound\n output.

\n', + type: 'Object' + } + ], + example: [ + "\n
\nvar cVerb, sound;\nfunction preload() {\n soundFormats('ogg', 'mp3');\n\n cVerb = createConvolver('assets/concrete-tunnel.mp3');\n\n sound = loadSound('assets/beat.mp3');\n}\n\nfunction setup() {\n // disconnect from master output...\n sound.disconnect();\n\n // ...and process with (i.e. connect to) cVerb\n // so that we only hear the convolution\n cVerb.process(sound);\n\n sound.play();\n}\n
" + ], + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10154, + description: + '

If you load multiple impulse files using the .addImpulse method,\nthey will be stored as Objects in this Array. Toggle between them\nwith the toggleImpulse(id) method.

\n', + itemtype: 'property', + name: 'impulses', + type: 'Array', + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10162, + description: + '

Load and assign a new Impulse Response to the p5.Convolver.\nThe impulse is added to the .impulses array. Previous\nimpulses can be accessed with the .toggleImpulse(id)\nmethod.

\n', + itemtype: 'method', + name: 'addImpulse', + params: [ + { + name: 'path', + description: '

path to a sound file

\n', + type: 'String' + }, + { + name: 'callback', + description: '

function (optional)

\n', + type: 'Function' + }, + { + name: 'errorCallback', + description: '

function (optional)

\n', + type: 'Function' + } + ], + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10180, + description: + '

Similar to .addImpulse, except that the .impulses\nArray is reset to save memory. A new .impulses\narray is created with this impulse as the only item.

\n', + itemtype: 'method', + name: 'resetImpulse', + params: [ + { + name: 'path', + description: '

path to a sound file

\n', + type: 'String' + }, + { + name: 'callback', + description: '

function (optional)

\n', + type: 'Function' + }, + { + name: 'errorCallback', + description: '

function (optional)

\n', + type: 'Function' + } + ], + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10198, + description: + '

If you have used .addImpulse() to add multiple impulses\nto a p5.Convolver, then you can use this method to toggle between\nthe items in the .impulses Array. Accepts a parameter\nto identify which impulse you wish to use, identified either by its\noriginal filename (String) or by its position in the .impulses\n Array (Number).
\nYou can access the objects in the .impulses Array directly. Each\nObject has two attributes: an .audioBuffer (type:\nWeb Audio \nAudioBuffer) and a .name, a String that corresponds\nwith the original filename.

\n', + itemtype: 'method', + name: 'toggleImpulse', + params: [ + { + name: 'id', + description: + '

Identify the impulse by its original filename\n (String), or by its position in the\n .impulses Array (Number).

\n', + type: 'String|Number' + } + ], + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10240, + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10265, + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10460, + description: + '

Set the global tempo, in beats per minute, for all\np5.Parts. This method will impact all active p5.Parts.

\n', + itemtype: 'method', + name: 'setBPM', + params: [ + { + name: 'BPM', + description: '

Beats Per Minute

\n', + type: 'Number' + }, + { + name: 'rampTime', + description: '

Seconds from now

\n', + type: 'Number' + } + ], + class: 'p5.Convolver', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10550, + description: + '

Array of values to pass into the callback\nat each step of the phrase. Depending on the callback\nfunction's requirements, these values may be numbers,\nstrings, or an object with multiple parameters.\nZero (0) indicates a rest.

\n', + itemtype: 'property', + name: 'sequence', + type: 'Array', + class: 'p5.Phrase', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10638, + description: '

Set the tempo of this part, in Beats Per Minute.

\n', + itemtype: 'method', + name: 'setBPM', + params: [ + { + name: 'BPM', + description: '

Beats Per Minute

\n', + type: 'Number' + }, + { + name: 'rampTime', + description: '

Seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10648, + description: + '

Returns the tempo, in Beats Per Minute, of this part.

\n', + itemtype: 'method', + name: 'getBPM', + return: { + description: '', + type: 'Number' + }, + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10657, + description: + '

Start playback of this part. It will play\nthrough all of its phrases at a speed\ndetermined by setBPM.

\n', + itemtype: 'method', + name: 'start', + params: [ + { + name: 'time', + description: '

seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10673, + description: + '

Loop playback of this part. It will begin\nlooping through all of its phrases at a speed\ndetermined by setBPM.

\n', + itemtype: 'method', + name: 'loop', + params: [ + { + name: 'time', + description: '

seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10690, + description: '

Tell the part to stop looping.

\n', + itemtype: 'method', + name: 'noLoop', + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10702, + description: + '

Stop the part and cue it to step 0. Playback will resume from the begining of the Part when it is played again.

\n', + itemtype: 'method', + name: 'stop', + params: [ + { + name: 'time', + description: '

seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10712, + description: + '

Pause the part. Playback will resume\nfrom the current step.

\n', + itemtype: 'method', + name: 'pause', + params: [ + { + name: 'time', + description: '

seconds from now

\n', + type: 'Number' + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10724, + description: '

Add a p5.Phrase to this Part.

\n', + itemtype: 'method', + name: 'addPhrase', + params: [ + { + name: 'phrase', + description: '

reference to a p5.Phrase

\n', + type: 'p5.Phrase' + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10745, + description: + '

Remove a phrase from this part, based on the name it was\ngiven when it was created.

\n', + itemtype: 'method', + name: 'removePhrase', + params: [ + { + name: 'phraseName', + description: '', + type: 'String' + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10759, + description: + '

Get a phrase from this part, based on the name it was\ngiven when it was created. Now you can modify its array.

\n', + itemtype: 'method', + name: 'getPhrase', + params: [ + { + name: 'phraseName', + description: '', + type: 'String' + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10773, + description: + '

Find all sequences with the specified name, and replace their patterns with the specified array.

\n', + itemtype: 'method', + name: 'replaceSequence', + params: [ + { + name: 'phraseName', + description: '', + type: 'String' + }, + { + name: 'sequence', + description: + '

Array of values to pass into the callback\n at each step of the phrase.

\n', + type: 'Array' + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10800, + description: + '

Set the function that will be called at every step. This will clear the previous function.

\n', + itemtype: 'method', + name: 'onStep', + params: [ + { + name: 'callback', + description: + '

The name of the callback\n you want to fire\n on every beat/tatum.

\n', + type: 'Function' + } + ], + class: 'p5.Part', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10853, + description: '

Start playback of the score.

\n', + itemtype: 'method', + name: 'start', + class: 'p5.Score', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10862, + description: '

Stop playback of the score.

\n', + itemtype: 'method', + name: 'stop', + class: 'p5.Score', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10872, + description: '

Pause playback of the score.

\n', + itemtype: 'method', + name: 'pause', + class: 'p5.Score', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10880, + description: '

Loop playback of the score.

\n', + itemtype: 'method', + name: 'loop', + class: 'p5.Score', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10889, + description: + '

Stop looping playback of the score. If it\nis currently playing, this will go into effect\nafter the current round of playback completes.

\n', + itemtype: 'method', + name: 'noLoop', + class: 'p5.Score', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10914, + description: '

Set the tempo for all parts in the score

\n', + itemtype: 'method', + name: 'setBPM', + params: [ + { + name: 'BPM', + description: '

Beats Per Minute

\n', + type: 'Number' + }, + { + name: 'rampTime', + description: '

Seconds from now

\n', + type: 'Number' + } + ], + class: 'p5.Score', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10982, + description: + '

musicalTimeMode uses Tone.Time convention\ntrue if string, false if number

\n', + itemtype: 'property', + name: 'musicalTimeMode', + type: 'Boolean', + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10989, + description: + '

musicalTimeMode variables\nmodify these only when the interval is specified in musicalTime format as a string

\n', + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 10996, + description: + '

Set a limit to the number of loops to play. defaults to Infinity

\n', + itemtype: 'property', + name: 'maxIterations', + type: 'Number', + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11005, + description: + '

Do not initiate the callback if timeFromNow is < 0\nThis ususually occurs for a few milliseconds when the page\nis not fully loaded

\n

The callback should only be called until maxIterations is reached

\n', + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11019, + description: '

Start the loop

\n', + itemtype: 'method', + name: 'start', + params: [ + { + name: 'timeFromNow', + description: '

schedule a starting time

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11032, + description: '

Stop the loop

\n', + itemtype: 'method', + name: 'stop', + params: [ + { + name: 'timeFromNow', + description: '

schedule a stopping time

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11045, + description: '

Pause the loop

\n', + itemtype: 'method', + name: 'pause', + params: [ + { + name: 'timeFromNow', + description: '

schedule a pausing time

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11058, + description: + '

Synchronize loops. Use this method to start two more more loops in synchronization\nor to start a loop in synchronization with a loop that is already playing\nThis method will schedule the implicit loop in sync with the explicit master loop\ni.e. loopToStart.syncedStart(loopToSyncWith)

\n', + itemtype: 'method', + name: 'syncedStart', + params: [ + { + name: 'otherLoop', + description: '

a p5.SoundLoop to sync with

\n', + type: 'Object' + }, + { + name: 'timeFromNow', + description: + '

Start the loops in sync after timeFromNow seconds

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11139, + description: + '

Getters and Setters, setting any paramter will result in a change in the clock's\nfrequency, that will be reflected after the next callback\nbeats per minute (defaults to 60)

\n', + itemtype: 'property', + name: 'bpm', + type: 'Number', + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11157, + description: + '

number of quarter notes in a measure (defaults to 4)

\n', + itemtype: 'property', + name: 'timeSignature', + type: 'Number', + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11173, + description: '

length of the loops interval

\n', + itemtype: 'property', + name: 'interval', + type: 'Number|String', + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11187, + description: '

how many times the callback has been called so far

\n', + itemtype: 'property', + name: 'iterations', + type: 'Number', + readonly: '', + class: 'p5.SoundLoop', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11228, + description: + '

The p5.Compressor is built with a Web Audio Dynamics Compressor Node\n

\n', + itemtype: 'property', + name: 'compressor', + type: 'AudioNode', + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11239, + description: + '

Performs the same function as .connect, but also accepts\noptional parameters to set compressor's audioParams

\n', + itemtype: 'method', + name: 'process', + params: [ + { + name: 'src', + description: '

Sound source to be connected

\n', + type: 'Object' + }, + { + name: 'attack', + description: + '

The amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1

\n', + type: 'Number', + optional: true + }, + { + name: 'knee', + description: + '

A decibel value representing the range above the \n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40

\n', + type: 'Number', + optional: true + }, + { + name: 'ratio', + description: + '

The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20

\n', + type: 'Number', + optional: true + }, + { + name: 'threshold', + description: + '

The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0

\n', + type: 'Number', + optional: true + }, + { + name: 'release', + description: + '

The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11262, + description: '

Set the paramters of a compressor.

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'attack', + description: + '

The amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1

\n', + type: 'Number' + }, + { + name: 'knee', + description: + '

A decibel value representing the range above the \n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40

\n', + type: 'Number' + }, + { + name: 'ratio', + description: + '

The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20

\n', + type: 'Number' + }, + { + name: 'threshold', + description: + '

The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0

\n', + type: 'Number' + }, + { + name: 'release', + description: + '

The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1

\n', + type: 'Number' + } + ], + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11294, + description: '

Get current attack or set value w/ time ramp

\n', + itemtype: 'method', + name: 'attack', + params: [ + { + name: 'attack', + description: + '

Attack is the amount of time (in seconds) to reduce the gain by 10dB,\n default = .003, range 0 - 1

\n', + type: 'Number', + optional: true + }, + { + name: 'time', + description: + '

Assign time value to schedule the change in value

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11314, + description: '

Get current knee or set value w/ time ramp

\n', + itemtype: 'method', + name: 'knee', + params: [ + { + name: 'knee', + description: + '

A decibel value representing the range above the \n threshold where the curve smoothly transitions to the "ratio" portion.\n default = 30, range 0 - 40

\n', + type: 'Number', + optional: true + }, + { + name: 'time', + description: + '

Assign time value to schedule the change in value

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11334, + description: '

Get current ratio or set value w/ time ramp

\n', + itemtype: 'method', + name: 'ratio', + params: [ + { + name: 'ratio', + description: + '

The amount of dB change in input for a 1 dB change in output\n default = 12, range 1 - 20

\n', + type: 'Number', + optional: true + }, + { + name: 'time', + description: + '

Assign time value to schedule the change in value

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11353, + description: '

Get current threshold or set value w/ time ramp

\n', + itemtype: 'method', + name: 'threshold', + params: [ + { + name: 'threshold', + description: + '

The decibel value above which the compression will start taking effect\n default = -24, range -100 - 0

\n', + type: 'Number' + }, + { + name: 'time', + description: + '

Assign time value to schedule the change in value

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11372, + description: '

Get current release or set value w/ time ramp

\n', + itemtype: 'method', + name: 'release', + params: [ + { + name: 'release', + description: + '

The amount of time (in seconds) to increase the gain by 10dB\n default = .25, range 0 - 1

\n', + type: 'Number' + }, + { + name: 'time', + description: + '

Assign time value to schedule the change in value

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11392, + description: '

Return the current reduction value

\n', + itemtype: 'method', + name: 'reduction', + return: { + description: + 'Value of the amount of gain reduction that is applied to the signal', + type: 'Number' + }, + class: 'p5.Compressor', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11508, + description: + '

Connect a specific device to the p5.SoundRecorder.\nIf no parameter is given, p5.SoundRecorer will record\nall audible p5.sound from your sketch.

\n', + itemtype: 'method', + name: 'setInput', + params: [ + { + name: 'unit', + description: + '

p5.sound object or a web audio unit\n that outputs sound

\n', + type: 'Object', + optional: true + } + ], + class: 'p5.SoundRecorder', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11529, + description: + '

Start recording. To access the recording, provide\na p5.SoundFile as the first parameter. The p5.SoundRecorder\nwill send its recording to that p5.SoundFile for playback once\nrecording is complete. Optional parameters include duration\n(in seconds) of the recording, and a callback function that\nwill be called once the complete recording has been\ntransfered to the p5.SoundFile.

\n', + itemtype: 'method', + name: 'record', + params: [ + { + name: 'soundFile', + description: '

p5.SoundFile

\n', + type: 'p5.SoundFile' + }, + { + name: 'duration', + description: '

Time (in seconds)

\n', + type: 'Number', + optional: true + }, + { + name: 'callback', + description: + '

The name of a function that will be\n called once the recording completes

\n', + type: 'Function', + optional: true + } + ], + class: 'p5.SoundRecorder', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11562, + description: + '

Stop the recording. Once the recording is stopped,\nthe results will be sent to the p5.SoundFile that\nwas given on .record(), and if a callback function\nwas provided on record, that function will be called.

\n', + itemtype: 'method', + name: 'stop', + class: 'p5.SoundRecorder', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11635, + description: + '

Save a p5.SoundFile as a .wav file. The browser will prompt the user\nto download the file to their device.\nFor uploading audio to a server, use\np5.SoundFile.saveBlob.

\n', + itemtype: 'method', + name: 'saveSound', + params: [ + { + name: 'soundFile', + description: '

p5.SoundFile that you wish to save

\n', + type: 'p5.SoundFile' + }, + { + name: 'fileName', + description: '

name of the resulting .wav file.

\n', + type: 'String' + } + ], + class: 'p5', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11761, + description: '

isDetected is set to true when a peak is detected.

\n', + itemtype: 'attribute', + name: 'isDetected', + type: 'Boolean', + default: 'false', + class: 'p5.PeakDetect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11774, + description: + '

The update method is run in the draw loop.

\n

Accepts an FFT object. You must call .analyze()\non the FFT object prior to updating the peakDetect\nbecause it relies on a completed FFT analysis.

\n', + itemtype: 'method', + name: 'update', + params: [ + { + name: 'fftObject', + description: '

A p5.FFT object

\n', + type: 'p5.FFT' + } + ], + class: 'p5.PeakDetect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11805, + description: + '

onPeak accepts two arguments: a function to call when\na peak is detected. The value of the peak,\nbetween 0.0 and 1.0, is passed to the callback.

\n', + itemtype: 'method', + name: 'onPeak', + params: [ + { + name: 'callback', + description: + '

Name of a function that will\n be called when a peak is\n detected.

\n', + type: 'Function' + }, + { + name: 'val', + description: + '

Optional value to pass\n into the function when\n a peak is detected.

\n', + type: 'Object', + optional: true + } + ], + example: [ + "\n
\nvar cnv, soundFile, fft, peakDetect;\nvar ellipseWidth = 0;\n\nfunction preload() {\n soundFile = loadSound('assets/beat.mp3');\n}\n\nfunction setup() {\n cnv = createCanvas(100,100);\n textAlign(CENTER);\n\n fft = new p5.FFT();\n peakDetect = new p5.PeakDetect();\n\n setupSound();\n\n // when a beat is detected, call triggerBeat()\n peakDetect.onPeak(triggerBeat);\n}\n\nfunction draw() {\n background(0);\n fill(255);\n text('click to play', width/2, height/2);\n\n fft.analyze();\n peakDetect.update(fft);\n\n ellipseWidth *= 0.95;\n ellipse(width/2, height/2, ellipseWidth, ellipseWidth);\n}\n\n// this function is called by peakDetect.onPeak\nfunction triggerBeat() {\n ellipseWidth = 50;\n}\n\n// mouseclick starts/stops sound\nfunction setupSound() {\n cnv.mouseClicked( function() {\n if (soundFile.isPlaying() ) {\n soundFile.stop();\n } else {\n soundFile.play();\n }\n });\n}\n
" + ], + class: 'p5.PeakDetect', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11954, + description: '

Connect a source to the gain node.

\n', + itemtype: 'method', + name: 'setInput', + params: [ + { + name: 'src', + description: + '

p5.sound / Web Audio object with a sound\n output.

\n', + type: 'Object' + } + ], + class: 'p5.Gain', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11964, + description: '

Send output to a p5.sound or web audio object

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.Gain', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11974, + description: '

Disconnect all output.

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.Gain', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 11984, + description: '

Set the output level of the gain node.

\n', + itemtype: 'method', + name: 'amp', + params: [ + { + name: 'volume', + description: '

amplitude between 0 and 1.0

\n', + type: 'Number' + }, + { + name: 'rampTime', + description: '

create a fade that lasts rampTime

\n', + type: 'Number', + optional: true + }, + { + name: 'timeFromNow', + description: + '

schedule this event to happen\n seconds from now

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.Gain', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12042, + description: '

Connect to p5 objects or Web Audio Nodes

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: '', + type: 'Object' + } + ], + class: 'p5.AudioVoice', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12051, + description: '

Disconnect from soundOut

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.AudioVoice', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12131, + description: + '

Play tells the MonoSynth to start playing a note. This method schedules\nthe calling of .triggerAttack and .triggerRelease.

\n', + itemtype: 'method', + name: 'play', + params: [ + { + name: 'note', + description: + '

the note you want to play, specified as a\n frequency in Hertz (Number) or as a midi\n value in Note/Octave format ("C4", "Eb3"...etc")\n See \n Tone. Defaults to 440 hz.

\n', + type: 'String | Number' + }, + { + name: 'velocity', + description: + '

velocity of the note to play (ranging from 0 to 1)

\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: '

time from now (in seconds) at which to play

\n', + type: 'Number', + optional: true + }, + { + name: 'sustainTime', + description: '

time to sustain before releasing the envelope

\n', + type: 'Number', + optional: true + } + ], + example: [ + '\n
\nvar monoSynth;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n cnv.mousePressed(playSynth);\n\n monoSynth = new p5.MonoSynth();\n\n textAlign(CENTER);\n text(\'click to play\', width/2, height/2);\n}\n\nfunction playSynth() {\n // time from now (in seconds)\n var time = 0;\n // note duration (in seconds)\n var dur = 1/6;\n // note velocity (volume, from 0 to 1)\n var v = random();\n\n monoSynth.play("Fb3", v, 0, dur);\n monoSynth.play("Gb3", v, time += dur, dur);\n\n background(random(255), random(255), 255);\n text(\'click to play\', width/2, height/2);\n}\n
\n' + ], + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12179, + description: + '

Trigger the Attack, and Decay portion of the Envelope.\nSimilar to holding down a key on a piano, but it will\nhold the sustain level until you let go.

\n', + params: [ + { + name: 'note', + description: + '

the note you want to play, specified as a\n frequency in Hertz (Number) or as a midi\n value in Note/Octave format ("C4", "Eb3"...etc")\n See \n Tone. Defaults to 440 hz

\n', + type: 'String | Number' + }, + { + name: 'velocity', + description: + '

velocity of the note to play (ranging from 0 to 1)

\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: '

time from now (in seconds) at which to play

\n', + type: 'Number', + optional: true + } + ], + itemtype: 'method', + name: 'triggerAttack', + example: [ + '\n
\nvar monoSynth = new p5.MonoSynth();\n\nfunction mousePressed() {\n monoSynth.triggerAttack("E3");\n}\n\nfunction mouseReleased() {\n monoSynth.triggerRelease();\n}\n
' + ], + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12212, + description: + '

Trigger the release of the Envelope. This is similar to releasing\nthe key on a piano and letting the sound fade according to the\nrelease level and release time.

\n', + params: [ + { + name: 'secondsFromNow', + description: '

time to trigger the release

\n', + type: 'Number' + } + ], + itemtype: 'method', + name: 'triggerRelease', + example: [ + '\n
\nvar monoSynth = new p5.MonoSynth();\n\nfunction mousePressed() {\n monoSynth.triggerAttack("E3");\n}\n\nfunction mouseReleased() {\n monoSynth.triggerRelease();\n}\n
' + ], + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12236, + description: + '

Set values like a traditional\n\nADSR envelope\n.

\n', + itemtype: 'method', + name: 'setADSR', + params: [ + { + name: 'attackTime', + description: + '

Time (in seconds before envelope\n reaches Attack Level

\n', + type: 'Number' + }, + { + name: 'decayTime', + description: + '

Time (in seconds) before envelope\n reaches Decay/Sustain Level

\n', + type: 'Number', + optional: true + }, + { + name: 'susRatio', + description: + '

Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using setRange),\n then decayLevel would increase proportionally, to become 0.5.

\n', + type: 'Number', + optional: true + }, + { + name: 'releaseTime', + description: '

Time in seconds from now (defaults to 0)

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12260, + description: '

Getters and Setters

\n', + itemtype: 'property', + name: 'attack', + type: 'Number', + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12264, + itemtype: 'property', + name: 'decay', + type: 'Number', + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12267, + itemtype: 'property', + name: 'sustain', + type: 'Number', + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12270, + itemtype: 'property', + name: 'release', + type: 'Number', + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12307, + description: '

MonoSynth amp

\n', + itemtype: 'method', + name: 'amp', + params: [ + { + name: 'vol', + description: '

desired volume

\n', + type: 'Number' + }, + { + name: 'rampTime', + description: '

Time to reach new volume

\n', + type: 'Number', + optional: true + } + ], + return: { + description: 'new volume value', + type: 'Number' + }, + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12321, + description: '

Connect to a p5.sound / Web Audio object.

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: '

A p5.sound or Web Audio object

\n', + type: 'Object' + } + ], + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12331, + description: '

Disconnect all outputs

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12341, + description: + '

Get rid of the MonoSynth and free up its resources / memory.

\n', + itemtype: 'method', + name: 'dispose', + class: 'p5.MonoSynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12411, + description: + '

An object that holds information about which notes have been played and\nwhich notes are currently being played. New notes are added as keys\non the fly. While a note has been attacked, but not released, the value of the\nkey is the audiovoice which is generating that note. When notes are released,\nthe value of the key becomes undefined.

\n', + itemtype: 'property', + name: 'notes', + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12423, + description: + '

A PolySynth must have at least 1 voice, defaults to 8

\n', + itemtype: 'property', + name: 'polyvalue', + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12428, + description: + '

Monosynth that generates the sound for each note that is triggered. The\np5.PolySynth defaults to using the p5.MonoSynth as its voice.

\n', + itemtype: 'property', + name: 'AudioVoice', + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12459, + description: + '

Play a note by triggering noteAttack and noteRelease with sustain time

\n', + itemtype: 'method', + name: 'play', + params: [ + { + name: 'note', + description: + '

midi note to play (ranging from 0 to 127 - 60 being a middle C)

\n', + type: 'Number', + optional: true + }, + { + name: 'velocity', + description: + '

velocity of the note to play (ranging from 0 to 1)

\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: '

time from now (in seconds) at which to play

\n', + type: 'Number', + optional: true + }, + { + name: 'sustainTime', + description: '

time to sustain before releasing the envelope

\n', + type: 'Number', + optional: true + } + ], + example: [ + '\n
\nvar polySynth;\n\nfunction setup() {\n var cnv = createCanvas(100, 100);\n cnv.mousePressed(playSynth);\n\n polySynth = new p5.PolySynth();\n\n textAlign(CENTER);\n text(\'click to play\', width/2, height/2);\n}\n\nfunction playSynth() {\n // note duration (in seconds)\n var dur = 0.1;\n\n // time from now (in seconds)\n var time = 0;\n\n // velocity (volume, from 0 to 1)\n var vel = 0.1;\n\n polySynth.play("G2", vel, 0, dur);\n polySynth.play("C3", vel, 0, dur);\n polySynth.play("G3", vel, 0, dur);\n\n background(random(255), random(255), 255);\n text(\'click to play\', width/2, height/2);\n}\n
' + ], + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12505, + description: + '

noteADSR sets the envelope for a specific note that has just been triggered.\nUsing this method modifies the envelope of whichever audiovoice is being used\nto play the desired note. The envelope should be reset before noteRelease is called\nin order to prevent the modified envelope from being used on other notes.

\n', + itemtype: 'method', + name: 'noteADSR', + params: [ + { + name: 'note', + description: '

Midi note on which ADSR should be set.

\n', + type: 'Number', + optional: true + }, + { + name: 'attackTime', + description: + '

Time (in seconds before envelope\n reaches Attack Level

\n', + type: 'Number', + optional: true + }, + { + name: 'decayTime', + description: + '

Time (in seconds) before envelope\n reaches Decay/Sustain Level

\n', + type: 'Number', + optional: true + }, + { + name: 'susRatio', + description: + '

Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using setRange),\n then decayLevel would increase proportionally, to become 0.5.

\n', + type: 'Number', + optional: true + }, + { + name: 'releaseTime', + description: '

Time in seconds from now (defaults to 0)

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12533, + description: + '

Set the PolySynths global envelope. This method modifies the envelopes of each\nmonosynth so that all notes are played with this envelope.

\n', + itemtype: 'method', + name: 'setADSR', + params: [ + { + name: 'attackTime', + description: + '

Time (in seconds before envelope\n reaches Attack Level

\n', + type: 'Number', + optional: true + }, + { + name: 'decayTime', + description: + '

Time (in seconds) before envelope\n reaches Decay/Sustain Level

\n', + type: 'Number', + optional: true + }, + { + name: 'susRatio', + description: + '

Ratio between attackLevel and releaseLevel, on a scale from 0 to 1,\n where 1.0 = attackLevel, 0.0 = releaseLevel.\n The susRatio determines the decayLevel and the level at which the\n sustain portion of the envelope will sustain.\n For example, if attackLevel is 0.4, releaseLevel is 0,\n and susAmt is 0.5, the decayLevel would be 0.2. If attackLevel is\n increased to 1.0 (using setRange),\n then decayLevel would increase proportionally, to become 0.5.

\n', + type: 'Number', + optional: true + }, + { + name: 'releaseTime', + description: '

Time in seconds from now (defaults to 0)

\n', + type: 'Number', + optional: true + } + ], + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12557, + description: + '

Trigger the Attack, and Decay portion of a MonoSynth.\nSimilar to holding down a key on a piano, but it will\nhold the sustain level until you let go.

\n', + itemtype: 'method', + name: 'noteAttack', + params: [ + { + name: 'note', + description: '

midi note on which attack should be triggered.

\n', + type: 'Number', + optional: true + }, + { + name: 'velocity', + description: + '

velocity of the note to play (ranging from 0 to 1)/

\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: '

time from now (in seconds)

\n', + type: 'Number', + optional: true + } + ], + example: [ + '\n
\nvar polySynth = new p5.PolySynth();\nvar pitches = ["G", "D", "G", "C"];\nvar octaves = [2, 3, 4];\n\nfunction mousePressed() {\n // play a chord: multiple notes at the same time\n for (var i = 0; i < 4; i++) {\n var note = random(pitches) + random(octaves);\n polySynth.noteAttack(note, 0.1);\n }\n}\n\nfunction mouseReleased() {\n // release all voices\n polySynth.noteRelease();\n}\n
' + ], + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12647, + description: + '

Trigger the Release of an AudioVoice note. This is similar to releasing\nthe key on a piano and letting the sound fade according to the\nrelease level and release time.

\n', + itemtype: 'method', + name: 'noteRelease', + params: [ + { + name: 'note', + description: + '

midi note on which attack should be triggered.\n If no value is provided, all notes will be released.

\n', + type: 'Number', + optional: true + }, + { + name: 'secondsFromNow', + description: '

time to trigger the release

\n', + type: 'Number', + optional: true + } + ], + example: [ + '\n
\nvar pitches = ["G", "D", "G", "C"];\nvar octaves = [2, 3, 4];\nvar polySynth = new p5.PolySynth();\n\nfunction mousePressed() {\n // play a chord: multiple notes at the same time\n for (var i = 0; i < 4; i++) {\n var note = random(pitches) + random(octaves);\n polySynth.noteAttack(note, 0.1);\n }\n}\n\nfunction mouseReleased() {\n // release all voices\n polySynth.noteRelease();\n}\n
\n' + ], + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12712, + description: '

Connect to a p5.sound / Web Audio object.

\n', + itemtype: 'method', + name: 'connect', + params: [ + { + name: 'unit', + description: '

A p5.sound or Web Audio object

\n', + type: 'Object' + } + ], + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12722, + description: '

Disconnect all outputs

\n', + itemtype: 'method', + name: 'disconnect', + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12732, + description: + '

Get rid of the MonoSynth and free up its resources / memory.

\n', + itemtype: 'method', + name: 'dispose', + class: 'p5.PolySynth', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12800, + description: + '

The p5.Distortion is built with a\n\nWeb Audio WaveShaper Node.

\n', + itemtype: 'property', + name: 'WaveShaperNode', + type: 'AudioNode', + class: 'p5.Distortion', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12815, + description: + '

Process a sound source, optionally specify amount and oversample values.

\n', + itemtype: 'method', + name: 'process', + params: [ + { + name: 'amount', + description: + '

Unbounded distortion amount.\n Normal values range from 0-1.

\n', + type: 'Number', + optional: true, + optdefault: '0.25' + }, + { + name: 'oversample', + description: '

'none', '2x', or '4x'.

\n', + type: 'String', + optional: true, + optdefault: "'none'" + } + ], + class: 'p5.Distortion', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12827, + description: + '

Set the amount and oversample of the waveshaper distortion.

\n', + itemtype: 'method', + name: 'set', + params: [ + { + name: 'amount', + description: + '

Unbounded distortion amount.\n Normal values range from 0-1.

\n', + type: 'Number', + optional: true, + optdefault: '0.25' + }, + { + name: 'oversample', + description: '

'none', '2x', or '4x'.

\n', + type: 'String', + optional: true, + optdefault: "'none'" + } + ], + class: 'p5.Distortion', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12845, + description: + '

Return the distortion amount, typically between 0-1.

\n', + itemtype: 'method', + name: 'getAmount', + return: { + description: + 'Unbounded distortion amount.\n Normal values range from 0-1.', + type: 'Number' + }, + class: 'p5.Distortion', + module: 'p5.sound', + submodule: 'p5.sound' + }, + { + file: 'lib/addons/p5.sound.js', + line: 12855, + description: '

Return the oversampling.

\n', + itemtype: 'method', + name: 'getOversample', + return: { + description: "Oversample can either be 'none', '2x', or '4x'.", + type: 'String' + }, + class: 'p5.Distortion', + module: 'p5.sound', + submodule: 'p5.sound' + } + ], + warnings: [ + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:16' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:61' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:91' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:134' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:332' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:363' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:400' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:497' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:527' + }, + { + message: 'unknown tag: alt', + line: ' src/color/creating_reading.js:567' + }, + { + message: 'unknown tag: alt', + line: ' src/color/p5.Color.js:52' + }, + { + message: 'unknown tag: alt', + line: ' src/color/p5.Color.js:253' + }, + { + message: 'unknown tag: alt', + line: ' src/color/p5.Color.js:280' + }, + { + message: 'unknown tag: alt', + line: ' src/color/p5.Color.js:307' + }, + { + message: 'unknown tag: alt', + line: ' src/color/p5.Color.js:334' + }, + { + message: 'unknown tag: alt', + line: ' src/color/p5.Color.js:768' + }, + { + message: 'unknown tag: alt', + line: ' src/color/setting.js:15' + }, + { + message: 'unknown tag: alt', + line: ' src/color/setting.js:181' + }, + { + message: 'unknown tag: alt', + line: ' src/color/setting.js:220' + }, + { + message: 'unknown tag: alt', + line: ' src/color/setting.js:341' + }, + { + message: 'unknown tag: alt', + line: ' src/color/setting.js:498' + }, + { + message: 'unknown tag: alt', + line: ' src/color/setting.js:539' + }, + { + message: 'unknown tag: alt', + line: ' src/color/setting.js:579' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:102' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:210' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:270' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:300' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:356' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:391' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:458' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:541' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/2d_primitives.js:595' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/attributes.js:14' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/attributes.js:83' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/attributes.js:116' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/attributes.js:185' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/attributes.js:219' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/attributes.js:256' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/attributes.js:323' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/curves.js:13' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/curves.js:96' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/curves.js:139' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/curves.js:194' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/curves.js:273' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/curves.js:364' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/curves.js:406' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/curves.js:502' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:22' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:70' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:270' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:270' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:270' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:398' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:443' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:508' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:568' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:654' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:720' + }, + { + message: 'unknown tag: alt', + line: ' src/core/shape/vertex.js:813' + }, + { + message: 'unknown tag: alt', + line: ' src/core/constants.js:61' + }, + { + message: 'unknown tag: alt', + line: ' src/core/constants.js:80' + }, + { + message: 'unknown tag: alt', + line: ' src/core/constants.js:99' + }, + { + message: 'unknown tag: alt', + line: ' src/core/constants.js:118' + }, + { + message: 'unknown tag: alt', + line: ' src/core/constants.js:137' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:22' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:53' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:80' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:131' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:163' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:232' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:332' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:357' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:376' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:395' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:411' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:427' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:505' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:556' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/core/environment.js:591' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/core/environment.js:611' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:611' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:668' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:699' + }, + { + message: 'unknown tag: alt', + line: ' src/core/environment.js:722' + }, + { + message: 'unknown tag: alt', + line: ' src/core/main.js:42' + }, + { + message: 'unknown tag: alt', + line: ' src/core/main.js:83' + }, + { + message: 'unknown tag: alt', + line: ' src/core/main.js:114' + }, + { + message: 'unknown tag: alt', + line: ' src/core/main.js:396' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:52' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:122' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:162' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:197' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:258' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:307' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:373' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:427' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:483' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:541' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:584' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:626' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:674' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:714' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:763' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Element.js:801' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Graphics.js:65' + }, + { + message: 'unknown tag: alt', + line: ' src/core/p5.Graphics.js:117' + }, + { + message: 'unknown tag: alt', + line: ' src/core/rendering.js:17' + }, + { + message: 'unknown tag: alt', + line: ' src/core/rendering.js:119' + }, + { + message: 'unknown tag: alt', + line: ' src/core/rendering.js:174' + }, + { + message: 'unknown tag: alt', + line: ' src/core/rendering.js:197' + }, + { + message: 'unknown tag: alt', + line: ' src/core/rendering.js:236' + }, + { + message: 'unknown tag: alt', + line: ' src/core/structure.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/core/structure.js:74' + }, + { + message: 'unknown tag: alt', + line: ' src/core/structure.js:122' + }, + { + message: 'unknown tag: alt', + line: ' src/core/structure.js:191' + }, + { + message: 'unknown tag: alt', + line: ' src/core/structure.js:261' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:13' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:150' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:176' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:216' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:246' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:276' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:306' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:381' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:421' + }, + { + message: 'unknown tag: alt', + line: ' src/core/transform.js:461' + }, + { + message: 'unknown tag: alt', + line: ' src/data/local_storage.js:11' + }, + { + message: 'unknown tag: alt', + line: ' src/data/local_storage.js:88' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:23' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:46' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:69' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:135' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:166' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:197' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:233' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:278' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:322' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:380' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:419' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:462' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:506' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:538' + }, + { + message: 'unknown tag: alt', + line: ' src/events/acceleration.js:597' + }, + { + message: 'unknown tag: alt', + line: ' src/events/keyboard.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/events/keyboard.js:39' + }, + { + message: 'unknown tag: alt', + line: ' src/events/keyboard.js:68' + }, + { + message: 'unknown tag: alt', + line: ' src/events/keyboard.js:109' + }, + { + message: 'unknown tag: alt', + line: ' src/events/keyboard.js:196' + }, + { + message: 'unknown tag: alt', + line: ' src/events/keyboard.js:248' + }, + { + message: 'unknown tag: alt', + line: ' src/events/keyboard.js:312' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:22' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:49' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:76' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:109' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:141' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:180' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:219' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:260' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:302' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:341' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:432' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:487' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:568' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:650' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:728' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:798' + }, + { + message: 'unknown tag: alt', + line: ' src/events/mouse.js:883' + }, + { + message: 'unknown tag: alt', + line: ' src/events/touch.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/events/touch.js:74' + }, + { + message: 'unknown tag: alt', + line: ' src/events/touch.js:154' + }, + { + message: 'unknown tag: alt', + line: ' src/events/touch.js:227' + }, + { + message: 'unknown tag: alt', + line: ' src/image/image.js:22' + }, + { + message: 'unknown tag: alt', + line: ' src/image/image.js:102' + }, + { + message: 'unknown tag: alt', + line: ' src/image/image.js:195' + }, + { + message: 'unknown tag: alt', + line: ' src/image/loading_displaying.js:17' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/image/loading_displaying.js:110' + }, + { + message: 'unknown tag: alt', + line: ' src/image/loading_displaying.js:127' + }, + { + message: 'unknown tag: alt', + line: ' src/image/loading_displaying.js:298' + }, + { + message: 'unknown tag: alt', + line: ' src/image/loading_displaying.js:398' + }, + { + message: 'unknown tag: alt', + line: ' src/image/loading_displaying.js:464' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:90' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:117' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:153' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:232' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:268' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:316' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:371' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:409' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:494' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:575' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:638' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:674' + }, + { + message: 'unknown tag: alt', + line: ' src/image/p5.Image.js:796' + }, + { + message: 'unknown tag: alt', + line: ' src/image/pixels.js:14' + }, + { + message: 'unknown tag: alt', + line: ' src/image/pixels.js:83' + }, + { + message: 'unknown tag: alt', + line: ' src/image/pixels.js:177' + }, + { + message: 'unknown tag: alt', + line: ' src/image/pixels.js:236' + }, + { + message: 'unknown tag: alt', + line: ' src/image/pixels.js:415' + }, + { + message: 'unknown tag: alt', + line: ' src/image/pixels.js:503' + }, + { + message: 'unknown tag: alt', + line: ' src/image/pixels.js:540' + }, + { + message: 'unknown tag: alt', + line: ' src/image/pixels.js:614' + }, + { + message: 'unknown tag: alt', + line: ' src/io/files.js:19' + }, + { + message: 'unknown tag: alt', + line: ' src/io/files.js:184' + }, + { + message: 'unknown tag: alt', + line: ' src/io/files.js:297' + }, + { + message: 'unknown tag: alt', + line: ' src/io/files.js:607' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/io/files.js:718' + }, + { + message: 'unknown tag: alt', + line: ' src/io/files.js:718' + }, + { + message: 'unknown tag: alt', + line: ' src/io/files.js:1526' + }, + { + message: 'unknown tag: alt', + line: ' src/io/files.js:1584' + }, + { + message: 'unknown tag: alt', + line: ' src/io/files.js:1652' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:56' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:120' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:168' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:214' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:263' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:328' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:523' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:576' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:618' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:879' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:944' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:994' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:1040' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:1085' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:1132' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:1177' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:1230' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.Table.js:1296' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.TableRow.js:42' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.TableRow.js:106' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.TableRow.js:150' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.TableRow.js:195' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.TableRow.js:243' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.TableRow.js:299' + }, + { + message: 'unknown tag: alt', + line: ' src/io/p5.XML.js:11' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:36' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:76' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:121' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:190' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:240' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:279' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:327' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:383' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:422' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:478' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:528' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:578' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:631' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:665' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:704' + }, + { + message: 'unknown tag: alt', + line: ' src/math/calculation.js:751' + }, + { + message: 'unknown tag: alt', + line: ' src/math/math.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/math/noise.js:40' + }, + { + message: 'unknown tag: alt', + line: ' src/math/noise.js:187' + }, + { + message: 'unknown tag: alt', + line: ' src/math/noise.js:253' + }, + { + message: 'unknown tag: alt', + line: ' src/math/p5.Vector.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/math/random.js:48' + }, + { + message: 'unknown tag: alt', + line: ' src/math/random.js:79' + }, + { + message: 'unknown tag: alt', + line: ' src/math/random.js:166' + }, + { + message: 'unknown tag: alt', + line: ' src/math/trigonometry.js:124' + }, + { + message: 'unknown tag: alt', + line: ' src/math/trigonometry.js:160' + }, + { + message: 'unknown tag: alt', + line: ' src/math/trigonometry.js:188' + }, + { + message: 'unknown tag: alt', + line: ' src/math/trigonometry.js:216' + }, + { + message: 'unknown tag: alt', + line: ' src/math/trigonometry.js:296' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/math/trigonometry.js:332' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/math/trigonometry.js:347' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/math/trigonometry.js:362' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/attributes.js:13' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/attributes.js:84' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/attributes.js:122' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/attributes.js:154' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/attributes.js:191' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/loading_displaying.js:16' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/loading_displaying.js:143' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/loading_displaying.js:230' + }, + { + message: 'unknown tag: alt', + line: ' src/typography/p5.Font.js:32' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/conversion.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/string_functions.js:15' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/string_functions.js:44' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/string_functions.js:132' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/string_functions.js:243' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/string_functions.js:319' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/string_functions.js:381' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/string_functions.js:459' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/string_functions.js:548' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/time_date.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/time_date.js:34' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/time_date.js:56' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/time_date.js:78' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/time_date.js:101' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/time_date.js:123' + }, + { + message: 'unknown tag: alt', + line: ' src/utilities/time_date.js:145' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/3d_primitives.js:14' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/interaction.js:13' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/interaction.js:146' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/interaction.js:146' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/interaction.js:146' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/interaction.js:146' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/interaction.js:146' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/interaction.js:380' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/light.js:12' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/light.js:87' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/light.js:185' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/light.js:287' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/light.js:318' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/loading.js:14' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/loading.js:14' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/loading.js:580' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:14' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/webgl/material.js:113' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:113' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:181' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:285' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:322' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:419' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:419' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:498' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:573' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:623' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/material.js:674' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:15' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:61' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:126' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:209' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:486' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:545' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:603' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:751' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:823' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Camera.js:1088' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/webgl/p5.RendererGL.Retained.js:40' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.RendererGL.js:263' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.RendererGL.js:519' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.RendererGL.js:561' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.RendererGL.js:631' + }, + { + message: 'unknown tag: alt', + line: ' src/webgl/p5.Shader.js:269' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:117' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/webgl/text.js:160' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:193' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:205' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:235' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:249' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:387' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' src/webgl/text.js:387' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:457' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:472' + }, + { + message: 'replacing incorrect tag: function with method', + line: ' src/webgl/text.js:547' + }, + { + message: 'unknown tag: alt', + line: ' lib/addons/p5.dom.js:245' + }, + { + message: 'unknown tag: alt', + line: ' lib/addons/p5.dom.js:313' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.dom.js:1463' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.dom.js:1525' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.dom.js:1629' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.dom.js:1668' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.dom.js:1762' + }, + { + message: 'unknown tag: alt', + line: ' lib/addons/p5.dom.js:2119' + }, + { + message: 'replacing incorrect tag: params with param', + line: ' lib/addons/p5.sound.js:2480' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.sound.js:2480' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.sound.js:3094' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.sound.js:7659' + }, + { + message: 'replacing incorrect tag: returns with return', + line: ' lib/addons/p5.sound.js:9626' + }, + { + message: + "Missing item type\nConversions adapted from .\n\nIn these functions, hue is always in the range [0, 1], just like all other\ncomponents are in the range [0, 1]. 'Brightness' and 'value' are used\ninterchangeably.", + line: ' src/color/color_conversion.js:10' + }, + { + message: 'Missing item type\nConvert an HSBA array to HSLA.', + line: ' src/color/color_conversion.js:21' + }, + { + message: 'Missing item type\nConvert an HSBA array to RGBA.', + line: ' src/color/color_conversion.js:47' + }, + { + message: 'Missing item type\nConvert an HSLA array to HSBA.', + line: ' src/color/color_conversion.js:102' + }, + { + message: + "Missing item type\nConvert an HSLA array to RGBA.\n\nWe need to change basis from HSLA to something that can be more easily be\nprojected onto RGBA. We will choose hue and brightness as our first two\ncomponents, and pick a convenient third one ('zest') so that we don't need\nto calculate formal HSBA saturation.", + line: ' src/color/color_conversion.js:125' + }, + { + message: 'Missing item type\nConvert an RGBA array to HSBA.', + line: ' src/color/color_conversion.js:189' + }, + { + message: 'Missing item type\nConvert an RGBA array to HSLA.', + line: ' src/color/color_conversion.js:228' + }, + { + message: + 'Missing item type\nHue is the same in HSB and HSL, but the maximum value may be different.\nThis function will return the HSB-normalized saturation when supplied with\nan HSB color object, but will default to the HSL-normalized saturation\notherwise.', + line: ' src/color/p5.Color.js:415' + }, + { + message: + 'Missing item type\nSaturation is scaled differently in HSB and HSL. This function will return\nthe HSB saturation when supplied with an HSB color object, but will default\nto the HSL saturation otherwise.', + line: ' src/color/p5.Color.js:446' + }, + { + message: 'Missing item type\nCSS named colors.', + line: ' src/color/p5.Color.js:465' + }, + { + message: + 'Missing item type\nThese regular expressions are used to build up the patterns for matching\nviable CSS color strings: fragmenting the regexes in this way increases the\nlegibility and comprehensibility of the code.\n\nNote that RGB values of .9 are not parsed by IE, but are supported here for\ncolor string consistency.', + line: ' src/color/p5.Color.js:618' + }, + { + message: + 'Missing item type\nFull color string patterns. The capture groups are necessary.', + line: ' src/color/p5.Color.js:631' + }, + { + message: + 'Missing item type\nFor a number of different inputs, returns a color formatted as [r, g, b, a]\narrays, with each component normalized between 0 and 1.', + line: ' src/color/p5.Color.js:768' + }, + { + message: + 'Missing item type\nFor HSB and HSL, interpret the gray level as a brightness/lightness\nvalue (they are equivalent when chroma is zero). For RGB, normalize the\ngray level according to the blue maximum.', + line: ' src/color/p5.Color.js:994' + }, + { + message: + "Missing item type\nThis function does 3 things:\n\n 1. Bounds the desired start/stop angles for an arc (in radians) so that:\n\n 0 <= start < TWO_PI ; start <= stop < start + TWO_PI\n\n This means that the arc rendering functions don't have to be concerned\n with what happens if stop is smaller than start, or if the arc 'goes\n round more than once', etc.: they can just start at start and increase\n until stop and the correct arc will be drawn.\n\n 2. Optionally adjusts the angles within each quadrant to counter the naive\n scaling of the underlying ellipse up from the unit circle. Without\n this, the angles become arbitrary when width != height: 45 degrees\n might be drawn at 5 degrees on a 'wide' ellipse, or at 85 degrees on\n a 'tall' ellipse.\n\n 3. Flags up when start and stop correspond to the same place on the\n underlying ellipse. This is useful if you want to do something special\n there (like rendering a whole ellipse instead).", + line: ' src/core/shape/2d_primitives.js:16' + }, + { + message: 'Missing item type\nReturns the current framerate.', + line: ' src/core/environment.js:306' + }, + { + message: + 'Missing item type\nSpecifies the number of frames to be displayed every second. For example,\nthe function call frameRate(30) will attempt to refresh 30 times a second.\nIf the processor is not fast enough to maintain the specified rate, the\nframe rate will not be achieved. Setting the frame rate within setup() is\nrecommended. The default rate is 60 frames per second.\n\nCalling frameRate() with no arguments returns the current framerate.', + line: ' src/core/environment.js:316' + }, + { + message: 'Missing item type', + line: ' src/core/error_helpers.js:1' + }, + { + message: + 'Missing item type\nValidates parameters\nparam {String} func the name of the function\nparam {Array} args user input arguments\n\nexample:\n var a;\n ellipse(10,10,a,5);\nconsole ouput:\n "It looks like ellipse received an empty variable in spot #2."\n\nexample:\n ellipse(10,"foo",5,5);\nconsole output:\n "ellipse was expecting a number for parameter #1,\n received "foo" instead."', + line: ' src/core/error_helpers.js:584' + }, + { + message: + 'Missing item type\nPrints out all the colors in the color pallete with white text.\nFor color blindness testing.', + line: ' src/core/error_helpers.js:645' + }, + { + message: 'Missing item type', + line: ' src/core/helpers.js:1' + }, + { + message: + 'Missing item type\n_globalInit\n\nTODO: ???\nif sketch is on window\nassume "global" mode\nand instantiate p5 automatically\notherwise do nothing', + line: ' src/core/init.js:5' + }, + { + message: 'Missing item type', + line: ' src/core/legacy.js:1' + }, + { + message: 'Missing item type\nHelper fxn for sharing pixel methods', + line: ' src/core/p5.Element.js:865' + }, + { + message: 'Missing item type\nResize our canvas element.', + line: ' src/core/p5.Renderer.js:97' + }, + { + message: 'Missing item type\nHelper fxn to check font type (system or otf)', + line: ' src/core/p5.Renderer.js:335' + }, + { + message: + 'Missing item type\nHelper fxn to measure ascent and descent.\nAdapted from http://stackoverflow.com/a/25355178', + line: ' src/core/p5.Renderer.js:388' + }, + { + message: + 'Missing item type\np5.Renderer2D\nThe 2D graphics canvas renderer class.\nextends p5.Renderer', + line: ' src/core/p5.Renderer2D.js:9' + }, + { + message: + 'Missing item type\nGenerate a cubic Bezier representing an arc on the unit circle of total\nangle `size` radians, beginning `start` radians above the x-axis. Up to\nfour of these curves are combined to make a full arc.\n\nSee www.joecridge.me/bezier.pdf for an explanation of the method.', + line: ' src/core/p5.Renderer2D.js:407' + }, + { + message: + 'Missing item type\nshim for Uint8ClampedArray.slice\n(allows arrayCopy to work with pixels[])\nwith thanks to http://halfpapstudios.com/blog/tag/html5-canvas/\nEnumerable set to false to protect for...in from\nUint8ClampedArray.prototype pollution.', + line: ' src/core/shim.js:23' + }, + { + message: + 'Missing item type\nthis is implementation of Object.assign() which is unavailable in\nIE11 and (non-Chrome) Android browsers.\nThe assign() method is used to copy the values of all enumerable\nown properties from one or more source objects to a target object.\nIt will return the target object.\nModified from https://github.com/ljharb/object.assign', + line: ' src/core/shim.js:45' + }, + { + message: + 'Missing item type\nprivate helper function to handle the user passing in objects\nduring construction or calls to create()', + line: ' src/data/p5.TypedDict.js:203' + }, + { + message: + 'Missing item type\nprivate helper function to ensure that the user passed in valid\nvalues for the Dictionary type', + line: ' src/data/p5.TypedDict.js:394' + }, + { + message: + 'Missing item type\nprivate helper function to ensure that the user passed in valid\nvalues for the Dictionary type', + line: ' src/data/p5.TypedDict.js:437' + }, + { + message: + "Missing item type\nprivate helper function for finding lowest or highest value\nthe argument 'flip' is used to flip the comparison arrow\nfrom 'less than' to 'greater than'", + line: ' src/data/p5.TypedDict.js:554' + }, + { + message: + "Missing item type\nprivate helper function for finding lowest or highest key\nthe argument 'flip' is used to flip the comparison arrow\nfrom 'less than' to 'greater than'", + line: ' src/data/p5.TypedDict.js:621' + }, + { + message: + 'Missing item type\n_updatePAccelerations updates the pAcceleration values', + line: ' src/events/acceleration.js:124' + }, + { + message: + 'Missing item type\nThe onblur function is called when the user is no longer focused\non the p5 element. Because the keyup events will not fire if the user is\nnot focused on the element we must assume all keys currently down have\nbeen released.', + line: ' src/events/keyboard.js:302' + }, + { + message: + 'Missing item type\nThe _areDownKeys function returns a boolean true if any keys pressed\nand a false if no keys are currently pressed.\n\nHelps avoid instances where multiple keys are pressed simultaneously and\nreleasing a single key will then switch the\nkeyIsPressed property to true.', + line: ' src/events/keyboard.js:389' + }, + { + message: + 'Missing item type\nThis module defines the filters for use with image buffers.\n\nThis module is basically a collection of functions stored in an object\nas opposed to modules. The functions are destructive, modifying\nthe passed in canvas rather than creating a copy.\n\nGenerally speaking users of this module will use the Filters.apply method\non a canvas to create an effect.\n\nA number of functions are borrowed/adapted from\nhttp://www.html5rocks.com/en/tutorials/canvas/imagefilters/\nor the java processing implementation.', + line: ' src/image/filters.js:3' + }, + { + message: 'Missing item type\nReturns the pixel buffer for a canvas', + line: ' src/image/filters.js:26' + }, + { + message: + 'Missing item type\nReturns a 32 bit number containing ARGB data at ith pixel in the\n1D array containing pixels data.', + line: ' src/image/filters.js:46' + }, + { + message: + 'Missing item type\nModifies pixels RGBA values to values contained in the data object.', + line: ' src/image/filters.js:67' + }, + { + message: + 'Missing item type\nReturns the ImageData object for a canvas\nhttps://developer.mozilla.org/en-US/docs/Web/API/ImageData', + line: ' src/image/filters.js:87' + }, + { + message: 'Missing item type\nReturns a blank ImageData object.', + line: ' src/image/filters.js:107' + }, + { + message: + 'Missing item type\nApplys a filter function to a canvas.\n\nThe difference between this and the actual filter functions defined below\nis that the filter functions generally modify the pixel buffer but do\nnot actually put that data back to the canvas (where it would actually\nupdate what is visible). By contrast this method does make the changes\nactually visible in the canvas.\n\nThe apply method is the method that callers of this module would generally\nuse. It has been separated from the actual filters to support an advanced\nuse case of creating a filter chain that executes without actually updating\nthe canvas in between everystep.', + line: ' src/image/filters.js:122' + }, + { + message: + 'Missing item type\nConverts the image to black and white pixels depending if they are above or\nbelow the threshold defined by the level parameter. The parameter must be\nbetween 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used.\n\nBorrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/', + line: ' src/image/filters.js:175' + }, + { + message: + 'Missing item type\nConverts any colors in the image to grayscale equivalents.\nNo parameter is used.\n\nBorrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/', + line: ' src/image/filters.js:209' + }, + { + message: + 'Missing item type\nSets the alpha channel to entirely opaque. No parameter is used.', + line: ' src/image/filters.js:232' + }, + { + message: + 'Missing item type\nSets each pixel to its inverse value. No parameter is used.', + line: ' src/image/filters.js:248' + }, + { + message: + 'Missing item type\nLimits each channel of the image to the number of colors specified as\nthe parameter. The parameter can be set to values between 2 and 255, but\nresults are most noticeable in the lower ranges.\n\nAdapted from java based processing implementation', + line: ' src/image/filters.js:263' + }, + { + message: 'Missing item type\nreduces the bright areas in an image', + line: ' src/image/filters.js:295' + }, + { + message: 'Missing item type\nincreases the bright areas in an image', + line: ' src/image/filters.js:383' + }, + { + message: + 'Missing item type\nThis module defines the p5 methods for the p5.Image class\nfor drawing images to the main display canvas.', + line: ' src/image/image.js:8' + }, + { + message: + 'Missing item type\nValidates clipping params. Per drawImage spec sWidth and sHight cannot be\nnegative or greater than image intrinsic width and height', + line: ' src/image/loading_displaying.js:110' + }, + { + message: + 'Missing item type\nApply the current tint color to the input image, return the resulting\ncanvas.', + line: ' src/image/loading_displaying.js:427' + }, + { + message: + 'Missing item type\nThis module defines the p5.Image class and P5 methods for\ndrawing images to the main display canvas.', + line: ' src/image/p5.Image.js:9' + }, + { + message: 'Missing item type\nHelper fxn for sharing pixel methods', + line: ' src/image/p5.Image.js:223' + }, + { + message: + 'Missing item type\nGenerate a blob of file data as a url to prepare for download.\nAccepts an array of data, a filename, and an extension (optional).\nThis is a private function because it does not do any formatting,\nbut it is used by saveStrings, saveJSON, saveTable etc.', + line: ' src/io/files.js:1778' + }, + { + message: + 'Missing item type\nReturns a file extension, or another string\nif the provided parameter has no extension.', + line: ' src/io/files.js:1847' + }, + { + message: + 'Missing item type\nReturns true if the browser is Safari, false if not.\nSafari makes trouble for downloading files.', + line: ' src/io/files.js:1880' + }, + { + message: + 'Missing item type\nHelper function, a callback for download that deletes\nan invisible anchor element from the DOM once the file\nhas been automatically downloaded.', + line: ' src/io/files.js:1892' + }, + { + message: + 'Missing item type\nTable Options\n

Generic class for handling tabular data, typically from a\nCSV, TSV, or other sort of spreadsheet file.

\n

CSV files are\n\ncomma separated values, often with the data in quotes. TSV\nfiles use tabs as separators, and usually don\'t bother with the\nquotes.

\n

File names should end with .csv if they\'re comma separated.

\n

A rough "spec" for CSV can be found\nhere.

\n

To load files, use the loadTable method.

\n

To save tables to your computer, use the save method\n or the saveTable method.

\n\nPossible options include:\n
    \n
  • csv - parse the table as comma-separated values\n
  • tsv - parse the table as tab-separated values\n
  • header - this table has a header (title) row\n
', + line: ' src/io/p5.Table.js:11' + }, + { + message: + 'Missing item type\nMultiplies a vector by a scalar and returns a new vector.', + line: ' src/math/p5.Vector.js:1610' + }, + { + message: + 'Missing item type\nDivides a vector by a scalar and returns a new vector.', + line: ' src/math/p5.Vector.js:1637' + }, + { + message: 'Missing item type\nCalculates the dot product of two vectors.', + line: ' src/math/p5.Vector.js:1664' + }, + { + message: 'Missing item type\nCalculates the cross product of two vectors.', + line: ' src/math/p5.Vector.js:1678' + }, + { + message: + 'Missing item type\nCalculates the Euclidean distance between two points (considering a\npoint as a vector object).', + line: ' src/math/p5.Vector.js:1692' + }, + { + message: + 'Missing item type\nLinear interpolate a vector to another vector and return the result as a\nnew vector.', + line: ' src/math/p5.Vector.js:1707' + }, + { + message: + 'Missing item type\nHelper function to measure ascent and descent.', + line: ' src/typography/attributes.js:284' + }, + { + message: + 'Missing item type\nReturns the set of opentype glyphs for the supplied string.\n\nNote that there is not a strict one-to-one mapping between characters\nand glyphs, so the list of returned glyphs can be larger or smaller\n than the length of the given string.', + line: ' src/typography/p5.Font.js:255' + }, + { + message: + 'Missing item type\nReturns an opentype path for the supplied string and position.', + line: ' src/typography/p5.Font.js:270' + }, + { + message: 'Missing item type', + line: ' src/webgl/3d_primitives.js:260' + }, + { + message: + 'Missing item type\nDraws a point, a coordinate in space at the dimension of one pixel,\ngiven x, y and z coordinates. The color of the point is determined\nby the current stroke, while the point size is determined by current\nstroke weight.', + line: ' src/webgl/3d_primitives.js:732' + }, + { + message: 'Missing item type\nDraw a line given two points', + line: ' src/webgl/3d_primitives.js:1155' + }, + { + message: + 'Missing item type\nParse OBJ lines into model. For reference, this is what a simple model of a\nsquare might look like:\n\nv -0.5 -0.5 0.5\nv -0.5 -0.5 -0.5\nv -0.5 0.5 -0.5\nv -0.5 0.5 0.5\n\nf 4 3 2 1', + line: ' src/webgl/loading.js:169' + }, + { + message: + 'Missing item type\nSTL files can be of two types, ASCII and Binary,\n\nWe need to convert the arrayBuffer to an array of strings,\nto parse it as an ASCII file.', + line: ' src/webgl/loading.js:278' + }, + { + message: + 'Missing item type\nThis function checks if the file is in ASCII format or in Binary format\n\nIt is done by searching keyword `solid` at the start of the file.\n\nAn ASCII STL data must begin with `solid` as the first six bytes.\nHowever, ASCII STLs lacking the SPACE after the `d` are known to be\nplentiful. So, check the first 5 bytes for `solid`.\n\nSeveral encodings, such as UTF-8, precede the text with up to 5 bytes:\nhttps://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding\nSearch for `solid` to start anywhere after those prefixes.', + line: ' src/webgl/loading.js:305' + }, + { + message: + 'Missing item type\nThis function matches the `query` at the provided `offset`', + line: ' src/webgl/loading.js:332' + }, + { + message: + 'Missing item type\nThis function parses the Binary STL files.\nhttps://en.wikipedia.org/wiki/STL_%28file_format%29#Binary_STL\n\nCurrently there is no support for the colors provided in STL files.', + line: ' src/webgl/loading.js:344' + }, + { + message: + "Missing item type\nASCII STL file starts with `solid 'nameOfFile'`\nThen contain the normal of the face, starting with `facet normal`\nNext contain a keyword indicating the start of face vertex, `outer loop`\nNext comes the three vertex, starting with `vertex x y z`\nVertices ends with `endloop`\nFace ends with `endfacet`\nNext face starts with `facet normal`\nThe end of the file is indicated by `endsolid`", + line: ' src/webgl/loading.js:433' + }, + { + message: 'Missing item type', + line: ' src/webgl/material.js:719' + }, + { + message: 'Missing item type', + line: ' src/webgl/material.js:741' + }, + { + message: + 'Missing item type\nCreate a 2D array for establishing stroke connections', + line: ' src/webgl/p5.Geometry.js:206' + }, + { + message: + "Missing item type\nCreate 4 vertices for each stroke line, two at the beginning position\nand two at the end position. These vertices are displaced relative to\nthat line's normal on the GPU", + line: ' src/webgl/p5.Geometry.js:227' + }, + { + message: 'Missing item type', + line: ' src/webgl/p5.Matrix.js:1' + }, + { + message: 'Missing item type\nPRIVATE', + line: ' src/webgl/p5.Matrix.js:730' + }, + { + message: + 'Missing item type\nWelcome to RendererGL Immediate Mode.\nImmediate mode is used for drawing custom shapes\nfrom a set of vertices. Immediate Mode is activated\nwhen you call beginShape() & de-activated when you call endShape().\nImmediate mode is a style of programming borrowed\nfrom OpenGL\'s (now-deprecated) immediate mode.\nIt differs from p5.js\' default, Retained Mode, which caches\ngeometries and buffers on the CPU to reduce the number of webgl\ndraw calls. Retained mode is more efficient & performative,\nhowever, Immediate Mode is useful for sketching quick\ngeometric ideas.', + line: ' src/webgl/p5.RendererGL.Immediate.js:1' + }, + { + message: + 'Missing item type\nEnd shape drawing and render vertices to screen.', + line: ' src/webgl/p5.RendererGL.Immediate.js:140' + }, + { + message: + 'Missing item type\ninitializes buffer defaults. runs each time a new geometry is\nregistered', + line: ' src/webgl/p5.RendererGL.Retained.js:40' + }, + { + message: + 'Missing item type\ncreates a buffers object that holds the WebGL render buffers\nfor a geometry.', + line: ' src/webgl/p5.RendererGL.Retained.js:144' + }, + { + message: 'Missing item type\nDraws buffers given a geometry key ID', + line: ' src/webgl/p5.RendererGL.Retained.js:182' + }, + { + message: 'Missing item type\nmodel view, projection, & normal\nmatrices', + line: ' src/webgl/p5.RendererGL.js:96' + }, + { + message: 'Missing item type\n[background description]', + line: ' src/webgl/p5.RendererGL.js:501' + }, + { + message: 'Missing item type\n[resize description]', + line: ' src/webgl/p5.RendererGL.js:752' + }, + { + message: 'Missing item type\nclears color and depth buffers\nwith r,g,b,a', + line: ' src/webgl/p5.RendererGL.js:783' + }, + { + message: 'Missing item type\n[translate description]', + line: ' src/webgl/p5.RendererGL.js:816' + }, + { + message: 'Missing item type\nScales the Model View Matrix by a vector', + line: ' src/webgl/p5.RendererGL.js:835' + }, + { + message: + 'Missing item type\nturn a two dimensional array into one dimensional array', + line: ' src/webgl/p5.RendererGL.js:1200' + }, + { + message: + 'Missing item type\nturn a p5.Vector Array into a one dimensional number array', + line: ' src/webgl/p5.RendererGL.js:1237' + }, + { + message: + 'Missing item type\nensures that p5 is using a 3d renderer. throws an error if not.', + line: ' src/webgl/p5.RendererGL.js:1254' + }, + { + message: 'Missing item type\nHelper function for select and selectAll', + line: ' lib/addons/p5.dom.js:168' + }, + { + message: + 'Missing item type\nHelper function for getElement and getElements.', + line: ' lib/addons/p5.dom.js:184' + }, + { + message: 'Missing item type\nHelpers for create methods.', + line: ' lib/addons/p5.dom.js:348' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.dom.js:488' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.dom.js:1070' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.dom.js:1159' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.dom.js:1199' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.dom.js:3021' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.dom.js:3087' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.dom.js:3149' + }, + { + message: + "Missing item type\np5.sound \nhttps://p5js.org/reference/#/libraries/p5.sound\n\nFrom the Processing Foundation and contributors\nhttps://github.com/processing/p5.js-sound/graphs/contributors\n\nMIT License (MIT)\nhttps://github.com/processing/p5.js-sound/blob/master/LICENSE\n\nSome of the many audio libraries & resources that inspire p5.sound:\n - TONE.js (c) Yotam Mann. Licensed under The MIT License (MIT). https://github.com/TONEnoTONE/Tone.js\n - buzz.js (c) Jay Salvat. Licensed under The MIT License (MIT). http://buzz.jaysalvat.com/\n - Boris Smus Web Audio API book, 2013. Licensed under the Apache License http://www.apache.org/licenses/LICENSE-2.0\n - wavesurfer.js https://github.com/katspaugh/wavesurfer.js\n - Web Audio Components by Jordan Santell https://github.com/web-audio-components\n - Wilm Thoben's Sound library for Processing https://github.com/processing/processing/tree/master/java/libraries/sound\n\n Web Audio API: http://w3.org/TR/webaudio/", + line: ' lib/addons/p5.sound.js:46' + }, + { + message: + 'Missing item type\nDetermine which filetypes are supported (inspired by buzz.js)\nThe audio element (el) will only be used to test browser support for various audio formats', + line: ' lib/addons/p5.sound.js:214' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:363' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:740' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:810' + }, + { + message: + 'Missing item type\nMaster contains AudioContext and the master sound output.', + line: ' lib/addons/p5.sound.js:1099' + }, + { + message: + 'Missing item type\na silent connection to the DesinationNode\nwhich will ensure that anything connected to it\nwill not be garbage collected', + line: ' lib/addons/p5.sound.js:1194' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:1210' + }, + { + message: 'Missing item type\nUsed by Osc and Envelope to chain signal math', + line: ' lib/addons/p5.sound.js:1415' + }, + { + message: + 'Missing item type\nThis is a helper function that the p5.SoundFile calls to load\nitself. Accepts a callback (the name of another function)\nas an optional parameter.', + line: ' lib/addons/p5.sound.js:1813' + }, + { + message: + "Missing item type\nStop playback on all of this soundfile's sources.", + line: ' lib/addons/p5.sound.js:2218' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:2656' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:2934' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:4055' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:4076' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:4135' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:4453' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:4625' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:4783' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:4824' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:4881' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:5049' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:5097' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:5128' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:5149' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:5169' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:5879' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:6082' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7750' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7766' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7790' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7816' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7838' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7860' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7906' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7937' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:7955' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:8292' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:8314' + }, + { + message: + 'Missing item type\nThe p5.Effect class is built\n \tusing Tone.js CrossFade', + line: ' lib/addons/p5.sound.js:8384' + }, + { + message: + 'Missing item type\nIn classes that extend\np5.Effect, connect effect nodes\nto the wet parameter', + line: ' lib/addons/p5.sound.js:8390' + }, + { + message: + 'Missing item type\nEQFilter extends p5.Filter with constraints\nnecessary for the p5.EQ', + line: ' lib/addons/p5.sound.js:8779' + }, + { + message: + 'Missing item type\nInspired by Simple Reverb by Jordan Santell\nhttps://github.com/web-audio-components/simple-reverb/blob/master/index.js\n\nUtility function for building an impulse response\nbased on the module parameters.', + line: ' lib/addons/p5.sound.js:9889' + }, + { + message: + 'Missing item type\nPrivate method to load a buffer as an Impulse Response,\nassign it to the convolverNode, and add to the Array of .impulses.', + line: ' lib/addons/p5.sound.js:10056' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:10240' + }, + { + message: 'Missing item type', + line: ' lib/addons/p5.sound.js:10265' + }, + { + message: + 'Missing item type\nmusicalTimeMode variables\nmodify these only when the interval is specified in musicalTime format as a string', + line: ' lib/addons/p5.sound.js:10989' + }, + { + message: + 'Missing item type\nDo not initiate the callback if timeFromNow is < 0\nThis ususually occurs for a few milliseconds when the page\nis not fully loaded\n\nThe callback should only be called until maxIterations is reached', + line: ' lib/addons/p5.sound.js:11005' + }, + { + message: 'Missing item type\ncallback invoked when the recording is over', + line: ' lib/addons/p5.sound.js:11495' + }, + { + message: 'Missing item type\ninternal method called on audio process', + line: ' lib/addons/p5.sound.js:11581' + }, + { + message: + 'Missing item type\nPrivate method to ensure accurate values of this._voicesInUse\nAny time a new value is scheduled, it is necessary to increment all subsequent\nscheduledValues after attack, and decrement all subsequent\nscheduledValues after release', + line: ' lib/addons/p5.sound.js:12627' + }, + { + message: + "Missing item type\np5.sound \nhttps://p5js.org/reference/#/libraries/p5.sound\n\nFrom the Processing Foundation and contributors\nhttps://github.com/processing/p5.js-sound/graphs/contributors\n\nMIT License (MIT)\nhttps://github.com/processing/p5.js-sound/blob/master/LICENSE\n\nSome of the many audio libraries & resources that inspire p5.sound:\n - TONE.js (c) Yotam Mann. Licensed under The MIT License (MIT). https://github.com/TONEnoTONE/Tone.js\n - buzz.js (c) Jay Salvat. Licensed under The MIT License (MIT). http://buzz.jaysalvat.com/\n - Boris Smus Web Audio API book, 2013. Licensed under the Apache License http://www.apache.org/licenses/LICENSE-2.0\n - wavesurfer.js https://github.com/katspaugh/wavesurfer.js\n - Web Audio Components by Jordan Santell https://github.com/web-audio-components\n - Wilm Thoben's Sound library for Processing https://github.com/processing/processing/tree/master/java/libraries/sound\n\n Web Audio API: http://w3.org/TR/webaudio/", + line: ' lib/addons/p5.sound.min.js:3' + } + ], + consts: { + RGB: ['p5.colorMode'], + HSB: ['p5.colorMode'], + HSL: ['p5.colorMode'], + CHORD: ['p5.arc'], + PIE: ['p5.arc'], + OPEN: ['p5.arc'], + CENTER: ['p5.ellipseMode', 'p5.rectMode', 'p5.imageMode', 'p5.textAlign'], + RADIUS: ['p5.ellipseMode', 'p5.rectMode'], + CORNER: ['p5.ellipseMode', 'p5.rectMode', 'p5.imageMode'], + CORNERS: ['p5.ellipseMode', 'p5.rectMode', 'p5.imageMode'], + SQUARE: ['p5.strokeCap'], + PROJECT: ['p5.strokeCap'], + ROUND: ['p5.strokeCap', 'p5.strokeJoin'], + MITER: ['p5.strokeJoin'], + BEVEL: ['p5.strokeJoin'], + POINTS: ['p5.beginShape'], + LINES: ['p5.beginShape'], + TRIANGLES: ['p5.beginShape'], + TRIANGLE_FAN: ['p5.beginShape'], + TRIANGLE_STRIP: ['p5.beginShape'], + QUADS: ['p5.beginShape'], + QUAD_STRIP: ['p5.beginShape'], + CLOSE: ['p5.endShape'], + ARROW: ['p5.cursor'], + CROSS: ['p5.cursor'], + HAND: ['p5.cursor'], + MOVE: ['p5.cursor'], + TEXT: ['p5.cursor'], + P2D: ['p5.createCanvas', 'p5.createGraphics'], + WEBGL: ['p5.createCanvas', 'p5.createGraphics'], + BLEND: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + DARKEST: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + LIGHTEST: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + DIFFERENCE: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + MULTIPLY: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + EXCLUSION: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + SCREEN: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + REPLACE: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + OVERLAY: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + HARD_LIGHT: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + SOFT_LIGHT: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + DODGE: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + BURN: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + ADD: ['p5.blendMode', 'p5.Image.blend', 'p5.blend'], + SUBTRACT: ['p5.blendMode'], + THRESHOLD: ['p5.Image.filter', 'p5.filter'], + GRAY: ['p5.Image.filter', 'p5.filter'], + OPAQUE: ['p5.Image.filter', 'p5.filter'], + INVERT: ['p5.Image.filter', 'p5.filter'], + POSTERIZE: ['p5.Image.filter', 'p5.filter'], + BLUR: ['p5.Image.filter', 'p5.filter'], + ERODE: ['p5.Image.filter', 'p5.filter'], + DILATE: ['p5.Image.filter', 'p5.filter'], + NORMAL: ['p5.Image.blend', 'p5.blend', 'p5.textStyle', 'p5.textureMode'], + RADIANS: ['p5.angleMode'], + DEGREES: ['p5.angleMode'], + LEFT: ['p5.textAlign'], + RIGHT: ['p5.textAlign'], + TOP: ['p5.textAlign'], + BOTTOM: ['p5.textAlign'], + BASELINE: ['p5.textAlign'], + ITALIC: ['p5.textStyle'], + BOLD: ['p5.textStyle'], + BOLDITALIC: ['p5.textStyle'], + IMAGE: ['p5.textureMode'], + CLAMP: ['p5.textureWrap'], + REPEAT: ['p5.textureWrap'], + MIRROR: ['p5.textureWrap'], + VIDEO: ['p5.createCapture'], + AUDIO: ['p5.createCapture'] + } + }; + }, + {} + ], + 2: [ + function(_dereq_, module, exports) { + 'use strict'; + + exports.byteLength = byteLength; + exports.toByteArray = toByteArray; + exports.fromByteArray = fromByteArray; + + var lookup = []; + var revLookup = []; + var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array; + + var code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + for (var i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i]; + revLookup[code.charCodeAt(i)] = i; + } + + // Support decoding URL-safe base64 strings, as Node.js does. + // See: https://en.wikipedia.org/wiki/Base64#URL_applications + revLookup['-'.charCodeAt(0)] = 62; + revLookup['_'.charCodeAt(0)] = 63; + + function getLens(b64) { + var len = b64.length; + + if (len % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4'); + } + + // Trim off extra bytes after placeholder bytes are found + // See: https://github.com/beatgammit/base64-js/issues/42 + var validLen = b64.indexOf('='); + if (validLen === -1) validLen = len; + + var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; + + return [validLen, placeHoldersLen]; + } + + // base64 is 4/3 + up to two characters of the original data + function byteLength(b64) { + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; + } + + function _byteLength(b64, validLen, placeHoldersLen) { + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; + } + + function toByteArray(b64) { + var tmp; + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); + + var curByte = 0; + + // if there are placeholders, only get up to the last complete 4 chars + var len = placeHoldersLen > 0 ? validLen - 4 : validLen; + + for (var i = 0; i < len; i += 4) { + tmp = + (revLookup[b64.charCodeAt(i)] << 18) | + (revLookup[b64.charCodeAt(i + 1)] << 12) | + (revLookup[b64.charCodeAt(i + 2)] << 6) | + revLookup[b64.charCodeAt(i + 3)]; + arr[curByte++] = (tmp >> 16) & 0xff; + arr[curByte++] = (tmp >> 8) & 0xff; + arr[curByte++] = tmp & 0xff; + } + + if (placeHoldersLen === 2) { + tmp = + (revLookup[b64.charCodeAt(i)] << 2) | + (revLookup[b64.charCodeAt(i + 1)] >> 4); + arr[curByte++] = tmp & 0xff; + } + + if (placeHoldersLen === 1) { + tmp = + (revLookup[b64.charCodeAt(i)] << 10) | + (revLookup[b64.charCodeAt(i + 1)] << 4) | + (revLookup[b64.charCodeAt(i + 2)] >> 2); + arr[curByte++] = (tmp >> 8) & 0xff; + arr[curByte++] = tmp & 0xff; + } + + return arr; + } + + function tripletToBase64(num) { + return ( + lookup[(num >> 18) & 0x3f] + + lookup[(num >> 12) & 0x3f] + + lookup[(num >> 6) & 0x3f] + + lookup[num & 0x3f] + ); + } + + function encodeChunk(uint8, start, end) { + var tmp; + var output = []; + for (var i = start; i < end; i += 3) { + tmp = + ((uint8[i] << 16) & 0xff0000) + + ((uint8[i + 1] << 8) & 0xff00) + + (uint8[i + 2] & 0xff); + output.push(tripletToBase64(tmp)); + } + return output.join(''); + } + + function fromByteArray(uint8) { + var tmp; + var len = uint8.length; + var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes + var parts = []; + var maxChunkLength = 16383; // must be multiple of 3 + + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push( + encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength) + ); + } + + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1]; + parts.push(lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3f] + '=='); + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + uint8[len - 1]; + parts.push( + lookup[tmp >> 10] + + lookup[(tmp >> 4) & 0x3f] + + lookup[(tmp << 2) & 0x3f] + + '=' + ); + } + + return parts.join(''); + } + }, + {} + ], + 3: [function(_dereq_, module, exports) {}, {}], + 4: [ + function(_dereq_, module, exports) { + /*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ + /* eslint-disable no-proto */ + + 'use strict'; + + var base64 = _dereq_('base64-js'); + var ieee754 = _dereq_('ieee754'); + + exports.Buffer = Buffer; + exports.SlowBuffer = SlowBuffer; + exports.INSPECT_MAX_BYTES = 50; + + var K_MAX_LENGTH = 0x7fffffff; + exports.kMaxLength = K_MAX_LENGTH; + + /** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Print warning and recommend using `buffer` v4.x which has an Object + * implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. + */ + Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); + + if ( + !Buffer.TYPED_ARRAY_SUPPORT && + typeof console !== 'undefined' && + typeof console.error === 'function' + ) { + console.error( + 'This browser lacks typed array (Uint8Array) support which is required by ' + + '`buffer` v5.x. Use `buffer` v4.x if you require old browser support.' + ); + } + + function typedArraySupport() { + // Can typed array instances can be augmented? + try { + var arr = new Uint8Array(1); + arr.__proto__ = { + __proto__: Uint8Array.prototype, + foo: function() { + return 42; + } + }; + return arr.foo() === 42; + } catch (e) { + return false; + } + } + + Object.defineProperty(Buffer.prototype, 'parent', { + enumerable: true, + get: function() { + if (!Buffer.isBuffer(this)) return undefined; + return this.buffer; + } + }); + + Object.defineProperty(Buffer.prototype, 'offset', { + enumerable: true, + get: function() { + if (!Buffer.isBuffer(this)) return undefined; + return this.byteOffset; + } + }); + + function createBuffer(length) { + if (length > K_MAX_LENGTH) { + throw new RangeError( + 'The value "' + length + '" is invalid for option "size"' + ); + } + // Return an augmented `Uint8Array` instance + var buf = new Uint8Array(length); + buf.__proto__ = Buffer.prototype; + return buf; + } + + /** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ + + function Buffer(arg, encodingOrOffset, length) { + // Common case. + if (typeof arg === 'number') { + if (typeof encodingOrOffset === 'string') { + throw new TypeError( + 'The "string" argument must be of type string. Received type number' + ); + } + return allocUnsafe(arg); + } + return from(arg, encodingOrOffset, length); + } + + // Fix subarray() in ES2016. See: https://github.com/feross/buffer/pull/97 + if ( + typeof Symbol !== 'undefined' && + Symbol.species != null && + Buffer[Symbol.species] === Buffer + ) { + Object.defineProperty(Buffer, Symbol.species, { + value: null, + configurable: true, + enumerable: false, + writable: false + }); + } + + Buffer.poolSize = 8192; // not used by this implementation + + function from(value, encodingOrOffset, length) { + if (typeof value === 'string') { + return fromString(value, encodingOrOffset); + } + + if (ArrayBuffer.isView(value)) { + return fromArrayLike(value); + } + + if (value == null) { + throw TypeError( + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + + 'or Array-like Object. Received type ' + + typeof value + ); + } + + if ( + isInstance(value, ArrayBuffer) || + (value && isInstance(value.buffer, ArrayBuffer)) + ) { + return fromArrayBuffer(value, encodingOrOffset, length); + } + + if (typeof value === 'number') { + throw new TypeError( + 'The "value" argument must not be of type number. Received type number' + ); + } + + var valueOf = value.valueOf && value.valueOf(); + if (valueOf != null && valueOf !== value) { + return Buffer.from(valueOf, encodingOrOffset, length); + } + + var b = fromObject(value); + if (b) return b; + + if ( + typeof Symbol !== 'undefined' && + Symbol.toPrimitive != null && + typeof value[Symbol.toPrimitive] === 'function' + ) { + return Buffer.from( + value[Symbol.toPrimitive]('string'), + encodingOrOffset, + length + ); + } + + throw new TypeError( + 'The first argument must be one of type string, Buffer, ArrayBuffer, Array, ' + + 'or Array-like Object. Received type ' + + typeof value + ); + } + + /** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ + Buffer.from = function(value, encodingOrOffset, length) { + return from(value, encodingOrOffset, length); + }; + + // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: + // https://github.com/feross/buffer/pull/148 + Buffer.prototype.__proto__ = Uint8Array.prototype; + Buffer.__proto__ = Uint8Array; + + function assertSize(size) { + if (typeof size !== 'number') { + throw new TypeError('"size" argument must be of type number'); + } else if (size < 0) { + throw new RangeError('The value "' + size + '" is invalid for option "size"'); + } + } + + function alloc(size, fill, encoding) { + assertSize(size); + if (size <= 0) { + return createBuffer(size); + } + if (fill !== undefined) { + // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpretted as a start offset. + return typeof encoding === 'string' + ? createBuffer(size).fill(fill, encoding) + : createBuffer(size).fill(fill); + } + return createBuffer(size); + } + + /** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ + Buffer.alloc = function(size, fill, encoding) { + return alloc(size, fill, encoding); + }; + + function allocUnsafe(size) { + assertSize(size); + return createBuffer(size < 0 ? 0 : checked(size) | 0); + } + + /** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ + Buffer.allocUnsafe = function(size) { + return allocUnsafe(size); + }; + /** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ + Buffer.allocUnsafeSlow = function(size) { + return allocUnsafe(size); + }; + + function fromString(string, encoding) { + if (typeof encoding !== 'string' || encoding === '') { + encoding = 'utf8'; + } + + if (!Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding); + } + + var length = byteLength(string, encoding) | 0; + var buf = createBuffer(length); + + var actual = buf.write(string, encoding); + + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + buf = buf.slice(0, actual); + } + + return buf; + } + + function fromArrayLike(array) { + var length = array.length < 0 ? 0 : checked(array.length) | 0; + var buf = createBuffer(length); + for (var i = 0; i < length; i += 1) { + buf[i] = array[i] & 255; + } + return buf; + } + + function fromArrayBuffer(array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError('"offset" is outside of buffer bounds'); + } + + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError('"length" is outside of buffer bounds'); + } + + var buf; + if (byteOffset === undefined && length === undefined) { + buf = new Uint8Array(array); + } else if (length === undefined) { + buf = new Uint8Array(array, byteOffset); + } else { + buf = new Uint8Array(array, byteOffset, length); + } + + // Return an augmented `Uint8Array` instance + buf.__proto__ = Buffer.prototype; + return buf; + } + + function fromObject(obj) { + if (Buffer.isBuffer(obj)) { + var len = checked(obj.length) | 0; + var buf = createBuffer(len); + + if (buf.length === 0) { + return buf; + } + + obj.copy(buf, 0, 0, len); + return buf; + } + + if (obj.length !== undefined) { + if (typeof obj.length !== 'number' || numberIsNaN(obj.length)) { + return createBuffer(0); + } + return fromArrayLike(obj); + } + + if (obj.type === 'Buffer' && Array.isArray(obj.data)) { + return fromArrayLike(obj.data); + } + } + + function checked(length) { + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= K_MAX_LENGTH) { + throw new RangeError( + 'Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + + K_MAX_LENGTH.toString(16) + + ' bytes' + ); + } + return length | 0; + } + + function SlowBuffer(length) { + if (+length != length) { + // eslint-disable-line eqeqeq + length = 0; + } + return Buffer.alloc(+length); + } + + Buffer.isBuffer = function isBuffer(b) { + return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false + }; + + Buffer.compare = function compare(a, b) { + if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength); + if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength); + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError( + 'The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array' + ); + } + + if (a === b) return 0; + + var x = a.length; + var y = b.length; + + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i]; + y = b[i]; + break; + } + } + + if (x < y) return -1; + if (y < x) return 1; + return 0; + }; + + Buffer.isEncoding = function isEncoding(encoding) { + switch (String(encoding).toLowerCase()) { + case 'hex': + case 'utf8': + case 'utf-8': + case 'ascii': + case 'latin1': + case 'binary': + case 'base64': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true; + default: + return false; + } + }; + + Buffer.concat = function concat(list, length) { + if (!Array.isArray(list)) { + throw new TypeError('"list" argument must be an Array of Buffers'); + } + + if (list.length === 0) { + return Buffer.alloc(0); + } + + var i; + if (length === undefined) { + length = 0; + for (i = 0; i < list.length; ++i) { + length += list[i].length; + } + } + + var buffer = Buffer.allocUnsafe(length); + var pos = 0; + for (i = 0; i < list.length; ++i) { + var buf = list[i]; + if (isInstance(buf, Uint8Array)) { + buf = Buffer.from(buf); + } + if (!Buffer.isBuffer(buf)) { + throw new TypeError('"list" argument must be an Array of Buffers'); + } + buf.copy(buffer, pos); + pos += buf.length; + } + return buffer; + }; + + function byteLength(string, encoding) { + if (Buffer.isBuffer(string)) { + return string.length; + } + if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { + return string.byteLength; + } + if (typeof string !== 'string') { + throw new TypeError( + 'The "string" argument must be one of type string, Buffer, or ArrayBuffer. ' + + 'Received type ' + + typeof string + ); + } + + var len = string.length; + var mustMatch = arguments.length > 2 && arguments[2] === true; + if (!mustMatch && len === 0) return 0; + + // Use a for loop to avoid recursion + var loweredCase = false; + for (;;) { + switch (encoding) { + case 'ascii': + case 'latin1': + case 'binary': + return len; + case 'utf8': + case 'utf-8': + return utf8ToBytes(string).length; + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return len * 2; + case 'hex': + return len >>> 1; + case 'base64': + return base64ToBytes(string).length; + default: + if (loweredCase) { + return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8 + } + encoding = ('' + encoding).toLowerCase(); + loweredCase = true; + } + } + } + Buffer.byteLength = byteLength; + + function slowToString(encoding, start, end) { + var loweredCase = false; + + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. + + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) { + start = 0; + } + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) { + return ''; + } + + if (end === undefined || end > this.length) { + end = this.length; + } + + if (end <= 0) { + return ''; + } + + // Force coersion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0; + start >>>= 0; + + if (end <= start) { + return ''; + } + + if (!encoding) encoding = 'utf8'; + + while (true) { + switch (encoding) { + case 'hex': + return hexSlice(this, start, end); + + case 'utf8': + case 'utf-8': + return utf8Slice(this, start, end); + + case 'ascii': + return asciiSlice(this, start, end); + + case 'latin1': + case 'binary': + return latin1Slice(this, start, end); + + case 'base64': + return base64Slice(this, start, end); + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return utf16leSlice(this, start, end); + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); + encoding = (encoding + '').toLowerCase(); + loweredCase = true; + } + } + } + + // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) + // to detect a Buffer instance. It's not possible to use `instanceof Buffer` + // reliably in a browserify context because there could be multiple different + // copies of the 'buffer' package in use. This method works even for Buffer + // instances that were created from another copy of the `buffer` package. + // See: https://github.com/feross/buffer/issues/154 + Buffer.prototype._isBuffer = true; + + function swap(b, n, m) { + var i = b[n]; + b[n] = b[m]; + b[m] = i; + } + + Buffer.prototype.swap16 = function swap16() { + var len = this.length; + if (len % 2 !== 0) { + throw new RangeError('Buffer size must be a multiple of 16-bits'); + } + for (var i = 0; i < len; i += 2) { + swap(this, i, i + 1); + } + return this; + }; + + Buffer.prototype.swap32 = function swap32() { + var len = this.length; + if (len % 4 !== 0) { + throw new RangeError('Buffer size must be a multiple of 32-bits'); + } + for (var i = 0; i < len; i += 4) { + swap(this, i, i + 3); + swap(this, i + 1, i + 2); + } + return this; + }; + + Buffer.prototype.swap64 = function swap64() { + var len = this.length; + if (len % 8 !== 0) { + throw new RangeError('Buffer size must be a multiple of 64-bits'); + } + for (var i = 0; i < len; i += 8) { + swap(this, i, i + 7); + swap(this, i + 1, i + 6); + swap(this, i + 2, i + 5); + swap(this, i + 3, i + 4); + } + return this; + }; + + Buffer.prototype.toString = function toString() { + var length = this.length; + if (length === 0) return ''; + if (arguments.length === 0) return utf8Slice(this, 0, length); + return slowToString.apply(this, arguments); + }; + + Buffer.prototype.toLocaleString = Buffer.prototype.toString; + + Buffer.prototype.equals = function equals(b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer'); + if (this === b) return true; + return Buffer.compare(this, b) === 0; + }; + + Buffer.prototype.inspect = function inspect() { + var str = ''; + var max = exports.INSPECT_MAX_BYTES; + str = this.toString('hex', 0, max) + .replace(/(.{2})/g, '$1 ') + .trim(); + if (this.length > max) str += ' ... '; + return ''; + }; + + Buffer.prototype.compare = function compare( + target, + start, + end, + thisStart, + thisEnd + ) { + if (isInstance(target, Uint8Array)) { + target = Buffer.from(target, target.offset, target.byteLength); + } + if (!Buffer.isBuffer(target)) { + throw new TypeError( + 'The "target" argument must be one of type Buffer or Uint8Array. ' + + 'Received type ' + + typeof target + ); + } + + if (start === undefined) { + start = 0; + } + if (end === undefined) { + end = target ? target.length : 0; + } + if (thisStart === undefined) { + thisStart = 0; + } + if (thisEnd === undefined) { + thisEnd = this.length; + } + + if ( + start < 0 || + end > target.length || + thisStart < 0 || + thisEnd > this.length + ) { + throw new RangeError('out of range index'); + } + + if (thisStart >= thisEnd && start >= end) { + return 0; + } + if (thisStart >= thisEnd) { + return -1; + } + if (start >= end) { + return 1; + } + + start >>>= 0; + end >>>= 0; + thisStart >>>= 0; + thisEnd >>>= 0; + + if (this === target) return 0; + + var x = thisEnd - thisStart; + var y = end - start; + var len = Math.min(x, y); + + var thisCopy = this.slice(thisStart, thisEnd); + var targetCopy = target.slice(start, end); + + for (var i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i]; + y = targetCopy[i]; + break; + } + } + + if (x < y) return -1; + if (y < x) return 1; + return 0; + }; + + // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, + // OR the last index of `val` in `buffer` at offset <= `byteOffset`. + // + // Arguments: + // - buffer - a Buffer to search + // - val - a string, Buffer, or number + // - byteOffset - an index into `buffer`; will be clamped to an int32 + // - encoding - an optional encoding, relevant is val is a string + // - dir - true for indexOf, false for lastIndexOf + function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1; + + // Normalize byteOffset + if (typeof byteOffset === 'string') { + encoding = byteOffset; + byteOffset = 0; + } else if (byteOffset > 0x7fffffff) { + byteOffset = 0x7fffffff; + } else if (byteOffset < -0x80000000) { + byteOffset = -0x80000000; + } + byteOffset = +byteOffset; // Coerce to Number. + if (numberIsNaN(byteOffset)) { + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : buffer.length - 1; + } + + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset; + if (byteOffset >= buffer.length) { + if (dir) return -1; + else byteOffset = buffer.length - 1; + } else if (byteOffset < 0) { + if (dir) byteOffset = 0; + else return -1; + } + + // Normalize val + if (typeof val === 'string') { + val = Buffer.from(val, encoding); + } + + // Finally, search either indexOf (if dir is true) or lastIndexOf + if (Buffer.isBuffer(val)) { + // Special case: looking for empty string/buffer always fails + if (val.length === 0) { + return -1; + } + return arrayIndexOf(buffer, val, byteOffset, encoding, dir); + } else if (typeof val === 'number') { + val = val & 0xff; // Search for a byte value [0-255] + if (typeof Uint8Array.prototype.indexOf === 'function') { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); + } + } + return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); + } + + throw new TypeError('val must be string, number or Buffer'); + } + + function arrayIndexOf(arr, val, byteOffset, encoding, dir) { + var indexSize = 1; + var arrLength = arr.length; + var valLength = val.length; + + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase(); + if ( + encoding === 'ucs2' || + encoding === 'ucs-2' || + encoding === 'utf16le' || + encoding === 'utf-16le' + ) { + if (arr.length < 2 || val.length < 2) { + return -1; + } + indexSize = 2; + arrLength /= 2; + valLength /= 2; + byteOffset /= 2; + } + } + + function read(buf, i) { + if (indexSize === 1) { + return buf[i]; + } else { + return buf.readUInt16BE(i * indexSize); + } + } + + var i; + if (dir) { + var foundIndex = -1; + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) foundIndex = i; + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; + } else { + if (foundIndex !== -1) i -= i - foundIndex; + foundIndex = -1; + } + } + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; + for (i = byteOffset; i >= 0; i--) { + var found = true; + for (var j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false; + break; + } + } + if (found) return i; + } + } + + return -1; + } + + Buffer.prototype.includes = function includes(val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1; + }; + + Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true); + }; + + Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false); + }; + + function hexWrite(buf, string, offset, length) { + offset = Number(offset) || 0; + var remaining = buf.length - offset; + if (!length) { + length = remaining; + } else { + length = Number(length); + if (length > remaining) { + length = remaining; + } + } + + var strLen = string.length; + + if (length > strLen / 2) { + length = strLen / 2; + } + for (var i = 0; i < length; ++i) { + var parsed = parseInt(string.substr(i * 2, 2), 16); + if (numberIsNaN(parsed)) return i; + buf[offset + i] = parsed; + } + return i; + } + + function utf8Write(buf, string, offset, length) { + return blitBuffer( + utf8ToBytes(string, buf.length - offset), + buf, + offset, + length + ); + } + + function asciiWrite(buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length); + } + + function latin1Write(buf, string, offset, length) { + return asciiWrite(buf, string, offset, length); + } + + function base64Write(buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length); + } + + function ucs2Write(buf, string, offset, length) { + return blitBuffer( + utf16leToBytes(string, buf.length - offset), + buf, + offset, + length + ); + } + + Buffer.prototype.write = function write(string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = 'utf8'; + length = this.length; + offset = 0; + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === 'string') { + encoding = offset; + length = this.length; + offset = 0; + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset >>> 0; + if (isFinite(length)) { + length = length >>> 0; + if (encoding === undefined) encoding = 'utf8'; + } else { + encoding = length; + length = undefined; + } + } else { + throw new Error( + 'Buffer.write(string, encoding, offset[, length]) is no longer supported' + ); + } + + var remaining = this.length - offset; + if (length === undefined || length > remaining) length = remaining; + + if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) { + throw new RangeError('Attempt to write outside buffer bounds'); + } + + if (!encoding) encoding = 'utf8'; + + var loweredCase = false; + for (;;) { + switch (encoding) { + case 'hex': + return hexWrite(this, string, offset, length); + + case 'utf8': + case 'utf-8': + return utf8Write(this, string, offset, length); + + case 'ascii': + return asciiWrite(this, string, offset, length); + + case 'latin1': + case 'binary': + return latin1Write(this, string, offset, length); + + case 'base64': + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length); + + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return ucs2Write(this, string, offset, length); + + default: + if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding); + encoding = ('' + encoding).toLowerCase(); + loweredCase = true; + } + } + }; + + Buffer.prototype.toJSON = function toJSON() { + return { + type: 'Buffer', + data: Array.prototype.slice.call(this._arr || this, 0) + }; + }; + + function base64Slice(buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf); + } else { + return base64.fromByteArray(buf.slice(start, end)); + } + } + + function utf8Slice(buf, start, end) { + end = Math.min(buf.length, end); + var res = []; + + var i = start; + while (i < end) { + var firstByte = buf[i]; + var codePoint = null; + var bytesPerSequence = + firstByte > 0xef ? 4 : firstByte > 0xdf ? 3 : firstByte > 0xbf ? 2 : 1; + + if (i + bytesPerSequence <= end) { + var secondByte, thirdByte, fourthByte, tempCodePoint; + + switch (bytesPerSequence) { + case 1: + if (firstByte < 0x80) { + codePoint = firstByte; + } + break; + case 2: + secondByte = buf[i + 1]; + if ((secondByte & 0xc0) === 0x80) { + tempCodePoint = ((firstByte & 0x1f) << 0x6) | (secondByte & 0x3f); + if (tempCodePoint > 0x7f) { + codePoint = tempCodePoint; + } + } + break; + case 3: + secondByte = buf[i + 1]; + thirdByte = buf[i + 2]; + if ((secondByte & 0xc0) === 0x80 && (thirdByte & 0xc0) === 0x80) { + tempCodePoint = + ((firstByte & 0xf) << 0xc) | + ((secondByte & 0x3f) << 0x6) | + (thirdByte & 0x3f); + if ( + tempCodePoint > 0x7ff && + (tempCodePoint < 0xd800 || tempCodePoint > 0xdfff) + ) { + codePoint = tempCodePoint; + } + } + break; + case 4: + secondByte = buf[i + 1]; + thirdByte = buf[i + 2]; + fourthByte = buf[i + 3]; + if ( + (secondByte & 0xc0) === 0x80 && + (thirdByte & 0xc0) === 0x80 && + (fourthByte & 0xc0) === 0x80 + ) { + tempCodePoint = + ((firstByte & 0xf) << 0x12) | + ((secondByte & 0x3f) << 0xc) | + ((thirdByte & 0x3f) << 0x6) | + (fourthByte & 0x3f); + if (tempCodePoint > 0xffff && tempCodePoint < 0x110000) { + codePoint = tempCodePoint; + } + } + } + } + + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 0xfffd; + bytesPerSequence = 1; + } else if (codePoint > 0xffff) { + // encode to utf16 (surrogate pair dance) + codePoint -= 0x10000; + res.push(((codePoint >>> 10) & 0x3ff) | 0xd800); + codePoint = 0xdc00 | (codePoint & 0x3ff); + } + + res.push(codePoint); + i += bytesPerSequence; + } + + return decodeCodePointsArray(res); + } + + // Based on http://stackoverflow.com/a/22747272/680742, the browser with + // the lowest limit is Chrome, with 0x10000 args. + // We go 1 magnitude less, for safety + var MAX_ARGUMENTS_LENGTH = 0x1000; + + function decodeCodePointsArray(codePoints) { + var len = codePoints.length; + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints); // avoid extra slice() + } + + // Decode in chunks to avoid "call stack size exceeded". + var res = ''; + var i = 0; + while (i < len) { + res += String.fromCharCode.apply( + String, + codePoints.slice(i, (i += MAX_ARGUMENTS_LENGTH)) + ); + } + return res; + } + + function asciiSlice(buf, start, end) { + var ret = ''; + end = Math.min(buf.length, end); + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i] & 0x7f); + } + return ret; + } + + function latin1Slice(buf, start, end) { + var ret = ''; + end = Math.min(buf.length, end); + + for (var i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i]); + } + return ret; + } + + function hexSlice(buf, start, end) { + var len = buf.length; + + if (!start || start < 0) start = 0; + if (!end || end < 0 || end > len) end = len; + + var out = ''; + for (var i = start; i < end; ++i) { + out += toHex(buf[i]); + } + return out; + } + + function utf16leSlice(buf, start, end) { + var bytes = buf.slice(start, end); + var res = ''; + for (var i = 0; i < bytes.length; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); + } + return res; + } + + Buffer.prototype.slice = function slice(start, end) { + var len = this.length; + start = ~~start; + end = end === undefined ? len : ~~end; + + if (start < 0) { + start += len; + if (start < 0) start = 0; + } else if (start > len) { + start = len; + } + + if (end < 0) { + end += len; + if (end < 0) end = 0; + } else if (end > len) { + end = len; + } + + if (end < start) end = start; + + var newBuf = this.subarray(start, end); + // Return an augmented `Uint8Array` instance + newBuf.__proto__ = Buffer.prototype; + return newBuf; + }; + + /* + * Need to make sure that buffer isn't trying to write out of bounds. + */ + function checkOffset(offset, ext, length) { + if (offset % 1 !== 0 || offset < 0) throw new RangeError('offset is not uint'); + if (offset + ext > length) + throw new RangeError('Trying to access beyond buffer length'); + } + + Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + + var val = this[offset]; + var mul = 1; + var i = 0; + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul; + } + + return val; + }; + + Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) { + checkOffset(offset, byteLength, this.length); + } + + var val = this[offset + --byteLength]; + var mul = 1; + while (byteLength > 0 && (mul *= 0x100)) { + val += this[offset + --byteLength] * mul; + } + + return val; + }; + + Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 1, this.length); + return this[offset]; + }; + + Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + return this[offset] | (this[offset + 1] << 8); + }; + + Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + return (this[offset] << 8) | this[offset + 1]; + }; + + Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + + return ( + (this[offset] | (this[offset + 1] << 8) | (this[offset + 2] << 16)) + + this[offset + 3] * 0x1000000 + ); + }; + + Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + + return ( + this[offset] * 0x1000000 + + ((this[offset + 1] << 16) | (this[offset + 2] << 8) | this[offset + 3]) + ); + }; + + Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + + var val = this[offset]; + var mul = 1; + var i = 0; + while (++i < byteLength && (mul *= 0x100)) { + val += this[offset + i] * mul; + } + mul *= 0x80; + + if (val >= mul) val -= Math.pow(2, 8 * byteLength); + + return val; + }; + + Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + + var i = byteLength; + var mul = 1; + var val = this[offset + --i]; + while (i > 0 && (mul *= 0x100)) { + val += this[offset + --i] * mul; + } + mul *= 0x80; + + if (val >= mul) val -= Math.pow(2, 8 * byteLength); + + return val; + }; + + Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 1, this.length); + if (!(this[offset] & 0x80)) return this[offset]; + return (0xff - this[offset] + 1) * -1; + }; + + Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + var val = this[offset] | (this[offset + 1] << 8); + return val & 0x8000 ? val | 0xffff0000 : val; + }; + + Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + var val = this[offset + 1] | (this[offset] << 8); + return val & 0x8000 ? val | 0xffff0000 : val; + }; + + Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + + return ( + this[offset] | + (this[offset + 1] << 8) | + (this[offset + 2] << 16) | + (this[offset + 3] << 24) + ); + }; + + Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + + return ( + (this[offset] << 24) | + (this[offset + 1] << 16) | + (this[offset + 2] << 8) | + this[offset + 3] + ); + }; + + Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return ieee754.read(this, offset, true, 23, 4); + }; + + Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return ieee754.read(this, offset, false, 23, 4); + }; + + Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 8, this.length); + return ieee754.read(this, offset, true, 52, 8); + }; + + Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 8, this.length); + return ieee754.read(this, offset, false, 52, 8); + }; + + function checkInt(buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) + throw new TypeError('"buffer" argument must be a Buffer instance'); + if (value > max || value < min) + throw new RangeError('"value" argument is out of bounds'); + if (offset + ext > buf.length) throw new RangeError('Index out of range'); + } + + Buffer.prototype.writeUIntLE = function writeUIntLE( + value, + offset, + byteLength, + noAssert + ) { + value = +value; + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1; + checkInt(this, value, offset, byteLength, maxBytes, 0); + } + + var mul = 1; + var i = 0; + this[offset] = value & 0xff; + while (++i < byteLength && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xff; + } + + return offset + byteLength; + }; + + Buffer.prototype.writeUIntBE = function writeUIntBE( + value, + offset, + byteLength, + noAssert + ) { + value = +value; + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) { + var maxBytes = Math.pow(2, 8 * byteLength) - 1; + checkInt(this, value, offset, byteLength, maxBytes, 0); + } + + var i = byteLength - 1; + var mul = 1; + this[offset + i] = value & 0xff; + while (--i >= 0 && (mul *= 0x100)) { + this[offset + i] = (value / mul) & 0xff; + } + + return offset + byteLength; + }; + + Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0); + this[offset] = value & 0xff; + return offset + 1; + }; + + Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); + this[offset] = value & 0xff; + this[offset + 1] = value >>> 8; + return offset + 2; + }; + + Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0); + this[offset] = value >>> 8; + this[offset + 1] = value & 0xff; + return offset + 2; + }; + + Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); + this[offset + 3] = value >>> 24; + this[offset + 2] = value >>> 16; + this[offset + 1] = value >>> 8; + this[offset] = value & 0xff; + return offset + 4; + }; + + Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0); + this[offset] = value >>> 24; + this[offset + 1] = value >>> 16; + this[offset + 2] = value >>> 8; + this[offset + 3] = value & 0xff; + return offset + 4; + }; + + Buffer.prototype.writeIntLE = function writeIntLE( + value, + offset, + byteLength, + noAssert + ) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1); + + checkInt(this, value, offset, byteLength, limit - 1, -limit); + } + + var i = 0; + var mul = 1; + var sub = 0; + this[offset] = value & 0xff; + while (++i < byteLength && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1; + } + this[offset + i] = (((value / mul) >> 0) - sub) & 0xff; + } + + return offset + byteLength; + }; + + Buffer.prototype.writeIntBE = function writeIntBE( + value, + offset, + byteLength, + noAssert + ) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + var limit = Math.pow(2, 8 * byteLength - 1); + + checkInt(this, value, offset, byteLength, limit - 1, -limit); + } + + var i = byteLength - 1; + var mul = 1; + var sub = 0; + this[offset + i] = value & 0xff; + while (--i >= 0 && (mul *= 0x100)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1; + } + this[offset + i] = (((value / mul) >> 0) - sub) & 0xff; + } + + return offset + byteLength; + }; + + Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80); + if (value < 0) value = 0xff + value + 1; + this[offset] = value & 0xff; + return offset + 1; + }; + + Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); + this[offset] = value & 0xff; + this[offset + 1] = value >>> 8; + return offset + 2; + }; + + Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000); + this[offset] = value >>> 8; + this[offset + 1] = value & 0xff; + return offset + 2; + }; + + Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); + this[offset] = value & 0xff; + this[offset + 1] = value >>> 8; + this[offset + 2] = value >>> 16; + this[offset + 3] = value >>> 24; + return offset + 4; + }; + + Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000); + if (value < 0) value = 0xffffffff + value + 1; + this[offset] = value >>> 24; + this[offset + 1] = value >>> 16; + this[offset + 2] = value >>> 8; + this[offset + 3] = value & 0xff; + return offset + 4; + }; + + function checkIEEE754(buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) throw new RangeError('Index out of range'); + if (offset < 0) throw new RangeError('Index out of range'); + } + + function writeFloat(buf, value, offset, littleEndian, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + checkIEEE754( + buf, + value, + offset, + 4, + 3.4028234663852886e38, + -3.4028234663852886e38 + ); + } + ieee754.write(buf, value, offset, littleEndian, 23, 4); + return offset + 4; + } + + Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert); + }; + + Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert); + }; + + function writeDouble(buf, value, offset, littleEndian, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + checkIEEE754( + buf, + value, + offset, + 8, + 1.7976931348623157e308, + -1.7976931348623157e308 + ); + } + ieee754.write(buf, value, offset, littleEndian, 52, 8); + return offset + 8; + } + + Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert); + }; + + Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert); + }; + + // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) + Buffer.prototype.copy = function copy(target, targetStart, start, end) { + if (!Buffer.isBuffer(target)) + throw new TypeError('argument should be a Buffer'); + if (!start) start = 0; + if (!end && end !== 0) end = this.length; + if (targetStart >= target.length) targetStart = target.length; + if (!targetStart) targetStart = 0; + if (end > 0 && end < start) end = start; + + // Copy 0 bytes; we're done + if (end === start) return 0; + if (target.length === 0 || this.length === 0) return 0; + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError('targetStart out of bounds'); + } + if (start < 0 || start >= this.length) + throw new RangeError('Index out of range'); + if (end < 0) throw new RangeError('sourceEnd out of bounds'); + + // Are we oob? + if (end > this.length) end = this.length; + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start; + } + + var len = end - start; + + if (this === target && typeof Uint8Array.prototype.copyWithin === 'function') { + // Use built-in when available, missing from IE11 + this.copyWithin(targetStart, start, end); + } else if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (var i = len - 1; i >= 0; --i) { + target[i + targetStart] = this[i + start]; + } + } else { + Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart); + } + + return len; + }; + + // Usage: + // buffer.fill(number[, offset[, end]]) + // buffer.fill(buffer[, offset[, end]]) + // buffer.fill(string[, offset[, end]][, encoding]) + Buffer.prototype.fill = function fill(val, start, end, encoding) { + // Handle string cases: + if (typeof val === 'string') { + if (typeof start === 'string') { + encoding = start; + start = 0; + end = this.length; + } else if (typeof end === 'string') { + encoding = end; + end = this.length; + } + if (encoding !== undefined && typeof encoding !== 'string') { + throw new TypeError('encoding must be a string'); + } + if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) { + throw new TypeError('Unknown encoding: ' + encoding); + } + if (val.length === 1) { + var code = val.charCodeAt(0); + if ((encoding === 'utf8' && code < 128) || encoding === 'latin1') { + // Fast path: If `val` fits into a single byte, use that numeric value. + val = code; + } + } + } else if (typeof val === 'number') { + val = val & 255; + } + + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError('Out of range index'); + } + + if (end <= start) { + return this; + } + + start = start >>> 0; + end = end === undefined ? this.length : end >>> 0; + + if (!val) val = 0; + + var i; + if (typeof val === 'number') { + for (i = start; i < end; ++i) { + this[i] = val; + } + } else { + var bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding); + var len = bytes.length; + if (len === 0) { + throw new TypeError( + 'The value "' + val + '" is invalid for argument "value"' + ); + } + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len]; + } + } + + return this; + }; + + // HELPER FUNCTIONS + // ================ + + var INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; + + function base64clean(str) { + // Node takes equal signs as end of the Base64 encoding + str = str.split('=')[0]; + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = str.trim().replace(INVALID_BASE64_RE, ''); + // Node converts strings with length < 2 to '' + if (str.length < 2) return ''; + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while (str.length % 4 !== 0) { + str = str + '='; + } + return str; + } + + function toHex(n) { + if (n < 16) return '0' + n.toString(16); + return n.toString(16); + } + + function utf8ToBytes(string, units) { + units = units || Infinity; + var codePoint; + var length = string.length; + var leadSurrogate = null; + var bytes = []; + + for (var i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i); + + // is surrogate component + if (codePoint > 0xd7ff && codePoint < 0xe000) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 0xdbff) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(0xef, 0xbf, 0xbd); + continue; + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(0xef, 0xbf, 0xbd); + continue; + } + + // valid lead + leadSurrogate = codePoint; + + continue; + } + + // 2 leads in a row + if (codePoint < 0xdc00) { + if ((units -= 3) > -1) bytes.push(0xef, 0xbf, 0xbd); + leadSurrogate = codePoint; + continue; + } + + // valid surrogate pair + codePoint = + (((leadSurrogate - 0xd800) << 10) | (codePoint - 0xdc00)) + 0x10000; + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(0xef, 0xbf, 0xbd); + } + + leadSurrogate = null; + + // encode utf8 + if (codePoint < 0x80) { + if ((units -= 1) < 0) break; + bytes.push(codePoint); + } else if (codePoint < 0x800) { + if ((units -= 2) < 0) break; + bytes.push((codePoint >> 0x6) | 0xc0, (codePoint & 0x3f) | 0x80); + } else if (codePoint < 0x10000) { + if ((units -= 3) < 0) break; + bytes.push( + (codePoint >> 0xc) | 0xe0, + ((codePoint >> 0x6) & 0x3f) | 0x80, + (codePoint & 0x3f) | 0x80 + ); + } else if (codePoint < 0x110000) { + if ((units -= 4) < 0) break; + bytes.push( + (codePoint >> 0x12) | 0xf0, + ((codePoint >> 0xc) & 0x3f) | 0x80, + ((codePoint >> 0x6) & 0x3f) | 0x80, + (codePoint & 0x3f) | 0x80 + ); + } else { + throw new Error('Invalid code point'); + } + } + + return bytes; + } + + function asciiToBytes(str) { + var byteArray = []; + for (var i = 0; i < str.length; ++i) { + // Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 0xff); + } + return byteArray; + } + + function utf16leToBytes(str, units) { + var c, hi, lo; + var byteArray = []; + for (var i = 0; i < str.length; ++i) { + if ((units -= 2) < 0) break; + + c = str.charCodeAt(i); + hi = c >> 8; + lo = c % 256; + byteArray.push(lo); + byteArray.push(hi); + } + + return byteArray; + } + + function base64ToBytes(str) { + return base64.toByteArray(base64clean(str)); + } + + function blitBuffer(src, dst, offset, length) { + for (var i = 0; i < length; ++i) { + if (i + offset >= dst.length || i >= src.length) break; + dst[i + offset] = src[i]; + } + return i; + } + + // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass + // the `instanceof` check but they should be treated as of that type. + // See: https://github.com/feross/buffer/issues/166 + function isInstance(obj, type) { + return ( + obj instanceof type || + (obj != null && + obj.constructor != null && + obj.constructor.name != null && + obj.constructor.name === type.name) + ); + } + function numberIsNaN(obj) { + // For IE11 support + return obj !== obj; // eslint-disable-line no-self-compare + } + }, + { 'base64-js': 2, ieee754: 8 } + ], + 5: [ + function(_dereq_, module, exports) { + (function(process, global) { + /*! + * @overview es6-promise - a tiny implementation of Promises/A+. + * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald) + * @license Licensed under MIT license + * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE + * @version v4.2.6+9869a4bc + */ + + (function(global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' + ? (module.exports = factory()) + : typeof define === 'function' && define.amd + ? define(factory) + : (global.ES6Promise = factory()); + })(this, function() { + 'use strict'; + + function objectOrFunction(x) { + var type = typeof x; + return x !== null && (type === 'object' || type === 'function'); + } + + function isFunction(x) { + return typeof x === 'function'; + } + + var _isArray = void 0; + if (Array.isArray) { + _isArray = Array.isArray; + } else { + _isArray = function(x) { + return Object.prototype.toString.call(x) === '[object Array]'; + }; + } + + var isArray = _isArray; + + var len = 0; + var vertxNext = void 0; + var customSchedulerFn = void 0; + + var asap = function asap(callback, arg) { + queue[len] = callback; + queue[len + 1] = arg; + len += 2; + if (len === 2) { + // If len is 2, that means that we need to schedule an async flush. + // If additional callbacks are queued before the queue is flushed, they + // will be processed by this flush that we are scheduling. + if (customSchedulerFn) { + customSchedulerFn(flush); + } else { + scheduleFlush(); + } + } + }; + + function setScheduler(scheduleFn) { + customSchedulerFn = scheduleFn; + } + + function setAsap(asapFn) { + asap = asapFn; + } + + var browserWindow = typeof window !== 'undefined' ? window : undefined; + var browserGlobal = browserWindow || {}; + var BrowserMutationObserver = + browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; + var isNode = + typeof self === 'undefined' && + typeof process !== 'undefined' && + {}.toString.call(process) === '[object process]'; + + // test for web worker but not in IE10 + var isWorker = + typeof Uint8ClampedArray !== 'undefined' && + typeof importScripts !== 'undefined' && + typeof MessageChannel !== 'undefined'; + + // node + function useNextTick() { + // node version 0.10.x displays a deprecation warning when nextTick is used recursively + // see https://github.com/cujojs/when/issues/410 for details + return function() { + return process.nextTick(flush); + }; + } + + // vertx + function useVertxTimer() { + if (typeof vertxNext !== 'undefined') { + return function() { + vertxNext(flush); + }; + } + + return useSetTimeout(); + } + + function useMutationObserver() { + var iterations = 0; + var observer = new BrowserMutationObserver(flush); + var node = document.createTextNode(''); + observer.observe(node, { characterData: true }); + + return function() { + node.data = iterations = ++iterations % 2; + }; + } + + // web worker + function useMessageChannel() { + var channel = new MessageChannel(); + channel.port1.onmessage = flush; + return function() { + return channel.port2.postMessage(0); + }; + } + + function useSetTimeout() { + // Store setTimeout reference so es6-promise will be unaffected by + // other code modifying setTimeout (like sinon.useFakeTimers()) + var globalSetTimeout = setTimeout; + return function() { + return globalSetTimeout(flush, 1); + }; + } + + var queue = new Array(1000); + function flush() { + for (var i = 0; i < len; i += 2) { + var callback = queue[i]; + var arg = queue[i + 1]; + + callback(arg); + + queue[i] = undefined; + queue[i + 1] = undefined; + } + + len = 0; + } + + function attemptVertx() { + try { + var vertx = Function('return this')().require('vertx'); + vertxNext = vertx.runOnLoop || vertx.runOnContext; + return useVertxTimer(); + } catch (e) { + return useSetTimeout(); + } + } + + var scheduleFlush = void 0; + // Decide what async method to use to triggering processing of queued callbacks: + if (isNode) { + scheduleFlush = useNextTick(); + } else if (BrowserMutationObserver) { + scheduleFlush = useMutationObserver(); + } else if (isWorker) { + scheduleFlush = useMessageChannel(); + } else if (browserWindow === undefined && typeof _dereq_ === 'function') { + scheduleFlush = attemptVertx(); + } else { + scheduleFlush = useSetTimeout(); + } + + function then(onFulfillment, onRejection) { + var parent = this; + + var child = new this.constructor(noop); + + if (child[PROMISE_ID] === undefined) { + makePromise(child); + } + + var _state = parent._state; + + if (_state) { + var callback = arguments[_state - 1]; + asap(function() { + return invokeCallback(_state, child, callback, parent._result); + }); + } else { + subscribe(parent, child, onFulfillment, onRejection); + } + + return child; + } + + /** + `Promise.resolve` returns a promise that will become resolved with the + passed `value`. It is shorthand for the following: + + ```javascript + let promise = new Promise(function(resolve, reject){ + resolve(1); + }); + + promise.then(function(value){ + // value === 1 + }); + ``` + + Instead of writing the above, your code now simply becomes the following: + + ```javascript + let promise = Promise.resolve(1); + + promise.then(function(value){ + // value === 1 + }); + ``` + + @method resolve + @static + @param {Any} value value that the returned promise will be resolved with + Useful for tooling. + @return {Promise} a promise that will become fulfilled with the given + `value` +*/ + function resolve$1(object) { + /*jshint validthis:true */ + var Constructor = this; + + if ( + object && + typeof object === 'object' && + object.constructor === Constructor + ) { + return object; + } + + var promise = new Constructor(noop); + resolve(promise, object); + return promise; + } + + var PROMISE_ID = Math.random() + .toString(36) + .substring(2); + + function noop() {} + + var PENDING = void 0; + var FULFILLED = 1; + var REJECTED = 2; + + var TRY_CATCH_ERROR = { error: null }; + + function selfFulfillment() { + return new TypeError('You cannot resolve a promise with itself'); + } + + function cannotReturnOwn() { + return new TypeError( + 'A promises callback cannot return that same promise.' + ); + } + + function getThen(promise) { + try { + return promise.then; + } catch (error) { + TRY_CATCH_ERROR.error = error; + return TRY_CATCH_ERROR; + } + } + + function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { + try { + then$$1.call(value, fulfillmentHandler, rejectionHandler); + } catch (e) { + return e; + } + } + + function handleForeignThenable(promise, thenable, then$$1) { + asap(function(promise) { + var sealed = false; + var error = tryThen( + then$$1, + thenable, + function(value) { + if (sealed) { + return; + } + sealed = true; + if (thenable !== value) { + resolve(promise, value); + } else { + fulfill(promise, value); + } + }, + function(reason) { + if (sealed) { + return; + } + sealed = true; + + reject(promise, reason); + }, + 'Settle: ' + (promise._label || ' unknown promise') + ); + + if (!sealed && error) { + sealed = true; + reject(promise, error); + } + }, promise); + } + + function handleOwnThenable(promise, thenable) { + if (thenable._state === FULFILLED) { + fulfill(promise, thenable._result); + } else if (thenable._state === REJECTED) { + reject(promise, thenable._result); + } else { + subscribe( + thenable, + undefined, + function(value) { + return resolve(promise, value); + }, + function(reason) { + return reject(promise, reason); + } + ); + } + } + + function handleMaybeThenable(promise, maybeThenable, then$$1) { + if ( + maybeThenable.constructor === promise.constructor && + then$$1 === then && + maybeThenable.constructor.resolve === resolve$1 + ) { + handleOwnThenable(promise, maybeThenable); + } else { + if (then$$1 === TRY_CATCH_ERROR) { + reject(promise, TRY_CATCH_ERROR.error); + TRY_CATCH_ERROR.error = null; + } else if (then$$1 === undefined) { + fulfill(promise, maybeThenable); + } else if (isFunction(then$$1)) { + handleForeignThenable(promise, maybeThenable, then$$1); + } else { + fulfill(promise, maybeThenable); + } + } + } + + function resolve(promise, value) { + if (promise === value) { + reject(promise, selfFulfillment()); + } else if (objectOrFunction(value)) { + handleMaybeThenable(promise, value, getThen(value)); + } else { + fulfill(promise, value); + } + } + + function publishRejection(promise) { + if (promise._onerror) { + promise._onerror(promise._result); + } + + publish(promise); + } + + function fulfill(promise, value) { + if (promise._state !== PENDING) { + return; + } + + promise._result = value; + promise._state = FULFILLED; + + if (promise._subscribers.length !== 0) { + asap(publish, promise); + } + } + + function reject(promise, reason) { + if (promise._state !== PENDING) { + return; + } + promise._state = REJECTED; + promise._result = reason; + + asap(publishRejection, promise); + } + + function subscribe(parent, child, onFulfillment, onRejection) { + var _subscribers = parent._subscribers; + var length = _subscribers.length; + + parent._onerror = null; + + _subscribers[length] = child; + _subscribers[length + FULFILLED] = onFulfillment; + _subscribers[length + REJECTED] = onRejection; + + if (length === 0 && parent._state) { + asap(publish, parent); + } + } + + function publish(promise) { + var subscribers = promise._subscribers; + var settled = promise._state; + + if (subscribers.length === 0) { + return; + } + + var child = void 0, + callback = void 0, + detail = promise._result; + + for (var i = 0; i < subscribers.length; i += 3) { + child = subscribers[i]; + callback = subscribers[i + settled]; + + if (child) { + invokeCallback(settled, child, callback, detail); + } else { + callback(detail); + } + } + + promise._subscribers.length = 0; + } + + function tryCatch(callback, detail) { + try { + return callback(detail); + } catch (e) { + TRY_CATCH_ERROR.error = e; + return TRY_CATCH_ERROR; + } + } + + function invokeCallback(settled, promise, callback, detail) { + var hasCallback = isFunction(callback), + value = void 0, + error = void 0, + succeeded = void 0, + failed = void 0; + + if (hasCallback) { + value = tryCatch(callback, detail); + + if (value === TRY_CATCH_ERROR) { + failed = true; + error = value.error; + value.error = null; + } else { + succeeded = true; + } + + if (promise === value) { + reject(promise, cannotReturnOwn()); + return; + } + } else { + value = detail; + succeeded = true; + } + + if (promise._state !== PENDING) { + // noop + } else if (hasCallback && succeeded) { + resolve(promise, value); + } else if (failed) { + reject(promise, error); + } else if (settled === FULFILLED) { + fulfill(promise, value); + } else if (settled === REJECTED) { + reject(promise, value); + } + } + + function initializePromise(promise, resolver) { + try { + resolver( + function resolvePromise(value) { + resolve(promise, value); + }, + function rejectPromise(reason) { + reject(promise, reason); + } + ); + } catch (e) { + reject(promise, e); + } + } + + var id = 0; + function nextId() { + return id++; + } + + function makePromise(promise) { + promise[PROMISE_ID] = id++; + promise._state = undefined; + promise._result = undefined; + promise._subscribers = []; + } + + function validationError() { + return new Error('Array Methods must be provided an Array'); + } + + var Enumerator = (function() { + function Enumerator(Constructor, input) { + this._instanceConstructor = Constructor; + this.promise = new Constructor(noop); + + if (!this.promise[PROMISE_ID]) { + makePromise(this.promise); + } + + if (isArray(input)) { + this.length = input.length; + this._remaining = input.length; + + this._result = new Array(this.length); + + if (this.length === 0) { + fulfill(this.promise, this._result); + } else { + this.length = this.length || 0; + this._enumerate(input); + if (this._remaining === 0) { + fulfill(this.promise, this._result); + } + } + } else { + reject(this.promise, validationError()); + } + } + + Enumerator.prototype._enumerate = function _enumerate(input) { + for (var i = 0; this._state === PENDING && i < input.length; i++) { + this._eachEntry(input[i], i); + } + }; + + Enumerator.prototype._eachEntry = function _eachEntry(entry, i) { + var c = this._instanceConstructor; + var resolve$$1 = c.resolve; + + if (resolve$$1 === resolve$1) { + var _then = getThen(entry); + + if (_then === then && entry._state !== PENDING) { + this._settledAt(entry._state, i, entry._result); + } else if (typeof _then !== 'function') { + this._remaining--; + this._result[i] = entry; + } else if (c === Promise$1) { + var promise = new c(noop); + handleMaybeThenable(promise, entry, _then); + this._willSettleAt(promise, i); + } else { + this._willSettleAt( + new c(function(resolve$$1) { + return resolve$$1(entry); + }), + i + ); + } + } else { + this._willSettleAt(resolve$$1(entry), i); + } + }; + + Enumerator.prototype._settledAt = function _settledAt(state, i, value) { + var promise = this.promise; + + if (promise._state === PENDING) { + this._remaining--; + + if (state === REJECTED) { + reject(promise, value); + } else { + this._result[i] = value; + } + } + + if (this._remaining === 0) { + fulfill(promise, this._result); + } + }; + + Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) { + var enumerator = this; + + subscribe( + promise, + undefined, + function(value) { + return enumerator._settledAt(FULFILLED, i, value); + }, + function(reason) { + return enumerator._settledAt(REJECTED, i, reason); + } + ); + }; + + return Enumerator; + })(); + + /** + `Promise.all` accepts an array of promises, and returns a new promise which + is fulfilled with an array of fulfillment values for the passed promises, or + rejected with the reason of the first passed promise to be rejected. It casts all + elements of the passed iterable to promises as it runs this algorithm. + + Example: + + ```javascript + let promise1 = resolve(1); + let promise2 = resolve(2); + let promise3 = resolve(3); + let promises = [ promise1, promise2, promise3 ]; + + Promise.all(promises).then(function(array){ + // The array here would be [ 1, 2, 3 ]; + }); + ``` + + If any of the `promises` given to `all` are rejected, the first promise + that is rejected will be given as an argument to the returned promises's + rejection handler. For example: + + Example: + + ```javascript + let promise1 = resolve(1); + let promise2 = reject(new Error("2")); + let promise3 = reject(new Error("3")); + let promises = [ promise1, promise2, promise3 ]; + + Promise.all(promises).then(function(array){ + // Code here never runs because there are rejected promises! + }, function(error) { + // error.message === "2" + }); + ``` + + @method all + @static + @param {Array} entries array of promises + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled when all `promises` have been + fulfilled, or rejected if any of them become rejected. + @static +*/ + function all(entries) { + return new Enumerator(this, entries).promise; + } + + /** + `Promise.race` returns a new promise which is settled in the same way as the + first passed promise to settle. + + Example: + + ```javascript + let promise1 = new Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 1'); + }, 200); + }); + + let promise2 = new Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 2'); + }, 100); + }); + + Promise.race([promise1, promise2]).then(function(result){ + // result === 'promise 2' because it was resolved before promise1 + // was resolved. + }); + ``` + + `Promise.race` is deterministic in that only the state of the first + settled promise matters. For example, even if other promises given to the + `promises` array argument are resolved, but the first settled promise has + become rejected before the other promises became fulfilled, the returned + promise will become rejected: + + ```javascript + let promise1 = new Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 1'); + }, 200); + }); + + let promise2 = new Promise(function(resolve, reject){ + setTimeout(function(){ + reject(new Error('promise 2')); + }, 100); + }); + + Promise.race([promise1, promise2]).then(function(result){ + // Code here never runs + }, function(reason){ + // reason.message === 'promise 2' because promise 2 became rejected before + // promise 1 became fulfilled + }); + ``` + + An example real-world use case is implementing timeouts: + + ```javascript + Promise.race([ajax('foo.json'), timeout(5000)]) + ``` + + @method race + @static + @param {Array} promises array of promises to observe + Useful for tooling. + @return {Promise} a promise which settles in the same way as the first passed + promise to settle. +*/ + function race(entries) { + /*jshint validthis:true */ + var Constructor = this; + + if (!isArray(entries)) { + return new Constructor(function(_, reject) { + return reject(new TypeError('You must pass an array to race.')); + }); + } else { + return new Constructor(function(resolve, reject) { + var length = entries.length; + for (var i = 0; i < length; i++) { + Constructor.resolve(entries[i]).then(resolve, reject); + } + }); + } + } + + /** + `Promise.reject` returns a promise rejected with the passed `reason`. + It is shorthand for the following: + + ```javascript + let promise = new Promise(function(resolve, reject){ + reject(new Error('WHOOPS')); + }); + + promise.then(function(value){ + // Code here doesn't run because the promise is rejected! + }, function(reason){ + // reason.message === 'WHOOPS' + }); + ``` + + Instead of writing the above, your code now simply becomes the following: + + ```javascript + let promise = Promise.reject(new Error('WHOOPS')); + + promise.then(function(value){ + // Code here doesn't run because the promise is rejected! + }, function(reason){ + // reason.message === 'WHOOPS' + }); + ``` + + @method reject + @static + @param {Any} reason value that the returned promise will be rejected with. + Useful for tooling. + @return {Promise} a promise rejected with the given `reason`. +*/ + function reject$1(reason) { + /*jshint validthis:true */ + var Constructor = this; + var promise = new Constructor(noop); + reject(promise, reason); + return promise; + } + + function needsResolver() { + throw new TypeError( + 'You must pass a resolver function as the first argument to the promise constructor' + ); + } + + function needsNew() { + throw new TypeError( + "Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function." + ); + } + + /** + Promise objects represent the eventual result of an asynchronous operation. The + primary way of interacting with a promise is through its `then` method, which + registers callbacks to receive either a promise's eventual value or the reason + why the promise cannot be fulfilled. + + Terminology + ----------- + + - `promise` is an object or function with a `then` method whose behavior conforms to this specification. + - `thenable` is an object or function that defines a `then` method. + - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). + - `exception` is a value that is thrown using the throw statement. + - `reason` is a value that indicates why a promise was rejected. + - `settled` the final resting state of a promise, fulfilled or rejected. + + A promise can be in one of three states: pending, fulfilled, or rejected. + + Promises that are fulfilled have a fulfillment value and are in the fulfilled + state. Promises that are rejected have a rejection reason and are in the + rejected state. A fulfillment value is never a thenable. + + Promises can also be said to *resolve* a value. If this value is also a + promise, then the original promise's settled state will match the value's + settled state. So a promise that *resolves* a promise that rejects will + itself reject, and a promise that *resolves* a promise that fulfills will + itself fulfill. + + + Basic Usage: + ------------ + + ```js + let promise = new Promise(function(resolve, reject) { + // on success + resolve(value); + + // on failure + reject(reason); + }); + + promise.then(function(value) { + // on fulfillment + }, function(reason) { + // on rejection + }); + ``` + + Advanced Usage: + --------------- + + Promises shine when abstracting away asynchronous interactions such as + `XMLHttpRequest`s. + + ```js + function getJSON(url) { + return new Promise(function(resolve, reject){ + let xhr = new XMLHttpRequest(); + + xhr.open('GET', url); + xhr.onreadystatechange = handler; + xhr.responseType = 'json'; + xhr.setRequestHeader('Accept', 'application/json'); + xhr.send(); + + function handler() { + if (this.readyState === this.DONE) { + if (this.status === 200) { + resolve(this.response); + } else { + reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); + } + } + }; + }); + } + + getJSON('/posts.json').then(function(json) { + // on fulfillment + }, function(reason) { + // on rejection + }); + ``` + + Unlike callbacks, promises are great composable primitives. + + ```js + Promise.all([ + getJSON('/posts'), + getJSON('/comments') + ]).then(function(values){ + values[0] // => postsJSON + values[1] // => commentsJSON + + return values; + }); + ``` + + @class Promise + @param {Function} resolver + Useful for tooling. + @constructor +*/ + + var Promise$1 = (function() { + function Promise(resolver) { + this[PROMISE_ID] = nextId(); + this._result = this._state = undefined; + this._subscribers = []; + + if (noop !== resolver) { + typeof resolver !== 'function' && needsResolver(); + this instanceof Promise + ? initializePromise(this, resolver) + : needsNew(); + } + } + + /** + The primary way of interacting with a promise is through its `then` method, + which registers callbacks to receive either a promise's eventual value or the + reason why the promise cannot be fulfilled. + ```js + findUser().then(function(user){ + // user is available + }, function(reason){ + // user is unavailable, and you are given the reason why + }); + ``` + Chaining + -------- + The return value of `then` is itself a promise. This second, 'downstream' + promise is resolved with the return value of the first promise's fulfillment + or rejection handler, or rejected if the handler throws an exception. + ```js + findUser().then(function (user) { + return user.name; + }, function (reason) { + return 'default name'; + }).then(function (userName) { + // If `findUser` fulfilled, `userName` will be the user's name, otherwise it + // will be `'default name'` + }); + findUser().then(function (user) { + throw new Error('Found user, but still unhappy'); + }, function (reason) { + throw new Error('`findUser` rejected and we're unhappy'); + }).then(function (value) { + // never reached + }, function (reason) { + // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. + // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. + }); + ``` + If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. + ```js + findUser().then(function (user) { + throw new PedagogicalException('Upstream error'); + }).then(function (value) { + // never reached + }).then(function (value) { + // never reached + }, function (reason) { + // The `PedgagocialException` is propagated all the way down to here + }); + ``` + Assimilation + ------------ + Sometimes the value you want to propagate to a downstream promise can only be + retrieved asynchronously. This can be achieved by returning a promise in the + fulfillment or rejection handler. The downstream promise will then be pending + until the returned promise is settled. This is called *assimilation*. + ```js + findUser().then(function (user) { + return findCommentsByAuthor(user); + }).then(function (comments) { + // The user's comments are now available + }); + ``` + If the assimliated promise rejects, then the downstream promise will also reject. + ```js + findUser().then(function (user) { + return findCommentsByAuthor(user); + }).then(function (comments) { + // If `findCommentsByAuthor` fulfills, we'll have the value here + }, function (reason) { + // If `findCommentsByAuthor` rejects, we'll have the reason here + }); + ``` + Simple Example + -------------- + Synchronous Example + ```javascript + let result; + try { + result = findResult(); + // success + } catch(reason) { + // failure + } + ``` + Errback Example + ```js + findResult(function(result, err){ + if (err) { + // failure + } else { + // success + } + }); + ``` + Promise Example; + ```javascript + findResult().then(function(result){ + // success + }, function(reason){ + // failure + }); + ``` + Advanced Example + -------------- + Synchronous Example + ```javascript + let author, books; + try { + author = findAuthor(); + books = findBooksByAuthor(author); + // success + } catch(reason) { + // failure + } + ``` + Errback Example + ```js + function foundBooks(books) { + } + function failure(reason) { + } + findAuthor(function(author, err){ + if (err) { + failure(err); + // failure + } else { + try { + findBoooksByAuthor(author, function(books, err) { + if (err) { + failure(err); + } else { + try { + foundBooks(books); + } catch(reason) { + failure(reason); + } + } + }); + } catch(error) { + failure(err); + } + // success + } + }); + ``` + Promise Example; + ```javascript + findAuthor(). + then(findBooksByAuthor). + then(function(books){ + // found books + }).catch(function(reason){ + // something went wrong + }); + ``` + @method then + @param {Function} onFulfilled + @param {Function} onRejected + Useful for tooling. + @return {Promise} + */ + + /** + `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same + as the catch block of a try/catch statement. + ```js + function findAuthor(){ + throw new Error('couldn't find that author'); + } + // synchronous + try { + findAuthor(); + } catch(reason) { + // something went wrong + } + // async with promises + findAuthor().catch(function(reason){ + // something went wrong + }); + ``` + @method catch + @param {Function} onRejection + Useful for tooling. + @return {Promise} + */ + + Promise.prototype.catch = function _catch(onRejection) { + return this.then(null, onRejection); + }; + + /** + `finally` will be invoked regardless of the promise's fate just as native + try/catch/finally behaves + + Synchronous example: + + ```js + findAuthor() { + if (Math.random() > 0.5) { + throw new Error(); + } + return new Author(); + } + + try { + return findAuthor(); // succeed or fail + } catch(error) { + return findOtherAuther(); + } finally { + // always runs + // doesn't affect the return value + } + ``` + + Asynchronous example: + + ```js + findAuthor().catch(function(reason){ + return findOtherAuther(); + }).finally(function(){ + // author was either found, or not + }); + ``` + + @method finally + @param {Function} callback + @return {Promise} + */ + + Promise.prototype.finally = function _finally(callback) { + var promise = this; + var constructor = promise.constructor; + + if (isFunction(callback)) { + return promise.then( + function(value) { + return constructor.resolve(callback()).then(function() { + return value; + }); + }, + function(reason) { + return constructor.resolve(callback()).then(function() { + throw reason; + }); + } + ); + } + + return promise.then(callback, callback); + }; + + return Promise; + })(); + + Promise$1.prototype.then = then; + Promise$1.all = all; + Promise$1.race = race; + Promise$1.resolve = resolve$1; + Promise$1.reject = reject$1; + Promise$1._setScheduler = setScheduler; + Promise$1._setAsap = setAsap; + Promise$1._asap = asap; + + /*global self*/ + function polyfill() { + var local = void 0; + + if (typeof global !== 'undefined') { + local = global; + } else if (typeof self !== 'undefined') { + local = self; + } else { + try { + local = Function('return this')(); + } catch (e) { + throw new Error( + 'polyfill failed because global object is unavailable in this environment' + ); + } + } + + var P = local.Promise; + + if (P) { + var promiseToString = null; + try { + promiseToString = Object.prototype.toString.call(P.resolve()); + } catch (e) { + // silently ignored + } + + if (promiseToString === '[object Promise]' && !P.cast) { + return; + } + } + + local.Promise = Promise$1; + } + + // Strange compat.. + Promise$1.polyfill = polyfill; + Promise$1.Promise = Promise$1; + + return Promise$1; + }); + }.call( + this, + _dereq_('_process'), + typeof global !== 'undefined' + ? global + : typeof self !== 'undefined' + ? self + : typeof window !== 'undefined' ? window : {} + )); + }, + { _process: 11 } + ], + 6: [ + function(_dereq_, module, exports) { + (function(global, factory) { + if (typeof define === 'function' && define.amd) { + define(['exports', 'module'], factory); + } else if (typeof exports !== 'undefined' && typeof module !== 'undefined') { + factory(exports, module); + } else { + var mod = { + exports: {} + }; + factory(mod.exports, mod); + global.fetchJsonp = mod.exports; + } + })(this, function(exports, module) { + 'use strict'; + + var defaultOptions = { + timeout: 5000, + jsonpCallback: 'callback', + jsonpCallbackFunction: null + }; + + function generateCallbackFunction() { + return 'jsonp_' + Date.now() + '_' + Math.ceil(Math.random() * 100000); + } + + function clearFunction(functionName) { + // IE8 throws an exception when you try to delete a property on window + // http://stackoverflow.com/a/1824228/751089 + try { + delete window[functionName]; + } catch (e) { + window[functionName] = undefined; + } + } + + function removeScript(scriptId) { + var script = document.getElementById(scriptId); + if (script) { + document.getElementsByTagName('head')[0].removeChild(script); + } + } + + function fetchJsonp(_url) { + var options = + arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; + + // to avoid param reassign + var url = _url; + var timeout = options.timeout || defaultOptions.timeout; + var jsonpCallback = options.jsonpCallback || defaultOptions.jsonpCallback; + + var timeoutId = undefined; + + return new Promise(function(resolve, reject) { + var callbackFunction = + options.jsonpCallbackFunction || generateCallbackFunction(); + var scriptId = jsonpCallback + '_' + callbackFunction; + + window[callbackFunction] = function(response) { + resolve({ + ok: true, + // keep consistent with fetch API + json: function json() { + return Promise.resolve(response); + } + }); + + if (timeoutId) clearTimeout(timeoutId); + + removeScript(scriptId); + + clearFunction(callbackFunction); + }; + + // Check if the user set their own params, and if not add a ? to start a list of params + url += url.indexOf('?') === -1 ? '?' : '&'; + + var jsonpScript = document.createElement('script'); + jsonpScript.setAttribute( + 'src', + '' + url + jsonpCallback + '=' + callbackFunction + ); + if (options.charset) { + jsonpScript.setAttribute('charset', options.charset); + } + jsonpScript.id = scriptId; + document.getElementsByTagName('head')[0].appendChild(jsonpScript); + + timeoutId = setTimeout(function() { + reject(new Error('JSONP request to ' + _url + ' timed out')); + + clearFunction(callbackFunction); + removeScript(scriptId); + window[callbackFunction] = function() { + clearFunction(callbackFunction); + }; + }, timeout); + + // Caught if got 404/500 + jsonpScript.onerror = function() { + reject(new Error('JSONP request to ' + _url + ' failed')); + + clearFunction(callbackFunction); + removeScript(scriptId); + if (timeoutId) clearTimeout(timeoutId); + }; + }); + } + + // export as global function + /* + let local; + if (typeof global !== 'undefined') { + local = global; + } else if (typeof self !== 'undefined') { + local = self; + } else { + try { + local = Function('return this')(); + } catch (e) { + throw new Error('polyfill failed because global object is unavailable in this environment'); + } + } + local.fetchJsonp = fetchJsonp; + */ + + module.exports = fetchJsonp; + }); + }, + {} + ], + 7: [ + function(_dereq_, module, exports) { + /* FileSaver.js + * A saveAs() FileSaver implementation. + * 1.3.2 + * 2016-06-16 18:25:19 + * + * By Eli Grey, http://eligrey.com + * License: MIT + * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md + */ + + /*global self */ + /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */ + + /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */ + + var saveAs = + saveAs || + (function(view) { + 'use strict'; + // IE <10 is explicitly unsupported + if ( + typeof view === 'undefined' || + (typeof navigator !== 'undefined' && + /MSIE [1-9]\./.test(navigator.userAgent)) + ) { + return; + } + var doc = view.document, + // only get URL when necessary in case Blob.js hasn't overridden it yet + get_URL = function() { + return view.URL || view.webkitURL || view; + }, + save_link = doc.createElementNS('http://www.w3.org/1999/xhtml', 'a'), + can_use_save_link = 'download' in save_link, + click = function(node) { + var event = new MouseEvent('click'); + node.dispatchEvent(event); + }, + is_safari = /constructor/i.test(view.HTMLElement) || view.safari, + is_chrome_ios = /CriOS\/[\d]+/.test(navigator.userAgent), + throw_outside = function(ex) { + (view.setImmediate || view.setTimeout)(function() { + throw ex; + }, 0); + }, + force_saveable_type = 'application/octet-stream', + // the Blob API is fundamentally broken as there is no "downloadfinished" event to subscribe to + arbitrary_revoke_timeout = 1000 * 40, // in ms + revoke = function(file) { + var revoker = function() { + if (typeof file === 'string') { + // file is an object URL + get_URL().revokeObjectURL(file); + } else { + // file is a File + file.remove(); + } + }; + setTimeout(revoker, arbitrary_revoke_timeout); + }, + dispatch = function(filesaver, event_types, event) { + event_types = [].concat(event_types); + var i = event_types.length; + while (i--) { + var listener = filesaver['on' + event_types[i]]; + if (typeof listener === 'function') { + try { + listener.call(filesaver, event || filesaver); + } catch (ex) { + throw_outside(ex); + } + } + } + }, + auto_bom = function(blob) { + // prepend BOM for UTF-8 XML and text/* types (including HTML) + // note: your browser will automatically convert UTF-16 U+FEFF to EF BB BF + if ( + /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test( + blob.type + ) + ) { + return new Blob([String.fromCharCode(0xfeff), blob], { + type: blob.type + }); + } + return blob; + }, + FileSaver = function(blob, name, no_auto_bom) { + if (!no_auto_bom) { + blob = auto_bom(blob); + } + // First try a.download, then web filesystem, then object URLs + var filesaver = this, + type = blob.type, + force = type === force_saveable_type, + object_url, + dispatch_all = function() { + dispatch(filesaver, 'writestart progress write writeend'.split(' ')); + }, + // on any filesys errors revert to saving with object URLs + fs_error = function() { + if ((is_chrome_ios || (force && is_safari)) && view.FileReader) { + // Safari doesn't allow downloading of blob urls + var reader = new FileReader(); + reader.onloadend = function() { + var url = is_chrome_ios + ? reader.result + : reader.result.replace( + /^data:[^;]*;/, + 'data:attachment/file;' + ); + var popup = view.open(url, '_blank'); + if (!popup) view.location.href = url; + url = undefined; // release reference before dispatching + filesaver.readyState = filesaver.DONE; + dispatch_all(); + }; + reader.readAsDataURL(blob); + filesaver.readyState = filesaver.INIT; + return; + } + // don't create more object URLs than needed + if (!object_url) { + object_url = get_URL().createObjectURL(blob); + } + if (force) { + view.location.href = object_url; + } else { + var opened = view.open(object_url, '_blank'); + if (!opened) { + // Apple does not allow window.open, see https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html + view.location.href = object_url; + } + } + filesaver.readyState = filesaver.DONE; + dispatch_all(); + revoke(object_url); + }; + filesaver.readyState = filesaver.INIT; + + if (can_use_save_link) { + object_url = get_URL().createObjectURL(blob); + setTimeout(function() { + save_link.href = object_url; + save_link.download = name; + click(save_link); + dispatch_all(); + revoke(object_url); + filesaver.readyState = filesaver.DONE; + }); + return; + } + + fs_error(); + }, + FS_proto = FileSaver.prototype, + saveAs = function(blob, name, no_auto_bom) { + return new FileSaver(blob, name || blob.name || 'download', no_auto_bom); + }; + // IE 10+ (native saveAs) + if (typeof navigator !== 'undefined' && navigator.msSaveOrOpenBlob) { + return function(blob, name, no_auto_bom) { + name = name || blob.name || 'download'; + + if (!no_auto_bom) { + blob = auto_bom(blob); + } + return navigator.msSaveOrOpenBlob(blob, name); + }; + } + + FS_proto.abort = function() {}; + FS_proto.readyState = FS_proto.INIT = 0; + FS_proto.WRITING = 1; + FS_proto.DONE = 2; + + FS_proto.error = FS_proto.onwritestart = FS_proto.onprogress = FS_proto.onwrite = FS_proto.onabort = FS_proto.onerror = FS_proto.onwriteend = null; + + return saveAs; + })( + (typeof self !== 'undefined' && self) || + (typeof window !== 'undefined' && window) || + this.content + ); + // `self` is undefined in Firefox for Android content script context + // while `this` is nsIContentFrameMessageManager + // with an attribute `content` that corresponds to the window + + if (typeof module !== 'undefined' && module.exports) { + module.exports.saveAs = saveAs; + } else if ( + typeof define !== 'undefined' && + define !== null && + define.amd !== null + ) { + define('FileSaver.js', function() { + return saveAs; + }); + } + }, + {} + ], + 8: [ + function(_dereq_, module, exports) { + exports.read = function(buffer, offset, isLE, mLen, nBytes) { + var e, m; + var eLen = nBytes * 8 - mLen - 1; + var eMax = (1 << eLen) - 1; + var eBias = eMax >> 1; + var nBits = -7; + var i = isLE ? nBytes - 1 : 0; + var d = isLE ? -1 : 1; + var s = buffer[offset + i]; + + i += d; + + e = s & ((1 << -nBits) - 1); + s >>= -nBits; + nBits += eLen; + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + m = e & ((1 << -nBits) - 1); + e >>= -nBits; + nBits += mLen; + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + + if (e === 0) { + e = 1 - eBias; + } else if (e === eMax) { + return m ? NaN : (s ? -1 : 1) * Infinity; + } else { + m = m + Math.pow(2, mLen); + e = e - eBias; + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen); + }; + + exports.write = function(buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c; + var eLen = nBytes * 8 - mLen - 1; + var eMax = (1 << eLen) - 1; + var eBias = eMax >> 1; + var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; + var i = isLE ? 0 : nBytes - 1; + var d = isLE ? 1 : -1; + var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0; + + value = Math.abs(value); + + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0; + e = eMax; + } else { + e = Math.floor(Math.log(value) / Math.LN2); + if (value * (c = Math.pow(2, -e)) < 1) { + e--; + c *= 2; + } + if (e + eBias >= 1) { + value += rt / c; + } else { + value += rt * Math.pow(2, 1 - eBias); + } + if (value * c >= 2) { + e++; + c /= 2; + } + + if (e + eBias >= eMax) { + m = 0; + e = eMax; + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen); + e = e + eBias; + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); + e = 0; + } + } + + for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {} + + e = (e << mLen) | m; + eLen += mLen; + for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {} + + buffer[offset + i - d] |= s * 128; + }; + }, + {} + ], + 9: [ + function(_dereq_, module, exports) { + /* + + Copyright 2000, Silicon Graphics, Inc. All Rights Reserved. + Copyright 2015, Google Inc. All Rights Reserved. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice including the dates of first publication and + either this permission notice or a reference to http://oss.sgi.com/projects/FreeB/ + shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR + IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + Original Code. The Original Code is: OpenGL Sample Implementation, + Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, + Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. + Copyright in any portions created by third parties is as indicated + elsewhere herein. All Rights Reserved. +*/ + 'use strict'; + var n; + function t(a, b) { + return a.b === b.b && a.a === b.a; + } + function u(a, b) { + return a.b < b.b || (a.b === b.b && a.a <= b.a); + } + function v(a, b, c) { + var d = b.b - a.b, + e = c.b - b.b; + return 0 < d + e + ? d < e + ? b.a - a.a + d / (d + e) * (a.a - c.a) + : b.a - c.a + e / (d + e) * (c.a - a.a) + : 0; + } + function x(a, b, c) { + var d = b.b - a.b, + e = c.b - b.b; + return 0 < d + e ? (b.a - c.a) * d + (b.a - a.a) * e : 0; + } + function z(a, b) { + return a.a < b.a || (a.a === b.a && a.b <= b.b); + } + function aa(a, b, c) { + var d = b.a - a.a, + e = c.a - b.a; + return 0 < d + e + ? d < e + ? b.b - a.b + d / (d + e) * (a.b - c.b) + : b.b - c.b + e / (d + e) * (c.b - a.b) + : 0; + } + function ba(a, b, c) { + var d = b.a - a.a, + e = c.a - b.a; + return 0 < d + e ? (b.b - c.b) * d + (b.b - a.b) * e : 0; + } + function ca(a) { + return u(a.b.a, a.a); + } + function da(a) { + return u(a.a, a.b.a); + } + function A(a, b, c, d) { + a = 0 > a ? 0 : a; + c = 0 > c ? 0 : c; + return a <= c + ? 0 === c ? (b + d) / 2 : b + a / (a + c) * (d - b) + : d + c / (a + c) * (b - d); + } + function ea(a) { + var b = B(a.b); + C(b, a.c); + C(b.b, a.c); + D(b, a.a); + return b; + } + function E(a, b) { + var c = !1, + d = !1; + a !== b && + (b.a !== a.a && ((d = !0), F(b.a, a.a)), + b.d !== a.d && ((c = !0), G(b.d, a.d)), + H(b, a), + d || (C(b, a.a), (a.a.c = a)), + c || (D(b, a.d), (a.d.a = a))); + } + function I(a) { + var b = a.b, + c = !1; + a.d !== a.b.d && ((c = !0), G(a.d, a.b.d)); + a.c === a + ? F(a.a, null) + : ((a.b.d.a = J(a)), (a.a.c = a.c), H(a, J(a)), c || D(a, a.d)); + b.c === b + ? (F(b.a, null), G(b.d, null)) + : ((a.d.a = J(b)), (b.a.c = b.c), H(b, J(b))); + fa(a); + } + function K(a) { + var b = B(a), + c = b.b; + H(b, a.e); + b.a = a.b.a; + C(c, b.a); + b.d = c.d = a.d; + b = b.b; + H(a.b, J(a.b)); + H(a.b, b); + a.b.a = b.a; + b.b.a.c = b.b; + b.b.d = a.b.d; + b.f = a.f; + b.b.f = a.b.f; + return b; + } + function L(a, b) { + var c = !1, + d = B(a), + e = d.b; + b.d !== a.d && ((c = !0), G(b.d, a.d)); + H(d, a.e); + H(e, b); + d.a = a.b.a; + e.a = b.a; + d.d = e.d = a.d; + a.d.a = e; + c || D(d, a.d); + return d; + } + function B(a) { + var b = new M(), + c = new M(), + d = a.b.h; + c.h = d; + d.b.h = b; + b.h = a; + a.b.h = c; + b.b = c; + b.c = b; + b.e = c; + c.b = b; + c.c = c; + return (c.e = b); + } + function H(a, b) { + var c = a.c, + d = b.c; + c.b.e = b; + d.b.e = a; + a.c = d; + b.c = c; + } + function C(a, b) { + var c = b.f, + d = new N(b, c); + c.e = d; + b.f = d; + c = d.c = a; + do (c.a = d), (c = c.c); + while (c !== a); + } + function D(a, b) { + var c = b.d, + d = new ga(b, c); + c.b = d; + b.d = d; + d.a = a; + d.c = b.c; + c = a; + do (c.d = d), (c = c.e); + while (c !== a); + } + function fa(a) { + var b = a.h; + a = a.b.h; + b.b.h = a; + a.b.h = b; + } + function F(a, b) { + var c = a.c, + d = c; + do (d.a = b), (d = d.c); + while (d !== c); + c = a.f; + d = a.e; + d.f = c; + c.e = d; + } + function G(a, b) { + var c = a.a, + d = c; + do (d.d = b), (d = d.e); + while (d !== c); + c = a.d; + d = a.b; + d.d = c; + c.b = d; + } + function ha(a) { + var b = 0; + Math.abs(a[1]) > Math.abs(a[0]) && (b = 1); + Math.abs(a[2]) > Math.abs(a[b]) && (b = 2); + return b; + } + var O = 4 * 1e150; + function P(a, b) { + a.f += b.f; + a.b.f += b.b.f; + } + function ia(a, b, c) { + a = a.a; + b = b.a; + c = c.a; + if (b.b.a === a) + return c.b.a === a + ? u(b.a, c.a) ? 0 >= x(c.b.a, b.a, c.a) : 0 <= x(b.b.a, c.a, b.a) + : 0 >= x(c.b.a, a, c.a); + if (c.b.a === a) return 0 <= x(b.b.a, a, b.a); + b = v(b.b.a, a, b.a); + a = v(c.b.a, a, c.a); + return b >= a; + } + function Q(a) { + a.a.i = null; + var b = a.e; + b.a.c = b.c; + b.c.a = b.a; + a.e = null; + } + function ja(a, b) { + I(a.a); + a.c = !1; + a.a = b; + b.i = a; + } + function ka(a) { + var b = a.a.a; + do a = R(a); + while (a.a.a === b); + a.c && ((b = L(S(a).a.b, a.a.e)), ja(a, b), (a = R(a))); + return a; + } + function la(a, b, c) { + var d = new ma(); + d.a = c; + d.e = na(a.f, b.e, d); + return (c.i = d); + } + function oa(a, b) { + switch (a.s) { + case 100130: + return 0 !== (b & 1); + case 100131: + return 0 !== b; + case 100132: + return 0 < b; + case 100133: + return 0 > b; + case 100134: + return 2 <= b || -2 >= b; + } + return !1; + } + function pa(a) { + var b = a.a, + c = b.d; + c.c = a.d; + c.a = b; + Q(a); + } + function T(a, b, c) { + a = b; + for (b = b.a; a !== c; ) { + a.c = !1; + var d = S(a), + e = d.a; + if (e.a !== b.a) { + if (!d.c) { + pa(a); + break; + } + e = L(b.c.b, e.b); + ja(d, e); + } + b.c !== e && (E(J(e), e), E(b, e)); + pa(a); + b = d.a; + a = d; + } + return b; + } + function U(a, b, c, d, e, f) { + var g = !0; + do la(a, b, c.b), (c = c.c); + while (c !== d); + for (null === e && (e = S(b).a.b.c); ; ) { + d = S(b); + c = d.a.b; + if (c.a !== e.a) break; + c.c !== e && (E(J(c), c), E(J(e), c)); + d.f = b.f - c.f; + d.d = oa(a, d.f); + b.b = !0; + !g && qa(a, b) && (P(c, e), Q(b), I(e)); + g = !1; + b = d; + e = c; + } + b.b = !0; + f && ra(a, b); + } + function sa(a, b, c, d, e) { + var f = [b.g[0], b.g[1], b.g[2]]; + b.d = null; + b.d = a.o ? a.o(f, c, d, a.c) || null : null; + null === b.d && (e ? a.n || (V(a, 100156), (a.n = !0)) : (b.d = c[0])); + } + function ta(a, b, c) { + var d = [null, null, null, null]; + d[0] = b.a.d; + d[1] = c.a.d; + sa(a, b.a, d, [0.5, 0.5, 0, 0], !1); + E(b, c); + } + function ua(a, b, c, d, e) { + var f = Math.abs(b.b - a.b) + Math.abs(b.a - a.a), + g = Math.abs(c.b - a.b) + Math.abs(c.a - a.a), + h = e + 1; + d[e] = 0.5 * g / (f + g); + d[h] = 0.5 * f / (f + g); + a.g[0] += d[e] * b.g[0] + d[h] * c.g[0]; + a.g[1] += d[e] * b.g[1] + d[h] * c.g[1]; + a.g[2] += d[e] * b.g[2] + d[h] * c.g[2]; + } + function qa(a, b) { + var c = S(b), + d = b.a, + e = c.a; + if (u(d.a, e.a)) { + if (0 < x(e.b.a, d.a, e.a)) return !1; + if (!t(d.a, e.a)) K(e.b), E(d, J(e)), (b.b = c.b = !0); + else if (d.a !== e.a) { + var c = a.e, + f = d.a.h; + if (0 <= f) { + var c = c.b, + g = c.d, + h = c.e, + k = c.c, + l = k[f]; + g[l] = g[c.a]; + k[g[l]] = l; + l <= --c.a && + (1 >= l ? W(c, l) : u(h[g[l >> 1]], h[g[l]]) ? W(c, l) : va(c, l)); + h[f] = null; + k[f] = c.b; + c.b = f; + } else + for (c.c[-(f + 1)] = null; 0 < c.a && null === c.c[c.d[c.a - 1]]; ) --c.a; + ta(a, J(e), d); + } + } else { + if (0 > x(d.b.a, e.a, d.a)) return !1; + R(b).b = b.b = !0; + K(d.b); + E(J(e), d); + } + return !0; + } + function wa(a, b) { + var c = S(b), + d = b.a, + e = c.a, + f = d.a, + g = e.a, + h = d.b.a, + k = e.b.a, + l = new N(); + x(h, a.a, f); + x(k, a.a, g); + if (f === g || Math.min(f.a, h.a) > Math.max(g.a, k.a)) return !1; + if (u(f, g)) { + if (0 < x(k, f, g)) return !1; + } else if (0 > x(h, g, f)) return !1; + var r = h, + p = f, + q = k, + y = g, + m, + w; + u(r, p) || ((m = r), (r = p), (p = m)); + u(q, y) || ((m = q), (q = y), (y = m)); + u(r, q) || ((m = r), (r = q), (q = m), (m = p), (p = y), (y = m)); + u(q, p) + ? u(p, y) + ? ((m = v(r, q, p)), + (w = v(q, p, y)), + 0 > m + w && ((m = -m), (w = -w)), + (l.b = A(m, q.b, w, p.b))) + : ((m = x(r, q, p)), + (w = -x(r, y, p)), + 0 > m + w && ((m = -m), (w = -w)), + (l.b = A(m, q.b, w, y.b))) + : (l.b = (q.b + p.b) / 2); + z(r, p) || ((m = r), (r = p), (p = m)); + z(q, y) || ((m = q), (q = y), (y = m)); + z(r, q) || ((m = r), (r = q), (q = m), (m = p), (p = y), (y = m)); + z(q, p) + ? z(p, y) + ? ((m = aa(r, q, p)), + (w = aa(q, p, y)), + 0 > m + w && ((m = -m), (w = -w)), + (l.a = A(m, q.a, w, p.a))) + : ((m = ba(r, q, p)), + (w = -ba(r, y, p)), + 0 > m + w && ((m = -m), (w = -w)), + (l.a = A(m, q.a, w, y.a))) + : (l.a = (q.a + p.a) / 2); + u(l, a.a) && ((l.b = a.a.b), (l.a = a.a.a)); + r = u(f, g) ? f : g; + u(r, l) && ((l.b = r.b), (l.a = r.a)); + if (t(l, f) || t(l, g)) return qa(a, b), !1; + if ((!t(h, a.a) && 0 <= x(h, a.a, l)) || (!t(k, a.a) && 0 >= x(k, a.a, l))) { + if (k === a.a) + return ( + K(d.b), + E(e.b, d), + (b = ka(b)), + (d = S(b).a), + T(a, S(b), c), + U(a, b, J(d), d, d, !0), + !0 + ); + if (h === a.a) { + K(e.b); + E(d.e, J(e)); + f = c = b; + g = f.a.b.a; + do f = R(f); + while (f.a.b.a === g); + b = f; + f = S(b).a.b.c; + c.a = J(e); + e = T(a, c, null); + U(a, b, e.c, d.b.c, f, !0); + return !0; + } + 0 <= x(h, a.a, l) && + ((R(b).b = b.b = !0), K(d.b), (d.a.b = a.a.b), (d.a.a = a.a.a)); + 0 >= x(k, a.a, l) && + ((b.b = c.b = !0), K(e.b), (e.a.b = a.a.b), (e.a.a = a.a.a)); + return !1; + } + K(d.b); + K(e.b); + E(J(e), d); + d.a.b = l.b; + d.a.a = l.a; + d.a.h = xa(a.e, d.a); + d = d.a; + e = [0, 0, 0, 0]; + l = [f.d, h.d, g.d, k.d]; + d.g[0] = d.g[1] = d.g[2] = 0; + ua(d, f, h, e, 0); + ua(d, g, k, e, 2); + sa(a, d, l, e, !0); + R(b).b = b.b = c.b = !0; + return !1; + } + function ra(a, b) { + for (var c = S(b); ; ) { + for (; c.b; ) (b = c), (c = S(c)); + if (!b.b && ((c = b), (b = R(b)), null === b || !b.b)) break; + b.b = !1; + var d = b.a, + e = c.a, + f; + if ((f = d.b.a !== e.b.a)) + a: { + f = b; + var g = S(f), + h = f.a, + k = g.a, + l = void 0; + if (u(h.b.a, k.b.a)) { + if (0 > x(h.b.a, k.b.a, h.a)) { + f = !1; + break a; + } + R(f).b = f.b = !0; + l = K(h); + E(k.b, l); + l.d.c = f.d; + } else { + if (0 < x(k.b.a, h.b.a, k.a)) { + f = !1; + break a; + } + f.b = g.b = !0; + l = K(k); + E(h.e, k.b); + l.b.d.c = f.d; + } + f = !0; + } + f && + (c.c + ? (Q(c), I(e), (c = S(b)), (e = c.a)) + : b.c && (Q(b), I(d), (b = R(c)), (d = b.a))); + if (d.a !== e.a) + if (d.b.a === e.b.a || b.c || c.c || (d.b.a !== a.a && e.b.a !== a.a)) + qa(a, b); + else if (wa(a, b)) break; + d.a === e.a && d.b.a === e.b.a && (P(e, d), Q(b), I(d), (b = R(c))); + } + } + function ya(a, b) { + a.a = b; + for (var c = b.c; null === c.i; ) + if (((c = c.c), c === b.c)) { + var c = a, + d = b, + e = new ma(); + e.a = d.c.b; + var f = c.f, + g = f.a; + do g = g.a; + while (null !== g.b && !f.c(f.b, e, g.b)); + var f = g.b, + h = S(f), + e = f.a, + g = h.a; + if (0 === x(e.b.a, d, e.a)) + (e = f.a), + t(e.a, d) || + t(e.b.a, d) || + (K(e.b), f.c && (I(e.c), (f.c = !1)), E(d.c, e), ya(c, d)); + else { + var k = u(g.b.a, e.b.a) ? f : h, + h = void 0; + f.d || k.c + ? (k === f ? (h = L(d.c.b, e.e)) : (h = L(g.b.c.b, d.c).b), + k.c + ? ja(k, h) + : ((e = c), + (f = la(c, f, h)), + (f.f = R(f).f + f.a.f), + (f.d = oa(e, f.f))), + ya(c, d)) + : U(c, f, d.c, d.c, null, !0); + } + return; + } + c = ka(c.i); + e = S(c); + f = e.a; + e = T(a, e, null); + if (e.c === f) { + var f = e, + e = f.c, + g = S(c), + h = c.a, + k = g.a, + l = !1; + h.b.a !== k.b.a && wa(a, c); + t(h.a, a.a) && + (E(J(e), h), (c = ka(c)), (e = S(c).a), T(a, S(c), g), (l = !0)); + t(k.a, a.a) && (E(f, J(k)), (f = T(a, g, null)), (l = !0)); + l + ? U(a, c, f.c, e, e, !0) + : (u(k.a, h.a) ? (d = J(k)) : (d = h), + (d = L(f.c.b, d)), + U(a, c, d, d.c, d.c, !1), + (d.b.i.c = !0), + ra(a, c)); + } else U(a, c, e.c, f, f, !0); + } + function za(a, b) { + var c = new ma(), + d = ea(a.b); + d.a.b = O; + d.a.a = b; + d.b.a.b = -O; + d.b.a.a = b; + a.a = d.b.a; + c.a = d; + c.f = 0; + c.d = !1; + c.c = !1; + c.h = !0; + c.b = !1; + d = a.f; + d = na(d, d.a, c); + c.e = d; + } + function Aa(a) { + this.a = new Ba(); + this.b = a; + this.c = ia; + } + function na(a, b, c) { + do b = b.c; + while (null !== b.b && !a.c(a.b, b.b, c)); + a = new Ba(c, b.a, b); + b.a.c = a; + return (b.a = a); + } + function Ba(a, b, c) { + this.b = a || null; + this.a = b || this; + this.c = c || this; + } + function X() { + this.d = Y; + this.p = this.b = this.q = null; + this.j = [0, 0, 0]; + this.s = 100130; + this.n = !1; + this.o = this.a = this.e = this.f = null; + this.m = !1; + this.c = this.r = this.i = this.k = this.l = this.h = null; + } + var Y = 0; + n = X.prototype; + n.x = function() { + Z(this, Y); + }; + n.B = function(a, b) { + switch (a) { + case 100142: + return; + case 100140: + switch (b) { + case 100130: + case 100131: + case 100132: + case 100133: + case 100134: + this.s = b; + return; + } + break; + case 100141: + this.m = !!b; + return; + default: + V(this, 100900); + return; + } + V(this, 100901); + }; + n.y = function(a) { + switch (a) { + case 100142: + return 0; + case 100140: + return this.s; + case 100141: + return this.m; + default: + V(this, 100900); + } + return !1; + }; + n.A = function(a, b, c) { + this.j[0] = a; + this.j[1] = b; + this.j[2] = c; + }; + n.z = function(a, b) { + var c = b ? b : null; + switch (a) { + case 100100: + case 100106: + this.h = c; + break; + case 100104: + case 100110: + this.l = c; + break; + case 100101: + case 100107: + this.k = c; + break; + case 100102: + case 100108: + this.i = c; + break; + case 100103: + case 100109: + this.p = c; + break; + case 100105: + case 100111: + this.o = c; + break; + case 100112: + this.r = c; + break; + default: + V(this, 100900); + } + }; + n.C = function(a, b) { + var c = !1, + d = [0, 0, 0]; + Z(this, 2); + for (var e = 0; 3 > e; ++e) { + var f = a[e]; + -1e150 > f && ((f = -1e150), (c = !0)); + 1e150 < f && ((f = 1e150), (c = !0)); + d[e] = f; + } + c && V(this, 100155); + c = this.q; + null === c ? ((c = ea(this.b)), E(c, c.b)) : (K(c), (c = c.e)); + c.a.d = b; + c.a.g[0] = d[0]; + c.a.g[1] = d[1]; + c.a.g[2] = d[2]; + c.f = 1; + c.b.f = -1; + this.q = c; + }; + n.u = function(a) { + Z(this, Y); + this.d = 1; + this.b = new Ca(); + this.c = a; + }; + n.t = function() { + Z(this, 1); + this.d = 2; + this.q = null; + }; + n.v = function() { + Z(this, 2); + this.d = 1; + }; + n.w = function() { + Z(this, 1); + this.d = Y; + var a = this.j[0], + b = this.j[1], + c = this.j[2], + d = !1, + e = [a, b, c]; + if (0 === a && 0 === b && 0 === c) { + for ( + var b = [-2 * 1e150, -2 * 1e150, -2 * 1e150], + f = [2 * 1e150, 2 * 1e150, 2 * 1e150], + c = [], + g = [], + d = this.b.c, + a = d.e; + a !== d; + a = a.e + ) + for (var h = 0; 3 > h; ++h) { + var k = a.g[h]; + k < f[h] && ((f[h] = k), (g[h] = a)); + k > b[h] && ((b[h] = k), (c[h] = a)); + } + a = 0; + b[1] - f[1] > b[0] - f[0] && (a = 1); + b[2] - f[2] > b[a] - f[a] && (a = 2); + if (f[a] >= b[a]) (e[0] = 0), (e[1] = 0), (e[2] = 1); + else { + b = 0; + f = g[a]; + c = c[a]; + g = [0, 0, 0]; + f = [f.g[0] - c.g[0], f.g[1] - c.g[1], f.g[2] - c.g[2]]; + h = [0, 0, 0]; + for (a = d.e; a !== d; a = a.e) + (h[0] = a.g[0] - c.g[0]), + (h[1] = a.g[1] - c.g[1]), + (h[2] = a.g[2] - c.g[2]), + (g[0] = f[1] * h[2] - f[2] * h[1]), + (g[1] = f[2] * h[0] - f[0] * h[2]), + (g[2] = f[0] * h[1] - f[1] * h[0]), + (k = g[0] * g[0] + g[1] * g[1] + g[2] * g[2]), + k > b && ((b = k), (e[0] = g[0]), (e[1] = g[1]), (e[2] = g[2])); + 0 >= b && ((e[0] = e[1] = e[2] = 0), (e[ha(f)] = 1)); + } + d = !0; + } + g = ha(e); + a = this.b.c; + b = (g + 1) % 3; + c = (g + 2) % 3; + g = 0 < e[g] ? 1 : -1; + for (e = a.e; e !== a; e = e.e) (e.b = e.g[b]), (e.a = g * e.g[c]); + if (d) { + e = 0; + d = this.b.a; + for (a = d.b; a !== d; a = a.b) + if (((b = a.a), !(0 >= b.f))) { + do (e += (b.a.b - b.b.a.b) * (b.a.a + b.b.a.a)), (b = b.e); + while (b !== a.a); + } + if (0 > e) for (e = this.b.c, d = e.e; d !== e; d = d.e) d.a = -d.a; + } + this.n = !1; + e = this.b.b; + for (a = e.h; a !== e; a = d) + if ( + ((d = a.h), + (b = a.e), + t(a.a, a.b.a) && a.e.e !== a && (ta(this, b, a), I(a), (a = b), (b = a.e)), + b.e === a) + ) { + if (b !== a) { + if (b === d || b === d.b) d = d.h; + I(b); + } + if (a === d || a === d.b) d = d.h; + I(a); + } + this.e = e = new Da(); + d = this.b.c; + for (a = d.e; a !== d; a = a.e) a.h = xa(e, a); + Ea(e); + this.f = new Aa(this); + za(this, -O); + for (za(this, O); null !== (e = Fa(this.e)); ) { + for (;;) { + a: if (((a = this.e), 0 === a.a)) d = Ga(a.b); + else if ( + ((d = a.c[a.d[a.a - 1]]), 0 !== a.b.a && ((a = Ga(a.b)), u(a, d))) + ) { + d = a; + break a; + } + if (null === d || !t(d, e)) break; + d = Fa(this.e); + ta(this, e.c, d.c); + } + ya(this, e); + } + this.a = this.f.a.a.b.a.a; + for (e = 0; null !== (d = this.f.a.a.b); ) d.h || ++e, Q(d); + this.f = null; + e = this.e; + e.b = null; + e.d = null; + this.e = e.c = null; + e = this.b; + for (a = e.a.b; a !== e.a; a = d) + (d = a.b), (a = a.a), a.e.e === a && (P(a.c, a), I(a)); + if (!this.n) { + e = this.b; + if (this.m) + for (a = e.b.h; a !== e.b; a = d) + (d = a.h), a.b.d.c !== a.d.c ? (a.f = a.d.c ? 1 : -1) : I(a); + else + for (a = e.a.b; a !== e.a; a = d) + if (((d = a.b), a.c)) { + for (a = a.a; u(a.b.a, a.a); a = a.c.b); + for (; u(a.a, a.b.a); a = a.e); + b = a.c.b; + for (c = void 0; a.e !== b; ) + if (u(a.b.a, b.a)) { + for (; b.e !== a && (ca(b.e) || 0 >= x(b.a, b.b.a, b.e.b.a)); ) + (c = L(b.e, b)), (b = c.b); + b = b.c.b; + } else { + for (; b.e !== a && (da(a.c.b) || 0 <= x(a.b.a, a.a, a.c.b.a)); ) + (c = L(a, a.c.b)), (a = c.b); + a = a.e; + } + for (; b.e.e !== a; ) (c = L(b.e, b)), (b = c.b); + } + if (this.h || this.i || this.k || this.l) + if (this.m) + for (e = this.b, d = e.a.b; d !== e.a; d = d.b) { + if (d.c) { + this.h && this.h(2, this.c); + a = d.a; + do this.k && this.k(a.a.d, this.c), (a = a.e); + while (a !== d.a); + this.i && this.i(this.c); + } + } + else { + e = this.b; + d = !!this.l; + a = !1; + b = -1; + for (c = e.a.d; c !== e.a; c = c.d) + if (c.c) { + a || (this.h && this.h(4, this.c), (a = !0)); + g = c.a; + do + d && + ((f = g.b.d.c ? 0 : 1), + b !== f && ((b = f), this.l && this.l(!!b, this.c))), + this.k && this.k(g.a.d, this.c), + (g = g.e); + while (g !== c.a); + } + a && this.i && this.i(this.c); + } + if (this.r) { + e = this.b; + for (a = e.a.b; a !== e.a; a = d) + if (((d = a.b), !a.c)) { + b = a.a; + c = b.e; + g = void 0; + do + (g = c), + (c = g.e), + (g.d = null), + null === g.b.d && + (g.c === g ? F(g.a, null) : ((g.a.c = g.c), H(g, J(g))), + (f = g.b), + f.c === f ? F(f.a, null) : ((f.a.c = f.c), H(f, J(f))), + fa(g)); + while (g !== b); + b = a.d; + a = a.b; + a.d = b; + b.b = a; + } + this.r(this.b); + this.c = this.b = null; + return; + } + } + this.b = this.c = null; + }; + function Z(a, b) { + if (a.d !== b) + for (; a.d !== b; ) + if (a.d < b) + switch (a.d) { + case Y: + V(a, 100151); + a.u(null); + break; + case 1: + V(a, 100152), a.t(); + } + else + switch (a.d) { + case 2: + V(a, 100154); + a.v(); + break; + case 1: + V(a, 100153), a.w(); + } + } + function V(a, b) { + a.p && a.p(b, a.c); + } + function ga(a, b) { + this.b = a || this; + this.d = b || this; + this.a = null; + this.c = !1; + } + function M() { + this.h = this; + this.i = this.d = this.a = this.e = this.c = this.b = null; + this.f = 0; + } + function J(a) { + return a.b.e; + } + function Ca() { + this.c = new N(); + this.a = new ga(); + this.b = new M(); + this.d = new M(); + this.b.b = this.d; + this.d.b = this.b; + } + function N(a, b) { + this.e = a || this; + this.f = b || this; + this.d = this.c = null; + this.g = [0, 0, 0]; + this.h = this.a = this.b = 0; + } + function Da() { + this.c = []; + this.d = null; + this.a = 0; + this.e = !1; + this.b = new Ha(); + } + function Ea(a) { + a.d = []; + for (var b = 0; b < a.a; b++) a.d[b] = b; + a.d.sort( + (function(a) { + return function(b, e) { + return u(a[b], a[e]) ? 1 : -1; + }; + })(a.c) + ); + a.e = !0; + Ia(a.b); + } + function xa(a, b) { + if (a.e) { + var c = a.b, + d = ++c.a; + 2 * d > c.f && ((c.f *= 2), (c.c = Ja(c.c, c.f + 1))); + var e; + 0 === c.b ? (e = d) : ((e = c.b), (c.b = c.c[c.b])); + c.e[e] = b; + c.c[e] = d; + c.d[d] = e; + c.h && va(c, d); + return e; + } + c = a.a++; + a.c[c] = b; + return -(c + 1); + } + function Fa(a) { + if (0 === a.a) return Ka(a.b); + var b = a.c[a.d[a.a - 1]]; + if (0 !== a.b.a && u(Ga(a.b), b)) return Ka(a.b); + do --a.a; + while (0 < a.a && null === a.c[a.d[a.a - 1]]); + return b; + } + function Ha() { + this.d = Ja([0], 33); + this.e = [null, null]; + this.c = [0, 0]; + this.a = 0; + this.f = 32; + this.b = 0; + this.h = !1; + this.d[1] = 1; + } + function Ja(a, b) { + for (var c = Array(b), d = 0; d < a.length; d++) c[d] = a[d]; + for (; d < b; d++) c[d] = 0; + return c; + } + function Ia(a) { + for (var b = a.a; 1 <= b; --b) W(a, b); + a.h = !0; + } + function Ga(a) { + return a.e[a.d[1]]; + } + function Ka(a) { + var b = a.d, + c = a.e, + d = a.c, + e = b[1], + f = c[e]; + 0 < a.a && + ((b[1] = b[a.a]), + (d[b[1]] = 1), + (c[e] = null), + (d[e] = a.b), + (a.b = e), + 0 < --a.a && W(a, 1)); + return f; + } + function W(a, b) { + for (var c = a.d, d = a.e, e = a.c, f = b, g = c[f]; ; ) { + var h = f << 1; + h < a.a && u(d[c[h + 1]], d[c[h]]) && (h += 1); + var k = c[h]; + if (h > a.a || u(d[g], d[k])) { + c[f] = g; + e[g] = f; + break; + } + c[f] = k; + e[k] = f; + f = h; + } + } + function va(a, b) { + for (var c = a.d, d = a.e, e = a.c, f = b, g = c[f]; ; ) { + var h = f >> 1, + k = c[h]; + if (0 === h || u(d[k], d[g])) { + c[f] = g; + e[g] = f; + break; + } + c[f] = k; + e[k] = f; + f = h; + } + } + function ma() { + this.e = this.a = null; + this.f = 0; + this.c = this.b = this.h = this.d = !1; + } + function S(a) { + return a.e.c.b; + } + function R(a) { + return a.e.a.b; + } + this.libtess = { + GluTesselator: X, + windingRule: { + GLU_TESS_WINDING_ODD: 100130, + GLU_TESS_WINDING_NONZERO: 100131, + GLU_TESS_WINDING_POSITIVE: 100132, + GLU_TESS_WINDING_NEGATIVE: 100133, + GLU_TESS_WINDING_ABS_GEQ_TWO: 100134 + }, + primitiveType: { + GL_LINE_LOOP: 2, + GL_TRIANGLES: 4, + GL_TRIANGLE_STRIP: 5, + GL_TRIANGLE_FAN: 6 + }, + errorType: { + GLU_TESS_MISSING_BEGIN_POLYGON: 100151, + GLU_TESS_MISSING_END_POLYGON: 100153, + GLU_TESS_MISSING_BEGIN_CONTOUR: 100152, + GLU_TESS_MISSING_END_CONTOUR: 100154, + GLU_TESS_COORD_TOO_LARGE: 100155, + GLU_TESS_NEED_COMBINE_CALLBACK: 100156 + }, + gluEnum: { + GLU_TESS_MESH: 100112, + GLU_TESS_TOLERANCE: 100142, + GLU_TESS_WINDING_RULE: 100140, + GLU_TESS_BOUNDARY_ONLY: 100141, + GLU_INVALID_ENUM: 100900, + GLU_INVALID_VALUE: 100901, + GLU_TESS_BEGIN: 100100, + GLU_TESS_VERTEX: 100101, + GLU_TESS_END: 100102, + GLU_TESS_ERROR: 100103, + GLU_TESS_EDGE_FLAG: 100104, + GLU_TESS_COMBINE: 100105, + GLU_TESS_BEGIN_DATA: 100106, + GLU_TESS_VERTEX_DATA: 100107, + GLU_TESS_END_DATA: 100108, + GLU_TESS_ERROR_DATA: 100109, + GLU_TESS_EDGE_FLAG_DATA: 100110, + GLU_TESS_COMBINE_DATA: 100111 + } + }; + X.prototype.gluDeleteTess = X.prototype.x; + X.prototype.gluTessProperty = X.prototype.B; + X.prototype.gluGetTessProperty = X.prototype.y; + X.prototype.gluTessNormal = X.prototype.A; + X.prototype.gluTessCallback = X.prototype.z; + X.prototype.gluTessVertex = X.prototype.C; + X.prototype.gluTessBeginPolygon = X.prototype.u; + X.prototype.gluTessBeginContour = X.prototype.t; + X.prototype.gluTessEndContour = X.prototype.v; + X.prototype.gluTessEndPolygon = X.prototype.w; + if (typeof module !== 'undefined') { + module.exports = this.libtess; + } + }, + {} + ], + 10: [ + function(_dereq_, module, exports) { + (function(Buffer) { + /** + * https://opentype.js.org v0.9.0 | (c) Frederik De Bleser and other contributors | MIT License | Uses tiny-inflate by Devon Govett and string.prototype.codepointat polyfill by Mathias Bynens + */ + + (function(global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' + ? factory(exports) + : typeof define === 'function' && define.amd + ? define(['exports'], factory) + : factory((global.opentype = {})); + })(this, function(exports) { + 'use strict'; + + /*! https://mths.be/codepointat v0.2.0 by @mathias */ + if (!String.prototype.codePointAt) { + (function() { + var defineProperty = (function() { + // IE 8 only supports `Object.defineProperty` on DOM elements + try { + var object = {}; + var $defineProperty = Object.defineProperty; + var result = + $defineProperty(object, object, object) && $defineProperty; + } catch (error) {} + return result; + })(); + var codePointAt = function(position) { + if (this == null) { + throw TypeError(); + } + var string = String(this); + var size = string.length; + // `ToInteger` + var index = position ? Number(position) : 0; + if (index != index) { + // better `isNaN` + index = 0; + } + // Account for out-of-bounds indices: + if (index < 0 || index >= size) { + return undefined; + } + // Get the first code unit + var first = string.charCodeAt(index); + var second; + if ( + // check if it’s the start of a surrogate pair + first >= 0xd800 && + first <= 0xdbff && // high surrogate + size > index + 1 // there is a next code unit + ) { + second = string.charCodeAt(index + 1); + if (second >= 0xdc00 && second <= 0xdfff) { + // low surrogate + // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + return (first - 0xd800) * 0x400 + second - 0xdc00 + 0x10000; + } + } + return first; + }; + if (defineProperty) { + defineProperty(String.prototype, 'codePointAt', { + value: codePointAt, + configurable: true, + writable: true + }); + } else { + String.prototype.codePointAt = codePointAt; + } + })(); + } + + var TINF_OK = 0; + var TINF_DATA_ERROR = -3; + + function Tree() { + this.table = new Uint16Array(16); /* table of code length counts */ + this.trans = new Uint16Array(288); /* code -> symbol translation table */ + } + + function Data(source, dest) { + this.source = source; + this.sourceIndex = 0; + this.tag = 0; + this.bitcount = 0; + + this.dest = dest; + this.destLen = 0; + + this.ltree = new Tree(); /* dynamic length/symbol tree */ + this.dtree = new Tree(); /* dynamic distance tree */ + } + + /* --------------------------------------------------- * + * -- uninitialized global data (static structures) -- * + * --------------------------------------------------- */ + + var sltree = new Tree(); + var sdtree = new Tree(); + + /* extra bits and base tables for length codes */ + var length_bits = new Uint8Array(30); + var length_base = new Uint16Array(30); + + /* extra bits and base tables for distance codes */ + var dist_bits = new Uint8Array(30); + var dist_base = new Uint16Array(30); + + /* special ordering of code length codes */ + var clcidx = new Uint8Array([ + 16, + 17, + 18, + 0, + 8, + 7, + 9, + 6, + 10, + 5, + 11, + 4, + 12, + 3, + 13, + 2, + 14, + 1, + 15 + ]); + + /* used by tinf_decode_trees, avoids allocations every call */ + var code_tree = new Tree(); + var lengths = new Uint8Array(288 + 32); + + /* ----------------------- * + * -- utility functions -- * + * ----------------------- */ + + /* build extra bits and base tables */ + function tinf_build_bits_base(bits, base, delta, first) { + var i, sum; + + /* build bits table */ + for (i = 0; i < delta; ++i) { + bits[i] = 0; + } + for (i = 0; i < 30 - delta; ++i) { + bits[i + delta] = (i / delta) | 0; + } + + /* build base table */ + for (sum = first, i = 0; i < 30; ++i) { + base[i] = sum; + sum += 1 << bits[i]; + } + } + + /* build the fixed huffman trees */ + function tinf_build_fixed_trees(lt, dt) { + var i; + + /* build fixed length tree */ + for (i = 0; i < 7; ++i) { + lt.table[i] = 0; + } + + lt.table[7] = 24; + lt.table[8] = 152; + lt.table[9] = 112; + + for (i = 0; i < 24; ++i) { + lt.trans[i] = 256 + i; + } + for (i = 0; i < 144; ++i) { + lt.trans[24 + i] = i; + } + for (i = 0; i < 8; ++i) { + lt.trans[24 + 144 + i] = 280 + i; + } + for (i = 0; i < 112; ++i) { + lt.trans[24 + 144 + 8 + i] = 144 + i; + } + + /* build fixed distance tree */ + for (i = 0; i < 5; ++i) { + dt.table[i] = 0; + } + + dt.table[5] = 32; + + for (i = 0; i < 32; ++i) { + dt.trans[i] = i; + } + } + + /* given an array of code lengths, build a tree */ + var offs = new Uint16Array(16); + + function tinf_build_tree(t, lengths, off, num) { + var i, sum; + + /* clear code length count table */ + for (i = 0; i < 16; ++i) { + t.table[i] = 0; + } + + /* scan symbol lengths, and sum code length counts */ + for (i = 0; i < num; ++i) { + t.table[lengths[off + i]]++; + } + + t.table[0] = 0; + + /* compute offset table for distribution sort */ + for (sum = 0, i = 0; i < 16; ++i) { + offs[i] = sum; + sum += t.table[i]; + } + + /* create code->symbol translation table (symbols sorted by code) */ + for (i = 0; i < num; ++i) { + if (lengths[off + i]) { + t.trans[offs[lengths[off + i]]++] = i; + } + } + } + + /* ---------------------- * + * -- decode functions -- * + * ---------------------- */ + + /* get one bit from source stream */ + function tinf_getbit(d) { + /* check if tag is empty */ + if (!d.bitcount--) { + /* load next tag */ + d.tag = d.source[d.sourceIndex++]; + d.bitcount = 7; + } + + /* shift bit out of tag */ + var bit = d.tag & 1; + d.tag >>>= 1; + + return bit; + } + + /* read a num bit value from a stream and add base */ + function tinf_read_bits(d, num, base) { + if (!num) { + return base; + } + + while (d.bitcount < 24) { + d.tag |= d.source[d.sourceIndex++] << d.bitcount; + d.bitcount += 8; + } + + var val = d.tag & (0xffff >>> (16 - num)); + d.tag >>>= num; + d.bitcount -= num; + return val + base; + } + + /* given a data stream and a tree, decode a symbol */ + function tinf_decode_symbol(d, t) { + while (d.bitcount < 24) { + d.tag |= d.source[d.sourceIndex++] << d.bitcount; + d.bitcount += 8; + } + + var sum = 0, + cur = 0, + len = 0; + var tag = d.tag; + + /* get more bits while code value is above sum */ + do { + cur = 2 * cur + (tag & 1); + tag >>>= 1; + ++len; + + sum += t.table[len]; + cur -= t.table[len]; + } while (cur >= 0); + + d.tag = tag; + d.bitcount -= len; + + return t.trans[sum + cur]; + } + + /* given a data stream, decode dynamic trees from it */ + function tinf_decode_trees(d, lt, dt) { + var hlit, hdist, hclen; + var i, num, length; + + /* get 5 bits HLIT (257-286) */ + hlit = tinf_read_bits(d, 5, 257); + + /* get 5 bits HDIST (1-32) */ + hdist = tinf_read_bits(d, 5, 1); + + /* get 4 bits HCLEN (4-19) */ + hclen = tinf_read_bits(d, 4, 4); + + for (i = 0; i < 19; ++i) { + lengths[i] = 0; + } + + /* read code lengths for code length alphabet */ + for (i = 0; i < hclen; ++i) { + /* get 3 bits code length (0-7) */ + var clen = tinf_read_bits(d, 3, 0); + lengths[clcidx[i]] = clen; + } + + /* build code length tree */ + tinf_build_tree(code_tree, lengths, 0, 19); + + /* decode code lengths for the dynamic trees */ + for (num = 0; num < hlit + hdist; ) { + var sym = tinf_decode_symbol(d, code_tree); + + switch (sym) { + case 16: + /* copy previous code length 3-6 times (read 2 bits) */ + var prev = lengths[num - 1]; + for (length = tinf_read_bits(d, 2, 3); length; --length) { + lengths[num++] = prev; + } + break; + case 17: + /* repeat code length 0 for 3-10 times (read 3 bits) */ + for (length = tinf_read_bits(d, 3, 3); length; --length) { + lengths[num++] = 0; + } + break; + case 18: + /* repeat code length 0 for 11-138 times (read 7 bits) */ + for (length = tinf_read_bits(d, 7, 11); length; --length) { + lengths[num++] = 0; + } + break; + default: + /* values 0-15 represent the actual code lengths */ + lengths[num++] = sym; + break; + } + } + + /* build dynamic trees */ + tinf_build_tree(lt, lengths, 0, hlit); + tinf_build_tree(dt, lengths, hlit, hdist); + } + + /* ----------------------------- * + * -- block inflate functions -- * + * ----------------------------- */ + + /* given a stream and two trees, inflate a block of data */ + function tinf_inflate_block_data(d, lt, dt) { + while (1) { + var sym = tinf_decode_symbol(d, lt); + + /* check for end of block */ + if (sym === 256) { + return TINF_OK; + } + + if (sym < 256) { + d.dest[d.destLen++] = sym; + } else { + var length, dist, offs; + var i; + + sym -= 257; + + /* possibly get more bits from length code */ + length = tinf_read_bits(d, length_bits[sym], length_base[sym]); + + dist = tinf_decode_symbol(d, dt); + + /* possibly get more bits from distance code */ + offs = d.destLen - tinf_read_bits(d, dist_bits[dist], dist_base[dist]); + + /* copy match */ + for (i = offs; i < offs + length; ++i) { + d.dest[d.destLen++] = d.dest[i]; + } + } + } + } + + /* inflate an uncompressed block of data */ + function tinf_inflate_uncompressed_block(d) { + var length, invlength; + var i; + + /* unread from bitbuffer */ + while (d.bitcount > 8) { + d.sourceIndex--; + d.bitcount -= 8; + } + + /* get length */ + length = d.source[d.sourceIndex + 1]; + length = 256 * length + d.source[d.sourceIndex]; + + /* get one's complement of length */ + invlength = d.source[d.sourceIndex + 3]; + invlength = 256 * invlength + d.source[d.sourceIndex + 2]; + + /* check length */ + if (length !== (~invlength & 0x0000ffff)) { + return TINF_DATA_ERROR; + } + + d.sourceIndex += 4; + + /* copy block */ + for (i = length; i; --i) { + d.dest[d.destLen++] = d.source[d.sourceIndex++]; + } + + /* make sure we start next block on a byte boundary */ + d.bitcount = 0; + + return TINF_OK; + } + + /* inflate stream from source to dest */ + function tinf_uncompress(source, dest) { + var d = new Data(source, dest); + var bfinal, btype, res; + + do { + /* read final block flag */ + bfinal = tinf_getbit(d); + + /* read block type (2 bits) */ + btype = tinf_read_bits(d, 2, 0); + + /* decompress block */ + switch (btype) { + case 0: + /* decompress uncompressed block */ + res = tinf_inflate_uncompressed_block(d); + break; + case 1: + /* decompress block with fixed huffman trees */ + res = tinf_inflate_block_data(d, sltree, sdtree); + break; + case 2: + /* decompress block with dynamic huffman trees */ + tinf_decode_trees(d, d.ltree, d.dtree); + res = tinf_inflate_block_data(d, d.ltree, d.dtree); + break; + default: + res = TINF_DATA_ERROR; + } + + if (res !== TINF_OK) { + throw new Error('Data error'); + } + } while (!bfinal); + + if (d.destLen < d.dest.length) { + if (typeof d.dest.slice === 'function') { + return d.dest.slice(0, d.destLen); + } else { + return d.dest.subarray(0, d.destLen); + } + } + + return d.dest; + } + + /* -------------------- * + * -- initialization -- * + * -------------------- */ + + /* build fixed huffman trees */ + tinf_build_fixed_trees(sltree, sdtree); + + /* build extra bits and base tables */ + tinf_build_bits_base(length_bits, length_base, 4, 3); + tinf_build_bits_base(dist_bits, dist_base, 2, 1); + + /* fix a special case */ + length_bits[28] = 0; + length_base[28] = 258; + + var tinyInflate = tinf_uncompress; + + // The Bounding Box object + + function derive(v0, v1, v2, v3, t) { + return ( + Math.pow(1 - t, 3) * v0 + + 3 * Math.pow(1 - t, 2) * t * v1 + + 3 * (1 - t) * Math.pow(t, 2) * v2 + + Math.pow(t, 3) * v3 + ); + } + /** + * A bounding box is an enclosing box that describes the smallest measure within which all the points lie. + * It is used to calculate the bounding box of a glyph or text path. + * + * On initialization, x1/y1/x2/y2 will be NaN. Check if the bounding box is empty using `isEmpty()`. + * + * @exports opentype.BoundingBox + * @class + * @constructor + */ + function BoundingBox() { + this.x1 = Number.NaN; + this.y1 = Number.NaN; + this.x2 = Number.NaN; + this.y2 = Number.NaN; + } + + /** + * Returns true if the bounding box is empty, that is, no points have been added to the box yet. + */ + BoundingBox.prototype.isEmpty = function() { + return isNaN(this.x1) || isNaN(this.y1) || isNaN(this.x2) || isNaN(this.y2); + }; + + /** + * Add the point to the bounding box. + * The x1/y1/x2/y2 coordinates of the bounding box will now encompass the given point. + * @param {number} x - The X coordinate of the point. + * @param {number} y - The Y coordinate of the point. + */ + BoundingBox.prototype.addPoint = function(x, y) { + if (typeof x === 'number') { + if (isNaN(this.x1) || isNaN(this.x2)) { + this.x1 = x; + this.x2 = x; + } + if (x < this.x1) { + this.x1 = x; + } + if (x > this.x2) { + this.x2 = x; + } + } + if (typeof y === 'number') { + if (isNaN(this.y1) || isNaN(this.y2)) { + this.y1 = y; + this.y2 = y; + } + if (y < this.y1) { + this.y1 = y; + } + if (y > this.y2) { + this.y2 = y; + } + } + }; + + /** + * Add a X coordinate to the bounding box. + * This extends the bounding box to include the X coordinate. + * This function is used internally inside of addBezier. + * @param {number} x - The X coordinate of the point. + */ + BoundingBox.prototype.addX = function(x) { + this.addPoint(x, null); + }; + + /** + * Add a Y coordinate to the bounding box. + * This extends the bounding box to include the Y coordinate. + * This function is used internally inside of addBezier. + * @param {number} y - The Y coordinate of the point. + */ + BoundingBox.prototype.addY = function(y) { + this.addPoint(null, y); + }; + + /** + * Add a Bézier curve to the bounding box. + * This extends the bounding box to include the entire Bézier. + * @param {number} x0 - The starting X coordinate. + * @param {number} y0 - The starting Y coordinate. + * @param {number} x1 - The X coordinate of the first control point. + * @param {number} y1 - The Y coordinate of the first control point. + * @param {number} x2 - The X coordinate of the second control point. + * @param {number} y2 - The Y coordinate of the second control point. + * @param {number} x - The ending X coordinate. + * @param {number} y - The ending Y coordinate. + */ + BoundingBox.prototype.addBezier = function(x0, y0, x1, y1, x2, y2, x, y) { + var this$1 = this; + + // This code is based on http://nishiohirokazu.blogspot.com/2009/06/how-to-calculate-bezier-curves-bounding.html + // and https://github.com/icons8/svg-path-bounding-box + + var p0 = [x0, y0]; + var p1 = [x1, y1]; + var p2 = [x2, y2]; + var p3 = [x, y]; + + this.addPoint(x0, y0); + this.addPoint(x, y); + + for (var i = 0; i <= 1; i++) { + var b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i]; + var a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i]; + var c = 3 * p1[i] - 3 * p0[i]; + + if (a === 0) { + if (b === 0) { + continue; + } + var t = -c / b; + if (0 < t && t < 1) { + if (i === 0) { + this$1.addX(derive(p0[i], p1[i], p2[i], p3[i], t)); + } + if (i === 1) { + this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t)); + } + } + continue; + } + + var b2ac = Math.pow(b, 2) - 4 * c * a; + if (b2ac < 0) { + continue; + } + var t1 = (-b + Math.sqrt(b2ac)) / (2 * a); + if (0 < t1 && t1 < 1) { + if (i === 0) { + this$1.addX(derive(p0[i], p1[i], p2[i], p3[i], t1)); + } + if (i === 1) { + this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t1)); + } + } + var t2 = (-b - Math.sqrt(b2ac)) / (2 * a); + if (0 < t2 && t2 < 1) { + if (i === 0) { + this$1.addX(derive(p0[i], p1[i], p2[i], p3[i], t2)); + } + if (i === 1) { + this$1.addY(derive(p0[i], p1[i], p2[i], p3[i], t2)); + } + } + } + }; + + /** + * Add a quadratic curve to the bounding box. + * This extends the bounding box to include the entire quadratic curve. + * @param {number} x0 - The starting X coordinate. + * @param {number} y0 - The starting Y coordinate. + * @param {number} x1 - The X coordinate of the control point. + * @param {number} y1 - The Y coordinate of the control point. + * @param {number} x - The ending X coordinate. + * @param {number} y - The ending Y coordinate. + */ + BoundingBox.prototype.addQuad = function(x0, y0, x1, y1, x, y) { + var cp1x = x0 + 2 / 3 * (x1 - x0); + var cp1y = y0 + 2 / 3 * (y1 - y0); + var cp2x = cp1x + 1 / 3 * (x - x0); + var cp2y = cp1y + 1 / 3 * (y - y0); + this.addBezier(x0, y0, cp1x, cp1y, cp2x, cp2y, x, y); + }; + + // Geometric objects + + /** + * A bézier path containing a set of path commands similar to a SVG path. + * Paths can be drawn on a context using `draw`. + * @exports opentype.Path + * @class + * @constructor + */ + function Path() { + this.commands = []; + this.fill = 'black'; + this.stroke = null; + this.strokeWidth = 1; + } + + /** + * @param {number} x + * @param {number} y + */ + Path.prototype.moveTo = function(x, y) { + this.commands.push({ + type: 'M', + x: x, + y: y + }); + }; + + /** + * @param {number} x + * @param {number} y + */ + Path.prototype.lineTo = function(x, y) { + this.commands.push({ + type: 'L', + x: x, + y: y + }); + }; + + /** + * Draws cubic curve + * @function + * curveTo + * @memberof opentype.Path.prototype + * @param {number} x1 - x of control 1 + * @param {number} y1 - y of control 1 + * @param {number} x2 - x of control 2 + * @param {number} y2 - y of control 2 + * @param {number} x - x of path point + * @param {number} y - y of path point + */ + + /** + * Draws cubic curve + * @function + * bezierCurveTo + * @memberof opentype.Path.prototype + * @param {number} x1 - x of control 1 + * @param {number} y1 - y of control 1 + * @param {number} x2 - x of control 2 + * @param {number} y2 - y of control 2 + * @param {number} x - x of path point + * @param {number} y - y of path point + * @see curveTo + */ + Path.prototype.curveTo = Path.prototype.bezierCurveTo = function( + x1, + y1, + x2, + y2, + x, + y + ) { + this.commands.push({ + type: 'C', + x1: x1, + y1: y1, + x2: x2, + y2: y2, + x: x, + y: y + }); + }; + + /** + * Draws quadratic curve + * @function + * quadraticCurveTo + * @memberof opentype.Path.prototype + * @param {number} x1 - x of control + * @param {number} y1 - y of control + * @param {number} x - x of path point + * @param {number} y - y of path point + */ + + /** + * Draws quadratic curve + * @function + * quadTo + * @memberof opentype.Path.prototype + * @param {number} x1 - x of control + * @param {number} y1 - y of control + * @param {number} x - x of path point + * @param {number} y - y of path point + */ + Path.prototype.quadTo = Path.prototype.quadraticCurveTo = function( + x1, + y1, + x, + y + ) { + this.commands.push({ + type: 'Q', + x1: x1, + y1: y1, + x: x, + y: y + }); + }; + + /** + * Closes the path + * @function closePath + * @memberof opentype.Path.prototype + */ + + /** + * Close the path + * @function close + * @memberof opentype.Path.prototype + */ + Path.prototype.close = Path.prototype.closePath = function() { + this.commands.push({ + type: 'Z' + }); + }; + + /** + * Add the given path or list of commands to the commands of this path. + * @param {Array} pathOrCommands - another opentype.Path, an opentype.BoundingBox, or an array of commands. + */ + Path.prototype.extend = function(pathOrCommands) { + if (pathOrCommands.commands) { + pathOrCommands = pathOrCommands.commands; + } else if (pathOrCommands instanceof BoundingBox) { + var box = pathOrCommands; + this.moveTo(box.x1, box.y1); + this.lineTo(box.x2, box.y1); + this.lineTo(box.x2, box.y2); + this.lineTo(box.x1, box.y2); + this.close(); + return; + } + + Array.prototype.push.apply(this.commands, pathOrCommands); + }; + + /** + * Calculate the bounding box of the path. + * @returns {opentype.BoundingBox} + */ + Path.prototype.getBoundingBox = function() { + var this$1 = this; + + var box = new BoundingBox(); + + var startX = 0; + var startY = 0; + var prevX = 0; + var prevY = 0; + for (var i = 0; i < this.commands.length; i++) { + var cmd = this$1.commands[i]; + switch (cmd.type) { + case 'M': + box.addPoint(cmd.x, cmd.y); + startX = prevX = cmd.x; + startY = prevY = cmd.y; + break; + case 'L': + box.addPoint(cmd.x, cmd.y); + prevX = cmd.x; + prevY = cmd.y; + break; + case 'Q': + box.addQuad(prevX, prevY, cmd.x1, cmd.y1, cmd.x, cmd.y); + prevX = cmd.x; + prevY = cmd.y; + break; + case 'C': + box.addBezier( + prevX, + prevY, + cmd.x1, + cmd.y1, + cmd.x2, + cmd.y2, + cmd.x, + cmd.y + ); + prevX = cmd.x; + prevY = cmd.y; + break; + case 'Z': + prevX = startX; + prevY = startY; + break; + default: + throw new Error('Unexpected path command ' + cmd.type); + } + } + if (box.isEmpty()) { + box.addPoint(0, 0); + } + return box; + }; + + /** + * Draw the path to a 2D context. + * @param {CanvasRenderingContext2D} ctx - A 2D drawing context. + */ + Path.prototype.draw = function(ctx) { + var this$1 = this; + + ctx.beginPath(); + for (var i = 0; i < this.commands.length; i += 1) { + var cmd = this$1.commands[i]; + if (cmd.type === 'M') { + ctx.moveTo(cmd.x, cmd.y); + } else if (cmd.type === 'L') { + ctx.lineTo(cmd.x, cmd.y); + } else if (cmd.type === 'C') { + ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); + } else if (cmd.type === 'Q') { + ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y); + } else if (cmd.type === 'Z') { + ctx.closePath(); + } + } + + if (this.fill) { + ctx.fillStyle = this.fill; + ctx.fill(); + } + + if (this.stroke) { + ctx.strokeStyle = this.stroke; + ctx.lineWidth = this.strokeWidth; + ctx.stroke(); + } + }; + + /** + * Convert the Path to a string of path data instructions + * See http://www.w3.org/TR/SVG/paths.html#PathData + * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values + * @return {string} + */ + Path.prototype.toPathData = function(decimalPlaces) { + var this$1 = this; + + decimalPlaces = decimalPlaces !== undefined ? decimalPlaces : 2; + + function floatToString(v) { + if (Math.round(v) === v) { + return '' + Math.round(v); + } else { + return v.toFixed(decimalPlaces); + } + } + + function packValues() { + var arguments$1 = arguments; + + var s = ''; + for (var i = 0; i < arguments.length; i += 1) { + var v = arguments$1[i]; + if (v >= 0 && i > 0) { + s += ' '; + } + + s += floatToString(v); + } + + return s; + } + + var d = ''; + for (var i = 0; i < this.commands.length; i += 1) { + var cmd = this$1.commands[i]; + if (cmd.type === 'M') { + d += 'M' + packValues(cmd.x, cmd.y); + } else if (cmd.type === 'L') { + d += 'L' + packValues(cmd.x, cmd.y); + } else if (cmd.type === 'C') { + d += 'C' + packValues(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); + } else if (cmd.type === 'Q') { + d += 'Q' + packValues(cmd.x1, cmd.y1, cmd.x, cmd.y); + } else if (cmd.type === 'Z') { + d += 'Z'; + } + } + + return d; + }; + + /** + * Convert the path to an SVG element, as a string. + * @param {number} [decimalPlaces=2] - The amount of decimal places for floating-point values + * @return {string} + */ + Path.prototype.toSVG = function(decimalPlaces) { + var svg = '= 0 && v <= 255, + 'Byte value should be between 0 and 255.' + ); + return [v]; + }; + /** + * @constant + * @type {number} + */ + sizeOf.BYTE = constant(1); + + /** + * Convert a 8-bit signed integer to a list of 1 byte. + * @param {string} + * @returns {Array} + */ + encode.CHAR = function(v) { + return [v.charCodeAt(0)]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.CHAR = constant(1); + + /** + * Convert an ASCII string to a list of bytes. + * @param {string} + * @returns {Array} + */ + encode.CHARARRAY = function(v) { + var b = []; + for (var i = 0; i < v.length; i += 1) { + b[i] = v.charCodeAt(i); + } + + return b; + }; + + /** + * @param {Array} + * @returns {number} + */ + sizeOf.CHARARRAY = function(v) { + return v.length; + }; + + /** + * Convert a 16-bit unsigned integer to a list of 2 bytes. + * @param {number} + * @returns {Array} + */ + encode.USHORT = function(v) { + return [(v >> 8) & 0xff, v & 0xff]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.USHORT = constant(2); + + /** + * Convert a 16-bit signed integer to a list of 2 bytes. + * @param {number} + * @returns {Array} + */ + encode.SHORT = function(v) { + // Two's complement + if (v >= LIMIT16) { + v = -(2 * LIMIT16 - v); + } + + return [(v >> 8) & 0xff, v & 0xff]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.SHORT = constant(2); + + /** + * Convert a 24-bit unsigned integer to a list of 3 bytes. + * @param {number} + * @returns {Array} + */ + encode.UINT24 = function(v) { + return [(v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.UINT24 = constant(3); + + /** + * Convert a 32-bit unsigned integer to a list of 4 bytes. + * @param {number} + * @returns {Array} + */ + encode.ULONG = function(v) { + return [(v >> 24) & 0xff, (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.ULONG = constant(4); + + /** + * Convert a 32-bit unsigned integer to a list of 4 bytes. + * @param {number} + * @returns {Array} + */ + encode.LONG = function(v) { + // Two's complement + if (v >= LIMIT32) { + v = -(2 * LIMIT32 - v); + } + + return [(v >> 24) & 0xff, (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.LONG = constant(4); + + encode.FIXED = encode.ULONG; + sizeOf.FIXED = sizeOf.ULONG; + + encode.FWORD = encode.SHORT; + sizeOf.FWORD = sizeOf.SHORT; + + encode.UFWORD = encode.USHORT; + sizeOf.UFWORD = sizeOf.USHORT; + + /** + * Convert a 32-bit Apple Mac timestamp integer to a list of 8 bytes, 64-bit timestamp. + * @param {number} + * @returns {Array} + */ + encode.LONGDATETIME = function(v) { + return [ + 0, + 0, + 0, + 0, + (v >> 24) & 0xff, + (v >> 16) & 0xff, + (v >> 8) & 0xff, + v & 0xff + ]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.LONGDATETIME = constant(8); + + /** + * Convert a 4-char tag to a list of 4 bytes. + * @param {string} + * @returns {Array} + */ + encode.TAG = function(v) { + check.argument(v.length === 4, 'Tag should be exactly 4 ASCII characters.'); + return [v.charCodeAt(0), v.charCodeAt(1), v.charCodeAt(2), v.charCodeAt(3)]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.TAG = constant(4); + + // CFF data types /////////////////////////////////////////////////////////// + + encode.Card8 = encode.BYTE; + sizeOf.Card8 = sizeOf.BYTE; + + encode.Card16 = encode.USHORT; + sizeOf.Card16 = sizeOf.USHORT; + + encode.OffSize = encode.BYTE; + sizeOf.OffSize = sizeOf.BYTE; + + encode.SID = encode.USHORT; + sizeOf.SID = sizeOf.USHORT; + + // Convert a numeric operand or charstring number to a variable-size list of bytes. + /** + * Convert a numeric operand or charstring number to a variable-size list of bytes. + * @param {number} + * @returns {Array} + */ + encode.NUMBER = function(v) { + if (v >= -107 && v <= 107) { + return [v + 139]; + } else if (v >= 108 && v <= 1131) { + v = v - 108; + return [(v >> 8) + 247, v & 0xff]; + } else if (v >= -1131 && v <= -108) { + v = -v - 108; + return [(v >> 8) + 251, v & 0xff]; + } else if (v >= -32768 && v <= 32767) { + return encode.NUMBER16(v); + } else { + return encode.NUMBER32(v); + } + }; + + /** + * @param {number} + * @returns {number} + */ + sizeOf.NUMBER = function(v) { + return encode.NUMBER(v).length; + }; + + /** + * Convert a signed number between -32768 and +32767 to a three-byte value. + * This ensures we always use three bytes, but is not the most compact format. + * @param {number} + * @returns {Array} + */ + encode.NUMBER16 = function(v) { + return [28, (v >> 8) & 0xff, v & 0xff]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.NUMBER16 = constant(3); + + /** + * Convert a signed number between -(2^31) and +(2^31-1) to a five-byte value. + * This is useful if you want to be sure you always use four bytes, + * at the expense of wasting a few bytes for smaller numbers. + * @param {number} + * @returns {Array} + */ + encode.NUMBER32 = function(v) { + return [29, (v >> 24) & 0xff, (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff]; + }; + + /** + * @constant + * @type {number} + */ + sizeOf.NUMBER32 = constant(5); + + /** + * @param {number} + * @returns {Array} + */ + encode.REAL = function(v) { + var value = v.toString(); + + // Some numbers use an epsilon to encode the value. (e.g. JavaScript will store 0.0000001 as 1e-7) + // This code converts it back to a number without the epsilon. + var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value); + if (m) { + var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length)); + value = (Math.round(v * epsilon) / epsilon).toString(); + } + + var nibbles = ''; + for (var i = 0, ii = value.length; i < ii; i += 1) { + var c = value[i]; + if (c === 'e') { + nibbles += value[++i] === '-' ? 'c' : 'b'; + } else if (c === '.') { + nibbles += 'a'; + } else if (c === '-') { + nibbles += 'e'; + } else { + nibbles += c; + } + } + + nibbles += nibbles.length & 1 ? 'f' : 'ff'; + var out = [30]; + for (var i$1 = 0, ii$1 = nibbles.length; i$1 < ii$1; i$1 += 2) { + out.push(parseInt(nibbles.substr(i$1, 2), 16)); + } + + return out; + }; + + /** + * @param {number} + * @returns {number} + */ + sizeOf.REAL = function(v) { + return encode.REAL(v).length; + }; + + encode.NAME = encode.CHARARRAY; + sizeOf.NAME = sizeOf.CHARARRAY; + + encode.STRING = encode.CHARARRAY; + sizeOf.STRING = sizeOf.CHARARRAY; + + /** + * @param {DataView} data + * @param {number} offset + * @param {number} numBytes + * @returns {string} + */ + decode.UTF8 = function(data, offset, numBytes) { + var codePoints = []; + var numChars = numBytes; + for (var j = 0; j < numChars; j++, offset += 1) { + codePoints[j] = data.getUint8(offset); + } + + return String.fromCharCode.apply(null, codePoints); + }; + + /** + * @param {DataView} data + * @param {number} offset + * @param {number} numBytes + * @returns {string} + */ + decode.UTF16 = function(data, offset, numBytes) { + var codePoints = []; + var numChars = numBytes / 2; + for (var j = 0; j < numChars; j++, offset += 2) { + codePoints[j] = data.getUint16(offset); + } + + return String.fromCharCode.apply(null, codePoints); + }; + + /** + * Convert a JavaScript string to UTF16-BE. + * @param {string} + * @returns {Array} + */ + encode.UTF16 = function(v) { + var b = []; + for (var i = 0; i < v.length; i += 1) { + var codepoint = v.charCodeAt(i); + b[b.length] = (codepoint >> 8) & 0xff; + b[b.length] = codepoint & 0xff; + } + + return b; + }; + + /** + * @param {string} + * @returns {number} + */ + sizeOf.UTF16 = function(v) { + return v.length * 2; + }; + + // Data for converting old eight-bit Macintosh encodings to Unicode. + // This representation is optimized for decoding; encoding is slower + // and needs more memory. The assumption is that all opentype.js users + // want to open fonts, but saving a font will be comparatively rare + // so it can be more expensive. Keyed by IANA character set name. + // + // Python script for generating these strings: + // + // s = u''.join([chr(c).decode('mac_greek') for c in range(128, 256)]) + // print(s.encode('utf-8')) + /** + * @private + */ + var eightBitMacEncodings = { + // Python: 'mac_croatian' + 'x-mac-croatian': + 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®Š™´¨≠ŽØ∞±≤≥∆µ∂∑∏š∫ªºΩžø' + + '¿¡¬√ƒ≈ƫȅ ÀÃÕŒœĐ—“”‘’÷◊©⁄€‹›Æ»–·‚„‰ÂćÁčÈÍÎÏÌÓÔđÒÚÛÙıˆ˜¯πË˚¸Êæˇ', + // Python: 'mac_cyrillic' + 'x-mac-cyrillic': + 'АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ†°Ґ£§•¶І®©™Ђђ≠Ѓѓ∞±≤≥іµґЈЄєЇїЉљЊњ' + + 'јЅ¬√ƒ≈∆«»… ЋћЌќѕ–—“”‘’÷„ЎўЏџ№Ёёяабвгдежзийклмнопрстуфхцчшщъыьэю', + // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/GAELIC.TXT + 'x-mac-gaelic': + 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØḂ±≤≥ḃĊċḊḋḞḟĠġṀæø' + + 'ṁṖṗɼƒſṠ«»… ÀÃÕŒœ–—“”‘’ṡẛÿŸṪ€‹›Ŷŷṫ·Ỳỳ⁊ÂÊÁËÈÍÎÏÌÓÔ♣ÒÚÛÙıÝýŴŵẄẅẀẁẂẃ', + // Python: 'mac_greek' + 'x-mac-greek': + 'Ĺ²É³ÖÜ΅àâä΄¨çéèê룙î‰ôö¦€ùûü†ΓΔΘΛΞΠß®©ΣΪ§≠°·Α±≤≥¥ΒΕΖΗΙΚΜΦΫΨΩ' + + 'άΝ¬ΟΡ≈Τ«»… ΥΧΆΈœ–―“”‘’÷ΉΊΌΎέήίόΏύαβψδεφγηιξκλμνοπώρστθωςχυζϊϋΐΰ\u00AD', + // Python: 'mac_iceland' + 'x-mac-icelandic': + 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûüݰ¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' + + '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€ÐðÞþý·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ', + // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/INUIT.TXT + 'x-mac-inuit': + 'ᐃᐄᐅᐆᐊᐋᐱᐲᐳᐴᐸᐹᑉᑎᑏᑐᑑᑕᑖᑦᑭᑮᑯᑰᑲᑳᒃᒋᒌᒍᒎᒐᒑ°ᒡᒥᒦ•¶ᒧ®©™ᒨᒪᒫᒻᓂᓃᓄᓅᓇᓈᓐᓯᓰᓱᓲᓴᓵᔅᓕᓖᓗ' + + 'ᓘᓚᓛᓪᔨᔩᔪᔫᔭ… ᔮᔾᕕᕖᕗ–—“”‘’ᕘᕙᕚᕝᕆᕇᕈᕉᕋᕌᕐᕿᖀᖁᖂᖃᖄᖅᖏᖐᖑᖒᖓᖔᖕᙱᙲᙳᙴᙵᙶᖖᖠᖡᖢᖣᖤᖥᖦᕼŁł', + // Python: 'mac_latin2' + 'x-mac-ce': + 'ÄĀāÉĄÖÜáąČäčĆć鏟ĎíďĒēĖóėôöõúĚěü†°Ę£§•¶ß®©™ę¨≠ģĮįĪ≤≥īĶ∂∑łĻļĽľĹĺŅ' + + 'ņѬ√ńŇ∆«»… ňŐÕőŌ–—“”‘’÷◊ōŔŕŘ‹›řŖŗŠ‚„šŚśÁŤťÍŽžŪÓÔūŮÚůŰűŲųÝýķŻŁżĢˇ', + // Python: 'mac_roman' + macintosh: + 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' + + '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ', + // Python: 'mac_romanian' + 'x-mac-romanian': + 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ĂȘ∞±≤≥¥µ∂∑∏π∫ªºΩăș' + + '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›Țț‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ', + // Python: 'mac_turkish' + 'x-mac-turkish': + 'ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø' + + '¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸĞğİıŞş‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙˆ˜¯˘˙˚¸˝˛ˇ' + }; + + /** + * Decodes an old-style Macintosh string. Returns either a Unicode JavaScript + * string, or 'undefined' if the encoding is unsupported. For example, we do + * not support Chinese, Japanese or Korean because these would need large + * mapping tables. + * @param {DataView} dataView + * @param {number} offset + * @param {number} dataLength + * @param {string} encoding + * @returns {string} + */ + decode.MACSTRING = function(dataView, offset, dataLength, encoding) { + var table = eightBitMacEncodings[encoding]; + if (table === undefined) { + return undefined; + } + + var result = ''; + for (var i = 0; i < dataLength; i++) { + var c = dataView.getUint8(offset + i); + // In all eight-bit Mac encodings, the characters 0x00..0x7F are + // mapped to U+0000..U+007F; we only need to look up the others. + if (c <= 0x7f) { + result += String.fromCharCode(c); + } else { + result += table[c & 0x7f]; + } + } + + return result; + }; + + // Helper function for encode.MACSTRING. Returns a dictionary for mapping + // Unicode character codes to their 8-bit MacOS equivalent. This table + // is not exactly a super cheap data structure, but we do not care because + // encoding Macintosh strings is only rarely needed in typical applications. + var macEncodingTableCache = typeof WeakMap === 'function' && new WeakMap(); + var macEncodingCacheKeys; + var getMacEncodingTable = function(encoding) { + // Since we use encoding as a cache key for WeakMap, it has to be + // a String object and not a literal. And at least on NodeJS 2.10.1, + // WeakMap requires that the same String instance is passed for cache hits. + if (!macEncodingCacheKeys) { + macEncodingCacheKeys = {}; + for (var e in eightBitMacEncodings) { + /*jshint -W053 */ // Suppress "Do not use String as a constructor." + macEncodingCacheKeys[e] = new String(e); + } + } + + var cacheKey = macEncodingCacheKeys[encoding]; + if (cacheKey === undefined) { + return undefined; + } + + // We can't do "if (cache.has(key)) {return cache.get(key)}" here: + // since garbage collection may run at any time, it could also kick in + // between the calls to cache.has() and cache.get(). In that case, + // we would return 'undefined' even though we do support the encoding. + if (macEncodingTableCache) { + var cachedTable = macEncodingTableCache.get(cacheKey); + if (cachedTable !== undefined) { + return cachedTable; + } + } + + var decodingTable = eightBitMacEncodings[encoding]; + if (decodingTable === undefined) { + return undefined; + } + + var encodingTable = {}; + for (var i = 0; i < decodingTable.length; i++) { + encodingTable[decodingTable.charCodeAt(i)] = i + 0x80; + } + + if (macEncodingTableCache) { + macEncodingTableCache.set(cacheKey, encodingTable); + } + + return encodingTable; + }; + + /** + * Encodes an old-style Macintosh string. Returns a byte array upon success. + * If the requested encoding is unsupported, or if the input string contains + * a character that cannot be expressed in the encoding, the function returns + * 'undefined'. + * @param {string} str + * @param {string} encoding + * @returns {Array} + */ + encode.MACSTRING = function(str, encoding) { + var table = getMacEncodingTable(encoding); + if (table === undefined) { + return undefined; + } + + var result = []; + for (var i = 0; i < str.length; i++) { + var c = str.charCodeAt(i); + + // In all eight-bit Mac encodings, the characters 0x00..0x7F are + // mapped to U+0000..U+007F; we only need to look up the others. + if (c >= 0x80) { + c = table[c]; + if (c === undefined) { + // str contains a Unicode character that cannot be encoded + // in the requested encoding. + return undefined; + } + } + result[i] = c; + // result.push(c); + } + + return result; + }; + + /** + * @param {string} str + * @param {string} encoding + * @returns {number} + */ + sizeOf.MACSTRING = function(str, encoding) { + var b = encode.MACSTRING(str, encoding); + if (b !== undefined) { + return b.length; + } else { + return 0; + } + }; + + // Helper for encode.VARDELTAS + function isByteEncodable(value) { + return value >= -128 && value <= 127; + } + + // Helper for encode.VARDELTAS + function encodeVarDeltaRunAsZeroes(deltas, pos, result) { + var runLength = 0; + var numDeltas = deltas.length; + while (pos < numDeltas && runLength < 64 && deltas[pos] === 0) { + ++pos; + ++runLength; + } + result.push(0x80 | (runLength - 1)); + return pos; + } + + // Helper for encode.VARDELTAS + function encodeVarDeltaRunAsBytes(deltas, offset, result) { + var runLength = 0; + var numDeltas = deltas.length; + var pos = offset; + while (pos < numDeltas && runLength < 64) { + var value = deltas[pos]; + if (!isByteEncodable(value)) { + break; + } + + // Within a byte-encoded run of deltas, a single zero is best + // stored literally as 0x00 value. However, if we have two or + // more zeroes in a sequence, it is better to start a new run. + // Fore example, the sequence of deltas [15, 15, 0, 15, 15] + // becomes 6 bytes (04 0F 0F 00 0F 0F) when storing the zero + // within the current run, but 7 bytes (01 0F 0F 80 01 0F 0F) + // when starting a new run. + if (value === 0 && pos + 1 < numDeltas && deltas[pos + 1] === 0) { + break; + } + + ++pos; + ++runLength; + } + result.push(runLength - 1); + for (var i = offset; i < pos; ++i) { + result.push((deltas[i] + 256) & 0xff); + } + return pos; + } + + // Helper for encode.VARDELTAS + function encodeVarDeltaRunAsWords(deltas, offset, result) { + var runLength = 0; + var numDeltas = deltas.length; + var pos = offset; + while (pos < numDeltas && runLength < 64) { + var value = deltas[pos]; + + // Within a word-encoded run of deltas, it is easiest to start + // a new run (with a different encoding) whenever we encounter + // a zero value. For example, the sequence [0x6666, 0, 0x7777] + // needs 7 bytes when storing the zero inside the current run + // (42 66 66 00 00 77 77), and equally 7 bytes when starting a + // new run (40 66 66 80 40 77 77). + if (value === 0) { + break; + } + + // Within a word-encoded run of deltas, a single value in the + // range (-128..127) should be encoded within the current run + // because it is more compact. For example, the sequence + // [0x6666, 2, 0x7777] becomes 7 bytes when storing the value + // literally (42 66 66 00 02 77 77), but 8 bytes when starting + // a new run (40 66 66 00 02 40 77 77). + if ( + isByteEncodable(value) && + pos + 1 < numDeltas && + isByteEncodable(deltas[pos + 1]) + ) { + break; + } + + ++pos; + ++runLength; + } + result.push(0x40 | (runLength - 1)); + for (var i = offset; i < pos; ++i) { + var val = deltas[i]; + result.push(((val + 0x10000) >> 8) & 0xff, (val + 0x100) & 0xff); + } + return pos; + } + + /** + * Encode a list of variation adjustment deltas. + * + * Variation adjustment deltas are used in ‘gvar’ and ‘cvar’ tables. + * They indicate how points (in ‘gvar’) or values (in ‘cvar’) get adjusted + * when generating instances of variation fonts. + * + * @see https://www.microsoft.com/typography/otspec/gvar.htm + * @see https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gvar.html + * @param {Array} + * @return {Array} + */ + encode.VARDELTAS = function(deltas) { + var pos = 0; + var result = []; + while (pos < deltas.length) { + var value = deltas[pos]; + if (value === 0) { + pos = encodeVarDeltaRunAsZeroes(deltas, pos, result); + } else if (value >= -128 && value <= 127) { + pos = encodeVarDeltaRunAsBytes(deltas, pos, result); + } else { + pos = encodeVarDeltaRunAsWords(deltas, pos, result); + } + } + return result; + }; + + // Convert a list of values to a CFF INDEX structure. + // The values should be objects containing name / type / value. + /** + * @param {Array} l + * @returns {Array} + */ + encode.INDEX = function(l) { + //var offset, offsets, offsetEncoder, encodedOffsets, encodedOffset, data, + // i, v; + // Because we have to know which data type to use to encode the offsets, + // we have to go through the values twice: once to encode the data and + // calculate the offsets, then again to encode the offsets using the fitting data type. + var offset = 1; // First offset is always 1. + var offsets = [offset]; + var data = []; + for (var i = 0; i < l.length; i += 1) { + var v = encode.OBJECT(l[i]); + Array.prototype.push.apply(data, v); + offset += v.length; + offsets.push(offset); + } + + if (data.length === 0) { + return [0, 0]; + } + + var encodedOffsets = []; + var offSize = (1 + Math.floor(Math.log(offset) / Math.log(2)) / 8) | 0; + var offsetEncoder = [ + undefined, + encode.BYTE, + encode.USHORT, + encode.UINT24, + encode.ULONG + ][offSize]; + for (var i$1 = 0; i$1 < offsets.length; i$1 += 1) { + var encodedOffset = offsetEncoder(offsets[i$1]); + Array.prototype.push.apply(encodedOffsets, encodedOffset); + } + + return Array.prototype.concat( + encode.Card16(l.length), + encode.OffSize(offSize), + encodedOffsets, + data + ); + }; + + /** + * @param {Array} + * @returns {number} + */ + sizeOf.INDEX = function(v) { + return encode.INDEX(v).length; + }; + + /** + * Convert an object to a CFF DICT structure. + * The keys should be numeric. + * The values should be objects containing name / type / value. + * @param {Object} m + * @returns {Array} + */ + encode.DICT = function(m) { + var d = []; + var keys = Object.keys(m); + var length = keys.length; + + for (var i = 0; i < length; i += 1) { + // Object.keys() return string keys, but our keys are always numeric. + var k = parseInt(keys[i], 0); + var v = m[k]; + // Value comes before the key. + d = d.concat(encode.OPERAND(v.value, v.type)); + d = d.concat(encode.OPERATOR(k)); + } + + return d; + }; + + /** + * @param {Object} + * @returns {number} + */ + sizeOf.DICT = function(m) { + return encode.DICT(m).length; + }; + + /** + * @param {number} + * @returns {Array} + */ + encode.OPERATOR = function(v) { + if (v < 1200) { + return [v]; + } else { + return [12, v - 1200]; + } + }; + + /** + * @param {Array} v + * @param {string} + * @returns {Array} + */ + encode.OPERAND = function(v, type) { + var d = []; + if (Array.isArray(type)) { + for (var i = 0; i < type.length; i += 1) { + check.argument( + v.length === type.length, + 'Not enough arguments given for type' + type + ); + d = d.concat(encode.OPERAND(v[i], type[i])); + } + } else { + if (type === 'SID') { + d = d.concat(encode.NUMBER(v)); + } else if (type === 'offset') { + // We make it easy for ourselves and always encode offsets as + // 4 bytes. This makes offset calculation for the top dict easier. + d = d.concat(encode.NUMBER32(v)); + } else if (type === 'number') { + d = d.concat(encode.NUMBER(v)); + } else if (type === 'real') { + d = d.concat(encode.REAL(v)); + } else { + throw new Error('Unknown operand type ' + type); + // FIXME Add support for booleans + } + } + + return d; + }; + + encode.OP = encode.BYTE; + sizeOf.OP = sizeOf.BYTE; + + // memoize charstring encoding using WeakMap if available + var wmm = typeof WeakMap === 'function' && new WeakMap(); + + /** + * Convert a list of CharString operations to bytes. + * @param {Array} + * @returns {Array} + */ + encode.CHARSTRING = function(ops) { + // See encode.MACSTRING for why we don't do "if (wmm && wmm.has(ops))". + if (wmm) { + var cachedValue = wmm.get(ops); + if (cachedValue !== undefined) { + return cachedValue; + } + } + + var d = []; + var length = ops.length; + + for (var i = 0; i < length; i += 1) { + var op = ops[i]; + d = d.concat(encode[op.type](op.value)); + } + + if (wmm) { + wmm.set(ops, d); + } + + return d; + }; + + /** + * @param {Array} + * @returns {number} + */ + sizeOf.CHARSTRING = function(ops) { + return encode.CHARSTRING(ops).length; + }; + + // Utility functions //////////////////////////////////////////////////////// + + /** + * Convert an object containing name / type / value to bytes. + * @param {Object} + * @returns {Array} + */ + encode.OBJECT = function(v) { + var encodingFunction = encode[v.type]; + check.argument( + encodingFunction !== undefined, + 'No encoding function for type ' + v.type + ); + return encodingFunction(v.value); + }; + + /** + * @param {Object} + * @returns {number} + */ + sizeOf.OBJECT = function(v) { + var sizeOfFunction = sizeOf[v.type]; + check.argument( + sizeOfFunction !== undefined, + 'No sizeOf function for type ' + v.type + ); + return sizeOfFunction(v.value); + }; + + /** + * Convert a table object to bytes. + * A table contains a list of fields containing the metadata (name, type and default value). + * The table itself has the field values set as attributes. + * @param {opentype.Table} + * @returns {Array} + */ + encode.TABLE = function(table) { + var d = []; + var length = table.fields.length; + var subtables = []; + var subtableOffsets = []; + + for (var i = 0; i < length; i += 1) { + var field = table.fields[i]; + var encodingFunction = encode[field.type]; + check.argument( + encodingFunction !== undefined, + 'No encoding function for field type ' + + field.type + + ' (' + + field.name + + ')' + ); + var value = table[field.name]; + if (value === undefined) { + value = field.value; + } + + var bytes = encodingFunction(value); + + if (field.type === 'TABLE') { + subtableOffsets.push(d.length); + d = d.concat([0, 0]); + subtables.push(bytes); + } else { + d = d.concat(bytes); + } + } + + for (var i$1 = 0; i$1 < subtables.length; i$1 += 1) { + var o = subtableOffsets[i$1]; + var offset = d.length; + check.argument(offset < 65536, 'Table ' + table.tableName + ' too big.'); + d[o] = offset >> 8; + d[o + 1] = offset & 0xff; + d = d.concat(subtables[i$1]); + } + + return d; + }; + + /** + * @param {opentype.Table} + * @returns {number} + */ + sizeOf.TABLE = function(table) { + var numBytes = 0; + var length = table.fields.length; + + for (var i = 0; i < length; i += 1) { + var field = table.fields[i]; + var sizeOfFunction = sizeOf[field.type]; + check.argument( + sizeOfFunction !== undefined, + 'No sizeOf function for field type ' + + field.type + + ' (' + + field.name + + ')' + ); + var value = table[field.name]; + if (value === undefined) { + value = field.value; + } + + numBytes += sizeOfFunction(value); + + // Subtables take 2 more bytes for offsets. + if (field.type === 'TABLE') { + numBytes += 2; + } + } + + return numBytes; + }; + + encode.RECORD = encode.TABLE; + sizeOf.RECORD = sizeOf.TABLE; + + // Merge in a list of bytes. + encode.LITERAL = function(v) { + return v; + }; + + sizeOf.LITERAL = function(v) { + return v.length; + }; + + // Table metadata + + /** + * @exports opentype.Table + * @class + * @param {string} tableName + * @param {Array} fields + * @param {Object} options + * @constructor + */ + function Table(tableName, fields, options) { + var this$1 = this; + + for (var i = 0; i < fields.length; i += 1) { + var field = fields[i]; + this$1[field.name] = field.value; + } + + this.tableName = tableName; + this.fields = fields; + if (options) { + var optionKeys = Object.keys(options); + for (var i$1 = 0; i$1 < optionKeys.length; i$1 += 1) { + var k = optionKeys[i$1]; + var v = options[k]; + if (this$1[k] !== undefined) { + this$1[k] = v; + } + } + } + } + + /** + * Encodes the table and returns an array of bytes + * @return {Array} + */ + Table.prototype.encode = function() { + return encode.TABLE(this); + }; + + /** + * Get the size of the table. + * @return {number} + */ + Table.prototype.sizeOf = function() { + return sizeOf.TABLE(this); + }; + + /** + * @private + */ + function ushortList(itemName, list, count) { + if (count === undefined) { + count = list.length; + } + var fields = new Array(list.length + 1); + fields[0] = { name: itemName + 'Count', type: 'USHORT', value: count }; + for (var i = 0; i < list.length; i++) { + fields[i + 1] = { name: itemName + i, type: 'USHORT', value: list[i] }; + } + return fields; + } + + /** + * @private + */ + function tableList(itemName, records, itemCallback) { + var count = records.length; + var fields = new Array(count + 1); + fields[0] = { name: itemName + 'Count', type: 'USHORT', value: count }; + for (var i = 0; i < count; i++) { + fields[i + 1] = { + name: itemName + i, + type: 'TABLE', + value: itemCallback(records[i], i) + }; + } + return fields; + } + + /** + * @private + */ + function recordList(itemName, records, itemCallback) { + var count = records.length; + var fields = []; + fields[0] = { name: itemName + 'Count', type: 'USHORT', value: count }; + for (var i = 0; i < count; i++) { + fields = fields.concat(itemCallback(records[i], i)); + } + return fields; + } + + // Common Layout Tables + + /** + * @exports opentype.Coverage + * @class + * @param {opentype.Table} + * @constructor + * @extends opentype.Table + */ + function Coverage(coverageTable) { + if (coverageTable.format === 1) { + Table.call( + this, + 'coverageTable', + [{ name: 'coverageFormat', type: 'USHORT', value: 1 }].concat( + ushortList('glyph', coverageTable.glyphs) + ) + ); + } else { + check.assert(false, "Can't create coverage table format 2 yet."); + } + } + Coverage.prototype = Object.create(Table.prototype); + Coverage.prototype.constructor = Coverage; + + function ScriptList(scriptListTable) { + Table.call( + this, + 'scriptListTable', + recordList('scriptRecord', scriptListTable, function(scriptRecord, i) { + var script = scriptRecord.script; + var defaultLangSys = script.defaultLangSys; + check.assert( + !!defaultLangSys, + 'Unable to write GSUB: script ' + + scriptRecord.tag + + ' has no default language system.' + ); + return [ + { name: 'scriptTag' + i, type: 'TAG', value: scriptRecord.tag }, + { + name: 'script' + i, + type: 'TABLE', + value: new Table( + 'scriptTable', + [ + { + name: 'defaultLangSys', + type: 'TABLE', + value: new Table( + 'defaultLangSys', + [ + { name: 'lookupOrder', type: 'USHORT', value: 0 }, + { + name: 'reqFeatureIndex', + type: 'USHORT', + value: defaultLangSys.reqFeatureIndex + } + ].concat( + ushortList('featureIndex', defaultLangSys.featureIndexes) + ) + ) + } + ].concat( + recordList('langSys', script.langSysRecords, function( + langSysRecord, + i + ) { + var langSys = langSysRecord.langSys; + return [ + { + name: 'langSysTag' + i, + type: 'TAG', + value: langSysRecord.tag + }, + { + name: 'langSys' + i, + type: 'TABLE', + value: new Table( + 'langSys', + [ + { name: 'lookupOrder', type: 'USHORT', value: 0 }, + { + name: 'reqFeatureIndex', + type: 'USHORT', + value: langSys.reqFeatureIndex + } + ].concat( + ushortList('featureIndex', langSys.featureIndexes) + ) + ) + } + ]; + }) + ) + ) + } + ]; + }) + ); + } + ScriptList.prototype = Object.create(Table.prototype); + ScriptList.prototype.constructor = ScriptList; + + /** + * @exports opentype.FeatureList + * @class + * @param {opentype.Table} + * @constructor + * @extends opentype.Table + */ + function FeatureList(featureListTable) { + Table.call( + this, + 'featureListTable', + recordList('featureRecord', featureListTable, function(featureRecord, i) { + var feature = featureRecord.feature; + return [ + { name: 'featureTag' + i, type: 'TAG', value: featureRecord.tag }, + { + name: 'feature' + i, + type: 'TABLE', + value: new Table( + 'featureTable', + [ + { + name: 'featureParams', + type: 'USHORT', + value: feature.featureParams + } + ].concat(ushortList('lookupListIndex', feature.lookupListIndexes)) + ) + } + ]; + }) + ); + } + FeatureList.prototype = Object.create(Table.prototype); + FeatureList.prototype.constructor = FeatureList; + + /** + * @exports opentype.LookupList + * @class + * @param {opentype.Table} + * @param {Object} + * @constructor + * @extends opentype.Table + */ + function LookupList(lookupListTable, subtableMakers) { + Table.call( + this, + 'lookupListTable', + tableList('lookup', lookupListTable, function(lookupTable) { + var subtableCallback = subtableMakers[lookupTable.lookupType]; + check.assert( + !!subtableCallback, + 'Unable to write GSUB lookup type ' + + lookupTable.lookupType + + ' tables.' + ); + return new Table( + 'lookupTable', + [ + { + name: 'lookupType', + type: 'USHORT', + value: lookupTable.lookupType + }, + { + name: 'lookupFlag', + type: 'USHORT', + value: lookupTable.lookupFlag + } + ].concat( + tableList('subtable', lookupTable.subtables, subtableCallback) + ) + ); + }) + ); + } + LookupList.prototype = Object.create(Table.prototype); + LookupList.prototype.constructor = LookupList; + + // Record = same as Table, but inlined (a Table has an offset and its data is further in the stream) + // Don't use offsets inside Records (probable bug), only in Tables. + var table = { + Table: Table, + Record: Table, + Coverage: Coverage, + ScriptList: ScriptList, + FeatureList: FeatureList, + LookupList: LookupList, + ushortList: ushortList, + tableList: tableList, + recordList: recordList + }; + + // Parsing utility functions + + // Retrieve an unsigned byte from the DataView. + function getByte(dataView, offset) { + return dataView.getUint8(offset); + } + + // Retrieve an unsigned 16-bit short from the DataView. + // The value is stored in big endian. + function getUShort(dataView, offset) { + return dataView.getUint16(offset, false); + } + + // Retrieve a signed 16-bit short from the DataView. + // The value is stored in big endian. + function getShort(dataView, offset) { + return dataView.getInt16(offset, false); + } + + // Retrieve an unsigned 32-bit long from the DataView. + // The value is stored in big endian. + function getULong(dataView, offset) { + return dataView.getUint32(offset, false); + } + + // Retrieve a 32-bit signed fixed-point number (16.16) from the DataView. + // The value is stored in big endian. + function getFixed(dataView, offset) { + var decimal = dataView.getInt16(offset, false); + var fraction = dataView.getUint16(offset + 2, false); + return decimal + fraction / 65535; + } + + // Retrieve a 4-character tag from the DataView. + // Tags are used to identify tables. + function getTag(dataView, offset) { + var tag = ''; + for (var i = offset; i < offset + 4; i += 1) { + tag += String.fromCharCode(dataView.getInt8(i)); + } + + return tag; + } + + // Retrieve an offset from the DataView. + // Offsets are 1 to 4 bytes in length, depending on the offSize argument. + function getOffset(dataView, offset, offSize) { + var v = 0; + for (var i = 0; i < offSize; i += 1) { + v <<= 8; + v += dataView.getUint8(offset + i); + } + + return v; + } + + // Retrieve a number of bytes from start offset to the end offset from the DataView. + function getBytes(dataView, startOffset, endOffset) { + var bytes = []; + for (var i = startOffset; i < endOffset; i += 1) { + bytes.push(dataView.getUint8(i)); + } + + return bytes; + } + + // Convert the list of bytes to a string. + function bytesToString(bytes) { + var s = ''; + for (var i = 0; i < bytes.length; i += 1) { + s += String.fromCharCode(bytes[i]); + } + + return s; + } + + var typeOffsets = { + byte: 1, + uShort: 2, + short: 2, + uLong: 4, + fixed: 4, + longDateTime: 8, + tag: 4 + }; + + // A stateful parser that changes the offset whenever a value is retrieved. + // The data is a DataView. + function Parser(data, offset) { + this.data = data; + this.offset = offset; + this.relativeOffset = 0; + } + + Parser.prototype.parseByte = function() { + var v = this.data.getUint8(this.offset + this.relativeOffset); + this.relativeOffset += 1; + return v; + }; + + Parser.prototype.parseChar = function() { + var v = this.data.getInt8(this.offset + this.relativeOffset); + this.relativeOffset += 1; + return v; + }; + + Parser.prototype.parseCard8 = Parser.prototype.parseByte; + + Parser.prototype.parseUShort = function() { + var v = this.data.getUint16(this.offset + this.relativeOffset); + this.relativeOffset += 2; + return v; + }; + + Parser.prototype.parseCard16 = Parser.prototype.parseUShort; + Parser.prototype.parseSID = Parser.prototype.parseUShort; + Parser.prototype.parseOffset16 = Parser.prototype.parseUShort; + + Parser.prototype.parseShort = function() { + var v = this.data.getInt16(this.offset + this.relativeOffset); + this.relativeOffset += 2; + return v; + }; + + Parser.prototype.parseF2Dot14 = function() { + var v = this.data.getInt16(this.offset + this.relativeOffset) / 16384; + this.relativeOffset += 2; + return v; + }; + + Parser.prototype.parseULong = function() { + var v = getULong(this.data, this.offset + this.relativeOffset); + this.relativeOffset += 4; + return v; + }; + + Parser.prototype.parseOffset32 = Parser.prototype.parseULong; + + Parser.prototype.parseFixed = function() { + var v = getFixed(this.data, this.offset + this.relativeOffset); + this.relativeOffset += 4; + return v; + }; + + Parser.prototype.parseString = function(length) { + var dataView = this.data; + var offset = this.offset + this.relativeOffset; + var string = ''; + this.relativeOffset += length; + for (var i = 0; i < length; i++) { + string += String.fromCharCode(dataView.getUint8(offset + i)); + } + + return string; + }; + + Parser.prototype.parseTag = function() { + return this.parseString(4); + }; + + // LONGDATETIME is a 64-bit integer. + // JavaScript and unix timestamps traditionally use 32 bits, so we + // only take the last 32 bits. + // + Since until 2038 those bits will be filled by zeros we can ignore them. + Parser.prototype.parseLongDateTime = function() { + var v = getULong(this.data, this.offset + this.relativeOffset + 4); + // Subtract seconds between 01/01/1904 and 01/01/1970 + // to convert Apple Mac timestamp to Standard Unix timestamp + v -= 2082844800; + this.relativeOffset += 8; + return v; + }; + + Parser.prototype.parseVersion = function(minorBase) { + var major = getUShort(this.data, this.offset + this.relativeOffset); + + // How to interpret the minor version is very vague in the spec. 0x5000 is 5, 0x1000 is 1 + // Default returns the correct number if minor = 0xN000 where N is 0-9 + // Set minorBase to 1 for tables that use minor = N where N is 0-9 + var minor = getUShort(this.data, this.offset + this.relativeOffset + 2); + this.relativeOffset += 4; + if (minorBase === undefined) { + minorBase = 0x1000; + } + return major + minor / minorBase / 10; + }; + + Parser.prototype.skip = function(type, amount) { + if (amount === undefined) { + amount = 1; + } + + this.relativeOffset += typeOffsets[type] * amount; + }; + + ///// Parsing lists and records /////////////////////////////// + + // Parse a list of 32 bit unsigned integers. + Parser.prototype.parseULongList = function(count) { + if (count === undefined) { + count = this.parseULong(); + } + var offsets = new Array(count); + var dataView = this.data; + var offset = this.offset + this.relativeOffset; + for (var i = 0; i < count; i++) { + offsets[i] = dataView.getUint32(offset); + offset += 4; + } + + this.relativeOffset += count * 4; + return offsets; + }; + + // Parse a list of 16 bit unsigned integers. The length of the list can be read on the stream + // or provided as an argument. + Parser.prototype.parseOffset16List = Parser.prototype.parseUShortList = function( + count + ) { + if (count === undefined) { + count = this.parseUShort(); + } + var offsets = new Array(count); + var dataView = this.data; + var offset = this.offset + this.relativeOffset; + for (var i = 0; i < count; i++) { + offsets[i] = dataView.getUint16(offset); + offset += 2; + } + + this.relativeOffset += count * 2; + return offsets; + }; + + // Parses a list of 16 bit signed integers. + Parser.prototype.parseShortList = function(count) { + var list = new Array(count); + var dataView = this.data; + var offset = this.offset + this.relativeOffset; + for (var i = 0; i < count; i++) { + list[i] = dataView.getInt16(offset); + offset += 2; + } + + this.relativeOffset += count * 2; + return list; + }; + + // Parses a list of bytes. + Parser.prototype.parseByteList = function(count) { + var list = new Array(count); + var dataView = this.data; + var offset = this.offset + this.relativeOffset; + for (var i = 0; i < count; i++) { + list[i] = dataView.getUint8(offset++); + } + + this.relativeOffset += count; + return list; + }; + + /** + * Parse a list of items. + * Record count is optional, if omitted it is read from the stream. + * itemCallback is one of the Parser methods. + */ + Parser.prototype.parseList = function(count, itemCallback) { + var this$1 = this; + + if (!itemCallback) { + itemCallback = count; + count = this.parseUShort(); + } + var list = new Array(count); + for (var i = 0; i < count; i++) { + list[i] = itemCallback.call(this$1); + } + return list; + }; + + Parser.prototype.parseList32 = function(count, itemCallback) { + var this$1 = this; + + if (!itemCallback) { + itemCallback = count; + count = this.parseULong(); + } + var list = new Array(count); + for (var i = 0; i < count; i++) { + list[i] = itemCallback.call(this$1); + } + return list; + }; + + /** + * Parse a list of records. + * Record count is optional, if omitted it is read from the stream. + * Example of recordDescription: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort } + */ + Parser.prototype.parseRecordList = function(count, recordDescription) { + var this$1 = this; + + // If the count argument is absent, read it in the stream. + if (!recordDescription) { + recordDescription = count; + count = this.parseUShort(); + } + var records = new Array(count); + var fields = Object.keys(recordDescription); + for (var i = 0; i < count; i++) { + var rec = {}; + for (var j = 0; j < fields.length; j++) { + var fieldName = fields[j]; + var fieldType = recordDescription[fieldName]; + rec[fieldName] = fieldType.call(this$1); + } + records[i] = rec; + } + return records; + }; + + Parser.prototype.parseRecordList32 = function(count, recordDescription) { + var this$1 = this; + + // If the count argument is absent, read it in the stream. + if (!recordDescription) { + recordDescription = count; + count = this.parseULong(); + } + var records = new Array(count); + var fields = Object.keys(recordDescription); + for (var i = 0; i < count; i++) { + var rec = {}; + for (var j = 0; j < fields.length; j++) { + var fieldName = fields[j]; + var fieldType = recordDescription[fieldName]; + rec[fieldName] = fieldType.call(this$1); + } + records[i] = rec; + } + return records; + }; + + // Parse a data structure into an object + // Example of description: { sequenceIndex: Parser.uShort, lookupListIndex: Parser.uShort } + Parser.prototype.parseStruct = function(description) { + var this$1 = this; + + if (typeof description === 'function') { + return description.call(this); + } else { + var fields = Object.keys(description); + var struct = {}; + for (var j = 0; j < fields.length; j++) { + var fieldName = fields[j]; + var fieldType = description[fieldName]; + struct[fieldName] = fieldType.call(this$1); + } + return struct; + } + }; + + /** + * Parse a GPOS valueRecord + * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record + * valueFormat is optional, if omitted it is read from the stream. + */ + Parser.prototype.parseValueRecord = function(valueFormat) { + if (valueFormat === undefined) { + valueFormat = this.parseUShort(); + } + if (valueFormat === 0) { + // valueFormat2 in kerning pairs is most often 0 + // in this case return undefined instead of an empty object, to save space + return; + } + var valueRecord = {}; + + if (valueFormat & 0x0001) { + valueRecord.xPlacement = this.parseShort(); + } + if (valueFormat & 0x0002) { + valueRecord.yPlacement = this.parseShort(); + } + if (valueFormat & 0x0004) { + valueRecord.xAdvance = this.parseShort(); + } + if (valueFormat & 0x0008) { + valueRecord.yAdvance = this.parseShort(); + } + + // Device table (non-variable font) / VariationIndex table (variable font) not supported + // https://docs.microsoft.com/fr-fr/typography/opentype/spec/chapter2#devVarIdxTbls + if (valueFormat & 0x0010) { + valueRecord.xPlaDevice = undefined; + this.parseShort(); + } + if (valueFormat & 0x0020) { + valueRecord.yPlaDevice = undefined; + this.parseShort(); + } + if (valueFormat & 0x0040) { + valueRecord.xAdvDevice = undefined; + this.parseShort(); + } + if (valueFormat & 0x0080) { + valueRecord.yAdvDevice = undefined; + this.parseShort(); + } + + return valueRecord; + }; + + /** + * Parse a list of GPOS valueRecords + * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#value-record + * valueFormat and valueCount are read from the stream. + */ + Parser.prototype.parseValueRecordList = function() { + var this$1 = this; + + var valueFormat = this.parseUShort(); + var valueCount = this.parseUShort(); + var values = new Array(valueCount); + for (var i = 0; i < valueCount; i++) { + values[i] = this$1.parseValueRecord(valueFormat); + } + return values; + }; + + Parser.prototype.parsePointer = function(description) { + var structOffset = this.parseOffset16(); + if (structOffset > 0) { + // NULL offset => return undefined + return new Parser(this.data, this.offset + structOffset).parseStruct( + description + ); + } + return undefined; + }; + + Parser.prototype.parsePointer32 = function(description) { + var structOffset = this.parseOffset32(); + if (structOffset > 0) { + // NULL offset => return undefined + return new Parser(this.data, this.offset + structOffset).parseStruct( + description + ); + } + return undefined; + }; + + /** + * Parse a list of offsets to lists of 16-bit integers, + * or a list of offsets to lists of offsets to any kind of items. + * If itemCallback is not provided, a list of list of UShort is assumed. + * If provided, itemCallback is called on each item and must parse the item. + * See examples in tables/gsub.js + */ + Parser.prototype.parseListOfLists = function(itemCallback) { + var this$1 = this; + + var offsets = this.parseOffset16List(); + var count = offsets.length; + var relativeOffset = this.relativeOffset; + var list = new Array(count); + for (var i = 0; i < count; i++) { + var start = offsets[i]; + if (start === 0) { + // NULL offset + // Add i as owned property to list. Convenient with assert. + list[i] = undefined; + continue; + } + this$1.relativeOffset = start; + if (itemCallback) { + var subOffsets = this$1.parseOffset16List(); + var subList = new Array(subOffsets.length); + for (var j = 0; j < subOffsets.length; j++) { + this$1.relativeOffset = start + subOffsets[j]; + subList[j] = itemCallback.call(this$1); + } + list[i] = subList; + } else { + list[i] = this$1.parseUShortList(); + } + } + this.relativeOffset = relativeOffset; + return list; + }; + + ///// Complex tables parsing ////////////////////////////////// + + // Parse a coverage table in a GSUB, GPOS or GDEF table. + // https://www.microsoft.com/typography/OTSPEC/chapter2.htm + // parser.offset must point to the start of the table containing the coverage. + Parser.prototype.parseCoverage = function() { + var this$1 = this; + + var startOffset = this.offset + this.relativeOffset; + var format = this.parseUShort(); + var count = this.parseUShort(); + if (format === 1) { + return { + format: 1, + glyphs: this.parseUShortList(count) + }; + } else if (format === 2) { + var ranges = new Array(count); + for (var i = 0; i < count; i++) { + ranges[i] = { + start: this$1.parseUShort(), + end: this$1.parseUShort(), + index: this$1.parseUShort() + }; + } + return { + format: 2, + ranges: ranges + }; + } + throw new Error( + '0x' + startOffset.toString(16) + ': Coverage format must be 1 or 2.' + ); + }; + + // Parse a Class Definition Table in a GSUB, GPOS or GDEF table. + // https://www.microsoft.com/typography/OTSPEC/chapter2.htm + Parser.prototype.parseClassDef = function() { + var startOffset = this.offset + this.relativeOffset; + var format = this.parseUShort(); + if (format === 1) { + return { + format: 1, + startGlyph: this.parseUShort(), + classes: this.parseUShortList() + }; + } else if (format === 2) { + return { + format: 2, + ranges: this.parseRecordList({ + start: Parser.uShort, + end: Parser.uShort, + classId: Parser.uShort + }) + }; + } + throw new Error( + '0x' + startOffset.toString(16) + ': ClassDef format must be 1 or 2.' + ); + }; + + ///// Static methods /////////////////////////////////// + // These convenience methods can be used as callbacks and should be called with "this" context set to a Parser instance. + + Parser.list = function(count, itemCallback) { + return function() { + return this.parseList(count, itemCallback); + }; + }; + + Parser.list32 = function(count, itemCallback) { + return function() { + return this.parseList32(count, itemCallback); + }; + }; + + Parser.recordList = function(count, recordDescription) { + return function() { + return this.parseRecordList(count, recordDescription); + }; + }; + + Parser.recordList32 = function(count, recordDescription) { + return function() { + return this.parseRecordList32(count, recordDescription); + }; + }; + + Parser.pointer = function(description) { + return function() { + return this.parsePointer(description); + }; + }; + + Parser.pointer32 = function(description) { + return function() { + return this.parsePointer32(description); + }; + }; + + Parser.tag = Parser.prototype.parseTag; + Parser.byte = Parser.prototype.parseByte; + Parser.uShort = Parser.offset16 = Parser.prototype.parseUShort; + Parser.uShortList = Parser.prototype.parseUShortList; + Parser.uLong = Parser.offset32 = Parser.prototype.parseULong; + Parser.uLongList = Parser.prototype.parseULongList; + Parser.struct = Parser.prototype.parseStruct; + Parser.coverage = Parser.prototype.parseCoverage; + Parser.classDef = Parser.prototype.parseClassDef; + + ///// Script, Feature, Lookup lists /////////////////////////////////////////////// + // https://www.microsoft.com/typography/OTSPEC/chapter2.htm + + var langSysTable = { + reserved: Parser.uShort, + reqFeatureIndex: Parser.uShort, + featureIndexes: Parser.uShortList + }; + + Parser.prototype.parseScriptList = function() { + return ( + this.parsePointer( + Parser.recordList({ + tag: Parser.tag, + script: Parser.pointer({ + defaultLangSys: Parser.pointer(langSysTable), + langSysRecords: Parser.recordList({ + tag: Parser.tag, + langSys: Parser.pointer(langSysTable) + }) + }) + }) + ) || [] + ); + }; + + Parser.prototype.parseFeatureList = function() { + return ( + this.parsePointer( + Parser.recordList({ + tag: Parser.tag, + feature: Parser.pointer({ + featureParams: Parser.offset16, + lookupListIndexes: Parser.uShortList + }) + }) + ) || [] + ); + }; + + Parser.prototype.parseLookupList = function(lookupTableParsers) { + return ( + this.parsePointer( + Parser.list( + Parser.pointer(function() { + var lookupType = this.parseUShort(); + check.argument( + 1 <= lookupType && lookupType <= 9, + 'GPOS/GSUB lookup type ' + lookupType + ' unknown.' + ); + var lookupFlag = this.parseUShort(); + var useMarkFilteringSet = lookupFlag & 0x10; + return { + lookupType: lookupType, + lookupFlag: lookupFlag, + subtables: this.parseList( + Parser.pointer(lookupTableParsers[lookupType]) + ), + markFilteringSet: useMarkFilteringSet + ? this.parseUShort() + : undefined + }; + }) + ) + ) || [] + ); + }; + + Parser.prototype.parseFeatureVariationsList = function() { + return ( + this.parsePointer32(function() { + var majorVersion = this.parseUShort(); + var minorVersion = this.parseUShort(); + check.argument( + majorVersion === 1 && minorVersion < 1, + 'GPOS/GSUB feature variations table unknown.' + ); + var featureVariations = this.parseRecordList32({ + conditionSetOffset: Parser.offset32, + featureTableSubstitutionOffset: Parser.offset32 + }); + return featureVariations; + }) || [] + ); + }; + + var parse = { + getByte: getByte, + getCard8: getByte, + getUShort: getUShort, + getCard16: getUShort, + getShort: getShort, + getULong: getULong, + getFixed: getFixed, + getTag: getTag, + getOffset: getOffset, + getBytes: getBytes, + bytesToString: bytesToString, + Parser: Parser + }; + + // The `cmap` table stores the mappings from characters to glyphs. + + function parseCmapTableFormat12(cmap, p) { + //Skip reserved. + p.parseUShort(); + + // Length in bytes of the sub-tables. + cmap.length = p.parseULong(); + cmap.language = p.parseULong(); + + var groupCount; + cmap.groupCount = groupCount = p.parseULong(); + cmap.glyphIndexMap = {}; + + for (var i = 0; i < groupCount; i += 1) { + var startCharCode = p.parseULong(); + var endCharCode = p.parseULong(); + var startGlyphId = p.parseULong(); + + for (var c = startCharCode; c <= endCharCode; c += 1) { + cmap.glyphIndexMap[c] = startGlyphId; + startGlyphId++; + } + } + } + + function parseCmapTableFormat4(cmap, p, data, start, offset) { + // Length in bytes of the sub-tables. + cmap.length = p.parseUShort(); + cmap.language = p.parseUShort(); + + // segCount is stored x 2. + var segCount; + cmap.segCount = segCount = p.parseUShort() >> 1; + + // Skip searchRange, entrySelector, rangeShift. + p.skip('uShort', 3); + + // The "unrolled" mapping from character codes to glyph indices. + cmap.glyphIndexMap = {}; + var endCountParser = new parse.Parser(data, start + offset + 14); + var startCountParser = new parse.Parser( + data, + start + offset + 16 + segCount * 2 + ); + var idDeltaParser = new parse.Parser( + data, + start + offset + 16 + segCount * 4 + ); + var idRangeOffsetParser = new parse.Parser( + data, + start + offset + 16 + segCount * 6 + ); + var glyphIndexOffset = start + offset + 16 + segCount * 8; + for (var i = 0; i < segCount - 1; i += 1) { + var glyphIndex = void 0; + var endCount = endCountParser.parseUShort(); + var startCount = startCountParser.parseUShort(); + var idDelta = idDeltaParser.parseShort(); + var idRangeOffset = idRangeOffsetParser.parseUShort(); + for (var c = startCount; c <= endCount; c += 1) { + if (idRangeOffset !== 0) { + // The idRangeOffset is relative to the current position in the idRangeOffset array. + // Take the current offset in the idRangeOffset array. + glyphIndexOffset = + idRangeOffsetParser.offset + idRangeOffsetParser.relativeOffset - 2; + + // Add the value of the idRangeOffset, which will move us into the glyphIndex array. + glyphIndexOffset += idRangeOffset; + + // Then add the character index of the current segment, multiplied by 2 for USHORTs. + glyphIndexOffset += (c - startCount) * 2; + glyphIndex = parse.getUShort(data, glyphIndexOffset); + if (glyphIndex !== 0) { + glyphIndex = (glyphIndex + idDelta) & 0xffff; + } + } else { + glyphIndex = (c + idDelta) & 0xffff; + } + + cmap.glyphIndexMap[c] = glyphIndex; + } + } + } + + // Parse the `cmap` table. This table stores the mappings from characters to glyphs. + // There are many available formats, but we only support the Windows format 4 and 12. + // This function returns a `CmapEncoding` object or null if no supported format could be found. + function parseCmapTable(data, start) { + var cmap = {}; + cmap.version = parse.getUShort(data, start); + check.argument(cmap.version === 0, 'cmap table version should be 0.'); + + // The cmap table can contain many sub-tables, each with their own format. + // We're only interested in a "platform 0" (Unicode format) and "platform 3" (Windows format) table. + cmap.numTables = parse.getUShort(data, start + 2); + var offset = -1; + for (var i = cmap.numTables - 1; i >= 0; i -= 1) { + var platformId = parse.getUShort(data, start + 4 + i * 8); + var encodingId = parse.getUShort(data, start + 4 + i * 8 + 2); + if ( + (platformId === 3 && + (encodingId === 0 || encodingId === 1 || encodingId === 10)) || + (platformId === 0 && + (encodingId === 0 || + encodingId === 1 || + encodingId === 2 || + encodingId === 3 || + encodingId === 4)) + ) { + offset = parse.getULong(data, start + 4 + i * 8 + 4); + break; + } + } + + if (offset === -1) { + // There is no cmap table in the font that we support. + throw new Error('No valid cmap sub-tables found.'); + } + + var p = new parse.Parser(data, start + offset); + cmap.format = p.parseUShort(); + + if (cmap.format === 12) { + parseCmapTableFormat12(cmap, p); + } else if (cmap.format === 4) { + parseCmapTableFormat4(cmap, p, data, start, offset); + } else { + throw new Error( + 'Only format 4 and 12 cmap tables are supported (found format ' + + cmap.format + + ').' + ); + } + + return cmap; + } + + function addSegment(t, code, glyphIndex) { + t.segments.push({ + end: code, + start: code, + delta: -(code - glyphIndex), + offset: 0, + glyphIndex: glyphIndex + }); + } + + function addTerminatorSegment(t) { + t.segments.push({ + end: 0xffff, + start: 0xffff, + delta: 1, + offset: 0 + }); + } + + // Make cmap table, format 4 by default, 12 if needed only + function makeCmapTable(glyphs) { + // Plan 0 is the base Unicode Plan but emojis, for example are on another plan, and needs cmap 12 format (with 32bit) + var isPlan0Only = true; + var i; + + // Check if we need to add cmap format 12 or if format 4 only is fine + for (i = glyphs.length - 1; i > 0; i -= 1) { + var g = glyphs.get(i); + if (g.unicode > 65535) { + console.log('Adding CMAP format 12 (needed!)'); + isPlan0Only = false; + break; + } + } + + var cmapTable = [ + { name: 'version', type: 'USHORT', value: 0 }, + { name: 'numTables', type: 'USHORT', value: isPlan0Only ? 1 : 2 }, + + // CMAP 4 header + { name: 'platformID', type: 'USHORT', value: 3 }, + { name: 'encodingID', type: 'USHORT', value: 1 }, + { name: 'offset', type: 'ULONG', value: isPlan0Only ? 12 : 12 + 8 } + ]; + + if (!isPlan0Only) { + cmapTable = cmapTable.concat([ + // CMAP 12 header + { name: 'cmap12PlatformID', type: 'USHORT', value: 3 }, // We encode only for PlatformID = 3 (Windows) because it is supported everywhere + { name: 'cmap12EncodingID', type: 'USHORT', value: 10 }, + { name: 'cmap12Offset', type: 'ULONG', value: 0 } + ]); + } + + cmapTable = cmapTable.concat([ + // CMAP 4 Subtable + { name: 'format', type: 'USHORT', value: 4 }, + { name: 'cmap4Length', type: 'USHORT', value: 0 }, + { name: 'language', type: 'USHORT', value: 0 }, + { name: 'segCountX2', type: 'USHORT', value: 0 }, + { name: 'searchRange', type: 'USHORT', value: 0 }, + { name: 'entrySelector', type: 'USHORT', value: 0 }, + { name: 'rangeShift', type: 'USHORT', value: 0 } + ]); + + var t = new table.Table('cmap', cmapTable); + + t.segments = []; + for (i = 0; i < glyphs.length; i += 1) { + var glyph = glyphs.get(i); + for (var j = 0; j < glyph.unicodes.length; j += 1) { + addSegment(t, glyph.unicodes[j], i); + } + + t.segments = t.segments.sort(function(a, b) { + return a.start - b.start; + }); + } + + addTerminatorSegment(t); + + var segCount = t.segments.length; + var segCountToRemove = 0; + + // CMAP 4 + // Set up parallel segment arrays. + var endCounts = []; + var startCounts = []; + var idDeltas = []; + var idRangeOffsets = []; + var glyphIds = []; + + // CMAP 12 + var cmap12Groups = []; + + // Reminder this loop is not following the specification at 100% + // The specification -> find suites of characters and make a group + // Here we're doing one group for each letter + // Doing as the spec can save 8 times (or more) space + for (i = 0; i < segCount; i += 1) { + var segment = t.segments[i]; + + // CMAP 4 + if (segment.end <= 65535 && segment.start <= 65535) { + endCounts = endCounts.concat({ + name: 'end_' + i, + type: 'USHORT', + value: segment.end + }); + startCounts = startCounts.concat({ + name: 'start_' + i, + type: 'USHORT', + value: segment.start + }); + idDeltas = idDeltas.concat({ + name: 'idDelta_' + i, + type: 'SHORT', + value: segment.delta + }); + idRangeOffsets = idRangeOffsets.concat({ + name: 'idRangeOffset_' + i, + type: 'USHORT', + value: segment.offset + }); + if (segment.glyphId !== undefined) { + glyphIds = glyphIds.concat({ + name: 'glyph_' + i, + type: 'USHORT', + value: segment.glyphId + }); + } + } else { + // Skip Unicode > 65535 (16bit unsigned max) for CMAP 4, will be added in CMAP 12 + segCountToRemove += 1; + } + + // CMAP 12 + // Skip Terminator Segment + if (!isPlan0Only && segment.glyphIndex !== undefined) { + cmap12Groups = cmap12Groups.concat({ + name: 'cmap12Start_' + i, + type: 'ULONG', + value: segment.start + }); + cmap12Groups = cmap12Groups.concat({ + name: 'cmap12End_' + i, + type: 'ULONG', + value: segment.end + }); + cmap12Groups = cmap12Groups.concat({ + name: 'cmap12Glyph_' + i, + type: 'ULONG', + value: segment.glyphIndex + }); + } + } + + // CMAP 4 Subtable + t.segCountX2 = (segCount - segCountToRemove) * 2; + t.searchRange = + Math.pow( + 2, + Math.floor(Math.log(segCount - segCountToRemove) / Math.log(2)) + ) * 2; + t.entrySelector = Math.log(t.searchRange / 2) / Math.log(2); + t.rangeShift = t.segCountX2 - t.searchRange; + + t.fields = t.fields.concat(endCounts); + t.fields.push({ name: 'reservedPad', type: 'USHORT', value: 0 }); + t.fields = t.fields.concat(startCounts); + t.fields = t.fields.concat(idDeltas); + t.fields = t.fields.concat(idRangeOffsets); + t.fields = t.fields.concat(glyphIds); + + t.cmap4Length = + 14 + // Subtable header + endCounts.length * 2 + + 2 + // reservedPad + startCounts.length * 2 + + idDeltas.length * 2 + + idRangeOffsets.length * 2 + + glyphIds.length * 2; + + if (!isPlan0Only) { + // CMAP 12 Subtable + var cmap12Length = + 16 + // Subtable header + cmap12Groups.length * 4; + + t.cmap12Offset = 12 + 2 * 2 + 4 + t.cmap4Length; + t.fields = t.fields.concat([ + { name: 'cmap12Format', type: 'USHORT', value: 12 }, + { name: 'cmap12Reserved', type: 'USHORT', value: 0 }, + { name: 'cmap12Length', type: 'ULONG', value: cmap12Length }, + { name: 'cmap12Language', type: 'ULONG', value: 0 }, + { name: 'cmap12nGroups', type: 'ULONG', value: cmap12Groups.length / 3 } + ]); + + t.fields = t.fields.concat(cmap12Groups); + } + + return t; + } + + var cmap = { parse: parseCmapTable, make: makeCmapTable }; + + // Glyph encoding + + var cffStandardStrings = [ + '.notdef', + 'space', + 'exclam', + 'quotedbl', + 'numbersign', + 'dollar', + 'percent', + 'ampersand', + 'quoteright', + 'parenleft', + 'parenright', + 'asterisk', + 'plus', + 'comma', + 'hyphen', + 'period', + 'slash', + 'zero', + 'one', + 'two', + 'three', + 'four', + 'five', + 'six', + 'seven', + 'eight', + 'nine', + 'colon', + 'semicolon', + 'less', + 'equal', + 'greater', + 'question', + 'at', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + 'bracketleft', + 'backslash', + 'bracketright', + 'asciicircum', + 'underscore', + 'quoteleft', + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i', + 'j', + 'k', + 'l', + 'm', + 'n', + 'o', + 'p', + 'q', + 'r', + 's', + 't', + 'u', + 'v', + 'w', + 'x', + 'y', + 'z', + 'braceleft', + 'bar', + 'braceright', + 'asciitilde', + 'exclamdown', + 'cent', + 'sterling', + 'fraction', + 'yen', + 'florin', + 'section', + 'currency', + 'quotesingle', + 'quotedblleft', + 'guillemotleft', + 'guilsinglleft', + 'guilsinglright', + 'fi', + 'fl', + 'endash', + 'dagger', + 'daggerdbl', + 'periodcentered', + 'paragraph', + 'bullet', + 'quotesinglbase', + 'quotedblbase', + 'quotedblright', + 'guillemotright', + 'ellipsis', + 'perthousand', + 'questiondown', + 'grave', + 'acute', + 'circumflex', + 'tilde', + 'macron', + 'breve', + 'dotaccent', + 'dieresis', + 'ring', + 'cedilla', + 'hungarumlaut', + 'ogonek', + 'caron', + 'emdash', + 'AE', + 'ordfeminine', + 'Lslash', + 'Oslash', + 'OE', + 'ordmasculine', + 'ae', + 'dotlessi', + 'lslash', + 'oslash', + 'oe', + 'germandbls', + 'onesuperior', + 'logicalnot', + 'mu', + 'trademark', + 'Eth', + 'onehalf', + 'plusminus', + 'Thorn', + 'onequarter', + 'divide', + 'brokenbar', + 'degree', + 'thorn', + 'threequarters', + 'twosuperior', + 'registered', + 'minus', + 'eth', + 'multiply', + 'threesuperior', + 'copyright', + 'Aacute', + 'Acircumflex', + 'Adieresis', + 'Agrave', + 'Aring', + 'Atilde', + 'Ccedilla', + 'Eacute', + 'Ecircumflex', + 'Edieresis', + 'Egrave', + 'Iacute', + 'Icircumflex', + 'Idieresis', + 'Igrave', + 'Ntilde', + 'Oacute', + 'Ocircumflex', + 'Odieresis', + 'Ograve', + 'Otilde', + 'Scaron', + 'Uacute', + 'Ucircumflex', + 'Udieresis', + 'Ugrave', + 'Yacute', + 'Ydieresis', + 'Zcaron', + 'aacute', + 'acircumflex', + 'adieresis', + 'agrave', + 'aring', + 'atilde', + 'ccedilla', + 'eacute', + 'ecircumflex', + 'edieresis', + 'egrave', + 'iacute', + 'icircumflex', + 'idieresis', + 'igrave', + 'ntilde', + 'oacute', + 'ocircumflex', + 'odieresis', + 'ograve', + 'otilde', + 'scaron', + 'uacute', + 'ucircumflex', + 'udieresis', + 'ugrave', + 'yacute', + 'ydieresis', + 'zcaron', + 'exclamsmall', + 'Hungarumlautsmall', + 'dollaroldstyle', + 'dollarsuperior', + 'ampersandsmall', + 'Acutesmall', + 'parenleftsuperior', + 'parenrightsuperior', + '266 ff', + 'onedotenleader', + 'zerooldstyle', + 'oneoldstyle', + 'twooldstyle', + 'threeoldstyle', + 'fouroldstyle', + 'fiveoldstyle', + 'sixoldstyle', + 'sevenoldstyle', + 'eightoldstyle', + 'nineoldstyle', + 'commasuperior', + 'threequartersemdash', + 'periodsuperior', + 'questionsmall', + 'asuperior', + 'bsuperior', + 'centsuperior', + 'dsuperior', + 'esuperior', + 'isuperior', + 'lsuperior', + 'msuperior', + 'nsuperior', + 'osuperior', + 'rsuperior', + 'ssuperior', + 'tsuperior', + 'ff', + 'ffi', + 'ffl', + 'parenleftinferior', + 'parenrightinferior', + 'Circumflexsmall', + 'hyphensuperior', + 'Gravesmall', + 'Asmall', + 'Bsmall', + 'Csmall', + 'Dsmall', + 'Esmall', + 'Fsmall', + 'Gsmall', + 'Hsmall', + 'Ismall', + 'Jsmall', + 'Ksmall', + 'Lsmall', + 'Msmall', + 'Nsmall', + 'Osmall', + 'Psmall', + 'Qsmall', + 'Rsmall', + 'Ssmall', + 'Tsmall', + 'Usmall', + 'Vsmall', + 'Wsmall', + 'Xsmall', + 'Ysmall', + 'Zsmall', + 'colonmonetary', + 'onefitted', + 'rupiah', + 'Tildesmall', + 'exclamdownsmall', + 'centoldstyle', + 'Lslashsmall', + 'Scaronsmall', + 'Zcaronsmall', + 'Dieresissmall', + 'Brevesmall', + 'Caronsmall', + 'Dotaccentsmall', + 'Macronsmall', + 'figuredash', + 'hypheninferior', + 'Ogoneksmall', + 'Ringsmall', + 'Cedillasmall', + 'questiondownsmall', + 'oneeighth', + 'threeeighths', + 'fiveeighths', + 'seveneighths', + 'onethird', + 'twothirds', + 'zerosuperior', + 'foursuperior', + 'fivesuperior', + 'sixsuperior', + 'sevensuperior', + 'eightsuperior', + 'ninesuperior', + 'zeroinferior', + 'oneinferior', + 'twoinferior', + 'threeinferior', + 'fourinferior', + 'fiveinferior', + 'sixinferior', + 'seveninferior', + 'eightinferior', + 'nineinferior', + 'centinferior', + 'dollarinferior', + 'periodinferior', + 'commainferior', + 'Agravesmall', + 'Aacutesmall', + 'Acircumflexsmall', + 'Atildesmall', + 'Adieresissmall', + 'Aringsmall', + 'AEsmall', + 'Ccedillasmall', + 'Egravesmall', + 'Eacutesmall', + 'Ecircumflexsmall', + 'Edieresissmall', + 'Igravesmall', + 'Iacutesmall', + 'Icircumflexsmall', + 'Idieresissmall', + 'Ethsmall', + 'Ntildesmall', + 'Ogravesmall', + 'Oacutesmall', + 'Ocircumflexsmall', + 'Otildesmall', + 'Odieresissmall', + 'OEsmall', + 'Oslashsmall', + 'Ugravesmall', + 'Uacutesmall', + 'Ucircumflexsmall', + 'Udieresissmall', + 'Yacutesmall', + 'Thornsmall', + 'Ydieresissmall', + '001.000', + '001.001', + '001.002', + '001.003', + 'Black', + 'Bold', + 'Book', + 'Light', + 'Medium', + 'Regular', + 'Roman', + 'Semibold' + ]; + + var cffStandardEncoding = [ + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + 'space', + 'exclam', + 'quotedbl', + 'numbersign', + 'dollar', + 'percent', + 'ampersand', + 'quoteright', + 'parenleft', + 'parenright', + 'asterisk', + 'plus', + 'comma', + 'hyphen', + 'period', + 'slash', + 'zero', + 'one', + 'two', + 'three', + 'four', + 'five', + 'six', + 'seven', + 'eight', + 'nine', + 'colon', + 'semicolon', + 'less', + 'equal', + 'greater', + 'question', + 'at', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + 'bracketleft', + 'backslash', + 'bracketright', + 'asciicircum', + 'underscore', + 'quoteleft', + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i', + 'j', + 'k', + 'l', + 'm', + 'n', + 'o', + 'p', + 'q', + 'r', + 's', + 't', + 'u', + 'v', + 'w', + 'x', + 'y', + 'z', + 'braceleft', + 'bar', + 'braceright', + 'asciitilde', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + 'exclamdown', + 'cent', + 'sterling', + 'fraction', + 'yen', + 'florin', + 'section', + 'currency', + 'quotesingle', + 'quotedblleft', + 'guillemotleft', + 'guilsinglleft', + 'guilsinglright', + 'fi', + 'fl', + '', + 'endash', + 'dagger', + 'daggerdbl', + 'periodcentered', + '', + 'paragraph', + 'bullet', + 'quotesinglbase', + 'quotedblbase', + 'quotedblright', + 'guillemotright', + 'ellipsis', + 'perthousand', + '', + 'questiondown', + '', + 'grave', + 'acute', + 'circumflex', + 'tilde', + 'macron', + 'breve', + 'dotaccent', + 'dieresis', + '', + 'ring', + 'cedilla', + '', + 'hungarumlaut', + 'ogonek', + 'caron', + 'emdash', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + 'AE', + '', + 'ordfeminine', + '', + '', + '', + '', + 'Lslash', + 'Oslash', + 'OE', + 'ordmasculine', + '', + '', + '', + '', + '', + 'ae', + '', + '', + '', + 'dotlessi', + '', + '', + 'lslash', + 'oslash', + 'oe', + 'germandbls' + ]; + + var cffExpertEncoding = [ + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + 'space', + 'exclamsmall', + 'Hungarumlautsmall', + '', + 'dollaroldstyle', + 'dollarsuperior', + 'ampersandsmall', + 'Acutesmall', + 'parenleftsuperior', + 'parenrightsuperior', + 'twodotenleader', + 'onedotenleader', + 'comma', + 'hyphen', + 'period', + 'fraction', + 'zerooldstyle', + 'oneoldstyle', + 'twooldstyle', + 'threeoldstyle', + 'fouroldstyle', + 'fiveoldstyle', + 'sixoldstyle', + 'sevenoldstyle', + 'eightoldstyle', + 'nineoldstyle', + 'colon', + 'semicolon', + 'commasuperior', + 'threequartersemdash', + 'periodsuperior', + 'questionsmall', + '', + 'asuperior', + 'bsuperior', + 'centsuperior', + 'dsuperior', + 'esuperior', + '', + '', + 'isuperior', + '', + '', + 'lsuperior', + 'msuperior', + 'nsuperior', + 'osuperior', + '', + '', + 'rsuperior', + 'ssuperior', + 'tsuperior', + '', + 'ff', + 'fi', + 'fl', + 'ffi', + 'ffl', + 'parenleftinferior', + '', + 'parenrightinferior', + 'Circumflexsmall', + 'hyphensuperior', + 'Gravesmall', + 'Asmall', + 'Bsmall', + 'Csmall', + 'Dsmall', + 'Esmall', + 'Fsmall', + 'Gsmall', + 'Hsmall', + 'Ismall', + 'Jsmall', + 'Ksmall', + 'Lsmall', + 'Msmall', + 'Nsmall', + 'Osmall', + 'Psmall', + 'Qsmall', + 'Rsmall', + 'Ssmall', + 'Tsmall', + 'Usmall', + 'Vsmall', + 'Wsmall', + 'Xsmall', + 'Ysmall', + 'Zsmall', + 'colonmonetary', + 'onefitted', + 'rupiah', + 'Tildesmall', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + 'exclamdownsmall', + 'centoldstyle', + 'Lslashsmall', + '', + '', + 'Scaronsmall', + 'Zcaronsmall', + 'Dieresissmall', + 'Brevesmall', + 'Caronsmall', + '', + 'Dotaccentsmall', + '', + '', + 'Macronsmall', + '', + '', + 'figuredash', + 'hypheninferior', + '', + '', + 'Ogoneksmall', + 'Ringsmall', + 'Cedillasmall', + '', + '', + '', + 'onequarter', + 'onehalf', + 'threequarters', + 'questiondownsmall', + 'oneeighth', + 'threeeighths', + 'fiveeighths', + 'seveneighths', + 'onethird', + 'twothirds', + '', + '', + 'zerosuperior', + 'onesuperior', + 'twosuperior', + 'threesuperior', + 'foursuperior', + 'fivesuperior', + 'sixsuperior', + 'sevensuperior', + 'eightsuperior', + 'ninesuperior', + 'zeroinferior', + 'oneinferior', + 'twoinferior', + 'threeinferior', + 'fourinferior', + 'fiveinferior', + 'sixinferior', + 'seveninferior', + 'eightinferior', + 'nineinferior', + 'centinferior', + 'dollarinferior', + 'periodinferior', + 'commainferior', + 'Agravesmall', + 'Aacutesmall', + 'Acircumflexsmall', + 'Atildesmall', + 'Adieresissmall', + 'Aringsmall', + 'AEsmall', + 'Ccedillasmall', + 'Egravesmall', + 'Eacutesmall', + 'Ecircumflexsmall', + 'Edieresissmall', + 'Igravesmall', + 'Iacutesmall', + 'Icircumflexsmall', + 'Idieresissmall', + 'Ethsmall', + 'Ntildesmall', + 'Ogravesmall', + 'Oacutesmall', + 'Ocircumflexsmall', + 'Otildesmall', + 'Odieresissmall', + 'OEsmall', + 'Oslashsmall', + 'Ugravesmall', + 'Uacutesmall', + 'Ucircumflexsmall', + 'Udieresissmall', + 'Yacutesmall', + 'Thornsmall', + 'Ydieresissmall' + ]; + + var standardNames = [ + '.notdef', + '.null', + 'nonmarkingreturn', + 'space', + 'exclam', + 'quotedbl', + 'numbersign', + 'dollar', + 'percent', + 'ampersand', + 'quotesingle', + 'parenleft', + 'parenright', + 'asterisk', + 'plus', + 'comma', + 'hyphen', + 'period', + 'slash', + 'zero', + 'one', + 'two', + 'three', + 'four', + 'five', + 'six', + 'seven', + 'eight', + 'nine', + 'colon', + 'semicolon', + 'less', + 'equal', + 'greater', + 'question', + 'at', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F', + 'G', + 'H', + 'I', + 'J', + 'K', + 'L', + 'M', + 'N', + 'O', + 'P', + 'Q', + 'R', + 'S', + 'T', + 'U', + 'V', + 'W', + 'X', + 'Y', + 'Z', + 'bracketleft', + 'backslash', + 'bracketright', + 'asciicircum', + 'underscore', + 'grave', + 'a', + 'b', + 'c', + 'd', + 'e', + 'f', + 'g', + 'h', + 'i', + 'j', + 'k', + 'l', + 'm', + 'n', + 'o', + 'p', + 'q', + 'r', + 's', + 't', + 'u', + 'v', + 'w', + 'x', + 'y', + 'z', + 'braceleft', + 'bar', + 'braceright', + 'asciitilde', + 'Adieresis', + 'Aring', + 'Ccedilla', + 'Eacute', + 'Ntilde', + 'Odieresis', + 'Udieresis', + 'aacute', + 'agrave', + 'acircumflex', + 'adieresis', + 'atilde', + 'aring', + 'ccedilla', + 'eacute', + 'egrave', + 'ecircumflex', + 'edieresis', + 'iacute', + 'igrave', + 'icircumflex', + 'idieresis', + 'ntilde', + 'oacute', + 'ograve', + 'ocircumflex', + 'odieresis', + 'otilde', + 'uacute', + 'ugrave', + 'ucircumflex', + 'udieresis', + 'dagger', + 'degree', + 'cent', + 'sterling', + 'section', + 'bullet', + 'paragraph', + 'germandbls', + 'registered', + 'copyright', + 'trademark', + 'acute', + 'dieresis', + 'notequal', + 'AE', + 'Oslash', + 'infinity', + 'plusminus', + 'lessequal', + 'greaterequal', + 'yen', + 'mu', + 'partialdiff', + 'summation', + 'product', + 'pi', + 'integral', + 'ordfeminine', + 'ordmasculine', + 'Omega', + 'ae', + 'oslash', + 'questiondown', + 'exclamdown', + 'logicalnot', + 'radical', + 'florin', + 'approxequal', + 'Delta', + 'guillemotleft', + 'guillemotright', + 'ellipsis', + 'nonbreakingspace', + 'Agrave', + 'Atilde', + 'Otilde', + 'OE', + 'oe', + 'endash', + 'emdash', + 'quotedblleft', + 'quotedblright', + 'quoteleft', + 'quoteright', + 'divide', + 'lozenge', + 'ydieresis', + 'Ydieresis', + 'fraction', + 'currency', + 'guilsinglleft', + 'guilsinglright', + 'fi', + 'fl', + 'daggerdbl', + 'periodcentered', + 'quotesinglbase', + 'quotedblbase', + 'perthousand', + 'Acircumflex', + 'Ecircumflex', + 'Aacute', + 'Edieresis', + 'Egrave', + 'Iacute', + 'Icircumflex', + 'Idieresis', + 'Igrave', + 'Oacute', + 'Ocircumflex', + 'apple', + 'Ograve', + 'Uacute', + 'Ucircumflex', + 'Ugrave', + 'dotlessi', + 'circumflex', + 'tilde', + 'macron', + 'breve', + 'dotaccent', + 'ring', + 'cedilla', + 'hungarumlaut', + 'ogonek', + 'caron', + 'Lslash', + 'lslash', + 'Scaron', + 'scaron', + 'Zcaron', + 'zcaron', + 'brokenbar', + 'Eth', + 'eth', + 'Yacute', + 'yacute', + 'Thorn', + 'thorn', + 'minus', + 'multiply', + 'onesuperior', + 'twosuperior', + 'threesuperior', + 'onehalf', + 'onequarter', + 'threequarters', + 'franc', + 'Gbreve', + 'gbreve', + 'Idotaccent', + 'Scedilla', + 'scedilla', + 'Cacute', + 'cacute', + 'Ccaron', + 'ccaron', + 'dcroat' + ]; + + /** + * This is the encoding used for fonts created from scratch. + * It loops through all glyphs and finds the appropriate unicode value. + * Since it's linear time, other encodings will be faster. + * @exports opentype.DefaultEncoding + * @class + * @constructor + * @param {opentype.Font} + */ + function DefaultEncoding(font) { + this.font = font; + } + + DefaultEncoding.prototype.charToGlyphIndex = function(c) { + var code = c.codePointAt(0); + var glyphs = this.font.glyphs; + if (glyphs) { + for (var i = 0; i < glyphs.length; i += 1) { + var glyph = glyphs.get(i); + for (var j = 0; j < glyph.unicodes.length; j += 1) { + if (glyph.unicodes[j] === code) { + return i; + } + } + } + } + return null; + }; + + /** + * @exports opentype.CmapEncoding + * @class + * @constructor + * @param {Object} cmap - a object with the cmap encoded data + */ + function CmapEncoding(cmap) { + this.cmap = cmap; + } + + /** + * @param {string} c - the character + * @return {number} The glyph index. + */ + CmapEncoding.prototype.charToGlyphIndex = function(c) { + return this.cmap.glyphIndexMap[c.codePointAt(0)] || 0; + }; + + /** + * @exports opentype.CffEncoding + * @class + * @constructor + * @param {string} encoding - The encoding + * @param {Array} charset - The character set. + */ + function CffEncoding(encoding, charset) { + this.encoding = encoding; + this.charset = charset; + } + + /** + * @param {string} s - The character + * @return {number} The index. + */ + CffEncoding.prototype.charToGlyphIndex = function(s) { + var code = s.codePointAt(0); + var charName = this.encoding[code]; + return this.charset.indexOf(charName); + }; + + /** + * @exports opentype.GlyphNames + * @class + * @constructor + * @param {Object} post + */ + function GlyphNames(post) { + var this$1 = this; + + switch (post.version) { + case 1: + this.names = standardNames.slice(); + break; + case 2: + this.names = new Array(post.numberOfGlyphs); + for (var i = 0; i < post.numberOfGlyphs; i++) { + if (post.glyphNameIndex[i] < standardNames.length) { + this$1.names[i] = standardNames[post.glyphNameIndex[i]]; + } else { + this$1.names[i] = + post.names[post.glyphNameIndex[i] - standardNames.length]; + } + } + + break; + case 2.5: + this.names = new Array(post.numberOfGlyphs); + for (var i$1 = 0; i$1 < post.numberOfGlyphs; i$1++) { + this$1.names[i$1] = standardNames[i$1 + post.glyphNameIndex[i$1]]; + } + + break; + case 3: + this.names = []; + break; + default: + this.names = []; + break; + } + } + + /** + * Gets the index of a glyph by name. + * @param {string} name - The glyph name + * @return {number} The index + */ + GlyphNames.prototype.nameToGlyphIndex = function(name) { + return this.names.indexOf(name); + }; + + /** + * @param {number} gid + * @return {string} + */ + GlyphNames.prototype.glyphIndexToName = function(gid) { + return this.names[gid]; + }; + + /** + * @alias opentype.addGlyphNames + * @param {opentype.Font} + */ + function addGlyphNames(font) { + var glyph; + var glyphIndexMap = font.tables.cmap.glyphIndexMap; + var charCodes = Object.keys(glyphIndexMap); + + for (var i = 0; i < charCodes.length; i += 1) { + var c = charCodes[i]; + var glyphIndex = glyphIndexMap[c]; + glyph = font.glyphs.get(glyphIndex); + glyph.addUnicode(parseInt(c)); + } + + for (var i$1 = 0; i$1 < font.glyphs.length; i$1 += 1) { + glyph = font.glyphs.get(i$1); + if (font.cffEncoding) { + if (font.isCIDFont) { + glyph.name = 'gid' + i$1; + } else { + glyph.name = font.cffEncoding.charset[i$1]; + } + } else if (font.glyphNames.names) { + glyph.name = font.glyphNames.glyphIndexToName(i$1); + } + } + } + + // Drawing utility functions. + + // Draw a line on the given context from point `x1,y1` to point `x2,y2`. + function line(ctx, x1, y1, x2, y2) { + ctx.beginPath(); + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.stroke(); + } + + var draw = { line: line }; + + // The Glyph object + // import glyf from './tables/glyf' Can't be imported here, because it's a circular dependency + + function getPathDefinition(glyph, path) { + var _path = path || new Path(); + return { + configurable: true, + + get: function() { + if (typeof _path === 'function') { + _path = _path(); + } + + return _path; + }, + + set: function(p) { + _path = p; + } + }; + } + /** + * @typedef GlyphOptions + * @type Object + * @property {string} [name] - The glyph name + * @property {number} [unicode] + * @property {Array} [unicodes] + * @property {number} [xMin] + * @property {number} [yMin] + * @property {number} [xMax] + * @property {number} [yMax] + * @property {number} [advanceWidth] + */ + + // A Glyph is an individual mark that often corresponds to a character. + // Some glyphs, such as ligatures, are a combination of many characters. + // Glyphs are the basic building blocks of a font. + // + // The `Glyph` class contains utility methods for drawing the path and its points. + /** + * @exports opentype.Glyph + * @class + * @param {GlyphOptions} + * @constructor + */ + function Glyph(options) { + // By putting all the code on a prototype function (which is only declared once) + // we reduce the memory requirements for larger fonts by some 2% + this.bindConstructorValues(options); + } + + /** + * @param {GlyphOptions} + */ + Glyph.prototype.bindConstructorValues = function(options) { + this.index = options.index || 0; + + // These three values cannot be deferred for memory optimization: + this.name = options.name || null; + this.unicode = options.unicode || undefined; + this.unicodes = + options.unicodes || options.unicode !== undefined + ? [options.unicode] + : []; + + // But by binding these values only when necessary, we reduce can + // the memory requirements by almost 3% for larger fonts. + if (options.xMin) { + this.xMin = options.xMin; + } + + if (options.yMin) { + this.yMin = options.yMin; + } + + if (options.xMax) { + this.xMax = options.xMax; + } + + if (options.yMax) { + this.yMax = options.yMax; + } + + if (options.advanceWidth) { + this.advanceWidth = options.advanceWidth; + } + + // The path for a glyph is the most memory intensive, and is bound as a value + // with a getter/setter to ensure we actually do path parsing only once the + // path is actually needed by anything. + Object.defineProperty(this, 'path', getPathDefinition(this, options.path)); + }; + + /** + * @param {number} + */ + Glyph.prototype.addUnicode = function(unicode) { + if (this.unicodes.length === 0) { + this.unicode = unicode; + } + + this.unicodes.push(unicode); + }; + + /** + * Calculate the minimum bounding box for this glyph. + * @return {opentype.BoundingBox} + */ + Glyph.prototype.getBoundingBox = function() { + return this.path.getBoundingBox(); + }; + + /** + * Convert the glyph to a Path we can draw on a drawing context. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {Object=} options - xScale, yScale to stretch the glyph. + * @param {opentype.Font} if hinting is to be used, the font + * @return {opentype.Path} + */ + Glyph.prototype.getPath = function(x, y, fontSize, options, font) { + x = x !== undefined ? x : 0; + y = y !== undefined ? y : 0; + fontSize = fontSize !== undefined ? fontSize : 72; + var commands; + var hPoints; + if (!options) { + options = {}; + } + var xScale = options.xScale; + var yScale = options.yScale; + + if (options.hinting && font && font.hinting) { + // in case of hinting, the hinting engine takes care + // of scaling the points (not the path) before hinting. + hPoints = this.path && font.hinting.exec(this, fontSize); + // in case the hinting engine failed hPoints is undefined + // and thus reverts to plain rending + } + + if (hPoints) { + // Call font.hinting.getCommands instead of `glyf.getPath(hPoints).commands` to avoid a circular dependency + commands = font.hinting.getCommands(hPoints); + x = Math.round(x); + y = Math.round(y); + // TODO in case of hinting xyScaling is not yet supported + xScale = yScale = 1; + } else { + commands = this.path.commands; + var scale = 1 / this.path.unitsPerEm * fontSize; + if (xScale === undefined) { + xScale = scale; + } + if (yScale === undefined) { + yScale = scale; + } + } + + var p = new Path(); + for (var i = 0; i < commands.length; i += 1) { + var cmd = commands[i]; + if (cmd.type === 'M') { + p.moveTo(x + cmd.x * xScale, y + -cmd.y * yScale); + } else if (cmd.type === 'L') { + p.lineTo(x + cmd.x * xScale, y + -cmd.y * yScale); + } else if (cmd.type === 'Q') { + p.quadraticCurveTo( + x + cmd.x1 * xScale, + y + -cmd.y1 * yScale, + x + cmd.x * xScale, + y + -cmd.y * yScale + ); + } else if (cmd.type === 'C') { + p.curveTo( + x + cmd.x1 * xScale, + y + -cmd.y1 * yScale, + x + cmd.x2 * xScale, + y + -cmd.y2 * yScale, + x + cmd.x * xScale, + y + -cmd.y * yScale + ); + } else if (cmd.type === 'Z') { + p.closePath(); + } + } + + return p; + }; + + /** + * Split the glyph into contours. + * This function is here for backwards compatibility, and to + * provide raw access to the TrueType glyph outlines. + * @return {Array} + */ + Glyph.prototype.getContours = function() { + var this$1 = this; + + if (this.points === undefined) { + return []; + } + + var contours = []; + var currentContour = []; + for (var i = 0; i < this.points.length; i += 1) { + var pt = this$1.points[i]; + currentContour.push(pt); + if (pt.lastPointOfContour) { + contours.push(currentContour); + currentContour = []; + } + } + + check.argument( + currentContour.length === 0, + 'There are still points left in the current contour.' + ); + return contours; + }; + + /** + * Calculate the xMin/yMin/xMax/yMax/lsb/rsb for a Glyph. + * @return {Object} + */ + Glyph.prototype.getMetrics = function() { + var commands = this.path.commands; + var xCoords = []; + var yCoords = []; + for (var i = 0; i < commands.length; i += 1) { + var cmd = commands[i]; + if (cmd.type !== 'Z') { + xCoords.push(cmd.x); + yCoords.push(cmd.y); + } + + if (cmd.type === 'Q' || cmd.type === 'C') { + xCoords.push(cmd.x1); + yCoords.push(cmd.y1); + } + + if (cmd.type === 'C') { + xCoords.push(cmd.x2); + yCoords.push(cmd.y2); + } + } + + var metrics = { + xMin: Math.min.apply(null, xCoords), + yMin: Math.min.apply(null, yCoords), + xMax: Math.max.apply(null, xCoords), + yMax: Math.max.apply(null, yCoords), + leftSideBearing: this.leftSideBearing + }; + + if (!isFinite(metrics.xMin)) { + metrics.xMin = 0; + } + + if (!isFinite(metrics.xMax)) { + metrics.xMax = this.advanceWidth; + } + + if (!isFinite(metrics.yMin)) { + metrics.yMin = 0; + } + + if (!isFinite(metrics.yMax)) { + metrics.yMax = 0; + } + + metrics.rightSideBearing = + this.advanceWidth - + metrics.leftSideBearing - + (metrics.xMax - metrics.xMin); + return metrics; + }; + + /** + * Draw the glyph on the given context. + * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {Object=} options - xScale, yScale to stretch the glyph. + */ + Glyph.prototype.draw = function(ctx, x, y, fontSize, options) { + this.getPath(x, y, fontSize, options).draw(ctx); + }; + + /** + * Draw the points of the glyph. + * On-curve points will be drawn in blue, off-curve points will be drawn in red. + * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + */ + Glyph.prototype.drawPoints = function(ctx, x, y, fontSize) { + function drawCircles(l, x, y, scale) { + var PI_SQ = Math.PI * 2; + ctx.beginPath(); + for (var j = 0; j < l.length; j += 1) { + ctx.moveTo(x + l[j].x * scale, y + l[j].y * scale); + ctx.arc(x + l[j].x * scale, y + l[j].y * scale, 2, 0, PI_SQ, false); + } + + ctx.closePath(); + ctx.fill(); + } + + x = x !== undefined ? x : 0; + y = y !== undefined ? y : 0; + fontSize = fontSize !== undefined ? fontSize : 24; + var scale = 1 / this.path.unitsPerEm * fontSize; + + var blueCircles = []; + var redCircles = []; + var path = this.path; + for (var i = 0; i < path.commands.length; i += 1) { + var cmd = path.commands[i]; + if (cmd.x !== undefined) { + blueCircles.push({ x: cmd.x, y: -cmd.y }); + } + + if (cmd.x1 !== undefined) { + redCircles.push({ x: cmd.x1, y: -cmd.y1 }); + } + + if (cmd.x2 !== undefined) { + redCircles.push({ x: cmd.x2, y: -cmd.y2 }); + } + } + + ctx.fillStyle = 'blue'; + drawCircles(blueCircles, x, y, scale); + ctx.fillStyle = 'red'; + drawCircles(redCircles, x, y, scale); + }; + + /** + * Draw lines indicating important font measurements. + * Black lines indicate the origin of the coordinate system (point 0,0). + * Blue lines indicate the glyph bounding box. + * Green line indicates the advance width of the glyph. + * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + */ + Glyph.prototype.drawMetrics = function(ctx, x, y, fontSize) { + var scale; + x = x !== undefined ? x : 0; + y = y !== undefined ? y : 0; + fontSize = fontSize !== undefined ? fontSize : 24; + scale = 1 / this.path.unitsPerEm * fontSize; + ctx.lineWidth = 1; + + // Draw the origin + ctx.strokeStyle = 'black'; + draw.line(ctx, x, -10000, x, 10000); + draw.line(ctx, -10000, y, 10000, y); + + // This code is here due to memory optimization: by not using + // defaults in the constructor, we save a notable amount of memory. + var xMin = this.xMin || 0; + var yMin = this.yMin || 0; + var xMax = this.xMax || 0; + var yMax = this.yMax || 0; + var advanceWidth = this.advanceWidth || 0; + + // Draw the glyph box + ctx.strokeStyle = 'blue'; + draw.line(ctx, x + xMin * scale, -10000, x + xMin * scale, 10000); + draw.line(ctx, x + xMax * scale, -10000, x + xMax * scale, 10000); + draw.line(ctx, -10000, y + -yMin * scale, 10000, y + -yMin * scale); + draw.line(ctx, -10000, y + -yMax * scale, 10000, y + -yMax * scale); + + // Draw the advance width + ctx.strokeStyle = 'green'; + draw.line( + ctx, + x + advanceWidth * scale, + -10000, + x + advanceWidth * scale, + 10000 + ); + }; + + // The GlyphSet object + + // Define a property on the glyph that depends on the path being loaded. + function defineDependentProperty(glyph, externalName, internalName) { + Object.defineProperty(glyph, externalName, { + get: function() { + // Request the path property to make sure the path is loaded. + glyph.path; // jshint ignore:line + return glyph[internalName]; + }, + set: function(newValue) { + glyph[internalName] = newValue; + }, + enumerable: true, + configurable: true + }); + } + + /** + * A GlyphSet represents all glyphs available in the font, but modelled using + * a deferred glyph loader, for retrieving glyphs only once they are absolutely + * necessary, to keep the memory footprint down. + * @exports opentype.GlyphSet + * @class + * @param {opentype.Font} + * @param {Array} + */ + function GlyphSet(font, glyphs) { + var this$1 = this; + + this.font = font; + this.glyphs = {}; + if (Array.isArray(glyphs)) { + for (var i = 0; i < glyphs.length; i++) { + this$1.glyphs[i] = glyphs[i]; + } + } + + this.length = (glyphs && glyphs.length) || 0; + } + + /** + * @param {number} index + * @return {opentype.Glyph} + */ + GlyphSet.prototype.get = function(index) { + if (typeof this.glyphs[index] === 'function') { + this.glyphs[index] = this.glyphs[index](); + } + + return this.glyphs[index]; + }; + + /** + * @param {number} index + * @param {Object} + */ + GlyphSet.prototype.push = function(index, loader) { + this.glyphs[index] = loader; + this.length++; + }; + + /** + * @alias opentype.glyphLoader + * @param {opentype.Font} font + * @param {number} index + * @return {opentype.Glyph} + */ + function glyphLoader(font, index) { + return new Glyph({ index: index, font: font }); + } + + /** + * Generate a stub glyph that can be filled with all metadata *except* + * the "points" and "path" properties, which must be loaded only once + * the glyph's path is actually requested for text shaping. + * @alias opentype.ttfGlyphLoader + * @param {opentype.Font} font + * @param {number} index + * @param {Function} parseGlyph + * @param {Object} data + * @param {number} position + * @param {Function} buildPath + * @return {opentype.Glyph} + */ + function ttfGlyphLoader(font, index, parseGlyph, data, position, buildPath) { + return function() { + var glyph = new Glyph({ index: index, font: font }); + + glyph.path = function() { + parseGlyph(glyph, data, position); + var path = buildPath(font.glyphs, glyph); + path.unitsPerEm = font.unitsPerEm; + return path; + }; + + defineDependentProperty(glyph, 'xMin', '_xMin'); + defineDependentProperty(glyph, 'xMax', '_xMax'); + defineDependentProperty(glyph, 'yMin', '_yMin'); + defineDependentProperty(glyph, 'yMax', '_yMax'); + + return glyph; + }; + } + /** + * @alias opentype.cffGlyphLoader + * @param {opentype.Font} font + * @param {number} index + * @param {Function} parseCFFCharstring + * @param {string} charstring + * @return {opentype.Glyph} + */ + function cffGlyphLoader(font, index, parseCFFCharstring, charstring) { + return function() { + var glyph = new Glyph({ index: index, font: font }); + + glyph.path = function() { + var path = parseCFFCharstring(font, glyph, charstring); + path.unitsPerEm = font.unitsPerEm; + return path; + }; + + return glyph; + }; + } + + var glyphset = { + GlyphSet: GlyphSet, + glyphLoader: glyphLoader, + ttfGlyphLoader: ttfGlyphLoader, + cffGlyphLoader: cffGlyphLoader + }; + + // The `CFF` table contains the glyph outlines in PostScript format. + + // Custom equals function that can also check lists. + function equals(a, b) { + if (a === b) { + return true; + } else if (Array.isArray(a) && Array.isArray(b)) { + if (a.length !== b.length) { + return false; + } + + for (var i = 0; i < a.length; i += 1) { + if (!equals(a[i], b[i])) { + return false; + } + } + + return true; + } else { + return false; + } + } + + // Subroutines are encoded using the negative half of the number space. + // See type 2 chapter 4.7 "Subroutine operators". + function calcCFFSubroutineBias(subrs) { + var bias; + if (subrs.length < 1240) { + bias = 107; + } else if (subrs.length < 33900) { + bias = 1131; + } else { + bias = 32768; + } + + return bias; + } + + // Parse a `CFF` INDEX array. + // An index array consists of a list of offsets, then a list of objects at those offsets. + function parseCFFIndex(data, start, conversionFn) { + var offsets = []; + var objects = []; + var count = parse.getCard16(data, start); + var objectOffset; + var endOffset; + if (count !== 0) { + var offsetSize = parse.getByte(data, start + 2); + objectOffset = start + (count + 1) * offsetSize + 2; + var pos = start + 3; + for (var i = 0; i < count + 1; i += 1) { + offsets.push(parse.getOffset(data, pos, offsetSize)); + pos += offsetSize; + } + + // The total size of the index array is 4 header bytes + the value of the last offset. + endOffset = objectOffset + offsets[count]; + } else { + endOffset = start + 2; + } + + for (var i$1 = 0; i$1 < offsets.length - 1; i$1 += 1) { + var value = parse.getBytes( + data, + objectOffset + offsets[i$1], + objectOffset + offsets[i$1 + 1] + ); + if (conversionFn) { + value = conversionFn(value); + } + + objects.push(value); + } + + return { objects: objects, startOffset: start, endOffset: endOffset }; + } + + // Parse a `CFF` DICT real value. + function parseFloatOperand(parser) { + var s = ''; + var eof = 15; + var lookup = [ + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '.', + 'E', + 'E-', + null, + '-' + ]; + while (true) { + var b = parser.parseByte(); + var n1 = b >> 4; + var n2 = b & 15; + + if (n1 === eof) { + break; + } + + s += lookup[n1]; + + if (n2 === eof) { + break; + } + + s += lookup[n2]; + } + + return parseFloat(s); + } + + // Parse a `CFF` DICT operand. + function parseOperand(parser, b0) { + var b1; + var b2; + var b3; + var b4; + if (b0 === 28) { + b1 = parser.parseByte(); + b2 = parser.parseByte(); + return (b1 << 8) | b2; + } + + if (b0 === 29) { + b1 = parser.parseByte(); + b2 = parser.parseByte(); + b3 = parser.parseByte(); + b4 = parser.parseByte(); + return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4; + } + + if (b0 === 30) { + return parseFloatOperand(parser); + } + + if (b0 >= 32 && b0 <= 246) { + return b0 - 139; + } + + if (b0 >= 247 && b0 <= 250) { + b1 = parser.parseByte(); + return (b0 - 247) * 256 + b1 + 108; + } + + if (b0 >= 251 && b0 <= 254) { + b1 = parser.parseByte(); + return -(b0 - 251) * 256 - b1 - 108; + } + + throw new Error('Invalid b0 ' + b0); + } + + // Convert the entries returned by `parseDict` to a proper dictionary. + // If a value is a list of one, it is unpacked. + function entriesToObject(entries) { + var o = {}; + for (var i = 0; i < entries.length; i += 1) { + var key = entries[i][0]; + var values = entries[i][1]; + var value = void 0; + if (values.length === 1) { + value = values[0]; + } else { + value = values; + } + + if (o.hasOwnProperty(key) && !isNaN(o[key])) { + throw new Error('Object ' + o + ' already has key ' + key); + } + + o[key] = value; + } + + return o; + } + + // Parse a `CFF` DICT object. + // A dictionary contains key-value pairs in a compact tokenized format. + function parseCFFDict(data, start, size) { + start = start !== undefined ? start : 0; + var parser = new parse.Parser(data, start); + var entries = []; + var operands = []; + size = size !== undefined ? size : data.length; + + while (parser.relativeOffset < size) { + var op = parser.parseByte(); + + // The first byte for each dict item distinguishes between operator (key) and operand (value). + // Values <= 21 are operators. + if (op <= 21) { + // Two-byte operators have an initial escape byte of 12. + if (op === 12) { + op = 1200 + parser.parseByte(); + } + + entries.push([op, operands]); + operands = []; + } else { + // Since the operands (values) come before the operators (keys), we store all operands in a list + // until we encounter an operator. + operands.push(parseOperand(parser, op)); + } + } + + return entriesToObject(entries); + } + + // Given a String Index (SID), return the value of the string. + // Strings below index 392 are standard CFF strings and are not encoded in the font. + function getCFFString(strings, index) { + if (index <= 390) { + index = cffStandardStrings[index]; + } else { + index = strings[index - 391]; + } + + return index; + } + + // Interpret a dictionary and return a new dictionary with readable keys and values for missing entries. + // This function takes `meta` which is a list of objects containing `operand`, `name` and `default`. + function interpretDict(dict, meta, strings) { + var newDict = {}; + var value; + + // Because we also want to include missing values, we start out from the meta list + // and lookup values in the dict. + for (var i = 0; i < meta.length; i += 1) { + var m = meta[i]; + + if (Array.isArray(m.type)) { + var values = []; + values.length = m.type.length; + for (var j = 0; j < m.type.length; j++) { + value = dict[m.op] !== undefined ? dict[m.op][j] : undefined; + if (value === undefined) { + value = + m.value !== undefined && m.value[j] !== undefined + ? m.value[j] + : null; + } + if (m.type[j] === 'SID') { + value = getCFFString(strings, value); + } + values[j] = value; + } + newDict[m.name] = values; + } else { + value = dict[m.op]; + if (value === undefined) { + value = m.value !== undefined ? m.value : null; + } + + if (m.type === 'SID') { + value = getCFFString(strings, value); + } + newDict[m.name] = value; + } + } + + return newDict; + } + + // Parse the CFF header. + function parseCFFHeader(data, start) { + var header = {}; + header.formatMajor = parse.getCard8(data, start); + header.formatMinor = parse.getCard8(data, start + 1); + header.size = parse.getCard8(data, start + 2); + header.offsetSize = parse.getCard8(data, start + 3); + header.startOffset = start; + header.endOffset = start + 4; + return header; + } + + var TOP_DICT_META = [ + { name: 'version', op: 0, type: 'SID' }, + { name: 'notice', op: 1, type: 'SID' }, + { name: 'copyright', op: 1200, type: 'SID' }, + { name: 'fullName', op: 2, type: 'SID' }, + { name: 'familyName', op: 3, type: 'SID' }, + { name: 'weight', op: 4, type: 'SID' }, + { name: 'isFixedPitch', op: 1201, type: 'number', value: 0 }, + { name: 'italicAngle', op: 1202, type: 'number', value: 0 }, + { name: 'underlinePosition', op: 1203, type: 'number', value: -100 }, + { name: 'underlineThickness', op: 1204, type: 'number', value: 50 }, + { name: 'paintType', op: 1205, type: 'number', value: 0 }, + { name: 'charstringType', op: 1206, type: 'number', value: 2 }, + { + name: 'fontMatrix', + op: 1207, + type: ['real', 'real', 'real', 'real', 'real', 'real'], + value: [0.001, 0, 0, 0.001, 0, 0] + }, + { name: 'uniqueId', op: 13, type: 'number' }, + { + name: 'fontBBox', + op: 5, + type: ['number', 'number', 'number', 'number'], + value: [0, 0, 0, 0] + }, + { name: 'strokeWidth', op: 1208, type: 'number', value: 0 }, + { name: 'xuid', op: 14, type: [], value: null }, + { name: 'charset', op: 15, type: 'offset', value: 0 }, + { name: 'encoding', op: 16, type: 'offset', value: 0 }, + { name: 'charStrings', op: 17, type: 'offset', value: 0 }, + { name: 'private', op: 18, type: ['number', 'offset'], value: [0, 0] }, + { name: 'ros', op: 1230, type: ['SID', 'SID', 'number'] }, + { name: 'cidFontVersion', op: 1231, type: 'number', value: 0 }, + { name: 'cidFontRevision', op: 1232, type: 'number', value: 0 }, + { name: 'cidFontType', op: 1233, type: 'number', value: 0 }, + { name: 'cidCount', op: 1234, type: 'number', value: 8720 }, + { name: 'uidBase', op: 1235, type: 'number' }, + { name: 'fdArray', op: 1236, type: 'offset' }, + { name: 'fdSelect', op: 1237, type: 'offset' }, + { name: 'fontName', op: 1238, type: 'SID' } + ]; + + var PRIVATE_DICT_META = [ + { name: 'subrs', op: 19, type: 'offset', value: 0 }, + { name: 'defaultWidthX', op: 20, type: 'number', value: 0 }, + { name: 'nominalWidthX', op: 21, type: 'number', value: 0 } + ]; + + // Parse the CFF top dictionary. A CFF table can contain multiple fonts, each with their own top dictionary. + // The top dictionary contains the essential metadata for the font, together with the private dictionary. + function parseCFFTopDict(data, strings) { + var dict = parseCFFDict(data, 0, data.byteLength); + return interpretDict(dict, TOP_DICT_META, strings); + } + + // Parse the CFF private dictionary. We don't fully parse out all the values, only the ones we need. + function parseCFFPrivateDict(data, start, size, strings) { + var dict = parseCFFDict(data, start, size); + return interpretDict(dict, PRIVATE_DICT_META, strings); + } + + // Returns a list of "Top DICT"s found using an INDEX list. + // Used to read both the usual high-level Top DICTs and also the FDArray + // discovered inside CID-keyed fonts. When a Top DICT has a reference to + // a Private DICT that is read and saved into the Top DICT. + // + // In addition to the expected/optional values as outlined in TOP_DICT_META + // the following values might be saved into the Top DICT. + // + // _subrs [] array of local CFF subroutines from Private DICT + // _subrsBias bias value computed from number of subroutines + // (see calcCFFSubroutineBias() and parseCFFCharstring()) + // _defaultWidthX default widths for CFF characters + // _nominalWidthX bias added to width embedded within glyph description + // + // _privateDict saved copy of parsed Private DICT from Top DICT + function gatherCFFTopDicts(data, start, cffIndex, strings) { + var topDictArray = []; + for (var iTopDict = 0; iTopDict < cffIndex.length; iTopDict += 1) { + var topDictData = new DataView(new Uint8Array(cffIndex[iTopDict]).buffer); + var topDict = parseCFFTopDict(topDictData, strings); + topDict._subrs = []; + topDict._subrsBias = 0; + var privateSize = topDict.private[0]; + var privateOffset = topDict.private[1]; + if (privateSize !== 0 && privateOffset !== 0) { + var privateDict = parseCFFPrivateDict( + data, + privateOffset + start, + privateSize, + strings + ); + topDict._defaultWidthX = privateDict.defaultWidthX; + topDict._nominalWidthX = privateDict.nominalWidthX; + if (privateDict.subrs !== 0) { + var subrOffset = privateOffset + privateDict.subrs; + var subrIndex = parseCFFIndex(data, subrOffset + start); + topDict._subrs = subrIndex.objects; + topDict._subrsBias = calcCFFSubroutineBias(topDict._subrs); + } + topDict._privateDict = privateDict; + } + topDictArray.push(topDict); + } + return topDictArray; + } + + // Parse the CFF charset table, which contains internal names for all the glyphs. + // This function will return a list of glyph names. + // See Adobe TN #5176 chapter 13, "Charsets". + function parseCFFCharset(data, start, nGlyphs, strings) { + var sid; + var count; + var parser = new parse.Parser(data, start); + + // The .notdef glyph is not included, so subtract 1. + nGlyphs -= 1; + var charset = ['.notdef']; + + var format = parser.parseCard8(); + if (format === 0) { + for (var i = 0; i < nGlyphs; i += 1) { + sid = parser.parseSID(); + charset.push(getCFFString(strings, sid)); + } + } else if (format === 1) { + while (charset.length <= nGlyphs) { + sid = parser.parseSID(); + count = parser.parseCard8(); + for (var i$1 = 0; i$1 <= count; i$1 += 1) { + charset.push(getCFFString(strings, sid)); + sid += 1; + } + } + } else if (format === 2) { + while (charset.length <= nGlyphs) { + sid = parser.parseSID(); + count = parser.parseCard16(); + for (var i$2 = 0; i$2 <= count; i$2 += 1) { + charset.push(getCFFString(strings, sid)); + sid += 1; + } + } + } else { + throw new Error('Unknown charset format ' + format); + } + + return charset; + } + + // Parse the CFF encoding data. Only one encoding can be specified per font. + // See Adobe TN #5176 chapter 12, "Encodings". + function parseCFFEncoding(data, start, charset) { + var code; + var enc = {}; + var parser = new parse.Parser(data, start); + var format = parser.parseCard8(); + if (format === 0) { + var nCodes = parser.parseCard8(); + for (var i = 0; i < nCodes; i += 1) { + code = parser.parseCard8(); + enc[code] = i; + } + } else if (format === 1) { + var nRanges = parser.parseCard8(); + code = 1; + for (var i$1 = 0; i$1 < nRanges; i$1 += 1) { + var first = parser.parseCard8(); + var nLeft = parser.parseCard8(); + for (var j = first; j <= first + nLeft; j += 1) { + enc[j] = code; + code += 1; + } + } + } else { + throw new Error('Unknown encoding format ' + format); + } + + return new CffEncoding(enc, charset); + } + + // Take in charstring code and return a Glyph object. + // The encoding is described in the Type 2 Charstring Format + // https://www.microsoft.com/typography/OTSPEC/charstr2.htm + function parseCFFCharstring(font, glyph, code) { + var c1x; + var c1y; + var c2x; + var c2y; + var p = new Path(); + var stack = []; + var nStems = 0; + var haveWidth = false; + var open = false; + var x = 0; + var y = 0; + var subrs; + var subrsBias; + var defaultWidthX; + var nominalWidthX; + if (font.isCIDFont) { + var fdIndex = font.tables.cff.topDict._fdSelect[glyph.index]; + var fdDict = font.tables.cff.topDict._fdArray[fdIndex]; + subrs = fdDict._subrs; + subrsBias = fdDict._subrsBias; + defaultWidthX = fdDict._defaultWidthX; + nominalWidthX = fdDict._nominalWidthX; + } else { + subrs = font.tables.cff.topDict._subrs; + subrsBias = font.tables.cff.topDict._subrsBias; + defaultWidthX = font.tables.cff.topDict._defaultWidthX; + nominalWidthX = font.tables.cff.topDict._nominalWidthX; + } + var width = defaultWidthX; + + function newContour(x, y) { + if (open) { + p.closePath(); + } + + p.moveTo(x, y); + open = true; + } + + function parseStems() { + var hasWidthArg; + + // The number of stem operators on the stack is always even. + // If the value is uneven, that means a width is specified. + hasWidthArg = stack.length % 2 !== 0; + if (hasWidthArg && !haveWidth) { + width = stack.shift() + nominalWidthX; + } + + nStems += stack.length >> 1; + stack.length = 0; + haveWidth = true; + } + + function parse$$1(code) { + var b1; + var b2; + var b3; + var b4; + var codeIndex; + var subrCode; + var jpx; + var jpy; + var c3x; + var c3y; + var c4x; + var c4y; + + var i = 0; + while (i < code.length) { + var v = code[i]; + i += 1; + switch (v) { + case 1: // hstem + parseStems(); + break; + case 3: // vstem + parseStems(); + break; + case 4: // vmoveto + if (stack.length > 1 && !haveWidth) { + width = stack.shift() + nominalWidthX; + haveWidth = true; + } + + y += stack.pop(); + newContour(x, y); + break; + case 5: // rlineto + while (stack.length > 0) { + x += stack.shift(); + y += stack.shift(); + p.lineTo(x, y); + } + + break; + case 6: // hlineto + while (stack.length > 0) { + x += stack.shift(); + p.lineTo(x, y); + if (stack.length === 0) { + break; + } + + y += stack.shift(); + p.lineTo(x, y); + } + + break; + case 7: // vlineto + while (stack.length > 0) { + y += stack.shift(); + p.lineTo(x, y); + if (stack.length === 0) { + break; + } + + x += stack.shift(); + p.lineTo(x, y); + } + + break; + case 8: // rrcurveto + while (stack.length > 0) { + c1x = x + stack.shift(); + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + x = c2x + stack.shift(); + y = c2y + stack.shift(); + p.curveTo(c1x, c1y, c2x, c2y, x, y); + } + + break; + case 10: // callsubr + codeIndex = stack.pop() + subrsBias; + subrCode = subrs[codeIndex]; + if (subrCode) { + parse$$1(subrCode); + } + + break; + case 11: // return + return; + case 12: // flex operators + v = code[i]; + i += 1; + switch (v) { + case 35: // flex + // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 dx6 dy6 fd flex (12 35) |- + c1x = x + stack.shift(); // dx1 + c1y = y + stack.shift(); // dy1 + c2x = c1x + stack.shift(); // dx2 + c2y = c1y + stack.shift(); // dy2 + jpx = c2x + stack.shift(); // dx3 + jpy = c2y + stack.shift(); // dy3 + c3x = jpx + stack.shift(); // dx4 + c3y = jpy + stack.shift(); // dy4 + c4x = c3x + stack.shift(); // dx5 + c4y = c3y + stack.shift(); // dy5 + x = c4x + stack.shift(); // dx6 + y = c4y + stack.shift(); // dy6 + stack.shift(); // flex depth + p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); + p.curveTo(c3x, c3y, c4x, c4y, x, y); + break; + case 34: // hflex + // |- dx1 dx2 dy2 dx3 dx4 dx5 dx6 hflex (12 34) |- + c1x = x + stack.shift(); // dx1 + c1y = y; // dy1 + c2x = c1x + stack.shift(); // dx2 + c2y = c1y + stack.shift(); // dy2 + jpx = c2x + stack.shift(); // dx3 + jpy = c2y; // dy3 + c3x = jpx + stack.shift(); // dx4 + c3y = c2y; // dy4 + c4x = c3x + stack.shift(); // dx5 + c4y = y; // dy5 + x = c4x + stack.shift(); // dx6 + p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); + p.curveTo(c3x, c3y, c4x, c4y, x, y); + break; + case 36: // hflex1 + // |- dx1 dy1 dx2 dy2 dx3 dx4 dx5 dy5 dx6 hflex1 (12 36) |- + c1x = x + stack.shift(); // dx1 + c1y = y + stack.shift(); // dy1 + c2x = c1x + stack.shift(); // dx2 + c2y = c1y + stack.shift(); // dy2 + jpx = c2x + stack.shift(); // dx3 + jpy = c2y; // dy3 + c3x = jpx + stack.shift(); // dx4 + c3y = c2y; // dy4 + c4x = c3x + stack.shift(); // dx5 + c4y = c3y + stack.shift(); // dy5 + x = c4x + stack.shift(); // dx6 + p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); + p.curveTo(c3x, c3y, c4x, c4y, x, y); + break; + case 37: // flex1 + // |- dx1 dy1 dx2 dy2 dx3 dy3 dx4 dy4 dx5 dy5 d6 flex1 (12 37) |- + c1x = x + stack.shift(); // dx1 + c1y = y + stack.shift(); // dy1 + c2x = c1x + stack.shift(); // dx2 + c2y = c1y + stack.shift(); // dy2 + jpx = c2x + stack.shift(); // dx3 + jpy = c2y + stack.shift(); // dy3 + c3x = jpx + stack.shift(); // dx4 + c3y = jpy + stack.shift(); // dy4 + c4x = c3x + stack.shift(); // dx5 + c4y = c3y + stack.shift(); // dy5 + if (Math.abs(c4x - x) > Math.abs(c4y - y)) { + x = c4x + stack.shift(); + } else { + y = c4y + stack.shift(); + } + + p.curveTo(c1x, c1y, c2x, c2y, jpx, jpy); + p.curveTo(c3x, c3y, c4x, c4y, x, y); + break; + default: + console.log( + 'Glyph ' + glyph.index + ': unknown operator ' + 1200 + v + ); + stack.length = 0; + } + break; + case 14: // endchar + if (stack.length > 0 && !haveWidth) { + width = stack.shift() + nominalWidthX; + haveWidth = true; + } + + if (open) { + p.closePath(); + open = false; + } + + break; + case 18: // hstemhm + parseStems(); + break; + case 19: // hintmask + case 20: // cntrmask + parseStems(); + i += (nStems + 7) >> 3; + break; + case 21: // rmoveto + if (stack.length > 2 && !haveWidth) { + width = stack.shift() + nominalWidthX; + haveWidth = true; + } + + y += stack.pop(); + x += stack.pop(); + newContour(x, y); + break; + case 22: // hmoveto + if (stack.length > 1 && !haveWidth) { + width = stack.shift() + nominalWidthX; + haveWidth = true; + } + + x += stack.pop(); + newContour(x, y); + break; + case 23: // vstemhm + parseStems(); + break; + case 24: // rcurveline + while (stack.length > 2) { + c1x = x + stack.shift(); + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + x = c2x + stack.shift(); + y = c2y + stack.shift(); + p.curveTo(c1x, c1y, c2x, c2y, x, y); + } + + x += stack.shift(); + y += stack.shift(); + p.lineTo(x, y); + break; + case 25: // rlinecurve + while (stack.length > 6) { + x += stack.shift(); + y += stack.shift(); + p.lineTo(x, y); + } + + c1x = x + stack.shift(); + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + x = c2x + stack.shift(); + y = c2y + stack.shift(); + p.curveTo(c1x, c1y, c2x, c2y, x, y); + break; + case 26: // vvcurveto + if (stack.length % 2) { + x += stack.shift(); + } + + while (stack.length > 0) { + c1x = x; + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + x = c2x; + y = c2y + stack.shift(); + p.curveTo(c1x, c1y, c2x, c2y, x, y); + } + + break; + case 27: // hhcurveto + if (stack.length % 2) { + y += stack.shift(); + } + + while (stack.length > 0) { + c1x = x + stack.shift(); + c1y = y; + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + x = c2x + stack.shift(); + y = c2y; + p.curveTo(c1x, c1y, c2x, c2y, x, y); + } + + break; + case 28: // shortint + b1 = code[i]; + b2 = code[i + 1]; + stack.push(((b1 << 24) | (b2 << 16)) >> 16); + i += 2; + break; + case 29: // callgsubr + codeIndex = stack.pop() + font.gsubrsBias; + subrCode = font.gsubrs[codeIndex]; + if (subrCode) { + parse$$1(subrCode); + } + + break; + case 30: // vhcurveto + while (stack.length > 0) { + c1x = x; + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + x = c2x + stack.shift(); + y = c2y + (stack.length === 1 ? stack.shift() : 0); + p.curveTo(c1x, c1y, c2x, c2y, x, y); + if (stack.length === 0) { + break; + } + + c1x = x + stack.shift(); + c1y = y; + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + y = c2y + stack.shift(); + x = c2x + (stack.length === 1 ? stack.shift() : 0); + p.curveTo(c1x, c1y, c2x, c2y, x, y); + } + + break; + case 31: // hvcurveto + while (stack.length > 0) { + c1x = x + stack.shift(); + c1y = y; + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + y = c2y + stack.shift(); + x = c2x + (stack.length === 1 ? stack.shift() : 0); + p.curveTo(c1x, c1y, c2x, c2y, x, y); + if (stack.length === 0) { + break; + } + + c1x = x; + c1y = y + stack.shift(); + c2x = c1x + stack.shift(); + c2y = c1y + stack.shift(); + x = c2x + stack.shift(); + y = c2y + (stack.length === 1 ? stack.shift() : 0); + p.curveTo(c1x, c1y, c2x, c2y, x, y); + } + + break; + default: + if (v < 32) { + console.log('Glyph ' + glyph.index + ': unknown operator ' + v); + } else if (v < 247) { + stack.push(v - 139); + } else if (v < 251) { + b1 = code[i]; + i += 1; + stack.push((v - 247) * 256 + b1 + 108); + } else if (v < 255) { + b1 = code[i]; + i += 1; + stack.push(-(v - 251) * 256 - b1 - 108); + } else { + b1 = code[i]; + b2 = code[i + 1]; + b3 = code[i + 2]; + b4 = code[i + 3]; + i += 4; + stack.push(((b1 << 24) | (b2 << 16) | (b3 << 8) | b4) / 65536); + } + } + } + } + + parse$$1(code); + + glyph.advanceWidth = width; + return p; + } + + function parseCFFFDSelect(data, start, nGlyphs, fdArrayCount) { + var fdSelect = []; + var fdIndex; + var parser = new parse.Parser(data, start); + var format = parser.parseCard8(); + if (format === 0) { + // Simple list of nGlyphs elements + for (var iGid = 0; iGid < nGlyphs; iGid++) { + fdIndex = parser.parseCard8(); + if (fdIndex >= fdArrayCount) { + throw new Error( + 'CFF table CID Font FDSelect has bad FD index value ' + + fdIndex + + ' (FD count ' + + fdArrayCount + + ')' + ); + } + fdSelect.push(fdIndex); + } + } else if (format === 3) { + // Ranges + var nRanges = parser.parseCard16(); + var first = parser.parseCard16(); + if (first !== 0) { + throw new Error( + 'CFF Table CID Font FDSelect format 3 range has bad initial GID ' + + first + ); + } + var next; + for (var iRange = 0; iRange < nRanges; iRange++) { + fdIndex = parser.parseCard8(); + next = parser.parseCard16(); + if (fdIndex >= fdArrayCount) { + throw new Error( + 'CFF table CID Font FDSelect has bad FD index value ' + + fdIndex + + ' (FD count ' + + fdArrayCount + + ')' + ); + } + if (next > nGlyphs) { + throw new Error( + 'CFF Table CID Font FDSelect format 3 range has bad GID ' + next + ); + } + for (; first < next; first++) { + fdSelect.push(fdIndex); + } + first = next; + } + if (next !== nGlyphs) { + throw new Error( + 'CFF Table CID Font FDSelect format 3 range has bad final GID ' + next + ); + } + } else { + throw new Error( + 'CFF Table CID Font FDSelect table has unsupported format ' + format + ); + } + return fdSelect; + } + + // Parse the `CFF` table, which contains the glyph outlines in PostScript format. + function parseCFFTable(data, start, font) { + font.tables.cff = {}; + var header = parseCFFHeader(data, start); + var nameIndex = parseCFFIndex(data, header.endOffset, parse.bytesToString); + var topDictIndex = parseCFFIndex(data, nameIndex.endOffset); + var stringIndex = parseCFFIndex( + data, + topDictIndex.endOffset, + parse.bytesToString + ); + var globalSubrIndex = parseCFFIndex(data, stringIndex.endOffset); + font.gsubrs = globalSubrIndex.objects; + font.gsubrsBias = calcCFFSubroutineBias(font.gsubrs); + + var topDictArray = gatherCFFTopDicts( + data, + start, + topDictIndex.objects, + stringIndex.objects + ); + if (topDictArray.length !== 1) { + throw new Error( + "CFF table has too many fonts in 'FontSet' - count of fonts NameIndex.length = " + + topDictArray.length + ); + } + + var topDict = topDictArray[0]; + font.tables.cff.topDict = topDict; + + if (topDict._privateDict) { + font.defaultWidthX = topDict._privateDict.defaultWidthX; + font.nominalWidthX = topDict._privateDict.nominalWidthX; + } + + if (topDict.ros[0] !== undefined && topDict.ros[1] !== undefined) { + font.isCIDFont = true; + } + + if (font.isCIDFont) { + var fdArrayOffset = topDict.fdArray; + var fdSelectOffset = topDict.fdSelect; + if (fdArrayOffset === 0 || fdSelectOffset === 0) { + throw new Error( + 'Font is marked as a CID font, but FDArray and/or FDSelect information is missing' + ); + } + fdArrayOffset += start; + var fdArrayIndex = parseCFFIndex(data, fdArrayOffset); + var fdArray = gatherCFFTopDicts( + data, + start, + fdArrayIndex.objects, + stringIndex.objects + ); + topDict._fdArray = fdArray; + fdSelectOffset += start; + topDict._fdSelect = parseCFFFDSelect( + data, + fdSelectOffset, + font.numGlyphs, + fdArray.length + ); + } + + var privateDictOffset = start + topDict.private[1]; + var privateDict = parseCFFPrivateDict( + data, + privateDictOffset, + topDict.private[0], + stringIndex.objects + ); + font.defaultWidthX = privateDict.defaultWidthX; + font.nominalWidthX = privateDict.nominalWidthX; + + if (privateDict.subrs !== 0) { + var subrOffset = privateDictOffset + privateDict.subrs; + var subrIndex = parseCFFIndex(data, subrOffset); + font.subrs = subrIndex.objects; + font.subrsBias = calcCFFSubroutineBias(font.subrs); + } else { + font.subrs = []; + font.subrsBias = 0; + } + + // Offsets in the top dict are relative to the beginning of the CFF data, so add the CFF start offset. + var charStringsIndex = parseCFFIndex(data, start + topDict.charStrings); + font.nGlyphs = charStringsIndex.objects.length; + + var charset = parseCFFCharset( + data, + start + topDict.charset, + font.nGlyphs, + stringIndex.objects + ); + if (topDict.encoding === 0) { + // Standard encoding + font.cffEncoding = new CffEncoding(cffStandardEncoding, charset); + } else if (topDict.encoding === 1) { + // Expert encoding + font.cffEncoding = new CffEncoding(cffExpertEncoding, charset); + } else { + font.cffEncoding = parseCFFEncoding( + data, + start + topDict.encoding, + charset + ); + } + + // Prefer the CMAP encoding to the CFF encoding. + font.encoding = font.encoding || font.cffEncoding; + + font.glyphs = new glyphset.GlyphSet(font); + for (var i = 0; i < font.nGlyphs; i += 1) { + var charString = charStringsIndex.objects[i]; + font.glyphs.push( + i, + glyphset.cffGlyphLoader(font, i, parseCFFCharstring, charString) + ); + } + } + + // Convert a string to a String ID (SID). + // The list of strings is modified in place. + function encodeString(s, strings) { + var sid; + + // Is the string in the CFF standard strings? + var i = cffStandardStrings.indexOf(s); + if (i >= 0) { + sid = i; + } + + // Is the string already in the string index? + i = strings.indexOf(s); + if (i >= 0) { + sid = i + cffStandardStrings.length; + } else { + sid = cffStandardStrings.length + strings.length; + strings.push(s); + } + + return sid; + } + + function makeHeader() { + return new table.Record('Header', [ + { name: 'major', type: 'Card8', value: 1 }, + { name: 'minor', type: 'Card8', value: 0 }, + { name: 'hdrSize', type: 'Card8', value: 4 }, + { name: 'major', type: 'Card8', value: 1 } + ]); + } + + function makeNameIndex(fontNames) { + var t = new table.Record('Name INDEX', [ + { name: 'names', type: 'INDEX', value: [] } + ]); + t.names = []; + for (var i = 0; i < fontNames.length; i += 1) { + t.names.push({ name: 'name_' + i, type: 'NAME', value: fontNames[i] }); + } + + return t; + } + + // Given a dictionary's metadata, create a DICT structure. + function makeDict(meta, attrs, strings) { + var m = {}; + for (var i = 0; i < meta.length; i += 1) { + var entry = meta[i]; + var value = attrs[entry.name]; + if (value !== undefined && !equals(value, entry.value)) { + if (entry.type === 'SID') { + value = encodeString(value, strings); + } + + m[entry.op] = { name: entry.name, type: entry.type, value: value }; + } + } + + return m; + } + + // The Top DICT houses the global font attributes. + function makeTopDict(attrs, strings) { + var t = new table.Record('Top DICT', [ + { name: 'dict', type: 'DICT', value: {} } + ]); + t.dict = makeDict(TOP_DICT_META, attrs, strings); + return t; + } + + function makeTopDictIndex(topDict) { + var t = new table.Record('Top DICT INDEX', [ + { name: 'topDicts', type: 'INDEX', value: [] } + ]); + t.topDicts = [{ name: 'topDict_0', type: 'TABLE', value: topDict }]; + return t; + } + + function makeStringIndex(strings) { + var t = new table.Record('String INDEX', [ + { name: 'strings', type: 'INDEX', value: [] } + ]); + t.strings = []; + for (var i = 0; i < strings.length; i += 1) { + t.strings.push({ + name: 'string_' + i, + type: 'STRING', + value: strings[i] + }); + } + + return t; + } + + function makeGlobalSubrIndex() { + // Currently we don't use subroutines. + return new table.Record('Global Subr INDEX', [ + { name: 'subrs', type: 'INDEX', value: [] } + ]); + } + + function makeCharsets(glyphNames, strings) { + var t = new table.Record('Charsets', [ + { name: 'format', type: 'Card8', value: 0 } + ]); + for (var i = 0; i < glyphNames.length; i += 1) { + var glyphName = glyphNames[i]; + var glyphSID = encodeString(glyphName, strings); + t.fields.push({ name: 'glyph_' + i, type: 'SID', value: glyphSID }); + } + + return t; + } + + function glyphToOps(glyph) { + var ops = []; + var path = glyph.path; + ops.push({ name: 'width', type: 'NUMBER', value: glyph.advanceWidth }); + var x = 0; + var y = 0; + for (var i = 0; i < path.commands.length; i += 1) { + var dx = void 0; + var dy = void 0; + var cmd = path.commands[i]; + if (cmd.type === 'Q') { + // CFF only supports bézier curves, so convert the quad to a bézier. + var _13 = 1 / 3; + var _23 = 2 / 3; + + // We're going to create a new command so we don't change the original path. + cmd = { + type: 'C', + x: cmd.x, + y: cmd.y, + x1: _13 * x + _23 * cmd.x1, + y1: _13 * y + _23 * cmd.y1, + x2: _13 * cmd.x + _23 * cmd.x1, + y2: _13 * cmd.y + _23 * cmd.y1 + }; + } + + if (cmd.type === 'M') { + dx = Math.round(cmd.x - x); + dy = Math.round(cmd.y - y); + ops.push({ name: 'dx', type: 'NUMBER', value: dx }); + ops.push({ name: 'dy', type: 'NUMBER', value: dy }); + ops.push({ name: 'rmoveto', type: 'OP', value: 21 }); + x = Math.round(cmd.x); + y = Math.round(cmd.y); + } else if (cmd.type === 'L') { + dx = Math.round(cmd.x - x); + dy = Math.round(cmd.y - y); + ops.push({ name: 'dx', type: 'NUMBER', value: dx }); + ops.push({ name: 'dy', type: 'NUMBER', value: dy }); + ops.push({ name: 'rlineto', type: 'OP', value: 5 }); + x = Math.round(cmd.x); + y = Math.round(cmd.y); + } else if (cmd.type === 'C') { + var dx1 = Math.round(cmd.x1 - x); + var dy1 = Math.round(cmd.y1 - y); + var dx2 = Math.round(cmd.x2 - cmd.x1); + var dy2 = Math.round(cmd.y2 - cmd.y1); + dx = Math.round(cmd.x - cmd.x2); + dy = Math.round(cmd.y - cmd.y2); + ops.push({ name: 'dx1', type: 'NUMBER', value: dx1 }); + ops.push({ name: 'dy1', type: 'NUMBER', value: dy1 }); + ops.push({ name: 'dx2', type: 'NUMBER', value: dx2 }); + ops.push({ name: 'dy2', type: 'NUMBER', value: dy2 }); + ops.push({ name: 'dx', type: 'NUMBER', value: dx }); + ops.push({ name: 'dy', type: 'NUMBER', value: dy }); + ops.push({ name: 'rrcurveto', type: 'OP', value: 8 }); + x = Math.round(cmd.x); + y = Math.round(cmd.y); + } + + // Contours are closed automatically. + } + + ops.push({ name: 'endchar', type: 'OP', value: 14 }); + return ops; + } + + function makeCharStringsIndex(glyphs) { + var t = new table.Record('CharStrings INDEX', [ + { name: 'charStrings', type: 'INDEX', value: [] } + ]); + + for (var i = 0; i < glyphs.length; i += 1) { + var glyph = glyphs.get(i); + var ops = glyphToOps(glyph); + t.charStrings.push({ name: glyph.name, type: 'CHARSTRING', value: ops }); + } + + return t; + } + + function makePrivateDict(attrs, strings) { + var t = new table.Record('Private DICT', [ + { name: 'dict', type: 'DICT', value: {} } + ]); + t.dict = makeDict(PRIVATE_DICT_META, attrs, strings); + return t; + } + + function makeCFFTable(glyphs, options) { + var t = new table.Table('CFF ', [ + { name: 'header', type: 'RECORD' }, + { name: 'nameIndex', type: 'RECORD' }, + { name: 'topDictIndex', type: 'RECORD' }, + { name: 'stringIndex', type: 'RECORD' }, + { name: 'globalSubrIndex', type: 'RECORD' }, + { name: 'charsets', type: 'RECORD' }, + { name: 'charStringsIndex', type: 'RECORD' }, + { name: 'privateDict', type: 'RECORD' } + ]); + + var fontScale = 1 / options.unitsPerEm; + // We use non-zero values for the offsets so that the DICT encodes them. + // This is important because the size of the Top DICT plays a role in offset calculation, + // and the size shouldn't change after we've written correct offsets. + var attrs = { + version: options.version, + fullName: options.fullName, + familyName: options.familyName, + weight: options.weightName, + fontBBox: options.fontBBox || [0, 0, 0, 0], + fontMatrix: [fontScale, 0, 0, fontScale, 0, 0], + charset: 999, + encoding: 0, + charStrings: 999, + private: [0, 999] + }; + + var privateAttrs = {}; + + var glyphNames = []; + var glyph; + + // Skip first glyph (.notdef) + for (var i = 1; i < glyphs.length; i += 1) { + glyph = glyphs.get(i); + glyphNames.push(glyph.name); + } + + var strings = []; + + t.header = makeHeader(); + t.nameIndex = makeNameIndex([options.postScriptName]); + var topDict = makeTopDict(attrs, strings); + t.topDictIndex = makeTopDictIndex(topDict); + t.globalSubrIndex = makeGlobalSubrIndex(); + t.charsets = makeCharsets(glyphNames, strings); + t.charStringsIndex = makeCharStringsIndex(glyphs); + t.privateDict = makePrivateDict(privateAttrs, strings); + + // Needs to come at the end, to encode all custom strings used in the font. + t.stringIndex = makeStringIndex(strings); + + var startOffset = + t.header.sizeOf() + + t.nameIndex.sizeOf() + + t.topDictIndex.sizeOf() + + t.stringIndex.sizeOf() + + t.globalSubrIndex.sizeOf(); + attrs.charset = startOffset; + + // We use the CFF standard encoding; proper encoding will be handled in cmap. + attrs.encoding = 0; + attrs.charStrings = attrs.charset + t.charsets.sizeOf(); + attrs.private[1] = attrs.charStrings + t.charStringsIndex.sizeOf(); + + // Recreate the Top DICT INDEX with the correct offsets. + topDict = makeTopDict(attrs, strings); + t.topDictIndex = makeTopDictIndex(topDict); + + return t; + } + + var cff = { parse: parseCFFTable, make: makeCFFTable }; + + // The `head` table contains global information about the font. + + // Parse the header `head` table + function parseHeadTable(data, start) { + var head = {}; + var p = new parse.Parser(data, start); + head.version = p.parseVersion(); + head.fontRevision = Math.round(p.parseFixed() * 1000) / 1000; + head.checkSumAdjustment = p.parseULong(); + head.magicNumber = p.parseULong(); + check.argument( + head.magicNumber === 0x5f0f3cf5, + 'Font header has wrong magic number.' + ); + head.flags = p.parseUShort(); + head.unitsPerEm = p.parseUShort(); + head.created = p.parseLongDateTime(); + head.modified = p.parseLongDateTime(); + head.xMin = p.parseShort(); + head.yMin = p.parseShort(); + head.xMax = p.parseShort(); + head.yMax = p.parseShort(); + head.macStyle = p.parseUShort(); + head.lowestRecPPEM = p.parseUShort(); + head.fontDirectionHint = p.parseShort(); + head.indexToLocFormat = p.parseShort(); + head.glyphDataFormat = p.parseShort(); + return head; + } + + function makeHeadTable(options) { + // Apple Mac timestamp epoch is 01/01/1904 not 01/01/1970 + var timestamp = Math.round(new Date().getTime() / 1000) + 2082844800; + var createdTimestamp = timestamp; + + if (options.createdTimestamp) { + createdTimestamp = options.createdTimestamp + 2082844800; + } + + return new table.Table( + 'head', + [ + { name: 'version', type: 'FIXED', value: 0x00010000 }, + { name: 'fontRevision', type: 'FIXED', value: 0x00010000 }, + { name: 'checkSumAdjustment', type: 'ULONG', value: 0 }, + { name: 'magicNumber', type: 'ULONG', value: 0x5f0f3cf5 }, + { name: 'flags', type: 'USHORT', value: 0 }, + { name: 'unitsPerEm', type: 'USHORT', value: 1000 }, + { name: 'created', type: 'LONGDATETIME', value: createdTimestamp }, + { name: 'modified', type: 'LONGDATETIME', value: timestamp }, + { name: 'xMin', type: 'SHORT', value: 0 }, + { name: 'yMin', type: 'SHORT', value: 0 }, + { name: 'xMax', type: 'SHORT', value: 0 }, + { name: 'yMax', type: 'SHORT', value: 0 }, + { name: 'macStyle', type: 'USHORT', value: 0 }, + { name: 'lowestRecPPEM', type: 'USHORT', value: 0 }, + { name: 'fontDirectionHint', type: 'SHORT', value: 2 }, + { name: 'indexToLocFormat', type: 'SHORT', value: 0 }, + { name: 'glyphDataFormat', type: 'SHORT', value: 0 } + ], + options + ); + } + + var head = { parse: parseHeadTable, make: makeHeadTable }; + + // The `hhea` table contains information for horizontal layout. + + // Parse the horizontal header `hhea` table + function parseHheaTable(data, start) { + var hhea = {}; + var p = new parse.Parser(data, start); + hhea.version = p.parseVersion(); + hhea.ascender = p.parseShort(); + hhea.descender = p.parseShort(); + hhea.lineGap = p.parseShort(); + hhea.advanceWidthMax = p.parseUShort(); + hhea.minLeftSideBearing = p.parseShort(); + hhea.minRightSideBearing = p.parseShort(); + hhea.xMaxExtent = p.parseShort(); + hhea.caretSlopeRise = p.parseShort(); + hhea.caretSlopeRun = p.parseShort(); + hhea.caretOffset = p.parseShort(); + p.relativeOffset += 8; + hhea.metricDataFormat = p.parseShort(); + hhea.numberOfHMetrics = p.parseUShort(); + return hhea; + } + + function makeHheaTable(options) { + return new table.Table( + 'hhea', + [ + { name: 'version', type: 'FIXED', value: 0x00010000 }, + { name: 'ascender', type: 'FWORD', value: 0 }, + { name: 'descender', type: 'FWORD', value: 0 }, + { name: 'lineGap', type: 'FWORD', value: 0 }, + { name: 'advanceWidthMax', type: 'UFWORD', value: 0 }, + { name: 'minLeftSideBearing', type: 'FWORD', value: 0 }, + { name: 'minRightSideBearing', type: 'FWORD', value: 0 }, + { name: 'xMaxExtent', type: 'FWORD', value: 0 }, + { name: 'caretSlopeRise', type: 'SHORT', value: 1 }, + { name: 'caretSlopeRun', type: 'SHORT', value: 0 }, + { name: 'caretOffset', type: 'SHORT', value: 0 }, + { name: 'reserved1', type: 'SHORT', value: 0 }, + { name: 'reserved2', type: 'SHORT', value: 0 }, + { name: 'reserved3', type: 'SHORT', value: 0 }, + { name: 'reserved4', type: 'SHORT', value: 0 }, + { name: 'metricDataFormat', type: 'SHORT', value: 0 }, + { name: 'numberOfHMetrics', type: 'USHORT', value: 0 } + ], + options + ); + } + + var hhea = { parse: parseHheaTable, make: makeHheaTable }; + + // The `hmtx` table contains the horizontal metrics for all glyphs. + + // Parse the `hmtx` table, which contains the horizontal metrics for all glyphs. + // This function augments the glyph array, adding the advanceWidth and leftSideBearing to each glyph. + function parseHmtxTable(data, start, numMetrics, numGlyphs, glyphs) { + var advanceWidth; + var leftSideBearing; + var p = new parse.Parser(data, start); + for (var i = 0; i < numGlyphs; i += 1) { + // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs. + if (i < numMetrics) { + advanceWidth = p.parseUShort(); + leftSideBearing = p.parseShort(); + } + + var glyph = glyphs.get(i); + glyph.advanceWidth = advanceWidth; + glyph.leftSideBearing = leftSideBearing; + } + } + + function makeHmtxTable(glyphs) { + var t = new table.Table('hmtx', []); + for (var i = 0; i < glyphs.length; i += 1) { + var glyph = glyphs.get(i); + var advanceWidth = glyph.advanceWidth || 0; + var leftSideBearing = glyph.leftSideBearing || 0; + t.fields.push({ + name: 'advanceWidth_' + i, + type: 'USHORT', + value: advanceWidth + }); + t.fields.push({ + name: 'leftSideBearing_' + i, + type: 'SHORT', + value: leftSideBearing + }); + } + + return t; + } + + var hmtx = { parse: parseHmtxTable, make: makeHmtxTable }; + + // The `ltag` table stores IETF BCP-47 language tags. It allows supporting + + function makeLtagTable(tags) { + var result = new table.Table('ltag', [ + { name: 'version', type: 'ULONG', value: 1 }, + { name: 'flags', type: 'ULONG', value: 0 }, + { name: 'numTags', type: 'ULONG', value: tags.length } + ]); + + var stringPool = ''; + var stringPoolOffset = 12 + tags.length * 4; + for (var i = 0; i < tags.length; ++i) { + var pos = stringPool.indexOf(tags[i]); + if (pos < 0) { + pos = stringPool.length; + stringPool += tags[i]; + } + + result.fields.push({ + name: 'offset ' + i, + type: 'USHORT', + value: stringPoolOffset + pos + }); + result.fields.push({ + name: 'length ' + i, + type: 'USHORT', + value: tags[i].length + }); + } + + result.fields.push({ + name: 'stringPool', + type: 'CHARARRAY', + value: stringPool + }); + return result; + } + + function parseLtagTable(data, start) { + var p = new parse.Parser(data, start); + var tableVersion = p.parseULong(); + check.argument(tableVersion === 1, 'Unsupported ltag table version.'); + // The 'ltag' specification does not define any flags; skip the field. + p.skip('uLong', 1); + var numTags = p.parseULong(); + + var tags = []; + for (var i = 0; i < numTags; i++) { + var tag = ''; + var offset = start + p.parseUShort(); + var length = p.parseUShort(); + for (var j = offset; j < offset + length; ++j) { + tag += String.fromCharCode(data.getInt8(j)); + } + + tags.push(tag); + } + + return tags; + } + + var ltag = { make: makeLtagTable, parse: parseLtagTable }; + + // The `maxp` table establishes the memory requirements for the font. + + // Parse the maximum profile `maxp` table. + function parseMaxpTable(data, start) { + var maxp = {}; + var p = new parse.Parser(data, start); + maxp.version = p.parseVersion(); + maxp.numGlyphs = p.parseUShort(); + if (maxp.version === 1.0) { + maxp.maxPoints = p.parseUShort(); + maxp.maxContours = p.parseUShort(); + maxp.maxCompositePoints = p.parseUShort(); + maxp.maxCompositeContours = p.parseUShort(); + maxp.maxZones = p.parseUShort(); + maxp.maxTwilightPoints = p.parseUShort(); + maxp.maxStorage = p.parseUShort(); + maxp.maxFunctionDefs = p.parseUShort(); + maxp.maxInstructionDefs = p.parseUShort(); + maxp.maxStackElements = p.parseUShort(); + maxp.maxSizeOfInstructions = p.parseUShort(); + maxp.maxComponentElements = p.parseUShort(); + maxp.maxComponentDepth = p.parseUShort(); + } + + return maxp; + } + + function makeMaxpTable(numGlyphs) { + return new table.Table('maxp', [ + { name: 'version', type: 'FIXED', value: 0x00005000 }, + { name: 'numGlyphs', type: 'USHORT', value: numGlyphs } + ]); + } + + var maxp = { parse: parseMaxpTable, make: makeMaxpTable }; + + // The `name` naming table. + + // NameIDs for the name table. + var nameTableNames = [ + 'copyright', // 0 + 'fontFamily', // 1 + 'fontSubfamily', // 2 + 'uniqueID', // 3 + 'fullName', // 4 + 'version', // 5 + 'postScriptName', // 6 + 'trademark', // 7 + 'manufacturer', // 8 + 'designer', // 9 + 'description', // 10 + 'manufacturerURL', // 11 + 'designerURL', // 12 + 'license', // 13 + 'licenseURL', // 14 + 'reserved', // 15 + 'preferredFamily', // 16 + 'preferredSubfamily', // 17 + 'compatibleFullName', // 18 + 'sampleText', // 19 + 'postScriptFindFontName', // 20 + 'wwsFamily', // 21 + 'wwsSubfamily' // 22 + ]; + + var macLanguages = { + 0: 'en', + 1: 'fr', + 2: 'de', + 3: 'it', + 4: 'nl', + 5: 'sv', + 6: 'es', + 7: 'da', + 8: 'pt', + 9: 'no', + 10: 'he', + 11: 'ja', + 12: 'ar', + 13: 'fi', + 14: 'el', + 15: 'is', + 16: 'mt', + 17: 'tr', + 18: 'hr', + 19: 'zh-Hant', + 20: 'ur', + 21: 'hi', + 22: 'th', + 23: 'ko', + 24: 'lt', + 25: 'pl', + 26: 'hu', + 27: 'es', + 28: 'lv', + 29: 'se', + 30: 'fo', + 31: 'fa', + 32: 'ru', + 33: 'zh', + 34: 'nl-BE', + 35: 'ga', + 36: 'sq', + 37: 'ro', + 38: 'cz', + 39: 'sk', + 40: 'si', + 41: 'yi', + 42: 'sr', + 43: 'mk', + 44: 'bg', + 45: 'uk', + 46: 'be', + 47: 'uz', + 48: 'kk', + 49: 'az-Cyrl', + 50: 'az-Arab', + 51: 'hy', + 52: 'ka', + 53: 'mo', + 54: 'ky', + 55: 'tg', + 56: 'tk', + 57: 'mn-CN', + 58: 'mn', + 59: 'ps', + 60: 'ks', + 61: 'ku', + 62: 'sd', + 63: 'bo', + 64: 'ne', + 65: 'sa', + 66: 'mr', + 67: 'bn', + 68: 'as', + 69: 'gu', + 70: 'pa', + 71: 'or', + 72: 'ml', + 73: 'kn', + 74: 'ta', + 75: 'te', + 76: 'si', + 77: 'my', + 78: 'km', + 79: 'lo', + 80: 'vi', + 81: 'id', + 82: 'tl', + 83: 'ms', + 84: 'ms-Arab', + 85: 'am', + 86: 'ti', + 87: 'om', + 88: 'so', + 89: 'sw', + 90: 'rw', + 91: 'rn', + 92: 'ny', + 93: 'mg', + 94: 'eo', + 128: 'cy', + 129: 'eu', + 130: 'ca', + 131: 'la', + 132: 'qu', + 133: 'gn', + 134: 'ay', + 135: 'tt', + 136: 'ug', + 137: 'dz', + 138: 'jv', + 139: 'su', + 140: 'gl', + 141: 'af', + 142: 'br', + 143: 'iu', + 144: 'gd', + 145: 'gv', + 146: 'ga', + 147: 'to', + 148: 'el-polyton', + 149: 'kl', + 150: 'az', + 151: 'nn' + }; + + // MacOS language ID → MacOS script ID + // + // Note that the script ID is not sufficient to determine what encoding + // to use in TrueType files. For some languages, MacOS used a modification + // of a mainstream script. For example, an Icelandic name would be stored + // with smRoman in the TrueType naming table, but the actual encoding + // is a special Icelandic version of the normal Macintosh Roman encoding. + // As another example, Inuktitut uses an 8-bit encoding for Canadian Aboriginal + // Syllables but MacOS had run out of available script codes, so this was + // done as a (pretty radical) "modification" of Ethiopic. + // + // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt + var macLanguageToScript = { + 0: 0, // langEnglish → smRoman + 1: 0, // langFrench → smRoman + 2: 0, // langGerman → smRoman + 3: 0, // langItalian → smRoman + 4: 0, // langDutch → smRoman + 5: 0, // langSwedish → smRoman + 6: 0, // langSpanish → smRoman + 7: 0, // langDanish → smRoman + 8: 0, // langPortuguese → smRoman + 9: 0, // langNorwegian → smRoman + 10: 5, // langHebrew → smHebrew + 11: 1, // langJapanese → smJapanese + 12: 4, // langArabic → smArabic + 13: 0, // langFinnish → smRoman + 14: 6, // langGreek → smGreek + 15: 0, // langIcelandic → smRoman (modified) + 16: 0, // langMaltese → smRoman + 17: 0, // langTurkish → smRoman (modified) + 18: 0, // langCroatian → smRoman (modified) + 19: 2, // langTradChinese → smTradChinese + 20: 4, // langUrdu → smArabic + 21: 9, // langHindi → smDevanagari + 22: 21, // langThai → smThai + 23: 3, // langKorean → smKorean + 24: 29, // langLithuanian → smCentralEuroRoman + 25: 29, // langPolish → smCentralEuroRoman + 26: 29, // langHungarian → smCentralEuroRoman + 27: 29, // langEstonian → smCentralEuroRoman + 28: 29, // langLatvian → smCentralEuroRoman + 29: 0, // langSami → smRoman + 30: 0, // langFaroese → smRoman (modified) + 31: 4, // langFarsi → smArabic (modified) + 32: 7, // langRussian → smCyrillic + 33: 25, // langSimpChinese → smSimpChinese + 34: 0, // langFlemish → smRoman + 35: 0, // langIrishGaelic → smRoman (modified) + 36: 0, // langAlbanian → smRoman + 37: 0, // langRomanian → smRoman (modified) + 38: 29, // langCzech → smCentralEuroRoman + 39: 29, // langSlovak → smCentralEuroRoman + 40: 0, // langSlovenian → smRoman (modified) + 41: 5, // langYiddish → smHebrew + 42: 7, // langSerbian → smCyrillic + 43: 7, // langMacedonian → smCyrillic + 44: 7, // langBulgarian → smCyrillic + 45: 7, // langUkrainian → smCyrillic (modified) + 46: 7, // langByelorussian → smCyrillic + 47: 7, // langUzbek → smCyrillic + 48: 7, // langKazakh → smCyrillic + 49: 7, // langAzerbaijani → smCyrillic + 50: 4, // langAzerbaijanAr → smArabic + 51: 24, // langArmenian → smArmenian + 52: 23, // langGeorgian → smGeorgian + 53: 7, // langMoldavian → smCyrillic + 54: 7, // langKirghiz → smCyrillic + 55: 7, // langTajiki → smCyrillic + 56: 7, // langTurkmen → smCyrillic + 57: 27, // langMongolian → smMongolian + 58: 7, // langMongolianCyr → smCyrillic + 59: 4, // langPashto → smArabic + 60: 4, // langKurdish → smArabic + 61: 4, // langKashmiri → smArabic + 62: 4, // langSindhi → smArabic + 63: 26, // langTibetan → smTibetan + 64: 9, // langNepali → smDevanagari + 65: 9, // langSanskrit → smDevanagari + 66: 9, // langMarathi → smDevanagari + 67: 13, // langBengali → smBengali + 68: 13, // langAssamese → smBengali + 69: 11, // langGujarati → smGujarati + 70: 10, // langPunjabi → smGurmukhi + 71: 12, // langOriya → smOriya + 72: 17, // langMalayalam → smMalayalam + 73: 16, // langKannada → smKannada + 74: 14, // langTamil → smTamil + 75: 15, // langTelugu → smTelugu + 76: 18, // langSinhalese → smSinhalese + 77: 19, // langBurmese → smBurmese + 78: 20, // langKhmer → smKhmer + 79: 22, // langLao → smLao + 80: 30, // langVietnamese → smVietnamese + 81: 0, // langIndonesian → smRoman + 82: 0, // langTagalog → smRoman + 83: 0, // langMalayRoman → smRoman + 84: 4, // langMalayArabic → smArabic + 85: 28, // langAmharic → smEthiopic + 86: 28, // langTigrinya → smEthiopic + 87: 28, // langOromo → smEthiopic + 88: 0, // langSomali → smRoman + 89: 0, // langSwahili → smRoman + 90: 0, // langKinyarwanda → smRoman + 91: 0, // langRundi → smRoman + 92: 0, // langNyanja → smRoman + 93: 0, // langMalagasy → smRoman + 94: 0, // langEsperanto → smRoman + 128: 0, // langWelsh → smRoman (modified) + 129: 0, // langBasque → smRoman + 130: 0, // langCatalan → smRoman + 131: 0, // langLatin → smRoman + 132: 0, // langQuechua → smRoman + 133: 0, // langGuarani → smRoman + 134: 0, // langAymara → smRoman + 135: 7, // langTatar → smCyrillic + 136: 4, // langUighur → smArabic + 137: 26, // langDzongkha → smTibetan + 138: 0, // langJavaneseRom → smRoman + 139: 0, // langSundaneseRom → smRoman + 140: 0, // langGalician → smRoman + 141: 0, // langAfrikaans → smRoman + 142: 0, // langBreton → smRoman (modified) + 143: 28, // langInuktitut → smEthiopic (modified) + 144: 0, // langScottishGaelic → smRoman (modified) + 145: 0, // langManxGaelic → smRoman (modified) + 146: 0, // langIrishGaelicScript → smRoman (modified) + 147: 0, // langTongan → smRoman + 148: 6, // langGreekAncient → smRoman + 149: 0, // langGreenlandic → smRoman + 150: 0, // langAzerbaijanRoman → smRoman + 151: 0 // langNynorsk → smRoman + }; + + // While Microsoft indicates a region/country for all its language + // IDs, we omit the region code if it's equal to the "most likely + // region subtag" according to Unicode CLDR. For scripts, we omit + // the subtag if it is equal to the Suppress-Script entry in the + // IANA language subtag registry for IETF BCP 47. + // + // For example, Microsoft states that its language code 0x041A is + // Croatian in Croatia. We transform this to the BCP 47 language code 'hr' + // and not 'hr-HR' because Croatia is the default country for Croatian, + // according to Unicode CLDR. As another example, Microsoft states + // that 0x101A is Croatian (Latin) in Bosnia-Herzegovina. We transform + // this to 'hr-BA' and not 'hr-Latn-BA' because Latin is the default script + // for the Croatian language, according to IANA. + // + // http://www.unicode.org/cldr/charts/latest/supplemental/likely_subtags.html + // http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry + var windowsLanguages = { + 0x0436: 'af', + 0x041c: 'sq', + 0x0484: 'gsw', + 0x045e: 'am', + 0x1401: 'ar-DZ', + 0x3c01: 'ar-BH', + 0x0c01: 'ar', + 0x0801: 'ar-IQ', + 0x2c01: 'ar-JO', + 0x3401: 'ar-KW', + 0x3001: 'ar-LB', + 0x1001: 'ar-LY', + 0x1801: 'ary', + 0x2001: 'ar-OM', + 0x4001: 'ar-QA', + 0x0401: 'ar-SA', + 0x2801: 'ar-SY', + 0x1c01: 'aeb', + 0x3801: 'ar-AE', + 0x2401: 'ar-YE', + 0x042b: 'hy', + 0x044d: 'as', + 0x082c: 'az-Cyrl', + 0x042c: 'az', + 0x046d: 'ba', + 0x042d: 'eu', + 0x0423: 'be', + 0x0845: 'bn', + 0x0445: 'bn-IN', + 0x201a: 'bs-Cyrl', + 0x141a: 'bs', + 0x047e: 'br', + 0x0402: 'bg', + 0x0403: 'ca', + 0x0c04: 'zh-HK', + 0x1404: 'zh-MO', + 0x0804: 'zh', + 0x1004: 'zh-SG', + 0x0404: 'zh-TW', + 0x0483: 'co', + 0x041a: 'hr', + 0x101a: 'hr-BA', + 0x0405: 'cs', + 0x0406: 'da', + 0x048c: 'prs', + 0x0465: 'dv', + 0x0813: 'nl-BE', + 0x0413: 'nl', + 0x0c09: 'en-AU', + 0x2809: 'en-BZ', + 0x1009: 'en-CA', + 0x2409: 'en-029', + 0x4009: 'en-IN', + 0x1809: 'en-IE', + 0x2009: 'en-JM', + 0x4409: 'en-MY', + 0x1409: 'en-NZ', + 0x3409: 'en-PH', + 0x4809: 'en-SG', + 0x1c09: 'en-ZA', + 0x2c09: 'en-TT', + 0x0809: 'en-GB', + 0x0409: 'en', + 0x3009: 'en-ZW', + 0x0425: 'et', + 0x0438: 'fo', + 0x0464: 'fil', + 0x040b: 'fi', + 0x080c: 'fr-BE', + 0x0c0c: 'fr-CA', + 0x040c: 'fr', + 0x140c: 'fr-LU', + 0x180c: 'fr-MC', + 0x100c: 'fr-CH', + 0x0462: 'fy', + 0x0456: 'gl', + 0x0437: 'ka', + 0x0c07: 'de-AT', + 0x0407: 'de', + 0x1407: 'de-LI', + 0x1007: 'de-LU', + 0x0807: 'de-CH', + 0x0408: 'el', + 0x046f: 'kl', + 0x0447: 'gu', + 0x0468: 'ha', + 0x040d: 'he', + 0x0439: 'hi', + 0x040e: 'hu', + 0x040f: 'is', + 0x0470: 'ig', + 0x0421: 'id', + 0x045d: 'iu', + 0x085d: 'iu-Latn', + 0x083c: 'ga', + 0x0434: 'xh', + 0x0435: 'zu', + 0x0410: 'it', + 0x0810: 'it-CH', + 0x0411: 'ja', + 0x044b: 'kn', + 0x043f: 'kk', + 0x0453: 'km', + 0x0486: 'quc', + 0x0487: 'rw', + 0x0441: 'sw', + 0x0457: 'kok', + 0x0412: 'ko', + 0x0440: 'ky', + 0x0454: 'lo', + 0x0426: 'lv', + 0x0427: 'lt', + 0x082e: 'dsb', + 0x046e: 'lb', + 0x042f: 'mk', + 0x083e: 'ms-BN', + 0x043e: 'ms', + 0x044c: 'ml', + 0x043a: 'mt', + 0x0481: 'mi', + 0x047a: 'arn', + 0x044e: 'mr', + 0x047c: 'moh', + 0x0450: 'mn', + 0x0850: 'mn-CN', + 0x0461: 'ne', + 0x0414: 'nb', + 0x0814: 'nn', + 0x0482: 'oc', + 0x0448: 'or', + 0x0463: 'ps', + 0x0415: 'pl', + 0x0416: 'pt', + 0x0816: 'pt-PT', + 0x0446: 'pa', + 0x046b: 'qu-BO', + 0x086b: 'qu-EC', + 0x0c6b: 'qu', + 0x0418: 'ro', + 0x0417: 'rm', + 0x0419: 'ru', + 0x243b: 'smn', + 0x103b: 'smj-NO', + 0x143b: 'smj', + 0x0c3b: 'se-FI', + 0x043b: 'se', + 0x083b: 'se-SE', + 0x203b: 'sms', + 0x183b: 'sma-NO', + 0x1c3b: 'sms', + 0x044f: 'sa', + 0x1c1a: 'sr-Cyrl-BA', + 0x0c1a: 'sr', + 0x181a: 'sr-Latn-BA', + 0x081a: 'sr-Latn', + 0x046c: 'nso', + 0x0432: 'tn', + 0x045b: 'si', + 0x041b: 'sk', + 0x0424: 'sl', + 0x2c0a: 'es-AR', + 0x400a: 'es-BO', + 0x340a: 'es-CL', + 0x240a: 'es-CO', + 0x140a: 'es-CR', + 0x1c0a: 'es-DO', + 0x300a: 'es-EC', + 0x440a: 'es-SV', + 0x100a: 'es-GT', + 0x480a: 'es-HN', + 0x080a: 'es-MX', + 0x4c0a: 'es-NI', + 0x180a: 'es-PA', + 0x3c0a: 'es-PY', + 0x280a: 'es-PE', + 0x500a: 'es-PR', + + // Microsoft has defined two different language codes for + // “Spanish with modern sorting” and “Spanish with traditional + // sorting”. This makes sense for collation APIs, and it would be + // possible to express this in BCP 47 language tags via Unicode + // extensions (eg., es-u-co-trad is Spanish with traditional + // sorting). However, for storing names in fonts, the distinction + // does not make sense, so we give “es” in both cases. + 0x0c0a: 'es', + 0x040a: 'es', + + 0x540a: 'es-US', + 0x380a: 'es-UY', + 0x200a: 'es-VE', + 0x081d: 'sv-FI', + 0x041d: 'sv', + 0x045a: 'syr', + 0x0428: 'tg', + 0x085f: 'tzm', + 0x0449: 'ta', + 0x0444: 'tt', + 0x044a: 'te', + 0x041e: 'th', + 0x0451: 'bo', + 0x041f: 'tr', + 0x0442: 'tk', + 0x0480: 'ug', + 0x0422: 'uk', + 0x042e: 'hsb', + 0x0420: 'ur', + 0x0843: 'uz-Cyrl', + 0x0443: 'uz', + 0x042a: 'vi', + 0x0452: 'cy', + 0x0488: 'wo', + 0x0485: 'sah', + 0x0478: 'ii', + 0x046a: 'yo' + }; + + // Returns a IETF BCP 47 language code, for example 'zh-Hant' + // for 'Chinese in the traditional script'. + function getLanguageCode(platformID, languageID, ltag) { + switch (platformID) { + case 0: // Unicode + if (languageID === 0xffff) { + return 'und'; + } else if (ltag) { + return ltag[languageID]; + } + + break; + + case 1: // Macintosh + return macLanguages[languageID]; + + case 3: // Windows + return windowsLanguages[languageID]; + } + + return undefined; + } + + var utf16 = 'utf-16'; + + // MacOS script ID → encoding. This table stores the default case, + // which can be overridden by macLanguageEncodings. + var macScriptEncodings = { + 0: 'macintosh', // smRoman + 1: 'x-mac-japanese', // smJapanese + 2: 'x-mac-chinesetrad', // smTradChinese + 3: 'x-mac-korean', // smKorean + 6: 'x-mac-greek', // smGreek + 7: 'x-mac-cyrillic', // smCyrillic + 9: 'x-mac-devanagai', // smDevanagari + 10: 'x-mac-gurmukhi', // smGurmukhi + 11: 'x-mac-gujarati', // smGujarati + 12: 'x-mac-oriya', // smOriya + 13: 'x-mac-bengali', // smBengali + 14: 'x-mac-tamil', // smTamil + 15: 'x-mac-telugu', // smTelugu + 16: 'x-mac-kannada', // smKannada + 17: 'x-mac-malayalam', // smMalayalam + 18: 'x-mac-sinhalese', // smSinhalese + 19: 'x-mac-burmese', // smBurmese + 20: 'x-mac-khmer', // smKhmer + 21: 'x-mac-thai', // smThai + 22: 'x-mac-lao', // smLao + 23: 'x-mac-georgian', // smGeorgian + 24: 'x-mac-armenian', // smArmenian + 25: 'x-mac-chinesesimp', // smSimpChinese + 26: 'x-mac-tibetan', // smTibetan + 27: 'x-mac-mongolian', // smMongolian + 28: 'x-mac-ethiopic', // smEthiopic + 29: 'x-mac-ce', // smCentralEuroRoman + 30: 'x-mac-vietnamese', // smVietnamese + 31: 'x-mac-extarabic' // smExtArabic + }; + + // MacOS language ID → encoding. This table stores the exceptional + // cases, which override macScriptEncodings. For writing MacOS naming + // tables, we need to emit a MacOS script ID. Therefore, we cannot + // merge macScriptEncodings into macLanguageEncodings. + // + // http://unicode.org/Public/MAPPINGS/VENDORS/APPLE/Readme.txt + var macLanguageEncodings = { + 15: 'x-mac-icelandic', // langIcelandic + 17: 'x-mac-turkish', // langTurkish + 18: 'x-mac-croatian', // langCroatian + 24: 'x-mac-ce', // langLithuanian + 25: 'x-mac-ce', // langPolish + 26: 'x-mac-ce', // langHungarian + 27: 'x-mac-ce', // langEstonian + 28: 'x-mac-ce', // langLatvian + 30: 'x-mac-icelandic', // langFaroese + 37: 'x-mac-romanian', // langRomanian + 38: 'x-mac-ce', // langCzech + 39: 'x-mac-ce', // langSlovak + 40: 'x-mac-ce', // langSlovenian + 143: 'x-mac-inuit', // langInuktitut + 146: 'x-mac-gaelic' // langIrishGaelicScript + }; + + function getEncoding(platformID, encodingID, languageID) { + switch (platformID) { + case 0: // Unicode + return utf16; + + case 1: // Apple Macintosh + return ( + macLanguageEncodings[languageID] || macScriptEncodings[encodingID] + ); + + case 3: // Microsoft Windows + if (encodingID === 1 || encodingID === 10) { + return utf16; + } + + break; + } + + return undefined; + } + + // Parse the naming `name` table. + // FIXME: Format 1 additional fields are not supported yet. + // ltag is the content of the `ltag' table, such as ['en', 'zh-Hans', 'de-CH-1904']. + function parseNameTable(data, start, ltag) { + var name = {}; + var p = new parse.Parser(data, start); + var format = p.parseUShort(); + var count = p.parseUShort(); + var stringOffset = p.offset + p.parseUShort(); + for (var i = 0; i < count; i++) { + var platformID = p.parseUShort(); + var encodingID = p.parseUShort(); + var languageID = p.parseUShort(); + var nameID = p.parseUShort(); + var property = nameTableNames[nameID] || nameID; + var byteLength = p.parseUShort(); + var offset = p.parseUShort(); + var language = getLanguageCode(platformID, languageID, ltag); + var encoding = getEncoding(platformID, encodingID, languageID); + if (encoding !== undefined && language !== undefined) { + var text = void 0; + if (encoding === utf16) { + text = decode.UTF16(data, stringOffset + offset, byteLength); + } else { + text = decode.MACSTRING( + data, + stringOffset + offset, + byteLength, + encoding + ); + } + + if (text) { + var translations = name[property]; + if (translations === undefined) { + translations = name[property] = {}; + } + + translations[language] = text; + } + } + } + + var langTagCount = 0; + if (format === 1) { + // FIXME: Also handle Microsoft's 'name' table 1. + langTagCount = p.parseUShort(); + } + + return name; + } + + // {23: 'foo'} → {'foo': 23} + // ['bar', 'baz'] → {'bar': 0, 'baz': 1} + function reverseDict(dict) { + var result = {}; + for (var key in dict) { + result[dict[key]] = parseInt(key); + } + + return result; + } + + function makeNameRecord( + platformID, + encodingID, + languageID, + nameID, + length, + offset + ) { + return new table.Record('NameRecord', [ + { name: 'platformID', type: 'USHORT', value: platformID }, + { name: 'encodingID', type: 'USHORT', value: encodingID }, + { name: 'languageID', type: 'USHORT', value: languageID }, + { name: 'nameID', type: 'USHORT', value: nameID }, + { name: 'length', type: 'USHORT', value: length }, + { name: 'offset', type: 'USHORT', value: offset } + ]); + } + + // Finds the position of needle in haystack, or -1 if not there. + // Like String.indexOf(), but for arrays. + function findSubArray(needle, haystack) { + var needleLength = needle.length; + var limit = haystack.length - needleLength + 1; + + loop: for (var pos = 0; pos < limit; pos++) { + for (; pos < limit; pos++) { + for (var k = 0; k < needleLength; k++) { + if (haystack[pos + k] !== needle[k]) { + continue loop; + } + } + + return pos; + } + } + + return -1; + } + + function addStringToPool(s, pool) { + var offset = findSubArray(s, pool); + if (offset < 0) { + offset = pool.length; + var i = 0; + var len = s.length; + for (; i < len; ++i) { + pool.push(s[i]); + } + } + + return offset; + } + + function makeNameTable(names, ltag) { + var nameID; + var nameIDs = []; + + var namesWithNumericKeys = {}; + var nameTableIds = reverseDict(nameTableNames); + for (var key in names) { + var id = nameTableIds[key]; + if (id === undefined) { + id = key; + } + + nameID = parseInt(id); + + if (isNaN(nameID)) { + throw new Error( + 'Name table entry "' + + key + + '" does not exist, see nameTableNames for complete list.' + ); + } + + namesWithNumericKeys[nameID] = names[key]; + nameIDs.push(nameID); + } + + var macLanguageIds = reverseDict(macLanguages); + var windowsLanguageIds = reverseDict(windowsLanguages); + + var nameRecords = []; + var stringPool = []; + + for (var i = 0; i < nameIDs.length; i++) { + nameID = nameIDs[i]; + var translations = namesWithNumericKeys[nameID]; + for (var lang in translations) { + var text = translations[lang]; + + // For MacOS, we try to emit the name in the form that was introduced + // in the initial version of the TrueType spec (in the late 1980s). + // However, this can fail for various reasons: the requested BCP 47 + // language code might not have an old-style Mac equivalent; + // we might not have a codec for the needed character encoding; + // or the name might contain characters that cannot be expressed + // in the old-style Macintosh encoding. In case of failure, we emit + // the name in a more modern fashion (Unicode encoding with BCP 47 + // language tags) that is recognized by MacOS 10.5, released in 2009. + // If fonts were only read by operating systems, we could simply + // emit all names in the modern form; this would be much easier. + // However, there are many applications and libraries that read + // 'name' tables directly, and these will usually only recognize + // the ancient form (silently skipping the unrecognized names). + var macPlatform = 1; // Macintosh + var macLanguage = macLanguageIds[lang]; + var macScript = macLanguageToScript[macLanguage]; + var macEncoding = getEncoding(macPlatform, macScript, macLanguage); + var macName = encode.MACSTRING(text, macEncoding); + if (macName === undefined) { + macPlatform = 0; // Unicode + macLanguage = ltag.indexOf(lang); + if (macLanguage < 0) { + macLanguage = ltag.length; + ltag.push(lang); + } + + macScript = 4; // Unicode 2.0 and later + macName = encode.UTF16(text); + } + + var macNameOffset = addStringToPool(macName, stringPool); + nameRecords.push( + makeNameRecord( + macPlatform, + macScript, + macLanguage, + nameID, + macName.length, + macNameOffset + ) + ); + + var winLanguage = windowsLanguageIds[lang]; + if (winLanguage !== undefined) { + var winName = encode.UTF16(text); + var winNameOffset = addStringToPool(winName, stringPool); + nameRecords.push( + makeNameRecord( + 3, + 1, + winLanguage, + nameID, + winName.length, + winNameOffset + ) + ); + } + } + } + + nameRecords.sort(function(a, b) { + return ( + a.platformID - b.platformID || + a.encodingID - b.encodingID || + a.languageID - b.languageID || + a.nameID - b.nameID + ); + }); + + var t = new table.Table('name', [ + { name: 'format', type: 'USHORT', value: 0 }, + { name: 'count', type: 'USHORT', value: nameRecords.length }, + { + name: 'stringOffset', + type: 'USHORT', + value: 6 + nameRecords.length * 12 + } + ]); + + for (var r = 0; r < nameRecords.length; r++) { + t.fields.push({ + name: 'record_' + r, + type: 'RECORD', + value: nameRecords[r] + }); + } + + t.fields.push({ name: 'strings', type: 'LITERAL', value: stringPool }); + return t; + } + + var _name = { parse: parseNameTable, make: makeNameTable }; + + // The `OS/2` table contains metrics required in OpenType fonts. + + var unicodeRanges = [ + { begin: 0x0000, end: 0x007f }, // Basic Latin + { begin: 0x0080, end: 0x00ff }, // Latin-1 Supplement + { begin: 0x0100, end: 0x017f }, // Latin Extended-A + { begin: 0x0180, end: 0x024f }, // Latin Extended-B + { begin: 0x0250, end: 0x02af }, // IPA Extensions + { begin: 0x02b0, end: 0x02ff }, // Spacing Modifier Letters + { begin: 0x0300, end: 0x036f }, // Combining Diacritical Marks + { begin: 0x0370, end: 0x03ff }, // Greek and Coptic + { begin: 0x2c80, end: 0x2cff }, // Coptic + { begin: 0x0400, end: 0x04ff }, // Cyrillic + { begin: 0x0530, end: 0x058f }, // Armenian + { begin: 0x0590, end: 0x05ff }, // Hebrew + { begin: 0xa500, end: 0xa63f }, // Vai + { begin: 0x0600, end: 0x06ff }, // Arabic + { begin: 0x07c0, end: 0x07ff }, // NKo + { begin: 0x0900, end: 0x097f }, // Devanagari + { begin: 0x0980, end: 0x09ff }, // Bengali + { begin: 0x0a00, end: 0x0a7f }, // Gurmukhi + { begin: 0x0a80, end: 0x0aff }, // Gujarati + { begin: 0x0b00, end: 0x0b7f }, // Oriya + { begin: 0x0b80, end: 0x0bff }, // Tamil + { begin: 0x0c00, end: 0x0c7f }, // Telugu + { begin: 0x0c80, end: 0x0cff }, // Kannada + { begin: 0x0d00, end: 0x0d7f }, // Malayalam + { begin: 0x0e00, end: 0x0e7f }, // Thai + { begin: 0x0e80, end: 0x0eff }, // Lao + { begin: 0x10a0, end: 0x10ff }, // Georgian + { begin: 0x1b00, end: 0x1b7f }, // Balinese + { begin: 0x1100, end: 0x11ff }, // Hangul Jamo + { begin: 0x1e00, end: 0x1eff }, // Latin Extended Additional + { begin: 0x1f00, end: 0x1fff }, // Greek Extended + { begin: 0x2000, end: 0x206f }, // General Punctuation + { begin: 0x2070, end: 0x209f }, // Superscripts And Subscripts + { begin: 0x20a0, end: 0x20cf }, // Currency Symbol + { begin: 0x20d0, end: 0x20ff }, // Combining Diacritical Marks For Symbols + { begin: 0x2100, end: 0x214f }, // Letterlike Symbols + { begin: 0x2150, end: 0x218f }, // Number Forms + { begin: 0x2190, end: 0x21ff }, // Arrows + { begin: 0x2200, end: 0x22ff }, // Mathematical Operators + { begin: 0x2300, end: 0x23ff }, // Miscellaneous Technical + { begin: 0x2400, end: 0x243f }, // Control Pictures + { begin: 0x2440, end: 0x245f }, // Optical Character Recognition + { begin: 0x2460, end: 0x24ff }, // Enclosed Alphanumerics + { begin: 0x2500, end: 0x257f }, // Box Drawing + { begin: 0x2580, end: 0x259f }, // Block Elements + { begin: 0x25a0, end: 0x25ff }, // Geometric Shapes + { begin: 0x2600, end: 0x26ff }, // Miscellaneous Symbols + { begin: 0x2700, end: 0x27bf }, // Dingbats + { begin: 0x3000, end: 0x303f }, // CJK Symbols And Punctuation + { begin: 0x3040, end: 0x309f }, // Hiragana + { begin: 0x30a0, end: 0x30ff }, // Katakana + { begin: 0x3100, end: 0x312f }, // Bopomofo + { begin: 0x3130, end: 0x318f }, // Hangul Compatibility Jamo + { begin: 0xa840, end: 0xa87f }, // Phags-pa + { begin: 0x3200, end: 0x32ff }, // Enclosed CJK Letters And Months + { begin: 0x3300, end: 0x33ff }, // CJK Compatibility + { begin: 0xac00, end: 0xd7af }, // Hangul Syllables + { begin: 0xd800, end: 0xdfff }, // Non-Plane 0 * + { begin: 0x10900, end: 0x1091f }, // Phoenicia + { begin: 0x4e00, end: 0x9fff }, // CJK Unified Ideographs + { begin: 0xe000, end: 0xf8ff }, // Private Use Area (plane 0) + { begin: 0x31c0, end: 0x31ef }, // CJK Strokes + { begin: 0xfb00, end: 0xfb4f }, // Alphabetic Presentation Forms + { begin: 0xfb50, end: 0xfdff }, // Arabic Presentation Forms-A + { begin: 0xfe20, end: 0xfe2f }, // Combining Half Marks + { begin: 0xfe10, end: 0xfe1f }, // Vertical Forms + { begin: 0xfe50, end: 0xfe6f }, // Small Form Variants + { begin: 0xfe70, end: 0xfeff }, // Arabic Presentation Forms-B + { begin: 0xff00, end: 0xffef }, // Halfwidth And Fullwidth Forms + { begin: 0xfff0, end: 0xffff }, // Specials + { begin: 0x0f00, end: 0x0fff }, // Tibetan + { begin: 0x0700, end: 0x074f }, // Syriac + { begin: 0x0780, end: 0x07bf }, // Thaana + { begin: 0x0d80, end: 0x0dff }, // Sinhala + { begin: 0x1000, end: 0x109f }, // Myanmar + { begin: 0x1200, end: 0x137f }, // Ethiopic + { begin: 0x13a0, end: 0x13ff }, // Cherokee + { begin: 0x1400, end: 0x167f }, // Unified Canadian Aboriginal Syllabics + { begin: 0x1680, end: 0x169f }, // Ogham + { begin: 0x16a0, end: 0x16ff }, // Runic + { begin: 0x1780, end: 0x17ff }, // Khmer + { begin: 0x1800, end: 0x18af }, // Mongolian + { begin: 0x2800, end: 0x28ff }, // Braille Patterns + { begin: 0xa000, end: 0xa48f }, // Yi Syllables + { begin: 0x1700, end: 0x171f }, // Tagalog + { begin: 0x10300, end: 0x1032f }, // Old Italic + { begin: 0x10330, end: 0x1034f }, // Gothic + { begin: 0x10400, end: 0x1044f }, // Deseret + { begin: 0x1d000, end: 0x1d0ff }, // Byzantine Musical Symbols + { begin: 0x1d400, end: 0x1d7ff }, // Mathematical Alphanumeric Symbols + { begin: 0xff000, end: 0xffffd }, // Private Use (plane 15) + { begin: 0xfe00, end: 0xfe0f }, // Variation Selectors + { begin: 0xe0000, end: 0xe007f }, // Tags + { begin: 0x1900, end: 0x194f }, // Limbu + { begin: 0x1950, end: 0x197f }, // Tai Le + { begin: 0x1980, end: 0x19df }, // New Tai Lue + { begin: 0x1a00, end: 0x1a1f }, // Buginese + { begin: 0x2c00, end: 0x2c5f }, // Glagolitic + { begin: 0x2d30, end: 0x2d7f }, // Tifinagh + { begin: 0x4dc0, end: 0x4dff }, // Yijing Hexagram Symbols + { begin: 0xa800, end: 0xa82f }, // Syloti Nagri + { begin: 0x10000, end: 0x1007f }, // Linear B Syllabary + { begin: 0x10140, end: 0x1018f }, // Ancient Greek Numbers + { begin: 0x10380, end: 0x1039f }, // Ugaritic + { begin: 0x103a0, end: 0x103df }, // Old Persian + { begin: 0x10450, end: 0x1047f }, // Shavian + { begin: 0x10480, end: 0x104af }, // Osmanya + { begin: 0x10800, end: 0x1083f }, // Cypriot Syllabary + { begin: 0x10a00, end: 0x10a5f }, // Kharoshthi + { begin: 0x1d300, end: 0x1d35f }, // Tai Xuan Jing Symbols + { begin: 0x12000, end: 0x123ff }, // Cuneiform + { begin: 0x1d360, end: 0x1d37f }, // Counting Rod Numerals + { begin: 0x1b80, end: 0x1bbf }, // Sundanese + { begin: 0x1c00, end: 0x1c4f }, // Lepcha + { begin: 0x1c50, end: 0x1c7f }, // Ol Chiki + { begin: 0xa880, end: 0xa8df }, // Saurashtra + { begin: 0xa900, end: 0xa92f }, // Kayah Li + { begin: 0xa930, end: 0xa95f }, // Rejang + { begin: 0xaa00, end: 0xaa5f }, // Cham + { begin: 0x10190, end: 0x101cf }, // Ancient Symbols + { begin: 0x101d0, end: 0x101ff }, // Phaistos Disc + { begin: 0x102a0, end: 0x102df }, // Carian + { begin: 0x1f030, end: 0x1f09f } // Domino Tiles + ]; + + function getUnicodeRange(unicode) { + for (var i = 0; i < unicodeRanges.length; i += 1) { + var range = unicodeRanges[i]; + if (unicode >= range.begin && unicode < range.end) { + return i; + } + } + + return -1; + } + + // Parse the OS/2 and Windows metrics `OS/2` table + function parseOS2Table(data, start) { + var os2 = {}; + var p = new parse.Parser(data, start); + os2.version = p.parseUShort(); + os2.xAvgCharWidth = p.parseShort(); + os2.usWeightClass = p.parseUShort(); + os2.usWidthClass = p.parseUShort(); + os2.fsType = p.parseUShort(); + os2.ySubscriptXSize = p.parseShort(); + os2.ySubscriptYSize = p.parseShort(); + os2.ySubscriptXOffset = p.parseShort(); + os2.ySubscriptYOffset = p.parseShort(); + os2.ySuperscriptXSize = p.parseShort(); + os2.ySuperscriptYSize = p.parseShort(); + os2.ySuperscriptXOffset = p.parseShort(); + os2.ySuperscriptYOffset = p.parseShort(); + os2.yStrikeoutSize = p.parseShort(); + os2.yStrikeoutPosition = p.parseShort(); + os2.sFamilyClass = p.parseShort(); + os2.panose = []; + for (var i = 0; i < 10; i++) { + os2.panose[i] = p.parseByte(); + } + + os2.ulUnicodeRange1 = p.parseULong(); + os2.ulUnicodeRange2 = p.parseULong(); + os2.ulUnicodeRange3 = p.parseULong(); + os2.ulUnicodeRange4 = p.parseULong(); + os2.achVendID = String.fromCharCode( + p.parseByte(), + p.parseByte(), + p.parseByte(), + p.parseByte() + ); + os2.fsSelection = p.parseUShort(); + os2.usFirstCharIndex = p.parseUShort(); + os2.usLastCharIndex = p.parseUShort(); + os2.sTypoAscender = p.parseShort(); + os2.sTypoDescender = p.parseShort(); + os2.sTypoLineGap = p.parseShort(); + os2.usWinAscent = p.parseUShort(); + os2.usWinDescent = p.parseUShort(); + if (os2.version >= 1) { + os2.ulCodePageRange1 = p.parseULong(); + os2.ulCodePageRange2 = p.parseULong(); + } + + if (os2.version >= 2) { + os2.sxHeight = p.parseShort(); + os2.sCapHeight = p.parseShort(); + os2.usDefaultChar = p.parseUShort(); + os2.usBreakChar = p.parseUShort(); + os2.usMaxContent = p.parseUShort(); + } + + return os2; + } + + function makeOS2Table(options) { + return new table.Table( + 'OS/2', + [ + { name: 'version', type: 'USHORT', value: 0x0003 }, + { name: 'xAvgCharWidth', type: 'SHORT', value: 0 }, + { name: 'usWeightClass', type: 'USHORT', value: 0 }, + { name: 'usWidthClass', type: 'USHORT', value: 0 }, + { name: 'fsType', type: 'USHORT', value: 0 }, + { name: 'ySubscriptXSize', type: 'SHORT', value: 650 }, + { name: 'ySubscriptYSize', type: 'SHORT', value: 699 }, + { name: 'ySubscriptXOffset', type: 'SHORT', value: 0 }, + { name: 'ySubscriptYOffset', type: 'SHORT', value: 140 }, + { name: 'ySuperscriptXSize', type: 'SHORT', value: 650 }, + { name: 'ySuperscriptYSize', type: 'SHORT', value: 699 }, + { name: 'ySuperscriptXOffset', type: 'SHORT', value: 0 }, + { name: 'ySuperscriptYOffset', type: 'SHORT', value: 479 }, + { name: 'yStrikeoutSize', type: 'SHORT', value: 49 }, + { name: 'yStrikeoutPosition', type: 'SHORT', value: 258 }, + { name: 'sFamilyClass', type: 'SHORT', value: 0 }, + { name: 'bFamilyType', type: 'BYTE', value: 0 }, + { name: 'bSerifStyle', type: 'BYTE', value: 0 }, + { name: 'bWeight', type: 'BYTE', value: 0 }, + { name: 'bProportion', type: 'BYTE', value: 0 }, + { name: 'bContrast', type: 'BYTE', value: 0 }, + { name: 'bStrokeVariation', type: 'BYTE', value: 0 }, + { name: 'bArmStyle', type: 'BYTE', value: 0 }, + { name: 'bLetterform', type: 'BYTE', value: 0 }, + { name: 'bMidline', type: 'BYTE', value: 0 }, + { name: 'bXHeight', type: 'BYTE', value: 0 }, + { name: 'ulUnicodeRange1', type: 'ULONG', value: 0 }, + { name: 'ulUnicodeRange2', type: 'ULONG', value: 0 }, + { name: 'ulUnicodeRange3', type: 'ULONG', value: 0 }, + { name: 'ulUnicodeRange4', type: 'ULONG', value: 0 }, + { name: 'achVendID', type: 'CHARARRAY', value: 'XXXX' }, + { name: 'fsSelection', type: 'USHORT', value: 0 }, + { name: 'usFirstCharIndex', type: 'USHORT', value: 0 }, + { name: 'usLastCharIndex', type: 'USHORT', value: 0 }, + { name: 'sTypoAscender', type: 'SHORT', value: 0 }, + { name: 'sTypoDescender', type: 'SHORT', value: 0 }, + { name: 'sTypoLineGap', type: 'SHORT', value: 0 }, + { name: 'usWinAscent', type: 'USHORT', value: 0 }, + { name: 'usWinDescent', type: 'USHORT', value: 0 }, + { name: 'ulCodePageRange1', type: 'ULONG', value: 0 }, + { name: 'ulCodePageRange2', type: 'ULONG', value: 0 }, + { name: 'sxHeight', type: 'SHORT', value: 0 }, + { name: 'sCapHeight', type: 'SHORT', value: 0 }, + { name: 'usDefaultChar', type: 'USHORT', value: 0 }, + { name: 'usBreakChar', type: 'USHORT', value: 0 }, + { name: 'usMaxContext', type: 'USHORT', value: 0 } + ], + options + ); + } + + var os2 = { + parse: parseOS2Table, + make: makeOS2Table, + unicodeRanges: unicodeRanges, + getUnicodeRange: getUnicodeRange + }; + + // The `post` table stores additional PostScript information, such as glyph names. + + // Parse the PostScript `post` table + function parsePostTable(data, start) { + var post = {}; + var p = new parse.Parser(data, start); + post.version = p.parseVersion(); + post.italicAngle = p.parseFixed(); + post.underlinePosition = p.parseShort(); + post.underlineThickness = p.parseShort(); + post.isFixedPitch = p.parseULong(); + post.minMemType42 = p.parseULong(); + post.maxMemType42 = p.parseULong(); + post.minMemType1 = p.parseULong(); + post.maxMemType1 = p.parseULong(); + switch (post.version) { + case 1: + post.names = standardNames.slice(); + break; + case 2: + post.numberOfGlyphs = p.parseUShort(); + post.glyphNameIndex = new Array(post.numberOfGlyphs); + for (var i = 0; i < post.numberOfGlyphs; i++) { + post.glyphNameIndex[i] = p.parseUShort(); + } + + post.names = []; + for (var i$1 = 0; i$1 < post.numberOfGlyphs; i$1++) { + if (post.glyphNameIndex[i$1] >= standardNames.length) { + var nameLength = p.parseChar(); + post.names.push(p.parseString(nameLength)); + } + } + + break; + case 2.5: + post.numberOfGlyphs = p.parseUShort(); + post.offset = new Array(post.numberOfGlyphs); + for (var i$2 = 0; i$2 < post.numberOfGlyphs; i$2++) { + post.offset[i$2] = p.parseChar(); + } + + break; + } + return post; + } + + function makePostTable() { + return new table.Table('post', [ + { name: 'version', type: 'FIXED', value: 0x00030000 }, + { name: 'italicAngle', type: 'FIXED', value: 0 }, + { name: 'underlinePosition', type: 'FWORD', value: 0 }, + { name: 'underlineThickness', type: 'FWORD', value: 0 }, + { name: 'isFixedPitch', type: 'ULONG', value: 0 }, + { name: 'minMemType42', type: 'ULONG', value: 0 }, + { name: 'maxMemType42', type: 'ULONG', value: 0 }, + { name: 'minMemType1', type: 'ULONG', value: 0 }, + { name: 'maxMemType1', type: 'ULONG', value: 0 } + ]); + } + + var post = { parse: parsePostTable, make: makePostTable }; + + // The `GSUB` table contains ligatures, among other things. + + var subtableParsers = new Array(9); // subtableParsers[0] is unused + + // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#SS + subtableParsers[1] = function parseLookup1() { + var start = this.offset + this.relativeOffset; + var substFormat = this.parseUShort(); + if (substFormat === 1) { + return { + substFormat: 1, + coverage: this.parsePointer(Parser.coverage), + deltaGlyphId: this.parseUShort() + }; + } else if (substFormat === 2) { + return { + substFormat: 2, + coverage: this.parsePointer(Parser.coverage), + substitute: this.parseOffset16List() + }; + } + check.assert( + false, + '0x' + start.toString(16) + ': lookup type 1 format must be 1 or 2.' + ); + }; + + // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#MS + subtableParsers[2] = function parseLookup2() { + var substFormat = this.parseUShort(); + check.argument( + substFormat === 1, + 'GSUB Multiple Substitution Subtable identifier-format must be 1' + ); + return { + substFormat: substFormat, + coverage: this.parsePointer(Parser.coverage), + sequences: this.parseListOfLists() + }; + }; + + // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#AS + subtableParsers[3] = function parseLookup3() { + var substFormat = this.parseUShort(); + check.argument( + substFormat === 1, + 'GSUB Alternate Substitution Subtable identifier-format must be 1' + ); + return { + substFormat: substFormat, + coverage: this.parsePointer(Parser.coverage), + alternateSets: this.parseListOfLists() + }; + }; + + // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#LS + subtableParsers[4] = function parseLookup4() { + var substFormat = this.parseUShort(); + check.argument( + substFormat === 1, + 'GSUB ligature table identifier-format must be 1' + ); + return { + substFormat: substFormat, + coverage: this.parsePointer(Parser.coverage), + ligatureSets: this.parseListOfLists(function() { + return { + ligGlyph: this.parseUShort(), + components: this.parseUShortList(this.parseUShort() - 1) + }; + }) + }; + }; + + var lookupRecordDesc = { + sequenceIndex: Parser.uShort, + lookupListIndex: Parser.uShort + }; + + // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CSF + subtableParsers[5] = function parseLookup5() { + var start = this.offset + this.relativeOffset; + var substFormat = this.parseUShort(); + + if (substFormat === 1) { + return { + substFormat: substFormat, + coverage: this.parsePointer(Parser.coverage), + ruleSets: this.parseListOfLists(function() { + var glyphCount = this.parseUShort(); + var substCount = this.parseUShort(); + return { + input: this.parseUShortList(glyphCount - 1), + lookupRecords: this.parseRecordList(substCount, lookupRecordDesc) + }; + }) + }; + } else if (substFormat === 2) { + return { + substFormat: substFormat, + coverage: this.parsePointer(Parser.coverage), + classDef: this.parsePointer(Parser.classDef), + classSets: this.parseListOfLists(function() { + var glyphCount = this.parseUShort(); + var substCount = this.parseUShort(); + return { + classes: this.parseUShortList(glyphCount - 1), + lookupRecords: this.parseRecordList(substCount, lookupRecordDesc) + }; + }) + }; + } else if (substFormat === 3) { + var glyphCount = this.parseUShort(); + var substCount = this.parseUShort(); + return { + substFormat: substFormat, + coverages: this.parseList(glyphCount, Parser.pointer(Parser.coverage)), + lookupRecords: this.parseRecordList(substCount, lookupRecordDesc) + }; + } + check.assert( + false, + '0x' + start.toString(16) + ': lookup type 5 format must be 1, 2 or 3.' + ); + }; + + // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#CC + subtableParsers[6] = function parseLookup6() { + var start = this.offset + this.relativeOffset; + var substFormat = this.parseUShort(); + if (substFormat === 1) { + return { + substFormat: 1, + coverage: this.parsePointer(Parser.coverage), + chainRuleSets: this.parseListOfLists(function() { + return { + backtrack: this.parseUShortList(), + input: this.parseUShortList(this.parseShort() - 1), + lookahead: this.parseUShortList(), + lookupRecords: this.parseRecordList(lookupRecordDesc) + }; + }) + }; + } else if (substFormat === 2) { + return { + substFormat: 2, + coverage: this.parsePointer(Parser.coverage), + backtrackClassDef: this.parsePointer(Parser.classDef), + inputClassDef: this.parsePointer(Parser.classDef), + lookaheadClassDef: this.parsePointer(Parser.classDef), + chainClassSet: this.parseListOfLists(function() { + return { + backtrack: this.parseUShortList(), + input: this.parseUShortList(this.parseShort() - 1), + lookahead: this.parseUShortList(), + lookupRecords: this.parseRecordList(lookupRecordDesc) + }; + }) + }; + } else if (substFormat === 3) { + return { + substFormat: 3, + backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)), + inputCoverage: this.parseList(Parser.pointer(Parser.coverage)), + lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)), + lookupRecords: this.parseRecordList(lookupRecordDesc) + }; + } + check.assert( + false, + '0x' + start.toString(16) + ': lookup type 6 format must be 1, 2 or 3.' + ); + }; + + // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#ES + subtableParsers[7] = function parseLookup7() { + // Extension Substitution subtable + var substFormat = this.parseUShort(); + check.argument( + substFormat === 1, + 'GSUB Extension Substitution subtable identifier-format must be 1' + ); + var extensionLookupType = this.parseUShort(); + var extensionParser = new Parser( + this.data, + this.offset + this.parseULong() + ); + return { + substFormat: 1, + lookupType: extensionLookupType, + extension: subtableParsers[extensionLookupType].call(extensionParser) + }; + }; + + // https://www.microsoft.com/typography/OTSPEC/GSUB.htm#RCCS + subtableParsers[8] = function parseLookup8() { + var substFormat = this.parseUShort(); + check.argument( + substFormat === 1, + 'GSUB Reverse Chaining Contextual Single Substitution Subtable identifier-format must be 1' + ); + return { + substFormat: substFormat, + coverage: this.parsePointer(Parser.coverage), + backtrackCoverage: this.parseList(Parser.pointer(Parser.coverage)), + lookaheadCoverage: this.parseList(Parser.pointer(Parser.coverage)), + substitutes: this.parseUShortList() + }; + }; + + // https://www.microsoft.com/typography/OTSPEC/gsub.htm + function parseGsubTable(data, start) { + start = start || 0; + var p = new Parser(data, start); + var tableVersion = p.parseVersion(1); + check.argument( + tableVersion === 1 || tableVersion === 1.1, + 'Unsupported GSUB table version.' + ); + if (tableVersion === 1) { + return { + version: tableVersion, + scripts: p.parseScriptList(), + features: p.parseFeatureList(), + lookups: p.parseLookupList(subtableParsers) + }; + } else { + return { + version: tableVersion, + scripts: p.parseScriptList(), + features: p.parseFeatureList(), + lookups: p.parseLookupList(subtableParsers), + variations: p.parseFeatureVariationsList() + }; + } + } + + // GSUB Writing ////////////////////////////////////////////// + var subtableMakers = new Array(9); + + subtableMakers[1] = function makeLookup1(subtable) { + if (subtable.substFormat === 1) { + return new table.Table('substitutionTable', [ + { name: 'substFormat', type: 'USHORT', value: 1 }, + { + name: 'coverage', + type: 'TABLE', + value: new table.Coverage(subtable.coverage) + }, + { name: 'deltaGlyphID', type: 'USHORT', value: subtable.deltaGlyphId } + ]); + } else { + return new table.Table( + 'substitutionTable', + [ + { name: 'substFormat', type: 'USHORT', value: 2 }, + { + name: 'coverage', + type: 'TABLE', + value: new table.Coverage(subtable.coverage) + } + ].concat(table.ushortList('substitute', subtable.substitute)) + ); + } + check.fail('Lookup type 1 substFormat must be 1 or 2.'); + }; + + subtableMakers[3] = function makeLookup3(subtable) { + check.assert( + subtable.substFormat === 1, + 'Lookup type 3 substFormat must be 1.' + ); + return new table.Table( + 'substitutionTable', + [ + { name: 'substFormat', type: 'USHORT', value: 1 }, + { + name: 'coverage', + type: 'TABLE', + value: new table.Coverage(subtable.coverage) + } + ].concat( + table.tableList('altSet', subtable.alternateSets, function( + alternateSet + ) { + return new table.Table( + 'alternateSetTable', + table.ushortList('alternate', alternateSet) + ); + }) + ) + ); + }; + + subtableMakers[4] = function makeLookup4(subtable) { + check.assert( + subtable.substFormat === 1, + 'Lookup type 4 substFormat must be 1.' + ); + return new table.Table( + 'substitutionTable', + [ + { name: 'substFormat', type: 'USHORT', value: 1 }, + { + name: 'coverage', + type: 'TABLE', + value: new table.Coverage(subtable.coverage) + } + ].concat( + table.tableList('ligSet', subtable.ligatureSets, function(ligatureSet) { + return new table.Table( + 'ligatureSetTable', + table.tableList('ligature', ligatureSet, function(ligature) { + return new table.Table( + 'ligatureTable', + [ + { name: 'ligGlyph', type: 'USHORT', value: ligature.ligGlyph } + ].concat( + table.ushortList( + 'component', + ligature.components, + ligature.components.length + 1 + ) + ) + ); + }) + ); + }) + ) + ); + }; + + function makeGsubTable(gsub) { + return new table.Table('GSUB', [ + { name: 'version', type: 'ULONG', value: 0x10000 }, + { + name: 'scripts', + type: 'TABLE', + value: new table.ScriptList(gsub.scripts) + }, + { + name: 'features', + type: 'TABLE', + value: new table.FeatureList(gsub.features) + }, + { + name: 'lookups', + type: 'TABLE', + value: new table.LookupList(gsub.lookups, subtableMakers) + } + ]); + } + + var gsub = { parse: parseGsubTable, make: makeGsubTable }; + + // The `GPOS` table contains kerning pairs, among other things. + + // Parse the metadata `meta` table. + // https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6meta.html + function parseMetaTable(data, start) { + var p = new parse.Parser(data, start); + var tableVersion = p.parseULong(); + check.argument(tableVersion === 1, 'Unsupported META table version.'); + p.parseULong(); // flags - currently unused and set to 0 + p.parseULong(); // tableOffset + var numDataMaps = p.parseULong(); + + var tags = {}; + for (var i = 0; i < numDataMaps; i++) { + var tag = p.parseTag(); + var dataOffset = p.parseULong(); + var dataLength = p.parseULong(); + var text = decode.UTF8(data, start + dataOffset, dataLength); + + tags[tag] = text; + } + return tags; + } + + function makeMetaTable(tags) { + var numTags = Object.keys(tags).length; + var stringPool = ''; + var stringPoolOffset = 16 + numTags * 12; + + var result = new table.Table('meta', [ + { name: 'version', type: 'ULONG', value: 1 }, + { name: 'flags', type: 'ULONG', value: 0 }, + { name: 'offset', type: 'ULONG', value: stringPoolOffset }, + { name: 'numTags', type: 'ULONG', value: numTags } + ]); + + for (var tag in tags) { + var pos = stringPool.length; + stringPool += tags[tag]; + + result.fields.push({ name: 'tag ' + tag, type: 'TAG', value: tag }); + result.fields.push({ + name: 'offset ' + tag, + type: 'ULONG', + value: stringPoolOffset + pos + }); + result.fields.push({ + name: 'length ' + tag, + type: 'ULONG', + value: tags[tag].length + }); + } + + result.fields.push({ + name: 'stringPool', + type: 'CHARARRAY', + value: stringPool + }); + + return result; + } + + var meta = { parse: parseMetaTable, make: makeMetaTable }; + + // The `sfnt` wrapper provides organization for the tables in the font. + + function log2(v) { + return (Math.log(v) / Math.log(2)) | 0; + } + + function computeCheckSum(bytes) { + while (bytes.length % 4 !== 0) { + bytes.push(0); + } + + var sum = 0; + for (var i = 0; i < bytes.length; i += 4) { + sum += + (bytes[i] << 24) + + (bytes[i + 1] << 16) + + (bytes[i + 2] << 8) + + bytes[i + 3]; + } + + sum %= Math.pow(2, 32); + return sum; + } + + function makeTableRecord(tag, checkSum, offset, length) { + return new table.Record('Table Record', [ + { name: 'tag', type: 'TAG', value: tag !== undefined ? tag : '' }, + { + name: 'checkSum', + type: 'ULONG', + value: checkSum !== undefined ? checkSum : 0 + }, + { + name: 'offset', + type: 'ULONG', + value: offset !== undefined ? offset : 0 + }, + { + name: 'length', + type: 'ULONG', + value: length !== undefined ? length : 0 + } + ]); + } + + function makeSfntTable(tables) { + var sfnt = new table.Table('sfnt', [ + { name: 'version', type: 'TAG', value: 'OTTO' }, + { name: 'numTables', type: 'USHORT', value: 0 }, + { name: 'searchRange', type: 'USHORT', value: 0 }, + { name: 'entrySelector', type: 'USHORT', value: 0 }, + { name: 'rangeShift', type: 'USHORT', value: 0 } + ]); + sfnt.tables = tables; + sfnt.numTables = tables.length; + var highestPowerOf2 = Math.pow(2, log2(sfnt.numTables)); + sfnt.searchRange = 16 * highestPowerOf2; + sfnt.entrySelector = log2(highestPowerOf2); + sfnt.rangeShift = sfnt.numTables * 16 - sfnt.searchRange; + + var recordFields = []; + var tableFields = []; + + var offset = sfnt.sizeOf() + makeTableRecord().sizeOf() * sfnt.numTables; + while (offset % 4 !== 0) { + offset += 1; + tableFields.push({ name: 'padding', type: 'BYTE', value: 0 }); + } + + for (var i = 0; i < tables.length; i += 1) { + var t = tables[i]; + check.argument( + t.tableName.length === 4, + 'Table name' + t.tableName + ' is invalid.' + ); + var tableLength = t.sizeOf(); + var tableRecord = makeTableRecord( + t.tableName, + computeCheckSum(t.encode()), + offset, + tableLength + ); + recordFields.push({ + name: tableRecord.tag + ' Table Record', + type: 'RECORD', + value: tableRecord + }); + tableFields.push({ + name: t.tableName + ' table', + type: 'RECORD', + value: t + }); + offset += tableLength; + check.argument( + !isNaN(offset), + 'Something went wrong calculating the offset.' + ); + while (offset % 4 !== 0) { + offset += 1; + tableFields.push({ name: 'padding', type: 'BYTE', value: 0 }); + } + } + + // Table records need to be sorted alphabetically. + recordFields.sort(function(r1, r2) { + if (r1.value.tag > r2.value.tag) { + return 1; + } else { + return -1; + } + }); + + sfnt.fields = sfnt.fields.concat(recordFields); + sfnt.fields = sfnt.fields.concat(tableFields); + return sfnt; + } + + // Get the metrics for a character. If the string has more than one character + // this function returns metrics for the first available character. + // You can provide optional fallback metrics if no characters are available. + function metricsForChar(font, chars, notFoundMetrics) { + for (var i = 0; i < chars.length; i += 1) { + var glyphIndex = font.charToGlyphIndex(chars[i]); + if (glyphIndex > 0) { + var glyph = font.glyphs.get(glyphIndex); + return glyph.getMetrics(); + } + } + + return notFoundMetrics; + } + + function average(vs) { + var sum = 0; + for (var i = 0; i < vs.length; i += 1) { + sum += vs[i]; + } + + return sum / vs.length; + } + + // Convert the font object to a SFNT data structure. + // This structure contains all the necessary tables and metadata to create a binary OTF file. + function fontToSfntTable(font) { + var xMins = []; + var yMins = []; + var xMaxs = []; + var yMaxs = []; + var advanceWidths = []; + var leftSideBearings = []; + var rightSideBearings = []; + var firstCharIndex; + var lastCharIndex = 0; + var ulUnicodeRange1 = 0; + var ulUnicodeRange2 = 0; + var ulUnicodeRange3 = 0; + var ulUnicodeRange4 = 0; + + for (var i = 0; i < font.glyphs.length; i += 1) { + var glyph = font.glyphs.get(i); + var unicode = glyph.unicode | 0; + + if (isNaN(glyph.advanceWidth)) { + throw new Error( + 'Glyph ' + glyph.name + ' (' + i + '): advanceWidth is not a number.' + ); + } + + if (firstCharIndex > unicode || firstCharIndex === undefined) { + // ignore .notdef char + if (unicode > 0) { + firstCharIndex = unicode; + } + } + + if (lastCharIndex < unicode) { + lastCharIndex = unicode; + } + + var position = os2.getUnicodeRange(unicode); + if (position < 32) { + ulUnicodeRange1 |= 1 << position; + } else if (position < 64) { + ulUnicodeRange2 |= 1 << (position - 32); + } else if (position < 96) { + ulUnicodeRange3 |= 1 << (position - 64); + } else if (position < 123) { + ulUnicodeRange4 |= 1 << (position - 96); + } else { + throw new Error( + 'Unicode ranges bits > 123 are reserved for internal usage' + ); + } + // Skip non-important characters. + if (glyph.name === '.notdef') { + continue; + } + var metrics = glyph.getMetrics(); + xMins.push(metrics.xMin); + yMins.push(metrics.yMin); + xMaxs.push(metrics.xMax); + yMaxs.push(metrics.yMax); + leftSideBearings.push(metrics.leftSideBearing); + rightSideBearings.push(metrics.rightSideBearing); + advanceWidths.push(glyph.advanceWidth); + } + + var globals = { + xMin: Math.min.apply(null, xMins), + yMin: Math.min.apply(null, yMins), + xMax: Math.max.apply(null, xMaxs), + yMax: Math.max.apply(null, yMaxs), + advanceWidthMax: Math.max.apply(null, advanceWidths), + advanceWidthAvg: average(advanceWidths), + minLeftSideBearing: Math.min.apply(null, leftSideBearings), + maxLeftSideBearing: Math.max.apply(null, leftSideBearings), + minRightSideBearing: Math.min.apply(null, rightSideBearings) + }; + globals.ascender = font.ascender; + globals.descender = font.descender; + + var headTable = head.make({ + flags: 3, // 00000011 (baseline for font at y=0; left sidebearing point at x=0) + unitsPerEm: font.unitsPerEm, + xMin: globals.xMin, + yMin: globals.yMin, + xMax: globals.xMax, + yMax: globals.yMax, + lowestRecPPEM: 3, + createdTimestamp: font.createdTimestamp + }); + + var hheaTable = hhea.make({ + ascender: globals.ascender, + descender: globals.descender, + advanceWidthMax: globals.advanceWidthMax, + minLeftSideBearing: globals.minLeftSideBearing, + minRightSideBearing: globals.minRightSideBearing, + xMaxExtent: globals.maxLeftSideBearing + (globals.xMax - globals.xMin), + numberOfHMetrics: font.glyphs.length + }); + + var maxpTable = maxp.make(font.glyphs.length); + + var os2Table = os2.make({ + xAvgCharWidth: Math.round(globals.advanceWidthAvg), + usWeightClass: font.tables.os2.usWeightClass, + usWidthClass: font.tables.os2.usWidthClass, + usFirstCharIndex: firstCharIndex, + usLastCharIndex: lastCharIndex, + ulUnicodeRange1: ulUnicodeRange1, + ulUnicodeRange2: ulUnicodeRange2, + ulUnicodeRange3: ulUnicodeRange3, + ulUnicodeRange4: ulUnicodeRange4, + fsSelection: font.tables.os2.fsSelection, // REGULAR + // See http://typophile.com/node/13081 for more info on vertical metrics. + // We get metrics for typical characters (such as "x" for xHeight). + // We provide some fallback characters if characters are unavailable: their + // ordering was chosen experimentally. + sTypoAscender: globals.ascender, + sTypoDescender: globals.descender, + sTypoLineGap: 0, + usWinAscent: globals.yMax, + usWinDescent: Math.abs(globals.yMin), + ulCodePageRange1: 1, // FIXME: hard-code Latin 1 support for now + sxHeight: metricsForChar(font, 'xyvw', { + yMax: Math.round(globals.ascender / 2) + }).yMax, + sCapHeight: metricsForChar(font, 'HIKLEFJMNTZBDPRAGOQSUVWXY', globals) + .yMax, + usDefaultChar: font.hasChar(' ') ? 32 : 0, // Use space as the default character, if available. + usBreakChar: font.hasChar(' ') ? 32 : 0 // Use space as the break character, if available. + }); + + var hmtxTable = hmtx.make(font.glyphs); + var cmapTable = cmap.make(font.glyphs); + + var englishFamilyName = font.getEnglishName('fontFamily'); + var englishStyleName = font.getEnglishName('fontSubfamily'); + var englishFullName = englishFamilyName + ' ' + englishStyleName; + var postScriptName = font.getEnglishName('postScriptName'); + if (!postScriptName) { + postScriptName = + englishFamilyName.replace(/\s/g, '') + '-' + englishStyleName; + } + + var names = {}; + for (var n in font.names) { + names[n] = font.names[n]; + } + + if (!names.uniqueID) { + names.uniqueID = { + en: font.getEnglishName('manufacturer') + ':' + englishFullName + }; + } + + if (!names.postScriptName) { + names.postScriptName = { en: postScriptName }; + } + + if (!names.preferredFamily) { + names.preferredFamily = font.names.fontFamily; + } + + if (!names.preferredSubfamily) { + names.preferredSubfamily = font.names.fontSubfamily; + } + + var languageTags = []; + var nameTable = _name.make(names, languageTags); + var ltagTable = + languageTags.length > 0 ? ltag.make(languageTags) : undefined; + + var postTable = post.make(); + var cffTable = cff.make(font.glyphs, { + version: font.getEnglishName('version'), + fullName: englishFullName, + familyName: englishFamilyName, + weightName: englishStyleName, + postScriptName: postScriptName, + unitsPerEm: font.unitsPerEm, + fontBBox: [0, globals.yMin, globals.ascender, globals.advanceWidthMax] + }); + + var metaTable = + font.metas && Object.keys(font.metas).length > 0 + ? meta.make(font.metas) + : undefined; + + // The order does not matter because makeSfntTable() will sort them. + var tables = [ + headTable, + hheaTable, + maxpTable, + os2Table, + nameTable, + cmapTable, + postTable, + cffTable, + hmtxTable + ]; + if (ltagTable) { + tables.push(ltagTable); + } + // Optional tables + if (font.tables.gsub) { + tables.push(gsub.make(font.tables.gsub)); + } + if (metaTable) { + tables.push(metaTable); + } + + var sfntTable = makeSfntTable(tables); + + // Compute the font's checkSum and store it in head.checkSumAdjustment. + var bytes = sfntTable.encode(); + var checkSum = computeCheckSum(bytes); + var tableFields = sfntTable.fields; + var checkSumAdjusted = false; + for (var i$1 = 0; i$1 < tableFields.length; i$1 += 1) { + if (tableFields[i$1].name === 'head table') { + tableFields[i$1].value.checkSumAdjustment = 0xb1b0afba - checkSum; + checkSumAdjusted = true; + break; + } + } + + if (!checkSumAdjusted) { + throw new Error('Could not find head table with checkSum to adjust.'); + } + + return sfntTable; + } + + var sfnt = { + make: makeSfntTable, + fontToTable: fontToSfntTable, + computeCheckSum: computeCheckSum + }; + + // The Layout object is the prototype of Substitution objects, and provides + + function searchTag(arr, tag) { + /* jshint bitwise: false */ + var imin = 0; + var imax = arr.length - 1; + while (imin <= imax) { + var imid = (imin + imax) >>> 1; + var val = arr[imid].tag; + if (val === tag) { + return imid; + } else if (val < tag) { + imin = imid + 1; + } else { + imax = imid - 1; + } + } + // Not found: return -1-insertion point + return -imin - 1; + } + + function binSearch(arr, value) { + /* jshint bitwise: false */ + var imin = 0; + var imax = arr.length - 1; + while (imin <= imax) { + var imid = (imin + imax) >>> 1; + var val = arr[imid]; + if (val === value) { + return imid; + } else if (val < value) { + imin = imid + 1; + } else { + imax = imid - 1; + } + } + // Not found: return -1-insertion point + return -imin - 1; + } + + // binary search in a list of ranges (coverage, class definition) + function searchRange(ranges, value) { + // jshint bitwise: false + var range; + var imin = 0; + var imax = ranges.length - 1; + while (imin <= imax) { + var imid = (imin + imax) >>> 1; + range = ranges[imid]; + var start = range.start; + if (start === value) { + return range; + } else if (start < value) { + imin = imid + 1; + } else { + imax = imid - 1; + } + } + if (imin > 0) { + range = ranges[imin - 1]; + if (value > range.end) { + return 0; + } + return range; + } + } + + /** + * @exports opentype.Layout + * @class + */ + function Layout(font, tableName) { + this.font = font; + this.tableName = tableName; + } + + Layout.prototype = { + /** + * Binary search an object by "tag" property + * @instance + * @function searchTag + * @memberof opentype.Layout + * @param {Array} arr + * @param {string} tag + * @return {number} + */ + searchTag: searchTag, + + /** + * Binary search in a list of numbers + * @instance + * @function binSearch + * @memberof opentype.Layout + * @param {Array} arr + * @param {number} value + * @return {number} + */ + binSearch: binSearch, + + /** + * Get or create the Layout table (GSUB, GPOS etc). + * @param {boolean} create - Whether to create a new one. + * @return {Object} The GSUB or GPOS table. + */ + getTable: function(create) { + var layout = this.font.tables[this.tableName]; + if (!layout && create) { + layout = this.font.tables[this.tableName] = this.createDefaultTable(); + } + return layout; + }, + + /** + * Returns all scripts in the substitution table. + * @instance + * @return {Array} + */ + getScriptNames: function() { + var layout = this.getTable(); + if (!layout) { + return []; + } + return layout.scripts.map(function(script) { + return script.tag; + }); + }, + + /** + * Returns the best bet for a script name. + * Returns 'DFLT' if it exists. + * If not, returns 'latn' if it exists. + * If neither exist, returns undefined. + */ + getDefaultScriptName: function() { + var layout = this.getTable(); + if (!layout) { + return; + } + var hasLatn = false; + for (var i = 0; i < layout.scripts.length; i++) { + var name = layout.scripts[i].tag; + if (name === 'DFLT') { + return name; + } + if (name === 'latn') { + hasLatn = true; + } + } + if (hasLatn) { + return 'latn'; + } + }, + + /** + * Returns all LangSysRecords in the given script. + * @instance + * @param {string} [script='DFLT'] + * @param {boolean} create - forces the creation of this script table if it doesn't exist. + * @return {Object} An object with tag and script properties. + */ + getScriptTable: function(script, create) { + var layout = this.getTable(create); + if (layout) { + script = script || 'DFLT'; + var scripts = layout.scripts; + var pos = searchTag(layout.scripts, script); + if (pos >= 0) { + return scripts[pos].script; + } else if (create) { + var scr = { + tag: script, + script: { + defaultLangSys: { + reserved: 0, + reqFeatureIndex: 0xffff, + featureIndexes: [] + }, + langSysRecords: [] + } + }; + scripts.splice(-1 - pos, 0, scr); + return scr.script; + } + } + }, + + /** + * Returns a language system table + * @instance + * @param {string} [script='DFLT'] + * @param {string} [language='dlft'] + * @param {boolean} create - forces the creation of this langSysTable if it doesn't exist. + * @return {Object} + */ + getLangSysTable: function(script, language, create) { + var scriptTable = this.getScriptTable(script, create); + if (scriptTable) { + if (!language || language === 'dflt' || language === 'DFLT') { + return scriptTable.defaultLangSys; + } + var pos = searchTag(scriptTable.langSysRecords, language); + if (pos >= 0) { + return scriptTable.langSysRecords[pos].langSys; + } else if (create) { + var langSysRecord = { + tag: language, + langSys: { + reserved: 0, + reqFeatureIndex: 0xffff, + featureIndexes: [] + } + }; + scriptTable.langSysRecords.splice(-1 - pos, 0, langSysRecord); + return langSysRecord.langSys; + } + } + }, + + /** + * Get a specific feature table. + * @instance + * @param {string} [script='DFLT'] + * @param {string} [language='dlft'] + * @param {string} feature - One of the codes listed at https://www.microsoft.com/typography/OTSPEC/featurelist.htm + * @param {boolean} create - forces the creation of the feature table if it doesn't exist. + * @return {Object} + */ + getFeatureTable: function(script, language, feature, create) { + var langSysTable = this.getLangSysTable(script, language, create); + if (langSysTable) { + var featureRecord; + var featIndexes = langSysTable.featureIndexes; + var allFeatures = this.font.tables[this.tableName].features; + // The FeatureIndex array of indices is in arbitrary order, + // even if allFeatures is sorted alphabetically by feature tag. + for (var i = 0; i < featIndexes.length; i++) { + featureRecord = allFeatures[featIndexes[i]]; + if (featureRecord.tag === feature) { + return featureRecord.feature; + } + } + if (create) { + var index = allFeatures.length; + // Automatic ordering of features would require to shift feature indexes in the script list. + check.assert( + index === 0 || feature >= allFeatures[index - 1].tag, + 'Features must be added in alphabetical order.' + ); + featureRecord = { + tag: feature, + feature: { params: 0, lookupListIndexes: [] } + }; + allFeatures.push(featureRecord); + featIndexes.push(index); + return featureRecord.feature; + } + } + }, + + /** + * Get the lookup tables of a given type for a script/language/feature. + * @instance + * @param {string} [script='DFLT'] + * @param {string} [language='dlft'] + * @param {string} feature - 4-letter feature code + * @param {number} lookupType - 1 to 9 + * @param {boolean} create - forces the creation of the lookup table if it doesn't exist, with no subtables. + * @return {Object[]} + */ + getLookupTables: function(script, language, feature, lookupType, create) { + var featureTable = this.getFeatureTable( + script, + language, + feature, + create + ); + var tables = []; + if (featureTable) { + var lookupTable; + var lookupListIndexes = featureTable.lookupListIndexes; + var allLookups = this.font.tables[this.tableName].lookups; + // lookupListIndexes are in no particular order, so use naive search. + for (var i = 0; i < lookupListIndexes.length; i++) { + lookupTable = allLookups[lookupListIndexes[i]]; + if (lookupTable.lookupType === lookupType) { + tables.push(lookupTable); + } + } + if (tables.length === 0 && create) { + lookupTable = { + lookupType: lookupType, + lookupFlag: 0, + subtables: [], + markFilteringSet: undefined + }; + var index = allLookups.length; + allLookups.push(lookupTable); + lookupListIndexes.push(index); + return [lookupTable]; + } + } + return tables; + }, + + /** + * Find a glyph in a class definition table + * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#class-definition-table + * @param {object} classDefTable - an OpenType Layout class definition table + * @param {number} glyphIndex - the index of the glyph to find + * @returns {number} -1 if not found + */ + getGlyphClass: function(classDefTable, glyphIndex) { + switch (classDefTable.format) { + case 1: + if ( + classDefTable.startGlyph <= glyphIndex && + glyphIndex < classDefTable.startGlyph + classDefTable.classes.length + ) { + return classDefTable.classes[glyphIndex - classDefTable.startGlyph]; + } + return 0; + case 2: + var range = searchRange(classDefTable.ranges, glyphIndex); + return range ? range.classId : 0; + } + }, + + /** + * Find a glyph in a coverage table + * https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-table + * @param {object} coverageTable - an OpenType Layout coverage table + * @param {number} glyphIndex - the index of the glyph to find + * @returns {number} -1 if not found + */ + getCoverageIndex: function(coverageTable, glyphIndex) { + switch (coverageTable.format) { + case 1: + var index = binSearch(coverageTable.glyphs, glyphIndex); + return index >= 0 ? index : -1; + case 2: + var range = searchRange(coverageTable.ranges, glyphIndex); + return range ? range.index + glyphIndex - range.start : -1; + } + }, + + /** + * Returns the list of glyph indexes of a coverage table. + * Format 1: the list is stored raw + * Format 2: compact list as range records. + * @instance + * @param {Object} coverageTable + * @return {Array} + */ + expandCoverage: function(coverageTable) { + if (coverageTable.format === 1) { + return coverageTable.glyphs; + } else { + var glyphs = []; + var ranges = coverageTable.ranges; + for (var i = 0; i < ranges.length; i++) { + var range = ranges[i]; + var start = range.start; + var end = range.end; + for (var j = start; j <= end; j++) { + glyphs.push(j); + } + } + return glyphs; + } + } + }; + + // The Position object provides utility methods to manipulate + + /** + * @exports opentype.Position + * @class + * @extends opentype.Layout + * @param {opentype.Font} + * @constructor + */ + function Position(font) { + Layout.call(this, font, 'gpos'); + } + + Position.prototype = Layout.prototype; + + /** + * Init some data for faster and easier access later. + */ + Position.prototype.init = function() { + var script = this.getDefaultScriptName(); + this.defaultKerningTables = this.getKerningTables(script); + }; + + /** + * Find a glyph pair in a list of lookup tables of type 2 and retrieve the xAdvance kerning value. + * + * @param {integer} leftIndex - left glyph index + * @param {integer} rightIndex - right glyph index + * @returns {integer} + */ + Position.prototype.getKerningValue = function( + kerningLookups, + leftIndex, + rightIndex + ) { + var this$1 = this; + + for (var i = 0; i < kerningLookups.length; i++) { + var subtables = kerningLookups[i].subtables; + for (var j = 0; j < subtables.length; j++) { + var subtable = subtables[j]; + var covIndex = this$1.getCoverageIndex(subtable.coverage, leftIndex); + if (covIndex < 0) { + continue; + } + switch (subtable.posFormat) { + case 1: + // Search Pair Adjustment Positioning Format 1 + var pairSet = subtable.pairSets[covIndex]; + for (var k = 0; k < pairSet.length; k++) { + var pair = pairSet[k]; + if (pair.secondGlyph === rightIndex) { + return (pair.value1 && pair.value1.xAdvance) || 0; + } + } + break; // left glyph found, not right glyph - try next subtable + case 2: + // Search Pair Adjustment Positioning Format 2 + var class1 = this$1.getGlyphClass(subtable.classDef1, leftIndex); + var class2 = this$1.getGlyphClass(subtable.classDef2, rightIndex); + var pair$1 = subtable.classRecords[class1][class2]; + return (pair$1.value1 && pair$1.value1.xAdvance) || 0; + } + } + } + return 0; + }; + + /** + * List all kerning lookup tables. + * + * @param {string} [script='DFLT'] - use font.position.getDefaultScriptName() for a better default value + * @param {string} [language='dflt'] + * @return {object[]} The list of kerning lookup tables (may be empty), or undefined if there is no GPOS table (and we should use the kern table) + */ + Position.prototype.getKerningTables = function(script, language) { + if (this.font.tables.gpos) { + return this.getLookupTables(script, language, 'kern', 2); + } + }; + + // The Substitution object provides utility methods to manipulate + + /** + * @exports opentype.Substitution + * @class + * @extends opentype.Layout + * @param {opentype.Font} + * @constructor + */ + function Substitution(font) { + Layout.call(this, font, 'gsub'); + } + + // Check if 2 arrays of primitives are equal. + function arraysEqual(ar1, ar2) { + var n = ar1.length; + if (n !== ar2.length) { + return false; + } + for (var i = 0; i < n; i++) { + if (ar1[i] !== ar2[i]) { + return false; + } + } + return true; + } + + // Find the first subtable of a lookup table in a particular format. + function getSubstFormat(lookupTable, format, defaultSubtable) { + var subtables = lookupTable.subtables; + for (var i = 0; i < subtables.length; i++) { + var subtable = subtables[i]; + if (subtable.substFormat === format) { + return subtable; + } + } + if (defaultSubtable) { + subtables.push(defaultSubtable); + return defaultSubtable; + } + return undefined; + } + + Substitution.prototype = Layout.prototype; + + /** + * Create a default GSUB table. + * @return {Object} gsub - The GSUB table. + */ + Substitution.prototype.createDefaultTable = function() { + // Generate a default empty GSUB table with just a DFLT script and dflt lang sys. + return { + version: 1, + scripts: [ + { + tag: 'DFLT', + script: { + defaultLangSys: { + reserved: 0, + reqFeatureIndex: 0xffff, + featureIndexes: [] + }, + langSysRecords: [] + } + } + ], + features: [], + lookups: [] + }; + }; + + /** + * List all single substitutions (lookup type 1) for a given script, language, and feature. + * @param {string} [script='DFLT'] + * @param {string} [language='dflt'] + * @param {string} feature - 4-character feature name ('aalt', 'salt', 'ss01'...) + * @return {Array} substitutions - The list of substitutions. + */ + Substitution.prototype.getSingle = function(feature, script, language) { + var this$1 = this; + + var substitutions = []; + var lookupTables = this.getLookupTables(script, language, feature, 1); + for (var idx = 0; idx < lookupTables.length; idx++) { + var subtables = lookupTables[idx].subtables; + for (var i = 0; i < subtables.length; i++) { + var subtable = subtables[i]; + var glyphs = this$1.expandCoverage(subtable.coverage); + var j = void 0; + if (subtable.substFormat === 1) { + var delta = subtable.deltaGlyphId; + for (j = 0; j < glyphs.length; j++) { + var glyph = glyphs[j]; + substitutions.push({ sub: glyph, by: glyph + delta }); + } + } else { + var substitute = subtable.substitute; + for (j = 0; j < glyphs.length; j++) { + substitutions.push({ sub: glyphs[j], by: substitute[j] }); + } + } + } + } + return substitutions; + }; + + /** + * List all alternates (lookup type 3) for a given script, language, and feature. + * @param {string} [script='DFLT'] + * @param {string} [language='dflt'] + * @param {string} feature - 4-character feature name ('aalt', 'salt'...) + * @return {Array} alternates - The list of alternates + */ + Substitution.prototype.getAlternates = function(feature, script, language) { + var this$1 = this; + + var alternates = []; + var lookupTables = this.getLookupTables(script, language, feature, 3); + for (var idx = 0; idx < lookupTables.length; idx++) { + var subtables = lookupTables[idx].subtables; + for (var i = 0; i < subtables.length; i++) { + var subtable = subtables[i]; + var glyphs = this$1.expandCoverage(subtable.coverage); + var alternateSets = subtable.alternateSets; + for (var j = 0; j < glyphs.length; j++) { + alternates.push({ sub: glyphs[j], by: alternateSets[j] }); + } + } + } + return alternates; + }; + + /** + * List all ligatures (lookup type 4) for a given script, language, and feature. + * The result is an array of ligature objects like { sub: [ids], by: id } + * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...) + * @param {string} [script='DFLT'] + * @param {string} [language='dflt'] + * @return {Array} ligatures - The list of ligatures. + */ + Substitution.prototype.getLigatures = function(feature, script, language) { + var this$1 = this; + + var ligatures = []; + var lookupTables = this.getLookupTables(script, language, feature, 4); + for (var idx = 0; idx < lookupTables.length; idx++) { + var subtables = lookupTables[idx].subtables; + for (var i = 0; i < subtables.length; i++) { + var subtable = subtables[i]; + var glyphs = this$1.expandCoverage(subtable.coverage); + var ligatureSets = subtable.ligatureSets; + for (var j = 0; j < glyphs.length; j++) { + var startGlyph = glyphs[j]; + var ligSet = ligatureSets[j]; + for (var k = 0; k < ligSet.length; k++) { + var lig = ligSet[k]; + ligatures.push({ + sub: [startGlyph].concat(lig.components), + by: lig.ligGlyph + }); + } + } + } + } + return ligatures; + }; + + /** + * Add or modify a single substitution (lookup type 1) + * Format 2, more flexible, is always used. + * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...) + * @param {Object} substitution - { sub: id, delta: number } for format 1 or { sub: id, by: id } for format 2. + * @param {string} [script='DFLT'] + * @param {string} [language='dflt'] + */ + Substitution.prototype.addSingle = function( + feature, + substitution, + script, + language + ) { + var lookupTable = this.getLookupTables( + script, + language, + feature, + 1, + true + )[0]; + var subtable = getSubstFormat(lookupTable, 2, { + // lookup type 1 subtable, format 2, coverage format 1 + substFormat: 2, + coverage: { format: 1, glyphs: [] }, + substitute: [] + }); + check.assert( + subtable.coverage.format === 1, + 'Ligature: unable to modify coverage table format ' + + subtable.coverage.format + ); + var coverageGlyph = substitution.sub; + var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph); + if (pos < 0) { + pos = -1 - pos; + subtable.coverage.glyphs.splice(pos, 0, coverageGlyph); + subtable.substitute.splice(pos, 0, 0); + } + subtable.substitute[pos] = substitution.by; + }; + + /** + * Add or modify an alternate substitution (lookup type 1) + * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...) + * @param {Object} substitution - { sub: id, by: [ids] } + * @param {string} [script='DFLT'] + * @param {string} [language='dflt'] + */ + Substitution.prototype.addAlternate = function( + feature, + substitution, + script, + language + ) { + var lookupTable = this.getLookupTables( + script, + language, + feature, + 3, + true + )[0]; + var subtable = getSubstFormat(lookupTable, 1, { + // lookup type 3 subtable, format 1, coverage format 1 + substFormat: 1, + coverage: { format: 1, glyphs: [] }, + alternateSets: [] + }); + check.assert( + subtable.coverage.format === 1, + 'Ligature: unable to modify coverage table format ' + + subtable.coverage.format + ); + var coverageGlyph = substitution.sub; + var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph); + if (pos < 0) { + pos = -1 - pos; + subtable.coverage.glyphs.splice(pos, 0, coverageGlyph); + subtable.alternateSets.splice(pos, 0, 0); + } + subtable.alternateSets[pos] = substitution.by; + }; + + /** + * Add a ligature (lookup type 4) + * Ligatures with more components must be stored ahead of those with fewer components in order to be found + * @param {string} feature - 4-letter feature name ('liga', 'rlig', 'dlig'...) + * @param {Object} ligature - { sub: [ids], by: id } + * @param {string} [script='DFLT'] + * @param {string} [language='dflt'] + */ + Substitution.prototype.addLigature = function( + feature, + ligature, + script, + language + ) { + var lookupTable = this.getLookupTables( + script, + language, + feature, + 4, + true + )[0]; + var subtable = lookupTable.subtables[0]; + if (!subtable) { + subtable = { + // lookup type 4 subtable, format 1, coverage format 1 + substFormat: 1, + coverage: { format: 1, glyphs: [] }, + ligatureSets: [] + }; + lookupTable.subtables[0] = subtable; + } + check.assert( + subtable.coverage.format === 1, + 'Ligature: unable to modify coverage table format ' + + subtable.coverage.format + ); + var coverageGlyph = ligature.sub[0]; + var ligComponents = ligature.sub.slice(1); + var ligatureTable = { + ligGlyph: ligature.by, + components: ligComponents + }; + var pos = this.binSearch(subtable.coverage.glyphs, coverageGlyph); + if (pos >= 0) { + // ligatureSet already exists + var ligatureSet = subtable.ligatureSets[pos]; + for (var i = 0; i < ligatureSet.length; i++) { + // If ligature already exists, return. + if (arraysEqual(ligatureSet[i].components, ligComponents)) { + return; + } + } + // ligature does not exist: add it. + ligatureSet.push(ligatureTable); + } else { + // Create a new ligatureSet and add coverage for the first glyph. + pos = -1 - pos; + subtable.coverage.glyphs.splice(pos, 0, coverageGlyph); + subtable.ligatureSets.splice(pos, 0, [ligatureTable]); + } + }; + + /** + * List all feature data for a given script and language. + * @param {string} feature - 4-letter feature name + * @param {string} [script='DFLT'] + * @param {string} [language='dflt'] + * @return {Array} substitutions - The list of substitutions. + */ + Substitution.prototype.getFeature = function(feature, script, language) { + if (/ss\d\d/.test(feature)) { + // ss01 - ss20 + return this.getSingle(feature, script, language); + } + switch (feature) { + case 'aalt': + case 'salt': + return this.getSingle(feature, script, language).concat( + this.getAlternates(feature, script, language) + ); + case 'dlig': + case 'liga': + case 'rlig': + return this.getLigatures(feature, script, language); + } + return undefined; + }; + + /** + * Add a substitution to a feature for a given script and language. + * @param {string} feature - 4-letter feature name + * @param {Object} sub - the substitution to add (an object like { sub: id or [ids], by: id or [ids] }) + * @param {string} [script='DFLT'] + * @param {string} [language='dflt'] + */ + Substitution.prototype.add = function(feature, sub, script, language) { + if (/ss\d\d/.test(feature)) { + // ss01 - ss20 + return this.addSingle(feature, sub, script, language); + } + switch (feature) { + case 'aalt': + case 'salt': + if (typeof sub.by === 'number') { + return this.addSingle(feature, sub, script, language); + } + return this.addAlternate(feature, sub, script, language); + case 'dlig': + case 'liga': + case 'rlig': + return this.addLigature(feature, sub, script, language); + } + return undefined; + }; + + function isBrowser() { + return typeof window !== 'undefined'; + } + + function nodeBufferToArrayBuffer(buffer) { + var ab = new ArrayBuffer(buffer.length); + var view = new Uint8Array(ab); + for (var i = 0; i < buffer.length; ++i) { + view[i] = buffer[i]; + } + + return ab; + } + + function arrayBufferToNodeBuffer(ab) { + var buffer = new Buffer(ab.byteLength); + var view = new Uint8Array(ab); + for (var i = 0; i < buffer.length; ++i) { + buffer[i] = view[i]; + } + + return buffer; + } + + function checkArgument(expression, message) { + if (!expression) { + throw message; + } + } + + // The `glyf` table describes the glyphs in TrueType outline format. + + // Parse the coordinate data for a glyph. + function parseGlyphCoordinate( + p, + flag, + previousValue, + shortVectorBitMask, + sameBitMask + ) { + var v; + if ((flag & shortVectorBitMask) > 0) { + // The coordinate is 1 byte long. + v = p.parseByte(); + // The `same` bit is re-used for short values to signify the sign of the value. + if ((flag & sameBitMask) === 0) { + v = -v; + } + + v = previousValue + v; + } else { + // The coordinate is 2 bytes long. + // If the `same` bit is set, the coordinate is the same as the previous coordinate. + if ((flag & sameBitMask) > 0) { + v = previousValue; + } else { + // Parse the coordinate as a signed 16-bit delta value. + v = previousValue + p.parseShort(); + } + } + + return v; + } + + // Parse a TrueType glyph. + function parseGlyph(glyph, data, start) { + var p = new parse.Parser(data, start); + glyph.numberOfContours = p.parseShort(); + glyph._xMin = p.parseShort(); + glyph._yMin = p.parseShort(); + glyph._xMax = p.parseShort(); + glyph._yMax = p.parseShort(); + var flags; + var flag; + + if (glyph.numberOfContours > 0) { + // This glyph is not a composite. + var endPointIndices = (glyph.endPointIndices = []); + for (var i = 0; i < glyph.numberOfContours; i += 1) { + endPointIndices.push(p.parseUShort()); + } + + glyph.instructionLength = p.parseUShort(); + glyph.instructions = []; + for (var i$1 = 0; i$1 < glyph.instructionLength; i$1 += 1) { + glyph.instructions.push(p.parseByte()); + } + + var numberOfCoordinates = endPointIndices[endPointIndices.length - 1] + 1; + flags = []; + for (var i$2 = 0; i$2 < numberOfCoordinates; i$2 += 1) { + flag = p.parseByte(); + flags.push(flag); + // If bit 3 is set, we repeat this flag n times, where n is the next byte. + if ((flag & 8) > 0) { + var repeatCount = p.parseByte(); + for (var j = 0; j < repeatCount; j += 1) { + flags.push(flag); + i$2 += 1; + } + } + } + + check.argument(flags.length === numberOfCoordinates, 'Bad flags.'); + + if (endPointIndices.length > 0) { + var points = []; + var point; + // X/Y coordinates are relative to the previous point, except for the first point which is relative to 0,0. + if (numberOfCoordinates > 0) { + for (var i$3 = 0; i$3 < numberOfCoordinates; i$3 += 1) { + flag = flags[i$3]; + point = {}; + point.onCurve = !!(flag & 1); + point.lastPointOfContour = endPointIndices.indexOf(i$3) >= 0; + points.push(point); + } + + var px = 0; + for (var i$4 = 0; i$4 < numberOfCoordinates; i$4 += 1) { + flag = flags[i$4]; + point = points[i$4]; + point.x = parseGlyphCoordinate(p, flag, px, 2, 16); + px = point.x; + } + + var py = 0; + for (var i$5 = 0; i$5 < numberOfCoordinates; i$5 += 1) { + flag = flags[i$5]; + point = points[i$5]; + point.y = parseGlyphCoordinate(p, flag, py, 4, 32); + py = point.y; + } + } + + glyph.points = points; + } else { + glyph.points = []; + } + } else if (glyph.numberOfContours === 0) { + glyph.points = []; + } else { + glyph.isComposite = true; + glyph.points = []; + glyph.components = []; + var moreComponents = true; + while (moreComponents) { + flags = p.parseUShort(); + var component = { + glyphIndex: p.parseUShort(), + xScale: 1, + scale01: 0, + scale10: 0, + yScale: 1, + dx: 0, + dy: 0 + }; + if ((flags & 1) > 0) { + // The arguments are words + if ((flags & 2) > 0) { + // values are offset + component.dx = p.parseShort(); + component.dy = p.parseShort(); + } else { + // values are matched points + component.matchedPoints = [p.parseUShort(), p.parseUShort()]; + } + } else { + // The arguments are bytes + if ((flags & 2) > 0) { + // values are offset + component.dx = p.parseChar(); + component.dy = p.parseChar(); + } else { + // values are matched points + component.matchedPoints = [p.parseByte(), p.parseByte()]; + } + } + + if ((flags & 8) > 0) { + // We have a scale + component.xScale = component.yScale = p.parseF2Dot14(); + } else if ((flags & 64) > 0) { + // We have an X / Y scale + component.xScale = p.parseF2Dot14(); + component.yScale = p.parseF2Dot14(); + } else if ((flags & 128) > 0) { + // We have a 2x2 transformation + component.xScale = p.parseF2Dot14(); + component.scale01 = p.parseF2Dot14(); + component.scale10 = p.parseF2Dot14(); + component.yScale = p.parseF2Dot14(); + } + + glyph.components.push(component); + moreComponents = !!(flags & 32); + } + if (flags & 0x100) { + // We have instructions + glyph.instructionLength = p.parseUShort(); + glyph.instructions = []; + for (var i$6 = 0; i$6 < glyph.instructionLength; i$6 += 1) { + glyph.instructions.push(p.parseByte()); + } + } + } + } + + // Transform an array of points and return a new array. + function transformPoints(points, transform) { + var newPoints = []; + for (var i = 0; i < points.length; i += 1) { + var pt = points[i]; + var newPt = { + x: transform.xScale * pt.x + transform.scale01 * pt.y + transform.dx, + y: transform.scale10 * pt.x + transform.yScale * pt.y + transform.dy, + onCurve: pt.onCurve, + lastPointOfContour: pt.lastPointOfContour + }; + newPoints.push(newPt); + } + + return newPoints; + } + + function getContours(points) { + var contours = []; + var currentContour = []; + for (var i = 0; i < points.length; i += 1) { + var pt = points[i]; + currentContour.push(pt); + if (pt.lastPointOfContour) { + contours.push(currentContour); + currentContour = []; + } + } + + check.argument( + currentContour.length === 0, + 'There are still points left in the current contour.' + ); + return contours; + } + + // Convert the TrueType glyph outline to a Path. + function getPath(points) { + var p = new Path(); + if (!points) { + return p; + } + + var contours = getContours(points); + + for (var contourIndex = 0; contourIndex < contours.length; ++contourIndex) { + var contour = contours[contourIndex]; + + var prev = null; + var curr = contour[contour.length - 1]; + var next = contour[0]; + + if (curr.onCurve) { + p.moveTo(curr.x, curr.y); + } else { + if (next.onCurve) { + p.moveTo(next.x, next.y); + } else { + // If both first and last points are off-curve, start at their middle. + var start = { + x: (curr.x + next.x) * 0.5, + y: (curr.y + next.y) * 0.5 + }; + p.moveTo(start.x, start.y); + } + } + + for (var i = 0; i < contour.length; ++i) { + prev = curr; + curr = next; + next = contour[(i + 1) % contour.length]; + + if (curr.onCurve) { + // This is a straight line. + p.lineTo(curr.x, curr.y); + } else { + var prev2 = prev; + var next2 = next; + + if (!prev.onCurve) { + prev2 = { x: (curr.x + prev.x) * 0.5, y: (curr.y + prev.y) * 0.5 }; + } + + if (!next.onCurve) { + next2 = { x: (curr.x + next.x) * 0.5, y: (curr.y + next.y) * 0.5 }; + } + + p.quadraticCurveTo(curr.x, curr.y, next2.x, next2.y); + } + } + + p.closePath(); + } + return p; + } + + function buildPath(glyphs, glyph) { + if (glyph.isComposite) { + for (var j = 0; j < glyph.components.length; j += 1) { + var component = glyph.components[j]; + var componentGlyph = glyphs.get(component.glyphIndex); + // Force the ttfGlyphLoader to parse the glyph. + componentGlyph.getPath(); + if (componentGlyph.points) { + var transformedPoints = void 0; + if (component.matchedPoints === undefined) { + // component positioned by offset + transformedPoints = transformPoints( + componentGlyph.points, + component + ); + } else { + // component positioned by matched points + if ( + component.matchedPoints[0] > glyph.points.length - 1 || + component.matchedPoints[1] > componentGlyph.points.length - 1 + ) { + throw Error('Matched points out of range in ' + glyph.name); + } + var firstPt = glyph.points[component.matchedPoints[0]]; + var secondPt = componentGlyph.points[component.matchedPoints[1]]; + var transform = { + xScale: component.xScale, + scale01: component.scale01, + scale10: component.scale10, + yScale: component.yScale, + dx: 0, + dy: 0 + }; + secondPt = transformPoints([secondPt], transform)[0]; + transform.dx = firstPt.x - secondPt.x; + transform.dy = firstPt.y - secondPt.y; + transformedPoints = transformPoints( + componentGlyph.points, + transform + ); + } + glyph.points = glyph.points.concat(transformedPoints); + } + } + } + + return getPath(glyph.points); + } + + // Parse all the glyphs according to the offsets from the `loca` table. + function parseGlyfTable(data, start, loca, font) { + var glyphs = new glyphset.GlyphSet(font); + + // The last element of the loca table is invalid. + for (var i = 0; i < loca.length - 1; i += 1) { + var offset = loca[i]; + var nextOffset = loca[i + 1]; + if (offset !== nextOffset) { + glyphs.push( + i, + glyphset.ttfGlyphLoader( + font, + i, + parseGlyph, + data, + start + offset, + buildPath + ) + ); + } else { + glyphs.push(i, glyphset.glyphLoader(font, i)); + } + } + + return glyphs; + } + + var glyf = { getPath: getPath, parse: parseGlyfTable }; + + /* A TrueType font hinting interpreter. + * + * (c) 2017 Axel Kittenberger + * + * This interpreter has been implemented according to this documentation: + * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM05/Chap5.html + * + * According to the documentation F24DOT6 values are used for pixels. + * That means calculation is 1/64 pixel accurate and uses integer operations. + * However, Javascript has floating point operations by default and only + * those are available. One could make a case to simulate the 1/64 accuracy + * exactly by truncating after every division operation + * (for example with << 0) to get pixel exactly results as other TrueType + * implementations. It may make sense since some fonts are pixel optimized + * by hand using DELTAP instructions. The current implementation doesn't + * and rather uses full floating point precision. + * + * xScale, yScale and rotation is currently ignored. + * + * A few non-trivial instructions are missing as I didn't encounter yet + * a font that used them to test a possible implementation. + * + * Some fonts seem to use undocumented features regarding the twilight zone. + * Only some of them are implemented as they were encountered. + * + * The exports.DEBUG statements are removed on the minified distribution file. + */ + + var instructionTable; + var exec; + var execGlyph; + var execComponent; + + /* + * Creates a hinting object. + * + * There ought to be exactly one + * for each truetype font that is used for hinting. + */ + function Hinting(font) { + // the font this hinting object is for + this.font = font; + + this.getCommands = function(hPoints) { + return glyf.getPath(hPoints).commands; + }; + + // cached states + this._fpgmState = this._prepState = undefined; + + // errorState + // 0 ... all okay + // 1 ... had an error in a glyf, + // continue working but stop spamming + // the console + // 2 ... error at prep, stop hinting at this ppem + // 3 ... error at fpeg, stop hinting for this font at all + this._errorState = 0; + } + + /* + * Not rounding. + */ + function roundOff(v) { + return v; + } + + /* + * Rounding to grid. + */ + function roundToGrid(v) { + //Rounding in TT is supposed to "symmetrical around zero" + return Math.sign(v) * Math.round(Math.abs(v)); + } + + /* + * Rounding to double grid. + */ + function roundToDoubleGrid(v) { + return Math.sign(v) * Math.round(Math.abs(v * 2)) / 2; + } + + /* + * Rounding to half grid. + */ + function roundToHalfGrid(v) { + return Math.sign(v) * (Math.round(Math.abs(v) + 0.5) - 0.5); + } + + /* + * Rounding to up to grid. + */ + function roundUpToGrid(v) { + return Math.sign(v) * Math.ceil(Math.abs(v)); + } + + /* + * Rounding to down to grid. + */ + function roundDownToGrid(v) { + return Math.sign(v) * Math.floor(Math.abs(v)); + } + + /* + * Super rounding. + */ + var roundSuper = function(v) { + var period = this.srPeriod; + var phase = this.srPhase; + var threshold = this.srThreshold; + var sign = 1; + + if (v < 0) { + v = -v; + sign = -1; + } + + v += threshold - phase; + + v = Math.trunc(v / period) * period; + + v += phase; + + // according to http://xgridfit.sourceforge.net/round.html + if (v < 0) { + return phase * sign; + } + + return v * sign; + }; + + /* + * Unit vector of x-axis. + */ + var xUnitVector = { + x: 1, + + y: 0, + + axis: 'x', + + // Gets the projected distance between two points. + // o1/o2 ... if true, respective original position is used. + distance: function(p1, p2, o1, o2) { + return (o1 ? p1.xo : p1.x) - (o2 ? p2.xo : p2.x); + }, + + // Moves point p so the moved position has the same relative + // position to the moved positions of rp1 and rp2 than the + // original positions had. + // + // See APPENDIX on INTERPOLATE at the bottom of this file. + interpolate: function(p, rp1, rp2, pv) { + var do1; + var do2; + var doa1; + var doa2; + var dm1; + var dm2; + var dt; + + if (!pv || pv === this) { + do1 = p.xo - rp1.xo; + do2 = p.xo - rp2.xo; + dm1 = rp1.x - rp1.xo; + dm2 = rp2.x - rp2.xo; + doa1 = Math.abs(do1); + doa2 = Math.abs(do2); + dt = doa1 + doa2; + + if (dt === 0) { + p.x = p.xo + (dm1 + dm2) / 2; + return; + } + + p.x = p.xo + (dm1 * doa2 + dm2 * doa1) / dt; + return; + } + + do1 = pv.distance(p, rp1, true, true); + do2 = pv.distance(p, rp2, true, true); + dm1 = pv.distance(rp1, rp1, false, true); + dm2 = pv.distance(rp2, rp2, false, true); + doa1 = Math.abs(do1); + doa2 = Math.abs(do2); + dt = doa1 + doa2; + + if (dt === 0) { + xUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true); + return; + } + + xUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true); + }, + + // Slope of line normal to this + normalSlope: Number.NEGATIVE_INFINITY, + + // Sets the point 'p' relative to point 'rp' + // by the distance 'd'. + // + // See APPENDIX on SETRELATIVE at the bottom of this file. + // + // p ... point to set + // rp ... reference point + // d ... distance on projection vector + // pv ... projection vector (undefined = this) + // org ... if true, uses the original position of rp as reference. + setRelative: function(p, rp, d, pv, org) { + if (!pv || pv === this) { + p.x = (org ? rp.xo : rp.x) + d; + return; + } + + var rpx = org ? rp.xo : rp.x; + var rpy = org ? rp.yo : rp.y; + var rpdx = rpx + d * pv.x; + var rpdy = rpy + d * pv.y; + + p.x = rpdx + (p.y - rpdy) / pv.normalSlope; + }, + + // Slope of vector line. + slope: 0, + + // Touches the point p. + touch: function(p) { + p.xTouched = true; + }, + + // Tests if a point p is touched. + touched: function(p) { + return p.xTouched; + }, + + // Untouches the point p. + untouch: function(p) { + p.xTouched = false; + } + }; + + /* + * Unit vector of y-axis. + */ + var yUnitVector = { + x: 0, + + y: 1, + + axis: 'y', + + // Gets the projected distance between two points. + // o1/o2 ... if true, respective original position is used. + distance: function(p1, p2, o1, o2) { + return (o1 ? p1.yo : p1.y) - (o2 ? p2.yo : p2.y); + }, + + // Moves point p so the moved position has the same relative + // position to the moved positions of rp1 and rp2 than the + // original positions had. + // + // See APPENDIX on INTERPOLATE at the bottom of this file. + interpolate: function(p, rp1, rp2, pv) { + var do1; + var do2; + var doa1; + var doa2; + var dm1; + var dm2; + var dt; + + if (!pv || pv === this) { + do1 = p.yo - rp1.yo; + do2 = p.yo - rp2.yo; + dm1 = rp1.y - rp1.yo; + dm2 = rp2.y - rp2.yo; + doa1 = Math.abs(do1); + doa2 = Math.abs(do2); + dt = doa1 + doa2; + + if (dt === 0) { + p.y = p.yo + (dm1 + dm2) / 2; + return; + } + + p.y = p.yo + (dm1 * doa2 + dm2 * doa1) / dt; + return; + } + + do1 = pv.distance(p, rp1, true, true); + do2 = pv.distance(p, rp2, true, true); + dm1 = pv.distance(rp1, rp1, false, true); + dm2 = pv.distance(rp2, rp2, false, true); + doa1 = Math.abs(do1); + doa2 = Math.abs(do2); + dt = doa1 + doa2; + + if (dt === 0) { + yUnitVector.setRelative(p, p, (dm1 + dm2) / 2, pv, true); + return; + } + + yUnitVector.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true); + }, + + // Slope of line normal to this. + normalSlope: 0, + + // Sets the point 'p' relative to point 'rp' + // by the distance 'd' + // + // See APPENDIX on SETRELATIVE at the bottom of this file. + // + // p ... point to set + // rp ... reference point + // d ... distance on projection vector + // pv ... projection vector (undefined = this) + // org ... if true, uses the original position of rp as reference. + setRelative: function(p, rp, d, pv, org) { + if (!pv || pv === this) { + p.y = (org ? rp.yo : rp.y) + d; + return; + } + + var rpx = org ? rp.xo : rp.x; + var rpy = org ? rp.yo : rp.y; + var rpdx = rpx + d * pv.x; + var rpdy = rpy + d * pv.y; + + p.y = rpdy + pv.normalSlope * (p.x - rpdx); + }, + + // Slope of vector line. + slope: Number.POSITIVE_INFINITY, + + // Touches the point p. + touch: function(p) { + p.yTouched = true; + }, + + // Tests if a point p is touched. + touched: function(p) { + return p.yTouched; + }, + + // Untouches the point p. + untouch: function(p) { + p.yTouched = false; + } + }; + + Object.freeze(xUnitVector); + Object.freeze(yUnitVector); + + /* + * Creates a unit vector that is not x- or y-axis. + */ + function UnitVector(x, y) { + this.x = x; + this.y = y; + this.axis = undefined; + this.slope = y / x; + this.normalSlope = -x / y; + Object.freeze(this); + } + + /* + * Gets the projected distance between two points. + * o1/o2 ... if true, respective original position is used. + */ + UnitVector.prototype.distance = function(p1, p2, o1, o2) { + return ( + this.x * xUnitVector.distance(p1, p2, o1, o2) + + this.y * yUnitVector.distance(p1, p2, o1, o2) + ); + }; + + /* + * Moves point p so the moved position has the same relative + * position to the moved positions of rp1 and rp2 than the + * original positions had. + * + * See APPENDIX on INTERPOLATE at the bottom of this file. + */ + UnitVector.prototype.interpolate = function(p, rp1, rp2, pv) { + var dm1; + var dm2; + var do1; + var do2; + var doa1; + var doa2; + var dt; + + do1 = pv.distance(p, rp1, true, true); + do2 = pv.distance(p, rp2, true, true); + dm1 = pv.distance(rp1, rp1, false, true); + dm2 = pv.distance(rp2, rp2, false, true); + doa1 = Math.abs(do1); + doa2 = Math.abs(do2); + dt = doa1 + doa2; + + if (dt === 0) { + this.setRelative(p, p, (dm1 + dm2) / 2, pv, true); + return; + } + + this.setRelative(p, p, (dm1 * doa2 + dm2 * doa1) / dt, pv, true); + }; + + /* + * Sets the point 'p' relative to point 'rp' + * by the distance 'd' + * + * See APPENDIX on SETRELATIVE at the bottom of this file. + * + * p ... point to set + * rp ... reference point + * d ... distance on projection vector + * pv ... projection vector (undefined = this) + * org ... if true, uses the original position of rp as reference. + */ + UnitVector.prototype.setRelative = function(p, rp, d, pv, org) { + pv = pv || this; + + var rpx = org ? rp.xo : rp.x; + var rpy = org ? rp.yo : rp.y; + var rpdx = rpx + d * pv.x; + var rpdy = rpy + d * pv.y; + + var pvns = pv.normalSlope; + var fvs = this.slope; + + var px = p.x; + var py = p.y; + + p.x = (fvs * px - pvns * rpdx + rpdy - py) / (fvs - pvns); + p.y = fvs * (p.x - px) + py; + }; + + /* + * Touches the point p. + */ + UnitVector.prototype.touch = function(p) { + p.xTouched = true; + p.yTouched = true; + }; + + /* + * Returns a unit vector with x/y coordinates. + */ + function getUnitVector(x, y) { + var d = Math.sqrt(x * x + y * y); + + x /= d; + y /= d; + + if (x === 1 && y === 0) { + return xUnitVector; + } else if (x === 0 && y === 1) { + return yUnitVector; + } else { + return new UnitVector(x, y); + } + } + + /* + * Creates a point in the hinting engine. + */ + function HPoint(x, y, lastPointOfContour, onCurve) { + this.x = this.xo = Math.round(x * 64) / 64; // hinted x value and original x-value + this.y = this.yo = Math.round(y * 64) / 64; // hinted y value and original y-value + + this.lastPointOfContour = lastPointOfContour; + this.onCurve = onCurve; + this.prevPointOnContour = undefined; + this.nextPointOnContour = undefined; + this.xTouched = false; + this.yTouched = false; + + Object.preventExtensions(this); + } + + /* + * Returns the next touched point on the contour. + * + * v ... unit vector to test touch axis. + */ + HPoint.prototype.nextTouched = function(v) { + var p = this.nextPointOnContour; + + while (!v.touched(p) && p !== this) { + p = p.nextPointOnContour; + } + + return p; + }; + + /* + * Returns the previous touched point on the contour + * + * v ... unit vector to test touch axis. + */ + HPoint.prototype.prevTouched = function(v) { + var p = this.prevPointOnContour; + + while (!v.touched(p) && p !== this) { + p = p.prevPointOnContour; + } + + return p; + }; + + /* + * The zero point. + */ + var HPZero = Object.freeze(new HPoint(0, 0)); + + /* + * The default state of the interpreter. + * + * Note: Freezing the defaultState and then deriving from it + * makes the V8 Javascript engine going awkward, + * so this is avoided, albeit the defaultState shouldn't + * ever change. + */ + var defaultState = { + cvCutIn: 17 / 16, // control value cut in + deltaBase: 9, + deltaShift: 0.125, + loop: 1, // loops some instructions + minDis: 1, // minimum distance + autoFlip: true + }; + + /* + * The current state of the interpreter. + * + * env ... 'fpgm' or 'prep' or 'glyf' + * prog ... the program + */ + function State(env, prog) { + this.env = env; + this.stack = []; + this.prog = prog; + + switch (env) { + case 'glyf': + this.zp0 = this.zp1 = this.zp2 = 1; + this.rp0 = this.rp1 = this.rp2 = 0; + /* fall through */ + case 'prep': + this.fv = this.pv = this.dpv = xUnitVector; + this.round = roundToGrid; + } + } + + /* + * Executes a glyph program. + * + * This does the hinting for each glyph. + * + * Returns an array of moved points. + * + * glyph: the glyph to hint + * ppem: the size the glyph is rendered for + */ + Hinting.prototype.exec = function(glyph, ppem) { + if (typeof ppem !== 'number') { + throw new Error('Point size is not a number!'); + } + + // Received a fatal error, don't do any hinting anymore. + if (this._errorState > 2) { + return; + } + + var font = this.font; + var prepState = this._prepState; + + if (!prepState || prepState.ppem !== ppem) { + var fpgmState = this._fpgmState; + + if (!fpgmState) { + // Executes the fpgm state. + // This is used by fonts to define functions. + State.prototype = defaultState; + + fpgmState = this._fpgmState = new State('fpgm', font.tables.fpgm); + + fpgmState.funcs = []; + fpgmState.font = font; + + if (exports.DEBUG) { + console.log('---EXEC FPGM---'); + fpgmState.step = -1; + } + + try { + exec(fpgmState); + } catch (e) { + console.log('Hinting error in FPGM:' + e); + this._errorState = 3; + return; + } + } + + // Executes the prep program for this ppem setting. + // This is used by fonts to set cvt values + // depending on to be rendered font size. + + State.prototype = fpgmState; + prepState = this._prepState = new State('prep', font.tables.prep); + + prepState.ppem = ppem; + + // Creates a copy of the cvt table + // and scales it to the current ppem setting. + var oCvt = font.tables.cvt; + if (oCvt) { + var cvt = (prepState.cvt = new Array(oCvt.length)); + var scale = ppem / font.unitsPerEm; + for (var c = 0; c < oCvt.length; c++) { + cvt[c] = oCvt[c] * scale; + } + } else { + prepState.cvt = []; + } + + if (exports.DEBUG) { + console.log('---EXEC PREP---'); + prepState.step = -1; + } + + try { + exec(prepState); + } catch (e) { + if (this._errorState < 2) { + console.log('Hinting error in PREP:' + e); + } + this._errorState = 2; + } + } + + if (this._errorState > 1) { + return; + } + + try { + return execGlyph(glyph, prepState); + } catch (e) { + if (this._errorState < 1) { + console.log('Hinting error:' + e); + console.log('Note: further hinting errors are silenced'); + } + this._errorState = 1; + return undefined; + } + }; + + /* + * Executes the hinting program for a glyph. + */ + execGlyph = function(glyph, prepState) { + // original point positions + var xScale = prepState.ppem / prepState.font.unitsPerEm; + var yScale = xScale; + var components = glyph.components; + var contours; + var gZone; + var state; + + State.prototype = prepState; + if (!components) { + state = new State('glyf', glyph.instructions); + if (exports.DEBUG) { + console.log('---EXEC GLYPH---'); + state.step = -1; + } + execComponent(glyph, state, xScale, yScale); + gZone = state.gZone; + } else { + var font = prepState.font; + gZone = []; + contours = []; + for (var i = 0; i < components.length; i++) { + var c = components[i]; + var cg = font.glyphs.get(c.glyphIndex); + + state = new State('glyf', cg.instructions); + + if (exports.DEBUG) { + console.log('---EXEC COMP ' + i + '---'); + state.step = -1; + } + + execComponent(cg, state, xScale, yScale); + // appends the computed points to the result array + // post processes the component points + var dx = Math.round(c.dx * xScale); + var dy = Math.round(c.dy * yScale); + var gz = state.gZone; + var cc = state.contours; + for (var pi = 0; pi < gz.length; pi++) { + var p = gz[pi]; + p.xTouched = p.yTouched = false; + p.xo = p.x = p.x + dx; + p.yo = p.y = p.y + dy; + } + + var gLen = gZone.length; + gZone.push.apply(gZone, gz); + for (var j = 0; j < cc.length; j++) { + contours.push(cc[j] + gLen); + } + } + + if (glyph.instructions && !state.inhibitGridFit) { + // the composite has instructions on its own + state = new State('glyf', glyph.instructions); + + state.gZone = state.z0 = state.z1 = state.z2 = gZone; + + state.contours = contours; + + // note: HPZero cannot be used here, since + // the point might be modified + gZone.push( + new HPoint(0, 0), + new HPoint(Math.round(glyph.advanceWidth * xScale), 0) + ); + + if (exports.DEBUG) { + console.log('---EXEC COMPOSITE---'); + state.step = -1; + } + + exec(state); + + gZone.length -= 2; + } + } + + return gZone; + }; + + /* + * Executes the hinting program for a component of a multi-component glyph + * or of the glyph itself for a non-component glyph. + */ + execComponent = function(glyph, state, xScale, yScale) { + var points = glyph.points || []; + var pLen = points.length; + var gZone = (state.gZone = state.z0 = state.z1 = state.z2 = []); + var contours = (state.contours = []); + + // Scales the original points and + // makes copies for the hinted points. + var cp; // current point + for (var i = 0; i < pLen; i++) { + cp = points[i]; + + gZone[i] = new HPoint( + cp.x * xScale, + cp.y * yScale, + cp.lastPointOfContour, + cp.onCurve + ); + } + + // Chain links the contours. + var sp; // start point + var np; // next point + + for (var i$1 = 0; i$1 < pLen; i$1++) { + cp = gZone[i$1]; + + if (!sp) { + sp = cp; + contours.push(i$1); + } + + if (cp.lastPointOfContour) { + cp.nextPointOnContour = sp; + sp.prevPointOnContour = cp; + sp = undefined; + } else { + np = gZone[i$1 + 1]; + cp.nextPointOnContour = np; + np.prevPointOnContour = cp; + } + } + + if (state.inhibitGridFit) { + return; + } + + if (exports.DEBUG) { + console.log('PROCESSING GLYPH', state.stack); + for (var i$2 = 0; i$2 < pLen; i$2++) { + console.log(i$2, gZone[i$2].x, gZone[i$2].y); + } + } + + gZone.push( + new HPoint(0, 0), + new HPoint(Math.round(glyph.advanceWidth * xScale), 0) + ); + + exec(state); + + // Removes the extra points. + gZone.length -= 2; + + if (exports.DEBUG) { + console.log('FINISHED GLYPH', state.stack); + for (var i$3 = 0; i$3 < pLen; i$3++) { + console.log(i$3, gZone[i$3].x, gZone[i$3].y); + } + } + }; + + /* + * Executes the program loaded in state. + */ + exec = function(state) { + var prog = state.prog; + + if (!prog) { + return; + } + + var pLen = prog.length; + var ins; + + for (state.ip = 0; state.ip < pLen; state.ip++) { + if (exports.DEBUG) { + state.step++; + } + ins = instructionTable[prog[state.ip]]; + + if (!ins) { + throw new Error( + 'unknown instruction: 0x' + Number(prog[state.ip]).toString(16) + ); + } + + ins(state); + + // very extensive debugging for each step + /* + if (exports.DEBUG) { + var da; + if (state.gZone) { + da = []; + for (let i = 0; i < state.gZone.length; i++) + { + da.push(i + ' ' + + state.gZone[i].x * 64 + ' ' + + state.gZone[i].y * 64 + ' ' + + (state.gZone[i].xTouched ? 'x' : '') + + (state.gZone[i].yTouched ? 'y' : '') + ); + } + console.log('GZ', da); + } + + if (state.tZone) { + da = []; + for (let i = 0; i < state.tZone.length; i++) { + da.push(i + ' ' + + state.tZone[i].x * 64 + ' ' + + state.tZone[i].y * 64 + ' ' + + (state.tZone[i].xTouched ? 'x' : '') + + (state.tZone[i].yTouched ? 'y' : '') + ); + } + console.log('TZ', da); + } + + if (state.stack.length > 10) { + console.log( + state.stack.length, + '...', state.stack.slice(state.stack.length - 10) + ); + } else { + console.log(state.stack.length, state.stack); + } + } + */ + } + }; + + /* + * Initializes the twilight zone. + * + * This is only done if a SZPx instruction + * refers to the twilight zone. + */ + function initTZone(state) { + var tZone = (state.tZone = new Array(state.gZone.length)); + + // no idea if this is actually correct... + for (var i = 0; i < tZone.length; i++) { + tZone[i] = new HPoint(0, 0); + } + } + + /* + * Skips the instruction pointer ahead over an IF/ELSE block. + * handleElse .. if true breaks on matching ELSE + */ + function skip(state, handleElse) { + var prog = state.prog; + var ip = state.ip; + var nesting = 1; + var ins; + + do { + ins = prog[++ip]; + if (ins === 0x58) { + // IF + nesting++; + } else if (ins === 0x59) { + // EIF + nesting--; + } else if (ins === 0x40) { + // NPUSHB + ip += prog[ip + 1] + 1; + } else if (ins === 0x41) { + // NPUSHW + ip += 2 * prog[ip + 1] + 1; + } else if (ins >= 0xb0 && ins <= 0xb7) { + // PUSHB + ip += ins - 0xb0 + 1; + } else if (ins >= 0xb8 && ins <= 0xbf) { + // PUSHW + ip += (ins - 0xb8 + 1) * 2; + } else if (handleElse && nesting === 1 && ins === 0x1b) { + // ELSE + break; + } + } while (nesting > 0); + + state.ip = ip; + } + + /*----------------------------------------------------------* + * And then a lot of instructions... * + *----------------------------------------------------------*/ + + // SVTCA[a] Set freedom and projection Vectors To Coordinate Axis + // 0x00-0x01 + function SVTCA(v, state) { + if (exports.DEBUG) { + console.log(state.step, 'SVTCA[' + v.axis + ']'); + } + + state.fv = state.pv = state.dpv = v; + } + + // SPVTCA[a] Set Projection Vector to Coordinate Axis + // 0x02-0x03 + function SPVTCA(v, state) { + if (exports.DEBUG) { + console.log(state.step, 'SPVTCA[' + v.axis + ']'); + } + + state.pv = state.dpv = v; + } + + // SFVTCA[a] Set Freedom Vector to Coordinate Axis + // 0x04-0x05 + function SFVTCA(v, state) { + if (exports.DEBUG) { + console.log(state.step, 'SFVTCA[' + v.axis + ']'); + } + + state.fv = v; + } + + // SPVTL[a] Set Projection Vector To Line + // 0x06-0x07 + function SPVTL(a, state) { + var stack = state.stack; + var p2i = stack.pop(); + var p1i = stack.pop(); + var p2 = state.z2[p2i]; + var p1 = state.z1[p1i]; + + if (exports.DEBUG) { + console.log('SPVTL[' + a + ']', p2i, p1i); + } + + var dx; + var dy; + + if (!a) { + dx = p1.x - p2.x; + dy = p1.y - p2.y; + } else { + dx = p2.y - p1.y; + dy = p1.x - p2.x; + } + + state.pv = state.dpv = getUnitVector(dx, dy); + } + + // SFVTL[a] Set Freedom Vector To Line + // 0x08-0x09 + function SFVTL(a, state) { + var stack = state.stack; + var p2i = stack.pop(); + var p1i = stack.pop(); + var p2 = state.z2[p2i]; + var p1 = state.z1[p1i]; + + if (exports.DEBUG) { + console.log('SFVTL[' + a + ']', p2i, p1i); + } + + var dx; + var dy; + + if (!a) { + dx = p1.x - p2.x; + dy = p1.y - p2.y; + } else { + dx = p2.y - p1.y; + dy = p1.x - p2.x; + } + + state.fv = getUnitVector(dx, dy); + } + + // SPVFS[] Set Projection Vector From Stack + // 0x0A + function SPVFS(state) { + var stack = state.stack; + var y = stack.pop(); + var x = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SPVFS[]', y, x); + } + + state.pv = state.dpv = getUnitVector(x, y); + } + + // SFVFS[] Set Freedom Vector From Stack + // 0x0B + function SFVFS(state) { + var stack = state.stack; + var y = stack.pop(); + var x = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SPVFS[]', y, x); + } + + state.fv = getUnitVector(x, y); + } + + // GPV[] Get Projection Vector + // 0x0C + function GPV(state) { + var stack = state.stack; + var pv = state.pv; + + if (exports.DEBUG) { + console.log(state.step, 'GPV[]'); + } + + stack.push(pv.x * 0x4000); + stack.push(pv.y * 0x4000); + } + + // GFV[] Get Freedom Vector + // 0x0C + function GFV(state) { + var stack = state.stack; + var fv = state.fv; + + if (exports.DEBUG) { + console.log(state.step, 'GFV[]'); + } + + stack.push(fv.x * 0x4000); + stack.push(fv.y * 0x4000); + } + + // SFVTPV[] Set Freedom Vector To Projection Vector + // 0x0E + function SFVTPV(state) { + state.fv = state.pv; + + if (exports.DEBUG) { + console.log(state.step, 'SFVTPV[]'); + } + } + + // ISECT[] moves point p to the InterSECTion of two lines + // 0x0F + function ISECT(state) { + var stack = state.stack; + var pa0i = stack.pop(); + var pa1i = stack.pop(); + var pb0i = stack.pop(); + var pb1i = stack.pop(); + var pi = stack.pop(); + var z0 = state.z0; + var z1 = state.z1; + var pa0 = z0[pa0i]; + var pa1 = z0[pa1i]; + var pb0 = z1[pb0i]; + var pb1 = z1[pb1i]; + var p = state.z2[pi]; + + if (exports.DEBUG) { + console.log('ISECT[], ', pa0i, pa1i, pb0i, pb1i, pi); + } + + // math from + // en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line + + var x1 = pa0.x; + var y1 = pa0.y; + var x2 = pa1.x; + var y2 = pa1.y; + var x3 = pb0.x; + var y3 = pb0.y; + var x4 = pb1.x; + var y4 = pb1.y; + + var div = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); + var f1 = x1 * y2 - y1 * x2; + var f2 = x3 * y4 - y3 * x4; + + p.x = (f1 * (x3 - x4) - f2 * (x1 - x2)) / div; + p.y = (f1 * (y3 - y4) - f2 * (y1 - y2)) / div; + } + + // SRP0[] Set Reference Point 0 + // 0x10 + function SRP0(state) { + state.rp0 = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SRP0[]', state.rp0); + } + } + + // SRP1[] Set Reference Point 1 + // 0x11 + function SRP1(state) { + state.rp1 = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SRP1[]', state.rp1); + } + } + + // SRP1[] Set Reference Point 2 + // 0x12 + function SRP2(state) { + state.rp2 = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SRP2[]', state.rp2); + } + } + + // SZP0[] Set Zone Pointer 0 + // 0x13 + function SZP0(state) { + var n = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SZP0[]', n); + } + + state.zp0 = n; + + switch (n) { + case 0: + if (!state.tZone) { + initTZone(state); + } + state.z0 = state.tZone; + break; + case 1: + state.z0 = state.gZone; + break; + default: + throw new Error('Invalid zone pointer'); + } + } + + // SZP1[] Set Zone Pointer 1 + // 0x14 + function SZP1(state) { + var n = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SZP1[]', n); + } + + state.zp1 = n; + + switch (n) { + case 0: + if (!state.tZone) { + initTZone(state); + } + state.z1 = state.tZone; + break; + case 1: + state.z1 = state.gZone; + break; + default: + throw new Error('Invalid zone pointer'); + } + } + + // SZP2[] Set Zone Pointer 2 + // 0x15 + function SZP2(state) { + var n = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SZP2[]', n); + } + + state.zp2 = n; + + switch (n) { + case 0: + if (!state.tZone) { + initTZone(state); + } + state.z2 = state.tZone; + break; + case 1: + state.z2 = state.gZone; + break; + default: + throw new Error('Invalid zone pointer'); + } + } + + // SZPS[] Set Zone PointerS + // 0x16 + function SZPS(state) { + var n = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SZPS[]', n); + } + + state.zp0 = state.zp1 = state.zp2 = n; + + switch (n) { + case 0: + if (!state.tZone) { + initTZone(state); + } + state.z0 = state.z1 = state.z2 = state.tZone; + break; + case 1: + state.z0 = state.z1 = state.z2 = state.gZone; + break; + default: + throw new Error('Invalid zone pointer'); + } + } + + // SLOOP[] Set LOOP variable + // 0x17 + function SLOOP(state) { + state.loop = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SLOOP[]', state.loop); + } + } + + // RTG[] Round To Grid + // 0x18 + function RTG(state) { + if (exports.DEBUG) { + console.log(state.step, 'RTG[]'); + } + + state.round = roundToGrid; + } + + // RTHG[] Round To Half Grid + // 0x19 + function RTHG(state) { + if (exports.DEBUG) { + console.log(state.step, 'RTHG[]'); + } + + state.round = roundToHalfGrid; + } + + // SMD[] Set Minimum Distance + // 0x1A + function SMD(state) { + var d = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SMD[]', d); + } + + state.minDis = d / 0x40; + } + + // ELSE[] ELSE clause + // 0x1B + function ELSE(state) { + // This instruction has been reached by executing a then branch + // so it just skips ahead until matching EIF. + // + // In case the IF was negative the IF[] instruction already + // skipped forward over the ELSE[] + + if (exports.DEBUG) { + console.log(state.step, 'ELSE[]'); + } + + skip(state, false); + } + + // JMPR[] JuMP Relative + // 0x1C + function JMPR(state) { + var o = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'JMPR[]', o); + } + + // A jump by 1 would do nothing. + state.ip += o - 1; + } + + // SCVTCI[] Set Control Value Table Cut-In + // 0x1D + function SCVTCI(state) { + var n = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SCVTCI[]', n); + } + + state.cvCutIn = n / 0x40; + } + + // DUP[] DUPlicate top stack element + // 0x20 + function DUP(state) { + var stack = state.stack; + + if (exports.DEBUG) { + console.log(state.step, 'DUP[]'); + } + + stack.push(stack[stack.length - 1]); + } + + // POP[] POP top stack element + // 0x21 + function POP(state) { + if (exports.DEBUG) { + console.log(state.step, 'POP[]'); + } + + state.stack.pop(); + } + + // CLEAR[] CLEAR the stack + // 0x22 + function CLEAR(state) { + if (exports.DEBUG) { + console.log(state.step, 'CLEAR[]'); + } + + state.stack.length = 0; + } + + // SWAP[] SWAP the top two elements on the stack + // 0x23 + function SWAP(state) { + var stack = state.stack; + + var a = stack.pop(); + var b = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SWAP[]'); + } + + stack.push(a); + stack.push(b); + } + + // DEPTH[] DEPTH of the stack + // 0x24 + function DEPTH(state) { + var stack = state.stack; + + if (exports.DEBUG) { + console.log(state.step, 'DEPTH[]'); + } + + stack.push(stack.length); + } + + // LOOPCALL[] LOOPCALL function + // 0x2A + function LOOPCALL(state) { + var stack = state.stack; + var fn = stack.pop(); + var c = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'LOOPCALL[]', fn, c); + } + + // saves callers program + var cip = state.ip; + var cprog = state.prog; + + state.prog = state.funcs[fn]; + + // executes the function + for (var i = 0; i < c; i++) { + exec(state); + + if (exports.DEBUG) { + console.log( + ++state.step, + i + 1 < c ? 'next loopcall' : 'done loopcall', + i + ); + } + } + + // restores the callers program + state.ip = cip; + state.prog = cprog; + } + + // CALL[] CALL function + // 0x2B + function CALL(state) { + var fn = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'CALL[]', fn); + } + + // saves callers program + var cip = state.ip; + var cprog = state.prog; + + state.prog = state.funcs[fn]; + + // executes the function + exec(state); + + // restores the callers program + state.ip = cip; + state.prog = cprog; + + if (exports.DEBUG) { + console.log(++state.step, 'returning from', fn); + } + } + + // CINDEX[] Copy the INDEXed element to the top of the stack + // 0x25 + function CINDEX(state) { + var stack = state.stack; + var k = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'CINDEX[]', k); + } + + // In case of k == 1, it copies the last element after popping + // thus stack.length - k. + stack.push(stack[stack.length - k]); + } + + // MINDEX[] Move the INDEXed element to the top of the stack + // 0x26 + function MINDEX(state) { + var stack = state.stack; + var k = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'MINDEX[]', k); + } + + stack.push(stack.splice(stack.length - k, 1)[0]); + } + + // FDEF[] Function DEFinition + // 0x2C + function FDEF(state) { + if (state.env !== 'fpgm') { + throw new Error('FDEF not allowed here'); + } + var stack = state.stack; + var prog = state.prog; + var ip = state.ip; + + var fn = stack.pop(); + var ipBegin = ip; + + if (exports.DEBUG) { + console.log(state.step, 'FDEF[]', fn); + } + + while (prog[++ip] !== 0x2d) {} + + state.ip = ip; + state.funcs[fn] = prog.slice(ipBegin + 1, ip); + } + + // MDAP[a] Move Direct Absolute Point + // 0x2E-0x2F + function MDAP(round, state) { + var pi = state.stack.pop(); + var p = state.z0[pi]; + var fv = state.fv; + var pv = state.pv; + + if (exports.DEBUG) { + console.log(state.step, 'MDAP[' + round + ']', pi); + } + + var d = pv.distance(p, HPZero); + + if (round) { + d = state.round(d); + } + + fv.setRelative(p, HPZero, d, pv); + fv.touch(p); + + state.rp0 = state.rp1 = pi; + } + + // IUP[a] Interpolate Untouched Points through the outline + // 0x30 + function IUP(v, state) { + var z2 = state.z2; + var pLen = z2.length - 2; + var cp; + var pp; + var np; + + if (exports.DEBUG) { + console.log(state.step, 'IUP[' + v.axis + ']'); + } + + for (var i = 0; i < pLen; i++) { + cp = z2[i]; // current point + + // if this point has been touched go on + if (v.touched(cp)) { + continue; + } + + pp = cp.prevTouched(v); + + // no point on the contour has been touched? + if (pp === cp) { + continue; + } + + np = cp.nextTouched(v); + + if (pp === np) { + // only one point on the contour has been touched + // so simply moves the point like that + + v.setRelative(cp, cp, v.distance(pp, pp, false, true), v, true); + } + + v.interpolate(cp, pp, np, v); + } + } + + // SHP[] SHift Point using reference point + // 0x32-0x33 + function SHP(a, state) { + var stack = state.stack; + var rpi = a ? state.rp1 : state.rp2; + var rp = (a ? state.z0 : state.z1)[rpi]; + var fv = state.fv; + var pv = state.pv; + var loop = state.loop; + var z2 = state.z2; + + while (loop--) { + var pi = stack.pop(); + var p = z2[pi]; + + var d = pv.distance(rp, rp, false, true); + fv.setRelative(p, p, d, pv); + fv.touch(p); + + if (exports.DEBUG) { + console.log( + state.step, + (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + + 'SHP[' + + (a ? 'rp1' : 'rp2') + + ']', + pi + ); + } + } + + state.loop = 1; + } + + // SHC[] SHift Contour using reference point + // 0x36-0x37 + function SHC(a, state) { + var stack = state.stack; + var rpi = a ? state.rp1 : state.rp2; + var rp = (a ? state.z0 : state.z1)[rpi]; + var fv = state.fv; + var pv = state.pv; + var ci = stack.pop(); + var sp = state.z2[state.contours[ci]]; + var p = sp; + + if (exports.DEBUG) { + console.log(state.step, 'SHC[' + a + ']', ci); + } + + var d = pv.distance(rp, rp, false, true); + + do { + if (p !== rp) { + fv.setRelative(p, p, d, pv); + } + p = p.nextPointOnContour; + } while (p !== sp); + } + + // SHZ[] SHift Zone using reference point + // 0x36-0x37 + function SHZ(a, state) { + var stack = state.stack; + var rpi = a ? state.rp1 : state.rp2; + var rp = (a ? state.z0 : state.z1)[rpi]; + var fv = state.fv; + var pv = state.pv; + + var e = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SHZ[' + a + ']', e); + } + + var z; + switch (e) { + case 0: + z = state.tZone; + break; + case 1: + z = state.gZone; + break; + default: + throw new Error('Invalid zone'); + } + + var p; + var d = pv.distance(rp, rp, false, true); + var pLen = z.length - 2; + for (var i = 0; i < pLen; i++) { + p = z[i]; + fv.setRelative(p, p, d, pv); + //if (p !== rp) fv.setRelative(p, p, d, pv); + } + } + + // SHPIX[] SHift point by a PIXel amount + // 0x38 + function SHPIX(state) { + var stack = state.stack; + var loop = state.loop; + var fv = state.fv; + var d = stack.pop() / 0x40; + var z2 = state.z2; + + while (loop--) { + var pi = stack.pop(); + var p = z2[pi]; + + if (exports.DEBUG) { + console.log( + state.step, + (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + + 'SHPIX[]', + pi, + d + ); + } + + fv.setRelative(p, p, d); + fv.touch(p); + } + + state.loop = 1; + } + + // IP[] Interpolate Point + // 0x39 + function IP(state) { + var stack = state.stack; + var rp1i = state.rp1; + var rp2i = state.rp2; + var loop = state.loop; + var rp1 = state.z0[rp1i]; + var rp2 = state.z1[rp2i]; + var fv = state.fv; + var pv = state.dpv; + var z2 = state.z2; + + while (loop--) { + var pi = stack.pop(); + var p = z2[pi]; + + if (exports.DEBUG) { + console.log( + state.step, + (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + 'IP[]', + pi, + rp1i, + '<->', + rp2i + ); + } + + fv.interpolate(p, rp1, rp2, pv); + + fv.touch(p); + } + + state.loop = 1; + } + + // MSIRP[a] Move Stack Indirect Relative Point + // 0x3A-0x3B + function MSIRP(a, state) { + var stack = state.stack; + var d = stack.pop() / 64; + var pi = stack.pop(); + var p = state.z1[pi]; + var rp0 = state.z0[state.rp0]; + var fv = state.fv; + var pv = state.pv; + + fv.setRelative(p, rp0, d, pv); + fv.touch(p); + + if (exports.DEBUG) { + console.log(state.step, 'MSIRP[' + a + ']', d, pi); + } + + state.rp1 = state.rp0; + state.rp2 = pi; + if (a) { + state.rp0 = pi; + } + } + + // ALIGNRP[] Align to reference point. + // 0x3C + function ALIGNRP(state) { + var stack = state.stack; + var rp0i = state.rp0; + var rp0 = state.z0[rp0i]; + var loop = state.loop; + var fv = state.fv; + var pv = state.pv; + var z1 = state.z1; + + while (loop--) { + var pi = stack.pop(); + var p = z1[pi]; + + if (exports.DEBUG) { + console.log( + state.step, + (state.loop > 1 ? 'loop ' + (state.loop - loop) + ': ' : '') + + 'ALIGNRP[]', + pi + ); + } + + fv.setRelative(p, rp0, 0, pv); + fv.touch(p); + } + + state.loop = 1; + } + + // RTG[] Round To Double Grid + // 0x3D + function RTDG(state) { + if (exports.DEBUG) { + console.log(state.step, 'RTDG[]'); + } + + state.round = roundToDoubleGrid; + } + + // MIAP[a] Move Indirect Absolute Point + // 0x3E-0x3F + function MIAP(round, state) { + var stack = state.stack; + var n = stack.pop(); + var pi = stack.pop(); + var p = state.z0[pi]; + var fv = state.fv; + var pv = state.pv; + var cv = state.cvt[n]; + + if (exports.DEBUG) { + console.log(state.step, 'MIAP[' + round + ']', n, '(', cv, ')', pi); + } + + var d = pv.distance(p, HPZero); + + if (round) { + if (Math.abs(d - cv) < state.cvCutIn) { + d = cv; + } + + d = state.round(d); + } + + fv.setRelative(p, HPZero, d, pv); + + if (state.zp0 === 0) { + p.xo = p.x; + p.yo = p.y; + } + + fv.touch(p); + + state.rp0 = state.rp1 = pi; + } + + // NPUSB[] PUSH N Bytes + // 0x40 + function NPUSHB(state) { + var prog = state.prog; + var ip = state.ip; + var stack = state.stack; + + var n = prog[++ip]; + + if (exports.DEBUG) { + console.log(state.step, 'NPUSHB[]', n); + } + + for (var i = 0; i < n; i++) { + stack.push(prog[++ip]); + } + + state.ip = ip; + } + + // NPUSHW[] PUSH N Words + // 0x41 + function NPUSHW(state) { + var ip = state.ip; + var prog = state.prog; + var stack = state.stack; + var n = prog[++ip]; + + if (exports.DEBUG) { + console.log(state.step, 'NPUSHW[]', n); + } + + for (var i = 0; i < n; i++) { + var w = (prog[++ip] << 8) | prog[++ip]; + if (w & 0x8000) { + w = -((w ^ 0xffff) + 1); + } + stack.push(w); + } + + state.ip = ip; + } + + // WS[] Write Store + // 0x42 + function WS(state) { + var stack = state.stack; + var store = state.store; + + if (!store) { + store = state.store = []; + } + + var v = stack.pop(); + var l = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'WS', v, l); + } + + store[l] = v; + } + + // RS[] Read Store + // 0x43 + function RS(state) { + var stack = state.stack; + var store = state.store; + + var l = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'RS', l); + } + + var v = (store && store[l]) || 0; + + stack.push(v); + } + + // WCVTP[] Write Control Value Table in Pixel units + // 0x44 + function WCVTP(state) { + var stack = state.stack; + + var v = stack.pop(); + var l = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'WCVTP', v, l); + } + + state.cvt[l] = v / 0x40; + } + + // RCVT[] Read Control Value Table entry + // 0x45 + function RCVT(state) { + var stack = state.stack; + var cvte = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'RCVT', cvte); + } + + stack.push(state.cvt[cvte] * 0x40); + } + + // GC[] Get Coordinate projected onto the projection vector + // 0x46-0x47 + function GC(a, state) { + var stack = state.stack; + var pi = stack.pop(); + var p = state.z2[pi]; + + if (exports.DEBUG) { + console.log(state.step, 'GC[' + a + ']', pi); + } + + stack.push(state.dpv.distance(p, HPZero, a, false) * 0x40); + } + + // MD[a] Measure Distance + // 0x49-0x4A + function MD(a, state) { + var stack = state.stack; + var pi2 = stack.pop(); + var pi1 = stack.pop(); + var p2 = state.z1[pi2]; + var p1 = state.z0[pi1]; + var d = state.dpv.distance(p1, p2, a, a); + + if (exports.DEBUG) { + console.log(state.step, 'MD[' + a + ']', pi2, pi1, '->', d); + } + + state.stack.push(Math.round(d * 64)); + } + + // MPPEM[] Measure Pixels Per EM + // 0x4B + function MPPEM(state) { + if (exports.DEBUG) { + console.log(state.step, 'MPPEM[]'); + } + state.stack.push(state.ppem); + } + + // FLIPON[] set the auto FLIP Boolean to ON + // 0x4D + function FLIPON(state) { + if (exports.DEBUG) { + console.log(state.step, 'FLIPON[]'); + } + state.autoFlip = true; + } + + // LT[] Less Than + // 0x50 + function LT(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'LT[]', e2, e1); + } + + stack.push(e1 < e2 ? 1 : 0); + } + + // LTEQ[] Less Than or EQual + // 0x53 + function LTEQ(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'LTEQ[]', e2, e1); + } + + stack.push(e1 <= e2 ? 1 : 0); + } + + // GTEQ[] Greater Than + // 0x52 + function GT(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'GT[]', e2, e1); + } + + stack.push(e1 > e2 ? 1 : 0); + } + + // GTEQ[] Greater Than or EQual + // 0x53 + function GTEQ(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'GTEQ[]', e2, e1); + } + + stack.push(e1 >= e2 ? 1 : 0); + } + + // EQ[] EQual + // 0x54 + function EQ(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'EQ[]', e2, e1); + } + + stack.push(e2 === e1 ? 1 : 0); + } + + // NEQ[] Not EQual + // 0x55 + function NEQ(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'NEQ[]', e2, e1); + } + + stack.push(e2 !== e1 ? 1 : 0); + } + + // ODD[] ODD + // 0x56 + function ODD(state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'ODD[]', n); + } + + stack.push(Math.trunc(n) % 2 ? 1 : 0); + } + + // EVEN[] EVEN + // 0x57 + function EVEN(state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'EVEN[]', n); + } + + stack.push(Math.trunc(n) % 2 ? 0 : 1); + } + + // IF[] IF test + // 0x58 + function IF(state) { + var test = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'IF[]', test); + } + + // if test is true it just continues + // if not the ip is skipped until matching ELSE or EIF + if (!test) { + skip(state, true); + + if (exports.DEBUG) { + console.log(state.step, 'EIF[]'); + } + } + } + + // EIF[] End IF + // 0x59 + function EIF(state) { + // this can be reached normally when + // executing an else branch. + // -> just ignore it + + if (exports.DEBUG) { + console.log(state.step, 'EIF[]'); + } + } + + // AND[] logical AND + // 0x5A + function AND(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'AND[]', e2, e1); + } + + stack.push(e2 && e1 ? 1 : 0); + } + + // OR[] logical OR + // 0x5B + function OR(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'OR[]', e2, e1); + } + + stack.push(e2 || e1 ? 1 : 0); + } + + // NOT[] logical NOT + // 0x5C + function NOT(state) { + var stack = state.stack; + var e = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'NOT[]', e); + } + + stack.push(e ? 0 : 1); + } + + // DELTAP1[] DELTA exception P1 + // DELTAP2[] DELTA exception P2 + // DELTAP3[] DELTA exception P3 + // 0x5D, 0x71, 0x72 + function DELTAP123(b, state) { + var stack = state.stack; + var n = stack.pop(); + var fv = state.fv; + var pv = state.pv; + var ppem = state.ppem; + var base = state.deltaBase + (b - 1) * 16; + var ds = state.deltaShift; + var z0 = state.z0; + + if (exports.DEBUG) { + console.log(state.step, 'DELTAP[' + b + ']', n, stack); + } + + for (var i = 0; i < n; i++) { + var pi = stack.pop(); + var arg = stack.pop(); + var appem = base + ((arg & 0xf0) >> 4); + if (appem !== ppem) { + continue; + } + + var mag = (arg & 0x0f) - 8; + if (mag >= 0) { + mag++; + } + if (exports.DEBUG) { + console.log(state.step, 'DELTAPFIX', pi, 'by', mag * ds); + } + + var p = z0[pi]; + fv.setRelative(p, p, mag * ds, pv); + } + } + + // SDB[] Set Delta Base in the graphics state + // 0x5E + function SDB(state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SDB[]', n); + } + + state.deltaBase = n; + } + + // SDS[] Set Delta Shift in the graphics state + // 0x5F + function SDS(state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SDS[]', n); + } + + state.deltaShift = Math.pow(0.5, n); + } + + // ADD[] ADD + // 0x60 + function ADD(state) { + var stack = state.stack; + var n2 = stack.pop(); + var n1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'ADD[]', n2, n1); + } + + stack.push(n1 + n2); + } + + // SUB[] SUB + // 0x61 + function SUB(state) { + var stack = state.stack; + var n2 = stack.pop(); + var n1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SUB[]', n2, n1); + } + + stack.push(n1 - n2); + } + + // DIV[] DIV + // 0x62 + function DIV(state) { + var stack = state.stack; + var n2 = stack.pop(); + var n1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'DIV[]', n2, n1); + } + + stack.push(n1 * 64 / n2); + } + + // MUL[] MUL + // 0x63 + function MUL(state) { + var stack = state.stack; + var n2 = stack.pop(); + var n1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'MUL[]', n2, n1); + } + + stack.push(n1 * n2 / 64); + } + + // ABS[] ABSolute value + // 0x64 + function ABS(state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'ABS[]', n); + } + + stack.push(Math.abs(n)); + } + + // NEG[] NEGate + // 0x65 + function NEG(state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'NEG[]', n); + } + + stack.push(-n); + } + + // FLOOR[] FLOOR + // 0x66 + function FLOOR(state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'FLOOR[]', n); + } + + stack.push(Math.floor(n / 0x40) * 0x40); + } + + // CEILING[] CEILING + // 0x67 + function CEILING(state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'CEILING[]', n); + } + + stack.push(Math.ceil(n / 0x40) * 0x40); + } + + // ROUND[ab] ROUND value + // 0x68-0x6B + function ROUND(dt, state) { + var stack = state.stack; + var n = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'ROUND[]'); + } + + stack.push(state.round(n / 0x40) * 0x40); + } + + // WCVTF[] Write Control Value Table in Funits + // 0x70 + function WCVTF(state) { + var stack = state.stack; + var v = stack.pop(); + var l = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'WCVTF[]', v, l); + } + + state.cvt[l] = v * state.ppem / state.font.unitsPerEm; + } + + // DELTAC1[] DELTA exception C1 + // DELTAC2[] DELTA exception C2 + // DELTAC3[] DELTA exception C3 + // 0x73, 0x74, 0x75 + function DELTAC123(b, state) { + var stack = state.stack; + var n = stack.pop(); + var ppem = state.ppem; + var base = state.deltaBase + (b - 1) * 16; + var ds = state.deltaShift; + + if (exports.DEBUG) { + console.log(state.step, 'DELTAC[' + b + ']', n, stack); + } + + for (var i = 0; i < n; i++) { + var c = stack.pop(); + var arg = stack.pop(); + var appem = base + ((arg & 0xf0) >> 4); + if (appem !== ppem) { + continue; + } + + var mag = (arg & 0x0f) - 8; + if (mag >= 0) { + mag++; + } + + var delta = mag * ds; + + if (exports.DEBUG) { + console.log(state.step, 'DELTACFIX', c, 'by', delta); + } + + state.cvt[c] += delta; + } + } + + // SROUND[] Super ROUND + // 0x76 + function SROUND(state) { + var n = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'SROUND[]', n); + } + + state.round = roundSuper; + + var period; + + switch (n & 0xc0) { + case 0x00: + period = 0.5; + break; + case 0x40: + period = 1; + break; + case 0x80: + period = 2; + break; + default: + throw new Error('invalid SROUND value'); + } + + state.srPeriod = period; + + switch (n & 0x30) { + case 0x00: + state.srPhase = 0; + break; + case 0x10: + state.srPhase = 0.25 * period; + break; + case 0x20: + state.srPhase = 0.5 * period; + break; + case 0x30: + state.srPhase = 0.75 * period; + break; + default: + throw new Error('invalid SROUND value'); + } + + n &= 0x0f; + + if (n === 0) { + state.srThreshold = 0; + } else { + state.srThreshold = (n / 8 - 0.5) * period; + } + } + + // S45ROUND[] Super ROUND 45 degrees + // 0x77 + function S45ROUND(state) { + var n = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'S45ROUND[]', n); + } + + state.round = roundSuper; + + var period; + + switch (n & 0xc0) { + case 0x00: + period = Math.sqrt(2) / 2; + break; + case 0x40: + period = Math.sqrt(2); + break; + case 0x80: + period = 2 * Math.sqrt(2); + break; + default: + throw new Error('invalid S45ROUND value'); + } + + state.srPeriod = period; + + switch (n & 0x30) { + case 0x00: + state.srPhase = 0; + break; + case 0x10: + state.srPhase = 0.25 * period; + break; + case 0x20: + state.srPhase = 0.5 * period; + break; + case 0x30: + state.srPhase = 0.75 * period; + break; + default: + throw new Error('invalid S45ROUND value'); + } + + n &= 0x0f; + + if (n === 0) { + state.srThreshold = 0; + } else { + state.srThreshold = (n / 8 - 0.5) * period; + } + } + + // ROFF[] Round Off + // 0x7A + function ROFF(state) { + if (exports.DEBUG) { + console.log(state.step, 'ROFF[]'); + } + + state.round = roundOff; + } + + // RUTG[] Round Up To Grid + // 0x7C + function RUTG(state) { + if (exports.DEBUG) { + console.log(state.step, 'RUTG[]'); + } + + state.round = roundUpToGrid; + } + + // RDTG[] Round Down To Grid + // 0x7D + function RDTG(state) { + if (exports.DEBUG) { + console.log(state.step, 'RDTG[]'); + } + + state.round = roundDownToGrid; + } + + // SCANCTRL[] SCAN conversion ConTRoL + // 0x85 + function SCANCTRL(state) { + var n = state.stack.pop(); + + // ignored by opentype.js + + if (exports.DEBUG) { + console.log(state.step, 'SCANCTRL[]', n); + } + } + + // SDPVTL[a] Set Dual Projection Vector To Line + // 0x86-0x87 + function SDPVTL(a, state) { + var stack = state.stack; + var p2i = stack.pop(); + var p1i = stack.pop(); + var p2 = state.z2[p2i]; + var p1 = state.z1[p1i]; + + if (exports.DEBUG) { + console.log(state.step, 'SDPVTL[' + a + ']', p2i, p1i); + } + + var dx; + var dy; + + if (!a) { + dx = p1.x - p2.x; + dy = p1.y - p2.y; + } else { + dx = p2.y - p1.y; + dy = p1.x - p2.x; + } + + state.dpv = getUnitVector(dx, dy); + } + + // GETINFO[] GET INFOrmation + // 0x88 + function GETINFO(state) { + var stack = state.stack; + var sel = stack.pop(); + var r = 0; + + if (exports.DEBUG) { + console.log(state.step, 'GETINFO[]', sel); + } + + // v35 as in no subpixel hinting + if (sel & 0x01) { + r = 35; + } + + // TODO rotation and stretch currently not supported + // and thus those GETINFO are always 0. + + // opentype.js is always gray scaling + if (sel & 0x20) { + r |= 0x1000; + } + + stack.push(r); + } + + // ROLL[] ROLL the top three stack elements + // 0x8A + function ROLL(state) { + var stack = state.stack; + var a = stack.pop(); + var b = stack.pop(); + var c = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'ROLL[]'); + } + + stack.push(b); + stack.push(a); + stack.push(c); + } + + // MAX[] MAXimum of top two stack elements + // 0x8B + function MAX(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'MAX[]', e2, e1); + } + + stack.push(Math.max(e1, e2)); + } + + // MIN[] MINimum of top two stack elements + // 0x8C + function MIN(state) { + var stack = state.stack; + var e2 = stack.pop(); + var e1 = stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'MIN[]', e2, e1); + } + + stack.push(Math.min(e1, e2)); + } + + // SCANTYPE[] SCANTYPE + // 0x8D + function SCANTYPE(state) { + var n = state.stack.pop(); + // ignored by opentype.js + if (exports.DEBUG) { + console.log(state.step, 'SCANTYPE[]', n); + } + } + + // INSTCTRL[] INSTCTRL + // 0x8D + function INSTCTRL(state) { + var s = state.stack.pop(); + var v = state.stack.pop(); + + if (exports.DEBUG) { + console.log(state.step, 'INSTCTRL[]', s, v); + } + + switch (s) { + case 1: + state.inhibitGridFit = !!v; + return; + case 2: + state.ignoreCvt = !!v; + return; + default: + throw new Error('invalid INSTCTRL[] selector'); + } + } + + // PUSHB[abc] PUSH Bytes + // 0xB0-0xB7 + function PUSHB(n, state) { + var stack = state.stack; + var prog = state.prog; + var ip = state.ip; + + if (exports.DEBUG) { + console.log(state.step, 'PUSHB[' + n + ']'); + } + + for (var i = 0; i < n; i++) { + stack.push(prog[++ip]); + } + + state.ip = ip; + } + + // PUSHW[abc] PUSH Words + // 0xB8-0xBF + function PUSHW(n, state) { + var ip = state.ip; + var prog = state.prog; + var stack = state.stack; + + if (exports.DEBUG) { + console.log(state.ip, 'PUSHW[' + n + ']'); + } + + for (var i = 0; i < n; i++) { + var w = (prog[++ip] << 8) | prog[++ip]; + if (w & 0x8000) { + w = -((w ^ 0xffff) + 1); + } + stack.push(w); + } + + state.ip = ip; + } + + // MDRP[abcde] Move Direct Relative Point + // 0xD0-0xEF + // (if indirect is 0) + // + // and + // + // MIRP[abcde] Move Indirect Relative Point + // 0xE0-0xFF + // (if indirect is 1) + + function MDRP_MIRP(indirect, setRp0, keepD, ro, dt, state) { + var stack = state.stack; + var cvte = indirect && stack.pop(); + var pi = stack.pop(); + var rp0i = state.rp0; + var rp = state.z0[rp0i]; + var p = state.z1[pi]; + + var md = state.minDis; + var fv = state.fv; + var pv = state.dpv; + var od; // original distance + var d; // moving distance + var sign; // sign of distance + var cv; + + d = od = pv.distance(p, rp, true, true); + sign = d >= 0 ? 1 : -1; // Math.sign would be 0 in case of 0 + + // TODO consider autoFlip + d = Math.abs(d); + + if (indirect) { + cv = state.cvt[cvte]; + + if (ro && Math.abs(d - cv) < state.cvCutIn) { + d = cv; + } + } + + if (keepD && d < md) { + d = md; + } + + if (ro) { + d = state.round(d); + } + + fv.setRelative(p, rp, sign * d, pv); + fv.touch(p); + + if (exports.DEBUG) { + console.log( + state.step, + (indirect ? 'MIRP[' : 'MDRP[') + + (setRp0 ? 'M' : 'm') + + (keepD ? '>' : '_') + + (ro ? 'R' : '_') + + (dt === 0 ? 'Gr' : dt === 1 ? 'Bl' : dt === 2 ? 'Wh' : '') + + ']', + indirect ? cvte + '(' + state.cvt[cvte] + ',' + cv + ')' : '', + pi, + '(d =', + od, + '->', + sign * d, + ')' + ); + } + + state.rp1 = state.rp0; + state.rp2 = pi; + if (setRp0) { + state.rp0 = pi; + } + } + + /* + * The instruction table. + */ + instructionTable = [ + /* 0x00 */ SVTCA.bind(undefined, yUnitVector), + /* 0x01 */ SVTCA.bind(undefined, xUnitVector), + /* 0x02 */ SPVTCA.bind(undefined, yUnitVector), + /* 0x03 */ SPVTCA.bind(undefined, xUnitVector), + /* 0x04 */ SFVTCA.bind(undefined, yUnitVector), + /* 0x05 */ SFVTCA.bind(undefined, xUnitVector), + /* 0x06 */ SPVTL.bind(undefined, 0), + /* 0x07 */ SPVTL.bind(undefined, 1), + /* 0x08 */ SFVTL.bind(undefined, 0), + /* 0x09 */ SFVTL.bind(undefined, 1), + /* 0x0A */ SPVFS, + /* 0x0B */ SFVFS, + /* 0x0C */ GPV, + /* 0x0D */ GFV, + /* 0x0E */ SFVTPV, + /* 0x0F */ ISECT, + /* 0x10 */ SRP0, + /* 0x11 */ SRP1, + /* 0x12 */ SRP2, + /* 0x13 */ SZP0, + /* 0x14 */ SZP1, + /* 0x15 */ SZP2, + /* 0x16 */ SZPS, + /* 0x17 */ SLOOP, + /* 0x18 */ RTG, + /* 0x19 */ RTHG, + /* 0x1A */ SMD, + /* 0x1B */ ELSE, + /* 0x1C */ JMPR, + /* 0x1D */ SCVTCI, + /* 0x1E */ undefined, // TODO SSWCI + /* 0x1F */ undefined, // TODO SSW + /* 0x20 */ DUP, + /* 0x21 */ POP, + /* 0x22 */ CLEAR, + /* 0x23 */ SWAP, + /* 0x24 */ DEPTH, + /* 0x25 */ CINDEX, + /* 0x26 */ MINDEX, + /* 0x27 */ undefined, // TODO ALIGNPTS + /* 0x28 */ undefined, + /* 0x29 */ undefined, // TODO UTP + /* 0x2A */ LOOPCALL, + /* 0x2B */ CALL, + /* 0x2C */ FDEF, + /* 0x2D */ undefined, // ENDF (eaten by FDEF) + /* 0x2E */ MDAP.bind(undefined, 0), + /* 0x2F */ MDAP.bind(undefined, 1), + /* 0x30 */ IUP.bind(undefined, yUnitVector), + /* 0x31 */ IUP.bind(undefined, xUnitVector), + /* 0x32 */ SHP.bind(undefined, 0), + /* 0x33 */ SHP.bind(undefined, 1), + /* 0x34 */ SHC.bind(undefined, 0), + /* 0x35 */ SHC.bind(undefined, 1), + /* 0x36 */ SHZ.bind(undefined, 0), + /* 0x37 */ SHZ.bind(undefined, 1), + /* 0x38 */ SHPIX, + /* 0x39 */ IP, + /* 0x3A */ MSIRP.bind(undefined, 0), + /* 0x3B */ MSIRP.bind(undefined, 1), + /* 0x3C */ ALIGNRP, + /* 0x3D */ RTDG, + /* 0x3E */ MIAP.bind(undefined, 0), + /* 0x3F */ MIAP.bind(undefined, 1), + /* 0x40 */ NPUSHB, + /* 0x41 */ NPUSHW, + /* 0x42 */ WS, + /* 0x43 */ RS, + /* 0x44 */ WCVTP, + /* 0x45 */ RCVT, + /* 0x46 */ GC.bind(undefined, 0), + /* 0x47 */ GC.bind(undefined, 1), + /* 0x48 */ undefined, // TODO SCFS + /* 0x49 */ MD.bind(undefined, 0), + /* 0x4A */ MD.bind(undefined, 1), + /* 0x4B */ MPPEM, + /* 0x4C */ undefined, // TODO MPS + /* 0x4D */ FLIPON, + /* 0x4E */ undefined, // TODO FLIPOFF + /* 0x4F */ undefined, // TODO DEBUG + /* 0x50 */ LT, + /* 0x51 */ LTEQ, + /* 0x52 */ GT, + /* 0x53 */ GTEQ, + /* 0x54 */ EQ, + /* 0x55 */ NEQ, + /* 0x56 */ ODD, + /* 0x57 */ EVEN, + /* 0x58 */ IF, + /* 0x59 */ EIF, + /* 0x5A */ AND, + /* 0x5B */ OR, + /* 0x5C */ NOT, + /* 0x5D */ DELTAP123.bind(undefined, 1), + /* 0x5E */ SDB, + /* 0x5F */ SDS, + /* 0x60 */ ADD, + /* 0x61 */ SUB, + /* 0x62 */ DIV, + /* 0x63 */ MUL, + /* 0x64 */ ABS, + /* 0x65 */ NEG, + /* 0x66 */ FLOOR, + /* 0x67 */ CEILING, + /* 0x68 */ ROUND.bind(undefined, 0), + /* 0x69 */ ROUND.bind(undefined, 1), + /* 0x6A */ ROUND.bind(undefined, 2), + /* 0x6B */ ROUND.bind(undefined, 3), + /* 0x6C */ undefined, // TODO NROUND[ab] + /* 0x6D */ undefined, // TODO NROUND[ab] + /* 0x6E */ undefined, // TODO NROUND[ab] + /* 0x6F */ undefined, // TODO NROUND[ab] + /* 0x70 */ WCVTF, + /* 0x71 */ DELTAP123.bind(undefined, 2), + /* 0x72 */ DELTAP123.bind(undefined, 3), + /* 0x73 */ DELTAC123.bind(undefined, 1), + /* 0x74 */ DELTAC123.bind(undefined, 2), + /* 0x75 */ DELTAC123.bind(undefined, 3), + /* 0x76 */ SROUND, + /* 0x77 */ S45ROUND, + /* 0x78 */ undefined, // TODO JROT[] + /* 0x79 */ undefined, // TODO JROF[] + /* 0x7A */ ROFF, + /* 0x7B */ undefined, + /* 0x7C */ RUTG, + /* 0x7D */ RDTG, + /* 0x7E */ POP, // actually SANGW, supposed to do only a pop though + /* 0x7F */ POP, // actually AA, supposed to do only a pop though + /* 0x80 */ undefined, // TODO FLIPPT + /* 0x81 */ undefined, // TODO FLIPRGON + /* 0x82 */ undefined, // TODO FLIPRGOFF + /* 0x83 */ undefined, + /* 0x84 */ undefined, + /* 0x85 */ SCANCTRL, + /* 0x86 */ SDPVTL.bind(undefined, 0), + /* 0x87 */ SDPVTL.bind(undefined, 1), + /* 0x88 */ GETINFO, + /* 0x89 */ undefined, // TODO IDEF + /* 0x8A */ ROLL, + /* 0x8B */ MAX, + /* 0x8C */ MIN, + /* 0x8D */ SCANTYPE, + /* 0x8E */ INSTCTRL, + /* 0x8F */ undefined, + /* 0x90 */ undefined, + /* 0x91 */ undefined, + /* 0x92 */ undefined, + /* 0x93 */ undefined, + /* 0x94 */ undefined, + /* 0x95 */ undefined, + /* 0x96 */ undefined, + /* 0x97 */ undefined, + /* 0x98 */ undefined, + /* 0x99 */ undefined, + /* 0x9A */ undefined, + /* 0x9B */ undefined, + /* 0x9C */ undefined, + /* 0x9D */ undefined, + /* 0x9E */ undefined, + /* 0x9F */ undefined, + /* 0xA0 */ undefined, + /* 0xA1 */ undefined, + /* 0xA2 */ undefined, + /* 0xA3 */ undefined, + /* 0xA4 */ undefined, + /* 0xA5 */ undefined, + /* 0xA6 */ undefined, + /* 0xA7 */ undefined, + /* 0xA8 */ undefined, + /* 0xA9 */ undefined, + /* 0xAA */ undefined, + /* 0xAB */ undefined, + /* 0xAC */ undefined, + /* 0xAD */ undefined, + /* 0xAE */ undefined, + /* 0xAF */ undefined, + /* 0xB0 */ PUSHB.bind(undefined, 1), + /* 0xB1 */ PUSHB.bind(undefined, 2), + /* 0xB2 */ PUSHB.bind(undefined, 3), + /* 0xB3 */ PUSHB.bind(undefined, 4), + /* 0xB4 */ PUSHB.bind(undefined, 5), + /* 0xB5 */ PUSHB.bind(undefined, 6), + /* 0xB6 */ PUSHB.bind(undefined, 7), + /* 0xB7 */ PUSHB.bind(undefined, 8), + /* 0xB8 */ PUSHW.bind(undefined, 1), + /* 0xB9 */ PUSHW.bind(undefined, 2), + /* 0xBA */ PUSHW.bind(undefined, 3), + /* 0xBB */ PUSHW.bind(undefined, 4), + /* 0xBC */ PUSHW.bind(undefined, 5), + /* 0xBD */ PUSHW.bind(undefined, 6), + /* 0xBE */ PUSHW.bind(undefined, 7), + /* 0xBF */ PUSHW.bind(undefined, 8), + /* 0xC0 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 0), + /* 0xC1 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 1), + /* 0xC2 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 2), + /* 0xC3 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 0, 3), + /* 0xC4 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 0), + /* 0xC5 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 1), + /* 0xC6 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 2), + /* 0xC7 */ MDRP_MIRP.bind(undefined, 0, 0, 0, 1, 3), + /* 0xC8 */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 0), + /* 0xC9 */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 1), + /* 0xCA */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 2), + /* 0xCB */ MDRP_MIRP.bind(undefined, 0, 0, 1, 0, 3), + /* 0xCC */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 0), + /* 0xCD */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 1), + /* 0xCE */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 2), + /* 0xCF */ MDRP_MIRP.bind(undefined, 0, 0, 1, 1, 3), + /* 0xD0 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 0), + /* 0xD1 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 1), + /* 0xD2 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 2), + /* 0xD3 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 0, 3), + /* 0xD4 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 0), + /* 0xD5 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 1), + /* 0xD6 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 2), + /* 0xD7 */ MDRP_MIRP.bind(undefined, 0, 1, 0, 1, 3), + /* 0xD8 */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 0), + /* 0xD9 */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 1), + /* 0xDA */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 2), + /* 0xDB */ MDRP_MIRP.bind(undefined, 0, 1, 1, 0, 3), + /* 0xDC */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 0), + /* 0xDD */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 1), + /* 0xDE */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 2), + /* 0xDF */ MDRP_MIRP.bind(undefined, 0, 1, 1, 1, 3), + /* 0xE0 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 0), + /* 0xE1 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 1), + /* 0xE2 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 2), + /* 0xE3 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 0, 3), + /* 0xE4 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 0), + /* 0xE5 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 1), + /* 0xE6 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 2), + /* 0xE7 */ MDRP_MIRP.bind(undefined, 1, 0, 0, 1, 3), + /* 0xE8 */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 0), + /* 0xE9 */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 1), + /* 0xEA */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 2), + /* 0xEB */ MDRP_MIRP.bind(undefined, 1, 0, 1, 0, 3), + /* 0xEC */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 0), + /* 0xED */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 1), + /* 0xEE */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 2), + /* 0xEF */ MDRP_MIRP.bind(undefined, 1, 0, 1, 1, 3), + /* 0xF0 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 0), + /* 0xF1 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 1), + /* 0xF2 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 2), + /* 0xF3 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 0, 3), + /* 0xF4 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 0), + /* 0xF5 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 1), + /* 0xF6 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 2), + /* 0xF7 */ MDRP_MIRP.bind(undefined, 1, 1, 0, 1, 3), + /* 0xF8 */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 0), + /* 0xF9 */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 1), + /* 0xFA */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 2), + /* 0xFB */ MDRP_MIRP.bind(undefined, 1, 1, 1, 0, 3), + /* 0xFC */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 0), + /* 0xFD */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 1), + /* 0xFE */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 2), + /* 0xFF */ MDRP_MIRP.bind(undefined, 1, 1, 1, 1, 3) + ]; + + /***************************** + Mathematical Considerations + ****************************** + + fv ... refers to freedom vector + pv ... refers to projection vector + rp ... refers to reference point + p ... refers to to point being operated on + d ... refers to distance + + SETRELATIVE: + ============ + + case freedom vector == x-axis: + ------------------------------ + + (pv) + .-' + rpd .-' + .-* + d .-'90°' + .-' ' + .-' ' + *-' ' b + rp ' + ' + ' + p *----------*-------------- (fv) + pm + + rpdx = rpx + d * pv.x + rpdy = rpy + d * pv.y + + equation of line b + + y - rpdy = pvns * (x- rpdx) + + y = p.y + + x = rpdx + ( p.y - rpdy ) / pvns + + + case freedom vector == y-axis: + ------------------------------ + + * pm + |\ + | \ + | \ + | \ + | \ + | \ + | \ + | \ + | \ + | \ b + | \ + | \ + | \ .-' (pv) + | 90° \.-' + | .-'* rpd + | .-' + * *-' d + p rp + + rpdx = rpx + d * pv.x + rpdy = rpy + d * pv.y + + equation of line b: + pvns ... normal slope to pv + + y - rpdy = pvns * (x - rpdx) + + x = p.x + + y = rpdy + pvns * (p.x - rpdx) + + + + generic case: + ------------- + + + .'(fv) + .' + .* pm + .' ! + .' . + .' ! + .' . b + .' ! + * . + p ! + 90° . ... (pv) + ...-*-''' + ...---''' rpd + ...---''' d + *--''' + rp + + rpdx = rpx + d * pv.x + rpdy = rpy + d * pv.y + + equation of line b: + pvns... normal slope to pv + + y - rpdy = pvns * (x - rpdx) + + equation of freedom vector line: + fvs ... slope of freedom vector (=fy/fx) + + y - py = fvs * (x - px) + + + on pm both equations are true for same x/y + + y - rpdy = pvns * (x - rpdx) + + y - py = fvs * (x - px) + + form to y and set equal: + + pvns * (x - rpdx) + rpdy = fvs * (x - px) + py + + expand: + + pvns * x - pvns * rpdx + rpdy = fvs * x - fvs * px + py + + switch: + + fvs * x - fvs * px + py = pvns * x - pvns * rpdx + rpdy + + solve for x: + + fvs * x - pvns * x = fvs * px - pvns * rpdx - py + rpdy + + + + fvs * px - pvns * rpdx + rpdy - py + x = ----------------------------------- + fvs - pvns + + and: + + y = fvs * (x - px) + py + + + + INTERPOLATE: + ============ + + Examples of point interpolation. + + The weight of the movement of the reference point gets bigger + the further the other reference point is away, thus the safest + option (that is avoiding 0/0 divisions) is to weight the + original distance of the other point by the sum of both distances. + + If the sum of both distances is 0, then move the point by the + arithmetic average of the movement of both reference points. + + + + + (+6) + rp1o *---->*rp1 + . . (+12) + . . rp2o *---------->* rp2 + . . . . + . . . . + . 10 20 . . + |.........|...................| . + . . . + . . (+8) . + po *------>*p . + . . . + . 12 . 24 . + |...........|.......................| + 36 + + + ------- + + + + (+10) + rp1o *-------->*rp1 + . . (-10) + . . rp2 *<---------* rpo2 + . . . . + . . . . + . 10 . 30 . . + |.........|.............................| + . . + . (+5) . + po *--->* p . + . . . + . . 20 . + |....|..............| + 5 15 + + + ------- + + + (+10) + rp1o *-------->*rp1 + . . + . . + rp2o *-------->*rp2 + + + (+10) + po *-------->* p + + ------- + + + (+10) + rp1o *-------->*rp1 + . . + . .(+30) + rp2o *---------------------------->*rp2 + + + (+25) + po *----------------------->* p + + + + vim: set ts=4 sw=4 expandtab: + *****/ + + // The Font object + + // This code is based on Array.from implementation for strings in https://github.com/mathiasbynens/Array.from + var arrayFromString = + Array.from || + function(s) { + return ( + s.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]?|[^\uD800-\uDFFF]|./g) || [] + ); + }; + + /** + * @typedef FontOptions + * @type Object + * @property {Boolean} empty - whether to create a new empty font + * @property {string} familyName + * @property {string} styleName + * @property {string=} fullName + * @property {string=} postScriptName + * @property {string=} designer + * @property {string=} designerURL + * @property {string=} manufacturer + * @property {string=} manufacturerURL + * @property {string=} license + * @property {string=} licenseURL + * @property {string=} version + * @property {string=} description + * @property {string=} copyright + * @property {string=} trademark + * @property {Number} unitsPerEm + * @property {Number} ascender + * @property {Number} descender + * @property {Number} createdTimestamp + * @property {string=} weightClass + * @property {string=} widthClass + * @property {string=} fsSelection + */ + + /** + * A Font represents a loaded OpenType font file. + * It contains a set of glyphs and methods to draw text on a drawing context, + * or to get a path representing the text. + * @exports opentype.Font + * @class + * @param {FontOptions} + * @constructor + */ + function Font(options) { + options = options || {}; + + if (!options.empty) { + // Check that we've provided the minimum set of names. + checkArgument( + options.familyName, + 'When creating a new Font object, familyName is required.' + ); + checkArgument( + options.styleName, + 'When creating a new Font object, styleName is required.' + ); + checkArgument( + options.unitsPerEm, + 'When creating a new Font object, unitsPerEm is required.' + ); + checkArgument( + options.ascender, + 'When creating a new Font object, ascender is required.' + ); + checkArgument( + options.descender, + 'When creating a new Font object, descender is required.' + ); + checkArgument( + options.descender < 0, + 'Descender should be negative (e.g. -512).' + ); + + // OS X will complain if the names are empty, so we put a single space everywhere by default. + this.names = { + fontFamily: { en: options.familyName || ' ' }, + fontSubfamily: { en: options.styleName || ' ' }, + fullName: { + en: options.fullName || options.familyName + ' ' + options.styleName + }, + // postScriptName may not contain any whitespace + postScriptName: { + en: + options.postScriptName || + (options.familyName + options.styleName).replace(/\s/g, '') + }, + designer: { en: options.designer || ' ' }, + designerURL: { en: options.designerURL || ' ' }, + manufacturer: { en: options.manufacturer || ' ' }, + manufacturerURL: { en: options.manufacturerURL || ' ' }, + license: { en: options.license || ' ' }, + licenseURL: { en: options.licenseURL || ' ' }, + version: { en: options.version || 'Version 0.1' }, + description: { en: options.description || ' ' }, + copyright: { en: options.copyright || ' ' }, + trademark: { en: options.trademark || ' ' } + }; + this.unitsPerEm = options.unitsPerEm || 1000; + this.ascender = options.ascender; + this.descender = options.descender; + this.createdTimestamp = options.createdTimestamp; + this.tables = { + os2: { + usWeightClass: options.weightClass || this.usWeightClasses.MEDIUM, + usWidthClass: options.widthClass || this.usWidthClasses.MEDIUM, + fsSelection: options.fsSelection || this.fsSelectionValues.REGULAR + } + }; + } + + this.supported = true; // Deprecated: parseBuffer will throw an error if font is not supported. + this.glyphs = new glyphset.GlyphSet(this, options.glyphs || []); + this.encoding = new DefaultEncoding(this); + this.position = new Position(this); + this.substitution = new Substitution(this); + this.tables = this.tables || {}; + + Object.defineProperty(this, 'hinting', { + get: function() { + if (this._hinting) { + return this._hinting; + } + if (this.outlinesFormat === 'truetype') { + return (this._hinting = new Hinting(this)); + } + } + }); + } + + /** + * Check if the font has a glyph for the given character. + * @param {string} + * @return {Boolean} + */ + Font.prototype.hasChar = function(c) { + return this.encoding.charToGlyphIndex(c) !== null; + }; + + /** + * Convert the given character to a single glyph index. + * Note that this function assumes that there is a one-to-one mapping between + * the given character and a glyph; for complex scripts this might not be the case. + * @param {string} + * @return {Number} + */ + Font.prototype.charToGlyphIndex = function(s) { + return this.encoding.charToGlyphIndex(s); + }; + + /** + * Convert the given character to a single Glyph object. + * Note that this function assumes that there is a one-to-one mapping between + * the given character and a glyph; for complex scripts this might not be the case. + * @param {string} + * @return {opentype.Glyph} + */ + Font.prototype.charToGlyph = function(c) { + var glyphIndex = this.charToGlyphIndex(c); + var glyph = this.glyphs.get(glyphIndex); + if (!glyph) { + // .notdef + glyph = this.glyphs.get(0); + } + + return glyph; + }; + + /** + * Convert the given text to a list of Glyph objects. + * Note that there is no strict one-to-one mapping between characters and + * glyphs, so the list of returned glyphs can be larger or smaller than the + * length of the given string. + * @param {string} + * @param {GlyphRenderOptions} [options] + * @return {opentype.Glyph[]} + */ + Font.prototype.stringToGlyphs = function(s, options) { + var this$1 = this; + + options = options || this.defaultRenderOptions; + // Get glyph indexes + var chars = arrayFromString(s); + var indexes = []; + for (var i = 0; i < chars.length; i += 1) { + var c = chars[i]; + indexes.push(this$1.charToGlyphIndex(c)); + } + var length = indexes.length; + + // Apply substitutions on glyph indexes + if (options.features) { + var script = options.script || this.substitution.getDefaultScriptName(); + var manyToOne = []; + if (options.features.liga) { + manyToOne = manyToOne.concat( + this.substitution.getFeature('liga', script, options.language) + ); + } + if (options.features.rlig) { + manyToOne = manyToOne.concat( + this.substitution.getFeature('rlig', script, options.language) + ); + } + for (var i$1 = 0; i$1 < length; i$1 += 1) { + for (var j = 0; j < manyToOne.length; j++) { + var ligature = manyToOne[j]; + var components = ligature.sub; + var compCount = components.length; + var k = 0; + while (k < compCount && components[k] === indexes[i$1 + k]) { + k++; + } + if (k === compCount) { + indexes.splice(i$1, compCount, ligature.by); + length = length - compCount + 1; + } + } + } + } + + // convert glyph indexes to glyph objects + var glyphs = new Array(length); + var notdef = this.glyphs.get(0); + for (var i$2 = 0; i$2 < length; i$2 += 1) { + glyphs[i$2] = this$1.glyphs.get(indexes[i$2]) || notdef; + } + return glyphs; + }; + + /** + * @param {string} + * @return {Number} + */ + Font.prototype.nameToGlyphIndex = function(name) { + return this.glyphNames.nameToGlyphIndex(name); + }; + + /** + * @param {string} + * @return {opentype.Glyph} + */ + Font.prototype.nameToGlyph = function(name) { + var glyphIndex = this.nameToGlyphIndex(name); + var glyph = this.glyphs.get(glyphIndex); + if (!glyph) { + // .notdef + glyph = this.glyphs.get(0); + } + + return glyph; + }; + + /** + * @param {Number} + * @return {String} + */ + Font.prototype.glyphIndexToName = function(gid) { + if (!this.glyphNames.glyphIndexToName) { + return ''; + } + + return this.glyphNames.glyphIndexToName(gid); + }; + + /** + * Retrieve the value of the kerning pair between the left glyph (or its index) + * and the right glyph (or its index). If no kerning pair is found, return 0. + * The kerning value gets added to the advance width when calculating the spacing + * between glyphs. + * For GPOS kerning, this method uses the default script and language, which covers + * most use cases. To have greater control, use font.position.getKerningValue . + * @param {opentype.Glyph} leftGlyph + * @param {opentype.Glyph} rightGlyph + * @return {Number} + */ + Font.prototype.getKerningValue = function(leftGlyph, rightGlyph) { + leftGlyph = leftGlyph.index || leftGlyph; + rightGlyph = rightGlyph.index || rightGlyph; + var gposKerning = this.position.defaultKerningTables; + if (gposKerning) { + return this.position.getKerningValue(gposKerning, leftGlyph, rightGlyph); + } + // "kern" table + return this.kerningPairs[leftGlyph + ',' + rightGlyph] || 0; + }; + + /** + * @typedef GlyphRenderOptions + * @type Object + * @property {string} [script] - script used to determine which features to apply. By default, 'DFLT' or 'latn' is used. + * See https://www.microsoft.com/typography/otspec/scripttags.htm + * @property {string} [language='dflt'] - language system used to determine which features to apply. + * See https://www.microsoft.com/typography/developers/opentype/languagetags.aspx + * @property {boolean} [kerning=true] - whether to include kerning values + * @property {object} [features] - OpenType Layout feature tags. Used to enable or disable the features of the given script/language system. + * See https://www.microsoft.com/typography/otspec/featuretags.htm + */ + Font.prototype.defaultRenderOptions = { + kerning: true, + features: { + liga: true, + rlig: true + } + }; + + /** + * Helper function that invokes the given callback for each glyph in the given text. + * The callback gets `(glyph, x, y, fontSize, options)`.* @param {string} text + * @param {string} text - The text to apply. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {GlyphRenderOptions=} options + * @param {Function} callback + */ + Font.prototype.forEachGlyph = function( + text, + x, + y, + fontSize, + options, + callback + ) { + var this$1 = this; + + x = x !== undefined ? x : 0; + y = y !== undefined ? y : 0; + fontSize = fontSize !== undefined ? fontSize : 72; + options = options || this.defaultRenderOptions; + var fontScale = 1 / this.unitsPerEm * fontSize; + var glyphs = this.stringToGlyphs(text, options); + var kerningLookups; + if (options.kerning) { + var script = options.script || this.position.getDefaultScriptName(); + kerningLookups = this.position.getKerningTables(script, options.language); + } + for (var i = 0; i < glyphs.length; i += 1) { + var glyph = glyphs[i]; + callback.call(this$1, glyph, x, y, fontSize, options); + if (glyph.advanceWidth) { + x += glyph.advanceWidth * fontScale; + } + + if (options.kerning && i < glyphs.length - 1) { + // We should apply position adjustment lookups in a more generic way. + // Here we only use the xAdvance value. + var kerningValue = kerningLookups + ? this$1.position.getKerningValue( + kerningLookups, + glyph.index, + glyphs[i + 1].index + ) + : this$1.getKerningValue(glyph, glyphs[i + 1]); + x += kerningValue * fontScale; + } + + if (options.letterSpacing) { + x += options.letterSpacing * fontSize; + } else if (options.tracking) { + x += options.tracking / 1000 * fontSize; + } + } + return x; + }; + + /** + * Create a Path object that represents the given text. + * @param {string} text - The text to create. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {GlyphRenderOptions=} options + * @return {opentype.Path} + */ + Font.prototype.getPath = function(text, x, y, fontSize, options) { + var fullPath = new Path(); + this.forEachGlyph(text, x, y, fontSize, options, function( + glyph, + gX, + gY, + gFontSize + ) { + var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this); + fullPath.extend(glyphPath); + }); + return fullPath; + }; + + /** + * Create an array of Path objects that represent the glyphs of a given text. + * @param {string} text - The text to create. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {GlyphRenderOptions=} options + * @return {opentype.Path[]} + */ + Font.prototype.getPaths = function(text, x, y, fontSize, options) { + var glyphPaths = []; + this.forEachGlyph(text, x, y, fontSize, options, function( + glyph, + gX, + gY, + gFontSize + ) { + var glyphPath = glyph.getPath(gX, gY, gFontSize, options, this); + glyphPaths.push(glyphPath); + }); + + return glyphPaths; + }; + + /** + * Returns the advance width of a text. + * + * This is something different than Path.getBoundingBox() as for example a + * suffixed whitespace increases the advanceWidth but not the bounding box + * or an overhanging letter like a calligraphic 'f' might have a quite larger + * bounding box than its advance width. + * + * This corresponds to canvas2dContext.measureText(text).width + * + * @param {string} text - The text to create. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {GlyphRenderOptions=} options + * @return advance width + */ + Font.prototype.getAdvanceWidth = function(text, fontSize, options) { + return this.forEachGlyph(text, 0, 0, fontSize, options, function() {}); + }; + + /** + * Draw the text on the given drawing context. + * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. + * @param {string} text - The text to create. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {GlyphRenderOptions=} options + */ + Font.prototype.draw = function(ctx, text, x, y, fontSize, options) { + this.getPath(text, x, y, fontSize, options).draw(ctx); + }; + + /** + * Draw the points of all glyphs in the text. + * On-curve points will be drawn in blue, off-curve points will be drawn in red. + * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. + * @param {string} text - The text to create. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {GlyphRenderOptions=} options + */ + Font.prototype.drawPoints = function(ctx, text, x, y, fontSize, options) { + this.forEachGlyph(text, x, y, fontSize, options, function( + glyph, + gX, + gY, + gFontSize + ) { + glyph.drawPoints(ctx, gX, gY, gFontSize); + }); + }; + + /** + * Draw lines indicating important font measurements for all glyphs in the text. + * Black lines indicate the origin of the coordinate system (point 0,0). + * Blue lines indicate the glyph bounding box. + * Green line indicates the advance width of the glyph. + * @param {CanvasRenderingContext2D} ctx - A 2D drawing context, like Canvas. + * @param {string} text - The text to create. + * @param {number} [x=0] - Horizontal position of the beginning of the text. + * @param {number} [y=0] - Vertical position of the *baseline* of the text. + * @param {number} [fontSize=72] - Font size in pixels. We scale the glyph units by `1 / unitsPerEm * fontSize`. + * @param {GlyphRenderOptions=} options + */ + Font.prototype.drawMetrics = function(ctx, text, x, y, fontSize, options) { + this.forEachGlyph(text, x, y, fontSize, options, function( + glyph, + gX, + gY, + gFontSize + ) { + glyph.drawMetrics(ctx, gX, gY, gFontSize); + }); + }; + + /** + * @param {string} + * @return {string} + */ + Font.prototype.getEnglishName = function(name) { + var translations = this.names[name]; + if (translations) { + return translations.en; + } + }; + + /** + * Validate + */ + Font.prototype.validate = function() { + var _this = this; + + function assert(predicate, message) {} + + function assertNamePresent(name) { + var englishName = _this.getEnglishName(name); + assert( + englishName && englishName.trim().length > 0, + 'No English ' + name + ' specified.' + ); + } + + // Identification information + assertNamePresent('fontFamily'); + assertNamePresent('weightName'); + assertNamePresent('manufacturer'); + assertNamePresent('copyright'); + assertNamePresent('version'); + + // Dimension information + assert(this.unitsPerEm > 0, 'No unitsPerEm specified.'); + }; + + /** + * Convert the font object to a SFNT data structure. + * This structure contains all the necessary tables and metadata to create a binary OTF file. + * @return {opentype.Table} + */ + Font.prototype.toTables = function() { + return sfnt.fontToTable(this); + }; + /** + * @deprecated Font.toBuffer is deprecated. Use Font.toArrayBuffer instead. + */ + Font.prototype.toBuffer = function() { + console.warn( + 'Font.toBuffer is deprecated. Use Font.toArrayBuffer instead.' + ); + return this.toArrayBuffer(); + }; + /** + * Converts a `opentype.Font` into an `ArrayBuffer` + * @return {ArrayBuffer} + */ + Font.prototype.toArrayBuffer = function() { + var sfntTable = this.toTables(); + var bytes = sfntTable.encode(); + var buffer = new ArrayBuffer(bytes.length); + var intArray = new Uint8Array(buffer); + for (var i = 0; i < bytes.length; i++) { + intArray[i] = bytes[i]; + } + + return buffer; + }; + + /** + * Initiate a download of the OpenType font. + */ + Font.prototype.download = function(fileName) { + var familyName = this.getEnglishName('fontFamily'); + var styleName = this.getEnglishName('fontSubfamily'); + fileName = + fileName || familyName.replace(/\s/g, '') + '-' + styleName + '.otf'; + var arrayBuffer = this.toArrayBuffer(); + + if (isBrowser()) { + window.requestFileSystem = + window.requestFileSystem || window.webkitRequestFileSystem; + window.requestFileSystem( + window.TEMPORARY, + arrayBuffer.byteLength, + function(fs) { + fs.root.getFile(fileName, { create: true }, function(fileEntry) { + fileEntry.createWriter(function(writer) { + var dataView = new DataView(arrayBuffer); + var blob = new Blob([dataView], { type: 'font/opentype' }); + writer.write(blob); + + writer.addEventListener( + 'writeend', + function() { + // Navigating to the file will download it. + location.href = fileEntry.toURL(); + }, + false + ); + }); + }); + }, + function(err) { + throw new Error(err.name + ': ' + err.message); + } + ); + } else { + var fs = _dereq_('fs'); + var buffer = arrayBufferToNodeBuffer(arrayBuffer); + fs.writeFileSync(fileName, buffer); + } + }; + /** + * @private + */ + Font.prototype.fsSelectionValues = { + ITALIC: 0x001, //1 + UNDERSCORE: 0x002, //2 + NEGATIVE: 0x004, //4 + OUTLINED: 0x008, //8 + STRIKEOUT: 0x010, //16 + BOLD: 0x020, //32 + REGULAR: 0x040, //64 + USER_TYPO_METRICS: 0x080, //128 + WWS: 0x100, //256 + OBLIQUE: 0x200 //512 + }; + + /** + * @private + */ + Font.prototype.usWidthClasses = { + ULTRA_CONDENSED: 1, + EXTRA_CONDENSED: 2, + CONDENSED: 3, + SEMI_CONDENSED: 4, + MEDIUM: 5, + SEMI_EXPANDED: 6, + EXPANDED: 7, + EXTRA_EXPANDED: 8, + ULTRA_EXPANDED: 9 + }; + + /** + * @private + */ + Font.prototype.usWeightClasses = { + THIN: 100, + EXTRA_LIGHT: 200, + LIGHT: 300, + NORMAL: 400, + MEDIUM: 500, + SEMI_BOLD: 600, + BOLD: 700, + EXTRA_BOLD: 800, + BLACK: 900 + }; + + // The `fvar` table stores font variation axes and instances. + + function addName(name, names) { + var nameString = JSON.stringify(name); + var nameID = 256; + for (var nameKey in names) { + var n = parseInt(nameKey); + if (!n || n < 256) { + continue; + } + + if (JSON.stringify(names[nameKey]) === nameString) { + return n; + } + + if (nameID <= n) { + nameID = n + 1; + } + } + + names[nameID] = name; + return nameID; + } + + function makeFvarAxis(n, axis, names) { + var nameID = addName(axis.name, names); + return [ + { name: 'tag_' + n, type: 'TAG', value: axis.tag }, + { name: 'minValue_' + n, type: 'FIXED', value: axis.minValue << 16 }, + { + name: 'defaultValue_' + n, + type: 'FIXED', + value: axis.defaultValue << 16 + }, + { name: 'maxValue_' + n, type: 'FIXED', value: axis.maxValue << 16 }, + { name: 'flags_' + n, type: 'USHORT', value: 0 }, + { name: 'nameID_' + n, type: 'USHORT', value: nameID } + ]; + } + + function parseFvarAxis(data, start, names) { + var axis = {}; + var p = new parse.Parser(data, start); + axis.tag = p.parseTag(); + axis.minValue = p.parseFixed(); + axis.defaultValue = p.parseFixed(); + axis.maxValue = p.parseFixed(); + p.skip('uShort', 1); // reserved for flags; no values defined + axis.name = names[p.parseUShort()] || {}; + return axis; + } + + function makeFvarInstance(n, inst, axes, names) { + var nameID = addName(inst.name, names); + var fields = [ + { name: 'nameID_' + n, type: 'USHORT', value: nameID }, + { name: 'flags_' + n, type: 'USHORT', value: 0 } + ]; + + for (var i = 0; i < axes.length; ++i) { + var axisTag = axes[i].tag; + fields.push({ + name: 'axis_' + n + ' ' + axisTag, + type: 'FIXED', + value: inst.coordinates[axisTag] << 16 + }); + } + + return fields; + } + + function parseFvarInstance(data, start, axes, names) { + var inst = {}; + var p = new parse.Parser(data, start); + inst.name = names[p.parseUShort()] || {}; + p.skip('uShort', 1); // reserved for flags; no values defined + + inst.coordinates = {}; + for (var i = 0; i < axes.length; ++i) { + inst.coordinates[axes[i].tag] = p.parseFixed(); + } + + return inst; + } + + function makeFvarTable(fvar, names) { + var result = new table.Table('fvar', [ + { name: 'version', type: 'ULONG', value: 0x10000 }, + { name: 'offsetToData', type: 'USHORT', value: 0 }, + { name: 'countSizePairs', type: 'USHORT', value: 2 }, + { name: 'axisCount', type: 'USHORT', value: fvar.axes.length }, + { name: 'axisSize', type: 'USHORT', value: 20 }, + { name: 'instanceCount', type: 'USHORT', value: fvar.instances.length }, + { name: 'instanceSize', type: 'USHORT', value: 4 + fvar.axes.length * 4 } + ]); + result.offsetToData = result.sizeOf(); + + for (var i = 0; i < fvar.axes.length; i++) { + result.fields = result.fields.concat( + makeFvarAxis(i, fvar.axes[i], names) + ); + } + + for (var j = 0; j < fvar.instances.length; j++) { + result.fields = result.fields.concat( + makeFvarInstance(j, fvar.instances[j], fvar.axes, names) + ); + } + + return result; + } + + function parseFvarTable(data, start, names) { + var p = new parse.Parser(data, start); + var tableVersion = p.parseULong(); + check.argument( + tableVersion === 0x00010000, + 'Unsupported fvar table version.' + ); + var offsetToData = p.parseOffset16(); + // Skip countSizePairs. + p.skip('uShort', 1); + var axisCount = p.parseUShort(); + var axisSize = p.parseUShort(); + var instanceCount = p.parseUShort(); + var instanceSize = p.parseUShort(); + + var axes = []; + for (var i = 0; i < axisCount; i++) { + axes.push( + parseFvarAxis(data, start + offsetToData + i * axisSize, names) + ); + } + + var instances = []; + var instanceStart = start + offsetToData + axisCount * axisSize; + for (var j = 0; j < instanceCount; j++) { + instances.push( + parseFvarInstance(data, instanceStart + j * instanceSize, axes, names) + ); + } + + return { axes: axes, instances: instances }; + } + + var fvar = { make: makeFvarTable, parse: parseFvarTable }; + + // The `GPOS` table contains kerning pairs, among other things. + + var subtableParsers$1 = new Array(10); // subtableParsers[0] is unused + + // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-1-single-adjustment-positioning-subtable + // this = Parser instance + subtableParsers$1[1] = function parseLookup1() { + var start = this.offset + this.relativeOffset; + var posformat = this.parseUShort(); + if (posformat === 1) { + return { + posFormat: 1, + coverage: this.parsePointer(Parser.coverage), + value: this.parseValueRecord() + }; + } else if (posformat === 2) { + return { + posFormat: 2, + coverage: this.parsePointer(Parser.coverage), + values: this.parseValueRecordList() + }; + } + check.assert( + false, + '0x' + start.toString(16) + ': GPOS lookup type 1 format must be 1 or 2.' + ); + }; + + // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookup-type-2-pair-adjustment-positioning-subtable + subtableParsers$1[2] = function parseLookup2() { + var start = this.offset + this.relativeOffset; + var posFormat = this.parseUShort(); + check.assert( + posFormat === 1 || posFormat === 2, + '0x' + start.toString(16) + ': GPOS lookup type 2 format must be 1 or 2.' + ); + var coverage = this.parsePointer(Parser.coverage); + var valueFormat1 = this.parseUShort(); + var valueFormat2 = this.parseUShort(); + if (posFormat === 1) { + // Adjustments for Glyph Pairs + return { + posFormat: posFormat, + coverage: coverage, + valueFormat1: valueFormat1, + valueFormat2: valueFormat2, + pairSets: this.parseList( + Parser.pointer( + Parser.list(function() { + return { + // pairValueRecord + secondGlyph: this.parseUShort(), + value1: this.parseValueRecord(valueFormat1), + value2: this.parseValueRecord(valueFormat2) + }; + }) + ) + ) + }; + } else if (posFormat === 2) { + var classDef1 = this.parsePointer(Parser.classDef); + var classDef2 = this.parsePointer(Parser.classDef); + var class1Count = this.parseUShort(); + var class2Count = this.parseUShort(); + return { + // Class Pair Adjustment + posFormat: posFormat, + coverage: coverage, + valueFormat1: valueFormat1, + valueFormat2: valueFormat2, + classDef1: classDef1, + classDef2: classDef2, + class1Count: class1Count, + class2Count: class2Count, + classRecords: this.parseList( + class1Count, + Parser.list(class2Count, function() { + return { + value1: this.parseValueRecord(valueFormat1), + value2: this.parseValueRecord(valueFormat2) + }; + }) + ) + }; + } + }; + + subtableParsers$1[3] = function parseLookup3() { + return { error: 'GPOS Lookup 3 not supported' }; + }; + subtableParsers$1[4] = function parseLookup4() { + return { error: 'GPOS Lookup 4 not supported' }; + }; + subtableParsers$1[5] = function parseLookup5() { + return { error: 'GPOS Lookup 5 not supported' }; + }; + subtableParsers$1[6] = function parseLookup6() { + return { error: 'GPOS Lookup 6 not supported' }; + }; + subtableParsers$1[7] = function parseLookup7() { + return { error: 'GPOS Lookup 7 not supported' }; + }; + subtableParsers$1[8] = function parseLookup8() { + return { error: 'GPOS Lookup 8 not supported' }; + }; + subtableParsers$1[9] = function parseLookup9() { + return { error: 'GPOS Lookup 9 not supported' }; + }; + + // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos + function parseGposTable(data, start) { + start = start || 0; + var p = new Parser(data, start); + var tableVersion = p.parseVersion(1); + check.argument( + tableVersion === 1 || tableVersion === 1.1, + 'Unsupported GPOS table version ' + tableVersion + ); + + if (tableVersion === 1) { + return { + version: tableVersion, + scripts: p.parseScriptList(), + features: p.parseFeatureList(), + lookups: p.parseLookupList(subtableParsers$1) + }; + } else { + return { + version: tableVersion, + scripts: p.parseScriptList(), + features: p.parseFeatureList(), + lookups: p.parseLookupList(subtableParsers$1), + variations: p.parseFeatureVariationsList() + }; + } + } + + // GPOS Writing ////////////////////////////////////////////// + // NOT SUPPORTED + var subtableMakers$1 = new Array(10); + + function makeGposTable(gpos) { + return new table.Table('GPOS', [ + { name: 'version', type: 'ULONG', value: 0x10000 }, + { + name: 'scripts', + type: 'TABLE', + value: new table.ScriptList(gpos.scripts) + }, + { + name: 'features', + type: 'TABLE', + value: new table.FeatureList(gpos.features) + }, + { + name: 'lookups', + type: 'TABLE', + value: new table.LookupList(gpos.lookups, subtableMakers$1) + } + ]); + } + + var gpos = { parse: parseGposTable, make: makeGposTable }; + + // The `kern` table contains kerning pairs. + + function parseWindowsKernTable(p) { + var pairs = {}; + // Skip nTables. + p.skip('uShort'); + var subtableVersion = p.parseUShort(); + check.argument( + subtableVersion === 0, + 'Unsupported kern sub-table version.' + ); + // Skip subtableLength, subtableCoverage + p.skip('uShort', 2); + var nPairs = p.parseUShort(); + // Skip searchRange, entrySelector, rangeShift. + p.skip('uShort', 3); + for (var i = 0; i < nPairs; i += 1) { + var leftIndex = p.parseUShort(); + var rightIndex = p.parseUShort(); + var value = p.parseShort(); + pairs[leftIndex + ',' + rightIndex] = value; + } + return pairs; + } + + function parseMacKernTable(p) { + var pairs = {}; + // The Mac kern table stores the version as a fixed (32 bits) but we only loaded the first 16 bits. + // Skip the rest. + p.skip('uShort'); + var nTables = p.parseULong(); + //check.argument(nTables === 1, 'Only 1 subtable is supported (got ' + nTables + ').'); + if (nTables > 1) { + console.warn('Only the first kern subtable is supported.'); + } + p.skip('uLong'); + var coverage = p.parseUShort(); + var subtableVersion = coverage & 0xff; + p.skip('uShort'); + if (subtableVersion === 0) { + var nPairs = p.parseUShort(); + // Skip searchRange, entrySelector, rangeShift. + p.skip('uShort', 3); + for (var i = 0; i < nPairs; i += 1) { + var leftIndex = p.parseUShort(); + var rightIndex = p.parseUShort(); + var value = p.parseShort(); + pairs[leftIndex + ',' + rightIndex] = value; + } + } + return pairs; + } + + // Parse the `kern` table which contains kerning pairs. + function parseKernTable(data, start) { + var p = new parse.Parser(data, start); + var tableVersion = p.parseUShort(); + if (tableVersion === 0) { + return parseWindowsKernTable(p); + } else if (tableVersion === 1) { + return parseMacKernTable(p); + } else { + throw new Error('Unsupported kern table version (' + tableVersion + ').'); + } + } + + var kern = { parse: parseKernTable }; + + // The `loca` table stores the offsets to the locations of the glyphs in the font. + + // Parse the `loca` table. This table stores the offsets to the locations of the glyphs in the font, + // relative to the beginning of the glyphData table. + // The number of glyphs stored in the `loca` table is specified in the `maxp` table (under numGlyphs) + // The loca table has two versions: a short version where offsets are stored as uShorts, and a long + // version where offsets are stored as uLongs. The `head` table specifies which version to use + // (under indexToLocFormat). + function parseLocaTable(data, start, numGlyphs, shortVersion) { + var p = new parse.Parser(data, start); + var parseFn = shortVersion ? p.parseUShort : p.parseULong; + // There is an extra entry after the last index element to compute the length of the last glyph. + // That's why we use numGlyphs + 1. + var glyphOffsets = []; + for (var i = 0; i < numGlyphs + 1; i += 1) { + var glyphOffset = parseFn.call(p); + if (shortVersion) { + // The short table version stores the actual offset divided by 2. + glyphOffset *= 2; + } + + glyphOffsets.push(glyphOffset); + } + + return glyphOffsets; + } + + var loca = { parse: parseLocaTable }; + + // opentype.js + + /** + * The opentype library. + * @namespace opentype + */ + + // File loaders ///////////////////////////////////////////////////////// + /** + * Loads a font from a file. The callback throws an error message as the first parameter if it fails + * and the font as an ArrayBuffer in the second parameter if it succeeds. + * @param {string} path - The path of the file + * @param {Function} callback - The function to call when the font load completes + */ + function loadFromFile(path, callback) { + var fs = _dereq_('fs'); + fs.readFile(path, function(err, buffer) { + if (err) { + return callback(err.message); + } + + callback(null, nodeBufferToArrayBuffer(buffer)); + }); + } + /** + * Loads a font from a URL. The callback throws an error message as the first parameter if it fails + * and the font as an ArrayBuffer in the second parameter if it succeeds. + * @param {string} url - The URL of the font file. + * @param {Function} callback - The function to call when the font load completes + */ + function loadFromUrl(url, callback) { + var request = new XMLHttpRequest(); + request.open('get', url, true); + request.responseType = 'arraybuffer'; + request.onload = function() { + if (request.response) { + return callback(null, request.response); + } else { + return callback('Font could not be loaded: ' + request.statusText); + } + }; + + request.onerror = function() { + callback('Font could not be loaded'); + }; + + request.send(); + } + + // Table Directory Entries ////////////////////////////////////////////// + /** + * Parses OpenType table entries. + * @param {DataView} + * @param {Number} + * @return {Object[]} + */ + function parseOpenTypeTableEntries(data, numTables) { + var tableEntries = []; + var p = 12; + for (var i = 0; i < numTables; i += 1) { + var tag = parse.getTag(data, p); + var checksum = parse.getULong(data, p + 4); + var offset = parse.getULong(data, p + 8); + var length = parse.getULong(data, p + 12); + tableEntries.push({ + tag: tag, + checksum: checksum, + offset: offset, + length: length, + compression: false + }); + p += 16; + } + + return tableEntries; + } + + /** + * Parses WOFF table entries. + * @param {DataView} + * @param {Number} + * @return {Object[]} + */ + function parseWOFFTableEntries(data, numTables) { + var tableEntries = []; + var p = 44; // offset to the first table directory entry. + for (var i = 0; i < numTables; i += 1) { + var tag = parse.getTag(data, p); + var offset = parse.getULong(data, p + 4); + var compLength = parse.getULong(data, p + 8); + var origLength = parse.getULong(data, p + 12); + var compression = void 0; + if (compLength < origLength) { + compression = 'WOFF'; + } else { + compression = false; + } + + tableEntries.push({ + tag: tag, + offset: offset, + compression: compression, + compressedLength: compLength, + length: origLength + }); + p += 20; + } + + return tableEntries; + } + + /** + * @typedef TableData + * @type Object + * @property {DataView} data - The DataView + * @property {number} offset - The data offset. + */ + + /** + * @param {DataView} + * @param {Object} + * @return {TableData} + */ + function uncompressTable(data, tableEntry) { + if (tableEntry.compression === 'WOFF') { + var inBuffer = new Uint8Array( + data.buffer, + tableEntry.offset + 2, + tableEntry.compressedLength - 2 + ); + var outBuffer = new Uint8Array(tableEntry.length); + tinyInflate(inBuffer, outBuffer); + if (outBuffer.byteLength !== tableEntry.length) { + throw new Error( + 'Decompression error: ' + + tableEntry.tag + + " decompressed length doesn't match recorded length" + ); + } + + var view = new DataView(outBuffer.buffer, 0); + return { data: view, offset: 0 }; + } else { + return { data: data, offset: tableEntry.offset }; + } + } + + // Public API /////////////////////////////////////////////////////////// + + /** + * Parse the OpenType file data (as an ArrayBuffer) and return a Font object. + * Throws an error if the font could not be parsed. + * @param {ArrayBuffer} + * @return {opentype.Font} + */ + function parseBuffer(buffer) { + var indexToLocFormat; + var ltagTable; + + // Since the constructor can also be called to create new fonts from scratch, we indicate this + // should be an empty font that we'll fill with our own data. + var font = new Font({ empty: true }); + + // OpenType fonts use big endian byte ordering. + // We can't rely on typed array view types, because they operate with the endianness of the host computer. + // Instead we use DataViews where we can specify endianness. + var data = new DataView(buffer, 0); + var numTables; + var tableEntries = []; + var signature = parse.getTag(data, 0); + if ( + signature === String.fromCharCode(0, 1, 0, 0) || + signature === 'true' || + signature === 'typ1' + ) { + font.outlinesFormat = 'truetype'; + numTables = parse.getUShort(data, 4); + tableEntries = parseOpenTypeTableEntries(data, numTables); + } else if (signature === 'OTTO') { + font.outlinesFormat = 'cff'; + numTables = parse.getUShort(data, 4); + tableEntries = parseOpenTypeTableEntries(data, numTables); + } else if (signature === 'wOFF') { + var flavor = parse.getTag(data, 4); + if (flavor === String.fromCharCode(0, 1, 0, 0)) { + font.outlinesFormat = 'truetype'; + } else if (flavor === 'OTTO') { + font.outlinesFormat = 'cff'; + } else { + throw new Error('Unsupported OpenType flavor ' + signature); + } + + numTables = parse.getUShort(data, 12); + tableEntries = parseWOFFTableEntries(data, numTables); + } else { + throw new Error('Unsupported OpenType signature ' + signature); + } + + var cffTableEntry; + var fvarTableEntry; + var glyfTableEntry; + var gposTableEntry; + var gsubTableEntry; + var hmtxTableEntry; + var kernTableEntry; + var locaTableEntry; + var nameTableEntry; + var metaTableEntry; + var p; + + for (var i = 0; i < numTables; i += 1) { + var tableEntry = tableEntries[i]; + var table = void 0; + switch (tableEntry.tag) { + case 'cmap': + table = uncompressTable(data, tableEntry); + font.tables.cmap = cmap.parse(table.data, table.offset); + font.encoding = new CmapEncoding(font.tables.cmap); + break; + case 'cvt ': + table = uncompressTable(data, tableEntry); + p = new parse.Parser(table.data, table.offset); + font.tables.cvt = p.parseShortList(tableEntry.length / 2); + break; + case 'fvar': + fvarTableEntry = tableEntry; + break; + case 'fpgm': + table = uncompressTable(data, tableEntry); + p = new parse.Parser(table.data, table.offset); + font.tables.fpgm = p.parseByteList(tableEntry.length); + break; + case 'head': + table = uncompressTable(data, tableEntry); + font.tables.head = head.parse(table.data, table.offset); + font.unitsPerEm = font.tables.head.unitsPerEm; + indexToLocFormat = font.tables.head.indexToLocFormat; + break; + case 'hhea': + table = uncompressTable(data, tableEntry); + font.tables.hhea = hhea.parse(table.data, table.offset); + font.ascender = font.tables.hhea.ascender; + font.descender = font.tables.hhea.descender; + font.numberOfHMetrics = font.tables.hhea.numberOfHMetrics; + break; + case 'hmtx': + hmtxTableEntry = tableEntry; + break; + case 'ltag': + table = uncompressTable(data, tableEntry); + ltagTable = ltag.parse(table.data, table.offset); + break; + case 'maxp': + table = uncompressTable(data, tableEntry); + font.tables.maxp = maxp.parse(table.data, table.offset); + font.numGlyphs = font.tables.maxp.numGlyphs; + break; + case 'name': + nameTableEntry = tableEntry; + break; + case 'OS/2': + table = uncompressTable(data, tableEntry); + font.tables.os2 = os2.parse(table.data, table.offset); + break; + case 'post': + table = uncompressTable(data, tableEntry); + font.tables.post = post.parse(table.data, table.offset); + font.glyphNames = new GlyphNames(font.tables.post); + break; + case 'prep': + table = uncompressTable(data, tableEntry); + p = new parse.Parser(table.data, table.offset); + font.tables.prep = p.parseByteList(tableEntry.length); + break; + case 'glyf': + glyfTableEntry = tableEntry; + break; + case 'loca': + locaTableEntry = tableEntry; + break; + case 'CFF ': + cffTableEntry = tableEntry; + break; + case 'kern': + kernTableEntry = tableEntry; + break; + case 'GPOS': + gposTableEntry = tableEntry; + break; + case 'GSUB': + gsubTableEntry = tableEntry; + break; + case 'meta': + metaTableEntry = tableEntry; + break; + } + } + + var nameTable = uncompressTable(data, nameTableEntry); + font.tables.name = _name.parse(nameTable.data, nameTable.offset, ltagTable); + font.names = font.tables.name; + + if (glyfTableEntry && locaTableEntry) { + var shortVersion = indexToLocFormat === 0; + var locaTable = uncompressTable(data, locaTableEntry); + var locaOffsets = loca.parse( + locaTable.data, + locaTable.offset, + font.numGlyphs, + shortVersion + ); + var glyfTable = uncompressTable(data, glyfTableEntry); + font.glyphs = glyf.parse( + glyfTable.data, + glyfTable.offset, + locaOffsets, + font + ); + } else if (cffTableEntry) { + var cffTable = uncompressTable(data, cffTableEntry); + cff.parse(cffTable.data, cffTable.offset, font); + } else { + throw new Error("Font doesn't contain TrueType or CFF outlines."); + } + + var hmtxTable = uncompressTable(data, hmtxTableEntry); + hmtx.parse( + hmtxTable.data, + hmtxTable.offset, + font.numberOfHMetrics, + font.numGlyphs, + font.glyphs + ); + addGlyphNames(font); + + if (kernTableEntry) { + var kernTable = uncompressTable(data, kernTableEntry); + font.kerningPairs = kern.parse(kernTable.data, kernTable.offset); + } else { + font.kerningPairs = {}; + } + + if (gposTableEntry) { + var gposTable = uncompressTable(data, gposTableEntry); + font.tables.gpos = gpos.parse(gposTable.data, gposTable.offset); + font.position.init(); + } + + if (gsubTableEntry) { + var gsubTable = uncompressTable(data, gsubTableEntry); + font.tables.gsub = gsub.parse(gsubTable.data, gsubTable.offset); + } + + if (fvarTableEntry) { + var fvarTable = uncompressTable(data, fvarTableEntry); + font.tables.fvar = fvar.parse( + fvarTable.data, + fvarTable.offset, + font.names + ); + } + + if (metaTableEntry) { + var metaTable = uncompressTable(data, metaTableEntry); + font.tables.meta = meta.parse(metaTable.data, metaTable.offset); + font.metas = font.tables.meta; + } + + return font; + } + + /** + * Asynchronously load the font from a URL or a filesystem. When done, call the callback + * with two arguments `(err, font)`. The `err` will be null on success, + * the `font` is a Font object. + * We use the node.js callback convention so that + * opentype.js can integrate with frameworks like async.js. + * @alias opentype.load + * @param {string} url - The URL of the font to load. + * @param {Function} callback - The callback. + */ + function load(url, callback) { + var isNode$$1 = typeof window === 'undefined'; + var loadFn = isNode$$1 ? loadFromFile : loadFromUrl; + loadFn(url, function(err, arrayBuffer) { + if (err) { + return callback(err); + } + var font; + try { + font = parseBuffer(arrayBuffer); + } catch (e) { + return callback(e, null); + } + return callback(null, font); + }); + } + + /** + * Synchronously load the font from a URL or file. + * When done, returns the font object or throws an error. + * @alias opentype.loadSync + * @param {string} url - The URL of the font to load. + * @return {opentype.Font} + */ + function loadSync(url) { + var fs = _dereq_('fs'); + var buffer = fs.readFileSync(url); + return parseBuffer(nodeBufferToArrayBuffer(buffer)); + } + + exports.Font = Font; + exports.Glyph = Glyph; + exports.Path = Path; + exports.BoundingBox = BoundingBox; + exports._parse = parse; + exports.parse = parseBuffer; + exports.load = load; + exports.loadSync = loadSync; + + Object.defineProperty(exports, '__esModule', { value: true }); + }); + }.call(this, _dereq_('buffer').Buffer)); + }, + { buffer: 4, fs: 3 } + ], + 11: [ + function(_dereq_, module, exports) { + // shim for using process in browser + var process = (module.exports = {}); + + // cached from whatever global is present so that test runners that stub it + // don't break things. But we need to wrap it in a try catch in case it is + // wrapped in strict mode code which doesn't define any globals. It's inside a + // function because try/catches deoptimize in certain engines. + + var cachedSetTimeout; + var cachedClearTimeout; + + function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); + } + function defaultClearTimeout() { + throw new Error('clearTimeout has not been defined'); + } + (function() { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } + })(); + function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ( + (cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && + setTimeout + ) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch (e) { + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch (e) { + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + } + function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ( + (cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && + clearTimeout + ) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e) { + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e) { + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + } + var queue = []; + var draining = false; + var currentQueue; + var queueIndex = -1; + + function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } + } + + function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while (len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); + } + + process.nextTick = function(fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } + }; + + // v8 likes predictible objects + function Item(fun, array) { + this.fun = fun; + this.array = array; + } + Item.prototype.run = function() { + this.fun.apply(null, this.array); + }; + process.title = 'browser'; + process.browser = true; + process.env = {}; + process.argv = []; + process.version = ''; // empty string to avoid regexp issues + process.versions = {}; + + function noop() {} + + process.on = noop; + process.addListener = noop; + process.once = noop; + process.off = noop; + process.removeListener = noop; + process.removeAllListeners = noop; + process.emit = noop; + process.prependListener = noop; + process.prependOnceListener = noop; + + process.listeners = function(name) { + return []; + }; + + process.binding = function(name) { + throw new Error('process.binding is not supported'); + }; + + process.cwd = function() { + return '/'; + }; + process.chdir = function(dir) { + throw new Error('process.chdir is not supported'); + }; + process.umask = function() { + return 0; + }; + }, + {} + ], + 12: [ + function(_dereq_, module, exports) { + (function(self) { + 'use strict'; + + if (self.fetch) { + return; + } + + var support = { + searchParams: 'URLSearchParams' in self, + iterable: 'Symbol' in self && 'iterator' in Symbol, + blob: + 'FileReader' in self && + 'Blob' in self && + (function() { + try { + new Blob(); + return true; + } catch (e) { + return false; + } + })(), + formData: 'FormData' in self, + arrayBuffer: 'ArrayBuffer' in self + }; + + if (support.arrayBuffer) { + var viewClasses = [ + '[object Int8Array]', + '[object Uint8Array]', + '[object Uint8ClampedArray]', + '[object Int16Array]', + '[object Uint16Array]', + '[object Int32Array]', + '[object Uint32Array]', + '[object Float32Array]', + '[object Float64Array]' + ]; + + var isDataView = function(obj) { + return obj && DataView.prototype.isPrototypeOf(obj); + }; + + var isArrayBufferView = + ArrayBuffer.isView || + function(obj) { + return ( + obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1 + ); + }; + } + + function normalizeName(name) { + if (typeof name !== 'string') { + name = String(name); + } + if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) { + throw new TypeError('Invalid character in header field name'); + } + return name.toLowerCase(); + } + + function normalizeValue(value) { + if (typeof value !== 'string') { + value = String(value); + } + return value; + } + + // Build a destructive iterator for the value list + function iteratorFor(items) { + var iterator = { + next: function() { + var value = items.shift(); + return { done: value === undefined, value: value }; + } + }; + + if (support.iterable) { + iterator[Symbol.iterator] = function() { + return iterator; + }; + } + + return iterator; + } + + function Headers(headers) { + this.map = {}; + + if (headers instanceof Headers) { + headers.forEach(function(value, name) { + this.append(name, value); + }, this); + } else if (Array.isArray(headers)) { + headers.forEach(function(header) { + this.append(header[0], header[1]); + }, this); + } else if (headers) { + Object.getOwnPropertyNames(headers).forEach(function(name) { + this.append(name, headers[name]); + }, this); + } + } + + Headers.prototype.append = function(name, value) { + name = normalizeName(name); + value = normalizeValue(value); + var oldValue = this.map[name]; + this.map[name] = oldValue ? oldValue + ',' + value : value; + }; + + Headers.prototype['delete'] = function(name) { + delete this.map[normalizeName(name)]; + }; + + Headers.prototype.get = function(name) { + name = normalizeName(name); + return this.has(name) ? this.map[name] : null; + }; + + Headers.prototype.has = function(name) { + return this.map.hasOwnProperty(normalizeName(name)); + }; + + Headers.prototype.set = function(name, value) { + this.map[normalizeName(name)] = normalizeValue(value); + }; + + Headers.prototype.forEach = function(callback, thisArg) { + for (var name in this.map) { + if (this.map.hasOwnProperty(name)) { + callback.call(thisArg, this.map[name], name, this); + } + } + }; + + Headers.prototype.keys = function() { + var items = []; + this.forEach(function(value, name) { + items.push(name); + }); + return iteratorFor(items); + }; + + Headers.prototype.values = function() { + var items = []; + this.forEach(function(value) { + items.push(value); + }); + return iteratorFor(items); + }; + + Headers.prototype.entries = function() { + var items = []; + this.forEach(function(value, name) { + items.push([name, value]); + }); + return iteratorFor(items); + }; + + if (support.iterable) { + Headers.prototype[Symbol.iterator] = Headers.prototype.entries; + } + + function consumed(body) { + if (body.bodyUsed) { + return Promise.reject(new TypeError('Already read')); + } + body.bodyUsed = true; + } + + function fileReaderReady(reader) { + return new Promise(function(resolve, reject) { + reader.onload = function() { + resolve(reader.result); + }; + reader.onerror = function() { + reject(reader.error); + }; + }); + } + + function readBlobAsArrayBuffer(blob) { + var reader = new FileReader(); + var promise = fileReaderReady(reader); + reader.readAsArrayBuffer(blob); + return promise; + } + + function readBlobAsText(blob) { + var reader = new FileReader(); + var promise = fileReaderReady(reader); + reader.readAsText(blob); + return promise; + } + + function readArrayBufferAsText(buf) { + var view = new Uint8Array(buf); + var chars = new Array(view.length); + + for (var i = 0; i < view.length; i++) { + chars[i] = String.fromCharCode(view[i]); + } + return chars.join(''); + } + + function bufferClone(buf) { + if (buf.slice) { + return buf.slice(0); + } else { + var view = new Uint8Array(buf.byteLength); + view.set(new Uint8Array(buf)); + return view.buffer; + } + } + + function Body() { + this.bodyUsed = false; + + this._initBody = function(body) { + this._bodyInit = body; + if (!body) { + this._bodyText = ''; + } else if (typeof body === 'string') { + this._bodyText = body; + } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { + this._bodyBlob = body; + } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { + this._bodyFormData = body; + } else if ( + support.searchParams && + URLSearchParams.prototype.isPrototypeOf(body) + ) { + this._bodyText = body.toString(); + } else if (support.arrayBuffer && support.blob && isDataView(body)) { + this._bodyArrayBuffer = bufferClone(body.buffer); + // IE 10-11 can't handle a DataView body. + this._bodyInit = new Blob([this._bodyArrayBuffer]); + } else if ( + support.arrayBuffer && + (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body)) + ) { + this._bodyArrayBuffer = bufferClone(body); + } else { + throw new Error('unsupported BodyInit type'); + } + + if (!this.headers.get('content-type')) { + if (typeof body === 'string') { + this.headers.set('content-type', 'text/plain;charset=UTF-8'); + } else if (this._bodyBlob && this._bodyBlob.type) { + this.headers.set('content-type', this._bodyBlob.type); + } else if ( + support.searchParams && + URLSearchParams.prototype.isPrototypeOf(body) + ) { + this.headers.set( + 'content-type', + 'application/x-www-form-urlencoded;charset=UTF-8' + ); + } + } + }; + + if (support.blob) { + this.blob = function() { + var rejected = consumed(this); + if (rejected) { + return rejected; + } + + if (this._bodyBlob) { + return Promise.resolve(this._bodyBlob); + } else if (this._bodyArrayBuffer) { + return Promise.resolve(new Blob([this._bodyArrayBuffer])); + } else if (this._bodyFormData) { + throw new Error('could not read FormData body as blob'); + } else { + return Promise.resolve(new Blob([this._bodyText])); + } + }; + + this.arrayBuffer = function() { + if (this._bodyArrayBuffer) { + return consumed(this) || Promise.resolve(this._bodyArrayBuffer); + } else { + return this.blob().then(readBlobAsArrayBuffer); + } + }; + } + + this.text = function() { + var rejected = consumed(this); + if (rejected) { + return rejected; + } + + if (this._bodyBlob) { + return readBlobAsText(this._bodyBlob); + } else if (this._bodyArrayBuffer) { + return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer)); + } else if (this._bodyFormData) { + throw new Error('could not read FormData body as text'); + } else { + return Promise.resolve(this._bodyText); + } + }; + + if (support.formData) { + this.formData = function() { + return this.text().then(decode); + }; + } + + this.json = function() { + return this.text().then(JSON.parse); + }; + + return this; + } + + // HTTP methods whose capitalization should be normalized + var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']; + + function normalizeMethod(method) { + var upcased = method.toUpperCase(); + return methods.indexOf(upcased) > -1 ? upcased : method; + } + + function Request(input, options) { + options = options || {}; + var body = options.body; + + if (input instanceof Request) { + if (input.bodyUsed) { + throw new TypeError('Already read'); + } + this.url = input.url; + this.credentials = input.credentials; + if (!options.headers) { + this.headers = new Headers(input.headers); + } + this.method = input.method; + this.mode = input.mode; + if (!body && input._bodyInit != null) { + body = input._bodyInit; + input.bodyUsed = true; + } + } else { + this.url = String(input); + } + + this.credentials = options.credentials || this.credentials || 'omit'; + if (options.headers || !this.headers) { + this.headers = new Headers(options.headers); + } + this.method = normalizeMethod(options.method || this.method || 'GET'); + this.mode = options.mode || this.mode || null; + this.referrer = null; + + if ((this.method === 'GET' || this.method === 'HEAD') && body) { + throw new TypeError('Body not allowed for GET or HEAD requests'); + } + this._initBody(body); + } + + Request.prototype.clone = function() { + return new Request(this, { body: this._bodyInit }); + }; + + function decode(body) { + var form = new FormData(); + body + .trim() + .split('&') + .forEach(function(bytes) { + if (bytes) { + var split = bytes.split('='); + var name = split.shift().replace(/\+/g, ' '); + var value = split.join('=').replace(/\+/g, ' '); + form.append(decodeURIComponent(name), decodeURIComponent(value)); + } + }); + return form; + } + + function parseHeaders(rawHeaders) { + var headers = new Headers(); + // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space + // https://tools.ietf.org/html/rfc7230#section-3.2 + var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' '); + preProcessedHeaders.split(/\r?\n/).forEach(function(line) { + var parts = line.split(':'); + var key = parts.shift().trim(); + if (key) { + var value = parts.join(':').trim(); + headers.append(key, value); + } + }); + return headers; + } + + Body.call(Request.prototype); + + function Response(bodyInit, options) { + if (!options) { + options = {}; + } + + this.type = 'default'; + this.status = options.status === undefined ? 200 : options.status; + this.ok = this.status >= 200 && this.status < 300; + this.statusText = 'statusText' in options ? options.statusText : 'OK'; + this.headers = new Headers(options.headers); + this.url = options.url || ''; + this._initBody(bodyInit); + } + + Body.call(Response.prototype); + + Response.prototype.clone = function() { + return new Response(this._bodyInit, { + status: this.status, + statusText: this.statusText, + headers: new Headers(this.headers), + url: this.url + }); + }; + + Response.error = function() { + var response = new Response(null, { status: 0, statusText: '' }); + response.type = 'error'; + return response; + }; + + var redirectStatuses = [301, 302, 303, 307, 308]; + + Response.redirect = function(url, status) { + if (redirectStatuses.indexOf(status) === -1) { + throw new RangeError('Invalid status code'); + } + + return new Response(null, { status: status, headers: { location: url } }); + }; + + self.Headers = Headers; + self.Request = Request; + self.Response = Response; + + self.fetch = function(input, init) { + return new Promise(function(resolve, reject) { + var request = new Request(input, init); + var xhr = new XMLHttpRequest(); + + xhr.onload = function() { + var options = { + status: xhr.status, + statusText: xhr.statusText, + headers: parseHeaders(xhr.getAllResponseHeaders() || '') + }; + options.url = + 'responseURL' in xhr + ? xhr.responseURL + : options.headers.get('X-Request-URL'); + var body = 'response' in xhr ? xhr.response : xhr.responseText; + resolve(new Response(body, options)); + }; + + xhr.onerror = function() { + reject(new TypeError('Network request failed')); + }; + + xhr.ontimeout = function() { + reject(new TypeError('Network request failed')); + }; + + xhr.open(request.method, request.url, true); + + if (request.credentials === 'include') { + xhr.withCredentials = true; + } else if (request.credentials === 'omit') { + xhr.withCredentials = false; + } + + if ('responseType' in xhr && support.blob) { + xhr.responseType = 'blob'; + } + + request.headers.forEach(function(value, name) { + xhr.setRequestHeader(name, value); + }); + + xhr.send( + typeof request._bodyInit === 'undefined' ? null : request._bodyInit + ); + }); + }; + self.fetch.polyfill = true; + })(typeof self !== 'undefined' ? self : this); + }, + {} + ], + 13: [ + function(_dereq_, module, exports) { + 'use strict'; + + // core + var p5 = _dereq_('./core/main'); + _dereq_('./core/constants'); + _dereq_('./core/environment'); + _dereq_('./core/error_helpers'); + _dereq_('./core/helpers'); + _dereq_('./core/legacy'); + _dereq_('./core/p5.Element'); + _dereq_('./core/p5.Graphics'); + _dereq_('./core/p5.Renderer'); + _dereq_('./core/p5.Renderer2D'); + _dereq_('./core/rendering'); + _dereq_('./core/shim'); + _dereq_('./core/structure'); + _dereq_('./core/transform'); + _dereq_('./core/shape/2d_primitives'); + _dereq_('./core/shape/attributes'); + _dereq_('./core/shape/curves'); + _dereq_('./core/shape/vertex'); + + // color + _dereq_('./color/color_conversion'); + _dereq_('./color/creating_reading'); + _dereq_('./color/p5.Color'); + _dereq_('./color/setting'); + + // data + _dereq_('./data/p5.TypedDict'); + _dereq_('./data/local_storage.js'); + + // events + _dereq_('./events/acceleration'); + _dereq_('./events/keyboard'); + _dereq_('./events/mouse'); + _dereq_('./events/touch'); + + // image + _dereq_('./image/filters'); + _dereq_('./image/image'); + _dereq_('./image/loading_displaying'); + _dereq_('./image/p5.Image'); + _dereq_('./image/pixels'); + + // io + _dereq_('./io/files'); + _dereq_('./io/p5.Table'); + _dereq_('./io/p5.TableRow'); + _dereq_('./io/p5.XML'); + + // math + _dereq_('./math/calculation'); + _dereq_('./math/math'); + _dereq_('./math/noise'); + _dereq_('./math/p5.Vector'); + _dereq_('./math/random'); + _dereq_('./math/trigonometry'); + + // typography + _dereq_('./typography/attributes'); + _dereq_('./typography/loading_displaying'); + _dereq_('./typography/p5.Font'); + + // utilities + _dereq_('./utilities/array_functions'); + _dereq_('./utilities/conversion'); + _dereq_('./utilities/string_functions'); + _dereq_('./utilities/time_date'); + + // webgl + _dereq_('./webgl/3d_primitives'); + _dereq_('./webgl/interaction'); + _dereq_('./webgl/light'); + _dereq_('./webgl/loading'); + _dereq_('./webgl/material'); + _dereq_('./webgl/p5.Camera'); + _dereq_('./webgl/p5.Geometry'); + _dereq_('./webgl/p5.Matrix'); + _dereq_('./webgl/p5.RendererGL.Immediate'); + _dereq_('./webgl/p5.RendererGL'); + _dereq_('./webgl/p5.RendererGL.Retained'); + _dereq_('./webgl/p5.Shader'); + _dereq_('./webgl/p5.Texture'); + _dereq_('./webgl/text'); + + _dereq_('./core/init'); + + module.exports = p5; + }, + { + './color/color_conversion': 14, + './color/creating_reading': 15, + './color/p5.Color': 16, + './color/setting': 17, + './core/constants': 18, + './core/environment': 19, + './core/error_helpers': 20, + './core/helpers': 21, + './core/init': 22, + './core/legacy': 23, + './core/main': 24, + './core/p5.Element': 25, + './core/p5.Graphics': 26, + './core/p5.Renderer': 27, + './core/p5.Renderer2D': 28, + './core/rendering': 29, + './core/shape/2d_primitives': 30, + './core/shape/attributes': 31, + './core/shape/curves': 32, + './core/shape/vertex': 33, + './core/shim': 34, + './core/structure': 35, + './core/transform': 36, + './data/local_storage.js': 37, + './data/p5.TypedDict': 38, + './events/acceleration': 39, + './events/keyboard': 40, + './events/mouse': 41, + './events/touch': 42, + './image/filters': 43, + './image/image': 44, + './image/loading_displaying': 45, + './image/p5.Image': 46, + './image/pixels': 47, + './io/files': 48, + './io/p5.Table': 49, + './io/p5.TableRow': 50, + './io/p5.XML': 51, + './math/calculation': 52, + './math/math': 53, + './math/noise': 54, + './math/p5.Vector': 55, + './math/random': 56, + './math/trigonometry': 57, + './typography/attributes': 58, + './typography/loading_displaying': 59, + './typography/p5.Font': 60, + './utilities/array_functions': 61, + './utilities/conversion': 62, + './utilities/string_functions': 63, + './utilities/time_date': 64, + './webgl/3d_primitives': 65, + './webgl/interaction': 66, + './webgl/light': 67, + './webgl/loading': 68, + './webgl/material': 69, + './webgl/p5.Camera': 70, + './webgl/p5.Geometry': 71, + './webgl/p5.Matrix': 72, + './webgl/p5.RendererGL': 75, + './webgl/p5.RendererGL.Immediate': 73, + './webgl/p5.RendererGL.Retained': 74, + './webgl/p5.Shader': 76, + './webgl/p5.Texture': 77, + './webgl/text': 78 + } + ], + 14: [ + function(_dereq_, module, exports) { + /** + * @module Color + * @submodule Color Conversion + * @for p5 + * @requires core + */ + + 'use strict'; + + /** + * Conversions adapted from . + * + * In these functions, hue is always in the range [0, 1], just like all other + * components are in the range [0, 1]. 'Brightness' and 'value' are used + * interchangeably. + */ + + var p5 = _dereq_('../core/main'); + p5.ColorConversion = {}; + + /** + * Convert an HSBA array to HSLA. + */ + p5.ColorConversion._hsbaToHSLA = function(hsba) { + var hue = hsba[0]; + var sat = hsba[1]; + var val = hsba[2]; + + // Calculate lightness. + var li = (2 - sat) * val / 2; + + // Convert saturation. + if (li !== 0) { + if (li === 1) { + sat = 0; + } else if (li < 0.5) { + sat = sat / (2 - sat); + } else { + sat = sat * val / (2 - li * 2); + } + } + + // Hue and alpha stay the same. + return [hue, sat, li, hsba[3]]; + }; + + /** + * Convert an HSBA array to RGBA. + */ + p5.ColorConversion._hsbaToRGBA = function(hsba) { + var hue = hsba[0] * 6; // We will split hue into 6 sectors. + var sat = hsba[1]; + var val = hsba[2]; + + var RGBA = []; + + if (sat === 0) { + RGBA = [val, val, val, hsba[3]]; // Return early if grayscale. + } else { + var sector = Math.floor(hue); + var tint1 = val * (1 - sat); + var tint2 = val * (1 - sat * (hue - sector)); + var tint3 = val * (1 - sat * (1 + sector - hue)); + var red, green, blue; + if (sector === 1) { + // Yellow to green. + red = tint2; + green = val; + blue = tint1; + } else if (sector === 2) { + // Green to cyan. + red = tint1; + green = val; + blue = tint3; + } else if (sector === 3) { + // Cyan to blue. + red = tint1; + green = tint2; + blue = val; + } else if (sector === 4) { + // Blue to magenta. + red = tint3; + green = tint1; + blue = val; + } else if (sector === 5) { + // Magenta to red. + red = val; + green = tint1; + blue = tint2; + } else { + // Red to yellow (sector could be 0 or 6). + red = val; + green = tint3; + blue = tint1; + } + RGBA = [red, green, blue, hsba[3]]; + } + + return RGBA; + }; + + /** + * Convert an HSLA array to HSBA. + */ + p5.ColorConversion._hslaToHSBA = function(hsla) { + var hue = hsla[0]; + var sat = hsla[1]; + var li = hsla[2]; + + // Calculate brightness. + var val; + if (li < 0.5) { + val = (1 + sat) * li; + } else { + val = li + sat - li * sat; + } + + // Convert saturation. + sat = 2 * (val - li) / val; + + // Hue and alpha stay the same. + return [hue, sat, val, hsla[3]]; + }; + + /** + * Convert an HSLA array to RGBA. + * + * We need to change basis from HSLA to something that can be more easily be + * projected onto RGBA. We will choose hue and brightness as our first two + * components, and pick a convenient third one ('zest') so that we don't need + * to calculate formal HSBA saturation. + */ + p5.ColorConversion._hslaToRGBA = function(hsla) { + var hue = hsla[0] * 6; // We will split hue into 6 sectors. + var sat = hsla[1]; + var li = hsla[2]; + + var RGBA = []; + + if (sat === 0) { + RGBA = [li, li, li, hsla[3]]; // Return early if grayscale. + } else { + // Calculate brightness. + var val; + if (li < 0.5) { + val = (1 + sat) * li; + } else { + val = li + sat - li * sat; + } + + // Define zest. + var zest = 2 * li - val; + + // Implement projection (project onto green by default). + var hzvToRGB = function hzvToRGB(hue, zest, val) { + if (hue < 0) { + // Hue must wrap to allow projection onto red and blue. + hue += 6; + } else if (hue >= 6) { + hue -= 6; + } + if (hue < 1) { + // Red to yellow (increasing green). + return zest + (val - zest) * hue; + } else if (hue < 3) { + // Yellow to cyan (greatest green). + return val; + } else if (hue < 4) { + // Cyan to blue (decreasing green). + return zest + (val - zest) * (4 - hue); + } else { + // Blue to red (least green). + return zest; + } + }; + + // Perform projections, offsetting hue as necessary. + RGBA = [ + hzvToRGB(hue + 2, zest, val), + hzvToRGB(hue, zest, val), + hzvToRGB(hue - 2, zest, val), + hsla[3] + ]; + } + + return RGBA; + }; + + /** + * Convert an RGBA array to HSBA. + */ + p5.ColorConversion._rgbaToHSBA = function(rgba) { + var red = rgba[0]; + var green = rgba[1]; + var blue = rgba[2]; + + var val = Math.max(red, green, blue); + var chroma = val - Math.min(red, green, blue); + + var hue, sat; + if (chroma === 0) { + // Return early if grayscale. + hue = 0; + sat = 0; + } else { + sat = chroma / val; + if (red === val) { + // Magenta to yellow. + hue = (green - blue) / chroma; + } else if (green === val) { + // Yellow to cyan. + hue = 2 + (blue - red) / chroma; + } else if (blue === val) { + // Cyan to magenta. + hue = 4 + (red - green) / chroma; + } + if (hue < 0) { + // Confine hue to the interval [0, 1). + hue += 6; + } else if (hue >= 6) { + hue -= 6; + } + } + + return [hue / 6, sat, val, rgba[3]]; + }; + + /** + * Convert an RGBA array to HSLA. + */ + p5.ColorConversion._rgbaToHSLA = function(rgba) { + var red = rgba[0]; + var green = rgba[1]; + var blue = rgba[2]; + + var val = Math.max(red, green, blue); + var min = Math.min(red, green, blue); + var li = val + min; // We will halve this later. + var chroma = val - min; + + var hue, sat; + if (chroma === 0) { + // Return early if grayscale. + hue = 0; + sat = 0; + } else { + if (li < 1) { + sat = chroma / li; + } else { + sat = chroma / (2 - li); + } + if (red === val) { + // Magenta to yellow. + hue = (green - blue) / chroma; + } else if (green === val) { + // Yellow to cyan. + hue = 2 + (blue - red) / chroma; + } else if (blue === val) { + // Cyan to magenta. + hue = 4 + (red - green) / chroma; + } + if (hue < 0) { + // Confine hue to the interval [0, 1). + hue += 6; + } else if (hue >= 6) { + hue -= 6; + } + } + + return [hue / 6, sat, li / 2, rgba[3]]; + }; + + module.exports = p5.ColorConversion; + }, + { '../core/main': 24 } + ], + 15: [ + function(_dereq_, module, exports) { + /** + * @module Color + * @submodule Creating & Reading + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + _dereq_('./p5.Color'); + _dereq_('../core/error_helpers'); + + /** + * Extracts the alpha value from a color or pixel array. + * + * @method alpha + * @param {p5.Color|Number[]|String} color p5.Color object, color components, + * or CSS color + * @return {Number} the alpha value + * @example + *
+ * + * noStroke(); + * let c = color(0, 126, 255, 102); + * fill(c); + * rect(15, 15, 35, 70); + * let value = alpha(c); // Sets 'value' to 102 + * fill(value); + * rect(50, 15, 35, 70); + * + *
+ * + * @alt + * Left half of canvas light blue and right half light charcoal grey. + * Left half of canvas light purple and right half a royal blue. + * Left half of canvas salmon pink and the right half white. + * Yellow rect in middle right of canvas, with 55 pixel width and height. + * Yellow ellipse in top left canvas, black ellipse in bottom right,both 80x80. + * Bright fuchsia rect in middle of canvas, 60 pixel width and height. + * Two bright green rects on opposite sides of the canvas, both 45x80. + * Four blue rects in each corner of the canvas, each are 35x35. + * Bright sea green rect on left and darker rect on right of canvas, both 45x80. + * Dark green rect on left and light green rect on right of canvas, both 45x80. + * Dark blue rect on left and light teal rect on right of canvas, both 45x80. + * blue rect on left and green on right, both with black outlines & 35x60. + * salmon pink rect on left and black on right, both 35x60. + * 4 rects, tan, brown, brownish purple and purple, with white outlines & 20x60. + * light pastel green rect on left and dark grey rect on right, both 35x60. + * yellow rect on left and red rect on right, both with black outlines & 35x60. + * grey canvas + * deep pink rect on left and grey rect on right, both 35x60. + */ + p5.prototype.alpha = function(c) { + p5._validateParameters('alpha', arguments); + return this.color(c)._getAlpha(); + }; + + /** + * Extracts the blue value from a color or pixel array. + * + * @method blue + * @param {p5.Color|Number[]|String} color p5.Color object, color components, + * or CSS color + * @return {Number} the blue value + * @example + *
+ * + * let c = color(175, 100, 220); // Define color 'c' + * fill(c); // Use color variable 'c' as fill color + * rect(15, 20, 35, 60); // Draw left rectangle + * + * let blueValue = blue(c); // Get blue in 'c' + * print(blueValue); // Prints "220.0" + * fill(0, 0, blueValue); // Use 'blueValue' in new fill + * rect(50, 20, 35, 60); // Draw right rectangle + * + *
+ * + * @alt + * Left half of canvas light purple and right half a royal blue. + * + */ + p5.prototype.blue = function(c) { + p5._validateParameters('blue', arguments); + return this.color(c)._getBlue(); + }; + + /** + * Extracts the HSB brightness value from a color or pixel array. + * + * @method brightness + * @param {p5.Color|Number[]|String} color p5.Color object, color components, + * or CSS color + * @return {Number} the brightness value + * @example + *
+ * + * noStroke(); + * colorMode(HSB, 255); + * let c = color(0, 126, 255); + * fill(c); + * rect(15, 20, 35, 60); + * let value = brightness(c); // Sets 'value' to 255 + * fill(value); + * rect(50, 20, 35, 60); + * + *
+ *
+ * + * noStroke(); + * colorMode(HSB, 255); + * let c = color('hsb(60, 100%, 50%)'); + * fill(c); + * rect(15, 20, 35, 60); + * let value = brightness(c); // A 'value' of 50% is 127.5 + * fill(value); + * rect(50, 20, 35, 60); + * + *
+ * + * @alt + * Left half of canvas salmon pink and the right half white. + * Left half of canvas yellow at half brightness and the right gray . + * + */ + p5.prototype.brightness = function(c) { + p5._validateParameters('brightness', arguments); + return this.color(c)._getBrightness(); + }; + + /** + * Creates colors for storing in variables of the color datatype. The + * parameters are interpreted as RGB or HSB values depending on the + * current colorMode(). The default mode is RGB values from 0 to 255 + * and, therefore, the function call color(255, 204, 0) will return a + * bright yellow color. + *

+ * Note that if only one value is provided to color(), it will be interpreted + * as a grayscale value. Add a second value, and it will be used for alpha + * transparency. When three values are specified, they are interpreted as + * either RGB or HSB values. Adding a fourth value applies alpha + * transparency. + *

+ * If a single string argument is provided, RGB, RGBA and Hex CSS color + * strings and all named color strings are supported. In this case, an alpha + * number value as a second argument is not supported, the RGBA form should be + * used. + * + * @method color + * @param {Number} gray number specifying value between white + * and black. + * @param {Number} [alpha] alpha value relative to current color range + * (default is 0-255) + * @return {p5.Color} resulting color + * + * @example + *
+ * + * let c = color(255, 204, 0); // Define color 'c' + * fill(c); // Use color variable 'c' as fill color + * noStroke(); // Don't draw a stroke around shapes + * rect(30, 20, 55, 55); // Draw rectangle + * + *
+ * + *
+ * + * let c = color(255, 204, 0); // Define color 'c' + * fill(c); // Use color variable 'c' as fill color + * noStroke(); // Don't draw a stroke around shapes + * ellipse(25, 25, 80, 80); // Draw left circle + * + * // Using only one value with color() + * // generates a grayscale value. + * c = color(65); // Update 'c' with grayscale value + * fill(c); // Use updated 'c' as fill color + * ellipse(75, 75, 80, 80); // Draw right circle + * + *
+ * + *
+ * + * // Named SVG & CSS colors may be used, + * let c = color('magenta'); + * fill(c); // Use 'c' as fill color + * noStroke(); // Don't draw a stroke around shapes + * rect(20, 20, 60, 60); // Draw rectangle + * + *
+ * + *
+ * + * // as can hex color codes: + * noStroke(); // Don't draw a stroke around shapes + * let c = color('#0f0'); + * fill(c); // Use 'c' as fill color + * rect(0, 10, 45, 80); // Draw rectangle + * + * c = color('#00ff00'); + * fill(c); // Use updated 'c' as fill color + * rect(55, 10, 45, 80); // Draw rectangle + * + *
+ * + *
+ * + * // RGB and RGBA color strings are also supported: + * // these all set to the same color (solid blue) + * let c; + * noStroke(); // Don't draw a stroke around shapes + * c = color('rgb(0,0,255)'); + * fill(c); // Use 'c' as fill color + * rect(10, 10, 35, 35); // Draw rectangle + * + * c = color('rgb(0%, 0%, 100%)'); + * fill(c); // Use updated 'c' as fill color + * rect(55, 10, 35, 35); // Draw rectangle + * + * c = color('rgba(0, 0, 255, 1)'); + * fill(c); // Use updated 'c' as fill color + * rect(10, 55, 35, 35); // Draw rectangle + * + * c = color('rgba(0%, 0%, 100%, 1)'); + * fill(c); // Use updated 'c' as fill color + * rect(55, 55, 35, 35); // Draw rectangle + * + *
+ * + *
+ * + * // HSL color is also supported and can be specified + * // by value + * let c; + * noStroke(); // Don't draw a stroke around shapes + * c = color('hsl(160, 100%, 50%)'); + * fill(c); // Use 'c' as fill color + * rect(0, 10, 45, 80); // Draw rectangle + * + * c = color('hsla(160, 100%, 50%, 0.5)'); + * fill(c); // Use updated 'c' as fill color + * rect(55, 10, 45, 80); // Draw rectangle + * + *
+ * + *
+ * + * // HSB color is also supported and can be specified + * // by value + * let c; + * noStroke(); // Don't draw a stroke around shapes + * c = color('hsb(160, 100%, 50%)'); + * fill(c); // Use 'c' as fill color + * rect(0, 10, 45, 80); // Draw rectangle + * + * c = color('hsba(160, 100%, 50%, 0.5)'); + * fill(c); // Use updated 'c' as fill color + * rect(55, 10, 45, 80); // Draw rectangle + * + *
+ * + *
+ * + * let c; // Declare color 'c' + * noStroke(); // Don't draw a stroke around shapes + * + * // If no colorMode is specified, then the + * // default of RGB with scale of 0-255 is used. + * c = color(50, 55, 100); // Create a color for 'c' + * fill(c); // Use color variable 'c' as fill color + * rect(0, 10, 45, 80); // Draw left rect + * + * colorMode(HSB, 100); // Use HSB with scale of 0-100 + * c = color(50, 55, 100); // Update 'c' with new color + * fill(c); // Use updated 'c' as fill color + * rect(55, 10, 45, 80); // Draw right rect + * + *
+ * + * @alt + * Yellow rect in middle right of canvas, with 55 pixel width and height. + * Yellow ellipse in top left of canvas, black ellipse in bottom right,both 80x80. + * Bright fuchsia rect in middle of canvas, 60 pixel width and height. + * Two bright green rects on opposite sides of the canvas, both 45x80. + * Four blue rects in each corner of the canvas, each are 35x35. + * Bright sea green rect on left and darker rect on right of canvas, both 45x80. + * Dark green rect on left and lighter green rect on right of canvas, both 45x80. + * Dark blue rect on left and light teal rect on right of canvas, both 45x80. + * + */ + /** + * @method color + * @param {Number} v1 red or hue value relative to + * the current color range + * @param {Number} v2 green or saturation value + * relative to the current color range + * @param {Number} v3 blue or brightness value + * relative to the current color range + * @param {Number} [alpha] + * @return {p5.Color} + */ + + /** + * @method color + * @param {String} value a color string + * @return {p5.Color} + */ + /** + * @method color + * @param {Number[]} values an array containing the red,green,blue & + * and alpha components of the color + * @return {p5.Color} + */ + /** + * @method color + * @param {p5.Color} color + * @return {p5.Color} + */ + + p5.prototype.color = function() { + p5._validateParameters('color', arguments); + if (arguments[0] instanceof p5.Color) { + return arguments[0]; // Do nothing if argument is already a color object. + } + + var args = arguments[0] instanceof Array ? arguments[0] : arguments; + return new p5.Color(this, args); + }; + + /** + * Extracts the green value from a color or pixel array. + * + * @method green + * @param {p5.Color|Number[]|String} color p5.Color object, color components, + * or CSS color + * @return {Number} the green value + * @example + *
+ * + * let c = color(20, 75, 200); // Define color 'c' + * fill(c); // Use color variable 'c' as fill color + * rect(15, 20, 35, 60); // Draw left rectangle + * + * let greenValue = green(c); // Get green in 'c' + * print(greenValue); // Print "75.0" + * fill(0, greenValue, 0); // Use 'greenValue' in new fill + * rect(50, 20, 35, 60); // Draw right rectangle + * + *
+ * + * @alt + * blue rect on left and green on right, both with black outlines & 35x60. + * + */ + + p5.prototype.green = function(c) { + p5._validateParameters('green', arguments); + return this.color(c)._getGreen(); + }; + + /** + * Extracts the hue value from a color or pixel array. + * + * Hue exists in both HSB and HSL. This function will return the + * HSB-normalized hue when supplied with an HSB color object (or when supplied + * with a pixel array while the color mode is HSB), but will default to the + * HSL-normalized hue otherwise. (The values will only be different if the + * maximum hue setting for each system is different.) + * + * @method hue + * @param {p5.Color|Number[]|String} color p5.Color object, color components, + * or CSS color + * @return {Number} the hue + * @example + *
+ * + * noStroke(); + * colorMode(HSB, 255); + * let c = color(0, 126, 255); + * fill(c); + * rect(15, 20, 35, 60); + * let value = hue(c); // Sets 'value' to "0" + * fill(value); + * rect(50, 20, 35, 60); + * + *
+ * + * @alt + * salmon pink rect on left and black on right, both 35x60. + * + */ + + p5.prototype.hue = function(c) { + p5._validateParameters('hue', arguments); + return this.color(c)._getHue(); + }; + + /** + * Blends two colors to find a third color somewhere between them. The amt + * parameter is the amount to interpolate between the two values where 0.0 + * equal to the first color, 0.1 is very near the first color, 0.5 is halfway + * in between, etc. An amount below 0 will be treated as 0. Likewise, amounts + * above 1 will be capped at 1. This is different from the behavior of lerp(), + * but necessary because otherwise numbers outside the range will produce + * strange and unexpected colors. + *

+ * The way that colours are interpolated depends on the current color mode. + * + * @method lerpColor + * @param {p5.Color} c1 interpolate from this color + * @param {p5.Color} c2 interpolate to this color + * @param {Number} amt number between 0 and 1 + * @return {p5.Color} interpolated color + * @example + *
+ * + * colorMode(RGB); + * stroke(255); + * background(51); + * let from = color(218, 165, 32); + * let to = color(72, 61, 139); + * colorMode(RGB); // Try changing to HSB. + * let interA = lerpColor(from, to, 0.33); + * let interB = lerpColor(from, to, 0.66); + * fill(from); + * rect(10, 20, 20, 60); + * fill(interA); + * rect(30, 20, 20, 60); + * fill(interB); + * rect(50, 20, 20, 60); + * fill(to); + * rect(70, 20, 20, 60); + * + *
+ * + * @alt + * 4 rects one tan, brown, brownish purple, purple, with white outlines & 20x60 + * + */ + + p5.prototype.lerpColor = function(c1, c2, amt) { + p5._validateParameters('lerpColor', arguments); + var mode = this._colorMode; + var maxes = this._colorMaxes; + var l0, l1, l2, l3; + var fromArray, toArray; + + if (mode === constants.RGB) { + fromArray = c1.levels.map(function(level) { + return level / 255; + }); + toArray = c2.levels.map(function(level) { + return level / 255; + }); + } else if (mode === constants.HSB) { + c1._getBrightness(); // Cache hsba so it definitely exists. + c2._getBrightness(); + fromArray = c1.hsba; + toArray = c2.hsba; + } else if (mode === constants.HSL) { + c1._getLightness(); // Cache hsla so it definitely exists. + c2._getLightness(); + fromArray = c1.hsla; + toArray = c2.hsla; + } else { + throw new Error(mode + 'cannot be used for interpolation.'); + } + + // Prevent extrapolation. + amt = Math.max(Math.min(amt, 1), 0); + + // Define lerp here itself if user isn't using math module. + // Maintains the definition as found in math/calculation.js + if (typeof this.lerp === 'undefined') { + this.lerp = function(start, stop, amt) { + return amt * (stop - start) + start; + }; + } + + // Perform interpolation. + l0 = this.lerp(fromArray[0], toArray[0], amt); + l1 = this.lerp(fromArray[1], toArray[1], amt); + l2 = this.lerp(fromArray[2], toArray[2], amt); + l3 = this.lerp(fromArray[3], toArray[3], amt); + + // Scale components. + l0 *= maxes[mode][0]; + l1 *= maxes[mode][1]; + l2 *= maxes[mode][2]; + l3 *= maxes[mode][3]; + + return this.color(l0, l1, l2, l3); + }; + + /** + * Extracts the HSL lightness value from a color or pixel array. + * + * @method lightness + * @param {p5.Color|Number[]|String} color p5.Color object, color components, + * or CSS color + * @return {Number} the lightness + * @example + *
+ * + * noStroke(); + * colorMode(HSL); + * let c = color(156, 100, 50, 1); + * fill(c); + * rect(15, 20, 35, 60); + * let value = lightness(c); // Sets 'value' to 50 + * fill(value); + * rect(50, 20, 35, 60); + * + *
+ * + * @alt + * light pastel green rect on left and dark grey rect on right, both 35x60. + * + */ + p5.prototype.lightness = function(c) { + p5._validateParameters('lightness', arguments); + return this.color(c)._getLightness(); + }; + + /** + * Extracts the red value from a color or pixel array. + * + * @method red + * @param {p5.Color|Number[]|String} color p5.Color object, color components, + * or CSS color + * @return {Number} the red value + * @example + *
+ * + * let c = color(255, 204, 0); // Define color 'c' + * fill(c); // Use color variable 'c' as fill color + * rect(15, 20, 35, 60); // Draw left rectangle + * + * let redValue = red(c); // Get red in 'c' + * print(redValue); // Print "255.0" + * fill(redValue, 0, 0); // Use 'redValue' in new fill + * rect(50, 20, 35, 60); // Draw right rectangle + * + *
+ * + *
+ * + * colorMode(RGB, 255); // Sets the range for red, green, and blue to 255 + * let c = color(127, 255, 0); + * colorMode(RGB, 1); // Sets the range for red, green, and blue to 1 + * let myColor = red(c); + * print(myColor); // 0.4980392156862745 + * + *
+ * + * @alt + * yellow rect on left and red rect on right, both with black outlines and 35x60. + * grey canvas + */ + p5.prototype.red = function(c) { + p5._validateParameters('red', arguments); + return this.color(c)._getRed(); + }; + + /** + * Extracts the saturation value from a color or pixel array. + * + * Saturation is scaled differently in HSB and HSL. This function will return + * the HSB saturation when supplied with an HSB color object (or when supplied + * with a pixel array while the color mode is HSB), but will default to the + * HSL saturation otherwise. + * + * @method saturation + * @param {p5.Color|Number[]|String} color p5.Color object, color components, + * or CSS color + * @return {Number} the saturation value + * @example + *
+ * + * noStroke(); + * colorMode(HSB, 255); + * let c = color(0, 126, 255); + * fill(c); + * rect(15, 20, 35, 60); + * let value = saturation(c); // Sets 'value' to 126 + * fill(value); + * rect(50, 20, 35, 60); + * + *
+ * + * @alt + *deep pink rect on left and grey rect on right, both 35x60. + * + */ + + p5.prototype.saturation = function(c) { + p5._validateParameters('saturation', arguments); + return this.color(c)._getSaturation(); + }; + + module.exports = p5; + }, + { + '../core/constants': 18, + '../core/error_helpers': 20, + '../core/main': 24, + './p5.Color': 16 + } + ], + 16: [ + function(_dereq_, module, exports) { + /** + * @module Color + * @submodule Creating & Reading + * @for p5 + * @requires core + * @requires constants + * @requires color_conversion + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + var color_conversion = _dereq_('./color_conversion'); + + /** + * Each color stores the color mode and level maxes that applied at the + * time of its construction. These are used to interpret the input arguments + * (at construction and later for that instance of color) and to format the + * output e.g. when saturation() is requested. + * + * Internally we store an array representing the ideal RGBA values in floating + * point form, normalized from 0 to 1. From this we calculate the closest + * screen color (RGBA levels from 0 to 255) and expose this to the renderer. + * + * We also cache normalized, floating point components of the color in various + * representations as they are calculated. This is done to prevent repeating a + * conversion that has already been performed. + * + * @class p5.Color + */ + p5.Color = function(pInst, vals) { + // Record color mode and maxes at time of construction. + this._storeModeAndMaxes(pInst._colorMode, pInst._colorMaxes); + + // Calculate normalized RGBA values. + if ( + this.mode !== constants.RGB && + this.mode !== constants.HSL && + this.mode !== constants.HSB + ) { + throw new Error(this.mode + ' is an invalid colorMode.'); + } else { + this._array = p5.Color._parseInputs.apply(this, vals); + } + + // Expose closest screen color. + this._calculateLevels(); + return this; + }; + + /** + * This function returns the color formatted as a string. This can be useful + * for debugging, or for using p5.js with other libraries. + * @method toString + * @param {String} [format] How the color string will be formatted. + * Leaving this empty formats the string as rgba(r, g, b, a). + * '#rgb' '#rgba' '#rrggbb' and '#rrggbbaa' format as hexadecimal color codes. + * 'rgb' 'hsb' and 'hsl' return the color formatted in the specified color mode. + * 'rgba' 'hsba' and 'hsla' are the same as above but with alpha channels. + * 'rgb%' 'hsb%' 'hsl%' 'rgba%' 'hsba%' and 'hsla%' format as percentages. + * @return {String} the formatted string + * @example + *
+ * + * let myColor; + * function setup() { + * createCanvas(200, 200); + * stroke(255); + * myColor = color(100, 100, 250); + * fill(myColor); + * } + * + * function draw() { + * rotate(HALF_PI); + * text(myColor.toString(), 0, -5); + * text(myColor.toString('#rrggbb'), 0, -30); + * text(myColor.toString('rgba%'), 0, -55); + * } + * + *
+ * + * @alt + * canvas with text representation of color + */ + p5.Color.prototype.toString = function(format) { + var a = this.levels; + var f = this._array; + var alpha = f[3]; // String representation uses normalized alpha + + switch (format) { + case '#rrggbb': + return '#'.concat( + a[0] < 16 ? '0'.concat(a[0].toString(16)) : a[0].toString(16), + a[1] < 16 ? '0'.concat(a[1].toString(16)) : a[1].toString(16), + a[2] < 16 ? '0'.concat(a[2].toString(16)) : a[2].toString(16) + ); + + case '#rrggbbaa': + return '#'.concat( + a[0] < 16 ? '0'.concat(a[0].toString(16)) : a[0].toString(16), + a[1] < 16 ? '0'.concat(a[1].toString(16)) : a[1].toString(16), + a[2] < 16 ? '0'.concat(a[2].toString(16)) : a[2].toString(16), + a[3] < 16 ? '0'.concat(a[2].toString(16)) : a[3].toString(16) + ); + + case '#rgb': + return '#'.concat( + Math.round(f[0] * 15).toString(16), + Math.round(f[1] * 15).toString(16), + Math.round(f[2] * 15).toString(16) + ); + + case '#rgba': + return '#'.concat( + Math.round(f[0] * 15).toString(16), + Math.round(f[1] * 15).toString(16), + Math.round(f[2] * 15).toString(16), + Math.round(f[3] * 15).toString(16) + ); + + case 'rgb': + return 'rgb('.concat(a[0], ', ', a[1], ', ', a[2], ')'); + + case 'rgb%': + return 'rgb('.concat( + (100 * f[0]).toPrecision(3), + '%, ', + (100 * f[1]).toPrecision(3), + '%, ', + (100 * f[2]).toPrecision(3), + '%)' + ); + + case 'rgba%': + return 'rgba('.concat( + (100 * f[0]).toPrecision(3), + '%, ', + (100 * f[1]).toPrecision(3), + '%, ', + (100 * f[2]).toPrecision(3), + '%, ', + (100 * f[3]).toPrecision(3), + '%)' + ); + + case 'hsb': + case 'hsv': + if (!this.hsba) this.hsba = color_conversion._rgbaToHSBA(this._array); + return 'hsb('.concat( + this.hsba[0] * this.maxes[constants.HSB][0], + ', ', + this.hsba[1] * this.maxes[constants.HSB][1], + ', ', + this.hsba[2] * this.maxes[constants.HSB][2], + ')' + ); + + case 'hsb%': + case 'hsv%': + if (!this.hsba) this.hsba = color_conversion._rgbaToHSBA(this._array); + return 'hsb('.concat( + (100 * this.hsba[0]).toPrecision(3), + '%, ', + (100 * this.hsba[1]).toPrecision(3), + '%, ', + (100 * this.hsba[2]).toPrecision(3), + '%)' + ); + + case 'hsba': + case 'hsva': + if (!this.hsba) this.hsba = color_conversion._rgbaToHSBA(this._array); + return 'hsba('.concat( + this.hsba[0] * this.maxes[constants.HSB][0], + ', ', + this.hsba[1] * this.maxes[constants.HSB][1], + ', ', + this.hsba[2] * this.maxes[constants.HSB][2], + ', ', + alpha, + ')' + ); + + case 'hsba%': + case 'hsva%': + if (!this.hsba) this.hsba = color_conversion._rgbaToHSBA(this._array); + return 'hsba('.concat( + (100 * this.hsba[0]).toPrecision(3), + '%, ', + (100 * this.hsba[1]).toPrecision(3), + '%, ', + (100 * this.hsba[2]).toPrecision(3), + '%, ', + (100 * alpha).toPrecision(3), + '%)' + ); + + case 'hsl': + if (!this.hsla) this.hsla = color_conversion._rgbaToHSLA(this._array); + return 'hsl('.concat( + this.hsla[0] * this.maxes[constants.HSL][0], + ', ', + this.hsla[1] * this.maxes[constants.HSL][1], + ', ', + this.hsla[2] * this.maxes[constants.HSL][2], + ')' + ); + + case 'hsl%': + if (!this.hsla) this.hsla = color_conversion._rgbaToHSLA(this._array); + return 'hsl('.concat( + (100 * this.hsla[0]).toPrecision(3), + '%, ', + (100 * this.hsla[1]).toPrecision(3), + '%, ', + (100 * this.hsla[2]).toPrecision(3), + '%)' + ); + + case 'hsla': + if (!this.hsla) this.hsla = color_conversion._rgbaToHSLA(this._array); + return 'hsla('.concat( + this.hsla[0] * this.maxes[constants.HSL][0], + ', ', + this.hsla[1] * this.maxes[constants.HSL][1], + ', ', + this.hsla[2] * this.maxes[constants.HSL][2], + ', ', + alpha, + ')' + ); + + case 'hsla%': + if (!this.hsla) this.hsla = color_conversion._rgbaToHSLA(this._array); + return 'hsl('.concat( + (100 * this.hsla[0]).toPrecision(3), + '%, ', + (100 * this.hsla[1]).toPrecision(3), + '%, ', + (100 * this.hsla[2]).toPrecision(3), + '%, ', + (100 * alpha).toPrecision(3), + '%)' + ); + + case 'rgba': + default: + return 'rgba('.concat(a[0], ',', a[1], ',', a[2], ',', alpha, ')'); + } + }; + + /** + * @method setRed + * @param {Number} red the new red value + * @example + *
+ * + * let backgroundColor; + * + * function setup() { + * backgroundColor = color(100, 50, 150); + * } + * + * function draw() { + * backgroundColor.setRed(128 + 128 * sin(millis() / 1000)); + * background(backgroundColor); + * } + * + *
+ * + * @alt + * canvas with gradually changing background color + */ + p5.Color.prototype.setRed = function(new_red) { + this._array[0] = new_red / this.maxes[constants.RGB][0]; + this._calculateLevels(); + }; + + /** + * @method setGreen + * @param {Number} green the new green value + * @example + *
+ * + * let backgroundColor; + * + * function setup() { + * backgroundColor = color(100, 50, 150); + * } + * + * function draw() { + * backgroundColor.setGreen(128 + 128 * sin(millis() / 1000)); + * background(backgroundColor); + * } + * + *
+ * + * @alt + * canvas with gradually changing background color + **/ + p5.Color.prototype.setGreen = function(new_green) { + this._array[1] = new_green / this.maxes[constants.RGB][1]; + this._calculateLevels(); + }; + + /** + * @method setBlue + * @param {Number} blue the new blue value + * @example + *
+ * + * let backgroundColor; + * + * function setup() { + * backgroundColor = color(100, 50, 150); + * } + * + * function draw() { + * backgroundColor.setBlue(128 + 128 * sin(millis() / 1000)); + * background(backgroundColor); + * } + * + *
+ * + * @alt + * canvas with gradually changing background color + **/ + p5.Color.prototype.setBlue = function(new_blue) { + this._array[2] = new_blue / this.maxes[constants.RGB][2]; + this._calculateLevels(); + }; + + /** + * @method setAlpha + * @param {Number} alpha the new alpha value + * @example + *
+ * + * let squareColor; + * + * function setup() { + * ellipseMode(CORNERS); + * strokeWeight(4); + * squareColor = color(100, 50, 150); + * } + * + * function draw() { + * background(255); + * + * noFill(); + * stroke(0); + * ellipse(10, 10, width - 10, height - 10); + * + * squareColor.setAlpha(128 + 128 * sin(millis() / 1000)); + * fill(squareColor); + * noStroke(); + * rect(13, 13, width - 26, height - 26); + * } + * + *
+ * + * @alt + * circle behind a square with gradually changing opacity + **/ + p5.Color.prototype.setAlpha = function(new_alpha) { + this._array[3] = new_alpha / this.maxes[this.mode][3]; + this._calculateLevels(); + }; + + // calculates and stores the closest screen levels + p5.Color.prototype._calculateLevels = function() { + var array = this._array; + // (loop backwards for performance) + var levels = (this.levels = new Array(array.length)); + for (var i = array.length - 1; i >= 0; --i) { + levels[i] = Math.round(array[i] * 255); + } + }; + + p5.Color.prototype._getAlpha = function() { + return this._array[3] * this.maxes[this.mode][3]; + }; + + // stores the color mode and maxes in this instance of Color + // for later use (by _parseInputs()) + p5.Color.prototype._storeModeAndMaxes = function(new_mode, new_maxes) { + this.mode = new_mode; + this.maxes = new_maxes; + }; + + p5.Color.prototype._getMode = function() { + return this.mode; + }; + + p5.Color.prototype._getMaxes = function() { + return this.maxes; + }; + + p5.Color.prototype._getBlue = function() { + return this._array[2] * this.maxes[constants.RGB][2]; + }; + + p5.Color.prototype._getBrightness = function() { + if (!this.hsba) { + this.hsba = color_conversion._rgbaToHSBA(this._array); + } + return this.hsba[2] * this.maxes[constants.HSB][2]; + }; + + p5.Color.prototype._getGreen = function() { + return this._array[1] * this.maxes[constants.RGB][1]; + }; + + /** + * Hue is the same in HSB and HSL, but the maximum value may be different. + * This function will return the HSB-normalized saturation when supplied with + * an HSB color object, but will default to the HSL-normalized saturation + * otherwise. + */ + p5.Color.prototype._getHue = function() { + if (this.mode === constants.HSB) { + if (!this.hsba) { + this.hsba = color_conversion._rgbaToHSBA(this._array); + } + return this.hsba[0] * this.maxes[constants.HSB][0]; + } else { + if (!this.hsla) { + this.hsla = color_conversion._rgbaToHSLA(this._array); + } + return this.hsla[0] * this.maxes[constants.HSL][0]; + } + }; + + p5.Color.prototype._getLightness = function() { + if (!this.hsla) { + this.hsla = color_conversion._rgbaToHSLA(this._array); + } + return this.hsla[2] * this.maxes[constants.HSL][2]; + }; + + p5.Color.prototype._getRed = function() { + return this._array[0] * this.maxes[constants.RGB][0]; + }; + + /** + * Saturation is scaled differently in HSB and HSL. This function will return + * the HSB saturation when supplied with an HSB color object, but will default + * to the HSL saturation otherwise. + */ + p5.Color.prototype._getSaturation = function() { + if (this.mode === constants.HSB) { + if (!this.hsba) { + this.hsba = color_conversion._rgbaToHSBA(this._array); + } + return this.hsba[1] * this.maxes[constants.HSB][1]; + } else { + if (!this.hsla) { + this.hsla = color_conversion._rgbaToHSLA(this._array); + } + return this.hsla[1] * this.maxes[constants.HSL][1]; + } + }; + + /** + * CSS named colors. + */ + var namedColors = { + aliceblue: '#f0f8ff', + antiquewhite: '#faebd7', + aqua: '#00ffff', + aquamarine: '#7fffd4', + azure: '#f0ffff', + beige: '#f5f5dc', + bisque: '#ffe4c4', + black: '#000000', + blanchedalmond: '#ffebcd', + blue: '#0000ff', + blueviolet: '#8a2be2', + brown: '#a52a2a', + burlywood: '#deb887', + cadetblue: '#5f9ea0', + chartreuse: '#7fff00', + chocolate: '#d2691e', + coral: '#ff7f50', + cornflowerblue: '#6495ed', + cornsilk: '#fff8dc', + crimson: '#dc143c', + cyan: '#00ffff', + darkblue: '#00008b', + darkcyan: '#008b8b', + darkgoldenrod: '#b8860b', + darkgray: '#a9a9a9', + darkgreen: '#006400', + darkgrey: '#a9a9a9', + darkkhaki: '#bdb76b', + darkmagenta: '#8b008b', + darkolivegreen: '#556b2f', + darkorange: '#ff8c00', + darkorchid: '#9932cc', + darkred: '#8b0000', + darksalmon: '#e9967a', + darkseagreen: '#8fbc8f', + darkslateblue: '#483d8b', + darkslategray: '#2f4f4f', + darkslategrey: '#2f4f4f', + darkturquoise: '#00ced1', + darkviolet: '#9400d3', + deeppink: '#ff1493', + deepskyblue: '#00bfff', + dimgray: '#696969', + dimgrey: '#696969', + dodgerblue: '#1e90ff', + firebrick: '#b22222', + floralwhite: '#fffaf0', + forestgreen: '#228b22', + fuchsia: '#ff00ff', + gainsboro: '#dcdcdc', + ghostwhite: '#f8f8ff', + gold: '#ffd700', + goldenrod: '#daa520', + gray: '#808080', + green: '#008000', + greenyellow: '#adff2f', + grey: '#808080', + honeydew: '#f0fff0', + hotpink: '#ff69b4', + indianred: '#cd5c5c', + indigo: '#4b0082', + ivory: '#fffff0', + khaki: '#f0e68c', + lavender: '#e6e6fa', + lavenderblush: '#fff0f5', + lawngreen: '#7cfc00', + lemonchiffon: '#fffacd', + lightblue: '#add8e6', + lightcoral: '#f08080', + lightcyan: '#e0ffff', + lightgoldenrodyellow: '#fafad2', + lightgray: '#d3d3d3', + lightgreen: '#90ee90', + lightgrey: '#d3d3d3', + lightpink: '#ffb6c1', + lightsalmon: '#ffa07a', + lightseagreen: '#20b2aa', + lightskyblue: '#87cefa', + lightslategray: '#778899', + lightslategrey: '#778899', + lightsteelblue: '#b0c4de', + lightyellow: '#ffffe0', + lime: '#00ff00', + limegreen: '#32cd32', + linen: '#faf0e6', + magenta: '#ff00ff', + maroon: '#800000', + mediumaquamarine: '#66cdaa', + mediumblue: '#0000cd', + mediumorchid: '#ba55d3', + mediumpurple: '#9370db', + mediumseagreen: '#3cb371', + mediumslateblue: '#7b68ee', + mediumspringgreen: '#00fa9a', + mediumturquoise: '#48d1cc', + mediumvioletred: '#c71585', + midnightblue: '#191970', + mintcream: '#f5fffa', + mistyrose: '#ffe4e1', + moccasin: '#ffe4b5', + navajowhite: '#ffdead', + navy: '#000080', + oldlace: '#fdf5e6', + olive: '#808000', + olivedrab: '#6b8e23', + orange: '#ffa500', + orangered: '#ff4500', + orchid: '#da70d6', + palegoldenrod: '#eee8aa', + palegreen: '#98fb98', + paleturquoise: '#afeeee', + palevioletred: '#db7093', + papayawhip: '#ffefd5', + peachpuff: '#ffdab9', + peru: '#cd853f', + pink: '#ffc0cb', + plum: '#dda0dd', + powderblue: '#b0e0e6', + purple: '#800080', + red: '#ff0000', + rosybrown: '#bc8f8f', + royalblue: '#4169e1', + saddlebrown: '#8b4513', + salmon: '#fa8072', + sandybrown: '#f4a460', + seagreen: '#2e8b57', + seashell: '#fff5ee', + sienna: '#a0522d', + silver: '#c0c0c0', + skyblue: '#87ceeb', + slateblue: '#6a5acd', + slategray: '#708090', + slategrey: '#708090', + snow: '#fffafa', + springgreen: '#00ff7f', + steelblue: '#4682b4', + tan: '#d2b48c', + teal: '#008080', + thistle: '#d8bfd8', + tomato: '#ff6347', + turquoise: '#40e0d0', + violet: '#ee82ee', + wheat: '#f5deb3', + white: '#ffffff', + whitesmoke: '#f5f5f5', + yellow: '#ffff00', + yellowgreen: '#9acd32' + }; + + /** + * These regular expressions are used to build up the patterns for matching + * viable CSS color strings: fragmenting the regexes in this way increases the + * legibility and comprehensibility of the code. + * + * Note that RGB values of .9 are not parsed by IE, but are supported here for + * color string consistency. + */ + var WHITESPACE = /\s*/; // Match zero or more whitespace characters. + var INTEGER = /(\d{1,3})/; // Match integers: 79, 255, etc. + var DECIMAL = /((?:\d+(?:\.\d+)?)|(?:\.\d+))/; // Match 129.6, 79, .9, etc. + var PERCENT = new RegExp(DECIMAL.source + '%'); // Match 12.9%, 79%, .9%, etc. + + /** + * Full color string patterns. The capture groups are necessary. + */ + var colorPatterns = { + // Match colors in format #XXX, e.g. #416. + HEX3: /^#([a-f0-9])([a-f0-9])([a-f0-9])$/i, + + // Match colors in format #XXXX, e.g. #5123. + HEX4: /^#([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])$/i, + + // Match colors in format #XXXXXX, e.g. #b4d455. + HEX6: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i, + + // Match colors in format #XXXXXXXX, e.g. #b4d45535. + HEX8: /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i, + + // Match colors in format rgb(R, G, B), e.g. rgb(255, 0, 128). + RGB: new RegExp( + [ + '^rgb\\(', + INTEGER.source, + ',', + INTEGER.source, + ',', + INTEGER.source, + '\\)$' + ].join(WHITESPACE.source), + 'i' + ), + + // Match colors in format rgb(R%, G%, B%), e.g. rgb(100%, 0%, 28.9%). + RGB_PERCENT: new RegExp( + [ + '^rgb\\(', + PERCENT.source, + ',', + PERCENT.source, + ',', + PERCENT.source, + '\\)$' + ].join(WHITESPACE.source), + 'i' + ), + + // Match colors in format rgb(R, G, B, A), e.g. rgb(255, 0, 128, 0.25). + RGBA: new RegExp( + [ + '^rgba\\(', + INTEGER.source, + ',', + INTEGER.source, + ',', + INTEGER.source, + ',', + DECIMAL.source, + '\\)$' + ].join(WHITESPACE.source), + 'i' + ), + + // Match colors in format rgb(R%, G%, B%, A), e.g. rgb(100%, 0%, 28.9%, 0.5). + RGBA_PERCENT: new RegExp( + [ + '^rgba\\(', + PERCENT.source, + ',', + PERCENT.source, + ',', + PERCENT.source, + ',', + DECIMAL.source, + '\\)$' + ].join(WHITESPACE.source), + 'i' + ), + + // Match colors in format hsla(H, S%, L%), e.g. hsl(100, 40%, 28.9%). + HSL: new RegExp( + [ + '^hsl\\(', + INTEGER.source, + ',', + PERCENT.source, + ',', + PERCENT.source, + '\\)$' + ].join(WHITESPACE.source), + 'i' + ), + + // Match colors in format hsla(H, S%, L%, A), e.g. hsla(100, 40%, 28.9%, 0.5). + HSLA: new RegExp( + [ + '^hsla\\(', + INTEGER.source, + ',', + PERCENT.source, + ',', + PERCENT.source, + ',', + DECIMAL.source, + '\\)$' + ].join(WHITESPACE.source), + 'i' + ), + + // Match colors in format hsb(H, S%, B%), e.g. hsb(100, 40%, 28.9%). + HSB: new RegExp( + [ + '^hsb\\(', + INTEGER.source, + ',', + PERCENT.source, + ',', + PERCENT.source, + '\\)$' + ].join(WHITESPACE.source), + 'i' + ), + + // Match colors in format hsba(H, S%, B%, A), e.g. hsba(100, 40%, 28.9%, 0.5). + HSBA: new RegExp( + [ + '^hsba\\(', + INTEGER.source, + ',', + PERCENT.source, + ',', + PERCENT.source, + ',', + DECIMAL.source, + '\\)$' + ].join(WHITESPACE.source), + 'i' + ) + }; + + /** + * For a number of different inputs, returns a color formatted as [r, g, b, a] + * arrays, with each component normalized between 0 and 1. + * + * @private + * @param {Array} [...args] An 'array-like' object that represents a list of + * arguments + * @return {Number[]} a color formatted as [r, g, b, a] + * Example: + * input ==> output + * g ==> [g, g, g, 255] + * g,a ==> [g, g, g, a] + * r, g, b ==> [r, g, b, 255] + * r, g, b, a ==> [r, g, b, a] + * [g] ==> [g, g, g, 255] + * [g, a] ==> [g, g, g, a] + * [r, g, b] ==> [r, g, b, 255] + * [r, g, b, a] ==> [r, g, b, a] + * @example + *
+ * + * // todo + * + *
+ * + * @alt + * //todo + * + */ + p5.Color._parseInputs = function(r, g, b, a) { + var numArgs = arguments.length; + var mode = this.mode; + var maxes = this.maxes[mode]; + var results = []; + var i; + + if (numArgs >= 3) { + // Argument is a list of component values. + + results[0] = r / maxes[0]; + results[1] = g / maxes[1]; + results[2] = b / maxes[2]; + + // Alpha may be undefined, so default it to 100%. + if (typeof a === 'number') { + results[3] = a / maxes[3]; + } else { + results[3] = 1; + } + + // Constrain components to the range [0,1]. + // (loop backwards for performance) + for (i = results.length - 1; i >= 0; --i) { + var result = results[i]; + if (result < 0) { + results[i] = 0; + } else if (result > 1) { + results[i] = 1; + } + } + + // Convert to RGBA and return. + if (mode === constants.HSL) { + return color_conversion._hslaToRGBA(results); + } else if (mode === constants.HSB) { + return color_conversion._hsbaToRGBA(results); + } else { + return results; + } + } else if (numArgs === 1 && typeof r === 'string') { + var str = r.trim().toLowerCase(); + + // Return if string is a named colour. + if (namedColors[str]) { + return p5.Color._parseInputs.call(this, namedColors[str]); + } + + // Try RGBA pattern matching. + if (colorPatterns.HEX3.test(str)) { + // #rgb + results = colorPatterns.HEX3.exec(str) + .slice(1) + .map(function(color) { + return parseInt(color + color, 16) / 255; + }); + results[3] = 1; + return results; + } else if (colorPatterns.HEX6.test(str)) { + // #rrggbb + results = colorPatterns.HEX6.exec(str) + .slice(1) + .map(function(color) { + return parseInt(color, 16) / 255; + }); + results[3] = 1; + return results; + } else if (colorPatterns.HEX4.test(str)) { + // #rgba + results = colorPatterns.HEX4.exec(str) + .slice(1) + .map(function(color) { + return parseInt(color + color, 16) / 255; + }); + return results; + } else if (colorPatterns.HEX8.test(str)) { + // #rrggbbaa + results = colorPatterns.HEX8.exec(str) + .slice(1) + .map(function(color) { + return parseInt(color, 16) / 255; + }); + return results; + } else if (colorPatterns.RGB.test(str)) { + // rgb(R,G,B) + results = colorPatterns.RGB.exec(str) + .slice(1) + .map(function(color) { + return color / 255; + }); + results[3] = 1; + return results; + } else if (colorPatterns.RGB_PERCENT.test(str)) { + // rgb(R%,G%,B%) + results = colorPatterns.RGB_PERCENT.exec(str) + .slice(1) + .map(function(color) { + return parseFloat(color) / 100; + }); + results[3] = 1; + return results; + } else if (colorPatterns.RGBA.test(str)) { + // rgba(R,G,B,A) + results = colorPatterns.RGBA.exec(str) + .slice(1) + .map(function(color, idx) { + if (idx === 3) { + return parseFloat(color); + } + return color / 255; + }); + return results; + } else if (colorPatterns.RGBA_PERCENT.test(str)) { + // rgba(R%,G%,B%,A%) + results = colorPatterns.RGBA_PERCENT.exec(str) + .slice(1) + .map(function(color, idx) { + if (idx === 3) { + return parseFloat(color); + } + return parseFloat(color) / 100; + }); + return results; + } + + // Try HSLA pattern matching. + if (colorPatterns.HSL.test(str)) { + // hsl(H,S,L) + results = colorPatterns.HSL.exec(str) + .slice(1) + .map(function(color, idx) { + if (idx === 0) { + return parseInt(color, 10) / 360; + } + return parseInt(color, 10) / 100; + }); + results[3] = 1; + } else if (colorPatterns.HSLA.test(str)) { + // hsla(H,S,L,A) + results = colorPatterns.HSLA.exec(str) + .slice(1) + .map(function(color, idx) { + if (idx === 0) { + return parseInt(color, 10) / 360; + } else if (idx === 3) { + return parseFloat(color); + } + return parseInt(color, 10) / 100; + }); + } + results = results.map(function(value) { + return Math.max(Math.min(value, 1), 0); + }); + if (results.length) { + return color_conversion._hslaToRGBA(results); + } + + // Try HSBA pattern matching. + if (colorPatterns.HSB.test(str)) { + // hsb(H,S,B) + results = colorPatterns.HSB.exec(str) + .slice(1) + .map(function(color, idx) { + if (idx === 0) { + return parseInt(color, 10) / 360; + } + return parseInt(color, 10) / 100; + }); + results[3] = 1; + } else if (colorPatterns.HSBA.test(str)) { + // hsba(H,S,B,A) + results = colorPatterns.HSBA.exec(str) + .slice(1) + .map(function(color, idx) { + if (idx === 0) { + return parseInt(color, 10) / 360; + } else if (idx === 3) { + return parseFloat(color); + } + return parseInt(color, 10) / 100; + }); + } + + if (results.length) { + // (loop backwards for performance) + for (i = results.length - 1; i >= 0; --i) { + results[i] = Math.max(Math.min(results[i], 1), 0); + } + + return color_conversion._hsbaToRGBA(results); + } + + // Input did not match any CSS color pattern: default to white. + results = [1, 1, 1, 1]; + } else if ((numArgs === 1 || numArgs === 2) && typeof r === 'number') { + // 'Grayscale' mode. + + /** + * For HSB and HSL, interpret the gray level as a brightness/lightness + * value (they are equivalent when chroma is zero). For RGB, normalize the + * gray level according to the blue maximum. + */ + results[0] = r / maxes[2]; + results[1] = r / maxes[2]; + results[2] = r / maxes[2]; + + // Alpha may be undefined, so default it to 100%. + if (typeof g === 'number') { + results[3] = g / maxes[3]; + } else { + results[3] = 1; + } + + // Constrain components to the range [0,1]. + results = results.map(function(value) { + return Math.max(Math.min(value, 1), 0); + }); + } else { + throw new Error(arguments + 'is not a valid color representation.'); + } + + return results; + }; + + module.exports = p5.Color; + }, + { '../core/constants': 18, '../core/main': 24, './color_conversion': 14 } + ], + 17: [ + function(_dereq_, module, exports) { + /** + * @module Color + * @submodule Setting + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + _dereq_('./p5.Color'); + + /** + * The background() function sets the color used for the background of the + * p5.js canvas. The default background is transparent. This function is + * typically used within draw() to clear the display window at the beginning + * of each frame, but it can be used inside setup() to set the background on + * the first frame of animation or if the background need only be set once. + *

+ * The color is either specified in terms of the RGB, HSB, or HSL color + * depending on the current colorMode. (The default color space is RGB, with + * each value in the range from 0 to 255). The alpha range by default is also 0 to 255. + *

+ * If a single string argument is provided, RGB, RGBA and Hex CSS color strings + * and all named color strings are supported. In this case, an alpha number + * value as a second argument is not supported, the RGBA form should be used. + *

+ * A p5.Color object can also be provided to set the background color. + *

+ * A p5.Image can also be provided to set the background image. + * + * @method background + * @param {p5.Color} color any value created by the color() function + * @chainable + * + * @example + *
+ * + * // Grayscale integer value + * background(51); + * + *
+ * + *
+ * + * // R, G & B integer values + * background(255, 204, 0); + * + *
+ * + *
+ * + * // H, S & B integer values + * colorMode(HSB); + * background(255, 204, 100); + * + *
+ * + *
+ * + * // Named SVG/CSS color string + * background('red'); + * + *
+ * + *
+ * + * // three-digit hexadecimal RGB notation + * background('#fae'); + * + *
+ * + *
+ * + * // six-digit hexadecimal RGB notation + * background('#222222'); + * + *
+ * + *
+ * + * // integer RGB notation + * background('rgb(0,255,0)'); + * + *
+ * + *
+ * + * // integer RGBA notation + * background('rgba(0,255,0, 0.25)'); + * + *
+ * + *
+ * + * // percentage RGB notation + * background('rgb(100%,0%,10%)'); + * + *
+ * + *
+ * + * // percentage RGBA notation + * background('rgba(100%,0%,100%,0.5)'); + * + *
+ * + *
+ * + * // p5 Color object + * background(color(0, 0, 255)); + * + *
+ * + * @alt + * canvas with darkest charcoal grey background. + * canvas with yellow background. + * canvas with royal blue background. + * canvas with red background. + * canvas with pink background. + * canvas with black background. + * canvas with bright green background. + * canvas with soft green background. + * canvas with red background. + * canvas with light purple background. + * canvas with blue background. + */ + + /** + * @method background + * @param {String} colorstring color string, possible formats include: integer + * rgb() or rgba(), percentage rgb() or rgba(), + * 3-digit hex, 6-digit hex + * @param {Number} [a] opacity of the background relative to current + * color range (default is 0-255) + * @chainable + */ + + /** + * @method background + * @param {Number} gray specifies a value between white and black + * @param {Number} [a] + * @chainable + */ + + /** + * @method background + * @param {Number} v1 red or hue value (depending on the current color + * mode) + * @param {Number} v2 green or saturation value (depending on the current + * color mode) + * @param {Number} v3 blue or brightness value (depending on the current + * color mode) + * @param {Number} [a] + * @chainable + */ + + /** + * @method background + * @param {Number[]} values an array containing the red, green, blue + * and alpha components of the color + * @chainable + */ + + /** + * @method background + * @param {p5.Image} image image created with loadImage() or createImage(), + * to set as background + * (must be same size as the sketch window) + * @param {Number} [a] + * @chainable + */ + + p5.prototype.background = function() { + this._renderer.background.apply(this._renderer, arguments); + return this; + }; + + /** + * Clears the pixels within a buffer. This function only clears the canvas. + * It will not clear objects created by createX() methods such as + * createVideo() or createDiv(). + * Unlike the main graphics context, pixels in additional graphics areas created + * with createGraphics() can be entirely + * or partially transparent. This function clears everything to make all of + * the pixels 100% transparent. + * + * @method clear + * @chainable + * @example + *
+ * + * // Clear the screen on mouse press. + * function setup() { + * createCanvas(100, 100); + * } + * + * function draw() { + * ellipse(mouseX, mouseY, 20, 20); + * } + * + * function mousePressed() { + * clear(); + * } + * + *
+ * + * @alt + * 20x20 white ellipses are continually drawn at mouse x and y coordinates. + * + */ + + p5.prototype.clear = function() { + this._renderer.clear(); + return this; + }; + + /** + * colorMode() changes the way p5.js interprets color data. By default, the + * parameters for fill(), stroke(), background(), and color() are defined by + * values between 0 and 255 using the RGB color model. This is equivalent to + * setting colorMode(RGB, 255). Setting colorMode(HSB) lets you use the HSB + * system instead. By default, this is colorMode(HSB, 360, 100, 100, 1). You + * can also use HSL. + *

+ * Note: existing color objects remember the mode that they were created in, + * so you can change modes as you like without affecting their appearance. + * + * + * @method colorMode + * @param {Constant} mode either RGB, HSB or HSL, corresponding to + * Red/Green/Blue and Hue/Saturation/Brightness + * (or Lightness) + * @param {Number} [max] range for all values + * @chainable + * + * @example + *
+ * + * noStroke(); + * colorMode(RGB, 100); + * for (let i = 0; i < 100; i++) { + * for (let j = 0; j < 100; j++) { + * stroke(i, j, 0); + * point(i, j); + * } + * } + * + *
+ * + *
+ * + * noStroke(); + * colorMode(HSB, 100); + * for (let i = 0; i < 100; i++) { + * for (let j = 0; j < 100; j++) { + * stroke(i, j, 100); + * point(i, j); + * } + * } + * + *
+ * + *
+ * + * colorMode(RGB, 255); + * let c = color(127, 255, 0); + * + * colorMode(RGB, 1); + * let myColor = c._getRed(); + * text(myColor, 10, 10, 80, 80); + * + *
+ * + *
+ * + * noFill(); + * colorMode(RGB, 255, 255, 255, 1); + * background(255); + * + * strokeWeight(4); + * stroke(255, 0, 10, 0.3); + * ellipse(40, 40, 50, 50); + * ellipse(50, 50, 40, 40); + * + *
+ * + * @alt + *Green to red gradient from bottom L to top R. shading originates from top left. + *Rainbow gradient from left to right. Brightness increasing to white at top. + *unknown image. + *50x50 ellipse at middle L & 40x40 ellipse at center. Translucent pink outlines. + * + */ + /** + * @method colorMode + * @param {Constant} mode + * @param {Number} max1 range for the red or hue depending on the + * current color mode + * @param {Number} max2 range for the green or saturation depending + * on the current color mode + * @param {Number} max3 range for the blue or brightness/lightness + * depending on the current color mode + * @param {Number} [maxA] range for the alpha + * @chainable + */ + p5.prototype.colorMode = function(mode, max1, max2, max3, maxA) { + p5._validateParameters('colorMode', arguments); + if ( + mode === constants.RGB || + mode === constants.HSB || + mode === constants.HSL + ) { + // Set color mode. + this._colorMode = mode; + + // Set color maxes. + var maxes = this._colorMaxes[mode]; + if (arguments.length === 2) { + maxes[0] = max1; // Red + maxes[1] = max1; // Green + maxes[2] = max1; // Blue + maxes[3] = max1; // Alpha + } else if (arguments.length === 4) { + maxes[0] = max1; // Red + maxes[1] = max2; // Green + maxes[2] = max3; // Blue + } else if (arguments.length === 5) { + maxes[0] = max1; // Red + maxes[1] = max2; // Green + maxes[2] = max3; // Blue + maxes[3] = maxA; // Alpha + } + } + + return this; + }; + + /** + * Sets the color used to fill shapes. For example, if you run + * fill(204, 102, 0), all shapes drawn after the fill command will be filled with the color orange. This + * color is either specified in terms of the RGB or HSB color depending on + * the current colorMode(). (The default color space is RGB, with each value + * in the range from 0 to 255). The alpha range by default is also 0 to 255. + *

+ * If a single string argument is provided, RGB, RGBA and Hex CSS color strings + * and all named color strings are supported. In this case, an alpha number + * value as a second argument is not supported, the RGBA form should be used. + *

+ * A p5 Color object can also be provided to set the fill color. + * + * @method fill + * @param {Number} v1 red or hue value relative to + * the current color range + * @param {Number} v2 green or saturation value + * relative to the current color range + * @param {Number} v3 blue or brightness value + * relative to the current color range + * @param {Number} [alpha] + * @chainable + * @example + *
+ * + * // Grayscale integer value + * fill(51); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // R, G & B integer values + * fill(255, 204, 0); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // H, S & B integer values + * colorMode(HSB); + * fill(255, 204, 100); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // Named SVG/CSS color string + * fill('red'); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // three-digit hexadecimal RGB notation + * fill('#fae'); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // six-digit hexadecimal RGB notation + * fill('#222222'); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // integer RGB notation + * fill('rgb(0,255,0)'); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // integer RGBA notation + * fill('rgba(0,255,0, 0.25)'); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // percentage RGB notation + * fill('rgb(100%,0%,10%)'); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // percentage RGBA notation + * fill('rgba(100%,0%,100%,0.5)'); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // p5 Color object + * fill(color(0, 0, 255)); + * rect(20, 20, 60, 60); + * + *
+ * @alt + * 60x60 dark charcoal grey rect with black outline in center of canvas. + * 60x60 yellow rect with black outline in center of canvas. + * 60x60 royal blue rect with black outline in center of canvas. + * 60x60 red rect with black outline in center of canvas. + * 60x60 pink rect with black outline in center of canvas. + * 60x60 black rect with black outline in center of canvas. + * 60x60 light green rect with black outline in center of canvas. + * 60x60 soft green rect with black outline in center of canvas. + * 60x60 red rect with black outline in center of canvas. + * 60x60 dark fuchsia rect with black outline in center of canvas. + * 60x60 blue rect with black outline in center of canvas. + */ + + /** + * @method fill + * @param {String} value a color string + * @chainable + */ + + /** + * @method fill + * @param {Number} gray a gray value + * @param {Number} [alpha] + * @chainable + */ + + /** + * @method fill + * @param {Number[]} values an array containing the red,green,blue & + * and alpha components of the color + * @chainable + */ + + /** + * @method fill + * @param {p5.Color} color the fill color + * @chainable + */ + p5.prototype.fill = function() { + this._renderer._setProperty('_fillSet', true); + this._renderer._setProperty('_doFill', true); + this._renderer.fill.apply(this._renderer, arguments); + return this; + }; + + /** + * Disables filling geometry. If both noStroke() and noFill() are called, + * nothing will be drawn to the screen. + * + * @method noFill + * @chainable + * @example + *
+ * + * rect(15, 10, 55, 55); + * noFill(); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(0); + * noFill(); + * stroke(100, 100, 240); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * box(45, 45, 45); + * } + * + *
+ * + * @alt + * white rect top middle and noFill rect center. Both 60x60 with black outlines. + * black canvas with purple cube wireframe spinning + */ + p5.prototype.noFill = function() { + this._renderer._setProperty('_doFill', false); + return this; + }; + + /** + * Disables drawing the stroke (outline). If both noStroke() and noFill() + * are called, nothing will be drawn to the screen. + * + * @method noStroke + * @chainable + * @example + *
+ * + * noStroke(); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(0); + * noStroke(); + * fill(240, 150, 150); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * box(45, 45, 45); + * } + * + *
+ * + * @alt + * 60x60 white rect at center. no outline. + * black canvas with pink cube spinning + */ + p5.prototype.noStroke = function() { + this._renderer._setProperty('_doStroke', false); + return this; + }; + + /** + * Sets the color used to draw lines and borders around shapes. This color + * is either specified in terms of the RGB or HSB color depending on the + * current colorMode() (the default color space is RGB, with each value in + * the range from 0 to 255). The alpha range by default is also 0 to 255. + *

+ * If a single string argument is provided, RGB, RGBA and Hex CSS color + * strings and all named color strings are supported. In this case, an alpha + * number value as a second argument is not supported, the RGBA form should be + * used. + *

+ * A p5 Color object can also be provided to set the stroke color. + * + * + * @method stroke + * @param {Number} v1 red or hue value relative to + * the current color range + * @param {Number} v2 green or saturation value + * relative to the current color range + * @param {Number} v3 blue or brightness value + * relative to the current color range + * @param {Number} [alpha] + * @chainable + * + * @example + *
+ * + * // Grayscale integer value + * strokeWeight(4); + * stroke(51); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // R, G & B integer values + * stroke(255, 204, 0); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // H, S & B integer values + * colorMode(HSB); + * strokeWeight(4); + * stroke(255, 204, 100); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // Named SVG/CSS color string + * stroke('red'); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // three-digit hexadecimal RGB notation + * stroke('#fae'); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // six-digit hexadecimal RGB notation + * stroke('#222222'); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // integer RGB notation + * stroke('rgb(0,255,0)'); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // integer RGBA notation + * stroke('rgba(0,255,0,0.25)'); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // percentage RGB notation + * stroke('rgb(100%,0%,10%)'); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // percentage RGBA notation + * stroke('rgba(100%,0%,100%,0.5)'); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + *
+ * + * // p5 Color object + * stroke(color(0, 0, 255)); + * strokeWeight(4); + * rect(20, 20, 60, 60); + * + *
+ * + * @alt + * 60x60 white rect at center. Dark charcoal grey outline. + * 60x60 white rect at center. Yellow outline. + * 60x60 white rect at center. Royal blue outline. + * 60x60 white rect at center. Red outline. + * 60x60 white rect at center. Pink outline. + * 60x60 white rect at center. Black outline. + * 60x60 white rect at center. Bright green outline. + * 60x60 white rect at center. Soft green outline. + * 60x60 white rect at center. Red outline. + * 60x60 white rect at center. Dark fuchsia outline. + * 60x60 white rect at center. Blue outline. + */ + + /** + * @method stroke + * @param {String} value a color string + * @chainable + */ + + /** + * @method stroke + * @param {Number} gray a gray value + * @param {Number} [alpha] + * @chainable + */ + + /** + * @method stroke + * @param {Number[]} values an array containing the red,green,blue & + * and alpha components of the color + * @chainable + */ + + /** + * @method stroke + * @param {p5.Color} color the stroke color + * @chainable + */ + + p5.prototype.stroke = function() { + this._renderer._setProperty('_strokeSet', true); + this._renderer._setProperty('_doStroke', true); + this._renderer.stroke.apply(this._renderer, arguments); + return this; + }; + + module.exports = p5; + }, + { '../core/constants': 18, '../core/main': 24, './p5.Color': 16 } + ], + 18: [ + function(_dereq_, module, exports) { + /** + * @module Constants + * @submodule Constants + * @for p5 + */ + + 'use strict'; + + var PI = Math.PI; + + module.exports = { + // GRAPHICS RENDERER + /** + * The default, two-dimensional renderer. + * @property {String} P2D + * @final + */ + P2D: 'p2d', + /** + * One of the two render modes in p5.js: P2D (default renderer) and WEBGL + * Enables 3D render by introducing the third dimension: Z + * @property {String} WEBGL + * @final + */ + WEBGL: 'webgl', + + // ENVIRONMENT + /** + * @property {String} ARROW + * @final + */ + ARROW: 'default', + /** + * @property {String} CROSS + * @final + */ + CROSS: 'crosshair', + /** + * @property {String} HAND + * @final + */ + HAND: 'pointer', + /** + * @property {String} MOVE + * @final + */ + MOVE: 'move', + /** + * @property {String} TEXT + * @final + */ + TEXT: 'text', + /** + * @property {String} WAIT + * @final + */ + WAIT: 'wait', + + // TRIGONOMETRY + + /** + * HALF_PI is a mathematical constant with the value + * 1.57079632679489661923. It is half the ratio of the + * circumference of a circle to its diameter. It is useful in + * combination with the trigonometric functions sin() and cos(). + * + * @property {Number} HALF_PI + * @final + * + * @example + *
+ * arc(50, 50, 80, 80, 0, HALF_PI); + *
+ * + * @alt + * 80x80 white quarter-circle with curve toward bottom right of canvas. + * + */ + HALF_PI: PI / 2, + /** + * PI is a mathematical constant with the value + * 3.14159265358979323846. It is the ratio of the circumference + * of a circle to its diameter. It is useful in combination with + * the trigonometric functions sin() and cos(). + * + * @property {Number} PI + * @final + * + * @example + *
+ * arc(50, 50, 80, 80, 0, PI); + *
+ * + * @alt + * white half-circle with curve toward bottom of canvas. + * + */ + PI: PI, + /** + * QUARTER_PI is a mathematical constant with the value 0.7853982. + * It is one quarter the ratio of the circumference of a circle to + * its diameter. It is useful in combination with the trigonometric + * functions sin() and cos(). + * + * @property {Number} QUARTER_PI + * @final + * + * @example + *
+ * arc(50, 50, 80, 80, 0, QUARTER_PI); + *
+ * + * @alt + * white eighth-circle rotated about 40 degrees with curve bottom right canvas. + * + */ + QUARTER_PI: PI / 4, + /** + * TAU is an alias for TWO_PI, a mathematical constant with the + * value 6.28318530717958647693. It is twice the ratio of the + * circumference of a circle to its diameter. It is useful in + * combination with the trigonometric functions sin() and cos(). + * + * @property {Number} TAU + * @final + * + * @example + *
+ * arc(50, 50, 80, 80, 0, TAU); + *
+ * + * @alt + * 80x80 white ellipse shape in center of canvas. + * + */ + TAU: PI * 2, + /** + * TWO_PI is a mathematical constant with the value + * 6.28318530717958647693. It is twice the ratio of the + * circumference of a circle to its diameter. It is useful in + * combination with the trigonometric functions sin() and cos(). + * + * @property {Number} TWO_PI + * @final + * + * @example + *
+ * arc(50, 50, 80, 80, 0, TWO_PI); + *
+ * + * @alt + * 80x80 white ellipse shape in center of canvas. + * + */ + TWO_PI: PI * 2, + /** + * Constant to be used with angleMode() function, to set the mode which + * p5.js interprates and calculates angles (either DEGREES or RADIANS). + * @property {String} DEGREES + * @final + * + * @example + *
+ * function setup() { + * angleMode(DEGREES); + * } + *
+ */ + DEGREES: 'degrees', + /** + * Constant to be used with angleMode() function, to set the mode which + * p5.js interprates and calculates angles (either RADIANS or DEGREES). + * @property {String} RADIANS + * @final + * + * @example + *
+ * function setup() { + * angleMode(RADIANS); + * } + *
+ */ + RADIANS: 'radians', + DEG_TO_RAD: PI / 180.0, + RAD_TO_DEG: 180.0 / PI, + + // SHAPE + /** + * @property {String} CORNER + * @final + */ + CORNER: 'corner', + /** + * @property {String} CORNERS + * @final + */ + CORNERS: 'corners', + /** + * @property {String} RADIUS + * @final + */ + RADIUS: 'radius', + /** + * @property {String} RIGHT + * @final + */ + RIGHT: 'right', + /** + * @property {String} LEFT + * @final + */ + LEFT: 'left', + /** + * @property {String} CENTER + * @final + */ + CENTER: 'center', + /** + * @property {String} TOP + * @final + */ + TOP: 'top', + /** + * @property {String} BOTTOM + * @final + */ + BOTTOM: 'bottom', + /** + * @property {String} BASELINE + * @final + * @default alphabetic + */ + BASELINE: 'alphabetic', + /** + * @property {Number} POINTS + * @final + * @default 0x0000 + */ + POINTS: 0x0000, + /** + * @property {Number} LINES + * @final + * @default 0x0001 + */ + LINES: 0x0001, + /** + * @property {Number} LINE_STRIP + * @final + * @default 0x0003 + */ + LINE_STRIP: 0x0003, + /** + * @property {Number} LINE_LOOP + * @final + * @default 0x0002 + */ + LINE_LOOP: 0x0002, + /** + * @property {Number} TRIANGLES + * @final + * @default 0x0004 + */ + TRIANGLES: 0x0004, + /** + * @property {Number} TRIANGLE_FAN + * @final + * @default 0x0006 + */ + TRIANGLE_FAN: 0x0006, + /** + * @property {Number} TRIANGLE_STRIP + * @final + * @default 0x0005 + */ + TRIANGLE_STRIP: 0x0005, + /** + * @property {String} QUADS + * @final + */ + QUADS: 'quads', + /** + * @property {String} QUAD_STRIP + * @final + * @default quad_strip + */ + QUAD_STRIP: 'quad_strip', + /** + * @property {String} CLOSE + * @final + */ + CLOSE: 'close', + /** + * @property {String} OPEN + * @final + */ + OPEN: 'open', + /** + * @property {String} CHORD + * @final + */ + CHORD: 'chord', + /** + * @property {String} PIE + * @final + */ + PIE: 'pie', + /** + * @property {String} PROJECT + * @final + * @default square + */ + PROJECT: 'square', // PEND: careful this is counterintuitive + /** + * @property {String} SQUARE + * @final + * @default butt + */ + SQUARE: 'butt', + /** + * @property {String} ROUND + * @final + */ + ROUND: 'round', + /** + * @property {String} BEVEL + * @final + */ + BEVEL: 'bevel', + /** + * @property {String} MITER + * @final + */ + MITER: 'miter', + + // COLOR + /** + * @property {String} RGB + * @final + */ + RGB: 'rgb', + /** + * @property {String} HSB + * @final + */ + HSB: 'hsb', + /** + * @property {String} HSL + * @final + */ + HSL: 'hsl', + + // DOM EXTENSION + /** + * AUTO allows us to automatically set the width or height of an element (but not both), + * based on the current height and width of the element. Only one parameter can + * be passed to the size function as AUTO, at a time. + * + * @property {String} AUTO + * @final + */ + AUTO: 'auto', + + // INPUT + ALT: 18, + BACKSPACE: 8, + CONTROL: 17, + DELETE: 46, + DOWN_ARROW: 40, + ENTER: 13, + ESCAPE: 27, + LEFT_ARROW: 37, + OPTION: 18, + RETURN: 13, + RIGHT_ARROW: 39, + SHIFT: 16, + TAB: 9, + UP_ARROW: 38, + + // RENDERING + /** + * @property {String} BLEND + * @final + * @default source-over + */ + BLEND: 'source-over', + /** + * @property {String} ADD + * @final + * @default lighter + */ + ADD: 'lighter', + //ADD: 'add', // + //SUBTRACT: 'subtract', // + /** + * @property {String} DARKEST + * @final + */ + DARKEST: 'darken', + /** + * @property {String} LIGHTEST + * @final + * @default lighten + */ + LIGHTEST: 'lighten', + /** + * @property {String} DIFFERENCE + * @final + */ + DIFFERENCE: 'difference', + /** + * @property {String} SUBTRACT + * @final + */ + SUBTRACT: 'subtract', + /** + * @property {String} EXCLUSION + * @final + */ + EXCLUSION: 'exclusion', + /** + * @property {String} MULTIPLY + * @final + */ + MULTIPLY: 'multiply', + /** + * @property {String} SCREEN + * @final + */ + SCREEN: 'screen', + /** + * @property {String} REPLACE + * @final + * @default copy + */ + REPLACE: 'copy', + /** + * @property {String} OVERLAY + * @final + */ + OVERLAY: 'overlay', + /** + * @property {String} HARD_LIGHT + * @final + */ + HARD_LIGHT: 'hard-light', + /** + * @property {String} SOFT_LIGHT + * @final + */ + SOFT_LIGHT: 'soft-light', + /** + * @property {String} DODGE + * @final + * @default color-dodge + */ + DODGE: 'color-dodge', + /** + * @property {String} BURN + * @final + * @default color-burn + */ + BURN: 'color-burn', + + // FILTERS + /** + * @property {String} THRESHOLD + * @final + */ + THRESHOLD: 'threshold', + /** + * @property {String} GRAY + * @final + */ + GRAY: 'gray', + /** + * @property {String} OPAQUE + * @final + */ + OPAQUE: 'opaque', + /** + * @property {String} INVERT + * @final + */ + INVERT: 'invert', + /** + * @property {String} POSTERIZE + * @final + */ + POSTERIZE: 'posterize', + /** + * @property {String} DILATE + * @final + */ + DILATE: 'dilate', + /** + * @property {String} ERODE + * @final + */ + ERODE: 'erode', + /** + * @property {String} BLUR + * @final + */ + BLUR: 'blur', + + // TYPOGRAPHY + /** + * @property {String} NORMAL + * @final + */ + NORMAL: 'normal', + /** + * @property {String} ITALIC + * @final + */ + ITALIC: 'italic', + /** + * @property {String} BOLD + * @final + */ + BOLD: 'bold', + /** + * @property {String} BOLDITALIC + * @final + */ + BOLDITALIC: 'bold italic', + + // TYPOGRAPHY-INTERNAL + _DEFAULT_TEXT_FILL: '#000000', + _DEFAULT_LEADMULT: 1.25, + _CTX_MIDDLE: 'middle', + + // VERTICES + LINEAR: 'linear', + QUADRATIC: 'quadratic', + BEZIER: 'bezier', + CURVE: 'curve', + + // WEBGL DRAWMODES + STROKE: 'stroke', + FILL: 'fill', + TEXTURE: 'texture', + IMMEDIATE: 'immediate', + + // WEBGL TEXTURE MODE + // NORMAL already exists for typography + /** + * @property {String} IMAGE + * @final + */ + IMAGE: 'image', + + // WEBGL TEXTURE WRAP AND FILTERING + // LINEAR already exists above + NEAREST: 'nearest', + REPEAT: 'repeat', + CLAMP: 'clamp', + MIRROR: 'mirror', + + // DEVICE-ORIENTATION + /** + * @property {String} LANDSCAPE + * @final + */ + LANDSCAPE: 'landscape', + /** + * @property {String} PORTRAIT + * @final + */ + PORTRAIT: 'portrait', + + // DEFAULTS + _DEFAULT_STROKE: '#000000', + _DEFAULT_FILL: '#FFFFFF', + + /** + * @property {String} GRID + * @final + */ + GRID: 'grid', + + /** + * @property {String} AXES + * @final + */ + AXES: 'axes' + }; + }, + {} + ], + 19: [ + function(_dereq_, module, exports) { + /** + * @module Environment + * @submodule Environment + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('./main'); + var C = _dereq_('./constants'); + + var standardCursors = [C.ARROW, C.CROSS, C.HAND, C.MOVE, C.TEXT, C.WAIT]; + + p5.prototype._frameRate = 0; + p5.prototype._lastFrameTime = window.performance.now(); + p5.prototype._targetFrameRate = 60; + + var _windowPrint = window.print; + + /** + * The print() function writes to the console area of your browser. + * This function is often helpful for looking at the data a program is + * producing. This function creates a new line of text for each call to + * the function. Individual elements can be + * separated with quotes ("") and joined with the addition operator (+). + * + * Note that calling print() without any arguments invokes the window.print() + * function which opens the browser's print dialog. To print a blank line + * to console you can write print('\n'). + * + * @method print + * @param {Any} contents any combination of Number, String, Object, Boolean, + * Array to print + * @example + *
+ * let x = 10; + * print('The value of x is ' + x); + * // prints "The value of x is 10" + *
+ * @alt + * default grey canvas + */ + p5.prototype.print = function() { + if (!arguments.length) { + _windowPrint(); + } else { + console.log.apply(console, arguments); + } + }; + + /** + * The system variable frameCount contains the number of frames that have + * been displayed since the program started. Inside setup() the value is 0, + * after the first iteration of draw it is 1, etc. + * + * @property {Integer} frameCount + * @readOnly + * @example + *
+ * function setup() { + * frameRate(30); + * textSize(30); + * textAlign(CENTER); + * } + * + * function draw() { + * background(200); + * text(frameCount, width / 2, height / 2); + * } +
+ * + * @alt + * numbers rapidly counting upward with frame count set to 30. + * + */ + p5.prototype.frameCount = 0; + + /** + * The system variable deltaTime contains the time + * difference between the beginning of the previous frame and the beginning + * of the current frame in milliseconds. + *

+ * This variable is useful for creating time sensitive animation or physics + * calculation that should stay constant regardless of frame rate. + * + * @property {Integer} deltaTime + * @readOnly + * @example + *
+ * let rectX = 0; + * let fr = 30; //starting FPS + * let clr; + * + * function setup() { + * background(200); + * frameRate(fr); // Attempt to refresh at starting FPS + * clr = color(255, 0, 0); + * } + * + * function draw() { + * background(200); + * rectX = rectX + 1 * (deltaTime / 50); // Move Rectangle in relation to deltaTime + * + * if (rectX >= width) { + * // If you go off screen. + * if (fr === 30) { + * clr = color(0, 0, 255); + * fr = 10; + * frameRate(fr); // make frameRate 10 FPS + * } else { + * clr = color(255, 0, 0); + * fr = 30; + * frameRate(fr); // make frameRate 30 FPS + * } + * rectX = 0; + * } + * fill(clr); + * rect(rectX, 40, 20, 20); + * } + *
+ * + * @alt + * red rect moves left to right, followed by blue rect moving at the same speed + * with a lower frame rate. Loops. + * + */ + p5.prototype.deltaTime = 0; + + /** + * Confirms if the window a p5.js program is in is "focused," meaning that + * the sketch will accept mouse or keyboard input. This variable is + * "true" if the window is focused and "false" if not. + * + * @property {Boolean} focused + * @readOnly + * @example + *
+ * // To demonstrate, put two windows side by side. + * // Click on the window that the p5 sketch isn't in! + * function draw() { + * background(200); + * noStroke(); + * fill(0, 200, 0); + * ellipse(25, 25, 50, 50); + * + * if (!focused) { + // or "if (focused === false)" + * stroke(200, 0, 0); + * line(0, 0, 100, 100); + * line(100, 0, 0, 100); + * } + * } + *
+ * + * @alt + * green 50x50 ellipse at top left. Red X covers canvas when page focus changes + * + */ + p5.prototype.focused = document.hasFocus(); + + /** + * Sets the cursor to a predefined symbol or an image, or makes it visible + * if already hidden. If you are trying to set an image as the cursor, the + * recommended size is 16x16 or 32x32 pixels. The values for parameters x and y + * must be less than the dimensions of the image. + * + * @method cursor + * @param {String|Constant} type Built-In: either ARROW, CROSS, HAND, MOVE, TEXT and WAIT + * Native CSS properties: 'grab', 'progress', 'cell' etc. + * External: path for cursor's images + * (Allowed File extensions: .cur, .gif, .jpg, .jpeg, .png) + * For more information on Native CSS cursors and url visit: + * https://developer.mozilla.org/en-US/docs/Web/CSS/cursor + * @param {Number} [x] the horizontal active spot of the cursor (must be less than 32) + * @param {Number} [y] the vertical active spot of the cursor (must be less than 32) + * @example + *
+ * // Move the mouse across the quadrants + * // to see the cursor change + * function draw() { + * line(width / 2, 0, width / 2, height); + * line(0, height / 2, width, height / 2); + * if (mouseX < 50 && mouseY < 50) { + * cursor(CROSS); + * } else if (mouseX > 50 && mouseY < 50) { + * cursor('progress'); + * } else if (mouseX > 50 && mouseY > 50) { + * cursor('https://s3.amazonaws.com/mupublicdata/cursor.cur'); + * } else { + * cursor('grab'); + * } + * } + *
+ * + * @alt + * canvas is divided into four quadrants. cursor on first is a cross, second is a progress, + * third is a custom cursor using path to the cursor and fourth is a grab. + * + */ + p5.prototype.cursor = function(type, x, y) { + var cursor = 'auto'; + var canvas = this._curElement.elt; + if (standardCursors.indexOf(type) > -1) { + // Standard css cursor + cursor = type; + } else if (typeof type === 'string') { + var coords = ''; + if (x && y && typeof x === 'number' && typeof y === 'number') { + // Note that x and y values must be unit-less positive integers < 32 + // https://developer.mozilla.org/en-US/docs/Web/CSS/cursor + coords = x + ' ' + y; + } + if ( + type.substring(0, 7) === 'http://' || + type.substring(0, 8) === 'https://' + ) { + // Image (absolute url) + cursor = 'url(' + type + ') ' + coords + ', auto'; + } else if (/\.(cur|jpg|jpeg|gif|png|CUR|JPG|JPEG|GIF|PNG)$/.test(type)) { + // Image file (relative path) - Separated for performance reasons + cursor = 'url(' + type + ') ' + coords + ', auto'; + } else { + // Any valid string for the css cursor property + cursor = type; + } + } + canvas.style.cursor = cursor; + }; + + /** + * Specifies the number of frames to be displayed every second. For example, + * the function call frameRate(30) will attempt to refresh 30 times a second. + * If the processor is not fast enough to maintain the specified rate, the + * frame rate will not be achieved. Setting the frame rate within setup() is + * recommended. The default frame rate is based on the frame rate of the display + * (here also called "refresh rate"), which is set to 60 frames per second on most + * computers. A frame rate of 24 frames per second (usual for movies) or above + * will be enough for smooth animations + * This is the same as setFrameRate(val). + *

+ * Calling frameRate() with no arguments returns the current framerate. The + * draw function must run at least once before it will return a value. This + * is the same as getFrameRate(). + *

+ * Calling frameRate() with arguments that are not of the type numbers + * or are non positive also returns current framerate. + * + * @method frameRate + * @param {Number} fps number of frames to be displayed every second + * @chainable + * + * @example + * + *
+ * let rectX = 0; + * let fr = 30; //starting FPS + * let clr; + * + * function setup() { + * background(200); + * frameRate(fr); // Attempt to refresh at starting FPS + * clr = color(255, 0, 0); + * } + * + * function draw() { + * background(200); + * rectX = rectX += 1; // Move Rectangle + * + * if (rectX >= width) { + // If you go off screen. + * if (fr === 30) { + * clr = color(0, 0, 255); + * fr = 10; + * frameRate(fr); // make frameRate 10 FPS + * } else { + * clr = color(255, 0, 0); + * fr = 30; + * frameRate(fr); // make frameRate 30 FPS + * } + * rectX = 0; + * } + * fill(clr); + * rect(rectX, 40, 20, 20); + * } + *
+ * + * @alt + * blue rect moves left to right, followed by red rect moving faster. Loops. + * + */ + /** + * @method frameRate + * @return {Number} current frameRate + */ + p5.prototype.frameRate = function(fps) { + p5._validateParameters('frameRate', arguments); + if (typeof fps !== 'number' || fps < 0) { + return this._frameRate; + } else { + this._setProperty('_targetFrameRate', fps); + return this; + } + }; + /** + * Returns the current framerate. + * + * @private + * @return {Number} current frameRate + */ + p5.prototype.getFrameRate = function() { + return this.frameRate(); + }; + + /** + * Specifies the number of frames to be displayed every second. For example, + * the function call frameRate(30) will attempt to refresh 30 times a second. + * If the processor is not fast enough to maintain the specified rate, the + * frame rate will not be achieved. Setting the frame rate within setup() is + * recommended. The default rate is 60 frames per second. + * + * Calling frameRate() with no arguments returns the current framerate. + * + * @private + * @param {Number} [fps] number of frames to be displayed every second + */ + p5.prototype.setFrameRate = function(fps) { + return this.frameRate(fps); + }; + + /** + * Hides the cursor from view. + * + * @method noCursor + * @example + *
+ * function setup() { + * noCursor(); + * } + * + * function draw() { + * background(200); + * ellipse(mouseX, mouseY, 10, 10); + * } + *
+ * + * + * @alt + * cursor becomes 10x 10 white ellipse the moves with mouse x and y. + * + */ + p5.prototype.noCursor = function() { + this._curElement.elt.style.cursor = 'none'; + }; + + /** + * System variable that stores the width of the screen display according to The + * default pixelDensity. This is used to run a + * full-screen program on any display size. To return actual screen size, + * multiply this by pixelDensity. + * + * @property {Number} displayWidth + * @readOnly + * @example + *
+ * createCanvas(displayWidth, displayHeight); + *
+ * + * @alt + * cursor becomes 10x 10 white ellipse the moves with mouse x and y. + * + */ + p5.prototype.displayWidth = screen.width; + + /** + * System variable that stores the height of the screen display according to The + * default pixelDensity. This is used to run a + * full-screen program on any display size. To return actual screen size, + * multiply this by pixelDensity. + * + * @property {Number} displayHeight + * @readOnly + * @example + *
+ * createCanvas(displayWidth, displayHeight); + *
+ * + * @alt + * no display. + * + */ + p5.prototype.displayHeight = screen.height; + + /** + * System variable that stores the width of the inner window, it maps to + * window.innerWidth. + * + * @property {Number} windowWidth + * @readOnly + * @example + *
+ * createCanvas(windowWidth, windowHeight); + *
+ * + * @alt + * no display. + * + */ + p5.prototype.windowWidth = getWindowWidth(); + /** + * System variable that stores the height of the inner window, it maps to + * window.innerHeight. + * + * @property {Number} windowHeight + * @readOnly + * @example + *
+ * createCanvas(windowWidth, windowHeight); + *
+ *@alt + * no display. + * + */ + p5.prototype.windowHeight = getWindowHeight(); + + /** + * The windowResized() function is called once every time the browser window + * is resized. This is a good place to resize the canvas or do any other + * adjustments to accommodate the new window size. + * + * @method windowResized + * @example + *
+ * function setup() { + * createCanvas(windowWidth, windowHeight); + * } + * + * function draw() { + * background(0, 100, 200); + * } + * + * function windowResized() { + * resizeCanvas(windowWidth, windowHeight); + * } + *
+ * @alt + * no display. + */ + p5.prototype._onresize = function(e) { + this._setProperty('windowWidth', getWindowWidth()); + this._setProperty('windowHeight', getWindowHeight()); + var context = this._isGlobal ? window : this; + var executeDefault; + if (typeof context.windowResized === 'function') { + executeDefault = context.windowResized(e); + if (executeDefault !== undefined && !executeDefault) { + e.preventDefault(); + } + } + }; + + function getWindowWidth() { + return ( + window.innerWidth || + (document.documentElement && document.documentElement.clientWidth) || + (document.body && document.body.clientWidth) || + 0 + ); + } + + function getWindowHeight() { + return ( + window.innerHeight || + (document.documentElement && document.documentElement.clientHeight) || + (document.body && document.body.clientHeight) || + 0 + ); + } + + /** + * System variable that stores the width of the drawing canvas. This value + * is set by the first parameter of the createCanvas() function. + * For example, the function call createCanvas(320, 240) sets the width + * variable to the value 320. The value of width defaults to 100 if + * createCanvas() is not used in a program. + * + * @property {Number} width + * @readOnly + */ + p5.prototype.width = 0; + + /** + * System variable that stores the height of the drawing canvas. This value + * is set by the second parameter of the createCanvas() function. For + * example, the function call createCanvas(320, 240) sets the height + * variable to the value 240. The value of height defaults to 100 if + * createCanvas() is not used in a program. + * + * @property {Number} height + * @readOnly + */ + p5.prototype.height = 0; + + /** + * If argument is given, sets the sketch to fullscreen or not based on the + * value of the argument. If no argument is given, returns the current + * fullscreen state. Note that due to browser restrictions this can only + * be called on user input, for example, on mouse press like the example + * below. + * + * @method fullscreen + * @param {Boolean} [val] whether the sketch should be in fullscreen mode + * or not + * @return {Boolean} current fullscreen state + * @example + *
+ * + * // Clicking in the box toggles fullscreen on and off. + * function setup() { + * background(200); + * } + * function mousePressed() { + * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) { + * let fs = fullscreen(); + * fullscreen(!fs); + * } + * } + * + *
+ * + * @alt + * no display. + * + */ + p5.prototype.fullscreen = function(val) { + p5._validateParameters('fullscreen', arguments); + // no arguments, return fullscreen or not + if (typeof val === 'undefined') { + return ( + document.fullscreenElement || + document.webkitFullscreenElement || + document.mozFullScreenElement || + document.msFullscreenElement + ); + } else { + // otherwise set to fullscreen or not + if (val) { + launchFullscreen(document.documentElement); + } else { + exitFullscreen(); + } + } + }; + + /** + * Sets the pixel scaling for high pixel density displays. By default + * pixel density is set to match display density, call pixelDensity(1) + * to turn this off. Calling pixelDensity() with no arguments returns + * the current pixel density of the sketch. + * + * @method pixelDensity + * @param {Number} val whether or how much the sketch should scale + * @chainable + * @example + *
+ * + * function setup() { + * pixelDensity(1); + * createCanvas(100, 100); + * background(200); + * ellipse(width / 2, height / 2, 50, 50); + * } + * + *
+ *
+ * + * function setup() { + * pixelDensity(3.0); + * createCanvas(100, 100); + * background(200); + * ellipse(width / 2, height / 2, 50, 50); + * } + * + *
+ * + * @alt + * fuzzy 50x50 white ellipse with black outline in center of canvas. + * sharp 50x50 white ellipse with black outline in center of canvas. + */ + /** + * @method pixelDensity + * @returns {Number} current pixel density of the sketch + */ + p5.prototype.pixelDensity = function(val) { + p5._validateParameters('pixelDensity', arguments); + var returnValue; + if (typeof val === 'number') { + if (val !== this._pixelDensity) { + this._pixelDensity = val; + this._pixelsDirty = true; + } + returnValue = this; + this.resizeCanvas(this.width, this.height, true); // as a side effect, it will clear the canvas + } else { + returnValue = this._pixelDensity; + } + return returnValue; + }; + + /** + * Returns the pixel density of the current display the sketch is running on. + * + * @method displayDensity + * @returns {Number} current pixel density of the display + * @example + *
+ * + * function setup() { + * let density = displayDensity(); + * pixelDensity(density); + * createCanvas(100, 100); + * background(200); + * ellipse(width / 2, height / 2, 50, 50); + * } + * + *
+ * + * @alt + * 50x50 white ellipse with black outline in center of canvas. + */ + p5.prototype.displayDensity = function() { + return window.devicePixelRatio; + }; + + function launchFullscreen(element) { + var enabled = + document.fullscreenEnabled || + document.webkitFullscreenEnabled || + document.mozFullScreenEnabled || + document.msFullscreenEnabled; + if (!enabled) { + throw new Error('Fullscreen not enabled in this browser.'); + } + if (element.requestFullscreen) { + element.requestFullscreen(); + } else if (element.mozRequestFullScreen) { + element.mozRequestFullScreen(); + } else if (element.webkitRequestFullscreen) { + element.webkitRequestFullscreen(); + } else if (element.msRequestFullscreen) { + element.msRequestFullscreen(); + } + } + + function exitFullscreen() { + if (document.exitFullscreen) { + document.exitFullscreen(); + } else if (document.mozCancelFullScreen) { + document.mozCancelFullScreen(); + } else if (document.webkitExitFullscreen) { + document.webkitExitFullscreen(); + } else if (document.msExitFullscreen) { + document.msExitFullscreen(); + } + } + + /** + * Gets the current URL. + * @method getURL + * @return {String} url + * @example + *
+ * + * let url; + * let x = 100; + * + * function setup() { + * fill(0); + * noStroke(); + * url = getURL(); + * } + * + * function draw() { + * background(200); + * text(url, x, height / 2); + * x--; + * } + * + *
+ * + * @alt + * current url (http://p5js.org/reference/#/p5/getURL) moves right to left. + * + */ + p5.prototype.getURL = function() { + return location.href; + }; + /** + * Gets the current URL path as an array. + * @method getURLPath + * @return {String[]} path components + * @example + *
+ * function setup() { + * let urlPath = getURLPath(); + * for (let i = 0; i < urlPath.length; i++) { + * text(urlPath[i], 10, i * 20 + 20); + * } + * } + *
+ * + * @alt + *no display + * + */ + p5.prototype.getURLPath = function() { + return location.pathname.split('/').filter(function(v) { + return v !== ''; + }); + }; + /** + * Gets the current URL params as an Object. + * @method getURLParams + * @return {Object} URL params + * @example + *
+ * + * // Example: http://p5js.org?year=2014&month=May&day=15 + * + * function setup() { + * let params = getURLParams(); + * text(params.day, 10, 20); + * text(params.month, 10, 40); + * text(params.year, 10, 60); + * } + * + *
+ * @alt + * no display. + * + */ + p5.prototype.getURLParams = function() { + var re = /[?&]([^&=]+)(?:[&=])([^&=]+)/gim; + var m; + var v = {}; + while ((m = re.exec(location.search)) != null) { + if (m.index === re.lastIndex) { + re.lastIndex++; + } + v[m[1]] = m[2]; + } + return v; + }; + + module.exports = p5; + }, + { './constants': 18, './main': 24 } + ], + 20: [ + function(_dereq_, module, exports) { + /** + * @for p5 + * @requires core + */ + + 'use strict'; + function _typeof(obj) { + if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { + _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + _typeof = function _typeof(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : typeof obj; + }; + } + return _typeof(obj); + } + + var p5 = _dereq_('./main'); + var constants = _dereq_('./constants'); + + // p5.js blue, p5.js orange, auto dark green; fallback p5.js darkened magenta + // See testColors below for all the color codes and names + var typeColors = ['#2D7BB6', '#EE9900', '#4DB200', '#C83C00']; + + if (typeof IS_MINIFIED !== 'undefined') { + p5._validateParameters = p5._friendlyFileLoadError = p5._friendlyError = function() {}; + } else { + var doFriendlyWelcome = false; // TEMP until we get it all working LM + // for parameter validation + var dataDoc = _dereq_('../../docs/reference/data.json'); + var arrDoc = JSON.parse(JSON.stringify(dataDoc)); + + // -- Borrowed from jQuery 1.11.3 -- + var class2type = {}; + var toString = class2type.toString; + var names = [ + 'Boolean', + 'Number', + 'String', + 'Function', + 'Array', + 'Date', + 'RegExp', + 'Object', + 'Error' + ]; + + for (var n = 0; n < names.length; n++) { + class2type['[object ' + names[n] + ']'] = names[n].toLowerCase(); + } + var getType = function getType(obj) { + if (obj == null) { + return obj + ''; + } + return _typeof(obj) === 'object' || typeof obj === 'function' + ? class2type[toString.call(obj)] || 'object' + : _typeof(obj); + }; + + // -- End borrow -- + + var friendlyWelcome = function friendlyWelcome() { + // p5.js brand - magenta: #ED225D + //var astrixBgColor = 'transparent'; + //var astrixTxtColor = '#ED225D'; + //var welcomeBgColor = '#ED225D'; + //var welcomeTextColor = 'white'; + console.log( + ' _ \n' + + ' /\\| |/\\ \n' + + " \\ ` ' / \n" + + ' / , . \\ \n' + + ' \\/|_|\\/ ' + + '\n\n> p5.js says: Welcome! ' + + 'This is your friendly debugger. ' + + 'To turn me off switch to using “p5.min.js”.' + ); + }; + + /** + * Prints out a fancy, colorful message to the console log + * + * @method report + * @private + * @param {String} message the words to be said + * @param {String} func the name of the function to link + * @param {Number|String} color CSS color string or error type + * + * @return console logs + */ + var report = function report(message, func, color) { + if (doFriendlyWelcome) { + friendlyWelcome(); + doFriendlyWelcome = false; + } + if ('undefined' === getType(color)) { + color = '#B40033'; // dark magenta + } else if (getType(color) === 'number') { + // Type to color + color = typeColors[color]; + } + if (func === 'loadX') { + console.log('> p5.js says: ' + message); + } else if (func.substring(0, 4) === 'load') { + console.log( + '> p5.js says: ' + + message + + '[https://github.com/processing/p5.js/wiki/Local-server]' + ); + } else { + console.log( + '> p5.js says: ' + + message + + ' [http://p5js.org/reference/#p5/' + + func + + ']' + ); + } + }; + + var errorCases = { + '0': { + fileType: 'image', + method: 'loadImage', + message: ' hosting the image online,' + }, + + '1': { + fileType: 'XML file', + method: 'loadXML' + }, + + '2': { + fileType: 'table file', + method: 'loadTable' + }, + + '3': { + fileType: 'text file', + method: 'loadStrings' + }, + + '4': { + fileType: 'font', + method: 'loadFont', + message: ' hosting the font online,' + }, + + '5': { + fileType: 'json', + method: 'loadJSON' + }, + + '6': { + fileType: 'file', + method: 'loadBytes' + }, + + '7': { + method: 'loadX', + message: + "In case your large file isn't fetched successfully," + + 'we recommend splitting the file into smaller segments and fetching those.' + } + }; + + /** + * This is called internally if there is a error during file loading. + * + * @method _friendlyFileLoadError + * @private + * @param {Number} errorType + * @param {String} filePath + */ + p5._friendlyFileLoadError = function(errorType, filePath) { + var errorInfo = errorCases[errorType]; + var message; + if (errorType === 7) { + message = errorInfo.message; + } else { + message = + 'It looks like there was a problem' + + ' loading your ' + + errorInfo.fileType + + '.' + + ' Try checking if the file path [' + + filePath + + '] is correct,' + + (errorInfo.message || '') + + ' or running a local server.'; + } + report(message, errorInfo.method, 3); + }; + + /** + * This is a generic method that can be called from anywhere in the p5 + * library to alert users to a common error. + * + * @method _friendlyError + * @private + * @param {Number} message message to be printed + * @param {String} method name of method + */ + p5._friendlyError = function(message, method) { + report(message, method); + }; + + var docCache = {}; + var builtinTypes = [ + 'null', + 'number', + 'string', + 'boolean', + 'constant', + 'function', + 'any', + 'integer' + ]; + + // validateParameters() helper functions: + // lookupParamDoc() for querying data.json + var lookupParamDoc = function lookupParamDoc(func) { + // look for the docs in the `data.json` datastructure + + var ichDot = func.lastIndexOf('.'); + var funcName = func.substr(ichDot + 1); + var funcClass = func.substr(0, ichDot) || 'p5'; + + var queryResult; + var classitems = arrDoc.classitems; + for (var ici = 0; ici < classitems.length; ici++) { + var x = classitems[ici]; + if (x.name === funcName && x.class === funcClass) { + queryResult = x; + break; + } + } + + // different JSON structure for funct with multi-format + var overloads = []; + if (queryResult.hasOwnProperty('overloads')) { + // add all the overloads + for (var i = 0; i < queryResult.overloads.length; i++) { + overloads.push({ formats: queryResult.overloads[i].params }); + } + } else { + // no overloads, just add the main method definition + overloads.push({ formats: queryResult.params || [] }); + } + + // parse the parameter types for each overload + var mapConstants = {}; + var maxParams = 0; + overloads.forEach(function(overload) { + var formats = overload.formats; + + // keep a record of the maximum number of arguments + // this method requires. + if (maxParams < formats.length) { + maxParams = formats.length; + } + + // calculate the minimum number of arguments + // this overload requires. + var minParams = formats.length; + while (minParams > 0 && formats[minParams - 1].optional) { + minParams--; + } + overload.minParams = minParams; + + // loop through each parameter position, and parse its types + formats.forEach(function(format) { + // split this parameter's types + format.types = format.type.split('|').map(function ct(type) { + // array + if (type.substr(type.length - 2, 2) === '[]') { + return { + name: type, + array: ct(type.substr(0, type.length - 2)) + }; + } + + var lowerType = type.toLowerCase(); + + // contant + if (lowerType === 'constant') { + var constant; + if (mapConstants.hasOwnProperty(format.name)) { + constant = mapConstants[format.name]; + } else { + // parse possible constant values from description + var myRe = /either\s+(?:[A-Z0-9_]+\s*,?\s*(?:or)?\s*)+/g; + var values = {}; + var names = []; + + constant = mapConstants[format.name] = { + values: values, + names: names + }; + + var myArray = myRe.exec(format.description); + if (func === 'endShape' && format.name === 'mode') { + values[constants.CLOSE] = true; + names.push('CLOSE'); + } else { + var match = myArray[0]; + var reConst = /[A-Z0-9_]+/g; + var matchConst; + while ((matchConst = reConst.exec(match)) !== null) { + var name = matchConst[0]; + if (constants.hasOwnProperty(name)) { + values[constants[name]] = true; + names.push(name); + } + } + } + } + return { + name: type, + builtin: lowerType, + names: constant.names, + values: constant.values + }; + } + + // function + if (lowerType.substr(0, 'function'.length) === 'function') { + lowerType = 'function'; + } + // builtin + if (builtinTypes.indexOf(lowerType) >= 0) { + return { name: type, builtin: lowerType }; + } + + // find type's prototype + var t = window; + var typeParts = type.split('.'); + + // special-case 'p5' since it may be non-global + if (typeParts[0] === 'p5') { + t = p5; + typeParts.shift(); + } + + typeParts.forEach(function(p) { + t = t && t[p]; + }); + if (t) { + return { name: type, prototype: t }; + } + + return { name: type, type: lowerType }; + }); + }); + }); + return { + overloads: overloads, + maxParams: maxParams + }; + }; + + var isNumber = function isNumber(param) { + switch (_typeof(param)) { + case 'number': + return true; + case 'string': + return !isNaN(param); + default: + return false; + } + }; + + var testParamType = function testParamType(param, type) { + var isArray = param instanceof Array; + var matches = true; + if (type.array && isArray) { + for (var i = 0; i < param.length; i++) { + var error = testParamType(param[i], type.array); + if (error) return error / 2; // half error for elements + } + } else if (type.prototype) { + matches = param instanceof type.prototype; + } else if (type.builtin) { + switch (type.builtin) { + case 'number': + matches = isNumber(param); + break; + case 'integer': + matches = isNumber(param) && Number(param) === Math.floor(param); + break; + case 'boolean': + case 'any': + matches = true; + break; + case 'array': + matches = isArray; + break; + case 'string': + matches = /*typeof param === 'number' ||*/ typeof param === 'string'; + break; + case 'constant': + matches = type.values.hasOwnProperty(param); + break; + case 'function': + matches = param instanceof Function; + break; + case 'null': + matches = param === null; + break; + } + } else { + matches = _typeof(param) === type.t; + } + return matches ? 0 : 1; + }; + + // testType() for non-object type parameter validation + var testParamTypes = function testParamTypes(param, types) { + var minScore = 9999; + for (var i = 0; minScore > 0 && i < types.length; i++) { + var score = testParamType(param, types[i]); + if (minScore > score) minScore = score; + } + return minScore; + }; + + // generate a score (higher is worse) for applying these args to + // this overload. + var scoreOverload = function scoreOverload(args, argCount, overload, minScore) { + var score = 0; + var formats = overload.formats; + var minParams = overload.minParams; + + // check for too few/many args + // the score is double number of extra/missing args + if (argCount < minParams) { + score = (minParams - argCount) * 2; + } else if (argCount > formats.length) { + score = (argCount - formats.length) * 2; + } + + // loop through the formats, adding up the error score for each arg. + // quit early if the score gets higher than the previous best overload. + for (var p = 0; score <= minScore && p < formats.length; p++) { + var arg = args[p]; + var format = formats[p]; + // '== null' checks for 'null' and typeof 'undefined' + if (arg == null) { + // handle non-optional and non-trailing undefined args + if (!format.optional || p < minParams || p < argCount) { + score += 1; + } + } else { + score += testParamTypes(arg, format.types); + } + } + return score; + }; + + // gets a list of errors for this overload + var getOverloadErrors = function getOverloadErrors(args, argCount, overload) { + var formats = overload.formats; + var minParams = overload.minParams; + + // check for too few/many args + if (argCount < minParams) { + return [ + { + type: 'TOO_FEW_ARGUMENTS', + argCount: argCount, + minParams: minParams + } + ]; + } else if (argCount > formats.length) { + return [ + { + type: 'TOO_MANY_ARGUMENTS', + argCount: argCount, + maxParams: formats.length + } + ]; + } + + var errorArray = []; + for (var p = 0; p < formats.length; p++) { + var arg = args[p]; + var format = formats[p]; + // '== null' checks for 'null' and typeof 'undefined' + if (arg == null) { + // handle non-optional and non-trailing undefined args + if (!format.optional || p < minParams || p < argCount) { + errorArray.push({ + type: 'EMPTY_VAR', + position: p, + format: format + }); + } + } else if (testParamTypes(arg, format.types) > 0) { + errorArray.push({ + type: 'WRONG_TYPE', + position: p, + format: format, + arg: arg + }); + } + } + + return errorArray; + }; + + // a custom error type, used by the mocha + // tests when expecting validation errors + p5.ValidationError = (function(name) { + var err = function err(message, func) { + this.message = message; + this.func = func; + if ('captureStackTrace' in Error) Error.captureStackTrace(this, err); + else this.stack = new Error().stack; + }; + err.prototype = Object.create(Error.prototype); + err.prototype.name = name; + err.prototype.constructor = err; + return err; + })('ValidationError'); + + // function for generating console.log() msg + p5._friendlyParamError = function(errorObj, func) { + var message; + + function formatType() { + var format = errorObj.format; + return format.types + .map(function(type) { + return type.names ? type.names.join('|') : type.name; + }) + .join('|'); + } + + switch (errorObj.type) { + case 'EMPTY_VAR': + message = + func + + '() was expecting ' + + formatType() + + ' for parameter #' + + errorObj.position + + ' (zero-based index), received an empty variable instead.' + + ' If not intentional, this is often a problem with scope:' + + ' [https://p5js.org/examples/data-variable-scope.html]'; + break; + case 'WRONG_TYPE': + var arg = errorObj.arg; + var argType = + arg instanceof Array + ? 'array' + : arg === null ? 'null' : arg.name || _typeof(arg); + message = + func + + '() was expecting ' + + formatType() + + ' for parameter #' + + errorObj.position + + ' (zero-based index), received ' + + argType + + ' instead'; + break; + case 'TOO_FEW_ARGUMENTS': + message = + func + + '() was expecting at least ' + + errorObj.minParams + + ' arguments, but received only ' + + errorObj.argCount; + break; + case 'TOO_MANY_ARGUMENTS': + message = + func + + '() was expecting no more than ' + + errorObj.maxParams + + ' arguments, but received ' + + errorObj.argCount; + break; + } + + if (message) { + if (p5._throwValidationErrors) { + throw new p5.ValidationError(message); + } + + try { + var re = /Function\.validateParameters.*[\r\n].*[\r\n].*\(([^)]*)/; + var location = re.exec(new Error().stack)[1]; + if (location) { + message += ' at ' + location; + } + } catch (err) {} + + report(message + '.', func, 3); + } + }; + + /** + * Validates parameters + * param {String} func the name of the function + * param {Array} args user input arguments + * + * example: + * var a; + * ellipse(10,10,a,5); + * console ouput: + * "It looks like ellipse received an empty variable in spot #2." + * + * example: + * ellipse(10,"foo",5,5); + * console output: + * "ellipse was expecting a number for parameter #1, + * received "foo" instead." + */ + p5._validateParameters = function validateParameters(func, args) { + if (p5.disableFriendlyErrors) { + return; // skip FES + } + + // lookup the docs in the 'data.json' file + var docs = docCache[func] || (docCache[func] = lookupParamDoc(func)); + var overloads = docs.overloads; + + // ignore any trailing `undefined` arguments + var argCount = args.length; + // '== null' checks for 'null' and typeof 'undefined' + while (argCount > 0 && args[argCount - 1] == null) { + argCount--; + } + + // find the overload with the best score + var minScore = 99999; + var minOverload; + for (var i = 0; i < overloads.length; i++) { + var score = scoreOverload(args, argCount, overloads[i], minScore); + if (score === 0) { + return; // done! + } else if (minScore > score) { + // this score is better that what we have so far... + minScore = score; + minOverload = i; + } + } + + // this should _always_ be true here... + if (minScore > 0) { + // get the errors for the best overload + var errorArray = getOverloadErrors(args, argCount, overloads[minOverload]); + + // generate err msg + for (var n = 0; n < errorArray.length; n++) { + p5._friendlyParamError(errorArray[n], func); + } + } + }; + + /** + * Prints out all the colors in the color pallete with white text. + * For color blindness testing. + */ + /* function testColors() { + var str = 'A box of biscuits, a box of mixed biscuits and a biscuit mixer'; + report(str, 'print', '#ED225D'); // p5.js magenta + report(str, 'print', '#2D7BB6'); // p5.js blue + report(str, 'print', '#EE9900'); // p5.js orange + report(str, 'print', '#A67F59'); // p5.js light brown + report(str, 'print', '#704F21'); // p5.js gold + report(str, 'print', '#1CC581'); // auto cyan + report(str, 'print', '#FF6625'); // auto orange + report(str, 'print', '#79EB22'); // auto green + report(str, 'print', '#B40033'); // p5.js darkened magenta + report(str, 'print', '#084B7F'); // p5.js darkened blue + report(str, 'print', '#945F00'); // p5.js darkened orange + report(str, 'print', '#6B441D'); // p5.js darkened brown + report(str, 'print', '#2E1B00'); // p5.js darkened gold + report(str, 'print', '#008851'); // auto dark cyan + report(str, 'print', '#C83C00'); // auto dark orange + report(str, 'print', '#4DB200'); // auto dark green + } */ + + p5.prototype._validateParameters = p5.validateParameters; + } + + // This is a lazily-defined list of p5 symbols that may be + // misused by beginners at top-level code, outside of setup/draw. We'd like + // to detect these errors and help the user by suggesting they move them + // into setup/draw. + // + // For more details, see https://github.com/processing/p5.js/issues/1121. + var misusedAtTopLevelCode = null; + var FAQ_URL = + 'https://github.com/processing/p5.js/wiki/p5.js-overview' + + '#why-cant-i-assign-variables-using-p5-functions-and-' + + 'variables-before-setup'; + + var defineMisusedAtTopLevelCode = function defineMisusedAtTopLevelCode() { + var uniqueNamesFound = {}; + + var getSymbols = function getSymbols(obj) { + return Object.getOwnPropertyNames(obj) + .filter(function(name) { + if (name[0] === '_') { + return false; + } + if (name in uniqueNamesFound) { + return false; + } + + uniqueNamesFound[name] = true; + + return true; + }) + .map(function(name) { + var type; + + if (typeof obj[name] === 'function') { + type = 'function'; + } else if (name === name.toUpperCase()) { + type = 'constant'; + } else { + type = 'variable'; + } + + return { name: name, type: type }; + }); + }; + + misusedAtTopLevelCode = [].concat( + getSymbols(p5.prototype), + // At present, p5 only adds its constants to p5.prototype during + // construction, which may not have happened at the time a + // ReferenceError is thrown, so we'll manually add them to our list. + getSymbols(_dereq_('./constants')) + ); + + // This will ultimately ensure that we report the most specific error + // possible to the user, e.g. advising them about HALF_PI instead of PI + // when their code misuses the former. + misusedAtTopLevelCode.sort(function(a, b) { + return b.name.length - a.name.length; + }); + }; + + var helpForMisusedAtTopLevelCode = function helpForMisusedAtTopLevelCode(e, log) { + if (!log) { + log = console.log.bind(console); + } + + if (!misusedAtTopLevelCode) { + defineMisusedAtTopLevelCode(); + } + + // If we find that we're logging lots of false positives, we can + // uncomment the following code to avoid displaying anything if the + // user's code isn't likely to be using p5's global mode. (Note that + // setup/draw are more likely to be defined due to JS function hoisting.) + // + //if (!('setup' in window || 'draw' in window)) { + // return; + //} + + misusedAtTopLevelCode.some(function(symbol) { + // Note that while just checking for the occurrence of the + // symbol name in the error message could result in false positives, + // a more rigorous test is difficult because different browsers + // log different messages, and the format of those messages may + // change over time. + // + // For example, if the user uses 'PI' in their code, it may result + // in any one of the following messages: + // + // * 'PI' is undefined (Microsoft Edge) + // * ReferenceError: PI is undefined (Firefox) + // * Uncaught ReferenceError: PI is not defined (Chrome) + + if (e.message && e.message.match('\\W?' + symbol.name + '\\W') !== null) { + log( + "Did you just try to use p5.js's " + + symbol.name + + (symbol.type === 'function' ? '() ' : ' ') + + symbol.type + + '? If so, you may want to ' + + "move it into your sketch's setup() function.\n\n" + + 'For more details, see: ' + + FAQ_URL + ); + + return true; + } + }); + }; + + // Exposing this primarily for unit testing. + p5.prototype._helpForMisusedAtTopLevelCode = helpForMisusedAtTopLevelCode; + + if (document.readyState !== 'complete') { + window.addEventListener('error', helpForMisusedAtTopLevelCode, false); + + // Our job is only to catch ReferenceErrors that are thrown when + // global (non-instance mode) p5 APIs are used at the top-level + // scope of a file, so we'll unbind our error listener now to make + // sure we don't log false positives later. + window.addEventListener('load', function() { + window.removeEventListener('error', helpForMisusedAtTopLevelCode, false); + }); + } + + module.exports = p5; + }, + { '../../docs/reference/data.json': 1, './constants': 18, './main': 24 } + ], + 21: [ + function(_dereq_, module, exports) { + /** + * @requires constants + */ + + 'use strict'; + + var constants = _dereq_('./constants'); + + module.exports = { + modeAdjust: function modeAdjust(a, b, c, d, mode) { + if (mode === constants.CORNER) { + return { x: a, y: b, w: c, h: d }; + } else if (mode === constants.CORNERS) { + return { x: a, y: b, w: c - a, h: d - b }; + } else if (mode === constants.RADIUS) { + return { x: a - c, y: b - d, w: 2 * c, h: 2 * d }; + } else if (mode === constants.CENTER) { + return { x: a - c * 0.5, y: b - d * 0.5, w: c, h: d }; + } + } + }; + }, + { './constants': 18 } + ], + 22: [ + function(_dereq_, module, exports) { + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * _globalInit + * + * TODO: ??? + * if sketch is on window + * assume "global" mode + * and instantiate p5 automatically + * otherwise do nothing + * + * @private + * @return {Undefined} + */ + var _globalInit = function _globalInit() { + if (!window.mocha) { + // If there is a setup or draw function on the window + // then instantiate p5 in "global" mode + if ( + ((window.setup && typeof window.setup === 'function') || + (window.draw && typeof window.draw === 'function')) && + !p5.instance + ) { + new p5(); + } + } + }; + + // TODO: ??? + + // if the page is ready, initialize p5 immediately + if (document.readyState === 'complete') { + _globalInit(); + // if the page is still loading, add an event listener + // and initialize p5 as soon as it finishes loading + } else { + window.addEventListener('load', _globalInit, false); + } + }, + { '../core/main': 24 } + ], + 23: [ + function(_dereq_, module, exports) { + /** + * @for p5 + * @requires core + * These are functions that are part of the Processing API but are not part of + * the p5.js API. In some cases they have a new name, in others, they are + * removed completely. Not all unsupported Processing functions are listed here + * but we try to include ones that a user coming from Processing might likely + * call. + */ + + 'use strict'; + + var p5 = _dereq_('./main'); + + p5.prototype.pushStyle = function() { + throw new Error('pushStyle() not used, see push()'); + }; + + p5.prototype.popStyle = function() { + throw new Error('popStyle() not used, see pop()'); + }; + + p5.prototype.popMatrix = function() { + throw new Error('popMatrix() not used, see pop()'); + }; + + p5.prototype.printMatrix = function() { + throw new Error( + 'printMatrix() is not implemented in p5.js, ' + + 'refer to [https://simonsarris.com/a-transformation-class-for-canvas-to-keep-track-of-the-transformation-matrix/] ' + + 'to add your own implementation.' + ); + }; + + p5.prototype.pushMatrix = function() { + throw new Error('pushMatrix() not used, see push()'); + }; + + module.exports = p5; + }, + { './main': 24 } + ], + 24: [ + function(_dereq_, module, exports) { + /** + * @module Structure + * @submodule Structure + * @for p5 + * @requires constants + */ + + 'use strict'; + + _dereq_('./shim'); + + // Core needs the PVariables object + var constants = _dereq_('./constants'); + + /** + * This is the p5 instance constructor. + * + * A p5 instance holds all the properties and methods related to + * a p5 sketch. It expects an incoming sketch closure and it can also + * take an optional node parameter for attaching the generated p5 canvas + * to a node. The sketch closure takes the newly created p5 instance as + * its sole argument and may optionally set preload(), setup(), and/or + * draw() properties on it for running a sketch. + * + * A p5 sketch can run in "global" or "instance" mode: + * "global" - all properties and methods are attached to the window + * "instance" - all properties and methods are bound to this p5 object + * + * @class p5 + * @constructor + * @param {function} sketch a closure that can set optional preload(), + * setup(), and/or draw() properties on the + * given p5 instance + * @param {HTMLElement} [node] element to attach canvas to + * @return {p5} a p5 instance + */ + var p5 = function p5(sketch, node, sync) { + ////////////////////////////////////////////// + // PUBLIC p5 PROPERTIES AND METHODS + ////////////////////////////////////////////// + + /** + * Called directly before setup(), the preload() function is used to handle + * asynchronous loading of external files in a blocking way. If a preload + * function is defined, setup() will wait until any load calls within have + * finished. Nothing besides load calls (loadImage, loadJSON, loadFont, + * loadStrings, etc.) should be inside the preload function. If asynchronous + * loading is preferred, the load methods can instead be called in setup() + * or anywhere else with the use of a callback parameter. + *

+ * By default the text "loading..." will be displayed. To make your own + * loading page, include an HTML element with id "p5_loading" in your + * page. More information here. + * + * @method preload + * @example + *
+ * let img; + * let c; + * function preload() { + * // preload() runs once + * img = loadImage('assets/laDefense.jpg'); + * } + * + * function setup() { + * // setup() waits until preload() is done + * img.loadPixels(); + * // get color of middle pixel + * c = img.get(img.width / 2, img.height / 2); + * } + * + * function draw() { + * background(c); + * image(img, 25, 25, 50, 50); + * } + *
+ * + * @alt + * nothing displayed + * + */ + + /** + * The setup() function is called once when the program starts. It's used to + * define initial environment properties such as screen size and background + * color and to load media such as images and fonts as the program starts. + * There can only be one setup() function for each program and it shouldn't + * be called again after its initial execution. + *

+ * Note: Variables declared within setup() are not accessible within other + * functions, including draw(). + * + * @method setup + * @example + *
+ * let a = 0; + * + * function setup() { + * background(0); + * noStroke(); + * fill(102); + * } + * + * function draw() { + * rect(a++ % width, 10, 2, 80); + * } + *
+ * + * @alt + * nothing displayed + * + */ + + /** + * Called directly after setup(), the draw() function continuously executes + * the lines of code contained inside its block until the program is stopped + * or noLoop() is called. Note if noLoop() is called in setup(), draw() will + * still be executed once before stopping. draw() is called automatically and + * should never be called explicitly. + *

+ * It should always be controlled with noLoop(), redraw() and loop(). After + * noLoop() stops the code in draw() from executing, redraw() causes the + * code inside draw() to execute once, and loop() will cause the code + * inside draw() to resume executing continuously. + *

+ * The number of times draw() executes in each second may be controlled with + * the frameRate() function. + *

+ * There can only be one draw() function for each sketch, and draw() must + * exist if you want the code to run continuously, or to process events such + * as mousePressed(). Sometimes, you might have an empty call to draw() in + * your program, as shown in the above example. + *

+ * It is important to note that the drawing coordinate system will be reset + * at the beginning of each draw() call. If any transformations are performed + * within draw() (ex: scale, rotate, translate), their effects will be + * undone at the beginning of draw(), so transformations will not accumulate + * over time. On the other hand, styling applied (ex: fill, stroke, etc) will + * remain in effect. + * + * @method draw + * @example + *
+ * let yPos = 0; + * function setup() { + * // setup() runs once + * frameRate(30); + * } + * function draw() { + * // draw() loops forever, until stopped + * background(204); + * yPos = yPos - 1; + * if (yPos < 0) { + * yPos = height; + * } + * line(0, yPos, width, yPos); + * } + *
+ * + * @alt + * nothing displayed + * + */ + + ////////////////////////////////////////////// + // PRIVATE p5 PROPERTIES AND METHODS + ////////////////////////////////////////////// + + this._setupDone = false; + // for handling hidpi + this._pixelDensity = Math.ceil(window.devicePixelRatio) || 1; + this._userNode = node; + this._curElement = null; + this._elements = []; + this._glAttributes = null; + this._requestAnimId = 0; + this._preloadCount = 0; + this._isGlobal = false; + this._loop = true; + this._initializeInstanceVariables(); + this._defaultCanvasSize = { + width: 100, + height: 100 + }; + + this._events = { + // keep track of user-events for unregistering later + mousemove: null, + mousedown: null, + mouseup: null, + dragend: null, + dragover: null, + click: null, + dblclick: null, + mouseover: null, + mouseout: null, + keydown: null, + keyup: null, + keypress: null, + touchstart: null, + touchmove: null, + touchend: null, + resize: null, + blur: null + }; + + this._events.wheel = null; + this._loadingScreenId = 'p5_loading'; + + // Allows methods to be registered on an instance that + // are instance-specific. + this._registeredMethods = {}; + var methods = Object.getOwnPropertyNames(p5.prototype._registeredMethods); + for (var i = 0; i < methods.length; i++) { + var prop = methods[i]; + this._registeredMethods[prop] = p5.prototype._registeredMethods[prop].slice(); + } + + if (window.DeviceOrientationEvent) { + this._events.deviceorientation = null; + } + if (window.DeviceMotionEvent && !window._isNodeWebkit) { + this._events.devicemotion = null; + } + + this._start = function() { + // Find node if id given + if (this._userNode) { + if (typeof this._userNode === 'string') { + this._userNode = document.getElementById(this._userNode); + } + } + + var context = this._isGlobal ? window : this; + var userPreload = context.preload; + if (userPreload) { + // Setup loading screen + // Set loading screen into dom if not present + // Otherwise displays and removes user provided loading screen + var loadingScreen = document.getElementById(this._loadingScreenId); + if (!loadingScreen) { + loadingScreen = document.createElement('div'); + loadingScreen.innerHTML = 'Loading...'; + loadingScreen.style.position = 'absolute'; + loadingScreen.id = this._loadingScreenId; + var node = this._userNode || document.body; + node.appendChild(loadingScreen); + } + var methods = this._preloadMethods; + for (var method in methods) { + // default to p5 if no object defined + methods[method] = methods[method] || p5; + var obj = methods[method]; + //it's p5, check if it's global or instance + if (obj === p5.prototype || obj === p5) { + if (this._isGlobal) { + window[method] = this._wrapPreload(this, method); + } + obj = this; + } + this._registeredPreloadMethods[method] = obj[method]; + obj[method] = this._wrapPreload(obj, method); + } + + userPreload(); + this._runIfPreloadsAreDone(); + } else { + this._setup(); + this._draw(); + } + }.bind(this); + + this._runIfPreloadsAreDone = function() { + var context = this._isGlobal ? window : this; + if (context._preloadCount === 0) { + var loadingScreen = document.getElementById(context._loadingScreenId); + if (loadingScreen) { + loadingScreen.parentNode.removeChild(loadingScreen); + } + context._setup(); + context._draw(); + } + }; + + this._decrementPreload = function() { + var context = this._isGlobal ? window : this; + if (typeof context.preload === 'function') { + context._setProperty('_preloadCount', context._preloadCount - 1); + context._runIfPreloadsAreDone(); + } + }; + + this._wrapPreload = function(obj, fnName) { + return function() { + //increment counter + this._incrementPreload(); + //call original function + return this._registeredPreloadMethods[fnName].apply(obj, arguments); + }.bind(this); + }; + + this._incrementPreload = function() { + var context = this._isGlobal ? window : this; + context._setProperty('_preloadCount', context._preloadCount + 1); + }; + + this._setup = function() { + // Always create a default canvas. + // Later on if the user calls createCanvas, this default one + // will be replaced + this.createCanvas( + this._defaultCanvasSize.width, + this._defaultCanvasSize.height, + 'p2d' + ); + + // return preload functions to their normal vals if switched by preload + var context = this._isGlobal ? window : this; + if (typeof context.preload === 'function') { + for (var f in this._preloadMethods) { + context[f] = this._preloadMethods[f][f]; + if (context[f] && this) { + context[f] = context[f].bind(this); + } + } + } + + // Short-circuit on this, in case someone used the library in "global" + // mode earlier + if (typeof context.setup === 'function') { + context.setup(); + } + + // unhide any hidden canvases that were created + var canvases = document.getElementsByTagName('canvas'); + for (var i = 0; i < canvases.length; i++) { + var k = canvases[i]; + if (k.dataset.hidden === 'true') { + k.style.visibility = ''; + delete k.dataset.hidden; + } + } + this._setupDone = true; + }.bind(this); + + this._draw = function() { + var now = window.performance.now(); + var time_since_last = now - this._lastFrameTime; + var target_time_between_frames = 1000 / this._targetFrameRate; + + // only draw if we really need to; don't overextend the browser. + // draw if we're within 5ms of when our next frame should paint + // (this will prevent us from giving up opportunities to draw + // again when it's really about time for us to do so). fixes an + // issue where the frameRate is too low if our refresh loop isn't + // in sync with the browser. note that we have to draw once even + // if looping is off, so we bypass the time delay if that + // is the case. + var epsilon = 5; + if (!this._loop || time_since_last >= target_time_between_frames - epsilon) { + //mandatory update values(matrixs and stack) + + this.redraw(); + this._frameRate = 1000.0 / (now - this._lastFrameTime); + this.deltaTime = now - this._lastFrameTime; + this._setProperty('deltaTime', this.deltaTime); + this._lastFrameTime = now; + + // If the user is actually using mouse module, then update + // coordinates, otherwise skip. We can test this by simply + // checking if any of the mouse functions are available or not. + // NOTE : This reflects only in complete build or modular build. + if (typeof this._updateMouseCoords !== 'undefined') { + this._updateMouseCoords(); + } + } + + // get notified the next time the browser gives us + // an opportunity to draw. + if (this._loop) { + this._requestAnimId = window.requestAnimationFrame(this._draw); + } + }.bind(this); + + this._setProperty = function(prop, value) { + this[prop] = value; + if (this._isGlobal) { + window[prop] = value; + } + }.bind(this); + + /** + * Removes the entire p5 sketch. This will remove the canvas and any + * elements created by p5.js. It will also stop the draw loop and unbind + * any properties or methods from the window global scope. It will + * leave a variable p5 in case you wanted to create a new p5 sketch. + * If you like, you can set p5 = null to erase it. While all functions and + * variables and objects created by the p5 library will be removed, any + * other global variables created by your code will remain. + * + * @method remove + * @example + *
+ * function draw() { + * ellipse(50, 50, 10, 10); + * } + * + * function mousePressed() { + * remove(); // remove whole sketch on mouse press + * } + *
+ * + * @alt + * nothing displayed + * + */ + this.remove = function() { + var loadingScreen = document.getElementById(this._loadingScreenId); + if (loadingScreen) { + loadingScreen.parentNode.removeChild(loadingScreen); + // Add 1 to preload counter to prevent the sketch ever executing setup() + this._incrementPreload(); + } + if (this._curElement) { + // stop draw + this._loop = false; + if (this._requestAnimId) { + window.cancelAnimationFrame(this._requestAnimId); + } + + // unregister events sketch-wide + for (var ev in this._events) { + window.removeEventListener(ev, this._events[ev]); + } + + // remove DOM elements created by p5, and listeners + for (var i = 0; i < this._elements.length; i++) { + var e = this._elements[i]; + if (e.elt.parentNode) { + e.elt.parentNode.removeChild(e.elt); + } + for (var elt_ev in e._events) { + e.elt.removeEventListener(elt_ev, e._events[elt_ev]); + } + } + + // call any registered remove functions + var self = this; + this._registeredMethods.remove.forEach(function(f) { + if (typeof f !== 'undefined') { + f.call(self); + } + }); + } + // remove window bound properties and methods + if (this._isGlobal) { + for (var p in p5.prototype) { + try { + delete window[p]; + } catch (x) { + window[p] = undefined; + } + } + for (var p2 in this) { + if (this.hasOwnProperty(p2)) { + try { + delete window[p2]; + } catch (x) { + window[p2] = undefined; + } + } + } + p5.instance = null; + } + }.bind(this); + + // call any registered init functions + this._registeredMethods.init.forEach(function(f) { + if (typeof f !== 'undefined') { + f.call(this); + } + }, this); + + var friendlyBindGlobal = this._createFriendlyGlobalFunctionBinder(); + + // If the user has created a global setup or draw function, + // assume "global" mode and make everything global (i.e. on the window) + if (!sketch) { + this._isGlobal = true; + p5.instance = this; + // Loop through methods on the prototype and attach them to the window + for (var p in p5.prototype) { + if (typeof p5.prototype[p] === 'function') { + var ev = p.substring(2); + if (!this._events.hasOwnProperty(ev)) { + if (Math.hasOwnProperty(p) && Math[p] === p5.prototype[p]) { + // Multiple p5 methods are just native Math functions. These can be + // called without any binding. + friendlyBindGlobal(p, p5.prototype[p]); + } else { + friendlyBindGlobal(p, p5.prototype[p].bind(this)); + } + } + } else { + friendlyBindGlobal(p, p5.prototype[p]); + } + } + // Attach its properties to the window + for (var p2 in this) { + if (this.hasOwnProperty(p2)) { + friendlyBindGlobal(p2, this[p2]); + } + } + } else { + // Else, the user has passed in a sketch closure that may set + // user-provided 'setup', 'draw', etc. properties on this instance of p5 + sketch(this); + } + + // Bind events to window (not using container div bc key events don't work) + + for (var e in this._events) { + var f = this['_on' + e]; + if (f) { + var m = f.bind(this); + window.addEventListener(e, m, { passive: false }); + this._events[e] = m; + } + } + + var focusHandler = function() { + this._setProperty('focused', true); + }.bind(this); + var blurHandler = function() { + this._setProperty('focused', false); + }.bind(this); + window.addEventListener('focus', focusHandler); + window.addEventListener('blur', blurHandler); + this.registerMethod('remove', function() { + window.removeEventListener('focus', focusHandler); + window.removeEventListener('blur', blurHandler); + }); + + if (document.readyState === 'complete') { + this._start(); + } else { + window.addEventListener('load', this._start.bind(this), false); + } + }; + + p5.prototype._initializeInstanceVariables = function() { + this._styles = []; + + this._bezierDetail = 20; + this._curveDetail = 20; + + this._colorMode = constants.RGB; + this._colorMaxes = { + rgb: [255, 255, 255, 255], + hsb: [360, 100, 100, 1], + hsl: [360, 100, 100, 1] + }; + + this._pixelsDirty = true; + + this._downKeys = {}; //Holds the key codes of currently pressed keys + }; + + // This is a pointer to our global mode p5 instance, if we're in + // global mode. + p5.instance = null; + + /** + * Allows for the friendly error system (FES) to be turned off when creating a sketch, + * which can give a significant boost to performance when needed. + * See + * disabling the friendly error system. + * + * @property {Boolean} disableFriendlyErrors + * @example + *
+ * p5.disableFriendlyErrors = true; + * + * function setup() { + * createCanvas(100, 50); + * } + *
+ */ + p5.disableFriendlyErrors = false; + + // attach constants to p5 prototype + for (var k in constants) { + p5.prototype[k] = constants[k]; + } + + // functions that cause preload to wait + // more can be added by using registerPreloadMethod(func) + p5.prototype._preloadMethods = { + loadJSON: p5.prototype, + loadImage: p5.prototype, + loadStrings: p5.prototype, + loadXML: p5.prototype, + loadBytes: p5.prototype, + loadTable: p5.prototype, + loadFont: p5.prototype, + loadModel: p5.prototype, + loadShader: p5.prototype + }; + + p5.prototype._registeredMethods = { init: [], pre: [], post: [], remove: [] }; + + p5.prototype._registeredPreloadMethods = {}; + + p5.prototype.registerPreloadMethod = function(fnString, obj) { + // obj = obj || p5.prototype; + if (!p5.prototype._preloadMethods.hasOwnProperty(fnString)) { + p5.prototype._preloadMethods[fnString] = obj; + } + }; + + p5.prototype.registerMethod = function(name, m) { + var target = this || p5.prototype; + if (!target._registeredMethods.hasOwnProperty(name)) { + target._registeredMethods[name] = []; + } + target._registeredMethods[name].push(m); + }; + + // create a function which provides a standardized process for binding + // globals; this is implemented as a factory primarily so that there's a + // way to redefine what "global" means for the binding function so it + // can be used in scenarios like unit testing where the window object + // might not exist + p5.prototype._createFriendlyGlobalFunctionBinder = function(options) { + options = options || {}; + + var globalObject = options.globalObject || window; + var log = options.log || console.log.bind(console); + var propsToForciblyOverwrite = { + // p5.print actually always overwrites an existing global function, + // albeit one that is very unlikely to be used: + // + // https://developer.mozilla.org/en-US/docs/Web/API/Window/print + print: true + }; + + return function(prop, value) { + if ( + !p5.disableFriendlyErrors && + typeof IS_MINIFIED === 'undefined' && + typeof value === 'function' && + !(prop in p5.prototype._preloadMethods) + ) { + try { + // Because p5 has so many common function names, it's likely + // that users may accidentally overwrite global p5 functions with + // their own variables. Let's allow this but log a warning to + // help users who may be doing this unintentionally. + // + // For more information, see: + // + // https://github.com/processing/p5.js/issues/1317 + + if (prop in globalObject && !(prop in propsToForciblyOverwrite)) { + throw new Error('global "' + prop + '" already exists'); + } + + // It's possible that this might throw an error because there + // are a lot of edge-cases in which `Object.defineProperty` might + // not succeed; since this functionality is only intended to + // help beginners anyways, we'll just catch such an exception + // if it occurs, and fall back to legacy behavior. + Object.defineProperty(globalObject, prop, { + configurable: true, + enumerable: true, + get: function get() { + return value; + }, + set: function set(newValue) { + Object.defineProperty(globalObject, prop, { + configurable: true, + enumerable: true, + value: newValue, + writable: true + }); + + log( + 'You just changed the value of "' + + prop + + '", which was ' + + "a p5 function. This could cause problems later if you're " + + 'not careful.' + ); + } + }); + } catch (e) { + log( + 'p5 had problems creating the global function "' + + prop + + '", ' + + 'possibly because your code is already using that name as ' + + 'a variable. You may want to rename your variable to something ' + + 'else.' + ); + + globalObject[prop] = value; + } + } else { + globalObject[prop] = value; + } + }; + }; + + module.exports = p5; + }, + { './constants': 18, './shim': 34 } + ], + 25: [ + function(_dereq_, module, exports) { + /** + * @module DOM + * @submodule DOM + * @for p5.Element + */ + + 'use strict'; + + var p5 = _dereq_('./main'); + + /** + * Base class for all elements added to a sketch, including canvas, + * graphics buffers, and other HTML elements. Methods in blue are + * included in the core functionality, methods in brown are added + * with the p5.dom + * library. + * It is not called directly, but p5.Element + * objects are created by calling createCanvas, createGraphics, + * or in the p5.dom library, createDiv, createImg, createInput, etc. + * + * @class p5.Element + * @param {String} elt DOM node that is wrapped + * @param {p5} [pInst] pointer to p5 instance + */ + p5.Element = function(elt, pInst) { + /** + * Underlying HTML element. All normal HTML methods can be called on this. + * @example + *
+ * + * function setup() { + * let c = createCanvas(50, 50); + * c.elt.style.border = '5px solid red'; + * } + * + * function draw() { + * background(220); + * } + * + *
+ * + * @property elt + * @readOnly + */ + this.elt = elt; + this._pInst = this._pixelsState = pInst; + this._events = {}; + this.width = this.elt.offsetWidth; + this.height = this.elt.offsetHeight; + }; + + /** + * + * Attaches the element to the parent specified. A way of setting + * the container for the element. Accepts either a string ID, DOM + * node, or p5.Element. If no arguments given, parent node is returned. + * For more ways to position the canvas, see the + * + * positioning the canvas wiki page. + * + * All above examples except for the first one require the inclusion of + * the p5.dom library in your index.html. See the + * using a library + * section for information on how to include this library. + * + * @method parent + * @param {String|p5.Element|Object} parent the ID, DOM node, or p5.Element + * of desired parent element + * @chainable + * + * @example + *
+ * // in the html file: + * // <div id="myContainer"></div> + * + * // in the js file: + * let cnv = createCanvas(100, 100); + * cnv.parent('myContainer'); + *
+ *
+ * let div0 = createDiv('this is the parent'); + * let div1 = createDiv('this is the child'); + * div1.parent(div0); // use p5.Element + *
+ *
+ * let div0 = createDiv('this is the parent'); + * div0.id('apples'); + * let div1 = createDiv('this is the child'); + * div1.parent('apples'); // use id + *
+ *
+ * let elt = document.getElementById('myParentDiv'); + * let div1 = createDiv('this is the child'); + * div1.parent(elt); // use element from page + *
+ * + * @alt + * no display. + */ + /** + * @method parent + * @return {p5.Element} + * + */ + p5.Element.prototype.parent = function(p) { + if (typeof p === 'undefined') { + return this.elt.parentNode; + } + + if (typeof p === 'string') { + if (p[0] === '#') { + p = p.substring(1); + } + p = document.getElementById(p); + } else if (p instanceof p5.Element) { + p = p.elt; + } + p.appendChild(this.elt); + return this; + }; + + /** + * + * Sets the ID of the element. If no ID argument is passed in, it instead + * returns the current ID of the element. + * Note that only one element can have a particular id in a page. + * The .class() function can be used + * to identify multiple elements with the same class name. + * + * @method id + * @param {String} id ID of the element + * @chainable + * + * @example + *
+ * function setup() { + * let cnv = createCanvas(100, 100); + * // Assigns a CSS selector ID to + * // the canvas element. + * cnv.id('mycanvas'); + * } + *
+ * + * @alt + * no display. + */ + /** + * @method id + * @return {String} the id of the element + */ + p5.Element.prototype.id = function(id) { + if (typeof id === 'undefined') { + return this.elt.id; + } + + this.elt.id = id; + this.width = this.elt.offsetWidth; + this.height = this.elt.offsetHeight; + return this; + }; + + /** + * + * Adds given class to the element. If no class argument is passed in, it + * instead returns a string containing the current class(es) of the element. + * + * @method class + * @param {String} class class to add + * @chainable + * + * @example + *
+ * function setup() { + * let cnv = createCanvas(100, 100); + * // Assigns a CSS selector class 'small' + * // to the canvas element. + * cnv.class('small'); + * } + *
+ * + * @alt + * no display. + */ + /** + * @method class + * @return {String} the class of the element + */ + p5.Element.prototype.class = function(c) { + if (typeof c === 'undefined') { + return this.elt.className; + } + + this.elt.className = c; + return this; + }; + + /** + * The .mousePressed() function is called once after every time a + * mouse button is pressed over the element. + * Some mobile browsers may also trigger this event on a touch screen, + * if the user performs a quick tap. + * This can be used to attach element specific event listeners. + * + * @method mousePressed + * @param {Function|Boolean} fxn function to be fired when mouse is + * pressed over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let d; + * let g; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.mousePressed(changeGray); // attach listener for + * // canvas click only + * d = 10; + * g = 100; + * } + * + * function draw() { + * background(g); + * ellipse(width / 2, height / 2, d, d); + * } + * + * // this function fires with any click anywhere + * function mousePressed() { + * d = d + 10; + * } + * + * // this function fires only when cnv is clicked + * function changeGray() { + * g = random(0, 255); + * } + *
+ * + * @alt + * no display. + * + */ + p5.Element.prototype.mousePressed = function(fxn) { + // Prepend the mouse property setters to the event-listener. + // This is required so that mouseButton is set correctly prior to calling the callback (fxn). + // For details, see https://github.com/processing/p5.js/issues/3087. + var eventPrependedFxn = function eventPrependedFxn(event) { + this._pInst._setProperty('mouseIsPressed', true); + this._pInst._setMouseButton(event); + // Pass along the return-value of the callback: + return fxn.call(this); + }; + // Pass along the event-prepended form of the callback. + p5.Element._adjustListener('mousedown', eventPrependedFxn, this); + return this; + }; + + /** + * The .doubleClicked() function is called once after every time a + * mouse button is pressed twice over the element. This can be used to + * attach element and action specific event listeners. + * + * @method doubleClicked + * @param {Function|Boolean} fxn function to be fired when mouse is + * double clicked over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @return {p5.Element} + * @example + *
+ * let cnv; + * let d; + * let g; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.doubleClicked(changeGray); // attach listener for + * // canvas double click only + * d = 10; + * g = 100; + * } + * + * function draw() { + * background(g); + * ellipse(width / 2, height / 2, d, d); + * } + * + * // this function fires with any double click anywhere + * function doubleClicked() { + * d = d + 10; + * } + * + * // this function fires only when cnv is double clicked + * function changeGray() { + * g = random(0, 255); + * } + *
+ * + * @alt + * no display. + * + */ + p5.Element.prototype.doubleClicked = function(fxn) { + p5.Element._adjustListener('dblclick', fxn, this); + return this; + }; + + /** + * The .mouseWheel() function is called once after every time a + * mouse wheel is scrolled over the element. This can be used to + * attach element specific event listeners. + *

+ * The function accepts a callback function as argument which will be executed + * when the `wheel` event is triggered on the element, the callback function is + * passed one argument `event`. The `event.deltaY` property returns negative + * values if the mouse wheel is rotated up or away from the user and positive + * in the other direction. The `event.deltaX` does the same as `event.deltaY` + * except it reads the horizontal wheel scroll of the mouse wheel. + *

+ * On OS X with "natural" scrolling enabled, the `event.deltaY` values are + * reversed. + * + * @method mouseWheel + * @param {Function|Boolean} fxn function to be fired when mouse is + * scrolled over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let d; + * let g; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.mouseWheel(changeSize); // attach listener for + * // activity on canvas only + * d = 10; + * g = 100; + * } + * + * function draw() { + * background(g); + * ellipse(width / 2, height / 2, d, d); + * } + * + * // this function fires with mousewheel movement + * // anywhere on screen + * function mouseWheel() { + * g = g + 10; + * } + * + * // this function fires with mousewheel movement + * // over canvas only + * function changeSize(event) { + * if (event.deltaY > 0) { + * d = d + 10; + * } else { + * d = d - 10; + * } + * } + *
+ * + * + * @alt + * no display. + * + */ + p5.Element.prototype.mouseWheel = function(fxn) { + p5.Element._adjustListener('wheel', fxn, this); + return this; + }; + + /** + * The .mouseReleased() function is called once after every time a + * mouse button is released over the element. + * Some mobile browsers may also trigger this event on a touch screen, + * if the user performs a quick tap. + * This can be used to attach element specific event listeners. + * + * @method mouseReleased + * @param {Function|Boolean} fxn function to be fired when mouse is + * released over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let d; + * let g; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.mouseReleased(changeGray); // attach listener for + * // activity on canvas only + * d = 10; + * g = 100; + * } + * + * function draw() { + * background(g); + * ellipse(width / 2, height / 2, d, d); + * } + * + * // this function fires after the mouse has been + * // released + * function mouseReleased() { + * d = d + 10; + * } + * + * // this function fires after the mouse has been + * // released while on canvas + * function changeGray() { + * g = random(0, 255); + * } + *
+ * + * + * @alt + * no display. + * + */ + p5.Element.prototype.mouseReleased = function(fxn) { + p5.Element._adjustListener('mouseup', fxn, this); + return this; + }; + + /** + * The .mouseClicked() function is called once after a mouse button is + * pressed and released over the element. + * Some mobile browsers may also trigger this event on a touch screen, + * if the user performs a quick tap. + * This can be used to attach element specific event listeners. + * + * @method mouseClicked + * @param {Function|Boolean} fxn function to be fired when mouse is + * clicked over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * + * let cnv; + * let d; + * let g; + * + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.mouseClicked(changeGray); // attach listener for + * // activity on canvas only + * d = 10; + * g = 100; + * } + * + * function draw() { + * background(g); + * ellipse(width / 2, height / 2, d, d); + * } + * + * // this function fires after the mouse has been + * // clicked anywhere + * function mouseClicked() { + * d = d + 10; + * } + * + * // this function fires after the mouse has been + * // clicked on canvas + * function changeGray() { + * g = random(0, 255); + * } + * + *
+ * + * @alt + * no display. + * + */ + p5.Element.prototype.mouseClicked = function(fxn) { + p5.Element._adjustListener('click', fxn, this); + return this; + }; + + /** + * The .mouseMoved() function is called once every time a + * mouse moves over the element. This can be used to attach an + * element specific event listener. + * + * @method mouseMoved + * @param {Function|Boolean} fxn function to be fired when a mouse moves + * over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let d = 30; + * let g; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.mouseMoved(changeSize); // attach listener for + * // activity on canvas only + * d = 10; + * g = 100; + * } + * + * function draw() { + * background(g); + * fill(200); + * ellipse(width / 2, height / 2, d, d); + * } + * + * // this function fires when mouse moves anywhere on + * // page + * function mouseMoved() { + * g = g + 5; + * if (g > 255) { + * g = 0; + * } + * } + * + * // this function fires when mouse moves over canvas + * function changeSize() { + * d = d + 2; + * if (d > 100) { + * d = 0; + * } + * } + *
+ * + * + * @alt + * no display. + * + */ + p5.Element.prototype.mouseMoved = function(fxn) { + p5.Element._adjustListener('mousemove', fxn, this); + return this; + }; + + /** + * The .mouseOver() function is called once after every time a + * mouse moves onto the element. This can be used to attach an + * element specific event listener. + * + * @method mouseOver + * @param {Function|Boolean} fxn function to be fired when a mouse moves + * onto the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let d; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.mouseOver(changeGray); + * d = 10; + * } + * + * function draw() { + * ellipse(width / 2, height / 2, d, d); + * } + * + * function changeGray() { + * d = d + 10; + * if (d > 100) { + * d = 0; + * } + * } + *
+ * + * + * @alt + * no display. + * + */ + p5.Element.prototype.mouseOver = function(fxn) { + p5.Element._adjustListener('mouseover', fxn, this); + return this; + }; + + /** + * The .mouseOut() function is called once after every time a + * mouse moves off the element. This can be used to attach an + * element specific event listener. + * + * @method mouseOut + * @param {Function|Boolean} fxn function to be fired when a mouse + * moves off of an element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let d; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.mouseOut(changeGray); + * d = 10; + * } + * + * function draw() { + * ellipse(width / 2, height / 2, d, d); + * } + * + * function changeGray() { + * d = d + 10; + * if (d > 100) { + * d = 0; + * } + * } + *
+ * + * @alt + * no display. + * + */ + p5.Element.prototype.mouseOut = function(fxn) { + p5.Element._adjustListener('mouseout', fxn, this); + return this; + }; + + /** + * The .touchStarted() function is called once after every time a touch is + * registered. This can be used to attach element specific event listeners. + * + * @method touchStarted + * @param {Function|Boolean} fxn function to be fired when a touch + * starts over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let d; + * let g; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.touchStarted(changeGray); // attach listener for + * // canvas click only + * d = 10; + * g = 100; + * } + * + * function draw() { + * background(g); + * ellipse(width / 2, height / 2, d, d); + * } + * + * // this function fires with any touch anywhere + * function touchStarted() { + * d = d + 10; + * } + * + * // this function fires only when cnv is clicked + * function changeGray() { + * g = random(0, 255); + * } + *
+ * + * @alt + * no display. + * + */ + p5.Element.prototype.touchStarted = function(fxn) { + p5.Element._adjustListener('touchstart', fxn, this); + return this; + }; + + /** + * The .touchMoved() function is called once after every time a touch move is + * registered. This can be used to attach element specific event listeners. + * + * @method touchMoved + * @param {Function|Boolean} fxn function to be fired when a touch moves over + * the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let g; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.touchMoved(changeGray); // attach listener for + * // canvas click only + * g = 100; + * } + * + * function draw() { + * background(g); + * } + * + * // this function fires only when cnv is clicked + * function changeGray() { + * g = random(0, 255); + * } + *
+ * + * @alt + * no display. + * + */ + p5.Element.prototype.touchMoved = function(fxn) { + p5.Element._adjustListener('touchmove', fxn, this); + return this; + }; + + /** + * The .touchEnded() function is called once after every time a touch is + * registered. This can be used to attach element specific event listeners. + * + * @method touchEnded + * @param {Function|Boolean} fxn function to be fired when a touch ends + * over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * let cnv; + * let d; + * let g; + * function setup() { + * cnv = createCanvas(100, 100); + * cnv.touchEnded(changeGray); // attach listener for + * // canvas click only + * d = 10; + * g = 100; + * } + * + * function draw() { + * background(g); + * ellipse(width / 2, height / 2, d, d); + * } + * + * // this function fires with any touch anywhere + * function touchEnded() { + * d = d + 10; + * } + * + * // this function fires only when cnv is clicked + * function changeGray() { + * g = random(0, 255); + * } + *
+ * + * + * @alt + * no display. + * + */ + p5.Element.prototype.touchEnded = function(fxn) { + p5.Element._adjustListener('touchend', fxn, this); + return this; + }; + + /** + * The .dragOver() function is called once after every time a + * file is dragged over the element. This can be used to attach an + * element specific event listener. + * + * @method dragOver + * @param {Function|Boolean} fxn function to be fired when a file is + * dragged over the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * // To test this sketch, simply drag a + * // file over the canvas + * function setup() { + * let c = createCanvas(100, 100); + * background(200); + * textAlign(CENTER); + * text('Drag file', width / 2, height / 2); + * c.dragOver(dragOverCallback); + * } + * + * // This function will be called whenever + * // a file is dragged over the canvas + * function dragOverCallback() { + * background(240); + * text('Dragged over', width / 2, height / 2); + * } + *
+ * @alt + * nothing displayed + */ + p5.Element.prototype.dragOver = function(fxn) { + p5.Element._adjustListener('dragover', fxn, this); + return this; + }; + + /** + * The .dragLeave() function is called once after every time a + * dragged file leaves the element area. This can be used to attach an + * element specific event listener. + * + * @method dragLeave + * @param {Function|Boolean} fxn function to be fired when a file is + * dragged off the element. + * if `false` is passed instead, the previously + * firing function will no longer fire. + * @chainable + * @example + *
+ * // To test this sketch, simply drag a file + * // over and then out of the canvas area + * function setup() { + * let c = createCanvas(100, 100); + * background(200); + * textAlign(CENTER); + * text('Drag file', width / 2, height / 2); + * c.dragLeave(dragLeaveCallback); + * } + * + * // This function will be called whenever + * // a file is dragged out of the canvas + * function dragLeaveCallback() { + * background(240); + * text('Dragged off', width / 2, height / 2); + * } + *
+ * @alt + * nothing displayed + */ + p5.Element.prototype.dragLeave = function(fxn) { + p5.Element._adjustListener('dragleave', fxn, this); + return this; + }; + + // General handler for event attaching and detaching + p5.Element._adjustListener = function(ev, fxn, ctx) { + if (fxn === false) { + p5.Element._detachListener(ev, ctx); + } else { + p5.Element._attachListener(ev, fxn, ctx); + } + return this; + }; + + p5.Element._attachListener = function(ev, fxn, ctx) { + // detach the old listener if there was one + if (ctx._events[ev]) { + p5.Element._detachListener(ev, ctx); + } + var f = fxn.bind(ctx); + ctx.elt.addEventListener(ev, f, false); + ctx._events[ev] = f; + }; + + p5.Element._detachListener = function(ev, ctx) { + var f = ctx._events[ev]; + ctx.elt.removeEventListener(ev, f, false); + ctx._events[ev] = null; + }; + + /** + * Helper fxn for sharing pixel methods + * + */ + p5.Element.prototype._setProperty = function(prop, value) { + this[prop] = value; + }; + + module.exports = p5.Element; + }, + { './main': 24 } + ], + 26: [ + function(_dereq_, module, exports) { + /** + * @module Rendering + * @submodule Rendering + * @for p5 + */ + + 'use strict'; + + var p5 = _dereq_('./main'); + var constants = _dereq_('./constants'); + + /** + * Thin wrapper around a renderer, to be used for creating a + * graphics buffer object. Use this class if you need + * to draw into an off-screen graphics buffer. The two parameters define the + * width and height in pixels. The fields and methods for this class are + * extensive, but mirror the normal drawing API for p5. + * + * @class p5.Graphics + * @extends p5.Element + * @param {Number} w width + * @param {Number} h height + * @param {Constant} renderer the renderer to use, either P2D or WEBGL + * @param {p5} [pInst] pointer to p5 instance + */ + p5.Graphics = function(w, h, renderer, pInst) { + var r = renderer || constants.P2D; + + this.canvas = document.createElement('canvas'); + var node = pInst._userNode || document.body; + node.appendChild(this.canvas); + + p5.Element.call(this, this.canvas, pInst); + + // bind methods and props of p5 to the new object + for (var p in p5.prototype) { + if (!this[p]) { + if (typeof p5.prototype[p] === 'function') { + this[p] = p5.prototype[p].bind(this); + } else { + this[p] = p5.prototype[p]; + } + } + } + + p5.prototype._initializeInstanceVariables.apply(this); + this.width = w; + this.height = h; + this._pixelDensity = pInst._pixelDensity; + + if (r === constants.WEBGL) { + this._renderer = new p5.RendererGL(this.canvas, this, false); + } else { + this._renderer = new p5.Renderer2D(this.canvas, this, false); + } + pInst._elements.push(this); + + this._renderer.resize(w, h); + this._renderer._applyDefaults(); + return this; + }; + + p5.Graphics.prototype = Object.create(p5.Element.prototype); + + /** + * Resets certain values such as those modified by functions in the Transform category + * and in the Lights category that are not automatically reset + * with graphics buffer objects. Calling this in draw() will copy the behavior + * of the standard canvas. + * + * @method reset + * @example + * + *
+ * let pg; + * function setup() { + * createCanvas(100, 100); + * background(0); + * pg = createGraphics(50, 100); + * pg.fill(0); + * frameRate(5); + * } + * function draw() { + * image(pg, width / 2, 0); + * pg.background(255); + * // p5.Graphics object behave a bit differently in some cases + * // The normal canvas on the left resets the translate + * // with every loop through draw() + * // the graphics object on the right doesn't automatically reset + * // so translate() is additive and it moves down the screen + * rect(0, 0, width / 2, 5); + * pg.rect(0, 0, width / 2, 5); + * translate(0, 5, 0); + * pg.translate(0, 5, 0); + * } + * function mouseClicked() { + * // if you click you will see that + * // reset() resets the translate back to the initial state + * // of the Graphics object + * pg.reset(); + * } + *
+ * + * @alt + * A white line on a black background stays still on the top-left half. + * A black line animates from top to bottom on a white background on the right half. + * When clicked, the black line starts back over at the top. + * + */ + p5.Graphics.prototype.reset = function() { + this._renderer.resetMatrix(); + if (this._renderer.isP3D) { + this._renderer._update(); + } + }; + + /** + * Removes a Graphics object from the page and frees any resources + * associated with it. + * + * @method remove + * + * @example + *
+ * let bg; + * function setup() { + * bg = createCanvas(100, 100); + * bg.background(0); + * image(bg, 0, 0); + * bg.remove(); + * } + *
+ * + *
+ * let bg; + * function setup() { + * pixelDensity(1); + * createCanvas(100, 100); + * stroke(255); + * fill(0); + * + * // create and draw the background image + * bg = createGraphics(100, 100); + * bg.background(200); + * bg.ellipse(50, 50, 80, 80); + * } + * function draw() { + * let t = millis() / 1000; + * // draw the background + * if (bg) { + * image(bg, frameCount % 100, 0); + * image(bg, frameCount % 100 - 100, 0); + * } + * // draw the foreground + * let p = p5.Vector.fromAngle(t, 35).add(50, 50); + * ellipse(p.x, p.y, 30); + * } + * function mouseClicked() { + * // remove the background + * if (bg) { + * bg.remove(); + * bg = null; + * } + * } + *
+ * + * @alt + * no image + * a multi-colored circle moving back and forth over a scrolling background. + * + */ + p5.Graphics.prototype.remove = function() { + if (this.elt.parentNode) { + this.elt.parentNode.removeChild(this.elt); + } + var idx = this._pInst._elements.indexOf(this); + if (idx !== -1) { + this._pInst._elements.splice(idx, 1); + } + for (var elt_ev in this._events) { + this.elt.removeEventListener(elt_ev, this._events[elt_ev]); + } + }; + + module.exports = p5.Graphics; + }, + { './constants': 18, './main': 24 } + ], + 27: [ + function(_dereq_, module, exports) { + /** + * @module Rendering + * @submodule Rendering + * @for p5 + */ + + 'use strict'; + function _typeof(obj) { + if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { + _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + _typeof = function _typeof(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : typeof obj; + }; + } + return _typeof(obj); + } + + var p5 = _dereq_('./main'); + var constants = _dereq_('../core/constants'); + + /** + * Main graphics and rendering context, as well as the base API + * implementation for p5.js "core". To be used as the superclass for + * Renderer2D and Renderer3D classes, respecitvely. + * + * @class p5.Renderer + * @constructor + * @extends p5.Element + * @param {String} elt DOM node that is wrapped + * @param {p5} [pInst] pointer to p5 instance + * @param {Boolean} [isMainCanvas] whether we're using it as main canvas + */ + p5.Renderer = function(elt, pInst, isMainCanvas) { + p5.Element.call(this, elt, pInst); + this.canvas = elt; + this._pixelsState = pInst; + if (isMainCanvas) { + this._isMainCanvas = true; + // for pixel method sharing with pimage + this._pInst._setProperty('_curElement', this); + this._pInst._setProperty('canvas', this.canvas); + this._pInst._setProperty('width', this.width); + this._pInst._setProperty('height', this.height); + } else { + // hide if offscreen buffer by default + this.canvas.style.display = 'none'; + this._styles = []; // non-main elt styles stored in p5.Renderer + } + + this._textSize = 12; + this._textLeading = 15; + this._textFont = 'sans-serif'; + this._textStyle = constants.NORMAL; + this._textAscent = null; + this._textDescent = null; + this._textAlign = constants.LEFT; + this._textBaseline = constants.BASELINE; + + this._rectMode = constants.CORNER; + this._ellipseMode = constants.CENTER; + this._curveTightness = 0; + this._imageMode = constants.CORNER; + + this._tint = null; + this._doStroke = true; + this._doFill = true; + this._strokeSet = false; + this._fillSet = false; + }; + + p5.Renderer.prototype = Object.create(p5.Element.prototype); + + // the renderer should return a 'style' object that it wishes to + // store on the push stack. + p5.Renderer.prototype.push = function() { + return { + properties: { + _doStroke: this._doStroke, + _strokeSet: this._strokeSet, + _doFill: this._doFill, + _fillSet: this._fillSet, + _tint: this._tint, + _imageMode: this._imageMode, + _rectMode: this._rectMode, + _ellipseMode: this._ellipseMode, + _textFont: this._textFont, + _textLeading: this._textLeading, + _textSize: this._textSize, + _textAlign: this._textAlign, + _textBaseline: this._textBaseline, + _textStyle: this._textStyle + } + }; + }; + + // a pop() operation is in progress + // the renderer is passed the 'style' object that it returned + // from its push() method. + p5.Renderer.prototype.pop = function(style) { + if (style.properties) { + // copy the style properties back into the renderer + Object.assign(this, style.properties); + } + }; + + /** + * Resize our canvas element. + */ + p5.Renderer.prototype.resize = function(w, h) { + this.width = w; + this.height = h; + this.elt.width = w * this._pInst._pixelDensity; + this.elt.height = h * this._pInst._pixelDensity; + this.elt.style.width = w + 'px'; + this.elt.style.height = h + 'px'; + if (this._isMainCanvas) { + this._pInst._setProperty('width', this.width); + this._pInst._setProperty('height', this.height); + } + }; + + p5.Renderer.prototype.get = function(x, y, w, h) { + var pixelsState = this._pixelsState; + var pd = pixelsState._pixelDensity; + var canvas = this.canvas; + + if (typeof x === 'undefined' && typeof y === 'undefined') { + // get() + x = y = 0; + w = pixelsState.width; + h = pixelsState.height; + } else { + x *= pd; + y *= pd; + + if (typeof w === 'undefined' && typeof h === 'undefined') { + // get(x,y) + if (x < 0 || y < 0 || x >= canvas.width || y >= canvas.height) { + return [0, 0, 0, 0]; + } + + return this._getPixel(x, y); + } + // get(x,y,w,h) + } + + var region = new p5.Image(w, h); + region.canvas + .getContext('2d') + .drawImage(canvas, x, y, w * pd, h * pd, 0, 0, w, h); + + return region; + }; + + p5.Renderer.prototype.textLeading = function(l) { + if (typeof l === 'number') { + this._setProperty('_textLeading', l); + return this._pInst; + } + + return this._textLeading; + }; + + p5.Renderer.prototype.textSize = function(s) { + if (typeof s === 'number') { + this._setProperty('_textSize', s); + this._setProperty('_textLeading', s * constants._DEFAULT_LEADMULT); + return this._applyTextProperties(); + } + + return this._textSize; + }; + + p5.Renderer.prototype.textStyle = function(s) { + if (s) { + if ( + s === constants.NORMAL || + s === constants.ITALIC || + s === constants.BOLD || + s === constants.BOLDITALIC + ) { + this._setProperty('_textStyle', s); + } + + return this._applyTextProperties(); + } + + return this._textStyle; + }; + + p5.Renderer.prototype.textAscent = function() { + if (this._textAscent === null) { + this._updateTextMetrics(); + } + return this._textAscent; + }; + + p5.Renderer.prototype.textDescent = function() { + if (this._textDescent === null) { + this._updateTextMetrics(); + } + return this._textDescent; + }; + + p5.Renderer.prototype.textAlign = function(h, v) { + if (typeof h !== 'undefined') { + this._setProperty('_textAlign', h); + + if (typeof v !== 'undefined') { + this._setProperty('_textBaseline', v); + } + + return this._applyTextProperties(); + } else { + return { + horizontal: this._textAlign, + vertical: this._textBaseline + }; + } + }; + + p5.Renderer.prototype.text = function(str, x, y, maxWidth, maxHeight) { + var p = this._pInst, + cars, + n, + ii, + jj, + line, + testLine, + testWidth, + words, + totalHeight, + finalMaxHeight = Number.MAX_VALUE; + + if (!(this._doFill || this._doStroke)) { + return; + } + + if (typeof str === 'undefined') { + return; + } else if (typeof str !== 'string') { + str = str.toString(); + } + + str = str.replace(/(\t)/g, ' '); + cars = str.split('\n'); + + if (typeof maxWidth !== 'undefined') { + totalHeight = 0; + for (ii = 0; ii < cars.length; ii++) { + line = ''; + words = cars[ii].split(' '); + for (n = 0; n < words.length; n++) { + testLine = line + words[n] + ' '; + testWidth = this.textWidth(testLine); + if (testWidth > maxWidth) { + line = words[n] + ' '; + totalHeight += p.textLeading(); + } else { + line = testLine; + } + } + } + + if (this._rectMode === constants.CENTER) { + x -= maxWidth / 2; + y -= maxHeight / 2; + } + + switch (this._textAlign) { + case constants.CENTER: + x += maxWidth / 2; + break; + case constants.RIGHT: + x += maxWidth; + break; + } + + var baselineHacked = false; + if (typeof maxHeight !== 'undefined') { + switch (this._textBaseline) { + case constants.BOTTOM: + y += maxHeight - totalHeight; + break; + case constants.CENTER: + y += (maxHeight - totalHeight) / 2; + break; + case constants.BASELINE: + baselineHacked = true; + this._textBaseline = constants.TOP; + break; + } + + // remember the max-allowed y-position for any line (fix to #928) + finalMaxHeight = y + maxHeight - p.textAscent(); + } + + for (ii = 0; ii < cars.length; ii++) { + line = ''; + words = cars[ii].split(' '); + for (n = 0; n < words.length; n++) { + testLine = line + words[n] + ' '; + testWidth = this.textWidth(testLine); + if (testWidth > maxWidth && line.length > 0) { + this._renderText(p, line, x, y, finalMaxHeight); + line = words[n] + ' '; + y += p.textLeading(); + } else { + line = testLine; + } + } + + this._renderText(p, line, x, y, finalMaxHeight); + y += p.textLeading(); + + if (baselineHacked) { + this._textBaseline = constants.BASELINE; + } + } + } else { + // Offset to account for vertically centering multiple lines of text - no + // need to adjust anything for vertical align top or baseline + var offset = 0, + vAlign = p.textAlign().vertical; + if (vAlign === constants.CENTER) { + offset = (cars.length - 1) * p.textLeading() / 2; + } else if (vAlign === constants.BOTTOM) { + offset = (cars.length - 1) * p.textLeading(); + } + + for (jj = 0; jj < cars.length; jj++) { + this._renderText(p, cars[jj], x, y - offset, finalMaxHeight); + y += p.textLeading(); + } + } + + return p; + }; + + p5.Renderer.prototype._applyDefaults = function() { + return this; + }; + + /** + * Helper fxn to check font type (system or otf) + */ + p5.Renderer.prototype._isOpenType = function(f) { + f = f || this._textFont; + return _typeof(f) === 'object' && f.font && f.font.supported; + }; + + p5.Renderer.prototype._updateTextMetrics = function() { + if (this._isOpenType()) { + this._setProperty('_textAscent', this._textFont._textAscent()); + this._setProperty('_textDescent', this._textFont._textDescent()); + return this; + } + + // Adapted from http://stackoverflow.com/a/25355178 + var text = document.createElement('span'); + text.style.fontFamily = this._textFont; + text.style.fontSize = this._textSize + 'px'; + text.innerHTML = 'ABCjgq|'; + + var block = document.createElement('div'); + block.style.display = 'inline-block'; + block.style.width = '1px'; + block.style.height = '0px'; + + var container = document.createElement('div'); + container.appendChild(text); + container.appendChild(block); + + container.style.height = '0px'; + container.style.overflow = 'hidden'; + document.body.appendChild(container); + + block.style.verticalAlign = 'baseline'; + var blockOffset = calculateOffset(block); + var textOffset = calculateOffset(text); + var ascent = blockOffset[1] - textOffset[1]; + + block.style.verticalAlign = 'bottom'; + blockOffset = calculateOffset(block); + textOffset = calculateOffset(text); + var height = blockOffset[1] - textOffset[1]; + var descent = height - ascent; + + document.body.removeChild(container); + + this._setProperty('_textAscent', ascent); + this._setProperty('_textDescent', descent); + + return this; + }; + + /** + * Helper fxn to measure ascent and descent. + * Adapted from http://stackoverflow.com/a/25355178 + */ + function calculateOffset(object) { + var currentLeft = 0, + currentTop = 0; + if (object.offsetParent) { + do { + currentLeft += object.offsetLeft; + currentTop += object.offsetTop; + } while ((object = object.offsetParent)); + } else { + currentLeft += object.offsetLeft; + currentTop += object.offsetTop; + } + return [currentLeft, currentTop]; + } + + module.exports = p5.Renderer; + }, + { '../core/constants': 18, './main': 24 } + ], + 28: [ + function(_dereq_, module, exports) { + 'use strict'; + + var p5 = _dereq_('./main'); + var constants = _dereq_('./constants'); + var filters = _dereq_('../image/filters'); + + _dereq_('./p5.Renderer'); + + /** + * p5.Renderer2D + * The 2D graphics canvas renderer class. + * extends p5.Renderer + */ + var styleEmpty = 'rgba(0,0,0,0)'; + // var alphaThreshold = 0.00125; // minimum visible + + p5.Renderer2D = function(elt, pInst, isMainCanvas) { + p5.Renderer.call(this, elt, pInst, isMainCanvas); + this.drawingContext = this.canvas.getContext('2d'); + this._pInst._setProperty('drawingContext', this.drawingContext); + return this; + }; + + p5.Renderer2D.prototype = Object.create(p5.Renderer.prototype); + + p5.Renderer2D.prototype._applyDefaults = function() { + this._cachedFillStyle = this._cachedStrokeStyle = undefined; + this._setFill(constants._DEFAULT_FILL); + this._setStroke(constants._DEFAULT_STROKE); + this.drawingContext.lineCap = constants.ROUND; + this.drawingContext.font = 'normal 12px sans-serif'; + }; + + p5.Renderer2D.prototype.resize = function(w, h) { + p5.Renderer.prototype.resize.call(this, w, h); + this.drawingContext.scale(this._pInst._pixelDensity, this._pInst._pixelDensity); + }; + + ////////////////////////////////////////////// + // COLOR | Setting + ////////////////////////////////////////////// + + p5.Renderer2D.prototype.background = function() { + this.drawingContext.save(); + this.resetMatrix(); + + if (arguments[0] instanceof p5.Image) { + this._pInst.image(arguments[0], 0, 0, this.width, this.height); + } else { + var curFill = this._getFill(); + // create background rect + var color = this._pInst.color.apply(this._pInst, arguments); + var newFill = color.toString(); + this._setFill(newFill); + this.drawingContext.fillRect(0, 0, this.width, this.height); + // reset fill + this._setFill(curFill); + } + this.drawingContext.restore(); + + this._pixelsState._pixelsDirty = true; + }; + + p5.Renderer2D.prototype.clear = function() { + this.drawingContext.save(); + this.resetMatrix(); + this.drawingContext.clearRect(0, 0, this.width, this.height); + this.drawingContext.restore(); + + this._pixelsState._pixelsDirty = true; + }; + + p5.Renderer2D.prototype.fill = function() { + var color = this._pInst.color.apply(this._pInst, arguments); + this._setFill(color.toString()); + }; + + p5.Renderer2D.prototype.stroke = function() { + var color = this._pInst.color.apply(this._pInst, arguments); + this._setStroke(color.toString()); + }; + + ////////////////////////////////////////////// + // IMAGE | Loading & Displaying + ////////////////////////////////////////////// + + p5.Renderer2D.prototype.image = function( + img, + sx, + sy, + sWidth, + sHeight, + dx, + dy, + dWidth, + dHeight + ) { + var cnv; + try { + if (this._tint) { + if (p5.MediaElement && img instanceof p5.MediaElement) { + img.loadPixels(); + } + if (img.canvas) { + cnv = this._getTintedImageCanvas(img); + } + } + if (!cnv) { + cnv = img.canvas || img.elt; + } + var s = 1; + if (img.width && img.width > 0) { + s = cnv.width / img.width; + } + this.drawingContext.drawImage( + cnv, + s * sx, + s * sy, + s * sWidth, + s * sHeight, + dx, + dy, + dWidth, + dHeight + ); + } catch (e) { + if (e.name !== 'NS_ERROR_NOT_AVAILABLE') { + throw e; + } + } + + this._pixelsState._pixelsDirty = true; + }; + + p5.Renderer2D.prototype._getTintedImageCanvas = function(img) { + if (!img.canvas) { + return img; + } + var pixels = filters._toPixels(img.canvas); + var tmpCanvas = document.createElement('canvas'); + tmpCanvas.width = img.canvas.width; + tmpCanvas.height = img.canvas.height; + var tmpCtx = tmpCanvas.getContext('2d'); + var id = tmpCtx.createImageData(img.canvas.width, img.canvas.height); + var newPixels = id.data; + for (var i = 0; i < pixels.length; i += 4) { + var r = pixels[i]; + var g = pixels[i + 1]; + var b = pixels[i + 2]; + var a = pixels[i + 3]; + newPixels[i] = r * this._tint[0] / 255; + newPixels[i + 1] = g * this._tint[1] / 255; + newPixels[i + 2] = b * this._tint[2] / 255; + newPixels[i + 3] = a * this._tint[3] / 255; + } + tmpCtx.putImageData(id, 0, 0); + return tmpCanvas; + }; + + ////////////////////////////////////////////// + // IMAGE | Pixels + ////////////////////////////////////////////// + + p5.Renderer2D.prototype.blendMode = function(mode) { + if (mode === constants.SUBTRACT) { + console.warn('blendMode(SUBTRACT) only works in WEBGL mode.'); + } else if ( + mode === constants.BLEND || + mode === constants.DARKEST || + mode === constants.LIGHTEST || + mode === constants.DIFFERENCE || + mode === constants.MULTIPLY || + mode === constants.EXCLUSION || + mode === constants.SCREEN || + mode === constants.REPLACE || + mode === constants.OVERLAY || + mode === constants.HARD_LIGHT || + mode === constants.SOFT_LIGHT || + mode === constants.DODGE || + mode === constants.BURN || + mode === constants.ADD + ) { + this.drawingContext.globalCompositeOperation = mode; + } else { + throw new Error('Mode ' + mode + ' not recognized.'); + } + }; + + p5.Renderer2D.prototype.blend = function() { + var currBlend = this.drawingContext.globalCompositeOperation; + var blendMode = arguments[arguments.length - 1]; + + var copyArgs = Array.prototype.slice.call(arguments, 0, arguments.length - 1); + + this.drawingContext.globalCompositeOperation = blendMode; + if (this._pInst) { + this._pInst.copy.apply(this._pInst, copyArgs); + } else { + this.copy.apply(this, copyArgs); + } + this.drawingContext.globalCompositeOperation = currBlend; + }; + + p5.Renderer2D.prototype.copy = function() { + var srcImage, sx, sy, sw, sh, dx, dy, dw, dh; + if (arguments.length === 9) { + srcImage = arguments[0]; + sx = arguments[1]; + sy = arguments[2]; + sw = arguments[3]; + sh = arguments[4]; + dx = arguments[5]; + dy = arguments[6]; + dw = arguments[7]; + dh = arguments[8]; + } else if (arguments.length === 8) { + srcImage = this._pInst; + sx = arguments[0]; + sy = arguments[1]; + sw = arguments[2]; + sh = arguments[3]; + dx = arguments[4]; + dy = arguments[5]; + dw = arguments[6]; + dh = arguments[7]; + } else { + throw new Error('Signature not supported'); + } + p5.Renderer2D._copyHelper(this, srcImage, sx, sy, sw, sh, dx, dy, dw, dh); + + this._pixelsState._pixelsDirty = true; + }; + + p5.Renderer2D._copyHelper = function( + dstImage, + srcImage, + sx, + sy, + sw, + sh, + dx, + dy, + dw, + dh + ) { + srcImage.loadPixels(); + var s = srcImage.canvas.width / srcImage.width; + dstImage.drawingContext.drawImage( + srcImage.canvas, + s * sx, + s * sy, + s * sw, + s * sh, + dx, + dy, + dw, + dh + ); + }; + + // p5.Renderer2D.prototype.get = p5.Renderer.prototype.get; + // .get() is not overridden + + // x,y are canvas-relative (pre-scaled by _pixelDensity) + p5.Renderer2D.prototype._getPixel = function(x, y) { + var pixelsState = this._pixelsState; + var imageData, index; + if (pixelsState._pixelsDirty) { + imageData = this.drawingContext.getImageData(x, y, 1, 1).data; + index = 0; + } else { + imageData = pixelsState.pixels; + index = (Math.floor(x) + Math.floor(y) * this.canvas.width) * 4; + } + return [ + imageData[index + 0], + imageData[index + 1], + imageData[index + 2], + imageData[index + 3] + ]; + }; + + p5.Renderer2D.prototype.loadPixels = function() { + var pixelsState = this._pixelsState; // if called by p5.Image + if (!pixelsState._pixelsDirty) return; + pixelsState._pixelsDirty = false; + + var pd = pixelsState._pixelDensity; + var w = this.width * pd; + var h = this.height * pd; + var imageData = this.drawingContext.getImageData(0, 0, w, h); + // @todo this should actually set pixels per object, so diff buffers can + // have diff pixel arrays. + pixelsState._setProperty('imageData', imageData); + pixelsState._setProperty('pixels', imageData.data); + }; + + p5.Renderer2D.prototype.set = function(x, y, imgOrCol) { + // round down to get integer numbers + x = Math.floor(x); + y = Math.floor(y); + var pixelsState = this._pixelsState; + if (imgOrCol instanceof p5.Image) { + this.drawingContext.save(); + this.drawingContext.setTransform(1, 0, 0, 1, 0, 0); + this.drawingContext.scale( + pixelsState._pixelDensity, + pixelsState._pixelDensity + ); + + this.drawingContext.drawImage(imgOrCol.canvas, x, y); + this.drawingContext.restore(); + pixelsState._pixelsDirty = true; + } else { + var r = 0, + g = 0, + b = 0, + a = 0; + var idx = + 4 * + (y * pixelsState._pixelDensity * (this.width * pixelsState._pixelDensity) + + x * pixelsState._pixelDensity); + if (!pixelsState.imageData || pixelsState._pixelsDirty) { + pixelsState.loadPixels.call(pixelsState); + } + if (typeof imgOrCol === 'number') { + if (idx < pixelsState.pixels.length) { + r = imgOrCol; + g = imgOrCol; + b = imgOrCol; + a = 255; + //this.updatePixels.call(this); + } + } else if (imgOrCol instanceof Array) { + if (imgOrCol.length < 4) { + throw new Error('pixel array must be of the form [R, G, B, A]'); + } + if (idx < pixelsState.pixels.length) { + r = imgOrCol[0]; + g = imgOrCol[1]; + b = imgOrCol[2]; + a = imgOrCol[3]; + //this.updatePixels.call(this); + } + } else if (imgOrCol instanceof p5.Color) { + if (idx < pixelsState.pixels.length) { + r = imgOrCol.levels[0]; + g = imgOrCol.levels[1]; + b = imgOrCol.levels[2]; + a = imgOrCol.levels[3]; + //this.updatePixels.call(this); + } + } + // loop over pixelDensity * pixelDensity + for (var i = 0; i < pixelsState._pixelDensity; i++) { + for (var j = 0; j < pixelsState._pixelDensity; j++) { + // loop over + idx = + 4 * + ((y * pixelsState._pixelDensity + j) * + this.width * + pixelsState._pixelDensity + + (x * pixelsState._pixelDensity + i)); + pixelsState.pixels[idx] = r; + pixelsState.pixels[idx + 1] = g; + pixelsState.pixels[idx + 2] = b; + pixelsState.pixels[idx + 3] = a; + } + } + } + }; + + p5.Renderer2D.prototype.updatePixels = function(x, y, w, h) { + var pixelsState = this._pixelsState; + var pd = pixelsState._pixelDensity; + if (x === undefined && y === undefined && w === undefined && h === undefined) { + x = 0; + y = 0; + w = this.width; + h = this.height; + } + x *= pd; + y *= pd; + w *= pd; + h *= pd; + + this.drawingContext.putImageData(pixelsState.imageData, x, y, 0, 0, w, h); + + if (x !== 0 || y !== 0 || w !== this.width || h !== this.height) { + pixelsState._pixelsDirty = true; + } + }; + + ////////////////////////////////////////////// + // SHAPE | 2D Primitives + ////////////////////////////////////////////// + + /** + * Generate a cubic Bezier representing an arc on the unit circle of total + * angle `size` radians, beginning `start` radians above the x-axis. Up to + * four of these curves are combined to make a full arc. + * + * See www.joecridge.me/bezier.pdf for an explanation of the method. + */ + p5.Renderer2D.prototype._acuteArcToBezier = function _acuteArcToBezier( + start, + size + ) { + // Evaluate constants. + var alpha = size / 2.0, + cos_alpha = Math.cos(alpha), + sin_alpha = Math.sin(alpha), + cot_alpha = 1.0 / Math.tan(alpha), + phi = start + alpha, // This is how far the arc needs to be rotated. + cos_phi = Math.cos(phi), + sin_phi = Math.sin(phi), + lambda = (4.0 - cos_alpha) / 3.0, + mu = sin_alpha + (cos_alpha - lambda) * cot_alpha; + + // Return rotated waypoints. + return { + ax: Math.cos(start).toFixed(7), + ay: Math.sin(start).toFixed(7), + bx: (lambda * cos_phi + mu * sin_phi).toFixed(7), + by: (lambda * sin_phi - mu * cos_phi).toFixed(7), + cx: (lambda * cos_phi - mu * sin_phi).toFixed(7), + cy: (lambda * sin_phi + mu * cos_phi).toFixed(7), + dx: Math.cos(start + size).toFixed(7), + dy: Math.sin(start + size).toFixed(7) + }; + }; + + /* + * This function requires that: + * + * 0 <= start < TWO_PI + * + * start <= stop < start + TWO_PI + */ + p5.Renderer2D.prototype.arc = function(x, y, w, h, start, stop, mode) { + var ctx = this.drawingContext; + var rx = w / 2.0; + var ry = h / 2.0; + var epsilon = 0.00001; // Smallest visible angle on displays up to 4K. + var arcToDraw = 0; + var curves = []; + + x += rx; + y += ry; + + // Create curves + while (stop - start >= epsilon) { + arcToDraw = Math.min(stop - start, constants.HALF_PI); + curves.push(this._acuteArcToBezier(start, arcToDraw)); + start += arcToDraw; + } + + // Fill curves + if (this._doFill) { + ctx.beginPath(); + curves.forEach(function(curve, index) { + if (index === 0) { + ctx.moveTo(x + curve.ax * rx, y + curve.ay * ry); + } + // prettier-ignore + ctx.bezierCurveTo(x + curve.bx * rx, y + curve.by * ry, + x + curve.cx * rx, y + curve.cy * ry, + x + curve.dx * rx, y + curve.dy * ry); + }); + if (mode === constants.PIE || mode == null) { + ctx.lineTo(x, y); + } + ctx.closePath(); + ctx.fill(); + this._pixelsState._pixelsDirty = true; + } + + // Stroke curves + if (this._doStroke) { + ctx.beginPath(); + curves.forEach(function(curve, index) { + if (index === 0) { + ctx.moveTo(x + curve.ax * rx, y + curve.ay * ry); + } + // prettier-ignore + ctx.bezierCurveTo(x + curve.bx * rx, y + curve.by * ry, + x + curve.cx * rx, y + curve.cy * ry, + x + curve.dx * rx, y + curve.dy * ry); + }); + if (mode === constants.PIE) { + ctx.lineTo(x, y); + ctx.closePath(); + } else if (mode === constants.CHORD) { + ctx.closePath(); + } + ctx.stroke(); + this._pixelsState._pixelsDirty = true; + } + return this; + }; + + p5.Renderer2D.prototype.ellipse = function(args) { + var ctx = this.drawingContext; + var doFill = this._doFill, + doStroke = this._doStroke; + var x = args[0], + y = args[1], + w = args[2], + h = args[3]; + if (doFill && !doStroke) { + if (this._getFill() === styleEmpty) { + return this; + } + } else if (!doFill && doStroke) { + if (this._getStroke() === styleEmpty) { + return this; + } + } + var kappa = 0.5522847498, + ox = w / 2 * kappa, // control point offset horizontal + oy = h / 2 * kappa, // control point offset vertical + xe = x + w, // x-end + ye = y + h, // y-end + xm = x + w / 2, // x-middle + ym = y + h / 2; // y-middle + ctx.beginPath(); + ctx.moveTo(x, ym); + ctx.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y); + ctx.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym); + ctx.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye); + ctx.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym); + ctx.closePath(); + if (doFill) { + ctx.fill(); + this._pixelsState._pixelsDirty = true; + } + if (doStroke) { + ctx.stroke(); + this._pixelsState._pixelsDirty = true; + } + }; + + p5.Renderer2D.prototype.line = function(x1, y1, x2, y2) { + var ctx = this.drawingContext; + if (!this._doStroke) { + return this; + } else if (this._getStroke() === styleEmpty) { + return this; + } + ctx.beginPath(); + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.stroke(); + this._pixelsState._pixelsDirty = true; + return this; + }; + + p5.Renderer2D.prototype.point = function(x, y) { + var ctx = this.drawingContext; + if (!this._doStroke) { + return this; + } else if (this._getStroke() === styleEmpty) { + return this; + } + var s = this._getStroke(); + var f = this._getFill(); + x = Math.round(x); + y = Math.round(y); + // swapping fill color to stroke and back after for correct point rendering + this._setFill(s); + if (ctx.lineWidth > 1) { + ctx.beginPath(); + ctx.arc(x, y, ctx.lineWidth / 2, 0, constants.TWO_PI, false); + ctx.fill(); + } else { + ctx.fillRect(x, y, 1, 1); + } + this._setFill(f); + this._pixelsState._pixelsDirty = true; + }; + + p5.Renderer2D.prototype.quad = function(x1, y1, x2, y2, x3, y3, x4, y4) { + var ctx = this.drawingContext; + var doFill = this._doFill, + doStroke = this._doStroke; + if (doFill && !doStroke) { + if (this._getFill() === styleEmpty) { + return this; + } + } else if (!doFill && doStroke) { + if (this._getStroke() === styleEmpty) { + return this; + } + } + ctx.beginPath(); + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.lineTo(x3, y3); + ctx.lineTo(x4, y4); + ctx.closePath(); + if (doFill) { + ctx.fill(); + } + if (doStroke) { + ctx.stroke(); + } + this._pixelsState._pixelsDirty = true; + return this; + }; + + p5.Renderer2D.prototype.rect = function(args) { + var x = args[0], + y = args[1], + w = args[2], + h = args[3], + tl = args[4], + tr = args[5], + br = args[6], + bl = args[7]; + var ctx = this.drawingContext; + var doFill = this._doFill, + doStroke = this._doStroke; + if (doFill && !doStroke) { + if (this._getFill() === styleEmpty) { + return this; + } + } else if (!doFill && doStroke) { + if (this._getStroke() === styleEmpty) { + return this; + } + } + ctx.beginPath(); + + if (typeof tl === 'undefined') { + // No rounded corners + ctx.rect(x, y, w, h); + } else { + // At least one rounded corner + // Set defaults when not specified + if (typeof tr === 'undefined') { + tr = tl; + } + if (typeof br === 'undefined') { + br = tr; + } + if (typeof bl === 'undefined') { + bl = br; + } + + var hw = w / 2; + var hh = h / 2; + + // Clip radii + if (w < 2 * tl) { + tl = hw; + } + if (h < 2 * tl) { + tl = hh; + } + if (w < 2 * tr) { + tr = hw; + } + if (h < 2 * tr) { + tr = hh; + } + if (w < 2 * br) { + br = hw; + } + if (h < 2 * br) { + br = hh; + } + if (w < 2 * bl) { + bl = hw; + } + if (h < 2 * bl) { + bl = hh; + } + + // Draw shape + ctx.beginPath(); + ctx.moveTo(x + tl, y); + ctx.arcTo(x + w, y, x + w, y + h, tr); + ctx.arcTo(x + w, y + h, x, y + h, br); + ctx.arcTo(x, y + h, x, y, bl); + ctx.arcTo(x, y, x + w, y, tl); + ctx.closePath(); + } + if (this._doFill) { + ctx.fill(); + } + if (this._doStroke) { + ctx.stroke(); + } + this._pixelsState._pixelsDirty = true; + return this; + }; + + p5.Renderer2D.prototype.triangle = function(args) { + var ctx = this.drawingContext; + var doFill = this._doFill, + doStroke = this._doStroke; + var x1 = args[0], + y1 = args[1]; + var x2 = args[2], + y2 = args[3]; + var x3 = args[4], + y3 = args[5]; + if (doFill && !doStroke) { + if (this._getFill() === styleEmpty) { + return this; + } + } else if (!doFill && doStroke) { + if (this._getStroke() === styleEmpty) { + return this; + } + } + ctx.beginPath(); + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.lineTo(x3, y3); + ctx.closePath(); + if (doFill) { + ctx.fill(); + this._pixelsState._pixelsDirty = true; + } + if (doStroke) { + ctx.stroke(); + this._pixelsState._pixelsDirty = true; + } + }; + + p5.Renderer2D.prototype.endShape = function( + mode, + vertices, + isCurve, + isBezier, + isQuadratic, + isContour, + shapeKind + ) { + if (vertices.length === 0) { + return this; + } + if (!this._doStroke && !this._doFill) { + return this; + } + var closeShape = mode === constants.CLOSE; + var v; + if (closeShape && !isContour) { + vertices.push(vertices[0]); + } + var i, j; + var numVerts = vertices.length; + if (isCurve && (shapeKind === constants.POLYGON || shapeKind === null)) { + if (numVerts > 3) { + var b = [], + s = 1 - this._curveTightness; + this.drawingContext.beginPath(); + this.drawingContext.moveTo(vertices[1][0], vertices[1][1]); + for (i = 1; i + 2 < numVerts; i++) { + v = vertices[i]; + b[0] = [v[0], v[1]]; + b[1] = [ + v[0] + (s * vertices[i + 1][0] - s * vertices[i - 1][0]) / 6, + v[1] + (s * vertices[i + 1][1] - s * vertices[i - 1][1]) / 6 + ]; + + b[2] = [ + vertices[i + 1][0] + (s * vertices[i][0] - s * vertices[i + 2][0]) / 6, + vertices[i + 1][1] + (s * vertices[i][1] - s * vertices[i + 2][1]) / 6 + ]; + + b[3] = [vertices[i + 1][0], vertices[i + 1][1]]; + this.drawingContext.bezierCurveTo( + b[1][0], + b[1][1], + b[2][0], + b[2][1], + b[3][0], + b[3][1] + ); + } + if (closeShape) { + this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); + } + this._doFillStrokeClose(closeShape); + } + } else if ( + isBezier && + (shapeKind === constants.POLYGON || shapeKind === null) + ) { + this.drawingContext.beginPath(); + for (i = 0; i < numVerts; i++) { + if (vertices[i].isVert) { + if (vertices[i].moveTo) { + this.drawingContext.moveTo(vertices[i][0], vertices[i][1]); + } else { + this.drawingContext.lineTo(vertices[i][0], vertices[i][1]); + } + } else { + this.drawingContext.bezierCurveTo( + vertices[i][0], + vertices[i][1], + vertices[i][2], + vertices[i][3], + vertices[i][4], + vertices[i][5] + ); + } + } + this._doFillStrokeClose(closeShape); + } else if ( + isQuadratic && + (shapeKind === constants.POLYGON || shapeKind === null) + ) { + this.drawingContext.beginPath(); + for (i = 0; i < numVerts; i++) { + if (vertices[i].isVert) { + if (vertices[i].moveTo) { + this.drawingContext.moveTo(vertices[i][0], vertices[i][1]); + } else { + this.drawingContext.lineTo(vertices[i][0], vertices[i][1]); + } + } else { + this.drawingContext.quadraticCurveTo( + vertices[i][0], + vertices[i][1], + vertices[i][2], + vertices[i][3] + ); + } + } + this._doFillStrokeClose(closeShape); + } else { + if (shapeKind === constants.POINTS) { + for (i = 0; i < numVerts; i++) { + v = vertices[i]; + if (this._doStroke) { + this._pInst.stroke(v[6]); + } + this._pInst.point(v[0], v[1]); + } + } else if (shapeKind === constants.LINES) { + for (i = 0; i + 1 < numVerts; i += 2) { + v = vertices[i]; + if (this._doStroke) { + this._pInst.stroke(vertices[i + 1][6]); + } + this._pInst.line(v[0], v[1], vertices[i + 1][0], vertices[i + 1][1]); + } + } else if (shapeKind === constants.TRIANGLES) { + for (i = 0; i + 2 < numVerts; i += 3) { + v = vertices[i]; + this.drawingContext.beginPath(); + this.drawingContext.moveTo(v[0], v[1]); + this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); + this.drawingContext.lineTo(vertices[i + 2][0], vertices[i + 2][1]); + this.drawingContext.closePath(); + if (this._doFill) { + this._pInst.fill(vertices[i + 2][5]); + this.drawingContext.fill(); + } + if (this._doStroke) { + this._pInst.stroke(vertices[i + 2][6]); + this.drawingContext.stroke(); + } + } + } else if (shapeKind === constants.TRIANGLE_STRIP) { + for (i = 0; i + 1 < numVerts; i++) { + v = vertices[i]; + this.drawingContext.beginPath(); + this.drawingContext.moveTo(vertices[i + 1][0], vertices[i + 1][1]); + this.drawingContext.lineTo(v[0], v[1]); + if (this._doStroke) { + this._pInst.stroke(vertices[i + 1][6]); + } + if (this._doFill) { + this._pInst.fill(vertices[i + 1][5]); + } + if (i + 2 < numVerts) { + this.drawingContext.lineTo(vertices[i + 2][0], vertices[i + 2][1]); + if (this._doStroke) { + this._pInst.stroke(vertices[i + 2][6]); + } + if (this._doFill) { + this._pInst.fill(vertices[i + 2][5]); + } + } + this._doFillStrokeClose(closeShape); + } + } else if (shapeKind === constants.TRIANGLE_FAN) { + if (numVerts > 2) { + // For performance reasons, try to batch as many of the + // fill and stroke calls as possible. + this.drawingContext.beginPath(); + for (i = 2; i < numVerts; i++) { + v = vertices[i]; + this.drawingContext.moveTo(vertices[0][0], vertices[0][1]); + this.drawingContext.lineTo(vertices[i - 1][0], vertices[i - 1][1]); + this.drawingContext.lineTo(v[0], v[1]); + this.drawingContext.lineTo(vertices[0][0], vertices[0][1]); + // If the next colour is going to be different, stroke / fill now + if (i < numVerts - 1) { + if ( + (this._doFill && v[5] !== vertices[i + 1][5]) || + (this._doStroke && v[6] !== vertices[i + 1][6]) + ) { + if (this._doFill) { + this._pInst.fill(v[5]); + this.drawingContext.fill(); + this._pInst.fill(vertices[i + 1][5]); + } + if (this._doStroke) { + this._pInst.stroke(v[6]); + this.drawingContext.stroke(); + this._pInst.stroke(vertices[i + 1][6]); + } + this.drawingContext.closePath(); + this.drawingContext.beginPath(); // Begin the next one + } + } + } + this._doFillStrokeClose(closeShape); + } + } else if (shapeKind === constants.QUADS) { + for (i = 0; i + 3 < numVerts; i += 4) { + v = vertices[i]; + this.drawingContext.beginPath(); + this.drawingContext.moveTo(v[0], v[1]); + for (j = 1; j < 4; j++) { + this.drawingContext.lineTo(vertices[i + j][0], vertices[i + j][1]); + } + this.drawingContext.lineTo(v[0], v[1]); + if (this._doFill) { + this._pInst.fill(vertices[i + 3][5]); + } + if (this._doStroke) { + this._pInst.stroke(vertices[i + 3][6]); + } + this._doFillStrokeClose(closeShape); + } + } else if (shapeKind === constants.QUAD_STRIP) { + if (numVerts > 3) { + for (i = 0; i + 1 < numVerts; i += 2) { + v = vertices[i]; + this.drawingContext.beginPath(); + if (i + 3 < numVerts) { + this.drawingContext.moveTo(vertices[i + 2][0], vertices[i + 2][1]); + this.drawingContext.lineTo(v[0], v[1]); + this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); + this.drawingContext.lineTo(vertices[i + 3][0], vertices[i + 3][1]); + if (this._doFill) { + this._pInst.fill(vertices[i + 3][5]); + } + if (this._doStroke) { + this._pInst.stroke(vertices[i + 3][6]); + } + } else { + this.drawingContext.moveTo(v[0], v[1]); + this.drawingContext.lineTo(vertices[i + 1][0], vertices[i + 1][1]); + } + this._doFillStrokeClose(closeShape); + } + } + } else { + this.drawingContext.beginPath(); + this.drawingContext.moveTo(vertices[0][0], vertices[0][1]); + for (i = 1; i < numVerts; i++) { + v = vertices[i]; + if (v.isVert) { + if (v.moveTo) { + this.drawingContext.moveTo(v[0], v[1]); + } else { + this.drawingContext.lineTo(v[0], v[1]); + } + } + } + this._doFillStrokeClose(closeShape); + } + } + isCurve = false; + isBezier = false; + isQuadratic = false; + isContour = false; + if (closeShape) { + vertices.pop(); + } + + this._pixelsState._pixelsDirty = true; + return this; + }; + ////////////////////////////////////////////// + // SHAPE | Attributes + ////////////////////////////////////////////// + + p5.Renderer2D.prototype.strokeCap = function(cap) { + if ( + cap === constants.ROUND || + cap === constants.SQUARE || + cap === constants.PROJECT + ) { + this.drawingContext.lineCap = cap; + } + return this; + }; + + p5.Renderer2D.prototype.strokeJoin = function(join) { + if ( + join === constants.ROUND || + join === constants.BEVEL || + join === constants.MITER + ) { + this.drawingContext.lineJoin = join; + } + return this; + }; + + p5.Renderer2D.prototype.strokeWeight = function(w) { + if (typeof w === 'undefined' || w === 0) { + // hack because lineWidth 0 doesn't work + this.drawingContext.lineWidth = 0.0001; + } else { + this.drawingContext.lineWidth = w; + } + return this; + }; + + p5.Renderer2D.prototype._getFill = function() { + if (!this._cachedFillStyle) { + this._cachedFillStyle = this.drawingContext.fillStyle; + } + return this._cachedFillStyle; + }; + + p5.Renderer2D.prototype._setFill = function(fillStyle) { + if (fillStyle !== this._cachedFillStyle) { + this.drawingContext.fillStyle = fillStyle; + this._cachedFillStyle = fillStyle; + } + }; + + p5.Renderer2D.prototype._getStroke = function() { + if (!this._cachedStrokeStyle) { + this._cachedStrokeStyle = this.drawingContext.strokeStyle; + } + return this._cachedStrokeStyle; + }; + + p5.Renderer2D.prototype._setStroke = function(strokeStyle) { + if (strokeStyle !== this._cachedStrokeStyle) { + this.drawingContext.strokeStyle = strokeStyle; + this._cachedStrokeStyle = strokeStyle; + } + }; + + ////////////////////////////////////////////// + // SHAPE | Curves + ////////////////////////////////////////////// + p5.Renderer2D.prototype.bezier = function(x1, y1, x2, y2, x3, y3, x4, y4) { + this._pInst.beginShape(); + this._pInst.vertex(x1, y1); + this._pInst.bezierVertex(x2, y2, x3, y3, x4, y4); + this._pInst.endShape(); + return this; + }; + + p5.Renderer2D.prototype.curve = function(x1, y1, x2, y2, x3, y3, x4, y4) { + this._pInst.beginShape(); + this._pInst.curveVertex(x1, y1); + this._pInst.curveVertex(x2, y2); + this._pInst.curveVertex(x3, y3); + this._pInst.curveVertex(x4, y4); + this._pInst.endShape(); + return this; + }; + + ////////////////////////////////////////////// + // SHAPE | Vertex + ////////////////////////////////////////////// + + p5.Renderer2D.prototype._doFillStrokeClose = function(closeShape) { + if (closeShape) { + this.drawingContext.closePath(); + } + if (this._doFill) { + this.drawingContext.fill(); + } + if (this._doStroke) { + this.drawingContext.stroke(); + } + + this._pixelsState._pixelsDirty = true; + }; + + ////////////////////////////////////////////// + // TRANSFORM + ////////////////////////////////////////////// + + p5.Renderer2D.prototype.applyMatrix = function(a, b, c, d, e, f) { + this.drawingContext.transform(a, b, c, d, e, f); + }; + + p5.Renderer2D.prototype.resetMatrix = function() { + this.drawingContext.setTransform(1, 0, 0, 1, 0, 0); + this.drawingContext.scale(this._pInst._pixelDensity, this._pInst._pixelDensity); + + return this; + }; + + p5.Renderer2D.prototype.rotate = function(rad) { + this.drawingContext.rotate(rad); + }; + + p5.Renderer2D.prototype.scale = function(x, y) { + this.drawingContext.scale(x, y); + return this; + }; + + p5.Renderer2D.prototype.translate = function(x, y) { + // support passing a vector as the 1st parameter + if (x instanceof p5.Vector) { + y = x.y; + x = x.x; + } + this.drawingContext.translate(x, y); + return this; + }; + + ////////////////////////////////////////////// + // TYPOGRAPHY + // + ////////////////////////////////////////////// + + p5.Renderer2D.prototype.text = function(str, x, y, maxWidth, maxHeight) { + var baselineHacked; + + // baselineHacked: (HACK) + // A temporary fix to conform to Processing's implementation + // of BASELINE vertical alignment in a bounding box + + if (typeof maxWidth !== 'undefined') { + if (this.drawingContext.textBaseline === constants.BASELINE) { + baselineHacked = true; + this.drawingContext.textBaseline = constants.TOP; + } + } + + var p = p5.Renderer.prototype.text.apply(this, arguments); + + if (baselineHacked) { + this.drawingContext.textBaseline = constants.BASELINE; + } + + return p; + }; + + p5.Renderer2D.prototype._renderText = function(p, line, x, y, maxY) { + if (y >= maxY) { + return; // don't render lines beyond our maxY position + } + + p.push(); // fix to #803 + + if (!this._isOpenType()) { + // a system/browser font + + // no stroke unless specified by user + if (this._doStroke && this._strokeSet) { + this.drawingContext.strokeText(line, x, y); + } + + if (this._doFill) { + // if fill hasn't been set by user, use default text fill + if (!this._fillSet) { + this._setFill(constants._DEFAULT_TEXT_FILL); + } + + this.drawingContext.fillText(line, x, y); + } + } else { + // an opentype font, let it handle the rendering + + this._textFont._renderPath(line, x, y, { renderer: this }); + } + + p.pop(); + + this._pixelsState._pixelsDirty = true; + return p; + }; + + p5.Renderer2D.prototype.textWidth = function(s) { + if (this._isOpenType()) { + return this._textFont._textWidth(s, this._textSize); + } + + return this.drawingContext.measureText(s).width; + }; + + p5.Renderer2D.prototype._applyTextProperties = function() { + var font, + p = this._pInst; + + this._setProperty('_textAscent', null); + this._setProperty('_textDescent', null); + + font = this._textFont; + + if (this._isOpenType()) { + font = this._textFont.font.familyName; + this._setProperty('_textStyle', this._textFont.font.styleName); + } + + this.drawingContext.font = + (this._textStyle || 'normal') + + ' ' + + (this._textSize || 12) + + 'px ' + + (font || 'sans-serif'); + + this.drawingContext.textAlign = this._textAlign; + if (this._textBaseline === constants.CENTER) { + this.drawingContext.textBaseline = constants._CTX_MIDDLE; + } else { + this.drawingContext.textBaseline = this._textBaseline; + } + + return p; + }; + + ////////////////////////////////////////////// + // STRUCTURE + ////////////////////////////////////////////// + + // a push() operation is in progress. + // the renderer should return a 'style' object that it wishes to + // store on the push stack. + // derived renderers should call the base class' push() method + // to fetch the base style object. + p5.Renderer2D.prototype.push = function() { + this.drawingContext.save(); + + // get the base renderer style + return p5.Renderer.prototype.push.apply(this); + }; + + // a pop() operation is in progress + // the renderer is passed the 'style' object that it returned + // from its push() method. + // derived renderers should pass this object to their base + // class' pop method + p5.Renderer2D.prototype.pop = function(style) { + this.drawingContext.restore(); + // Re-cache the fill / stroke state + this._cachedFillStyle = this.drawingContext.fillStyle; + this._cachedStrokeStyle = this.drawingContext.strokeStyle; + + p5.Renderer.prototype.pop.call(this, style); + }; + + module.exports = p5.Renderer2D; + }, + { '../image/filters': 43, './constants': 18, './main': 24, './p5.Renderer': 27 } + ], + 29: [ + function(_dereq_, module, exports) { + /** + * @module Rendering + * @submodule Rendering + * @for p5 + */ + + 'use strict'; + function _typeof(obj) { + if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { + _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + _typeof = function _typeof(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : typeof obj; + }; + } + return _typeof(obj); + } + + var p5 = _dereq_('./main'); + var constants = _dereq_('./constants'); + _dereq_('./p5.Graphics'); + _dereq_('./p5.Renderer2D'); + _dereq_('../webgl/p5.RendererGL'); + var defaultId = 'defaultCanvas0'; // this gets set again in createCanvas + var defaultClass = 'p5Canvas'; + + /** + * Creates a canvas element in the document, and sets the dimensions of it + * in pixels. This method should be called only once at the start of setup. + * Calling createCanvas more than once in a sketch will result in very + * unpredictable behavior. If you want more than one drawing canvas + * you could use createGraphics (hidden by default but it can be shown). + *

+ * The system variables width and height are set by the parameters passed + * to this function. If createCanvas() is not used, the window will be + * given a default size of 100x100 pixels. + *

+ * For more ways to position the canvas, see the + * + * positioning the canvas wiki page. + * + * @method createCanvas + * @param {Number} w width of the canvas + * @param {Number} h height of the canvas + * @param {Constant} [renderer] either P2D or WEBGL + * @return {p5.Renderer} + * @example + *
+ * + * function setup() { + * createCanvas(100, 50); + * background(153); + * line(0, 0, width, height); + * } + * + *
+ * + * @alt + * Black line extending from top-left of canvas to bottom right. + * + */ + + p5.prototype.createCanvas = function(w, h, renderer) { + p5._validateParameters('createCanvas', arguments); + //optional: renderer, otherwise defaults to p2d + var r = renderer || constants.P2D; + var c; + + if (r === constants.WEBGL) { + c = document.getElementById(defaultId); + if (c) { + //if defaultCanvas already exists + c.parentNode.removeChild(c); //replace the existing defaultCanvas + var thisRenderer = this._renderer; + this._elements = this._elements.filter(function(e) { + return e !== thisRenderer; + }); + } + c = document.createElement('canvas'); + c.id = defaultId; + c.classList.add(defaultClass); + } else { + if (!this._defaultGraphicsCreated) { + c = document.createElement('canvas'); + var i = 0; + while (document.getElementById('defaultCanvas' + i)) { + i++; + } + defaultId = 'defaultCanvas' + i; + c.id = defaultId; + c.classList.add(defaultClass); + } else { + // resize the default canvas if new one is created + c = this.canvas; + } + } + + // set to invisible if still in setup (to prevent flashing with manipulate) + if (!this._setupDone) { + c.dataset.hidden = true; // tag to show later + c.style.visibility = 'hidden'; + } + + if (this._userNode) { + // user input node case + this._userNode.appendChild(c); + } else { + document.body.appendChild(c); + } + + // Init our graphics renderer + //webgl mode + if (r === constants.WEBGL) { + this._setProperty('_renderer', new p5.RendererGL(c, this, true)); + this._elements.push(this._renderer); + } else { + //P2D mode + if (!this._defaultGraphicsCreated) { + this._setProperty('_renderer', new p5.Renderer2D(c, this, true)); + this._defaultGraphicsCreated = true; + this._elements.push(this._renderer); + } + } + this._renderer.resize(w, h); + this._renderer._applyDefaults(); + return this._renderer; + }; + + /** + * Resizes the canvas to given width and height. The canvas will be cleared + * and draw will be called immediately, allowing the sketch to re-render itself + * in the resized canvas. + * @method resizeCanvas + * @param {Number} w width of the canvas + * @param {Number} h height of the canvas + * @param {Boolean} [noRedraw] don't redraw the canvas immediately + * @example + *
+ * function setup() { + * createCanvas(windowWidth, windowHeight); + * } + * + * function draw() { + * background(0, 100, 200); + * } + * + * function windowResized() { + * resizeCanvas(windowWidth, windowHeight); + * } + *
+ * + * @alt + * No image displayed. + * + */ + p5.prototype.resizeCanvas = function(w, h, noRedraw) { + p5._validateParameters('resizeCanvas', arguments); + if (this._renderer) { + // save canvas properties + var props = {}; + for (var key in this.drawingContext) { + var val = this.drawingContext[key]; + if (_typeof(val) !== 'object' && typeof val !== 'function') { + props[key] = val; + } + } + this._renderer.resize(w, h); + this.width = w; + this.height = h; + // reset canvas properties + for (var savedKey in props) { + try { + this.drawingContext[savedKey] = props[savedKey]; + } catch (err) { + // ignore read-only property errors + } + } + if (!noRedraw) { + this.redraw(); + } + } + }; + + /** + * Removes the default canvas for a p5 sketch that doesn't + * require a canvas + * @method noCanvas + * @example + *
+ * + * function setup() { + * noCanvas(); + * } + * + *
+ * + * @alt + * no image displayed + * + */ + p5.prototype.noCanvas = function() { + if (this.canvas) { + this.canvas.parentNode.removeChild(this.canvas); + } + }; + + /** + * Creates and returns a new p5.Renderer object. Use this class if you need + * to draw into an off-screen graphics buffer. The two parameters define the + * width and height in pixels. + * + * @method createGraphics + * @param {Number} w width of the offscreen graphics buffer + * @param {Number} h height of the offscreen graphics buffer + * @param {Constant} [renderer] either P2D or WEBGL + * undefined defaults to p2d + * @return {p5.Graphics} offscreen graphics buffer + * @example + *
+ * + * let pg; + * function setup() { + * createCanvas(100, 100); + * pg = createGraphics(100, 100); + * } + * function draw() { + * background(200); + * pg.background(100); + * pg.noStroke(); + * pg.ellipse(pg.width / 2, pg.height / 2, 50, 50); + * image(pg, 50, 50); + * image(pg, 0, 0, 50, 50); + * } + * + *
+ * + * @alt + * 4 grey squares alternating light and dark grey. White quarter circle mid-left. + * + */ + p5.prototype.createGraphics = function(w, h, renderer) { + p5._validateParameters('createGraphics', arguments); + return new p5.Graphics(w, h, renderer, this); + }; + + /** + * Blends the pixels in the display window according to the defined mode. + * There is a choice of the following modes to blend the source pixels (A) + * with the ones of pixels already in the display window (B): + *
    + *
  • BLEND - linear interpolation of colours: C = + * A\*factor + B. This is the default blending mode.
  • + *
  • ADD - sum of A and B
  • + *
  • DARKEST - only the darkest colour succeeds: C = + * min(A\*factor, B).
  • + *
  • LIGHTEST - only the lightest colour succeeds: C = + * max(A\*factor, B).
  • + *
  • DIFFERENCE - subtract colors from underlying image.
  • + *
  • EXCLUSION - similar to DIFFERENCE, but less + * extreme.
  • + *
  • MULTIPLY - multiply the colors, result will always be + * darker.
  • + *
  • SCREEN - opposite multiply, uses inverse values of the + * colors.
  • + *
  • REPLACE - the pixels entirely replace the others and + * don't utilize alpha (transparency) values.
  • + *
  • OVERLAY - mix of MULTIPLY and SCREEN + * . Multiplies dark values, and screens light values. (2D)
  • + *
  • HARD_LIGHT - SCREEN when greater than 50% + * gray, MULTIPLY when lower. (2D)
  • + *
  • SOFT_LIGHT - mix of DARKEST and + * LIGHTEST. Works like OVERLAY, but not as harsh. (2D) + *
  • + *
  • DODGE - lightens light tones and increases contrast, + * ignores darks. (2D)
  • + *
  • BURN - darker areas are applied, increasing contrast, + * ignores lights. (2D)
  • + *
  • SUBTRACT - remainder of A and B (3D)
  • + *
+ *

+ * (2D) indicates that this blend mode only works in the 2D renderer.
+ * (3D) indicates that this blend mode only works in the WEBGL renderer. + * + * + * @method blendMode + * @param {Constant} mode blend mode to set for canvas. + * either BLEND, DARKEST, LIGHTEST, DIFFERENCE, MULTIPLY, + * EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT, + * SOFT_LIGHT, DODGE, BURN, ADD, or SUBTRACT + * @example + *
+ * + * blendMode(LIGHTEST); + * strokeWeight(30); + * stroke(80, 150, 255); + * line(25, 25, 75, 75); + * stroke(255, 50, 50); + * line(75, 25, 25, 75); + * + *
+ *
+ * + * blendMode(MULTIPLY); + * strokeWeight(30); + * stroke(80, 150, 255); + * line(25, 25, 75, 75); + * stroke(255, 50, 50); + * line(75, 25, 25, 75); + * + *
+ * @alt + * translucent image thick red & blue diagonal rounded lines intersecting center + * Thick red & blue diagonal rounded lines intersecting center. dark at overlap + * + */ + p5.prototype.blendMode = function(mode) { + p5._validateParameters('blendMode', arguments); + if (mode === constants.NORMAL) { + // Warning added 3/26/19, can be deleted in future (1.0 release?) + console.warn( + 'NORMAL has been deprecated for use in blendMode. defaulting to BLEND instead.' + ); + + mode = constants.BLEND; + } + this._renderer.blendMode(mode); + }; + + module.exports = p5; + }, + { + '../webgl/p5.RendererGL': 75, + './constants': 18, + './main': 24, + './p5.Graphics': 26, + './p5.Renderer2D': 28 + } + ], + 30: [ + function(_dereq_, module, exports) { + /** + * @module Shape + * @submodule 2D Primitives + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../main'); + var constants = _dereq_('../constants'); + var canvas = _dereq_('../helpers'); + _dereq_('../error_helpers'); + + /** + * This function does 3 things: + * + * 1. Bounds the desired start/stop angles for an arc (in radians) so that: + * + * 0 <= start < TWO_PI ; start <= stop < start + TWO_PI + * + * This means that the arc rendering functions don't have to be concerned + * with what happens if stop is smaller than start, or if the arc 'goes + * round more than once', etc.: they can just start at start and increase + * until stop and the correct arc will be drawn. + * + * 2. Optionally adjusts the angles within each quadrant to counter the naive + * scaling of the underlying ellipse up from the unit circle. Without + * this, the angles become arbitrary when width != height: 45 degrees + * might be drawn at 5 degrees on a 'wide' ellipse, or at 85 degrees on + * a 'tall' ellipse. + * + * 3. Flags up when start and stop correspond to the same place on the + * underlying ellipse. This is useful if you want to do something special + * there (like rendering a whole ellipse instead). + */ + p5.prototype._normalizeArcAngles = function( + start, + stop, + width, + height, + correctForScaling + ) { + var epsilon = 0.00001; // Smallest visible angle on displays up to 4K. + var separation; + + // The order of the steps is important here: each one builds upon the + // adjustments made in the steps that precede it. + + // Constrain both start and stop to [0,TWO_PI). + start = start - constants.TWO_PI * Math.floor(start / constants.TWO_PI); + stop = stop - constants.TWO_PI * Math.floor(stop / constants.TWO_PI); + + // Get the angular separation between the requested start and stop points. + // + // Technically this separation only matches what gets drawn if + // correctForScaling is enabled. We could add a more complicated calculation + // for when the scaling is uncorrected (in which case the drawn points could + // end up pushed together or pulled apart quite dramatically relative to what + // was requested), but it would make things more opaque for little practical + // benefit. + // + // (If you do disable correctForScaling and find that correspondToSamePoint + // is set too aggressively, the easiest thing to do is probably to just make + // epsilon smaller...) + separation = Math.min( + Math.abs(start - stop), + constants.TWO_PI - Math.abs(start - stop) + ); + + // Optionally adjust the angles to counter linear scaling. + if (correctForScaling) { + if (start <= constants.HALF_PI) { + start = Math.atan(width / height * Math.tan(start)); + } else if (start > constants.HALF_PI && start <= 3 * constants.HALF_PI) { + start = Math.atan(width / height * Math.tan(start)) + constants.PI; + } else { + start = Math.atan(width / height * Math.tan(start)) + constants.TWO_PI; + } + if (stop <= constants.HALF_PI) { + stop = Math.atan(width / height * Math.tan(stop)); + } else if (stop > constants.HALF_PI && stop <= 3 * constants.HALF_PI) { + stop = Math.atan(width / height * Math.tan(stop)) + constants.PI; + } else { + stop = Math.atan(width / height * Math.tan(stop)) + constants.TWO_PI; + } + } + + // Ensure that start <= stop < start + TWO_PI. + if (start > stop) { + stop += constants.TWO_PI; + } + + return { + start: start, + stop: stop, + correspondToSamePoint: separation < epsilon + }; + }; + + /** + * Draw an arc to the screen. If called with only x, y, w, h, start, and + * stop, the arc will be drawn and filled as an open pie segment. If a mode parameter is provided, the arc + * will be filled like an open semi-circle (OPEN) , a closed semi-circle (CHORD), or as a closed pie segment (PIE). The + * origin may be changed with the ellipseMode() function.

+ * The arc is always drawn clockwise from wherever start falls to wherever stop falls on the ellipse. + * Adding or subtracting TWO_PI to either angle does not change where they fall. + * If both start and stop fall at the same place, a full ellipse will be drawn. Be aware that the the + * y-axis increases in the downward direction therefore the values of PI is counter clockwise. + * @method arc + * @param {Number} x x-coordinate of the arc's ellipse + * @param {Number} y y-coordinate of the arc's ellipse + * @param {Number} w width of the arc's ellipse by default + * @param {Number} h height of the arc's ellipse by default + * @param {Number} start angle to start the arc, specified in radians + * @param {Number} stop angle to stop the arc, specified in radians + * @param {Constant} [mode] optional parameter to determine the way of drawing + * the arc. either CHORD, PIE or OPEN + * @param {Number} [detail] optional parameter for WebGL mode only. This is to + * specify the number of vertices that makes up the + * perimeter of the arc. Default value is 25. + * + * @chainable + * @example + *
+ * + * arc(50, 55, 50, 50, 0, HALF_PI); + * noFill(); + * arc(50, 55, 60, 60, HALF_PI, PI); + * arc(50, 55, 70, 70, PI, PI + QUARTER_PI); + * arc(50, 55, 80, 80, PI + QUARTER_PI, TWO_PI); + * + *
+ * + *
+ * + * arc(50, 50, 80, 80, 0, PI + QUARTER_PI); + * + *
+ * + *
+ * + * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, OPEN); + * + *
+ * + *
+ * + * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, CHORD); + * + *
+ * + *
+ * + * arc(50, 50, 80, 80, 0, PI + QUARTER_PI, PIE); + * + *
+ * + * @alt + *shattered outline of an ellipse with a quarter of a white circle bottom-right. + *white ellipse with top right quarter missing. + *white ellipse with black outline with top right missing. + *white ellipse with top right missing with black outline around shape. + *white ellipse with top right quarter missing with black outline around the shape. + * + */ + p5.prototype.arc = function(x, y, w, h, start, stop, mode, detail) { + p5._validateParameters('arc', arguments); + + // if the current stroke and fill settings wouldn't result in something + // visible, exit immediately + if (!this._renderer._doStroke && !this._renderer._doFill) { + return this; + } + + start = this._toRadians(start); + stop = this._toRadians(stop); + + // p5 supports negative width and heights for ellipses + w = Math.abs(w); + h = Math.abs(h); + + var vals = canvas.modeAdjust(x, y, w, h, this._renderer._ellipseMode); + var angles = this._normalizeArcAngles(start, stop, vals.w, vals.h, true); + + if (angles.correspondToSamePoint) { + // If the arc starts and ends at (near enough) the same place, we choose to + // draw an ellipse instead. This is preferable to faking an ellipse (by + // making stop ever-so-slightly less than start + TWO_PI) because the ends + // join up to each other rather than at a vertex at the centre (leaving + // an unwanted spike in the stroke/fill). + this._renderer.ellipse([vals.x, vals.y, vals.w, vals.h, detail]); + } else { + this._renderer.arc( + vals.x, + vals.y, + vals.w, + vals.h, + angles.start, // [0, TWO_PI) + angles.stop, // [start, start + TWO_PI) + mode, + detail + ); + } + + return this; + }; + + /** + * Draws an ellipse (oval) to the screen. An ellipse with equal width and + * height is a circle. By default, the first two parameters set the location, + * and the third and fourth parameters set the shape's width and height. If + * no height is specified, the value of width is used for both the width and + * height. If a negative height or width is specified, the absolute value is taken. + * The origin may be changed with the ellipseMode() function. + * + * @method ellipse + * @param {Number} x x-coordinate of the ellipse. + * @param {Number} y y-coordinate of the ellipse. + * @param {Number} w width of the ellipse. + * @param {Number} [h] height of the ellipse. + * @chainable + * @example + *
+ * + * ellipse(56, 46, 55, 55); + * + *
+ * + * @alt + *white ellipse with black outline in middle-right of canvas that is 55x55. + * + */ + /** + * @method ellipse + * @param {Number} x + * @param {Number} y + * @param {Number} w + * @param {Number} h + * @param {Integer} detail number of radial sectors to draw (for WebGL mode) + */ + p5.prototype.ellipse = function(x, y, w, h, detailX) { + p5._validateParameters('ellipse', arguments); + + // if the current stroke and fill settings wouldn't result in something + // visible, exit immediately + if (!this._renderer._doStroke && !this._renderer._doFill) { + return this; + } + + // p5 supports negative width and heights for rects + if (w < 0) { + w = Math.abs(w); + } + + if (typeof h === 'undefined') { + // Duplicate 3rd argument if only 3 given. + h = w; + } else if (h < 0) { + h = Math.abs(h); + } + + var vals = canvas.modeAdjust(x, y, w, h, this._renderer._ellipseMode); + this._renderer.ellipse([vals.x, vals.y, vals.w, vals.h, detailX]); + + return this; + }; + + /** + * Draws a circle to the screen. A circle is a simple closed shape. + * It is the set of all points in a plane that are at a given distance from a given point, the centre. + * This function is a special case of the ellipse() function, where the width and height of the ellipse are the same. + * Height and width of the ellipse correspond to the diameter of the circle. + * By default, the first two parameters set the location of the centre of the circle, the third sets the diameter of the circle. + * + * @method circle + * @param {Number} x x-coordinate of the centre of the circle. + * @param {Number} y y-coordinate of the centre of the circle. + * @param {Number} d diameter of the circle. + * @chainable + * @example + *
+ * + * // Draw a circle at location (30, 30) with a diameter of 20. + * circle(30, 30, 20); + * + *
+ * + * @alt + * white circle with black outline in mid of canvas that is 55x55. + */ + p5.prototype.circle = function() { + var args = Array.prototype.slice.call(arguments, 0, 2); + args.push(arguments[2]); + args.push(arguments[2]); + return this.ellipse.apply(this, args); + }; + + /** + * Draws a line (a direct path between two points) to the screen. The version + * of line() with four parameters draws the line in 2D. To color a line, use + * the stroke() function. A line cannot be filled, therefore the fill() + * function will not affect the color of a line. 2D lines are drawn with a + * width of one pixel by default, but this can be changed with the + * strokeWeight() function. + * + * @method line + * @param {Number} x1 the x-coordinate of the first point + * @param {Number} y1 the y-coordinate of the first point + * @param {Number} x2 the x-coordinate of the second point + * @param {Number} y2 the y-coordinate of the second point + * @chainable + * @example + *
+ * + * line(30, 20, 85, 75); + * + *
+ * + *
+ * + * line(30, 20, 85, 20); + * stroke(126); + * line(85, 20, 85, 75); + * stroke(255); + * line(85, 75, 30, 75); + * + *
+ * + * @alt + *line 78 pixels long running from mid-top to bottom-right of canvas. + *3 lines of various stroke sizes. Form top, bottom and right sides of a square. + * + */ + /** + * @method line + * @param {Number} x1 + * @param {Number} y1 + * @param {Number} z1 the z-coordinate of the first point + * @param {Number} x2 + * @param {Number} y2 + * @param {Number} z2 the z-coordinate of the second point + * @chainable + */ + p5.prototype.line = function() { + p5._validateParameters('line', arguments); + + if (this._renderer._doStroke) { + this._renderer.line.apply(this._renderer, arguments); + } + + return this; + }; + + /** + * Draws a point, a coordinate in space at the dimension of one pixel. + * The first parameter is the horizontal value for the point, the second + * value is the vertical value for the point. The color of the point is + * determined by the current stroke. + * + * @method point + * @param {Number} x the x-coordinate + * @param {Number} y the y-coordinate + * @param {Number} [z] the z-coordinate (for WebGL mode) + * @chainable + * @example + *
+ * + * point(30, 20); + * point(85, 20); + * point(85, 75); + * point(30, 75); + * + *
+ * + * @alt + *4 points centered in the middle-right of the canvas. + * + */ + p5.prototype.point = function() { + p5._validateParameters('point', arguments); + + if (this._renderer._doStroke) { + this._renderer.point.apply(this._renderer, arguments); + } + + return this; + }; + + /** + * Draw a quad. A quad is a quadrilateral, a four sided polygon. It is + * similar to a rectangle, but the angles between its edges are not + * constrained to ninety degrees. The first pair of parameters (x1,y1) + * sets the first vertex and the subsequent pairs should proceed + * clockwise or counter-clockwise around the defined shape. + * z-arguments only work when quad() is used in WEBGL mode. + * + * + * @method quad + * @param {Number} x1 the x-coordinate of the first point + * @param {Number} y1 the y-coordinate of the first point + * @param {Number} x2 the x-coordinate of the second point + * @param {Number} y2 the y-coordinate of the second point + * @param {Number} x3 the x-coordinate of the third point + * @param {Number} y3 the y-coordinate of the third point + * @param {Number} x4 the x-coordinate of the fourth point + * @param {Number} y4 the y-coordinate of the fourth point + * @chainable + * @example + *
+ * + * quad(38, 31, 86, 20, 69, 63, 30, 76); + * + *
+ * + * @alt + *irregular white quadrilateral shape with black outline mid-right of canvas. + * + */ + /** + * @method quad + * @param {Number} x1 + * @param {Number} y1 + * @param {Number} z1 the z-coordinate of the first point + * @param {Number} x2 + * @param {Number} y2 + * @param {Number} z2 the z-coordinate of the second point + * @param {Number} x3 + * @param {Number} y3 + * @param {Number} z3 the z-coordinate of the third point + * @param {Number} x4 + * @param {Number} y4 + * @param {Number} z4 the z-coordinate of the fourth point + * @chainable + */ + p5.prototype.quad = function() { + p5._validateParameters('quad', arguments); + + if (this._renderer._doStroke || this._renderer._doFill) { + if (this._renderer.isP3D && arguments.length !== 12) { + // if 3D and we weren't passed 12 args, assume Z is 0 + // prettier-ignore + this._renderer.quad.call( + this._renderer, + arguments[0], arguments[1], 0, + arguments[2], arguments[3], 0, + arguments[4], arguments[5], 0, + arguments[6], arguments[7], 0); + } else { + this._renderer.quad.apply(this._renderer, arguments); + } + } + + return this; + }; + + /** + * Draws a rectangle to the screen. A rectangle is a four-sided shape with + * every angle at ninety degrees. By default, the first two parameters set + * the location of the upper-left corner, the third sets the width, and the + * fourth sets the height. The way these parameters are interpreted, however, + * may be changed with the rectMode() function. + *

+ * The fifth, sixth, seventh and eighth parameters, if specified, + * determine corner radius for the top-left, top-right, lower-right and + * lower-left corners, respectively. An omitted corner radius parameter is set + * to the value of the previously specified radius value in the parameter list. + * + * @method rect + * @param {Number} x x-coordinate of the rectangle. + * @param {Number} y y-coordinate of the rectangle. + * @param {Number} w width of the rectangle. + * @param {Number} h height of the rectangle. + * @param {Number} [tl] optional radius of top-left corner. + * @param {Number} [tr] optional radius of top-right corner. + * @param {Number} [br] optional radius of bottom-right corner. + * @param {Number} [bl] optional radius of bottom-left corner. + * @chainable + * @example + *
+ * + * // Draw a rectangle at location (30, 20) with a width and height of 55. + * rect(30, 20, 55, 55); + * + *
+ * + *
+ * + * // Draw a rectangle with rounded corners, each having a radius of 20. + * rect(30, 20, 55, 55, 20); + * + *
+ * + *
+ * + * // Draw a rectangle with rounded corners having the following radii: + * // top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5. + * rect(30, 20, 55, 55, 20, 15, 10, 5); + * + *
+ * + * @alt + * 55x55 white rect with black outline in mid-right of canvas. + * 55x55 white rect with black outline and rounded edges in mid-right of canvas. + * 55x55 white rect with black outline and rounded edges of different radii. + */ + /** + * @method rect + * @param {Number} x + * @param {Number} y + * @param {Number} w + * @param {Number} h + * @param {Integer} [detailX] number of segments in the x-direction (for WebGL mode) + * @param {Integer} [detailY] number of segments in the y-direction (for WebGL mode) + * @chainable + */ + p5.prototype.rect = function() { + p5._validateParameters('rect', arguments); + + if (this._renderer._doStroke || this._renderer._doFill) { + var vals = canvas.modeAdjust( + arguments[0], + arguments[1], + arguments[2], + arguments[3], + this._renderer._rectMode + ); + + var args = [vals.x, vals.y, vals.w, vals.h]; + // append the additional arguments (either cornder radii, or + // segment details) to the argument list + for (var i = 4; i < arguments.length; i++) { + args[i] = arguments[i]; + } + this._renderer.rect(args); + } + + return this; + }; + + /** + * Draws a square to the screen. A square is a four-sided shape with + * every angle at ninety degrees, and equal side size. + * This function is a special case of the rect() function, where the width and height are the same, and the parameter is called "s" for side size. + * By default, the first two parameters set the location of the upper-left corner, the third sets the side size of the square. + * The way these parameters are interpreted, however, + * may be changed with the rectMode() function. + *

+ * The fourth, fifth, sixth and seventh parameters, if specified, + * determine corner radius for the top-left, top-right, lower-right and + * lower-left corners, respectively. An omitted corner radius parameter is set + * to the value of the previously specified radius value in the parameter list. + * + * @method square + * @param {Number} x x-coordinate of the square. + * @param {Number} y y-coordinate of the square. + * @param {Number} s side size of the square. + * @param {Number} [tl] optional radius of top-left corner. + * @param {Number} [tr] optional radius of top-right corner. + * @param {Number} [br] optional radius of bottom-right corner. + * @param {Number} [bl] optional radius of bottom-left corner. + * @chainable + * @example + *
+ * + * // Draw a square at location (30, 20) with a side size of 55. + * square(30, 20, 55); + * + *
+ * + *
+ * + * // Draw a square with rounded corners, each having a radius of 20. + * square(30, 20, 55, 20); + * + *
+ * + *
+ * + * // Draw a square with rounded corners having the following radii: + * // top-left = 20, top-right = 15, bottom-right = 10, bottom-left = 5. + * square(30, 20, 55, 20, 15, 10, 5); + * + *
+ * + * @alt + * 55x55 white square with black outline in mid-right of canvas. + * 55x55 white square with black outline and rounded edges in mid-right of canvas. + * 55x55 white square with black outline and rounded edges of different radii. + */ + p5.prototype.square = function(x, y, s, tl, tr, br, bl) { + return this.rect(x, y, s, s, tl, tr, br, bl); + }; + + /** + * A triangle is a plane created by connecting three points. The first two + * arguments specify the first point, the middle two arguments specify the + * second point, and the last two arguments specify the third point. + * + * @method triangle + * @param {Number} x1 x-coordinate of the first point + * @param {Number} y1 y-coordinate of the first point + * @param {Number} x2 x-coordinate of the second point + * @param {Number} y2 y-coordinate of the second point + * @param {Number} x3 x-coordinate of the third point + * @param {Number} y3 y-coordinate of the third point + * @chainable + * @example + *
+ * + * triangle(30, 75, 58, 20, 86, 75); + * + *
+ * + *@alt + * white triangle with black outline in mid-right of canvas. + * + */ + p5.prototype.triangle = function() { + p5._validateParameters('triangle', arguments); + + if (this._renderer._doStroke || this._renderer._doFill) { + this._renderer.triangle(arguments); + } + + return this; + }; + + module.exports = p5; + }, + { '../constants': 18, '../error_helpers': 20, '../helpers': 21, '../main': 24 } + ], + 31: [ + function(_dereq_, module, exports) { + /** + * @module Shape + * @submodule Attributes + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../main'); + var constants = _dereq_('../constants'); + + /** + * Modifies the location from which ellipses are drawn by changing the way + * in which parameters given to ellipse() are interpreted. + *

+ * The default mode is ellipseMode(CENTER), which interprets the first two + * parameters of ellipse() as the shape's center point, while the third and + * fourth parameters are its width and height. + *

+ * ellipseMode(RADIUS) also uses the first two parameters of ellipse() as + * the shape's center point, but uses the third and fourth parameters to + * specify half of the shapes's width and height. + *

+ * ellipseMode(CORNER) interprets the first two parameters of ellipse() as + * the upper-left corner of the shape, while the third and fourth parameters + * are its width and height. + *

+ * ellipseMode(CORNERS) interprets the first two parameters of ellipse() as + * the location of one corner of the ellipse's bounding box, and the third + * and fourth parameters as the location of the opposite corner. + *

+ * The parameter must be written in ALL CAPS because Javascript is a + * case-sensitive language. + * + * @method ellipseMode + * @param {Constant} mode either CENTER, RADIUS, CORNER, or CORNERS + * @chainable + * @example + *
+ * + * ellipseMode(RADIUS); // Set ellipseMode to RADIUS + * fill(255); // Set fill to white + * ellipse(50, 50, 30, 30); // Draw white ellipse using RADIUS mode + * + * ellipseMode(CENTER); // Set ellipseMode to CENTER + * fill(100); // Set fill to gray + * ellipse(50, 50, 30, 30); // Draw gray ellipse using CENTER mode + * + *
+ * + *
+ * + * ellipseMode(CORNER); // Set ellipseMode is CORNER + * fill(255); // Set fill to white + * ellipse(25, 25, 50, 50); // Draw white ellipse using CORNER mode + * + * ellipseMode(CORNERS); // Set ellipseMode to CORNERS + * fill(100); // Set fill to gray + * ellipse(25, 25, 50, 50); // Draw gray ellipse using CORNERS mode + * + *
+ * + * @alt + * 60x60 white ellipse and 30x30 grey ellipse with black outlines at center. + * 60x60 white ellipse @center and 30x30 grey ellipse top-right, black outlines. + * + */ + p5.prototype.ellipseMode = function(m) { + p5._validateParameters('ellipseMode', arguments); + if ( + m === constants.CORNER || + m === constants.CORNERS || + m === constants.RADIUS || + m === constants.CENTER + ) { + this._renderer._ellipseMode = m; + } + return this; + }; + + /** + * Draws all geometry with jagged (aliased) edges. Note that smooth() is + * active by default in 2D mode, so it is necessary to call noSmooth() to disable + * smoothing of geometry, images, and fonts. In 3D mode, noSmooth() is enabled + * by default, so it is necessary to call smooth() if you would like + * smooth (antialiased) edges on your geometry. + * + * @method noSmooth + * @chainable + * @example + *
+ * + * background(0); + * noStroke(); + * smooth(); + * ellipse(30, 48, 36, 36); + * noSmooth(); + * ellipse(70, 48, 36, 36); + * + *
+ * + * @alt + * 2 pixelated 36x36 white ellipses to left & right of center, black background + * + */ + p5.prototype.noSmooth = function() { + this.setAttributes('antialias', false); + if ('imageSmoothingEnabled' in this.drawingContext) { + this.drawingContext.imageSmoothingEnabled = false; + } + return this; + }; + + /** + * Modifies the location from which rectangles are drawn by changing the way + * in which parameters given to rect() are interpreted. + *

+ * The default mode is rectMode(CORNER), which interprets the first two + * parameters of rect() as the upper-left corner of the shape, while the + * third and fourth parameters are its width and height. + *

+ * rectMode(CORNERS) interprets the first two parameters of rect() as the + * location of one corner, and the third and fourth parameters as the + * location of the opposite corner. + *

+ * rectMode(CENTER) interprets the first two parameters of rect() as the + * shape's center point, while the third and fourth parameters are its + * width and height. + *

+ * rectMode(RADIUS) also uses the first two parameters of rect() as the + * shape's center point, but uses the third and fourth parameters to specify + * half of the shapes's width and height. + *

+ * The parameter must be written in ALL CAPS because Javascript is a + * case-sensitive language. + * + * @method rectMode + * @param {Constant} mode either CORNER, CORNERS, CENTER, or RADIUS + * @chainable + * @example + *
+ * + * rectMode(CORNER); // Default rectMode is CORNER + * fill(255); // Set fill to white + * rect(25, 25, 50, 50); // Draw white rect using CORNER mode + * + * rectMode(CORNERS); // Set rectMode to CORNERS + * fill(100); // Set fill to gray + * rect(25, 25, 50, 50); // Draw gray rect using CORNERS mode + * + *
+ * + *
+ * + * rectMode(RADIUS); // Set rectMode to RADIUS + * fill(255); // Set fill to white + * rect(50, 50, 30, 30); // Draw white rect using RADIUS mode + * + * rectMode(CENTER); // Set rectMode to CENTER + * fill(100); // Set fill to gray + * rect(50, 50, 30, 30); // Draw gray rect using CENTER mode + * + *
+ * + * @alt + * 50x50 white rect at center and 25x25 grey rect in the top left of the other. + * 50x50 white rect at center and 25x25 grey rect in the center of the other. + * + */ + p5.prototype.rectMode = function(m) { + p5._validateParameters('rectMode', arguments); + if ( + m === constants.CORNER || + m === constants.CORNERS || + m === constants.RADIUS || + m === constants.CENTER + ) { + this._renderer._rectMode = m; + } + return this; + }; + + /** + * Draws all geometry with smooth (anti-aliased) edges. smooth() will also + * improve image quality of resized images. Note that smooth() is active by + * default in 2D mode; noSmooth() can be used to disable smoothing of geometry, + * images, and fonts. In 3D mode, noSmooth() is enabled + * by default, so it is necessary to call smooth() if you would like + * smooth (antialiased) edges on your geometry. + * + * @method smooth + * @chainable + * @example + *
+ * + * background(0); + * noStroke(); + * smooth(); + * ellipse(30, 48, 36, 36); + * noSmooth(); + * ellipse(70, 48, 36, 36); + * + *
+ * + * @alt + * 2 pixelated 36x36 white ellipses one left one right of center. On black. + * + */ + p5.prototype.smooth = function() { + this.setAttributes('antialias', true); + if ('imageSmoothingEnabled' in this.drawingContext) { + this.drawingContext.imageSmoothingEnabled = true; + } + return this; + }; + + /** + * Sets the style for rendering line endings. These ends are either squared, + * extended, or rounded, each of which specified with the corresponding + * parameters: SQUARE, PROJECT, and ROUND. The default cap is ROUND. + * + * @method strokeCap + * @param {Constant} cap either SQUARE, PROJECT, or ROUND + * @chainable + * @example + *
+ * + * strokeWeight(12.0); + * strokeCap(ROUND); + * line(20, 30, 80, 30); + * strokeCap(SQUARE); + * line(20, 50, 80, 50); + * strokeCap(PROJECT); + * line(20, 70, 80, 70); + * + *
+ * + * @alt + * 3 lines. Top line: rounded ends, mid: squared, bottom:longer squared ends. + * + */ + p5.prototype.strokeCap = function(cap) { + p5._validateParameters('strokeCap', arguments); + if ( + cap === constants.ROUND || + cap === constants.SQUARE || + cap === constants.PROJECT + ) { + this._renderer.strokeCap(cap); + } + return this; + }; + + /** + * Sets the style of the joints which connect line segments. These joints + * are either mitered, beveled, or rounded and specified with the + * corresponding parameters MITER, BEVEL, and ROUND. The default joint is + * MITER. + * + * @method strokeJoin + * @param {Constant} join either MITER, BEVEL, ROUND + * @chainable + * @example + *
+ * + * noFill(); + * strokeWeight(10.0); + * strokeJoin(MITER); + * beginShape(); + * vertex(35, 20); + * vertex(65, 50); + * vertex(35, 80); + * endShape(); + * + *
+ * + *
+ * + * noFill(); + * strokeWeight(10.0); + * strokeJoin(BEVEL); + * beginShape(); + * vertex(35, 20); + * vertex(65, 50); + * vertex(35, 80); + * endShape(); + * + *
+ * + *
+ * + * noFill(); + * strokeWeight(10.0); + * strokeJoin(ROUND); + * beginShape(); + * vertex(35, 20); + * vertex(65, 50); + * vertex(35, 80); + * endShape(); + * + *
+ * + * @alt + * Right-facing arrowhead shape with pointed tip in center of canvas. + * Right-facing arrowhead shape with flat tip in center of canvas. + * Right-facing arrowhead shape with rounded tip in center of canvas. + * + */ + p5.prototype.strokeJoin = function(join) { + p5._validateParameters('strokeJoin', arguments); + if ( + join === constants.ROUND || + join === constants.BEVEL || + join === constants.MITER + ) { + this._renderer.strokeJoin(join); + } + return this; + }; + + /** + * Sets the width of the stroke used for lines, points, and the border + * around shapes. All widths are set in units of pixels. + * + * @method strokeWeight + * @param {Number} weight the weight (in pixels) of the stroke + * @chainable + * @example + *
+ * + * strokeWeight(1); // Default + * line(20, 20, 80, 20); + * strokeWeight(4); // Thicker + * line(20, 40, 80, 40); + * strokeWeight(10); // Beastly + * line(20, 70, 80, 70); + * + *
+ * + * @alt + * 3 horizontal black lines. Top line: thin, mid: medium, bottom:thick. + * + */ + p5.prototype.strokeWeight = function(w) { + p5._validateParameters('strokeWeight', arguments); + this._renderer.strokeWeight(w); + return this; + }; + + module.exports = p5; + }, + { '../constants': 18, '../main': 24 } + ], + 32: [ + function(_dereq_, module, exports) { + /** + * @module Shape + * @submodule Curves + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../main'); + _dereq_('../error_helpers'); + + /** + * Draws a cubic Bezier curve on the screen. These curves are defined by a + * series of anchor and control points. The first two parameters specify + * the first anchor point and the last two parameters specify the other + * anchor point, which become the first and last points on the curve. The + * middle parameters specify the two control points which define the shape + * of the curve. Approximately speaking, control points "pull" the curve + * towards them.

Bezier curves were developed by French + * automotive engineer Pierre Bezier, and are commonly used in computer + * graphics to define gently sloping curves. See also curve(). + * + * @method bezier + * @param {Number} x1 x-coordinate for the first anchor point + * @param {Number} y1 y-coordinate for the first anchor point + * @param {Number} x2 x-coordinate for the first control point + * @param {Number} y2 y-coordinate for the first control point + * @param {Number} x3 x-coordinate for the second control point + * @param {Number} y3 y-coordinate for the second control point + * @param {Number} x4 x-coordinate for the second anchor point + * @param {Number} y4 y-coordinate for the second anchor point + * @chainable + * @example + *
+ * + * noFill(); + * stroke(255, 102, 0); + * line(85, 20, 10, 10); + * line(90, 90, 15, 80); + * stroke(0, 0, 0); + * bezier(85, 20, 10, 10, 90, 90, 15, 80); + * + *
+ * + *
+ * + * background(0, 0, 0); + * noFill(); + * stroke(255); + * bezier(250, 250, 0, 100, 100, 0, 100, 0, 0, 0, 100, 0); + * + *
+ * + * @alt + * stretched black s-shape in center with orange lines extending from end points. + * stretched black s-shape with 10 5x5 white ellipses along the shape. + * stretched black s-shape with 7 5x5 ellipses and orange lines along the shape. + * stretched black s-shape with 17 small orange lines extending from under shape. + * horseshoe shape with orange ends facing left and black curved center. + * horseshoe shape with orange ends facing left and black curved center. + * Line shaped like right-facing arrow,points move with mouse-x and warp shape. + * horizontal line that hooks downward on the right and 13 5x5 ellipses along it. + * right curving line mid-right of canvas with 7 short lines radiating from it. + */ + /** + * @method bezier + * @param {Number} x1 + * @param {Number} y1 + * @param {Number} z1 z-coordinate for the first anchor point + * @param {Number} x2 + * @param {Number} y2 + * @param {Number} z2 z-coordinate for the first control point + * @param {Number} x3 + * @param {Number} y3 + * @param {Number} z3 z-coordinate for the second control point + * @param {Number} x4 + * @param {Number} y4 + * @param {Number} z4 z-coordinate for the second anchor point + * @chainable + */ + p5.prototype.bezier = function() { + p5._validateParameters('bezier', arguments); + + // if the current stroke and fill settings wouldn't result in something + // visible, exit immediately + if (!this._renderer._doStroke && !this._renderer._doFill) { + return this; + } + + this._renderer.bezier.apply(this._renderer, arguments); + + return this; + }; + + /** + * Sets the resolution at which Beziers display. + * + * The default value is 20. + * + * This function is only useful when using the WEBGL renderer + * as the default canvas renderer does not use this information. + * + * @method bezierDetail + * @param {Number} detail resolution of the curves + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * noFill(); + * + * bezierDetail(5); + * } + * + * function draw() { + * background(200); + * + * // prettier-ignore + * bezier(-40, -40, 0, + * 90, -40, 0, + * -90, 40, 0, + * 40, 40, 0); + * } + * + *
+ * + * @alt + * stretched black s-shape with a low level of bezier detail + * + */ + p5.prototype.bezierDetail = function(d) { + p5._validateParameters('bezierDetail', arguments); + this._bezierDetail = d; + return this; + }; + + /** + * Evaluates the Bezier at position t for points a, b, c, d. + * The parameters a and d are the first and last points + * on the curve, and b and c are the control points. + * The final parameter t varies between 0 and 1. + * This can be done once with the x coordinates and a second time + * with the y coordinates to get the location of a bezier curve at t. + * + * @method bezierPoint + * @param {Number} a coordinate of first point on the curve + * @param {Number} b coordinate of first control point + * @param {Number} c coordinate of second control point + * @param {Number} d coordinate of second point on the curve + * @param {Number} t value between 0 and 1 + * @return {Number} the value of the Bezier at position t + * @example + *
+ * + * noFill(); + * let x1 = 85, + x2 = 10, + x3 = 90, + x4 = 15; + * let y1 = 20, + y2 = 10, + y3 = 90, + y4 = 80; + * bezier(x1, y1, x2, y2, x3, y3, x4, y4); + * fill(255); + * let steps = 10; + * for (let i = 0; i <= steps; i++) { + * let t = i / steps; + * let x = bezierPoint(x1, x2, x3, x4, t); + * let y = bezierPoint(y1, y2, y3, y4, t); + * ellipse(x, y, 5, 5); + * } + * + *
+ * + * @alt + * stretched black s-shape with 17 small orange lines extending from under shape. + * + */ + p5.prototype.bezierPoint = function(a, b, c, d, t) { + p5._validateParameters('bezierPoint', arguments); + + var adjustedT = 1 - t; + return ( + Math.pow(adjustedT, 3) * a + + 3 * Math.pow(adjustedT, 2) * t * b + + 3 * adjustedT * Math.pow(t, 2) * c + + Math.pow(t, 3) * d + ); + }; + + /** + * Evaluates the tangent to the Bezier at position t for points a, b, c, d. + * The parameters a and d are the first and last points + * on the curve, and b and c are the control points. + * The final parameter t varies between 0 and 1. + * + * @method bezierTangent + * @param {Number} a coordinate of first point on the curve + * @param {Number} b coordinate of first control point + * @param {Number} c coordinate of second control point + * @param {Number} d coordinate of second point on the curve + * @param {Number} t value between 0 and 1 + * @return {Number} the tangent at position t + * @example + *
+ * + * noFill(); + * bezier(85, 20, 10, 10, 90, 90, 15, 80); + * let steps = 6; + * fill(255); + * for (let i = 0; i <= steps; i++) { + * let t = i / steps; + * // Get the location of the point + * let x = bezierPoint(85, 10, 90, 15, t); + * let y = bezierPoint(20, 10, 90, 80, t); + * // Get the tangent points + * let tx = bezierTangent(85, 10, 90, 15, t); + * let ty = bezierTangent(20, 10, 90, 80, t); + * // Calculate an angle from the tangent points + * let a = atan2(ty, tx); + * a += PI; + * stroke(255, 102, 0); + * line(x, y, cos(a) * 30 + x, sin(a) * 30 + y); + * // The following line of code makes a line + * // inverse of the above line + * //line(x, y, cos(a)*-30 + x, sin(a)*-30 + y); + * stroke(0); + * ellipse(x, y, 5, 5); + * } + * + *
+ * + *
+ * + * noFill(); + * bezier(85, 20, 10, 10, 90, 90, 15, 80); + * stroke(255, 102, 0); + * let steps = 16; + * for (let i = 0; i <= steps; i++) { + * let t = i / steps; + * let x = bezierPoint(85, 10, 90, 15, t); + * let y = bezierPoint(20, 10, 90, 80, t); + * let tx = bezierTangent(85, 10, 90, 15, t); + * let ty = bezierTangent(20, 10, 90, 80, t); + * let a = atan2(ty, tx); + * a -= HALF_PI; + * line(x, y, cos(a) * 8 + x, sin(a) * 8 + y); + * } + * + *
+ * + * @alt + * s-shaped line with 17 short orange lines extending from underside of shape + * + */ + p5.prototype.bezierTangent = function(a, b, c, d, t) { + p5._validateParameters('bezierTangent', arguments); + + var adjustedT = 1 - t; + return ( + 3 * d * Math.pow(t, 2) - + 3 * c * Math.pow(t, 2) + + 6 * c * adjustedT * t - + 6 * b * adjustedT * t + + 3 * b * Math.pow(adjustedT, 2) - + 3 * a * Math.pow(adjustedT, 2) + ); + }; + + /** + * Draws a curved line on the screen between two points, given as the + * middle four parameters. The first two parameters are a control point, as + * if the curve came from this point even though it's not drawn. The last + * two parameters similarly describe the other control point.

+ * Longer curves can be created by putting a series of curve() functions + * together or using curveVertex(). An additional function called + * curveTightness() provides control for the visual quality of the curve. + * The curve() function is an implementation of Catmull-Rom splines. + * + * @method curve + * @param {Number} x1 x-coordinate for the beginning control point + * @param {Number} y1 y-coordinate for the beginning control point + * @param {Number} x2 x-coordinate for the first point + * @param {Number} y2 y-coordinate for the first point + * @param {Number} x3 x-coordinate for the second point + * @param {Number} y3 y-coordinate for the second point + * @param {Number} x4 x-coordinate for the ending control point + * @param {Number} y4 y-coordinate for the ending control point + * @chainable + * @example + *
+ * + * noFill(); + * stroke(255, 102, 0); + * curve(5, 26, 5, 26, 73, 24, 73, 61); + * stroke(0); + * curve(5, 26, 73, 24, 73, 61, 15, 65); + * stroke(255, 102, 0); + * curve(73, 24, 73, 61, 15, 65, 15, 65); + * + *
+ *
+ * + * // Define the curve points as JavaScript objects + * let p1 = { x: 5, y: 26 }, + p2 = { x: 73, y: 24 }; + * let p3 = { x: 73, y: 61 }, + p4 = { x: 15, y: 65 }; + * noFill(); + * stroke(255, 102, 0); + * curve(p1.x, p1.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); + * stroke(0); + * curve(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y, p4.x, p4.y); + * stroke(255, 102, 0); + * curve(p2.x, p2.y, p3.x, p3.y, p4.x, p4.y, p4.x, p4.y); + * + *
+ *
+ * + * noFill(); + * stroke(255, 102, 0); + * curve(5, 26, 0, 5, 26, 0, 73, 24, 0, 73, 61, 0); + * stroke(0); + * curve(5, 26, 0, 73, 24, 0, 73, 61, 0, 15, 65, 0); + * stroke(255, 102, 0); + * curve(73, 24, 0, 73, 61, 0, 15, 65, 0, 15, 65, 0); + * + *
+ * + * @alt + * horseshoe shape with orange ends facing left and black curved center. + * horseshoe shape with orange ends facing left and black curved center. + * curving black and orange lines. + */ + /** + * @method curve + * @param {Number} x1 + * @param {Number} y1 + * @param {Number} z1 z-coordinate for the beginning control point + * @param {Number} x2 + * @param {Number} y2 + * @param {Number} z2 z-coordinate for the first point + * @param {Number} x3 + * @param {Number} y3 + * @param {Number} z3 z-coordinate for the second point + * @param {Number} x4 + * @param {Number} y4 + * @param {Number} z4 z-coordinate for the ending control point + * @chainable + */ + p5.prototype.curve = function() { + p5._validateParameters('curve', arguments); + + if (this._renderer._doStroke) { + this._renderer.curve.apply(this._renderer, arguments); + } + + return this; + }; + + /** + * Sets the resolution at which curves display. + * + * The default value is 20 while the minimum value is 3. + * + * This function is only useful when using the WEBGL renderer + * as the default canvas renderer does not use this + * information. + * + * @method curveDetail + * @param {Number} resolution resolution of the curves + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * + * curveDetail(5); + * } + * function draw() { + * background(200); + * + * curve(250, 600, 0, -30, 40, 0, 30, 30, 0, -250, 600, 0); + * } + * + *
+ * + * @alt + * white arch shape with a low level of curve detail. + * + */ + p5.prototype.curveDetail = function(d) { + p5._validateParameters('curveDetail', arguments); + if (d < 3) { + this._curveDetail = 3; + } else { + this._curveDetail = d; + } + return this; + }; + + /** + * Modifies the quality of forms created with curve() and curveVertex(). + * The parameter tightness determines how the curve fits to the vertex + * points. The value 0.0 is the default value for tightness (this value + * defines the curves to be Catmull-Rom splines) and the value 1.0 connects + * all the points with straight lines. Values within the range -5.0 and 5.0 + * will deform the curves but will leave them recognizable and as values + * increase in magnitude, they will continue to deform. + * + * @method curveTightness + * @param {Number} amount amount of deformation from the original vertices + * @chainable + * @example + *
+ * + * // Move the mouse left and right to see the curve change + * + * function setup() { + * createCanvas(100, 100); + * noFill(); + * } + * + * function draw() { + * background(204); + * let t = map(mouseX, 0, width, -5, 5); + * curveTightness(t); + * beginShape(); + * curveVertex(10, 26); + * curveVertex(10, 26); + * curveVertex(83, 24); + * curveVertex(83, 61); + * curveVertex(25, 65); + * curveVertex(25, 65); + * endShape(); + * } + * + *
+ * + * @alt + * Line shaped like right-facing arrow,points move with mouse-x and warp shape. + */ + p5.prototype.curveTightness = function(t) { + p5._validateParameters('curveTightness', arguments); + this._renderer._curveTightness = t; + return this; + }; + + /** + * Evaluates the curve at position t for points a, b, c, d. + * The parameter t varies between 0 and 1, a and d are control points + * of the curve, and b and c are the start and end points of the curve. + * This can be done once with the x coordinates and a second time + * with the y coordinates to get the location of a curve at t. + * + * @method curvePoint + * @param {Number} a coordinate of first control point of the curve + * @param {Number} b coordinate of first point + * @param {Number} c coordinate of second point + * @param {Number} d coordinate of second control point + * @param {Number} t value between 0 and 1 + * @return {Number} bezier value at position t + * @example + *
+ * + * noFill(); + * curve(5, 26, 5, 26, 73, 24, 73, 61); + * curve(5, 26, 73, 24, 73, 61, 15, 65); + * fill(255); + * ellipseMode(CENTER); + * let steps = 6; + * for (let i = 0; i <= steps; i++) { + * let t = i / steps; + * let x = curvePoint(5, 5, 73, 73, t); + * let y = curvePoint(26, 26, 24, 61, t); + * ellipse(x, y, 5, 5); + * x = curvePoint(5, 73, 73, 15, t); + * y = curvePoint(26, 24, 61, 65, t); + * ellipse(x, y, 5, 5); + * } + * + *
+ * + *line hooking down to right-bottom with 13 5x5 white ellipse points + */ + p5.prototype.curvePoint = function(a, b, c, d, t) { + p5._validateParameters('curvePoint', arguments); + + var t3 = t * t * t, + t2 = t * t, + f1 = -0.5 * t3 + t2 - 0.5 * t, + f2 = 1.5 * t3 - 2.5 * t2 + 1.0, + f3 = -1.5 * t3 + 2.0 * t2 + 0.5 * t, + f4 = 0.5 * t3 - 0.5 * t2; + return a * f1 + b * f2 + c * f3 + d * f4; + }; + + /** + * Evaluates the tangent to the curve at position t for points a, b, c, d. + * The parameter t varies between 0 and 1, a and d are points on the curve, + * and b and c are the control points. + * + * @method curveTangent + * @param {Number} a coordinate of first point on the curve + * @param {Number} b coordinate of first control point + * @param {Number} c coordinate of second control point + * @param {Number} d coordinate of second point on the curve + * @param {Number} t value between 0 and 1 + * @return {Number} the tangent at position t + * @example + *
+ * + * noFill(); + * curve(5, 26, 73, 24, 73, 61, 15, 65); + * let steps = 6; + * for (let i = 0; i <= steps; i++) { + * let t = i / steps; + * let x = curvePoint(5, 73, 73, 15, t); + * let y = curvePoint(26, 24, 61, 65, t); + * //ellipse(x, y, 5, 5); + * let tx = curveTangent(5, 73, 73, 15, t); + * let ty = curveTangent(26, 24, 61, 65, t); + * let a = atan2(ty, tx); + * a -= PI / 2.0; + * line(x, y, cos(a) * 8 + x, sin(a) * 8 + y); + * } + * + *
+ * + * @alt + *right curving line mid-right of canvas with 7 short lines radiating from it. + */ + p5.prototype.curveTangent = function(a, b, c, d, t) { + p5._validateParameters('curveTangent', arguments); + + var t2 = t * t, + f1 = -3 * t2 / 2 + 2 * t - 0.5, + f2 = 9 * t2 / 2 - 5 * t, + f3 = -9 * t2 / 2 + 4 * t + 0.5, + f4 = 3 * t2 / 2 - t; + return a * f1 + b * f2 + c * f3 + d * f4; + }; + + module.exports = p5; + }, + { '../error_helpers': 20, '../main': 24 } + ], + 33: [ + function(_dereq_, module, exports) { + /** + * @module Shape + * @submodule Vertex + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../main'); + var constants = _dereq_('../constants'); + var shapeKind = null; + var vertices = []; + var contourVertices = []; + var isBezier = false; + var isCurve = false; + var isQuadratic = false; + var isContour = false; + var isFirstContour = true; + + /** + * Use the beginContour() and endContour() functions to create negative + * shapes within shapes such as the center of the letter 'O'. beginContour() + * begins recording vertices for the shape and endContour() stops recording. + * The vertices that define a negative shape must "wind" in the opposite + * direction from the exterior shape. First draw vertices for the exterior + * clockwise order, then for internal shapes, draw vertices + * shape in counter-clockwise. + *

+ * These functions can only be used within a beginShape()/endShape() pair and + * transformations such as translate(), rotate(), and scale() do not work + * within a beginContour()/endContour() pair. It is also not possible to use + * other shapes, such as ellipse() or rect() within. + * + * @method beginContour + * @chainable + * @example + *
+ * + * translate(50, 50); + * stroke(255, 0, 0); + * beginShape(); + * // Exterior part of shape, clockwise winding + * vertex(-40, -40); + * vertex(40, -40); + * vertex(40, 40); + * vertex(-40, 40); + * // Interior part of shape, counter-clockwise winding + * beginContour(); + * vertex(-20, -20); + * vertex(-20, 20); + * vertex(20, 20); + * vertex(20, -20); + * endContour(); + * endShape(CLOSE); + * + *
+ * + * @alt + * white rect and smaller grey rect with red outlines in center of canvas. + * + */ + p5.prototype.beginContour = function() { + contourVertices = []; + isContour = true; + return this; + }; + + /** + * Using the beginShape() and endShape() functions allow creating more + * complex forms. beginShape() begins recording vertices for a shape and + * endShape() stops recording. The value of the kind parameter tells it which + * types of shapes to create from the provided vertices. With no mode + * specified, the shape can be any irregular polygon. + *

+ * The parameters available for beginShape() are POINTS, LINES, TRIANGLES, + * TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, and QUAD_STRIP. After calling the + * beginShape() function, a series of vertex() commands must follow. To stop + * drawing the shape, call endShape(). Each shape will be outlined with the + * current stroke color and filled with the fill color. + *

+ * Transformations such as translate(), rotate(), and scale() do not work + * within beginShape(). It is also not possible to use other shapes, such as + * ellipse() or rect() within beginShape(). + * + * @method beginShape + * @param {Constant} [kind] either POINTS, LINES, TRIANGLES, TRIANGLE_FAN + * TRIANGLE_STRIP, QUADS, or QUAD_STRIP + * @chainable + * @example + *
+ * + * beginShape(); + * vertex(30, 20); + * vertex(85, 20); + * vertex(85, 75); + * vertex(30, 75); + * endShape(CLOSE); + * + *
+ * + *
+ * + * beginShape(POINTS); + * vertex(30, 20); + * vertex(85, 20); + * vertex(85, 75); + * vertex(30, 75); + * endShape(); + * + *
+ * + *
+ * + * beginShape(LINES); + * vertex(30, 20); + * vertex(85, 20); + * vertex(85, 75); + * vertex(30, 75); + * endShape(); + * + *
+ * + *
+ * + * noFill(); + * beginShape(); + * vertex(30, 20); + * vertex(85, 20); + * vertex(85, 75); + * vertex(30, 75); + * endShape(); + * + *
+ * + *
+ * + * noFill(); + * beginShape(); + * vertex(30, 20); + * vertex(85, 20); + * vertex(85, 75); + * vertex(30, 75); + * endShape(CLOSE); + * + *
+ * + *
+ * + * beginShape(TRIANGLES); + * vertex(30, 75); + * vertex(40, 20); + * vertex(50, 75); + * vertex(60, 20); + * vertex(70, 75); + * vertex(80, 20); + * endShape(); + * + *
+ * + *
+ * + * beginShape(TRIANGLE_STRIP); + * vertex(30, 75); + * vertex(40, 20); + * vertex(50, 75); + * vertex(60, 20); + * vertex(70, 75); + * vertex(80, 20); + * vertex(90, 75); + * endShape(); + * + *
+ * + *
+ * + * beginShape(TRIANGLE_FAN); + * vertex(57.5, 50); + * vertex(57.5, 15); + * vertex(92, 50); + * vertex(57.5, 85); + * vertex(22, 50); + * vertex(57.5, 15); + * endShape(); + * + *
+ * + *
+ * + * beginShape(QUADS); + * vertex(30, 20); + * vertex(30, 75); + * vertex(50, 75); + * vertex(50, 20); + * vertex(65, 20); + * vertex(65, 75); + * vertex(85, 75); + * vertex(85, 20); + * endShape(); + * + *
+ * + *
+ * + * beginShape(QUAD_STRIP); + * vertex(30, 20); + * vertex(30, 75); + * vertex(50, 20); + * vertex(50, 75); + * vertex(65, 20); + * vertex(65, 75); + * vertex(85, 20); + * vertex(85, 75); + * endShape(); + * + *
+ * + *
+ * + * beginShape(); + * vertex(20, 20); + * vertex(40, 20); + * vertex(40, 40); + * vertex(60, 40); + * vertex(60, 60); + * vertex(20, 60); + * endShape(CLOSE); + * + *
+ * @alt + * white square-shape with black outline in middle-right of canvas. + * 4 black points in a square shape in middle-right of canvas. + * 2 horizontal black lines. In the top-right and bottom-right of canvas. + * 3 line shape with horizontal on top, vertical in middle and horizontal bottom. + * square line shape in middle-right of canvas. + * 2 white triangle shapes mid-right canvas. left one pointing up and right down. + * 5 horizontal interlocking and alternating white triangles in mid-right canvas. + * 4 interlocking white triangles in 45 degree rotated square-shape. + * 2 white rectangle shapes in mid-right canvas. Both 20x55. + * 3 side-by-side white rectangles center rect is smaller in mid-right canvas. + * Thick white l-shape with black outline mid-top-left of canvas. + * + */ + p5.prototype.beginShape = function(kind) { + p5._validateParameters('beginShape', arguments); + if (this._renderer.isP3D) { + this._renderer.beginShape.apply(this._renderer, arguments); + } else { + if ( + kind === constants.POINTS || + kind === constants.LINES || + kind === constants.TRIANGLES || + kind === constants.TRIANGLE_FAN || + kind === constants.TRIANGLE_STRIP || + kind === constants.QUADS || + kind === constants.QUAD_STRIP + ) { + shapeKind = kind; + } else { + shapeKind = null; + } + + vertices = []; + contourVertices = []; + } + return this; + }; + + /** + * Specifies vertex coordinates for Bezier curves. Each call to + * bezierVertex() defines the position of two control points and + * one anchor point of a Bezier curve, adding a new segment to a + * line or shape. For WebGL mode bezierVertex() can be used in 2D + * as well as 3D mode. 2D mode expects 6 parameters, while 3D mode + * expects 9 parameters (including z coordinates). + *

+ * The first time bezierVertex() is used within a beginShape() + * call, it must be prefaced with a call to vertex() to set the first anchor + * point. This function must be used between beginShape() and endShape() + * and only when there is no MODE or POINTS parameter specified to + * beginShape(). + * + * @method bezierVertex + * @param {Number} x2 x-coordinate for the first control point + * @param {Number} y2 y-coordinate for the first control point + * @param {Number} x3 x-coordinate for the second control point + * @param {Number} y3 y-coordinate for the second control point + * @param {Number} x4 x-coordinate for the anchor point + * @param {Number} y4 y-coordinate for the anchor point + * @chainable + * + * @example + *
+ * + * noFill(); + * beginShape(); + * vertex(30, 20); + * bezierVertex(80, 0, 80, 75, 30, 75); + * endShape(); + * + *
+ * + * @alt + * crescent-shaped line in middle of canvas. Points facing left. + * + * @example + *
+ * + * beginShape(); + * vertex(30, 20); + * bezierVertex(80, 0, 80, 75, 30, 75); + * bezierVertex(50, 80, 60, 25, 30, 20); + * endShape(); + * + *
+ * + * @alt + * white crescent shape in middle of canvas. Points facing left. + * + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * setAttributes('antialias', true); + * } + * function draw() { + * orbitControl(); + * background(50); + * strokeWeight(4); + * stroke(255); + * point(-25, 30); + * point(25, 30); + * point(25, -30); + * point(-25, -30); + * + * strokeWeight(1); + * noFill(); + * + * beginShape(); + * vertex(-25, 30); + * bezierVertex(25, 30, 25, -30, -25, -30); + * endShape(); + * + * beginShape(); + * vertex(-25, 30, 20); + * bezierVertex(25, 30, 20, 25, -30, 20, -25, -30, 20); + * endShape(); + * } + * + *
+ * + * @alt + * crescent shape in middle of canvas with another crescent shape on positive z-axis. + */ + + /** + * @method bezierVertex + * @param {Number} x2 + * @param {Number} y2 + * @param {Number} z2 z-coordinate for the first control point (for WebGL mode) + * @param {Number} x3 + * @param {Number} y3 + * @param {Number} z3 z-coordinate for the second control point (for WebGL mode) + * @param {Number} x4 + * @param {Number} y4 + * @param {Number} z4 z-coordinate for the anchor point (for WebGL mode) + * @chainable + */ + p5.prototype.bezierVertex = function() { + p5._validateParameters('bezierVertex', arguments); + if (this._renderer.isP3D) { + this._renderer.bezierVertex.apply(this._renderer, arguments); + } else { + if (vertices.length === 0) { + p5._friendlyError( + 'vertex() must be used once before calling bezierVertex()', + 'bezierVertex' + ); + } else { + isBezier = true; + var vert = []; + for (var i = 0; i < arguments.length; i++) { + vert[i] = arguments[i]; + } + vert.isVert = false; + if (isContour) { + contourVertices.push(vert); + } else { + vertices.push(vert); + } + } + } + return this; + }; + + /** + * Specifies vertex coordinates for curves. This function may only + * be used between beginShape() and endShape() and only when there + * is no MODE parameter specified to beginShape(). + * For WebGL mode curveVertex() can be used in 2D as well as 3D mode. + * 2D mode expects 2 parameters, while 3D mode expects 3 parameters. + *

+ * The first and last points in a series of curveVertex() lines will be used to + * guide the beginning and end of a the curve. A minimum of four + * points is required to draw a tiny curve between the second and + * third points. Adding a fifth point with curveVertex() will draw + * the curve between the second, third, and fourth points. The + * curveVertex() function is an implementation of Catmull-Rom + * splines. + * + * @method curveVertex + * @param {Number} x x-coordinate of the vertex + * @param {Number} y y-coordinate of the vertex + * @chainable + * @example + *
+ * + * strokeWeight(5); + * point(84, 91); + * point(68, 19); + * point(21, 17); + * point(32, 91); + * strokeWeight(1); + * + * noFill(); + * beginShape(); + * curveVertex(84, 91); + * curveVertex(84, 91); + * curveVertex(68, 19); + * curveVertex(21, 17); + * curveVertex(32, 91); + * curveVertex(32, 91); + * endShape(); + * + *
+ * + * + * @alt + * Upside-down u-shape line, mid canvas. left point extends beyond canvas view. + */ + /** + * @method curveVertex + * @param {Number} x + * @param {Number} y + * @param {Number} [z] z-coordinate of the vertex (for WebGL mode) + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * setAttributes('antialias', true); + * } + * function draw() { + * orbitControl(); + * background(50); + * strokeWeight(4); + * stroke(255); + * + * point(-25, 25); + * point(-25, 25); + * point(-25, -25); + * point(25, -25); + * point(25, 25); + * point(25, 25); + * + * strokeWeight(1); + * noFill(); + * + * beginShape(); + * curveVertex(-25, 25); + * curveVertex(-25, 25); + * curveVertex(-25, -25); + * curveVertex(25, -25); + * curveVertex(25, 25); + * curveVertex(25, 25); + * endShape(); + * + * beginShape(); + * curveVertex(-25, 25, 20); + * curveVertex(-25, 25, 20); + * curveVertex(-25, -25, 20); + * curveVertex(25, -25, 20); + * curveVertex(25, 25, 20); + * curveVertex(25, 25, 20); + * endShape(); + * } + * + *
+ * + * @alt + * Upside-down u-shape line, mid canvas with the same shape in positive z-axis. + * + */ + p5.prototype.curveVertex = function() { + p5._validateParameters('curveVertex', arguments); + if (this._renderer.isP3D) { + this._renderer.curveVertex.apply(this._renderer, arguments); + } else { + isCurve = true; + this.vertex(arguments[0], arguments[1]); + } + return this; + }; + + /** + * Use the beginContour() and endContour() functions to create negative + * shapes within shapes such as the center of the letter 'O'. beginContour() + * begins recording vertices for the shape and endContour() stops recording. + * The vertices that define a negative shape must "wind" in the opposite + * direction from the exterior shape. First draw vertices for the exterior + * clockwise order, then for internal shapes, draw vertices + * shape in counter-clockwise. + *

+ * These functions can only be used within a beginShape()/endShape() pair and + * transformations such as translate(), rotate(), and scale() do not work + * within a beginContour()/endContour() pair. It is also not possible to use + * other shapes, such as ellipse() or rect() within. + * + * @method endContour + * @chainable + * @example + *
+ * + * translate(50, 50); + * stroke(255, 0, 0); + * beginShape(); + * // Exterior part of shape, clockwise winding + * vertex(-40, -40); + * vertex(40, -40); + * vertex(40, 40); + * vertex(-40, 40); + * // Interior part of shape, counter-clockwise winding + * beginContour(); + * vertex(-20, -20); + * vertex(-20, 20); + * vertex(20, 20); + * vertex(20, -20); + * endContour(); + * endShape(CLOSE); + * + *
+ * + * @alt + * white rect and smaller grey rect with red outlines in center of canvas. + * + */ + p5.prototype.endContour = function() { + var vert = contourVertices[0].slice(); // copy all data + vert.isVert = contourVertices[0].isVert; + vert.moveTo = false; + contourVertices.push(vert); + + // prevent stray lines with multiple contours + if (isFirstContour) { + vertices.push(vertices[0]); + isFirstContour = false; + } + + for (var i = 0; i < contourVertices.length; i++) { + vertices.push(contourVertices[i]); + } + return this; + }; + + /** + * The endShape() function is the companion to beginShape() and may only be + * called after beginShape(). When endshape() is called, all of image data + * defined since the previous call to beginShape() is written into the image + * buffer. The constant CLOSE as the value for the MODE parameter to close + * the shape (to connect the beginning and the end). + * + * @method endShape + * @param {Constant} [mode] use CLOSE to close the shape + * @chainable + * @example + *
+ * + * noFill(); + * + * beginShape(); + * vertex(20, 20); + * vertex(45, 20); + * vertex(45, 80); + * endShape(CLOSE); + * + * beginShape(); + * vertex(50, 20); + * vertex(75, 20); + * vertex(75, 80); + * endShape(); + * + *
+ * + * @alt + * Triangle line shape with smallest interior angle on bottom and upside-down L. + * + */ + p5.prototype.endShape = function(mode) { + p5._validateParameters('endShape', arguments); + if (this._renderer.isP3D) { + this._renderer.endShape( + mode, + isCurve, + isBezier, + isQuadratic, + isContour, + shapeKind + ); + } else { + if (vertices.length === 0) { + return this; + } + if (!this._renderer._doStroke && !this._renderer._doFill) { + return this; + } + + var closeShape = mode === constants.CLOSE; + + // if the shape is closed, the first element is also the last element + if (closeShape && !isContour) { + vertices.push(vertices[0]); + } + + this._renderer.endShape( + mode, + vertices, + isCurve, + isBezier, + isQuadratic, + isContour, + shapeKind + ); + + // Reset some settings + isCurve = false; + isBezier = false; + isQuadratic = false; + isContour = false; + isFirstContour = true; + + // If the shape is closed, the first element was added as last element. + // We must remove it again to prevent the list of vertices from growing + // over successive calls to endShape(CLOSE) + if (closeShape) { + vertices.pop(); + } + } + return this; + }; + + /** + * Specifies vertex coordinates for quadratic Bezier curves. Each call to + * quadraticVertex() defines the position of one control points and one + * anchor point of a Bezier curve, adding a new segment to a line or shape. + * The first time quadraticVertex() is used within a beginShape() call, it + * must be prefaced with a call to vertex() to set the first anchor point. + * For WebGL mode quadraticVertex() can be used in 2D as well as 3D mode. + * 2D mode expects 4 parameters, while 3D mode expects 6 parameters + * (including z coordinates). + *

+ * This function must be used between beginShape() and endShape() + * and only when there is no MODE or POINTS parameter specified to + * beginShape(). + * + * @method quadraticVertex + * @param {Number} cx x-coordinate for the control point + * @param {Number} cy y-coordinate for the control point + * @param {Number} x3 x-coordinate for the anchor point + * @param {Number} y3 y-coordinate for the anchor point + * @chainable + * + * @example + *
+ * + * strokeWeight(5); + * point(20, 20); + * point(80, 20); + * point(50, 50); + * + * noFill(); + * strokeWeight(1); + * beginShape(); + * vertex(20, 20); + * quadraticVertex(80, 20, 50, 50); + * endShape(); + * + *
+ * + *
+ * + * strokeWeight(5); + * point(20, 20); + * point(80, 20); + * point(50, 50); + * + * point(20, 80); + * point(80, 80); + * point(80, 60); + * + * noFill(); + * strokeWeight(1); + * beginShape(); + * vertex(20, 20); + * quadraticVertex(80, 20, 50, 50); + * quadraticVertex(20, 80, 80, 80); + * vertex(80, 60); + * endShape(); + * + *
+ * + * @alt + * arched-shaped black line with 4 pixel thick stroke weight. + * backwards s-shaped black line with 4 pixel thick stroke weight. + * + */ + + /** + * @method quadraticVertex + * @param {Number} cx + * @param {Number} cy + * @param {Number} cz z-coordinate for the control point (for WebGL mode) + * @param {Number} x3 + * @param {Number} y3 + * @param {Number} z3 z-coordinate for the anchor point (for WebGL mode) + * @chainable + * + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * setAttributes('antialias', true); + * } + * function draw() { + * orbitControl(); + * background(50); + * strokeWeight(4); + * stroke(255); + * + * point(-35, -35); + * point(35, -35); + * point(0, 0); + * point(-35, 35); + * point(35, 35); + * point(35, 10); + * + * strokeWeight(1); + * noFill(); + * + * beginShape(); + * vertex(-35, -35); + * quadraticVertex(35, -35, 0, 0); + * quadraticVertex(-35, 35, 35, 35); + * vertex(35, 10); + * endShape(); + * + * beginShape(); + * vertex(-35, -35, 20); + * quadraticVertex(35, -35, 20, 0, 0, 20); + * quadraticVertex(-35, 35, 20, 35, 35, 20); + * vertex(35, 10, 20); + * endShape(); + * } + * + *
+ * + * @alt + * backwards s-shaped black line with the same s-shaped line in postive z-axis. + */ + p5.prototype.quadraticVertex = function() { + p5._validateParameters('quadraticVertex', arguments); + if (this._renderer.isP3D) { + this._renderer.quadraticVertex.apply(this._renderer, arguments); + } else { + //if we're drawing a contour, put the points into an + // array for inside drawing + if (this._contourInited) { + var pt = {}; + pt.x = arguments[0]; + pt.y = arguments[1]; + pt.x3 = arguments[2]; + pt.y3 = arguments[3]; + pt.type = constants.QUADRATIC; + this._contourVertices.push(pt); + + return this; + } + if (vertices.length > 0) { + isQuadratic = true; + var vert = []; + for (var i = 0; i < arguments.length; i++) { + vert[i] = arguments[i]; + } + vert.isVert = false; + if (isContour) { + contourVertices.push(vert); + } else { + vertices.push(vert); + } + } else { + p5._friendlyError( + 'vertex() must be used once before calling quadraticVertex()', + 'quadraticVertex' + ); + } + } + return this; + }; + + /** + * All shapes are constructed by connecting a series of vertices. vertex() + * is used to specify the vertex coordinates for points, lines, triangles, + * quads, and polygons. It is used exclusively within the beginShape() and + * endShape() functions. + * + * @method vertex + * @param {Number} x x-coordinate of the vertex + * @param {Number} y y-coordinate of the vertex + * @chainable + * @example + *
+ * + * strokeWeight(3); + * beginShape(POINTS); + * vertex(30, 20); + * vertex(85, 20); + * vertex(85, 75); + * vertex(30, 75); + * endShape(); + * + *
+ * + *
+ * + * createCanvas(100, 100, WEBGL); + * background(240, 240, 240); + * fill(237, 34, 93); + * noStroke(); + * beginShape(); + * vertex(0, 35); + * vertex(35, 0); + * vertex(0, -35); + * vertex(-35, 0); + * endShape(); + * + *
+ * + *
+ * + * createCanvas(100, 100, WEBGL); + * background(240, 240, 240); + * fill(237, 34, 93); + * noStroke(); + * beginShape(); + * vertex(-10, 10); + * vertex(0, 35); + * vertex(10, 10); + * vertex(35, 0); + * vertex(10, -8); + * vertex(0, -35); + * vertex(-10, -8); + * vertex(-35, 0); + * endShape(); + * + *
+ * + *
+ * + * strokeWeight(3); + * stroke(237, 34, 93); + * beginShape(LINES); + * vertex(10, 35); + * vertex(90, 35); + * vertex(10, 65); + * vertex(90, 65); + * vertex(35, 10); + * vertex(35, 90); + * vertex(65, 10); + * vertex(65, 90); + * endShape(); + * + *
+ * + *
+ * + * // Click to change the number of sides. + * // In WebGL mode, custom shapes will only + * // display hollow fill sections when + * // all calls to vertex() use the same z-value. + * + * let sides = 3; + * let angle, px, py; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * setAttributes('antialias', true); + * fill(237, 34, 93); + * strokeWeight(3); + * } + * + * function draw() { + * background(200); + * rotateX(frameCount * 0.01); + * rotateZ(frameCount * 0.01); + * ngon(sides, 0, 0, 80); + * } + * + * function mouseClicked() { + * if (sides > 6) { + * sides = 3; + * } else { + * sides++; + * } + * } + * + * function ngon(n, x, y, d) { + * beginShape(); + * for (var i = 0; i < n + 1; i++) { + * angle = TWO_PI / n * i; + * px = x + sin(angle) * d / 2; + * py = y - cos(angle) * d / 2; + * vertex(px, py, 0); + * } + * for (i = 0; i < n + 1; i++) { + * angle = TWO_PI / n * i; + * px = x + sin(angle) * d / 4; + * py = y - cos(angle) * d / 4; + * vertex(px, py, 0); + * } + * endShape(); + * } + * + *
+ * @alt + * 4 black points in a square shape in middle-right of canvas. + * 4 points making a diamond shape. + * 8 points making a star. + * 8 points making 4 lines. + * A rotating 3D shape with a hollow section in the middle. + * + */ + /** + * @method vertex + * @param {Number} x + * @param {Number} y + * @param {Number} z z-coordinate of the vertex + * @param {Number} [u] the vertex's texture u-coordinate + * @param {Number} [v] the vertex's texture v-coordinate + * @chainable + */ + p5.prototype.vertex = function(x, y, moveTo, u, v) { + if (this._renderer.isP3D) { + this._renderer.vertex.apply(this._renderer, arguments); + } else { + var vert = []; + vert.isVert = true; + vert[0] = x; + vert[1] = y; + vert[2] = 0; + vert[3] = 0; + vert[4] = 0; + vert[5] = this._renderer._getFill(); + vert[6] = this._renderer._getStroke(); + + if (moveTo) { + vert.moveTo = moveTo; + } + if (isContour) { + if (contourVertices.length === 0) { + vert.moveTo = true; + } + contourVertices.push(vert); + } else { + vertices.push(vert); + } + } + return this; + }; + + module.exports = p5; + }, + { '../constants': 18, '../main': 24 } + ], + 34: [ + function(_dereq_, module, exports) { + 'use strict'; + + // requestAnim shim layer by Paul Irish + // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ + // http://my.opera.com/emoller/blog/2011/12/20/ + // requestanimationframe-for-smart-er-animating + // requestAnimationFrame polyfill by Erik Möller + // fixes from Paul Irish and Tino Zijdel + function _typeof(obj) { + if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { + _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + _typeof = function _typeof(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : typeof obj; + }; + } + return _typeof(obj); + } + window.requestAnimationFrame = (function() { + return ( + window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function(callback, element) { + // should '60' here be framerate? + window.setTimeout(callback, 1000 / 60); + } + ); + })(); + + /** + * shim for Uint8ClampedArray.slice + * (allows arrayCopy to work with pixels[]) + * with thanks to http://halfpapstudios.com/blog/tag/html5-canvas/ + * Enumerable set to false to protect for...in from + * Uint8ClampedArray.prototype pollution. + */ + (function() { + 'use strict'; + if ( + typeof Uint8ClampedArray !== 'undefined' && + !Uint8ClampedArray.prototype.slice + ) { + Object.defineProperty(Uint8ClampedArray.prototype, 'slice', { + value: Array.prototype.slice, + writable: true, + configurable: true, + enumerable: false + }); + } + })(); + + /** + * this is implementation of Object.assign() which is unavailable in + * IE11 and (non-Chrome) Android browsers. + * The assign() method is used to copy the values of all enumerable + * own properties from one or more source objects to a target object. + * It will return the target object. + * Modified from https://github.com/ljharb/object.assign + */ + (function() { + 'use strict'; + if (!Object.assign) { + var keys = Object.keys; + var defineProperty = Object.defineProperty; + var canBeObject = function canBeObject(obj) { + return typeof obj !== 'undefined' && obj !== null; + }; + var hasSymbols = + typeof Symbol === 'function' && _typeof(Symbol()) === 'symbol'; + var propIsEnumerable = Object.prototype.propertyIsEnumerable; + var isEnumerableOn = function isEnumerableOn(obj) { + return function isEnumerable(prop) { + return propIsEnumerable.call(obj, prop); + }; + }; + + // per ES6 spec, this function has to have a length of 2 + var assignShim = function assign(target, source1) { + if (!canBeObject(target)) { + throw new TypeError('target must be an object'); + } + var objTarget = Object(target); + var s, source, i, props; + for (s = 1; s < arguments.length; ++s) { + source = Object(arguments[s]); + props = keys(source); + if (hasSymbols && Object.getOwnPropertySymbols) { + props.push.apply( + props, + Object.getOwnPropertySymbols(source).filter(isEnumerableOn(source)) + ); + } + for (i = 0; i < props.length; ++i) { + objTarget[props[i]] = source[props[i]]; + } + } + return objTarget; + }; + + defineProperty(Object, 'assign', { + value: assignShim, + configurable: true, + enumerable: false, + writable: true + }); + } + })(); + }, + {} + ], + 35: [ + function(_dereq_, module, exports) { + /** + * @module Structure + * @submodule Structure + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('./main'); + + /** + * Stops p5.js from continuously executing the code within draw(). + * If loop() is called, the code in draw() begins to run continuously again. + * If using noLoop() in setup(), it should be the last line inside the block. + *

+ * When noLoop() is used, it's not possible to manipulate or access the + * screen inside event handling functions such as mousePressed() or + * keyPressed(). Instead, use those functions to call redraw() or loop(), + * which will run draw(), which can update the screen properly. This means + * that when noLoop() has been called, no drawing can happen, and functions + * like saveFrame() or loadPixels() may not be used. + *

+ * Note that if the sketch is resized, redraw() will be called to update + * the sketch, even after noLoop() has been specified. Otherwise, the sketch + * would enter an odd state until loop() was called. + * + * @method noLoop + * @example + *
+ * function setup() { + * createCanvas(100, 100); + * background(200); + * noLoop(); + * } + + * function draw() { + * line(10, 10, 90, 90); + * } + *
+ * + *
+ * let x = 0; + * function setup() { + * createCanvas(100, 100); + * } + * + * function draw() { + * background(204); + * x = x + 0.1; + * if (x > width) { + * x = 0; + * } + * line(x, 0, x, height); + * } + * + * function mousePressed() { + * noLoop(); + * } + * + * function mouseReleased() { + * loop(); + * } + *
+ * + * @alt + * 113 pixel long line extending from top-left to bottom right of canvas. + * horizontal line moves slowly from left. Loops but stops on mouse press. + * + */ + p5.prototype.noLoop = function() { + this._loop = false; + }; + /** + * By default, p5.js loops through draw() continuously, executing the code + * within it. However, the draw() loop may be stopped by calling noLoop(). + * In that case, the draw() loop can be resumed with loop(). + * + * Avoid calling loop() from inside setup(). + * + * @method loop + * @example + *
+ * let x = 0; + * function setup() { + * createCanvas(100, 100); + * noLoop(); + * } + * + * function draw() { + * background(204); + * x = x + 0.1; + * if (x > width) { + * x = 0; + * } + * line(x, 0, x, height); + * } + * + * function mousePressed() { + * loop(); + * } + * + * function mouseReleased() { + * noLoop(); + * } + *
+ * + * @alt + * horizontal line moves slowly from left. Loops but stops on mouse press. + * + */ + + p5.prototype.loop = function() { + if (!this._loop) { + this._loop = true; + if (this._setupDone) { + this._draw(); + } + } + }; + + /** + * The push() function saves the current drawing style settings and + * transformations, while pop() restores these settings. Note that these + * functions are always used together. They allow you to change the style + * and transformation settings and later return to what you had. When a new + * state is started with push(), it builds on the current style and transform + * information. The push() and pop() functions can be embedded to provide + * more control. (See the second example for a demonstration.) + *

+ * push() stores information related to the current transformation state + * and style settings controlled by the following functions: fill(), + * stroke(), tint(), strokeWeight(), strokeCap(), strokeJoin(), + * imageMode(), rectMode(), ellipseMode(), colorMode(), textAlign(), + * textFont(), textSize(), textLeading(). + *

+ * In WEBGL mode additional style settings are stored. These are controlled by the following functions: setCamera(), ambientLight(), directionalLight(), + * pointLight(), texture(), specularMaterial(), shininess(), normalMaterial() + * and shader(). + * + * @method push + * @example + *
+ * + * ellipse(0, 50, 33, 33); // Left circle + * + * push(); // Start a new drawing state + * strokeWeight(10); + * fill(204, 153, 0); + * translate(50, 0); + * ellipse(0, 50, 33, 33); // Middle circle + * pop(); // Restore original state + * + * ellipse(100, 50, 33, 33); // Right circle + * + *
+ *
+ * + * ellipse(0, 50, 33, 33); // Left circle + * + * push(); // Start a new drawing state + * strokeWeight(10); + * fill(204, 153, 0); + * ellipse(33, 50, 33, 33); // Left-middle circle + * + * push(); // Start another new drawing state + * stroke(0, 102, 153); + * ellipse(66, 50, 33, 33); // Right-middle circle + * pop(); // Restore previous state + * + * pop(); // Restore original state + * + * ellipse(100, 50, 33, 33); // Right circle + * + *
+ * + * @alt + * Gold ellipse + thick black outline @center 2 white ellipses on left and right. + * 2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right. + * + */ + p5.prototype.push = function() { + this._styles.push({ + props: { + _colorMode: this._colorMode + }, + + renderer: this._renderer.push() + }); + }; + + /** + * The push() function saves the current drawing style settings and + * transformations, while pop() restores these settings. Note that these + * functions are always used together. They allow you to change the style + * and transformation settings and later return to what you had. When a new + * state is started with push(), it builds on the current style and transform + * information. The push() and pop() functions can be embedded to provide + * more control. (See the second example for a demonstration.) + *

+ * push() stores information related to the current transformation state + * and style settings controlled by the following functions: fill(), + * stroke(), tint(), strokeWeight(), strokeCap(), strokeJoin(), + * imageMode(), rectMode(), ellipseMode(), colorMode(), textAlign(), + * textFont(), textSize(), textLeading(). + *

+ * In WEBGL mode additional style settings are stored. These are controlled by the following functions: setCamera(), ambientLight(), directionalLight(), + * pointLight(), texture(), specularMaterial(), shininess(), normalMaterial() + * and shader(). + * + * @method pop + * @example + *
+ * + * ellipse(0, 50, 33, 33); // Left circle + * + * push(); // Start a new drawing state + * translate(50, 0); + * strokeWeight(10); + * fill(204, 153, 0); + * ellipse(0, 50, 33, 33); // Middle circle + * pop(); // Restore original state + * + * ellipse(100, 50, 33, 33); // Right circle + * + *
+ *
+ * + * ellipse(0, 50, 33, 33); // Left circle + * + * push(); // Start a new drawing state + * strokeWeight(10); + * fill(204, 153, 0); + * ellipse(33, 50, 33, 33); // Left-middle circle + * + * push(); // Start another new drawing state + * stroke(0, 102, 153); + * ellipse(66, 50, 33, 33); // Right-middle circle + * pop(); // Restore previous state + * + * pop(); // Restore original state + * + * ellipse(100, 50, 33, 33); // Right circle + * + *
+ * + * @alt + * Gold ellipse + thick black outline @center 2 white ellipses on left and right. + * 2 Gold ellipses left black right blue stroke. 2 white ellipses on left+right. + * + */ + p5.prototype.pop = function() { + var style = this._styles.pop(); + if (style) { + this._renderer.pop(style.renderer); + Object.assign(this, style.props); + } else { + console.warn('pop() was called without matching push()'); + } + }; + + /** + * + * Executes the code within draw() one time. This functions allows the + * program to update the display window only when necessary, for example + * when an event registered by mousePressed() or keyPressed() occurs. + *

+ * In structuring a program, it only makes sense to call redraw() within + * events such as mousePressed(). This is because redraw() does not run + * draw() immediately (it only sets a flag that indicates an update is + * needed). + *

+ * The redraw() function does not work properly when called inside draw(). + * To enable/disable animations, use loop() and noLoop(). + *

+ * In addition you can set the number of redraws per method call. Just + * add an integer as single parameter for the number of redraws. + * + * @method redraw + * @param {Integer} [n] Redraw for n-times. The default value is 1. + * @example + *
+ * let x = 0; + * + * function setup() { + * createCanvas(100, 100); + * noLoop(); + * } + * + * function draw() { + * background(204); + * line(x, 0, x, height); + * } + * + * function mousePressed() { + * x += 1; + * redraw(); + * } + *
+ * + *
+ * let x = 0; + * + * function setup() { + * createCanvas(100, 100); + * noLoop(); + * } + * + * function draw() { + * background(204); + * x += 1; + * line(x, 0, x, height); + * } + * + * function mousePressed() { + * redraw(5); + * } + *
+ * + * @alt + * black line on far left of canvas + * black line on far left of canvas + * + */ + p5.prototype.redraw = function(n) { + if (this._inUserDraw || !this._setupDone) { + return; + } + + var numberOfRedraws = parseInt(n); + if (isNaN(numberOfRedraws) || numberOfRedraws < 1) { + numberOfRedraws = 1; + } + + var context = this._isGlobal ? window : this; + var userSetup = context.setup; + var userDraw = context.draw; + if (typeof userDraw === 'function') { + if (typeof userSetup === 'undefined') { + context.scale(context._pixelDensity, context._pixelDensity); + } + var callMethod = function callMethod(f) { + f.call(context); + }; + for (var idxRedraw = 0; idxRedraw < numberOfRedraws; idxRedraw++) { + context.resetMatrix(); + if (context._renderer.isP3D) { + context._renderer._update(); + } + context._setProperty('frameCount', context.frameCount + 1); + context._registeredMethods.pre.forEach(callMethod); + this._inUserDraw = true; + try { + userDraw(); + } finally { + this._inUserDraw = false; + } + context._registeredMethods.post.forEach(callMethod); + } + } + }; + + module.exports = p5; + }, + { './main': 24 } + ], + 36: [ + function(_dereq_, module, exports) { + /** + * @module Transform + * @submodule Transform + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('./main'); + + /** + * Multiplies the current matrix by the one specified through the parameters. + * This is a powerful operation that can perform the equivalent of translate, + * scale, shear and rotate all at once. You can learn more about transformation + * matrices on + * Wikipedia. + * + * The naming of the arguments here follows the naming of the + * WHATWG specification and corresponds to a + * transformation matrix of the + * form: + * + * > The transformation matrix used when applyMatrix is called + * + * @method applyMatrix + * @param {Number} a numbers which define the 2x3 matrix to be multiplied + * @param {Number} b numbers which define the 2x3 matrix to be multiplied + * @param {Number} c numbers which define the 2x3 matrix to be multiplied + * @param {Number} d numbers which define the 2x3 matrix to be multiplied + * @param {Number} e numbers which define the 2x3 matrix to be multiplied + * @param {Number} f numbers which define the 2x3 matrix to be multiplied + * @chainable + * @example + *
+ * + * function setup() { + * frameRate(10); + * rectMode(CENTER); + * } + * + * function draw() { + * var step = frameCount % 20; + * background(200); + * // Equivalent to translate(x, y); + * applyMatrix(1, 0, 0, 1, 40 + step, 50); + * rect(0, 0, 50, 50); + * } + * + *
+ *
+ * + * function setup() { + * frameRate(10); + * rectMode(CENTER); + * } + * + * function draw() { + * var step = frameCount % 20; + * background(200); + * translate(50, 50); + * // Equivalent to scale(x, y); + * applyMatrix(1 / step, 0, 0, 1 / step, 0, 0); + * rect(0, 0, 50, 50); + * } + * + *
+ *
+ * + * function setup() { + * frameRate(10); + * rectMode(CENTER); + * } + * + * function draw() { + * var step = frameCount % 20; + * var angle = map(step, 0, 20, 0, TWO_PI); + * var cos_a = cos(angle); + * var sin_a = sin(angle); + * background(200); + * translate(50, 50); + * // Equivalent to rotate(angle); + * applyMatrix(cos_a, sin_a, -sin_a, cos_a, 0, 0); + * rect(0, 0, 50, 50); + * } + * + *
+ *
+ * + * function setup() { + * frameRate(10); + * rectMode(CENTER); + * } + * + * function draw() { + * var step = frameCount % 20; + * var angle = map(step, 0, 20, -PI / 4, PI / 4); + * background(200); + * translate(50, 50); + * // equivalent to shearX(angle); + * var shear_factor = 1 / tan(PI / 2 - angle); + * applyMatrix(1, 0, shear_factor, 1, 0, 0); + * rect(0, 0, 50, 50); + * } + * + *
+ *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * noFill(); + * } + * + * function draw() { + * background(200); + * rotateY(PI / 6); + * stroke(153); + * box(35); + * var rad = millis() / 1000; + * // Set rotation angles + * var ct = cos(rad); + * var st = sin(rad); + * // Matrix for rotation around the Y axis + * // prettier-ignore + * applyMatrix( ct, 0.0, st, 0.0, + * 0.0, 1.0, 0.0, 0.0, + * -st, 0.0, ct, 0.0, + * 0.0, 0.0, 0.0, 1.0); + * stroke(255); + * box(50); + * } + * + *
+ * + * @alt + * A rectangle translating to the right + * A rectangle shrinking to the center + * A rectangle rotating clockwise about the center + * A rectangle shearing + * + */ + p5.prototype.applyMatrix = function(a, b, c, d, e, f) { + this._renderer.applyMatrix.apply(this._renderer, arguments); + return this; + }; + + /** + * Replaces the current matrix with the identity matrix. + * + * @method resetMatrix + * @chainable + * @example + *
+ * + * translate(50, 50); + * applyMatrix(0.5, 0.5, -0.5, 0.5, 0, 0); + * rect(0, 0, 20, 20); + * // Note that the translate is also reset. + * resetMatrix(); + * rect(0, 0, 20, 20); + * + *
+ * + * @alt + * A rotated retangle in the center with another at the top left corner + * + */ + p5.prototype.resetMatrix = function() { + this._renderer.resetMatrix(); + return this; + }; + + /** + * Rotates a shape the amount specified by the angle parameter. This + * function accounts for angleMode, so angles can be entered in either + * RADIANS or DEGREES. + *

+ * Objects are always rotated around their relative position to the + * origin and positive numbers rotate objects in a clockwise direction. + * Transformations apply to everything that happens after and subsequent + * calls to the function accumulates the effect. For example, calling + * rotate(HALF_PI) and then rotate(HALF_PI) is the same as rotate(PI). + * All tranformations are reset when draw() begins again. + *

+ * Technically, rotate() multiplies the current transformation matrix + * by a rotation matrix. This function can be further controlled by + * the push() and pop(). + * + * @method rotate + * @param {Number} angle the angle of rotation, specified in radians + * or degrees, depending on current angleMode + * @param {p5.Vector|Number[]} [axis] (in 3d) the axis to rotate around + * @chainable + * @example + *
+ * + * translate(width / 2, height / 2); + * rotate(PI / 3.0); + * rect(-26, -26, 52, 52); + * + *
+ * + * @alt + * white 52x52 rect with black outline at center rotated counter 45 degrees + * + */ + p5.prototype.rotate = function(angle, axis) { + p5._validateParameters('rotate', arguments); + this._renderer.rotate(this._toRadians(angle), axis); + return this; + }; + + /** + * Rotates around X axis. + * @method rotateX + * @param {Number} angle the angle of rotation, specified in radians + * or degrees, depending on current angleMode + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(255); + * rotateX(millis() / 1000); + * box(); + * } + * + *
+ * + * @alt + * 3d box rotating around the x axis. + */ + p5.prototype.rotateX = function(angle) { + this._assert3d('rotateX'); + p5._validateParameters('rotateX', arguments); + this._renderer.rotateX(this._toRadians(angle)); + return this; + }; + + /** + * Rotates around Y axis. + * @method rotateY + * @param {Number} angle the angle of rotation, specified in radians + * or degrees, depending on current angleMode + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(255); + * rotateY(millis() / 1000); + * box(); + * } + * + *
+ * + * @alt + * 3d box rotating around the y axis. + */ + p5.prototype.rotateY = function(angle) { + this._assert3d('rotateY'); + p5._validateParameters('rotateY', arguments); + this._renderer.rotateY(this._toRadians(angle)); + return this; + }; + + /** + * Rotates around Z axis. Webgl mode only. + * @method rotateZ + * @param {Number} angle the angle of rotation, specified in radians + * or degrees, depending on current angleMode + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(255); + * rotateZ(millis() / 1000); + * box(); + * } + * + *
+ * + * @alt + * 3d box rotating around the z axis. + */ + p5.prototype.rotateZ = function(angle) { + this._assert3d('rotateZ'); + p5._validateParameters('rotateZ', arguments); + this._renderer.rotateZ(this._toRadians(angle)); + return this; + }; + + /** + * Increases or decreases the size of a shape by expanding and contracting + * vertices. Objects always scale from their relative origin to the + * coordinate system. Scale values are specified as decimal percentages. + * For example, the function call scale(2.0) increases the dimension of a + * shape by 200%. + *

+ * Transformations apply to everything that happens after and subsequent + * calls to the function multiply the effect. For example, calling scale(2.0) + * and then scale(1.5) is the same as scale(3.0). If scale() is called + * within draw(), the transformation is reset when the loop begins again. + *

+ * Using this function with the z parameter is only available in WEBGL mode. + * This function can be further controlled with push() and pop(). + * + * @method scale + * @param {Number|p5.Vector|Number[]} s + * percent to scale the object, or percentage to + * scale the object in the x-axis if multiple arguments + * are given + * @param {Number} [y] percent to scale the object in the y-axis + * @param {Number} [z] percent to scale the object in the z-axis (webgl only) + * @chainable + * @example + *
+ * + * rect(30, 20, 50, 50); + * scale(0.5); + * rect(30, 20, 50, 50); + * + *
+ * + *
+ * + * rect(30, 20, 50, 50); + * scale(0.5, 1.3); + * rect(30, 20, 50, 50); + * + *
+ * + * @alt + * white 52x52 rect with black outline at center rotated counter 45 degrees + * 2 white rects with black outline- 1 50x50 at center. other 25x65 bottom left + * + */ + /** + * @method scale + * @param {p5.Vector|Number[]} scales per-axis percents to scale the object + * @chainable + */ + p5.prototype.scale = function(x, y, z) { + p5._validateParameters('scale', arguments); + // Only check for Vector argument type if Vector is available + if (x instanceof p5.Vector) { + var v = x; + x = v.x; + y = v.y; + z = v.z; + } else if (x instanceof Array) { + var rg = x; + x = rg[0]; + y = rg[1]; + z = rg[2] || 1; + } + if (isNaN(y)) { + y = z = x; + } else if (isNaN(z)) { + z = 1; + } + + this._renderer.scale.call(this._renderer, x, y, z); + + return this; + }; + + /** + * Shears a shape around the x-axis the amount specified by the angle + * parameter. Angles should be specified in the current angleMode. + * Objects are always sheared around their relative position to the origin + * and positive numbers shear objects in a clockwise direction. + *

+ * Transformations apply to everything that happens after and subsequent + * calls to the function accumulates the effect. For example, calling + * shearX(PI/2) and then shearX(PI/2) is the same as shearX(PI). + * If shearX() is called within the draw(), the transformation is reset when + * the loop begins again. + *

+ * Technically, shearX() multiplies the current transformation matrix by a + * rotation matrix. This function can be further controlled by the + * push() and pop() functions. + * + * @method shearX + * @param {Number} angle angle of shear specified in radians or degrees, + * depending on current angleMode + * @chainable + * @example + *
+ * + * translate(width / 4, height / 4); + * shearX(PI / 4.0); + * rect(0, 0, 30, 30); + * + *
+ * + * @alt + * white irregular quadrilateral with black outline at top middle. + * + */ + p5.prototype.shearX = function(angle) { + p5._validateParameters('shearX', arguments); + var rad = this._toRadians(angle); + this._renderer.applyMatrix(1, 0, Math.tan(rad), 1, 0, 0); + return this; + }; + + /** + * Shears a shape around the y-axis the amount specified by the angle + * parameter. Angles should be specified in the current angleMode. Objects + * are always sheared around their relative position to the origin and + * positive numbers shear objects in a clockwise direction. + *

+ * Transformations apply to everything that happens after and subsequent + * calls to the function accumulates the effect. For example, calling + * shearY(PI/2) and then shearY(PI/2) is the same as shearY(PI). If + * shearY() is called within the draw(), the transformation is reset when + * the loop begins again. + *

+ * Technically, shearY() multiplies the current transformation matrix by a + * rotation matrix. This function can be further controlled by the + * push() and pop() functions. + * + * @method shearY + * @param {Number} angle angle of shear specified in radians or degrees, + * depending on current angleMode + * @chainable + * @example + *
+ * + * translate(width / 4, height / 4); + * shearY(PI / 4.0); + * rect(0, 0, 30, 30); + * + *
+ * + * @alt + * white irregular quadrilateral with black outline at middle bottom. + * + */ + p5.prototype.shearY = function(angle) { + p5._validateParameters('shearY', arguments); + var rad = this._toRadians(angle); + this._renderer.applyMatrix(1, Math.tan(rad), 0, 1, 0, 0); + return this; + }; + + /** + * Specifies an amount to displace objects within the display window. + * The x parameter specifies left/right translation, the y parameter + * specifies up/down translation. + *

+ * Transformations are cumulative and apply to everything that happens after + * and subsequent calls to the function accumulates the effect. For example, + * calling translate(50, 0) and then translate(20, 0) is the same as + * translate(70, 0). If translate() is called within draw(), the + * transformation is reset when the loop begins again. This function can be + * further controlled by using push() and pop(). + * + * @method translate + * @param {Number} x left/right translation + * @param {Number} y up/down translation + * @param {Number} [z] forward/backward translation (webgl only) + * @chainable + * @example + *
+ * + * translate(30, 20); + * rect(0, 0, 55, 55); + * + *
+ * + *
+ * + * rect(0, 0, 55, 55); // Draw rect at original 0,0 + * translate(30, 20); + * rect(0, 0, 55, 55); // Draw rect at new 0,0 + * translate(14, 14); + * rect(0, 0, 55, 55); // Draw rect at new 0,0 + * + *
+ * + + *
+ * + * function draw() { + * background(200); + * rectMode(CENTER); + * translate(width / 2, height / 2); + * translate(p5.Vector.fromAngle(millis() / 1000, 40)); + * rect(0, 0, 20, 20); + * } + * + *
+ * + * @alt + * white 55x55 rect with black outline at center right. + * 3 white 55x55 rects with black outlines at top-l, center-r and bottom-r. + * a 20x20 white rect moving in a circle around the canvas + * + */ + /** + * @method translate + * @param {p5.Vector} vector the vector to translate by + * @chainable + */ + p5.prototype.translate = function(x, y, z) { + p5._validateParameters('translate', arguments); + if (this._renderer.isP3D) { + this._renderer.translate(x, y, z); + } else { + this._renderer.translate(x, y); + } + return this; + }; + + module.exports = p5; + }, + { './main': 24 } + ], + 37: [ + function(_dereq_, module, exports) { + /** + * @module Data + * @submodule LocalStorage + * @requires core + * + * This module defines the p5 methods for working with local storage + */ + + 'use strict'; + function _typeof(obj) { + if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { + _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + _typeof = function _typeof(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : typeof obj; + }; + } + return _typeof(obj); + } + var p5 = _dereq_('../core/main'); + /** + * + * Stores a value in local storage under the key name. + * Local storage is saved in the browser and persists + * between browsing sessions and page reloads. + * The key can be the name of the variable but doesn't + * have to be. To retrieve stored items + * see getItem. + *

+ * Sensitive data such as passwords or personal information + * should not be stored in local storage. + * + * @method storeItem + * @for p5 + * @param {String} key + * @param {String|Number|Object|Boolean|p5.Color} value + * + * @example + *
+ * // Type to change the letter in the + * // center of the canvas. + * // If you reload the page, it will + * // still display the last key you entered + * + * let myText; + * + * function setup() { + * createCanvas(100, 100); + * myText = getItem('myText'); + * if (myText === null) { + * myText = ''; + * } + * } + * + * function draw() { + * textSize(40); + * background(255); + * text(myText, width / 2, height / 2); + * } + * + * function keyPressed() { + * myText = key; + * storeItem('myText', myText); + * } + *
+ * + * @alt + * When you type the key name is displayed as black text on white background. + * If you reload the page, the last letter typed is still displaying. + * + */ + p5.prototype.storeItem = function(key, value) { + if (typeof value === 'undefined') { + console.log('You cannot store undefined variables using storeItem()'); + } + var type = _typeof(value); + switch (type) { + case 'number': + case 'boolean': + value = value.toString(); + break; + case 'object': + if (value instanceof p5.Color) { + type = 'p5.Color'; + } + value = JSON.stringify(value); + break; + case 'string': + default: + break; + } + + localStorage.setItem(key, value); + var typeKey = key + 'p5TypeID'; + localStorage.setItem(typeKey, type); + }; + + /** + * + * Returns the value of an item that was stored in local storage + * using storeItem() + * + * @method getItem + * @for p5 + * @param {String} key name that you wish to use to store in local storage + * @return {Number|Object|String|Boolean|p5.Color} Value of stored item + * + * @example + *
+ * // Click the mouse to change + * // the color of the background + * // Once you have changed the color + * // it will stay changed even when you + * // reload the page. + * + * let myColor; + * + * function setup() { + * createCanvas(100, 100); + * myColor = getItem('myColor'); + * } + * + * function draw() { + * if (myColor !== null) { + * background(myColor); + * } + * } + * + * function mousePressed() { + * myColor = color(random(255), random(255), random(255)); + * storeItem('myColor', myColor); + * } + *
+ * + * @alt + * If you click, the canvas changes to a random color. + * If you reload the page, the canvas is still the color it + * was when the page was previously loaded. + * + */ + p5.prototype.getItem = function(key) { + var value = localStorage.getItem(key); + var type = localStorage.getItem(key + 'p5TypeID'); + if (typeof type === 'undefined') { + console.log( + 'Unable to determine type of item stored under ' + + key + + 'in local storage. Did you save the item with something other than setItem()?' + ); + } else if (value !== null) { + switch (type) { + case 'number': + value = parseInt(value); + break; + case 'boolean': + value = value === 'true'; + break; + case 'object': + value = JSON.parse(value); + break; + case 'p5.Color': + value = JSON.parse(value); + value = this.color.apply(this, value.levels); + break; + case 'string': + default: + break; + } + } + return value; + }; + + /** + * + * Clears all local storage items set with storeItem() + * for the current domain. + * + * @method clearStorage + * @for p5 + * + * @example + *
+ * + * function setup() { + * let myNum = 10; + * let myBool = false; + * storeItem('myNum', myNum); + * storeItem('myBool', myBool); + * print(getItem('myNum')); // logs 10 to the console + * print(getItem('myBool')); // logs false to the console + * clearStorage(); + * print(getItem('myNum')); // logs null to the console + * print(getItem('myBool')); // logs null to the console + * } + *
+ */ + p5.prototype.clearStorage = function() { + localStorage.clear(); + }; + + /** + * + * Removes an item that was stored with storeItem() + * + * @method removeItem + * @param {String} key + * @for p5 + * + * @example + *
+ * + * function setup() { + * let myVar = 10; + * storeItem('myVar', myVar); + * print(getItem('myVar')); // logs 10 to the console + * removeItem('myVar'); + * print(getItem('myVar')); // logs null to the console + * } + *
+ */ + p5.prototype.removeItem = function(key) { + if (typeof key !== 'string') { + console.log( + 'The argument that you passed to removeItem() - ' + + key + + ' is not a string.' + ); + } + localStorage.removeItem(key); + localStorage.removeItem(key + 'p5TypeID'); + }; + }, + { '../core/main': 24 } + ], + 38: [ + function(_dereq_, module, exports) { + /** + * @module Data + * @submodule Dictionary + * @for p5.TypedDict + * @requires core + * + * This module defines the p5 methods for the p5 Dictionary classes. + * The classes StringDict and NumberDict are for storing and working + * with key-value pairs. + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * + * Creates a new instance of p5.StringDict using the key-value pair + * or the object you provide. + * + * @method createStringDict + * @for p5 + * @param {String} key + * @param {String} value + * @return {p5.StringDict} + * + * @example + *
+ * + * function setup() { + * let myDictionary = createStringDict('p5', 'js'); + * print(myDictionary.hasKey('p5')); // logs true to console + * + * let anotherDictionary = createStringDict({ happy: 'coding' }); + * print(anotherDictionary.hasKey('happy')); // logs true to console + * } + *
+ */ + /** + * @method createStringDict + * @param {Object} object object + * @return {p5.StringDict} + */ + + p5.prototype.createStringDict = function(key, value) { + p5._validateParameters('createStringDict', arguments); + return new p5.StringDict(key, value); + }; + + /** + * + * Creates a new instance of p5.NumberDict using the key-value pair + * or object you provide. + * + * @method createNumberDict + * @for p5 + * @param {Number} key + * @param {Number} value + * @return {p5.NumberDict} + * + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict(100, 42); + * print(myDictionary.hasKey(100)); // logs true to console + * + * let anotherDictionary = createNumberDict({ 200: 84 }); + * print(anotherDictionary.hasKey(200)); // logs true to console + * } + *
+ */ + /** + * @method createNumberDict + * @param {Object} object object + * @return {p5.NumberDict} + */ + + p5.prototype.createNumberDict = function(key, value) { + p5._validateParameters('createNumberDict', arguments); + return new p5.NumberDict(key, value); + }; + + /** + * + * Base class for all p5.Dictionary types. Specifically + * typed Dictionary classes inherit from this class. + * + * @class p5.TypedDict + * + */ + + p5.TypedDict = function(key, value) { + if (key instanceof Object) { + this.data = key; + } else { + this.data = {}; + this.data[key] = value; + } + return this; + }; + + /** + * Returns the number of key-value pairs currently stored in the Dictionary. + * + * @method size + * @return {Integer} the number of key-value pairs in the Dictionary + * + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict(1, 10); + * myDictionary.create(2, 20); + * myDictionary.create(3, 30); + * print(myDictionary.size()); // logs 3 to the console + * } + *
+ * + */ + p5.TypedDict.prototype.size = function() { + return Object.keys(this.data).length; + }; + + /** + * Returns true if the given key exists in the Dictionary, + * otherwise returns false. + * + * @method hasKey + * @param {Number|String} key that you want to look up + * @return {Boolean} whether that key exists in Dictionary + * + * @example + *
+ * + * function setup() { + * let myDictionary = createStringDict('p5', 'js'); + * print(myDictionary.hasKey('p5')); // logs true to console + * } + *
+ * + */ + + p5.TypedDict.prototype.hasKey = function(key) { + return this.data.hasOwnProperty(key); + }; + + /** + * Returns the value stored at the given key. + * + * @method get + * @param {Number|String} the key you want to access + * @return {Number|String} the value stored at that key + * + * @example + *
+ * + * function setup() { + * let myDictionary = createStringDict('p5', 'js'); + * let myValue = myDictionary.get('p5'); + * print(myValue === 'js'); // logs true to console + * } + *
+ * + */ + + p5.TypedDict.prototype.get = function(key) { + if (this.data.hasOwnProperty(key)) { + return this.data[key]; + } else { + console.log(key + ' does not exist in this Dictionary'); + } + }; + + /** + * Updates the value associated with the given key in case it already exists + * in the Dictionary. Otherwise a new key-value pair is added. + * + * @method set + * @param {Number|String} key + * @param {Number|String} value + * + * @example + *
+ * + * function setup() { + * let myDictionary = createStringDict('p5', 'js'); + * myDictionary.set('p5', 'JS'); + * myDictionary.print(); // logs "key: p5 - value: JS" to console + * } + *
+ * + */ + + p5.TypedDict.prototype.set = function(key, value) { + if (this._validate(value)) { + this.data[key] = value; + } else { + console.log('Those values dont work for this dictionary type.'); + } + }; + + /** + * private helper function to handle the user passing in objects + * during construction or calls to create() + */ + + p5.TypedDict.prototype._addObj = function(obj) { + for (var key in obj) { + this.set(key, obj[key]); + } + }; + + /** + * Creates a new key-value pair in the Dictionary. + * + * @method create + * @param {Number|String} key + * @param {Number|String} value + * + * @example + *
+ * + * function setup() { + * let myDictionary = createStringDict('p5', 'js'); + * myDictionary.create('happy', 'coding'); + * myDictionary.print(); + * // above logs "key: p5 - value: js, key: happy - value: coding" to console + * } + *
+ */ + /** + * @method create + * @param {Object} obj key/value pair + */ + + p5.TypedDict.prototype.create = function(key, value) { + if (key instanceof Object && typeof value === 'undefined') { + this._addObj(key); + } else if (typeof key !== 'undefined') { + this.set(key, value); + } else { + console.log( + 'In order to create a new Dictionary entry you must pass ' + + 'an object or a key, value pair' + ); + } + }; + + /** + * Removes all previously stored key-value pairs from the Dictionary. + * + * @method clear + * @example + *
+ * + * function setup() { + * let myDictionary = createStringDict('p5', 'js'); + * print(myDictionary.hasKey('p5')); // prints 'true' + * myDictionary.clear(); + * print(myDictionary.hasKey('p5')); // prints 'false' + * } + * + *
+ */ + + p5.TypedDict.prototype.clear = function() { + this.data = {}; + }; + + /** + * Removes the key-value pair stored at the given key from the Dictionary. + * + * @method remove + * @param {Number|String} key for the pair to remove + * + * @example + *
+ * + * function setup() { + * let myDictionary = createStringDict('p5', 'js'); + * myDictionary.create('happy', 'coding'); + * myDictionary.print(); + * // above logs "key: p5 - value: js, key: happy - value: coding" to console + * myDictionary.remove('p5'); + * myDictionary.print(); + * // above logs "key: happy value: coding" to console + * } + *
+ * + */ + + p5.TypedDict.prototype.remove = function(key) { + if (this.data.hasOwnProperty(key)) { + delete this.data[key]; + } else { + throw new Error(key + ' does not exist in this Dictionary'); + } + }; + + /** + * Logs the set of items currently stored in the Dictionary to the console. + * + * @method print + * + * @example + *
+ * + * function setup() { + * let myDictionary = createStringDict('p5', 'js'); + * myDictionary.create('happy', 'coding'); + * myDictionary.print(); + * // above logs "key: p5 - value: js, key: happy - value: coding" to console + * } + * + *
+ */ + + p5.TypedDict.prototype.print = function() { + for (var item in this.data) { + console.log('key:' + item + ' value:' + this.data[item]); + } + }; + + /** + * Converts the Dictionary into a CSV file for local download. + * + * @method saveTable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100); + * background(200); + * text('click here to save', 10, 10, 70, 80); + * } + * + * function mousePressed() { + * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + * createStringDict({ + * john: 1940, + * paul: 1942, + * george: 1943, + * ringo: 1940 + * }).saveTable('beatles'); + * } + * } + * + *
+ */ + + p5.TypedDict.prototype.saveTable = function(filename) { + var output = ''; + + for (var key in this.data) { + output += key + ',' + this.data[key] + '\n'; + } + + var blob = new Blob([output], { type: 'text/csv' }); + p5.prototype.downloadFile(blob, filename || 'mycsv', 'csv'); + }; + + /** + * Converts the Dictionary into a JSON file for local download. + * + * @method saveJSON + * @example + *
+ * + * function setup() { + * createCanvas(100, 100); + * background(200); + * text('click here to save', 10, 10, 70, 80); + * } + * + * function mousePressed() { + * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + * createStringDict({ + * john: 1940, + * paul: 1942, + * george: 1943, + * ringo: 1940 + * }).saveJSON('beatles'); + * } + * } + * + *
+ */ + + p5.TypedDict.prototype.saveJSON = function(filename, opt) { + p5.prototype.saveJSON(this.data, filename, opt); + }; + + /** + * private helper function to ensure that the user passed in valid + * values for the Dictionary type + */ + + p5.TypedDict.prototype._validate = function(value) { + return true; + }; + + /** + * + * A simple Dictionary class for Strings. + * + * @class p5.StringDict + * @extends p5.TypedDict + * + */ + + p5.StringDict = function() { + p5.TypedDict.apply(this, arguments); + }; + + p5.StringDict.prototype = Object.create(p5.TypedDict.prototype); + + p5.StringDict.prototype._validate = function(value) { + return typeof value === 'string'; + }; + + /** + * + * A simple Dictionary class for Numbers. + * + * @class p5.NumberDict + * @extends p5.TypedDict + * + */ + + p5.NumberDict = function() { + p5.TypedDict.apply(this, arguments); + }; + + p5.NumberDict.prototype = Object.create(p5.TypedDict.prototype); + + /** + * private helper function to ensure that the user passed in valid + * values for the Dictionary type + */ + + p5.NumberDict.prototype._validate = function(value) { + return typeof value === 'number'; + }; + + /** + * Add the given number to the value currently stored at the given key. + * The sum then replaces the value previously stored in the Dictionary. + * + * @method add + * @param {Number} Key for the value you wish to add to + * @param {Number} Number to add to the value + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict(2, 5); + * myDictionary.add(2, 2); + * print(myDictionary.get(2)); // logs 7 to console. + * } + *
+ * + * + */ + + p5.NumberDict.prototype.add = function(key, amount) { + if (this.data.hasOwnProperty(key)) { + this.data[key] += amount; + } else { + console.log('The key - ' + key + ' does not exist in this dictionary.'); + } + }; + + /** + * Subtract the given number from the value currently stored at the given key. + * The difference then replaces the value previously stored in the Dictionary. + * + * @method sub + * @param {Number} Key for the value you wish to subtract from + * @param {Number} Number to subtract from the value + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict(2, 5); + * myDictionary.sub(2, 2); + * print(myDictionary.get(2)); // logs 3 to console. + * } + *
+ * + * + */ + + p5.NumberDict.prototype.sub = function(key, amount) { + this.add(key, -amount); + }; + + /** + * Multiply the given number with the value currently stored at the given key. + * The product then replaces the value previously stored in the Dictionary. + * + * @method mult + * @param {Number} Key for value you wish to multiply + * @param {Number} Amount to multiply the value by + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict(2, 4); + * myDictionary.mult(2, 2); + * print(myDictionary.get(2)); // logs 8 to console. + * } + *
+ * + * + */ + + p5.NumberDict.prototype.mult = function(key, amount) { + if (this.data.hasOwnProperty(key)) { + this.data[key] *= amount; + } else { + console.log('The key - ' + key + ' does not exist in this dictionary.'); + } + }; + + /** + * Divide the given number with the value currently stored at the given key. + * The quotient then replaces the value previously stored in the Dictionary. + * + * @method div + * @param {Number} Key for value you wish to divide + * @param {Number} Amount to divide the value by + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict(2, 8); + * myDictionary.div(2, 2); + * print(myDictionary.get(2)); // logs 4 to console. + * } + *
+ * + * + */ + + p5.NumberDict.prototype.div = function(key, amount) { + if (this.data.hasOwnProperty(key)) { + this.data[key] /= amount; + } else { + console.log('The key - ' + key + ' does not exist in this dictionary.'); + } + }; + + /** + * private helper function for finding lowest or highest value + * the argument 'flip' is used to flip the comparison arrow + * from 'less than' to 'greater than' + * + */ + + p5.NumberDict.prototype._valueTest = function(flip) { + if (Object.keys(this.data).length === 0) { + throw new Error( + 'Unable to search for a minimum or maximum value on an empty NumberDict' + ); + } else if (Object.keys(this.data).length === 1) { + return this.data[Object.keys(this.data)[0]]; + } else { + var result = this.data[Object.keys(this.data)[0]]; + for (var key in this.data) { + if (this.data[key] * flip < result * flip) { + result = this.data[key]; + } + } + return result; + } + }; + + /** + * Return the lowest number currently stored in the Dictionary. + * + * @method minValue + * @return {Number} + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 }); + * let lowestValue = myDictionary.minValue(); // value is -10 + * print(lowestValue); + * } + *
+ * + */ + + p5.NumberDict.prototype.minValue = function() { + return this._valueTest(1); + }; + + /** + * Return the highest number currently stored in the Dictionary. + * + * @method maxValue + * @return {Number} + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 }); + * let highestValue = myDictionary.maxValue(); // value is 3 + * print(highestValue); + * } + *
+ * + */ + + p5.NumberDict.prototype.maxValue = function() { + return this._valueTest(-1); + }; + + /** + * private helper function for finding lowest or highest key + * the argument 'flip' is used to flip the comparison arrow + * from 'less than' to 'greater than' + * + */ + + p5.NumberDict.prototype._keyTest = function(flip) { + if (Object.keys(this.data).length === 0) { + throw new Error('Unable to use minValue on an empty NumberDict'); + } else if (Object.keys(this.data).length === 1) { + return Object.keys(this.data)[0]; + } else { + var result = Object.keys(this.data)[0]; + for (var i = 1; i < Object.keys(this.data).length; i++) { + if (Object.keys(this.data)[i] * flip < result * flip) { + result = Object.keys(this.data)[i]; + } + } + return result; + } + }; + + /** + * Return the lowest key currently used in the Dictionary. + * + * @method minKey + * @return {Number} + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 }); + * let lowestKey = myDictionary.minKey(); // value is 1.2 + * print(lowestKey); + * } + *
+ * + */ + + p5.NumberDict.prototype.minKey = function() { + return this._keyTest(1); + }; + + /** + * Return the highest key currently used in the Dictionary. + * + * @method maxKey + * @return {Number} + * @example + *
+ * + * function setup() { + * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 }); + * let highestKey = myDictionary.maxKey(); // value is 4 + * print(highestKey); + * } + *
+ * + */ + + p5.NumberDict.prototype.maxKey = function() { + return this._keyTest(-1); + }; + + module.exports = p5.TypedDict; + }, + { '../core/main': 24 } + ], + 39: [ + function(_dereq_, module, exports) { + /** + * @module Events + * @submodule Acceleration + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * The system variable deviceOrientation always contains the orientation of + * the device. The value of this variable will either be set 'landscape' + * or 'portrait'. If no data is available it will be set to 'undefined'. + * either LANDSCAPE or PORTRAIT. + * + * @property {Constant} deviceOrientation + * @readOnly + */ + p5.prototype.deviceOrientation = undefined; + + /** + * The system variable accelerationX always contains the acceleration of the + * device along the x axis. Value is represented as meters per second squared. + * + * @property {Number} accelerationX + * @readOnly + * @example + *
+ * + * // Move a touchscreen device to register + * // acceleration changes. + * function draw() { + * background(220, 50); + * fill('magenta'); + * ellipse(width / 2, height / 2, accelerationX); + * } + * + *
+ * @alt + * Magnitude of device acceleration is displayed as ellipse size + */ + p5.prototype.accelerationX = 0; + + /** + * The system variable accelerationY always contains the acceleration of the + * device along the y axis. Value is represented as meters per second squared. + * + * @property {Number} accelerationY + * @readOnly + * @example + *
+ * + * // Move a touchscreen device to register + * // acceleration changes. + * function draw() { + * background(220, 50); + * fill('magenta'); + * ellipse(width / 2, height / 2, accelerationY); + * } + * + *
+ * @alt + * Magnitude of device acceleration is displayed as ellipse size + */ + p5.prototype.accelerationY = 0; + + /** + * The system variable accelerationZ always contains the acceleration of the + * device along the z axis. Value is represented as meters per second squared. + * + * @property {Number} accelerationZ + * @readOnly + * + * @example + *
+ * + * // Move a touchscreen device to register + * // acceleration changes. + * function draw() { + * background(220, 50); + * fill('magenta'); + * ellipse(width / 2, height / 2, accelerationZ); + * } + * + *
+ * + * @alt + * Magnitude of device acceleration is displayed as ellipse size + */ + p5.prototype.accelerationZ = 0; + + /** + * The system variable pAccelerationX always contains the acceleration of the + * device along the x axis in the frame previous to the current frame. Value + * is represented as meters per second squared. + * + * @property {Number} pAccelerationX + * @readOnly + */ + p5.prototype.pAccelerationX = 0; + + /** + * The system variable pAccelerationY always contains the acceleration of the + * device along the y axis in the frame previous to the current frame. Value + * is represented as meters per second squared. + * + * @property {Number} pAccelerationY + * @readOnly + */ + p5.prototype.pAccelerationY = 0; + + /** + * The system variable pAccelerationZ always contains the acceleration of the + * device along the z axis in the frame previous to the current frame. Value + * is represented as meters per second squared. + * + * @property {Number} pAccelerationZ + * @readOnly + */ + p5.prototype.pAccelerationZ = 0; + + /** + * _updatePAccelerations updates the pAcceleration values + * + * @private + */ + p5.prototype._updatePAccelerations = function() { + this._setProperty('pAccelerationX', this.accelerationX); + this._setProperty('pAccelerationY', this.accelerationY); + this._setProperty('pAccelerationZ', this.accelerationZ); + }; + + /** + * The system variable rotationX always contains the rotation of the + * device along the x axis. Value is represented as 0 to +/-180 degrees. + *

+ * Note: The order the rotations are called is important, ie. if used + * together, it must be called in the order Z-X-Y or there might be + * unexpected behaviour. + * + * @property {Number} rotationX + * @readOnly + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * //rotateZ(radians(rotationZ)); + * rotateX(radians(rotationX)); + * //rotateY(radians(rotationY)); + * box(200, 200, 200); + * } + * + *
+ * @alt + * red horizontal line right, green vertical line bottom. black background. + */ + p5.prototype.rotationX = 0; + + /** + * The system variable rotationY always contains the rotation of the + * device along the y axis. Value is represented as 0 to +/-90 degrees. + *

+ * Note: The order the rotations are called is important, ie. if used + * together, it must be called in the order Z-X-Y or there might be + * unexpected behaviour. + * + * @property {Number} rotationY + * @readOnly + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * //rotateZ(radians(rotationZ)); + * //rotateX(radians(rotationX)); + * rotateY(radians(rotationY)); + * box(200, 200, 200); + * } + * + *
+ * @alt + * red horizontal line right, green vertical line bottom. black background. + */ + p5.prototype.rotationY = 0; + + /** + * The system variable rotationZ always contains the rotation of the + * device along the z axis. Value is represented as 0 to 359 degrees. + *

+ * Unlike rotationX and rotationY, this variable is available for devices + * with a built-in compass only. + *

+ * Note: The order the rotations are called is important, ie. if used + * together, it must be called in the order Z-X-Y or there might be + * unexpected behaviour. + * + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * rotateZ(radians(rotationZ)); + * //rotateX(radians(rotationX)); + * //rotateY(radians(rotationY)); + * box(200, 200, 200); + * } + * + *
+ * + * @property {Number} rotationZ + * @readOnly + * + * @alt + * red horizontal line right, green vertical line bottom. black background. + */ + p5.prototype.rotationZ = 0; + + /** + * The system variable pRotationX always contains the rotation of the + * device along the x axis in the frame previous to the current frame. Value + * is represented as 0 to +/-180 degrees. + *

+ * pRotationX can also be used with rotationX to determine the rotate + * direction of the device along the X-axis. + * @example + *
+ * + * // A simple if statement looking at whether + * // rotationX - pRotationX < 0 is true or not will be + * // sufficient for determining the rotate direction + * // in most cases. + * + * // Some extra logic is needed to account for cases where + * // the angles wrap around. + * let rotateDirection = 'clockwise'; + * + * // Simple range conversion to make things simpler. + * // This is not absolutely necessary but the logic + * // will be different in that case. + * + * let rX = rotationX + 180; + * let pRX = pRotationX + 180; + * + * if ((rX - pRX > 0 && rX - pRX < 270) || rX - pRX < -270) { + * rotateDirection = 'clockwise'; + * } else if (rX - pRX < 0 || rX - pRX > 270) { + * rotateDirection = 'counter-clockwise'; + * } + * + * print(rotateDirection); + * + *
+ * + * @alt + * no image to display. + * + * + * @property {Number} pRotationX + * @readOnly + */ + p5.prototype.pRotationX = 0; + + /** + * The system variable pRotationY always contains the rotation of the + * device along the y axis in the frame previous to the current frame. Value + * is represented as 0 to +/-90 degrees. + *

+ * pRotationY can also be used with rotationY to determine the rotate + * direction of the device along the Y-axis. + * @example + *
+ * + * // A simple if statement looking at whether + * // rotationY - pRotationY < 0 is true or not will be + * // sufficient for determining the rotate direction + * // in most cases. + * + * // Some extra logic is needed to account for cases where + * // the angles wrap around. + * let rotateDirection = 'clockwise'; + * + * // Simple range conversion to make things simpler. + * // This is not absolutely necessary but the logic + * // will be different in that case. + * + * let rY = rotationY + 180; + * let pRY = pRotationY + 180; + * + * if ((rY - pRY > 0 && rY - pRY < 270) || rY - pRY < -270) { + * rotateDirection = 'clockwise'; + * } else if (rY - pRY < 0 || rY - pRY > 270) { + * rotateDirection = 'counter-clockwise'; + * } + * print(rotateDirection); + * + *
+ * + * @alt + * no image to display. + * + * + * @property {Number} pRotationY + * @readOnly + */ + p5.prototype.pRotationY = 0; + + /** + * The system variable pRotationZ always contains the rotation of the + * device along the z axis in the frame previous to the current frame. Value + * is represented as 0 to 359 degrees. + *

+ * pRotationZ can also be used with rotationZ to determine the rotate + * direction of the device along the Z-axis. + * @example + *
+ * + * // A simple if statement looking at whether + * // rotationZ - pRotationZ < 0 is true or not will be + * // sufficient for determining the rotate direction + * // in most cases. + * + * // Some extra logic is needed to account for cases where + * // the angles wrap around. + * let rotateDirection = 'clockwise'; + * + * if ( + * (rotationZ - pRotationZ > 0 && rotationZ - pRotationZ < 270) || + * rotationZ - pRotationZ < -270 + * ) { + * rotateDirection = 'clockwise'; + * } else if (rotationZ - pRotationZ < 0 || rotationZ - pRotationZ > 270) { + * rotateDirection = 'counter-clockwise'; + * } + * print(rotateDirection); + * + *
+ * + * @alt + * no image to display. + * + * + * @property {Number} pRotationZ + * @readOnly + */ + p5.prototype.pRotationZ = 0; + + var startAngleX = 0; + var startAngleY = 0; + var startAngleZ = 0; + + var rotateDirectionX = 'clockwise'; + var rotateDirectionY = 'clockwise'; + var rotateDirectionZ = 'clockwise'; + + var pRotateDirectionX; + var pRotateDirectionY; + var pRotateDirectionZ; + + p5.prototype._updatePRotations = function() { + this._setProperty('pRotationX', this.rotationX); + this._setProperty('pRotationY', this.rotationY); + this._setProperty('pRotationZ', this.rotationZ); + }; + + /** + * When a device is rotated, the axis that triggers the deviceTurned() + * method is stored in the turnAxis variable. The turnAxis variable is only defined within + * the scope of deviceTurned(). + * @property {String} turnAxis + * @readOnly + * @example + *
+ * + * // Run this example on a mobile device + * // Rotate the device by 90 degrees in the + * // X-axis to change the value. + * + * var value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceTurned() { + * if (turnAxis === 'X') { + * if (value === 0) { + * value = 255; + * } else if (value === 255) { + * value = 0; + * } + * } + * } + * + *
+ * + * @alt + * 50x50 black rect in center of canvas. turns white on mobile when device turns + * 50x50 black rect in center of canvas. turns white on mobile when x-axis turns + */ + p5.prototype.turnAxis = undefined; + + var move_threshold = 0.5; + var shake_threshold = 30; + + /** + * The setMoveThreshold() function is used to set the movement threshold for + * the deviceMoved() function. The default threshold is set to 0.5. + * + * @method setMoveThreshold + * @param {number} value The threshold value + * @example + *
+ * + * // Run this example on a mobile device + * // You will need to move the device incrementally further + * // the closer the square's color gets to white in order to change the value. + * + * let value = 0; + * let threshold = 0.5; + * function setup() { + * setMoveThreshold(threshold); + * } + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceMoved() { + * value = value + 5; + * threshold = threshold + 0.1; + * if (value > 255) { + * value = 0; + * threshold = 30; + * } + * setMoveThreshold(threshold); + * } + * + *
+ * + * @alt + * 50x50 black rect in center of canvas. turns white on mobile when device moves + */ + + p5.prototype.setMoveThreshold = function(val) { + p5._validateParameters('setMoveThreshold', arguments); + move_threshold = val; + }; + + /** + * The setShakeThreshold() function is used to set the movement threshold for + * the deviceShaken() function. The default threshold is set to 30. + * + * @method setShakeThreshold + * @param {number} value The threshold value + * @example + *
+ * + * // Run this example on a mobile device + * // You will need to shake the device more firmly + * // the closer the box's fill gets to white in order to change the value. + * + * let value = 0; + * let threshold = 30; + * function setup() { + * setShakeThreshold(threshold); + * } + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceMoved() { + * value = value + 5; + * threshold = threshold + 5; + * if (value > 255) { + * value = 0; + * threshold = 30; + * } + * setShakeThreshold(threshold); + * } + * + *
+ * + * @alt + * 50x50 black rect in center of canvas. turns white on mobile when device + * is being shaked + */ + + p5.prototype.setShakeThreshold = function(val) { + p5._validateParameters('setShakeThreshold', arguments); + shake_threshold = val; + }; + + /** + * The deviceMoved() function is called when the device is moved by more than + * the threshold value along X, Y or Z axis. The default threshold is set to 0.5. + * The threshold value can be changed using setMoveThreshold(). + * + * @method deviceMoved + * @example + *
+ * + * // Run this example on a mobile device + * // Move the device around + * // to change the value. + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceMoved() { + * value = value + 5; + * if (value > 255) { + * value = 0; + * } + * } + * + *
+ * + * @alt + * 50x50 black rect in center of canvas. turns white on mobile when device moves + * + */ + + /** + * The deviceTurned() function is called when the device rotates by + * more than 90 degrees continuously. + *

+ * The axis that triggers the deviceTurned() method is stored in the turnAxis + * variable. The deviceTurned() method can be locked to trigger on any axis: + * X, Y or Z by comparing the turnAxis variable to 'X', 'Y' or 'Z'. + * + * @method deviceTurned + * @example + *
+ * + * // Run this example on a mobile device + * // Rotate the device by 90 degrees + * // to change the value. + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceTurned() { + * if (value === 0) { + * value = 255; + * } else if (value === 255) { + * value = 0; + * } + * } + * + *
+ *
+ * + * // Run this example on a mobile device + * // Rotate the device by 90 degrees in the + * // X-axis to change the value. + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceTurned() { + * if (turnAxis === 'X') { + * if (value === 0) { + * value = 255; + * } else if (value === 255) { + * value = 0; + * } + * } + * } + * + *
+ * + * @alt + * 50x50 black rect in center of canvas. turns white on mobile when device turns + * 50x50 black rect in center of canvas. turns white on mobile when x-axis turns + * + */ + + /** + * The deviceShaken() function is called when the device total acceleration + * changes of accelerationX and accelerationY values is more than + * the threshold value. The default threshold is set to 30. + * The threshold value can be changed using setShakeThreshold(). + * + * @method deviceShaken + * @example + *
+ * + * // Run this example on a mobile device + * // Shake the device to change the value. + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function deviceShaken() { + * value = value + 5; + * if (value > 255) { + * value = 0; + * } + * } + * + *
+ * + * @alt + * 50x50 black rect in center of canvas. turns white on mobile when device shakes + * + */ + + p5.prototype._ondeviceorientation = function(e) { + this._updatePRotations(); + this._setProperty('rotationX', e.beta); + this._setProperty('rotationY', e.gamma); + this._setProperty('rotationZ', e.alpha); + this._handleMotion(); + }; + p5.prototype._ondevicemotion = function(e) { + this._updatePAccelerations(); + this._setProperty('accelerationX', e.acceleration.x * 2); + this._setProperty('accelerationY', e.acceleration.y * 2); + this._setProperty('accelerationZ', e.acceleration.z * 2); + this._handleMotion(); + }; + p5.prototype._handleMotion = function() { + if (window.orientation === 90 || window.orientation === -90) { + this._setProperty('deviceOrientation', 'landscape'); + } else if (window.orientation === 0) { + this._setProperty('deviceOrientation', 'portrait'); + } else if (window.orientation === undefined) { + this._setProperty('deviceOrientation', 'undefined'); + } + var deviceMoved = this.deviceMoved || window.deviceMoved; + if (typeof deviceMoved === 'function') { + if ( + Math.abs(this.accelerationX - this.pAccelerationX) > move_threshold || + Math.abs(this.accelerationY - this.pAccelerationY) > move_threshold || + Math.abs(this.accelerationZ - this.pAccelerationZ) > move_threshold + ) { + deviceMoved(); + } + } + var deviceTurned = this.deviceTurned || window.deviceTurned; + if (typeof deviceTurned === 'function') { + // The angles given by rotationX etc is from range -180 to 180. + // The following will convert them to 0 to 360 for ease of calculation + // of cases when the angles wrapped around. + // _startAngleX will be converted back at the end and updated. + var wRX = this.rotationX + 180; + var wPRX = this.pRotationX + 180; + var wSAX = startAngleX + 180; + if ((wRX - wPRX > 0 && wRX - wPRX < 270) || wRX - wPRX < -270) { + rotateDirectionX = 'clockwise'; + } else if (wRX - wPRX < 0 || wRX - wPRX > 270) { + rotateDirectionX = 'counter-clockwise'; + } + if (rotateDirectionX !== pRotateDirectionX) { + wSAX = wRX; + } + if (Math.abs(wRX - wSAX) > 90 && Math.abs(wRX - wSAX) < 270) { + wSAX = wRX; + this._setProperty('turnAxis', 'X'); + deviceTurned(); + } + pRotateDirectionX = rotateDirectionX; + startAngleX = wSAX - 180; + + // Y-axis is identical to X-axis except for changing some names. + var wRY = this.rotationY + 180; + var wPRY = this.pRotationY + 180; + var wSAY = startAngleY + 180; + if ((wRY - wPRY > 0 && wRY - wPRY < 270) || wRY - wPRY < -270) { + rotateDirectionY = 'clockwise'; + } else if (wRY - wPRY < 0 || wRY - this.pRotationY > 270) { + rotateDirectionY = 'counter-clockwise'; + } + if (rotateDirectionY !== pRotateDirectionY) { + wSAY = wRY; + } + if (Math.abs(wRY - wSAY) > 90 && Math.abs(wRY - wSAY) < 270) { + wSAY = wRY; + this._setProperty('turnAxis', 'Y'); + deviceTurned(); + } + pRotateDirectionY = rotateDirectionY; + startAngleY = wSAY - 180; + + // Z-axis is already in the range 0 to 360 + // so no conversion is needed. + if ( + (this.rotationZ - this.pRotationZ > 0 && + this.rotationZ - this.pRotationZ < 270) || + this.rotationZ - this.pRotationZ < -270 + ) { + rotateDirectionZ = 'clockwise'; + } else if ( + this.rotationZ - this.pRotationZ < 0 || + this.rotationZ - this.pRotationZ > 270 + ) { + rotateDirectionZ = 'counter-clockwise'; + } + if (rotateDirectionZ !== pRotateDirectionZ) { + startAngleZ = this.rotationZ; + } + if ( + Math.abs(this.rotationZ - startAngleZ) > 90 && + Math.abs(this.rotationZ - startAngleZ) < 270 + ) { + startAngleZ = this.rotationZ; + this._setProperty('turnAxis', 'Z'); + deviceTurned(); + } + pRotateDirectionZ = rotateDirectionZ; + this._setProperty('turnAxis', undefined); + } + var deviceShaken = this.deviceShaken || window.deviceShaken; + if (typeof deviceShaken === 'function') { + var accelerationChangeX; + var accelerationChangeY; + // Add accelerationChangeZ if acceleration change on Z is needed + if (this.pAccelerationX !== null) { + accelerationChangeX = Math.abs(this.accelerationX - this.pAccelerationX); + accelerationChangeY = Math.abs(this.accelerationY - this.pAccelerationY); + } + if (accelerationChangeX + accelerationChangeY > shake_threshold) { + deviceShaken(); + } + } + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 40: [ + function(_dereq_, module, exports) { + /** + * @module Events + * @submodule Keyboard + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * The boolean system variable keyIsPressed is true if any key is pressed + * and false if no keys are pressed. + * + * @property {Boolean} keyIsPressed + * @readOnly + * @example + *
+ * + * function draw() { + * if (keyIsPressed === true) { + * fill(0); + * } else { + * fill(255); + * } + * rect(25, 25, 50, 50); + * } + * + *
+ * + * @alt + * 50x50 white rect that turns black on keypress. + * + */ + p5.prototype.isKeyPressed = false; + p5.prototype.keyIsPressed = false; // khan + + /** + * The system variable key always contains the value of the most recent + * key on the keyboard that was typed. To get the proper capitalization, it + * is best to use it within keyTyped(). For non-ASCII keys, use the keyCode + * variable. + * + * @property {String} key + * @readOnly + * @example + *
+ * // Click any key to display it! + * // (Not Guaranteed to be Case Sensitive) + * function setup() { + * fill(245, 123, 158); + * textSize(50); + * } + * + * function draw() { + * background(200); + * text(key, 33, 65); // Display last key pressed. + * } + *
+ * + * @alt + * canvas displays any key value that is pressed in pink font. + * + */ + p5.prototype.key = ''; + + /** + * The variable keyCode is used to detect special keys such as BACKSPACE, + * DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, OPTION, ALT, UP_ARROW, + * DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW. + * You can also check for custom keys by looking up the keyCode of any key + * on a site like this: keycode.info. + * + * @property {Integer} keyCode + * @readOnly + * @example + *
+ * let fillVal = 126; + * function draw() { + * fill(fillVal); + * rect(25, 25, 50, 50); + * } + * + * function keyPressed() { + * if (keyCode === UP_ARROW) { + * fillVal = 255; + * } else if (keyCode === DOWN_ARROW) { + * fillVal = 0; + * } + * return false; // prevent default + * } + *
+ *
+ * function draw() {} + * function keyPressed() { + * background('yellow'); + * text(`${key} ${keyCode}`, 10, 40); + * print(key, ' ', keyCode); + * return false; // prevent default + * } + *
+ * @alt + * Grey rect center. turns white when up arrow pressed and black when down + * Display key pressed and its keyCode in a yellow box + */ + p5.prototype.keyCode = 0; + + /** + * The keyPressed() function is called once every time a key is pressed. The + * keyCode for the key that was pressed is stored in the keyCode variable. + *

+ * For non-ASCII keys, use the keyCode variable. You can check if the keyCode + * equals BACKSPACE, DELETE, ENTER, RETURN, TAB, ESCAPE, SHIFT, CONTROL, + * OPTION, ALT, UP_ARROW, DOWN_ARROW, LEFT_ARROW, RIGHT_ARROW. + *

+ * For ASCII keys, the key that was pressed is stored in the key variable. However, it + * does not distinguish between uppercase and lowercase. For this reason, it + * is recommended to use keyTyped() to read the key variable, in which the + * case of the variable will be distinguished. + *

+ * Because of how operating systems handle key repeats, holding down a key + * may cause multiple calls to keyTyped() (and keyReleased() as well). The + * rate of repeat is set by the operating system and how each computer is + * configured.

+ * Browsers may have different default + * behaviors attached to various key events. To prevent any default + * behavior for this event, add "return false" to the end of the method. + * + * @method keyPressed + * @example + *
+ * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function keyPressed() { + * if (value === 0) { + * value = 255; + * } else { + * value = 0; + * } + * } + * + *
+ *
+ * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function keyPressed() { + * if (keyCode === LEFT_ARROW) { + * value = 255; + * } else if (keyCode === RIGHT_ARROW) { + * value = 0; + * } + * } + * + *
+ *
+ * + * function keyPressed() { + * // Do something + * return false; // prevent any default behaviour + * } + * + *
+ * + * @alt + * black rect center. turns white when key pressed and black when released + * black rect center. turns white when left arrow pressed and black when right. + * + */ + p5.prototype._onkeydown = function(e) { + if (this._downKeys[e.which]) { + // prevent multiple firings + return; + } + this._setProperty('isKeyPressed', true); + this._setProperty('keyIsPressed', true); + this._setProperty('keyCode', e.which); + this._downKeys[e.which] = true; + this._setProperty('key', e.key || String.fromCharCode(e.which) || e.which); + var keyPressed = this.keyPressed || window.keyPressed; + if (typeof keyPressed === 'function' && !e.charCode) { + var executeDefault = keyPressed(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + /** + * The keyReleased() function is called once every time a key is released. + * See key and keyCode for more information.

+ * Browsers may have different default + * behaviors attached to various key events. To prevent any default + * behavior for this event, add "return false" to the end of the method. + * + * @method keyReleased + * @example + *
+ * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function keyReleased() { + * if (value === 0) { + * value = 255; + * } else { + * value = 0; + * } + * return false; // prevent any default behavior + * } + * + *
+ * + * @alt + * black rect center. turns white when key pressed and black when pressed again + * + */ + p5.prototype._onkeyup = function(e) { + var keyReleased = this.keyReleased || window.keyReleased; + this._downKeys[e.which] = false; + + if (!this._areDownKeys()) { + this._setProperty('isKeyPressed', false); + this._setProperty('keyIsPressed', false); + } + + this._setProperty('_lastKeyCodeTyped', null); + + this._setProperty('key', e.key || String.fromCharCode(e.which) || e.which); + this._setProperty('keyCode', e.which); + if (typeof keyReleased === 'function') { + var executeDefault = keyReleased(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + /** + * The keyTyped() function is called once every time a key is pressed, but + * action keys such as Backspace, Delete, Ctrl, Shift, and Alt are ignored. If you are trying to detect + * a keyCode for one of these keys, use the keyPressed() function instead. + * The most recent key typed will be stored in the key variable. + *

+ * Because of how operating systems handle key repeats, holding down a key + * will cause multiple calls to keyTyped() (and keyReleased() as well). The + * rate of repeat is set by the operating system and how each computer is + * configured.

+ * Browsers may have different default behaviors attached to various key + * events. To prevent any default behavior for this event, add "return false" + * to the end of the method. + * + * @method keyTyped + * @example + *
+ * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function keyTyped() { + * if (key === 'a') { + * value = 255; + * } else if (key === 'b') { + * value = 0; + * } + * // uncomment to prevent any default behavior + * // return false; + * } + * + *
+ * + * @alt + * black rect center. turns white when 'a' key typed and black when 'b' pressed + * + */ + p5.prototype._onkeypress = function(e) { + if (e.which === this._lastKeyCodeTyped) { + // prevent multiple firings + return; + } + this._setProperty('_lastKeyCodeTyped', e.which); // track last keyCode + this._setProperty('key', String.fromCharCode(e.which)); + var keyTyped = this.keyTyped || window.keyTyped; + if (typeof keyTyped === 'function') { + var executeDefault = keyTyped(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + /** + * The onblur function is called when the user is no longer focused + * on the p5 element. Because the keyup events will not fire if the user is + * not focused on the element we must assume all keys currently down have + * been released. + */ + p5.prototype._onblur = function(e) { + this._downKeys = {}; + }; + + /** + * The keyIsDown() function checks if the key is currently down, i.e. pressed. + * It can be used if you have an object that moves, and you want several keys + * to be able to affect its behaviour simultaneously, such as moving a + * sprite diagonally. You can put in any number representing the keyCode of + * the key, or use any of the variable keyCode names listed + * here. + * + * @method keyIsDown + * @param {Number} code The key to check for. + * @return {Boolean} whether key is down or not + * @example + *
+ * let x = 100; + * let y = 100; + * + * function setup() { + * createCanvas(512, 512); + * fill(255, 0, 0); + * } + * + * function draw() { + * if (keyIsDown(LEFT_ARROW)) { + * x -= 5; + * } + * + * if (keyIsDown(RIGHT_ARROW)) { + * x += 5; + * } + * + * if (keyIsDown(UP_ARROW)) { + * y -= 5; + * } + * + * if (keyIsDown(DOWN_ARROW)) { + * y += 5; + * } + * + * clear(); + * ellipse(x, y, 50, 50); + * } + *
+ * + *
+ * let diameter = 50; + * + * function setup() { + * createCanvas(512, 512); + * } + * + * function draw() { + * // 107 and 187 are keyCodes for "+" + * if (keyIsDown(107) || keyIsDown(187)) { + * diameter += 1; + * } + * + * // 109 and 189 are keyCodes for "-" + * if (keyIsDown(109) || keyIsDown(189)) { + * diameter -= 1; + * } + * + * clear(); + * fill(255, 0, 0); + * ellipse(50, 50, diameter, diameter); + * } + *
+ * + * @alt + * 50x50 red ellipse moves left, right, up and down with arrow presses. + * 50x50 red ellipse gets bigger or smaller when + or - are pressed. + * + */ + p5.prototype.keyIsDown = function(code) { + p5._validateParameters('keyIsDown', arguments); + return this._downKeys[code] || false; + }; + + /** + * The _areDownKeys function returns a boolean true if any keys pressed + * and a false if no keys are currently pressed. + + * Helps avoid instances where multiple keys are pressed simultaneously and + * releasing a single key will then switch the + * keyIsPressed property to true. + * @private + **/ + p5.prototype._areDownKeys = function() { + for (var key in this._downKeys) { + if (this._downKeys.hasOwnProperty(key) && this._downKeys[key] === true) { + return true; + } + } + return false; + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 41: [ + function(_dereq_, module, exports) { + /** + * @module Events + * @submodule Mouse + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + + /* + * This is a flag which is false until the first time + * we receive a mouse event. The pmouseX and pmouseY + * values will match the mouseX and mouseY values until + * this interaction takes place. + */ + p5.prototype._hasMouseInteracted = false; + + /** + * The system variable mouseX always contains the current horizontal + * position of the mouse, relative to (0, 0) of the canvas. The value at + * the top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL. + * If touch is used instead of mouse input, mouseX will hold the x value + * of the most recent touch point. + * + * @property {Number} mouseX + * @readOnly + * + * @example + *
+ * + * // Move the mouse across the canvas + * function draw() { + * background(244, 248, 252); + * line(mouseX, 0, mouseX, 100); + * } + * + *
+ * + * @alt + * horizontal black line moves left and right with mouse x-position + * + */ + p5.prototype.mouseX = 0; + + /** + * The system variable mouseY always contains the current vertical + * position of the mouse, relative to (0, 0) of the canvas. The value at + * the top-left corner is (0, 0) for 2-D and (-width/2, -height/2) for WebGL. + * If touch is used instead of mouse input, mouseY will hold the y value + * of the most recent touch point. + * + * @property {Number} mouseY + * @readOnly + * + * @example + *
+ * + * // Move the mouse across the canvas + * function draw() { + * background(244, 248, 252); + * line(0, mouseY, 100, mouseY); + * } + * + *
+ * + * @alt + * vertical black line moves up and down with mouse y-position + * + */ + p5.prototype.mouseY = 0; + + /** + * The system variable pmouseX always contains the horizontal position of + * the mouse or finger in the frame previous to the current frame, relative to + * (0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and + * (-width/2, -height/2) for WebGL. Note: pmouseX will be reset to the current mouseX + * value at the start of each touch event. + * + * @property {Number} pmouseX + * @readOnly + * + * @example + *
+ * + * // Move the mouse across the canvas to leave a trail + * function setup() { + * //slow down the frameRate to make it more visible + * frameRate(10); + * } + * + * function draw() { + * background(244, 248, 252); + * line(mouseX, mouseY, pmouseX, pmouseY); + * print(pmouseX + ' -> ' + mouseX); + * } + * + *
+ * + * @alt + * line trail is created from cursor movements. faster movement make longer line. + * + */ + p5.prototype.pmouseX = 0; + + /** + * The system variable pmouseY always contains the vertical position of + * the mouse or finger in the frame previous to the current frame, relative to + * (0, 0) of the canvas. The value at the top-left corner is (0, 0) for 2-D and + * (-width/2, -height/2) for WebGL. Note: pmouseY will be reset to the current mouseY + * value at the start of each touch event. + * + * @property {Number} pmouseY + * @readOnly + * + * @example + *
+ * + * function draw() { + * background(237, 34, 93); + * fill(0); + * //draw a square only if the mouse is not moving + * if (mouseY === pmouseY && mouseX === pmouseX) { + * rect(20, 20, 60, 60); + * } + * + * print(pmouseY + ' -> ' + mouseY); + * } + * + *
+ * + * @alt + * 60x60 black rect center, fuchsia background. rect flickers on mouse movement + * + */ + p5.prototype.pmouseY = 0; + + /** + * The system variable winMouseX always contains the current horizontal + * position of the mouse, relative to (0, 0) of the window. + * + * @property {Number} winMouseX + * @readOnly + * + * @example + *
+ * + * let myCanvas; + * + * function setup() { + * //use a variable to store a pointer to the canvas + * myCanvas = createCanvas(100, 100); + * const body = document.getElementsByTagName('body')[0]; + * myCanvas.parent(body); + * } + * + * function draw() { + * background(237, 34, 93); + * fill(0); + * + * //move the canvas to the horizontal mouse position + * //relative to the window + * myCanvas.position(winMouseX + 1, windowHeight / 2); + * + * //the y of the square is relative to the canvas + * rect(20, mouseY, 60, 60); + * } + * + *
+ * + * @alt + * 60x60 black rect y moves with mouse y and fuchsia canvas moves with mouse x + * + */ + p5.prototype.winMouseX = 0; + + /** + * The system variable winMouseY always contains the current vertical + * position of the mouse, relative to (0, 0) of the window. + * + * @property {Number} winMouseY + * @readOnly + * + * @example + *
+ * + * let myCanvas; + * + * function setup() { + * //use a variable to store a pointer to the canvas + * myCanvas = createCanvas(100, 100); + * const body = document.getElementsByTagName('body')[0]; + * myCanvas.parent(body); + * } + * + * function draw() { + * background(237, 34, 93); + * fill(0); + * + * //move the canvas to the vertical mouse position + * //relative to the window + * myCanvas.position(windowWidth / 2, winMouseY + 1); + * + * //the x of the square is relative to the canvas + * rect(mouseX, 20, 60, 60); + * } + * + *
+ * + * @alt + * 60x60 black rect x moves with mouse x and fuchsia canvas y moves with mouse y + * + */ + p5.prototype.winMouseY = 0; + + /** + * The system variable pwinMouseX always contains the horizontal position + * of the mouse in the frame previous to the current frame, relative to + * (0, 0) of the window. Note: pwinMouseX will be reset to the current winMouseX + * value at the start of each touch event. + * + * @property {Number} pwinMouseX + * @readOnly + * + * @example + *
+ * + * let myCanvas; + * + * function setup() { + * //use a variable to store a pointer to the canvas + * myCanvas = createCanvas(100, 100); + * noStroke(); + * fill(237, 34, 93); + * } + * + * function draw() { + * clear(); + * //the difference between previous and + * //current x position is the horizontal mouse speed + * let speed = abs(winMouseX - pwinMouseX); + * //change the size of the circle + * //according to the horizontal speed + * ellipse(50, 50, 10 + speed * 5, 10 + speed * 5); + * //move the canvas to the mouse position + * myCanvas.position(winMouseX + 1, winMouseY + 1); + * } + * + *
+ * + * @alt + * fuchsia ellipse moves with mouse x and y. Grows and shrinks with mouse speed + * + */ + p5.prototype.pwinMouseX = 0; + + /** + * The system variable pwinMouseY always contains the vertical position of + * the mouse in the frame previous to the current frame, relative to (0, 0) + * of the window. Note: pwinMouseY will be reset to the current winMouseY + * value at the start of each touch event. + * + * @property {Number} pwinMouseY + * @readOnly + * + * + * @example + *
+ * + * let myCanvas; + * + * function setup() { + * //use a variable to store a pointer to the canvas + * myCanvas = createCanvas(100, 100); + * noStroke(); + * fill(237, 34, 93); + * } + * + * function draw() { + * clear(); + * //the difference between previous and + * //current y position is the vertical mouse speed + * let speed = abs(winMouseY - pwinMouseY); + * //change the size of the circle + * //according to the vertical speed + * ellipse(50, 50, 10 + speed * 5, 10 + speed * 5); + * //move the canvas to the mouse position + * myCanvas.position(winMouseX + 1, winMouseY + 1); + * } + * + *
+ * + * @alt + * fuchsia ellipse moves with mouse x and y. Grows and shrinks with mouse speed + * + */ + p5.prototype.pwinMouseY = 0; + + /** + * Processing automatically tracks if the mouse button is pressed and which + * button is pressed. The value of the system variable mouseButton is either + * LEFT, RIGHT, or CENTER depending on which button was pressed last. + * Warning: different browsers may track mouseButton differently. + * + * @property {Constant} mouseButton + * @readOnly + * + * @example + *
+ * + * function draw() { + * background(237, 34, 93); + * fill(0); + * + * if (mouseIsPressed) { + * if (mouseButton === LEFT) { + * ellipse(50, 50, 50, 50); + * } + * if (mouseButton === RIGHT) { + * rect(25, 25, 50, 50); + * } + * if (mouseButton === CENTER) { + * triangle(23, 75, 50, 20, 78, 75); + * } + * } + * + * print(mouseButton); + * } + * + *
+ * + * @alt + * 50x50 black ellipse appears on center of fuchsia canvas on mouse click/press. + * + */ + p5.prototype.mouseButton = 0; + + /** + * The boolean system variable mouseIsPressed is true if the mouse is pressed + * and false if not. + * + * @property {Boolean} mouseIsPressed + * @readOnly + * + * @example + *
+ * + * function draw() { + * background(237, 34, 93); + * fill(0); + * + * if (mouseIsPressed) { + * ellipse(50, 50, 50, 50); + * } else { + * rect(25, 25, 50, 50); + * } + * + * print(mouseIsPressed); + * } + * + *
+ * + * @alt + * black 50x50 rect becomes ellipse with mouse click/press. fuchsia background. + * + */ + p5.prototype.mouseIsPressed = false; + + p5.prototype._updateNextMouseCoords = function(e) { + if (this._curElement !== null && (!e.touches || e.touches.length > 0)) { + var mousePos = getMousePos(this._curElement.elt, this.width, this.height, e); + + this._setProperty('mouseX', mousePos.x); + this._setProperty('mouseY', mousePos.y); + this._setProperty('winMouseX', mousePos.winX); + this._setProperty('winMouseY', mousePos.winY); + } + if (!this._hasMouseInteracted) { + // For first draw, make previous and next equal + this._updateMouseCoords(); + this._setProperty('_hasMouseInteracted', true); + } + }; + + p5.prototype._updateMouseCoords = function() { + this._setProperty('pmouseX', this.mouseX); + this._setProperty('pmouseY', this.mouseY); + this._setProperty('pwinMouseX', this.winMouseX); + this._setProperty('pwinMouseY', this.winMouseY); + + this._setProperty('_pmouseWheelDeltaY', this._mouseWheelDeltaY); + }; + + function getMousePos(canvas, w, h, evt) { + if (evt && !evt.clientX) { + // use touches if touch and not mouse + if (evt.touches) { + evt = evt.touches[0]; + } else if (evt.changedTouches) { + evt = evt.changedTouches[0]; + } + } + var rect = canvas.getBoundingClientRect(); + var sx = canvas.scrollWidth / w || 1; + var sy = canvas.scrollHeight / h || 1; + return { + x: (evt.clientX - rect.left) / sx, + y: (evt.clientY - rect.top) / sy, + winX: evt.clientX, + winY: evt.clientY, + id: evt.identifier + }; + } + + p5.prototype._setMouseButton = function(e) { + if (e.button === 1) { + this._setProperty('mouseButton', constants.CENTER); + } else if (e.button === 2) { + this._setProperty('mouseButton', constants.RIGHT); + } else { + this._setProperty('mouseButton', constants.LEFT); + } + }; + + /** + * The mouseMoved() function is called every time the mouse moves and a mouse + * button is not pressed.

+ * Browsers may have different default + * behaviors attached to various mouse events. To prevent any default + * behavior for this event, add "return false" to the end of the method. + * + * @method mouseMoved + * @param {Object} [event] optional MouseEvent callback argument. + * @example + *
+ * + * // Move the mouse across the page + * // to change its value + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function mouseMoved() { + * value = value + 5; + * if (value > 255) { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function mouseMoved() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a MouseEvent object + * // as a callback argument + * function mouseMoved(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * black 50x50 rect becomes lighter with mouse movements until white then resets + * no image displayed + * + */ + + /** + * The mouseDragged() function is called once every time the mouse moves and + * a mouse button is pressed. If no mouseDragged() function is defined, the + * touchMoved() function will be called instead if it is defined.

+ * Browsers may have different default + * behaviors attached to various mouse events. To prevent any default + * behavior for this event, add "return false" to the end of the method. + * + * @method mouseDragged + * @param {Object} [event] optional MouseEvent callback argument. + * @example + *
+ * + * // Drag the mouse across the page + * // to change its value + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function mouseDragged() { + * value = value + 5; + * if (value > 255) { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function mouseDragged() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a MouseEvent object + * // as a callback argument + * function mouseDragged(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * black 50x50 rect turns lighter with mouse click and drag until white, resets + * no image displayed + * + */ + p5.prototype._onmousemove = function(e) { + var context = this._isGlobal ? window : this; + var executeDefault; + this._updateNextMouseCoords(e); + if (!this.mouseIsPressed) { + if (typeof context.mouseMoved === 'function') { + executeDefault = context.mouseMoved(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + } else { + if (typeof context.mouseDragged === 'function') { + executeDefault = context.mouseDragged(e); + if (executeDefault === false) { + e.preventDefault(); + } + } else if (typeof context.touchMoved === 'function') { + executeDefault = context.touchMoved(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + } + }; + + /** + * The mousePressed() function is called once after every time a mouse button + * is pressed. The mouseButton variable (see the related reference entry) + * can be used to determine which button has been pressed. If no + * mousePressed() function is defined, the touchStarted() function will be + * called instead if it is defined.

+ * Browsers may have different default + * behaviors attached to various mouse events. To prevent any default + * behavior for this event, add "return false" to the end of the method. + * + * @method mousePressed + * @param {Object} [event] optional MouseEvent callback argument. + * @example + *
+ * + * // Click within the image to change + * // the value of the rectangle + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function mousePressed() { + * if (value === 0) { + * value = 255; + * } else { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function mousePressed() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a MouseEvent object + * // as a callback argument + * function mousePressed(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * black 50x50 rect turns white with mouse click/press. + * no image displayed + * + */ + p5.prototype._onmousedown = function(e) { + var context = this._isGlobal ? window : this; + var executeDefault; + this._setProperty('mouseIsPressed', true); + this._setMouseButton(e); + this._updateNextMouseCoords(e); + + if (typeof context.mousePressed === 'function') { + executeDefault = context.mousePressed(e); + if (executeDefault === false) { + e.preventDefault(); + } + // only safari needs this manual fallback for consistency + } else if ( + navigator.userAgent.toLowerCase().includes('safari') && + typeof context.touchStarted === 'function' + ) { + executeDefault = context.touchStarted(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + /** + * The mouseReleased() function is called every time a mouse button is + * released. If no mouseReleased() function is defined, the touchEnded() + * function will be called instead if it is defined.

+ * Browsers may have different default + * behaviors attached to various mouse events. To prevent any default + * behavior for this event, add "return false" to the end of the method. + * + * + * @method mouseReleased + * @param {Object} [event] optional MouseEvent callback argument. + * @example + *
+ * + * // Click within the image to change + * // the value of the rectangle + * // after the mouse has been clicked + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function mouseReleased() { + * if (value === 0) { + * value = 255; + * } else { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function mouseReleased() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a MouseEvent object + * // as a callback argument + * function mouseReleased(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * black 50x50 rect turns white with mouse click/press. + * no image displayed + * + */ + p5.prototype._onmouseup = function(e) { + var context = this._isGlobal ? window : this; + var executeDefault; + this._setProperty('mouseIsPressed', false); + if (typeof context.mouseReleased === 'function') { + executeDefault = context.mouseReleased(e); + if (executeDefault === false) { + e.preventDefault(); + } + } else if (typeof context.touchEnded === 'function') { + executeDefault = context.touchEnded(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + p5.prototype._ondragend = p5.prototype._onmouseup; + p5.prototype._ondragover = p5.prototype._onmousemove; + + /** + * The mouseClicked() function is called once after a mouse button has been + * pressed and then released.

+ * Browsers handle clicks differently, so this function is only guaranteed to be + * run when the left mouse button is clicked. To handle other mouse buttons + * being pressed or released, see mousePressed() or mouseReleased().

+ * Browsers may have different default + * behaviors attached to various mouse events. To prevent any default + * behavior for this event, add "return false" to the end of the method. + * + * @method mouseClicked + * @param {Object} [event] optional MouseEvent callback argument. + * @example + *
+ * + * // Click within the image to change + * // the value of the rectangle + * // after the mouse has been clicked + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * + * function mouseClicked() { + * if (value === 0) { + * value = 255; + * } else { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function mouseClicked() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a MouseEvent object + * // as a callback argument + * function mouseClicked(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * black 50x50 rect turns white with mouse click/press. + * no image displayed + * + */ + p5.prototype._onclick = function(e) { + var context = this._isGlobal ? window : this; + if (typeof context.mouseClicked === 'function') { + var executeDefault = context.mouseClicked(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + /** + * The doubleClicked() function is executed every time a event + * listener has detected a dblclick event which is a part of the + * DOM L3 specification. The doubleClicked event is fired when a + * pointing device button (usually a mouse's primary button) + * is clicked twice on a single element. For more info on the + * dblclick event refer to mozilla's documentation here: + * https://developer.mozilla.org/en-US/docs/Web/Events/dblclick + * + * @method doubleClicked + * @param {Object} [event] optional MouseEvent callback argument. + * @example + *
+ * + * // Click within the image to change + * // the value of the rectangle + * // after the mouse has been double clicked + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * + * function doubleClicked() { + * if (value === 0) { + * value = 255; + * } else { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function doubleClicked() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a MouseEvent object + * // as a callback argument + * function doubleClicked(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * black 50x50 rect turns white with mouse doubleClick/press. + * no image displayed + */ + + p5.prototype._ondblclick = function(e) { + var context = this._isGlobal ? window : this; + if (typeof context.doubleClicked === 'function') { + var executeDefault = context.doubleClicked(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + /** + * For use with WebGL orbitControl. + * @property {Number} _mouseWheelDeltaY + * @readOnly + * @private + */ + p5.prototype._mouseWheelDeltaY = 0; + + /** + * For use with WebGL orbitControl. + * @property {Number} _pmouseWheelDeltaY + * @readOnly + * @private + */ + p5.prototype._pmouseWheelDeltaY = 0; + + /** + * The function mouseWheel() is executed every time a vertical mouse wheel + * event is detected either triggered by an actual mouse wheel or by a + * touchpad.

+ * The event.delta property returns the amount the mouse wheel + * have scrolled. The values can be positive or negative depending on the + * scroll direction (on OS X with "natural" scrolling enabled, the signs + * are inverted).

+ * Browsers may have different default behaviors attached to various + * mouse events. To prevent any default behavior for this event, add + * "return false" to the end of the method.

+ * Due to the current support of the "wheel" event on Safari, the function + * may only work as expected if "return false" is included while using Safari. + * + * @method mouseWheel + * @param {Object} [event] optional WheelEvent callback argument. + * + * @example + *
+ * + * let pos = 25; + * + * function draw() { + * background(237, 34, 93); + * fill(0); + * rect(25, pos, 50, 50); + * } + * + * function mouseWheel(event) { + * print(event.delta); + * //move the square according to the vertical scroll amount + * pos += event.delta; + * //uncomment to block page scrolling + * //return false; + * } + * + *
+ * + * @alt + * black 50x50 rect moves up and down with vertical scroll. fuchsia background + * + */ + p5.prototype._onwheel = function(e) { + var context = this._isGlobal ? window : this; + this._setProperty('_mouseWheelDeltaY', e.deltaY); + if (typeof context.mouseWheel === 'function') { + e.delta = e.deltaY; + var executeDefault = context.mouseWheel(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + module.exports = p5; + }, + { '../core/constants': 18, '../core/main': 24 } + ], + 42: [ + function(_dereq_, module, exports) { + /** + * @module Events + * @submodule Touch + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * The system variable touches[] contains an array of the positions of all + * current touch points, relative to (0, 0) of the canvas, and IDs identifying a + * unique touch as it moves. Each element in the array is an object with x, y, + * and id properties. + * + * The touches[] array is not supported on Safari and IE on touch-based + * desktops (laptops). + * + * @property {Object[]} touches + * @readOnly + * + * @example + *
+ * + * // On a touchscreen device, touch + * // the canvas using one or more fingers + * // at the same time + * function draw() { + * clear(); + * let display = touches.length + ' touches'; + * text(display, 5, 10); + * } + * + *
+ * + * @alt + * Number of touches currently registered are displayed on the canvas + */ + p5.prototype.touches = []; + + p5.prototype._updateTouchCoords = function(e) { + if (this._curElement !== null) { + var touches = []; + for (var i = 0; i < e.touches.length; i++) { + touches[i] = getTouchInfo( + this._curElement.elt, + this.width, + this.height, + e, + i + ); + } + this._setProperty('touches', touches); + } + }; + + function getTouchInfo(canvas, w, h, e, i) { + i = i || 0; + var rect = canvas.getBoundingClientRect(); + var sx = canvas.scrollWidth / w || 1; + var sy = canvas.scrollHeight / h || 1; + var touch = e.touches[i] || e.changedTouches[i]; + return { + x: (touch.clientX - rect.left) / sx, + y: (touch.clientY - rect.top) / sy, + winX: touch.clientX, + winY: touch.clientY, + id: touch.identifier + }; + } + + /** + * The touchStarted() function is called once after every time a touch is + * registered. If no touchStarted() function is defined, the mousePressed() + * function will be called instead if it is defined.

+ * Browsers may have different default behaviors attached to various touch + * events. To prevent any default behavior for this event, add "return false" + * to the end of the method. + * + * @method touchStarted + * @param {Object} [event] optional TouchEvent callback argument. + * @example + *
+ * + * // Touch within the image to change + * // the value of the rectangle + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function touchStarted() { + * if (value === 0) { + * value = 255; + * } else { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function touchStarted() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a TouchEvent object + * // as a callback argument + * function touchStarted(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * 50x50 black rect turns white with touch event. + * no image displayed + */ + p5.prototype._ontouchstart = function(e) { + var context = this._isGlobal ? window : this; + var executeDefault; + this._setProperty('mouseIsPressed', true); + this._updateTouchCoords(e); + this._updateNextMouseCoords(e); + this._updateMouseCoords(); // reset pmouseXY at the start of each touch event + + if (typeof context.touchStarted === 'function') { + executeDefault = context.touchStarted(e); + if (executeDefault === false) { + e.preventDefault(); + } + // only safari needs this manual fallback for consistency + } else if ( + navigator.userAgent.toLowerCase().includes('safari') && + typeof context.touchStarted === 'function' + ) { + executeDefault = context.mousePressed(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + /** + * The touchMoved() function is called every time a touch move is registered. + * If no touchMoved() function is defined, the mouseDragged() function will + * be called instead if it is defined.

+ * Browsers may have different default behaviors attached to various touch + * events. To prevent any default behavior for this event, add "return false" + * to the end of the method. + * + * @method touchMoved + * @param {Object} [event] optional TouchEvent callback argument. + * @example + *
+ * + * // Move your finger across the page + * // to change its value + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function touchMoved() { + * value = value + 5; + * if (value > 255) { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function touchMoved() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a TouchEvent object + * // as a callback argument + * function touchMoved(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * 50x50 black rect turns lighter with touch until white. resets + * no image displayed + * + */ + p5.prototype._ontouchmove = function(e) { + var context = this._isGlobal ? window : this; + var executeDefault; + this._updateTouchCoords(e); + this._updateNextMouseCoords(e); + if (typeof context.touchMoved === 'function') { + executeDefault = context.touchMoved(e); + if (executeDefault === false) { + e.preventDefault(); + } + } else if (typeof context.mouseDragged === 'function') { + executeDefault = context.mouseDragged(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + /** + * The touchEnded() function is called every time a touch ends. If no + * touchEnded() function is defined, the mouseReleased() function will be + * called instead if it is defined.

+ * Browsers may have different default behaviors attached to various touch + * events. To prevent any default behavior for this event, add "return false" + * to the end of the method. + * + * @method touchEnded + * @param {Object} [event] optional TouchEvent callback argument. + * @example + *
+ * + * // Release touch within the image to + * // change the value of the rectangle + * + * let value = 0; + * function draw() { + * fill(value); + * rect(25, 25, 50, 50); + * } + * function touchEnded() { + * if (value === 0) { + * value = 255; + * } else { + * value = 0; + * } + * } + * + *
+ * + *
+ * + * function touchEnded() { + * ellipse(mouseX, mouseY, 5, 5); + * // prevent default + * return false; + * } + * + *
+ * + *
+ * + * // returns a TouchEvent object + * // as a callback argument + * function touchEnded(event) { + * console.log(event); + * } + * + *
+ * + * @alt + * 50x50 black rect turns white with touch. + * no image displayed + * + */ + p5.prototype._ontouchend = function(e) { + this._setProperty('mouseIsPressed', false); + this._updateTouchCoords(e); + this._updateNextMouseCoords(e); + var context = this._isGlobal ? window : this; + var executeDefault; + if (typeof context.touchEnded === 'function') { + executeDefault = context.touchEnded(e); + if (executeDefault === false) { + e.preventDefault(); + } + } else if (typeof context.mouseReleased === 'function') { + executeDefault = context.mouseReleased(e); + if (executeDefault === false) { + e.preventDefault(); + } + } + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 43: [ + function(_dereq_, module, exports) { + /*global ImageData:false */ + + /** + * This module defines the filters for use with image buffers. + * + * This module is basically a collection of functions stored in an object + * as opposed to modules. The functions are destructive, modifying + * the passed in canvas rather than creating a copy. + * + * Generally speaking users of this module will use the Filters.apply method + * on a canvas to create an effect. + * + * A number of functions are borrowed/adapted from + * http://www.html5rocks.com/en/tutorials/canvas/imagefilters/ + * or the java processing implementation. + */ + + 'use strict'; + + var Filters = {}; + + /* + * Helper functions + */ + + /** + * Returns the pixel buffer for a canvas + * + * @private + * + * @param {Canvas|ImageData} canvas the canvas to get pixels from + * @return {Uint8ClampedArray} a one-dimensional array containing + * the data in thc RGBA order, with integer + * values between 0 and 255 + */ + Filters._toPixels = function(canvas) { + if (canvas instanceof ImageData) { + return canvas.data; + } else { + return canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height) + .data; + } + }; + + /** + * Returns a 32 bit number containing ARGB data at ith pixel in the + * 1D array containing pixels data. + * + * @private + * + * @param {Uint8ClampedArray} data array returned by _toPixels() + * @param {Integer} i index of a 1D Image Array + * @return {Integer} 32 bit integer value representing + * ARGB value. + */ + Filters._getARGB = function(data, i) { + var offset = i * 4; + return ( + ((data[offset + 3] << 24) & 0xff000000) | + ((data[offset] << 16) & 0x00ff0000) | + ((data[offset + 1] << 8) & 0x0000ff00) | + (data[offset + 2] & 0x000000ff) + ); + }; + + /** + * Modifies pixels RGBA values to values contained in the data object. + * + * @private + * + * @param {Uint8ClampedArray} pixels array returned by _toPixels() + * @param {Int32Array} data source 1D array where each value + * represents ARGB values + */ + Filters._setPixels = function(pixels, data) { + var offset = 0; + for (var i = 0, al = pixels.length; i < al; i++) { + offset = i * 4; + pixels[offset + 0] = (data[i] & 0x00ff0000) >>> 16; + pixels[offset + 1] = (data[i] & 0x0000ff00) >>> 8; + pixels[offset + 2] = data[i] & 0x000000ff; + pixels[offset + 3] = (data[i] & 0xff000000) >>> 24; + } + }; + + /** + * Returns the ImageData object for a canvas + * https://developer.mozilla.org/en-US/docs/Web/API/ImageData + * + * @private + * + * @param {Canvas|ImageData} canvas canvas to get image data from + * @return {ImageData} Holder of pixel data (and width and + * height) for a canvas + */ + Filters._toImageData = function(canvas) { + if (canvas instanceof ImageData) { + return canvas; + } else { + return canvas + .getContext('2d') + .getImageData(0, 0, canvas.width, canvas.height); + } + }; + + /** + * Returns a blank ImageData object. + * + * @private + * + * @param {Integer} width + * @param {Integer} height + * @return {ImageData} + */ + Filters._createImageData = function(width, height) { + Filters._tmpCanvas = document.createElement('canvas'); + Filters._tmpCtx = Filters._tmpCanvas.getContext('2d'); + return this._tmpCtx.createImageData(width, height); + }; + + /** + * Applys a filter function to a canvas. + * + * The difference between this and the actual filter functions defined below + * is that the filter functions generally modify the pixel buffer but do + * not actually put that data back to the canvas (where it would actually + * update what is visible). By contrast this method does make the changes + * actually visible in the canvas. + * + * The apply method is the method that callers of this module would generally + * use. It has been separated from the actual filters to support an advanced + * use case of creating a filter chain that executes without actually updating + * the canvas in between everystep. + * + * @private + * @param {HTMLCanvasElement} canvas [description] + * @param {function(ImageData,Object)} func [description] + * @param {Object} filterParam [description] + */ + Filters.apply = function(canvas, func, filterParam) { + var pixelsState = canvas.getContext('2d'); + var imageData = pixelsState.getImageData(0, 0, canvas.width, canvas.height); + + //Filters can either return a new ImageData object, or just modify + //the one they received. + var newImageData = func(imageData, filterParam); + if (newImageData instanceof ImageData) { + pixelsState.putImageData( + newImageData, + 0, + 0, + 0, + 0, + canvas.width, + canvas.height + ); + } else { + pixelsState.putImageData(imageData, 0, 0, 0, 0, canvas.width, canvas.height); + } + }; + + /* + * Filters + */ + + /** + * Converts the image to black and white pixels depending if they are above or + * below the threshold defined by the level parameter. The parameter must be + * between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used. + * + * Borrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/ + * + * @private + * @param {Canvas} canvas + * @param {Float} level + */ + Filters.threshold = function(canvas, level) { + var pixels = Filters._toPixels(canvas); + + if (level === undefined) { + level = 0.5; + } + var thresh = Math.floor(level * 255); + + for (var i = 0; i < pixels.length; i += 4) { + var r = pixels[i]; + var g = pixels[i + 1]; + var b = pixels[i + 2]; + var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b; + var val; + if (gray >= thresh) { + val = 255; + } else { + val = 0; + } + pixels[i] = pixels[i + 1] = pixels[i + 2] = val; + } + }; + + /** + * Converts any colors in the image to grayscale equivalents. + * No parameter is used. + * + * Borrowed from http://www.html5rocks.com/en/tutorials/canvas/imagefilters/ + * + * @private + * @param {Canvas} canvas + */ + Filters.gray = function(canvas) { + var pixels = Filters._toPixels(canvas); + + for (var i = 0; i < pixels.length; i += 4) { + var r = pixels[i]; + var g = pixels[i + 1]; + var b = pixels[i + 2]; + + // CIE luminance for RGB + var gray = 0.2126 * r + 0.7152 * g + 0.0722 * b; + pixels[i] = pixels[i + 1] = pixels[i + 2] = gray; + } + }; + + /** + * Sets the alpha channel to entirely opaque. No parameter is used. + * + * @private + * @param {Canvas} canvas + */ + Filters.opaque = function(canvas) { + var pixels = Filters._toPixels(canvas); + + for (var i = 0; i < pixels.length; i += 4) { + pixels[i + 3] = 255; + } + + return pixels; + }; + + /** + * Sets each pixel to its inverse value. No parameter is used. + * @private + * @param {Canvas} canvas + */ + Filters.invert = function(canvas) { + var pixels = Filters._toPixels(canvas); + + for (var i = 0; i < pixels.length; i += 4) { + pixels[i] = 255 - pixels[i]; + pixels[i + 1] = 255 - pixels[i + 1]; + pixels[i + 2] = 255 - pixels[i + 2]; + } + }; + + /** + * Limits each channel of the image to the number of colors specified as + * the parameter. The parameter can be set to values between 2 and 255, but + * results are most noticeable in the lower ranges. + * + * Adapted from java based processing implementation + * + * @private + * @param {Canvas} canvas + * @param {Integer} level + */ + Filters.posterize = function(canvas, level) { + var pixels = Filters._toPixels(canvas); + + if (level < 2 || level > 255) { + throw new Error( + 'Level must be greater than 2 and less than 255 for posterize' + ); + } + + var levels1 = level - 1; + for (var i = 0; i < pixels.length; i += 4) { + var rlevel = pixels[i]; + var glevel = pixels[i + 1]; + var blevel = pixels[i + 2]; + + pixels[i] = ((rlevel * level) >> 8) * 255 / levels1; + pixels[i + 1] = ((glevel * level) >> 8) * 255 / levels1; + pixels[i + 2] = ((blevel * level) >> 8) * 255 / levels1; + } + }; + + /** + * reduces the bright areas in an image + * @private + * @param {Canvas} canvas + * + */ + Filters.dilate = function(canvas) { + var pixels = Filters._toPixels(canvas); + var currIdx = 0; + var maxIdx = pixels.length ? pixels.length / 4 : 0; + var out = new Int32Array(maxIdx); + var currRowIdx, maxRowIdx, colOrig, colOut, currLum; + + var idxRight, idxLeft, idxUp, idxDown; + var colRight, colLeft, colUp, colDown; + var lumRight, lumLeft, lumUp, lumDown; + + while (currIdx < maxIdx) { + currRowIdx = currIdx; + maxRowIdx = currIdx + canvas.width; + while (currIdx < maxRowIdx) { + colOrig = colOut = Filters._getARGB(pixels, currIdx); + idxLeft = currIdx - 1; + idxRight = currIdx + 1; + idxUp = currIdx - canvas.width; + idxDown = currIdx + canvas.width; + + if (idxLeft < currRowIdx) { + idxLeft = currIdx; + } + if (idxRight >= maxRowIdx) { + idxRight = currIdx; + } + if (idxUp < 0) { + idxUp = 0; + } + if (idxDown >= maxIdx) { + idxDown = currIdx; + } + colUp = Filters._getARGB(pixels, idxUp); + colLeft = Filters._getARGB(pixels, idxLeft); + colDown = Filters._getARGB(pixels, idxDown); + colRight = Filters._getARGB(pixels, idxRight); + + //compute luminance + currLum = + 77 * ((colOrig >> 16) & 0xff) + + 151 * ((colOrig >> 8) & 0xff) + + 28 * (colOrig & 0xff); + lumLeft = + 77 * ((colLeft >> 16) & 0xff) + + 151 * ((colLeft >> 8) & 0xff) + + 28 * (colLeft & 0xff); + lumRight = + 77 * ((colRight >> 16) & 0xff) + + 151 * ((colRight >> 8) & 0xff) + + 28 * (colRight & 0xff); + lumUp = + 77 * ((colUp >> 16) & 0xff) + + 151 * ((colUp >> 8) & 0xff) + + 28 * (colUp & 0xff); + lumDown = + 77 * ((colDown >> 16) & 0xff) + + 151 * ((colDown >> 8) & 0xff) + + 28 * (colDown & 0xff); + + if (lumLeft > currLum) { + colOut = colLeft; + currLum = lumLeft; + } + if (lumRight > currLum) { + colOut = colRight; + currLum = lumRight; + } + if (lumUp > currLum) { + colOut = colUp; + currLum = lumUp; + } + if (lumDown > currLum) { + colOut = colDown; + currLum = lumDown; + } + out[currIdx++] = colOut; + } + } + Filters._setPixels(pixels, out); + }; + + /** + * increases the bright areas in an image + * @private + * @param {Canvas} canvas + * + */ + Filters.erode = function(canvas) { + var pixels = Filters._toPixels(canvas); + var currIdx = 0; + var maxIdx = pixels.length ? pixels.length / 4 : 0; + var out = new Int32Array(maxIdx); + var currRowIdx, maxRowIdx, colOrig, colOut, currLum; + var idxRight, idxLeft, idxUp, idxDown; + var colRight, colLeft, colUp, colDown; + var lumRight, lumLeft, lumUp, lumDown; + + while (currIdx < maxIdx) { + currRowIdx = currIdx; + maxRowIdx = currIdx + canvas.width; + while (currIdx < maxRowIdx) { + colOrig = colOut = Filters._getARGB(pixels, currIdx); + idxLeft = currIdx - 1; + idxRight = currIdx + 1; + idxUp = currIdx - canvas.width; + idxDown = currIdx + canvas.width; + + if (idxLeft < currRowIdx) { + idxLeft = currIdx; + } + if (idxRight >= maxRowIdx) { + idxRight = currIdx; + } + if (idxUp < 0) { + idxUp = 0; + } + if (idxDown >= maxIdx) { + idxDown = currIdx; + } + colUp = Filters._getARGB(pixels, idxUp); + colLeft = Filters._getARGB(pixels, idxLeft); + colDown = Filters._getARGB(pixels, idxDown); + colRight = Filters._getARGB(pixels, idxRight); + + //compute luminance + currLum = + 77 * ((colOrig >> 16) & 0xff) + + 151 * ((colOrig >> 8) & 0xff) + + 28 * (colOrig & 0xff); + lumLeft = + 77 * ((colLeft >> 16) & 0xff) + + 151 * ((colLeft >> 8) & 0xff) + + 28 * (colLeft & 0xff); + lumRight = + 77 * ((colRight >> 16) & 0xff) + + 151 * ((colRight >> 8) & 0xff) + + 28 * (colRight & 0xff); + lumUp = + 77 * ((colUp >> 16) & 0xff) + + 151 * ((colUp >> 8) & 0xff) + + 28 * (colUp & 0xff); + lumDown = + 77 * ((colDown >> 16) & 0xff) + + 151 * ((colDown >> 8) & 0xff) + + 28 * (colDown & 0xff); + + if (lumLeft < currLum) { + colOut = colLeft; + currLum = lumLeft; + } + if (lumRight < currLum) { + colOut = colRight; + currLum = lumRight; + } + if (lumUp < currLum) { + colOut = colUp; + currLum = lumUp; + } + if (lumDown < currLum) { + colOut = colDown; + currLum = lumDown; + } + + out[currIdx++] = colOut; + } + } + Filters._setPixels(pixels, out); + }; + + // BLUR + + // internal kernel stuff for the gaussian blur filter + var blurRadius; + var blurKernelSize; + var blurKernel; + var blurMult; + + /* + * Port of https://github.com/processing/processing/blob/ + * master/core/src/processing/core/PImage.java#L1250 + * + * Optimized code for building the blur kernel. + * further optimized blur code (approx. 15% for radius=20) + * bigger speed gains for larger radii (~30%) + * added support for various image types (ALPHA, RGB, ARGB) + * [toxi 050728] + */ + function buildBlurKernel(r) { + var radius = (r * 3.5) | 0; + radius = radius < 1 ? 1 : radius < 248 ? radius : 248; + + if (blurRadius !== radius) { + blurRadius = radius; + blurKernelSize = (1 + blurRadius) << 1; + blurKernel = new Int32Array(blurKernelSize); + blurMult = new Array(blurKernelSize); + for (var l = 0; l < blurKernelSize; l++) { + blurMult[l] = new Int32Array(256); + } + + var bk, bki; + var bm, bmi; + + for (var i = 1, radiusi = radius - 1; i < radius; i++) { + blurKernel[radius + i] = blurKernel[radiusi] = bki = radiusi * radiusi; + bm = blurMult[radius + i]; + bmi = blurMult[radiusi--]; + for (var j = 0; j < 256; j++) { + bm[j] = bmi[j] = bki * j; + } + } + bk = blurKernel[radius] = radius * radius; + bm = blurMult[radius]; + + for (var k = 0; k < 256; k++) { + bm[k] = bk * k; + } + } + } + + // Port of https://github.com/processing/processing/blob/ + // master/core/src/processing/core/PImage.java#L1433 + function blurARGB(canvas, radius) { + var pixels = Filters._toPixels(canvas); + var width = canvas.width; + var height = canvas.height; + var numPackedPixels = width * height; + var argb = new Int32Array(numPackedPixels); + for (var j = 0; j < numPackedPixels; j++) { + argb[j] = Filters._getARGB(pixels, j); + } + var sum, cr, cg, cb, ca; + var read, ri, ym, ymi, bk0; + var a2 = new Int32Array(numPackedPixels); + var r2 = new Int32Array(numPackedPixels); + var g2 = new Int32Array(numPackedPixels); + var b2 = new Int32Array(numPackedPixels); + var yi = 0; + buildBlurKernel(radius); + var x, y, i; + var bm; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + cb = cg = cr = ca = sum = 0; + read = x - blurRadius; + if (read < 0) { + bk0 = -read; + read = 0; + } else { + if (read >= width) { + break; + } + bk0 = 0; + } + for (i = bk0; i < blurKernelSize; i++) { + if (read >= width) { + break; + } + var c = argb[read + yi]; + bm = blurMult[i]; + ca += bm[(c & -16777216) >>> 24]; + cr += bm[(c & 16711680) >> 16]; + cg += bm[(c & 65280) >> 8]; + cb += bm[c & 255]; + sum += blurKernel[i]; + read++; + } + ri = yi + x; + a2[ri] = ca / sum; + r2[ri] = cr / sum; + g2[ri] = cg / sum; + b2[ri] = cb / sum; + } + yi += width; + } + yi = 0; + ym = -blurRadius; + ymi = ym * width; + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + cb = cg = cr = ca = sum = 0; + if (ym < 0) { + bk0 = ri = -ym; + read = x; + } else { + if (ym >= height) { + break; + } + bk0 = 0; + ri = ym; + read = x + ymi; + } + for (i = bk0; i < blurKernelSize; i++) { + if (ri >= height) { + break; + } + bm = blurMult[i]; + ca += bm[a2[read]]; + cr += bm[r2[read]]; + cg += bm[g2[read]]; + cb += bm[b2[read]]; + sum += blurKernel[i]; + ri++; + read += width; + } + argb[x + yi] = + ((ca / sum) << 24) | ((cr / sum) << 16) | ((cg / sum) << 8) | (cb / sum); + } + yi += width; + ymi += width; + ym++; + } + Filters._setPixels(pixels, argb); + } + + Filters.blur = function(canvas, radius) { + blurARGB(canvas, radius); + }; + + module.exports = Filters; + }, + {} + ], + 44: [ + function(_dereq_, module, exports) { + /** + * @module Image + * @submodule Image + * @for p5 + * @requires core + */ + + /** + * This module defines the p5 methods for the p5.Image class + * for drawing images to the main display canvas. + */ + 'use strict'; + + var p5 = _dereq_('../core/main'); + // This is not global, but ESLint is not aware that + // this module is implicitly enclosed with Browserify: this overrides the + // redefined-global error and permits using the name "frames" for the array + // of saved animation frames. + + /* global frames:true */ var frames = []; + + /** + * Creates a new p5.Image (the datatype for storing images). This provides a + * fresh buffer of pixels to play with. Set the size of the buffer with the + * width and height parameters. + *

+ * .pixels gives access to an array containing the values for all the pixels + * in the display window. + * These values are numbers. This array is the size (including an appropriate + * factor for the pixelDensity) of the display window x4, + * representing the R, G, B, A values in order for each pixel, moving from + * left to right across each row, then down each column. See .pixels for + * more info. It may also be simpler to use set() or get(). + *

+ * Before accessing the pixels of an image, the data must loaded with the + * loadPixels() function. After the array data has been modified, the + * updatePixels() function must be run to update the changes. + * + * @method createImage + * @param {Integer} width width in pixels + * @param {Integer} height height in pixels + * @return {p5.Image} the p5.Image object + * @example + *
+ * + * let img = createImage(66, 66); + * img.loadPixels(); + * for (let i = 0; i < img.width; i++) { + * for (let j = 0; j < img.height; j++) { + * img.set(i, j, color(0, 90, 102)); + * } + * } + * img.updatePixels(); + * image(img, 17, 17); + * + *
+ * + *
+ * + * let img = createImage(66, 66); + * img.loadPixels(); + * for (let i = 0; i < img.width; i++) { + * for (let j = 0; j < img.height; j++) { + * img.set(i, j, color(0, 90, 102, (i % img.width) * 2)); + * } + * } + * img.updatePixels(); + * image(img, 17, 17); + * image(img, 34, 34); + * + *
+ * + *
+ * + * let pink = color(255, 102, 204); + * let img = createImage(66, 66); + * img.loadPixels(); + * let d = pixelDensity(); + * let halfImage = 4 * (img.width * d) * (img.height / 2 * d); + * for (let i = 0; i < halfImage; i += 4) { + * img.pixels[i] = red(pink); + * img.pixels[i + 1] = green(pink); + * img.pixels[i + 2] = blue(pink); + * img.pixels[i + 3] = alpha(pink); + * } + * img.updatePixels(); + * image(img, 17, 17); + * + *
+ * + * @alt + * 66x66 dark turquoise rect in center of canvas. + * 2 gradated dark turquoise rects fade left. 1 center 1 bottom right of canvas + * no image displayed + * + */ + p5.prototype.createImage = function(width, height) { + p5._validateParameters('createImage', arguments); + return new p5.Image(width, height); + }; + + /** + * Save the current canvas as an image. The browser will either save the + * file immediately, or prompt the user with a dialogue window. + * + * @method saveCanvas + * @param {p5.Element|HTMLCanvasElement} selectedCanvas a variable + * representing a specific html5 canvas (optional) + * @param {String} [filename] + * @param {String} [extension] 'jpg' or 'png' + * + * @example + *
+ * function setup() { + * let c = createCanvas(100, 100); + * background(255, 0, 0); + * saveCanvas(c, 'myCanvas', 'jpg'); + * } + *
+ *
+ * // note that this example has the same result as above + * // if no canvas is specified, defaults to main canvas + * function setup() { + * let c = createCanvas(100, 100); + * background(255, 0, 0); + * saveCanvas('myCanvas', 'jpg'); + * + * // all of the following are valid + * saveCanvas(c, 'myCanvas', 'jpg'); + * saveCanvas(c, 'myCanvas.jpg'); + * saveCanvas(c, 'myCanvas'); + * saveCanvas(c); + * saveCanvas('myCanvas', 'png'); + * saveCanvas('myCanvas'); + * saveCanvas(); + * } + *
+ * + * @alt + * no image displayed + * no image displayed + * no image displayed + */ + /** + * @method saveCanvas + * @param {String} [filename] + * @param {String} [extension] + */ + p5.prototype.saveCanvas = function() { + p5._validateParameters('saveCanvas', arguments); + + // copy arguments to array + var args = [].slice.call(arguments); + var htmlCanvas, filename, extension; + + if (arguments[0] instanceof HTMLCanvasElement) { + htmlCanvas = arguments[0]; + args.shift(); + } else if (arguments[0] instanceof p5.Element) { + htmlCanvas = arguments[0].elt; + args.shift(); + } else { + htmlCanvas = this._curElement && this._curElement.elt; + } + + if (args.length >= 1) { + filename = args[0]; + } + if (args.length >= 2) { + extension = args[1]; + } + + extension = + extension || + p5.prototype._checkFileExtension(filename, extension)[1] || + 'png'; + + var mimeType; + switch (extension) { + default: + //case 'png': + mimeType = 'image/png'; + break; + case 'jpeg': + case 'jpg': + mimeType = 'image/jpeg'; + break; + } + + htmlCanvas.toBlob(function(blob) { + p5.prototype.downloadFile(blob, filename, extension); + }, mimeType); + }; + + /** + * Capture a sequence of frames that can be used to create a movie. + * Accepts a callback. For example, you may wish to send the frames + * to a server where they can be stored or converted into a movie. + * If no callback is provided, the browser will pop up save dialogues in an + * attempt to download all of the images that have just been created. With the + * callback provided the image data isn't saved by default but instead passed + * as an argument to the callback function as an array of objects, with the + * size of array equal to the total number of frames. + * + * Note that saveFrames() will only save the first 15 frames of an animation. + * To export longer animations, you might look into a library like + * ccapture.js. + * + * @method saveFrames + * @param {String} filename + * @param {String} extension 'jpg' or 'png' + * @param {Number} duration Duration in seconds to save the frames for. + * @param {Number} framerate Framerate to save the frames in. + * @param {function(Array)} [callback] A callback function that will be executed + to handle the image data. This function + should accept an array as argument. The + array will contain the specified number of + frames of objects. Each object has three + properties: imageData - an + image/octet-stream, filename and extension. + * @example + *
+ * function draw() { + * background(mouseX); + * } + * + * function mousePressed() { + * saveFrames('out', 'png', 1, 25, data => { + * print(data); + * }); + * } +
+ * + * @alt + * canvas background goes from light to dark with mouse x. + * + */ + p5.prototype.saveFrames = function(fName, ext, _duration, _fps, callback) { + p5._validateParameters('saveFrames', arguments); + var duration = _duration || 3; + duration = p5.prototype.constrain(duration, 0, 15); + duration = duration * 1000; + var fps = _fps || 15; + fps = p5.prototype.constrain(fps, 0, 22); + var count = 0; + + var makeFrame = p5.prototype._makeFrame; + var cnv = this._curElement.elt; + var frameFactory = setInterval(function() { + makeFrame(fName + count, ext, cnv); + count++; + }, 1000 / fps); + + setTimeout(function() { + clearInterval(frameFactory); + if (callback) { + callback(frames); + } else { + for (var i = 0; i < frames.length; i++) { + var f = frames[i]; + p5.prototype.downloadFile(f.imageData, f.filename, f.ext); + } + } + frames = []; // clear frames + }, duration + 0.01); + }; + + p5.prototype._makeFrame = function(filename, extension, _cnv) { + var cnv; + if (this) { + cnv = this._curElement.elt; + } else { + cnv = _cnv; + } + var mimeType; + if (!extension) { + extension = 'png'; + mimeType = 'image/png'; + } else { + switch (extension.toLowerCase()) { + case 'png': + mimeType = 'image/png'; + break; + case 'jpeg': + mimeType = 'image/jpeg'; + break; + case 'jpg': + mimeType = 'image/jpeg'; + break; + default: + mimeType = 'image/png'; + break; + } + } + var downloadMime = 'image/octet-stream'; + var imageData = cnv.toDataURL(mimeType); + imageData = imageData.replace(mimeType, downloadMime); + + var thisFrame = {}; + thisFrame.imageData = imageData; + thisFrame.filename = filename; + thisFrame.ext = extension; + frames.push(thisFrame); + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 45: [ + function(_dereq_, module, exports) { + /** + * @module Image + * @submodule Loading & Displaying + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var Filters = _dereq_('./filters'); + var canvas = _dereq_('../core/helpers'); + var constants = _dereq_('../core/constants'); + + _dereq_('../core/error_helpers'); + + /** + * Loads an image from a path and creates a p5.Image from it. + *

+ * The image may not be immediately available for rendering + * If you want to ensure that the image is ready before doing + * anything with it, place the loadImage() call in preload(). + * You may also supply a callback function to handle the image when it's ready. + *

+ * The path to the image should be relative to the HTML file + * that links in your sketch. Loading an image from a URL or other + * remote location may be blocked due to your browser's built-in + * security. + * + * @method loadImage + * @param {String} path Path of the image to be loaded + * @param {function(p5.Image)} [successCallback] Function to be called once + * the image is loaded. Will be passed the + * p5.Image. + * @param {function(Event)} [failureCallback] called with event error if + * the image fails to load. + * @return {p5.Image} the p5.Image object + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * } + * + *
+ *
+ * + * function setup() { + * // here we use a callback to display the image after loading + * loadImage('assets/laDefense.jpg', img => { + * image(img, 0, 0); + * }); + * } + * + *
+ * + * @alt + * image of the underside of a white umbrella and grided ceililng above + * image of the underside of a white umbrella and grided ceililng above + * + */ + p5.prototype.loadImage = function(path, successCallback, failureCallback) { + p5._validateParameters('loadImage', arguments); + var img = new Image(); + var pImg = new p5.Image(1, 1, this); + + var self = this; + img.onload = function() { + pImg.width = pImg.canvas.width = img.width; + pImg.height = pImg.canvas.height = img.height; + + // Draw the image into the backing canvas of the p5.Image + pImg.drawingContext.drawImage(img, 0, 0); + pImg.modified = true; + + if (typeof successCallback === 'function') { + successCallback(pImg); + } + + self._decrementPreload(); + }; + img.onerror = function(e) { + p5._friendlyFileLoadError(0, img.src); + if (typeof failureCallback === 'function') { + failureCallback(e); + } else { + console.error(e); + } + }; + + // Set crossOrigin in case image is served with CORS headers. + // This will let us draw to the canvas without tainting it. + // See https://developer.mozilla.org/en-US/docs/HTML/CORS_Enabled_Image + // When using data-uris the file will be loaded locally + // so we don't need to worry about crossOrigin with base64 file types. + if (path.indexOf('data:image/') !== 0) { + img.crossOrigin = 'Anonymous'; + } + + // start loading the image + img.src = path; + + return pImg; + }; + + /** + * Validates clipping params. Per drawImage spec sWidth and sHight cannot be + * negative or greater than image intrinsic width and height + * @private + * @param {Number} sVal + * @param {Number} iVal + * @returns {Number} + * @private + */ + function _sAssign(sVal, iVal) { + if (sVal > 0 && sVal < iVal) { + return sVal; + } else { + return iVal; + } + } + + /** + * Draw an image to the p5.js canvas. + * + * This function can be used with different numbers of parameters. The + * simplest use requires only three parameters: img, x, and y—where (x, y) is + * the position of the image. Two more parameters can optionally be added to + * specify the width and height of the image. + * + * This function can also be used with all eight Number parameters. To + * differentiate between all these parameters, p5.js uses the language of + * "destination rectangle" (which corresponds to "dx", "dy", etc.) and "source + * image" (which corresponds to "sx", "sy", etc.) below. Specifying the + * "source image" dimensions can be useful when you want to display a + * subsection of the source image instead of the whole thing. Here's a diagram + * to explain further: + * + * + * @method image + * @param {p5.Image|p5.Element} img the image to display + * @param {Number} x the x-coordinate of the top-left corner of the image + * @param {Number} y the y-coordinate of the top-left corner of the image + * @param {Number} [width] the width to draw the image + * @param {Number} [height] the height to draw the image + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * function setup() { + * // Top-left corner of the img is at (0, 0) + * // Width and height are the img's original width and height + * image(img, 0, 0); + * } + * + *
+ *
+ * + * let img; + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * function setup() { + * background(50); + * // Top-left corner of the img is at (10, 10) + * // Width and height are 50 x 50 + * image(img, 10, 10, 50, 50); + * } + * + *
+ *
+ * + * function setup() { + * // Here, we use a callback to display the image after loading + * loadImage('assets/laDefense.jpg', img => { + * image(img, 0, 0); + * }); + * } + * + *
+ *
+ * + * let img; + * function preload() { + * img = loadImage('assets/gradient.png'); + * } + * function setup() { + * // 1. Background image + * // Top-left corner of the img is at (0, 0) + * // Width and height are the img's original width and height, 100 x 100 + * image(img, 0, 0); + * // 2. Top right image + * // Top-left corner of destination rectangle is at (50, 0) + * // Destination rectangle width and height are 40 x 20 + * // The next parameters are relative to the source image: + * // - Starting at position (50, 50) on the source image, capture a 50 x 50 + * // subsection + * // - Draw this subsection to fill the dimensions of the destination rectangle + * image(img, 50, 0, 40, 20, 50, 50, 50, 50); + * } + * + *
+ * @alt + * image of the underside of a white umbrella and gridded ceiling above + * image of the underside of a white umbrella and gridded ceiling above + * + */ + /** + * @method image + * @param {p5.Image|p5.Element} img + * @param {Number} dx the x-coordinate of the destination + * rectangle in which to draw the source image + * @param {Number} dy the y-coordinate of the destination + * rectangle in which to draw the source image + * @param {Number} dWidth the width of the destination rectangle + * @param {Number} dHeight the height of the destination rectangle + * @param {Number} sx the x-coordinate of the subsection of the source + * image to draw into the destination rectangle + * @param {Number} sy the y-coordinate of the subsection of the source + * image to draw into the destination rectangle + * @param {Number} [sWidth] the width of the subsection of the + * source image to draw into the destination + * rectangle + * @param {Number} [sHeight] the height of the subsection of the + * source image to draw into the destination rectangle + */ + p5.prototype.image = function( + img, + dx, + dy, + dWidth, + dHeight, + sx, + sy, + sWidth, + sHeight + ) { + // set defaults per spec: https://goo.gl/3ykfOq + + p5._validateParameters('image', arguments); + + var defW = img.width; + var defH = img.height; + + if (img.elt && img.elt.videoWidth && !img.canvas) { + // video no canvas + defW = img.elt.videoWidth; + defH = img.elt.videoHeight; + } + + var _dx = dx; + var _dy = dy; + var _dw = dWidth || defW; + var _dh = dHeight || defH; + var _sx = sx || 0; + var _sy = sy || 0; + var _sw = sWidth || defW; + var _sh = sHeight || defH; + + _sw = _sAssign(_sw, defW); + _sh = _sAssign(_sh, defH); + + // This part needs cleanup and unit tests + // see issues https://github.com/processing/p5.js/issues/1741 + // and https://github.com/processing/p5.js/issues/1673 + var pd = 1; + + if (img.elt && !img.canvas && img.elt.style.width) { + //if img is video and img.elt.size() has been used and + //no width passed to image() + if (img.elt.videoWidth && !dWidth) { + pd = img.elt.videoWidth; + } else { + //all other cases + pd = img.elt.width; + } + pd /= parseInt(img.elt.style.width, 10); + } + + _sx *= pd; + _sy *= pd; + _sh *= pd; + _sw *= pd; + + var vals = canvas.modeAdjust(_dx, _dy, _dw, _dh, this._renderer._imageMode); + + // tint the image if there is a tint + this._renderer.image(img, _sx, _sy, _sw, _sh, vals.x, vals.y, vals.w, vals.h); + }; + + /** + * Sets the fill value for displaying images. Images can be tinted to + * specified colors or made transparent by including an alpha value. + *

+ * To apply transparency to an image without affecting its color, use + * white as the tint color and specify an alpha value. For instance, + * tint(255, 128) will make an image 50% transparent (assuming the default + * alpha range of 0-255, which can be changed with colorMode()). + *

+ * The value for the gray parameter must be less than or equal to the current + * maximum value as specified by colorMode(). The default maximum value is + * 255. + * + * + * @method tint + * @param {Number} v1 red or hue value relative to + * the current color range + * @param {Number} v2 green or saturation value + * relative to the current color range + * @param {Number} v3 blue or brightness value + * relative to the current color range + * @param {Number} [alpha] + * + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * tint(0, 153, 204); // Tint blue + * image(img, 50, 0); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * tint(0, 153, 204, 126); // Tint blue and set transparency + * image(img, 50, 0); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * tint(255, 126); // Apply transparency without changing color + * image(img, 50, 0); + * } + * + *
+ * + * @alt + * 2 side by side images of umbrella and ceiling, one image with blue tint + * Images of umbrella and ceiling, one half of image with blue tint + * 2 side by side images of umbrella and ceiling, one image translucent + * + */ + + /** + * @method tint + * @param {String} value a color string + */ + + /** + * @method tint + * @param {Number} gray a gray value + * @param {Number} [alpha] + */ + + /** + * @method tint + * @param {Number[]} values an array containing the red,green,blue & + * and alpha components of the color + */ + + /** + * @method tint + * @param {p5.Color} color the tint color + */ + p5.prototype.tint = function() { + p5._validateParameters('tint', arguments); + var c = this.color.apply(this, arguments); + this._renderer._tint = c.levels; + }; + + /** + * Removes the current fill value for displaying images and reverts to + * displaying images with their original hues. + * + * @method noTint + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * tint(0, 153, 204); // Tint blue + * image(img, 0, 0); + * noTint(); // Disable tint + * image(img, 50, 0); + * } + * + *
+ * + * @alt + * 2 side by side images of bricks, left image with blue tint + * + */ + p5.prototype.noTint = function() { + this._renderer._tint = null; + }; + + /** + * Apply the current tint color to the input image, return the resulting + * canvas. + * + * @private + * @param {p5.Image} The image to be tinted + * @return {canvas} The resulting tinted canvas + * + */ + p5.prototype._getTintedImageCanvas = function(img) { + if (!img.canvas) { + return img; + } + var pixels = Filters._toPixels(img.canvas); + var tmpCanvas = document.createElement('canvas'); + tmpCanvas.width = img.canvas.width; + tmpCanvas.height = img.canvas.height; + var tmpCtx = tmpCanvas.getContext('2d'); + var id = tmpCtx.createImageData(img.canvas.width, img.canvas.height); + var newPixels = id.data; + + for (var i = 0; i < pixels.length; i += 4) { + var r = pixels[i]; + var g = pixels[i + 1]; + var b = pixels[i + 2]; + var a = pixels[i + 3]; + + newPixels[i] = r * this._renderer._tint[0] / 255; + newPixels[i + 1] = g * this._renderer._tint[1] / 255; + newPixels[i + 2] = b * this._renderer._tint[2] / 255; + newPixels[i + 3] = a * this._renderer._tint[3] / 255; + } + + tmpCtx.putImageData(id, 0, 0); + return tmpCanvas; + }; + + /** + * Set image mode. Modifies the location from which images are drawn by + * changing the way in which parameters given to image() are interpreted. + * The default mode is imageMode(CORNER), which interprets the second and + * third parameters of image() as the upper-left corner of the image. If + * two additional parameters are specified, they are used to set the image's + * width and height. + *

+ * imageMode(CORNERS) interprets the second and third parameters of image() + * as the location of one corner, and the fourth and fifth parameters as the + * opposite corner. + *

+ * imageMode(CENTER) interprets the second and third parameters of image() + * as the image's center point. If two additional parameters are specified, + * they are used to set the image's width and height. + * + * @method imageMode + * @param {Constant} mode either CORNER, CORNERS, or CENTER + * @example + * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * imageMode(CORNER); + * image(img, 10, 10, 50, 50); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * imageMode(CORNERS); + * image(img, 10, 10, 90, 40); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * imageMode(CENTER); + * image(img, 50, 50, 80, 80); + * } + * + *
+ * + * @alt + * small square image of bricks + * horizontal rectangle image of bricks + * large square image of bricks + * + */ + p5.prototype.imageMode = function(m) { + p5._validateParameters('imageMode', arguments); + if ( + m === constants.CORNER || + m === constants.CORNERS || + m === constants.CENTER + ) { + this._renderer._imageMode = m; + } + }; + + module.exports = p5; + }, + { + '../core/constants': 18, + '../core/error_helpers': 20, + '../core/helpers': 21, + '../core/main': 24, + './filters': 43 + } + ], + 46: [ + function(_dereq_, module, exports) { + /** + * @module Image + * @submodule Image + * @requires core + * @requires constants + * @requires filters + */ + + /** + * This module defines the p5.Image class and P5 methods for + * drawing images to the main display canvas. + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var Filters = _dereq_('./filters'); + + /* + * Class methods + */ + + /** + * Creates a new p5.Image. A p5.Image is a canvas backed representation of an + * image. + *

+ * p5 can display .gif, .jpg and .png images. Images may be displayed + * in 2D and 3D space. Before an image is used, it must be loaded with the + * loadImage() function. The p5.Image class contains fields for the width and + * height of the image, as well as an array called pixels[] that contains the + * values for every pixel in the image. + *

+ * The methods described below allow easy access to the image's pixels and + * alpha channel and simplify the process of compositing. + *

+ * Before using the pixels[] array, be sure to use the loadPixels() method on + * the image to make sure that the pixel data is properly loaded. + * @example + *
+ * function setup() { + * let img = createImage(100, 100); // same as new p5.Image(100, 100); + * img.loadPixels(); + * createCanvas(100, 100); + * background(0); + * + * // helper for writing color to array + * function writeColor(image, x, y, red, green, blue, alpha) { + * let index = (x + y * width) * 4; + * image.pixels[index] = red; + * image.pixels[index + 1] = green; + * image.pixels[index + 2] = blue; + * image.pixels[index + 3] = alpha; + * } + * + * let x, y; + * // fill with random colors + * for (y = 0; y < img.height; y++) { + * for (x = 0; x < img.width; x++) { + * let red = random(255); + * let green = random(255); + * let blue = random(255); + * let alpha = 255; + * writeColor(img, x, y, red, green, blue, alpha); + * } + * } + * + * // draw a red line + * y = 0; + * for (x = 0; x < img.width; x++) { + * writeColor(img, x, y, 255, 0, 0, 255); + * } + * + * // draw a green line + * y = img.height - 1; + * for (x = 0; x < img.width; x++) { + * writeColor(img, x, y, 0, 255, 0, 255); + * } + * + * img.updatePixels(); + * image(img, 0, 0); + * } + *
+ * + * + * @class p5.Image + * @param {Number} width + * @param {Number} height + */ + p5.Image = function(width, height) { + /** + * Image width. + * @property {Number} width + * @readOnly + * @example + *
+ * let img; + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * createCanvas(100, 100); + * image(img, 0, 0); + * for (let i = 0; i < img.width; i++) { + * let c = img.get(i, img.height / 2); + * stroke(c); + * line(i, height / 2, i, height); + * } + * } + *
+ * + * @alt + * rocky mountains in top and horizontal lines in corresponding colors in bottom. + * + */ + this.width = width; + /** + * Image height. + * @property {Number} height + * @readOnly + * @example + *
+ * let img; + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * createCanvas(100, 100); + * image(img, 0, 0); + * for (let i = 0; i < img.height; i++) { + * let c = img.get(img.width / 2, i); + * stroke(c); + * line(0, i, width / 2, i); + * } + * } + *
+ * + * @alt + * rocky mountains on right and vertical lines in corresponding colors on left. + * + */ + this.height = height; + this.canvas = document.createElement('canvas'); + this.canvas.width = this.width; + this.canvas.height = this.height; + this.drawingContext = this.canvas.getContext('2d'); + this._pixelsState = this; + this._pixelDensity = 1; + this._pixelsDirty = true; + //For WebGL Texturing only: used to determine whether to reupload texture to GPU + this._modified = false; + /** + * Array containing the values for all the pixels in the display window. + * These values are numbers. This array is the size (include an appropriate + * factor for pixelDensity) of the display window x4, + * representing the R, G, B, A values in order for each pixel, moving from + * left to right across each row, then down each column. Retina and other + * high denisty displays may have more pixels (by a factor of + * pixelDensity^2). + * For example, if the image is 100x100 pixels, there will be 40,000. With + * pixelDensity = 2, there will be 160,000. The first four values + * (indices 0-3) in the array will be the R, G, B, A values of the pixel at + * (0, 0). The second four values (indices 4-7) will contain the R, G, B, A + * values of the pixel at (1, 0). More generally, to set values for a pixel + * at (x, y): + * ```javascript + * let d = pixelDensity(); + * for (let i = 0; i < d; i++) { + * for (let j = 0; j < d; j++) { + * // loop over + * index = 4 * ((y * d + j) * width * d + (x * d + i)); + * pixels[index] = r; + * pixels[index+1] = g; + * pixels[index+2] = b; + * pixels[index+3] = a; + * } + * } + * ``` + *

+ * Before accessing this array, the data must loaded with the loadPixels() + * function. After the array data has been modified, the updatePixels() + * function must be run to update the changes. + * @property {Number[]} pixels + * @example + *
+ * + * let img = createImage(66, 66); + * img.loadPixels(); + * for (let i = 0; i < img.width; i++) { + * for (let j = 0; j < img.height; j++) { + * img.set(i, j, color(0, 90, 102)); + * } + * } + * img.updatePixels(); + * image(img, 17, 17); + * + *
+ *
+ * + * let pink = color(255, 102, 204); + * let img = createImage(66, 66); + * img.loadPixels(); + * for (let i = 0; i < 4 * (width * height / 2); i += 4) { + * img.pixels[i] = red(pink); + * img.pixels[i + 1] = green(pink); + * img.pixels[i + 2] = blue(pink); + * img.pixels[i + 3] = alpha(pink); + * } + * img.updatePixels(); + * image(img, 17, 17); + * + *
+ * + * @alt + * 66x66 turquoise rect in center of canvas + * 66x66 pink rect in center of canvas + * + */ + this.pixels = []; + }; + + /** + * Helper fxn for sharing pixel methods + * + */ + p5.Image.prototype._setProperty = function(prop, value) { + this[prop] = value; + this.setModified(true); + }; + + /** + * Loads the pixels data for this image into the [pixels] attribute. + * + * @method loadPixels + * @example + *
+ * let myImage; + * let halfImage; + * + * function preload() { + * myImage = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * myImage.loadPixels(); + * halfImage = 4 * myImage.width * myImage.height / 2; + * for (let i = 0; i < halfImage; i++) { + * myImage.pixels[i + halfImage] = myImage.pixels[i]; + * } + * myImage.updatePixels(); + * } + * + * function draw() { + * image(myImage, 0, 0, width, height); + * } + *
+ * + * @alt + * 2 images of rocky mountains vertically stacked + * + */ + p5.Image.prototype.loadPixels = function() { + p5.Renderer2D.prototype.loadPixels.call(this); + this.setModified(true); + }; + + /** + * Updates the backing canvas for this image with the contents of + * the [pixels] array. + * + * @method updatePixels + * @param {Integer} x x-offset of the target update area for the + * underlying canvas + * @param {Integer} y y-offset of the target update area for the + * underlying canvas + * @param {Integer} w height of the target update area for the + * underlying canvas + * @param {Integer} h height of the target update area for the + * underlying canvas + * @example + *
+ * let myImage; + * let halfImage; + * + * function preload() { + * myImage = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * myImage.loadPixels(); + * halfImage = 4 * myImage.width * myImage.height / 2; + * for (let i = 0; i < halfImage; i++) { + * myImage.pixels[i + halfImage] = myImage.pixels[i]; + * } + * myImage.updatePixels(); + * } + * + * function draw() { + * image(myImage, 0, 0, width, height); + * } + *
+ * + * @alt + * 2 images of rocky mountains vertically stacked + * + */ + /** + * @method updatePixels + */ + p5.Image.prototype.updatePixels = function(x, y, w, h) { + p5.Renderer2D.prototype.updatePixels.call(this, x, y, w, h); + this.setModified(true); + }; + + /** + * Get a region of pixels from an image. + * + * If no params are passed, the whole image is returned. + * If x and y are the only params passed a single pixel is extracted. + * If all params are passed a rectangle region is extracted and a p5.Image + * is returned. + * + * @method get + * @param {Number} x x-coordinate of the pixel + * @param {Number} y y-coordinate of the pixel + * @param {Number} w width + * @param {Number} h height + * @return {p5.Image} the rectangle p5.Image + * @example + *
+ * let myImage; + * let c; + * + * function preload() { + * myImage = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * background(myImage); + * noStroke(); + * c = myImage.get(60, 90); + * fill(c); + * rect(25, 25, 50, 50); + * } + * + * //get() returns color here + *
+ * + * @alt + * image of rocky mountains with 50x50 green rect in front + * + */ + /** + * @method get + * @return {p5.Image} the whole p5.Image + */ + /** + * @method get + * @param {Number} x + * @param {Number} y + * @return {Number[]} color of pixel at x,y in array format [R, G, B, A] + */ + p5.Image.prototype.get = function(x, y, w, h) { + p5._validateParameters('p5.Image.get', arguments); + return p5.Renderer2D.prototype.get.apply(this, arguments); + }; + + p5.Image.prototype._getPixel = p5.Renderer2D.prototype._getPixel; + + /** + * Set the color of a single pixel or write an image into + * this p5.Image. + * + * Note that for a large number of pixels this will + * be slower than directly manipulating the pixels array + * and then calling updatePixels(). + * + * @method set + * @param {Number} x x-coordinate of the pixel + * @param {Number} y y-coordinate of the pixel + * @param {Number|Number[]|Object} a grayscale value | pixel array | + * a p5.Color | image to copy + * @example + *
+ * + * let img = createImage(66, 66); + * img.loadPixels(); + * for (let i = 0; i < img.width; i++) { + * for (let j = 0; j < img.height; j++) { + * img.set(i, j, color(0, 90, 102, (i % img.width) * 2)); + * } + * } + * img.updatePixels(); + * image(img, 17, 17); + * image(img, 34, 34); + * + *
+ * + * @alt + * 2 gradated dark turquoise rects fade left. 1 center 1 bottom right of canvas + * + */ + p5.Image.prototype.set = function(x, y, imgOrCol) { + p5.Renderer2D.prototype.set.call(this, x, y, imgOrCol); + this.setModified(true); + }; + + /** + * Resize the image to a new width and height. To make the image scale + * proportionally, use 0 as the value for the wide or high parameter. + * For instance, to make the width of an image 150 pixels, and change + * the height using the same proportion, use resize(150, 0). + * + * @method resize + * @param {Number} width the resized image width + * @param {Number} height the resized image height + * @example + *
+ * let img; + * + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + + * function draw() { + * image(img, 0, 0); + * } + * + * function mousePressed() { + * img.resize(50, 100); + * } + *
+ * + * @alt + * image of rocky mountains. zoomed in + * + */ + p5.Image.prototype.resize = function(width, height) { + // Copy contents to a temporary canvas, resize the original + // and then copy back. + // + // There is a faster approach that involves just one copy and swapping the + // this.canvas reference. We could switch to that approach if (as i think + // is the case) there an expectation that the user would not hold a + // reference to the backing canvas of a p5.Image. But since we do not + // enforce that at the moment, I am leaving in the slower, but safer + // implementation. + + // auto-resize + if (width === 0 && height === 0) { + width = this.canvas.width; + height = this.canvas.height; + } else if (width === 0) { + width = this.canvas.width * height / this.canvas.height; + } else if (height === 0) { + height = this.canvas.height * width / this.canvas.width; + } + + width = Math.floor(width); + height = Math.floor(height); + + var tempCanvas = document.createElement('canvas'); + tempCanvas.width = width; + tempCanvas.height = height; + // prettier-ignore + tempCanvas.getContext('2d').drawImage( + this.canvas, + 0, 0, this.canvas.width, this.canvas.height, + 0, 0, tempCanvas.width, tempCanvas.height); + + // Resize the original canvas, which will clear its contents + this.canvas.width = this.width = width; + this.canvas.height = this.height = height; + + //Copy the image back + + // prettier-ignore + this.drawingContext.drawImage( + tempCanvas, + 0, 0, width, height, + 0, 0, width, height); + + if (this.pixels.length > 0) { + this.loadPixels(); + } + + this.setModified(true); + this._pixelsDirty = true; + }; + + /** + * Copies a region of pixels from one image to another. If no + * srcImage is specified this is used as the source. If the source + * and destination regions aren't the same size, it will + * automatically resize source pixels to fit the specified + * target region. + * + * @method copy + * @param {p5.Image|p5.Element} srcImage source image + * @param {Integer} sx X coordinate of the source's upper left corner + * @param {Integer} sy Y coordinate of the source's upper left corner + * @param {Integer} sw source image width + * @param {Integer} sh source image height + * @param {Integer} dx X coordinate of the destination's upper left corner + * @param {Integer} dy Y coordinate of the destination's upper left corner + * @param {Integer} dw destination image width + * @param {Integer} dh destination image height + * @example + *
+ * let photo; + * let bricks; + * let x; + * let y; + * + * function preload() { + * photo = loadImage('assets/rockies.jpg'); + * bricks = loadImage('assets/bricks.jpg'); + * } + * + * function setup() { + * x = bricks.width / 2; + * y = bricks.height / 2; + * photo.copy(bricks, 0, 0, x, y, 0, 0, x, y); + * image(photo, 0, 0); + * } + *
+ * + * @alt + * image of rocky mountains and smaller image on top of bricks at top left + * + */ + /** + * @method copy + * @param {Integer} sx + * @param {Integer} sy + * @param {Integer} sw + * @param {Integer} sh + * @param {Integer} dx + * @param {Integer} dy + * @param {Integer} dw + * @param {Integer} dh + */ + p5.Image.prototype.copy = function() { + var srcImage, sx, sy, sw, sh, dx, dy, dw, dh; + if (arguments.length === 9) { + srcImage = arguments[0]; + sx = arguments[1]; + sy = arguments[2]; + sw = arguments[3]; + sh = arguments[4]; + dx = arguments[5]; + dy = arguments[6]; + dw = arguments[7]; + dh = arguments[8]; + } else if (arguments.length === 8) { + srcImage = this; + sx = arguments[0]; + sy = arguments[1]; + sw = arguments[2]; + sh = arguments[3]; + dx = arguments[4]; + dy = arguments[5]; + dw = arguments[6]; + dh = arguments[7]; + } else { + throw new Error('Signature not supported'); + } + p5.Renderer2D._copyHelper(this, srcImage, sx, sy, sw, sh, dx, dy, dw, dh); + this._pixelsDirty = true; + }; + + /** + * Masks part of an image from displaying by loading another + * image and using it's alpha channel as an alpha channel for + * this image. + * + * @method mask + * @param {p5.Image} srcImage source image + * @example + *
+ * let photo, maskImage; + * function preload() { + * photo = loadImage('assets/rockies.jpg'); + * maskImage = loadImage('assets/mask2.png'); + * } + * + * function setup() { + * createCanvas(100, 100); + * photo.mask(maskImage); + * image(photo, 0, 0); + * } + *
+ * + * @alt + * image of rocky mountains with white at right + * + * + * http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/ + * + */ + // TODO: - Accept an array of alpha values. + // - Use other channels of an image. p5 uses the + // blue channel (which feels kind of arbitrary). Note: at the + // moment this method does not match native processings original + // functionality exactly. + p5.Image.prototype.mask = function(p5Image) { + if (p5Image === undefined) { + p5Image = this; + } + var currBlend = this.drawingContext.globalCompositeOperation; + + var scaleFactor = 1; + if (p5Image instanceof p5.Renderer) { + scaleFactor = p5Image._pInst._pixelDensity; + } + + var copyArgs = [ + p5Image, + 0, + 0, + scaleFactor * p5Image.width, + scaleFactor * p5Image.height, + 0, + 0, + this.width, + this.height + ]; + + this.drawingContext.globalCompositeOperation = 'destination-in'; + p5.Image.prototype.copy.apply(this, copyArgs); + this.drawingContext.globalCompositeOperation = currBlend; + this.setModified(true); + }; + + /** + * Applies an image filter to a p5.Image + * + * @method filter + * @param {Constant} filterType either THRESHOLD, GRAY, OPAQUE, INVERT, + * POSTERIZE, BLUR, ERODE, DILATE or BLUR. + * See Filters.js for docs on + * each available filter + * @param {Number} [filterParam] an optional parameter unique + * to each filter, see above + * @example + *
+ * let photo1; + * let photo2; + * + * function preload() { + * photo1 = loadImage('assets/rockies.jpg'); + * photo2 = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * photo2.filter(GRAY); + * image(photo1, 0, 0); + * image(photo2, width / 2, 0); + * } + *
+ * + * @alt + * 2 images of rocky mountains left one in color, right in black and white + * + */ + p5.Image.prototype.filter = function(operation, value) { + Filters.apply(this.canvas, Filters[operation], value); + this.setModified(true); + }; + + /** + * Copies a region of pixels from one image to another, using a specified + * blend mode to do the operation. + * + * @method blend + * @param {p5.Image} srcImage source image + * @param {Integer} sx X coordinate of the source's upper left corner + * @param {Integer} sy Y coordinate of the source's upper left corner + * @param {Integer} sw source image width + * @param {Integer} sh source image height + * @param {Integer} dx X coordinate of the destination's upper left corner + * @param {Integer} dy Y coordinate of the destination's upper left corner + * @param {Integer} dw destination image width + * @param {Integer} dh destination image height + * @param {Constant} blendMode the blend mode. either + * BLEND, DARKEST, LIGHTEST, DIFFERENCE, + * MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT, + * SOFT_LIGHT, DODGE, BURN, ADD or NORMAL. + * + * Available blend modes are: normal | multiply | screen | overlay | + * darken | lighten | color-dodge | color-burn | hard-light | + * soft-light | difference | exclusion | hue | saturation | + * color | luminosity + * + * + * http://blogs.adobe.com/webplatform/2013/01/28/blending-features-in-canvas/ + * @example + *
+ * let mountains; + * let bricks; + * + * function preload() { + * mountains = loadImage('assets/rockies.jpg'); + * bricks = loadImage('assets/bricks_third.jpg'); + * } + * + * function setup() { + * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD); + * image(mountains, 0, 0); + * image(bricks, 0, 0); + * } + *
+ *
+ * let mountains; + * let bricks; + * + * function preload() { + * mountains = loadImage('assets/rockies.jpg'); + * bricks = loadImage('assets/bricks_third.jpg'); + * } + * + * function setup() { + * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST); + * image(mountains, 0, 0); + * image(bricks, 0, 0); + * } + *
+ *
+ * let mountains; + * let bricks; + * + * function preload() { + * mountains = loadImage('assets/rockies.jpg'); + * bricks = loadImage('assets/bricks_third.jpg'); + * } + * + * function setup() { + * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST); + * image(mountains, 0, 0); + * image(bricks, 0, 0); + * } + *
+ * + * @alt + * image of rocky mountains. Brick images on left and right. Right overexposed + * image of rockies. Brickwall images on left and right. Right mortar transparent + * image of rockies. Brickwall images on left and right. Right translucent + * + */ + /** + * @method blend + * @param {Integer} sx + * @param {Integer} sy + * @param {Integer} sw + * @param {Integer} sh + * @param {Integer} dx + * @param {Integer} dy + * @param {Integer} dw + * @param {Integer} dh + * @param {Constant} blendMode + */ + p5.Image.prototype.blend = function() { + p5.prototype.blend.apply(this, arguments); + this.setModified(true); + }; + + /** + * helper method for web GL mode to indicate that an image has been + * changed or unchanged since last upload. gl texture upload will + * set this value to false after uploading the texture. + * @method setModified + * @param {boolean} val sets whether or not the image has been + * modified. + * @private + */ + p5.Image.prototype.setModified = function(val) { + this._modified = val; //enforce boolean? + }; + + /** + * helper method for web GL mode to figure out if the image + * has been modified and might need to be re-uploaded to texture + * memory between frames. + * @method isModified + * @private + * @return {boolean} a boolean indicating whether or not the + * image has been updated or modified since last texture upload. + */ + p5.Image.prototype.isModified = function() { + return this._modified; + }; + + /** + * Saves the image to a file and force the browser to download it. + * Accepts two strings for filename and file extension + * Supports png (default) and jpg. + * + * @method save + * @param {String} filename give your file a name + * @param {String} extension 'png' or 'jpg' + * @example + *
+ * let photo; + * + * function preload() { + * photo = loadImage('assets/rockies.jpg'); + * } + * + * function draw() { + * image(photo, 0, 0); + * } + * + * function keyTyped() { + * if (key === 's') { + * photo.save('photo', 'png'); + * } + * } + *
+ * + * @alt + * image of rocky mountains. + * + */ + p5.Image.prototype.save = function(filename, extension) { + p5.prototype.saveCanvas(this.canvas, filename, extension); + }; + + module.exports = p5.Image; + }, + { '../core/main': 24, './filters': 43 } + ], + 47: [ + function(_dereq_, module, exports) { + /** + * @module Image + * @submodule Pixels + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var Filters = _dereq_('./filters'); + _dereq_('../color/p5.Color'); + + /** + * Uint8ClampedArray + * containing the values for all the pixels in the display window. + * These values are numbers. This array is the size (include an appropriate + * factor for pixelDensity) of the display window x4, + * representing the R, G, B, A values in order for each pixel, moving from + * left to right across each row, then down each column. Retina and other + * high density displays will have more pixels[] (by a factor of + * pixelDensity^2). + * For example, if the image is 100x100 pixels, there will be 40,000. On a + * retina display, there will be 160,000. + *

+ * The first four values (indices 0-3) in the array will be the R, G, B, A + * values of the pixel at (0, 0). The second four values (indices 4-7) will + * contain the R, G, B, A values of the pixel at (1, 0). More generally, to + * set values for a pixel at (x, y): + * ```javascript + * let d = pixelDensity(); + * for (let i = 0; i < d; i++) { + * for (let j = 0; j < d; j++) { + * // loop over + * index = 4 * ((y * d + j) * width * d + (x * d + i)); + * pixels[index] = r; + * pixels[index+1] = g; + * pixels[index+2] = b; + * pixels[index+3] = a; + * } + * } + * ``` + *

While the above method is complex, it is flexible enough to work with + * any pixelDensity. Note that set() will automatically take care of + * setting all the appropriate values in pixels[] for a given (x, y) at + * any pixelDensity, but the performance may not be as fast when lots of + * modifications are made to the pixel array. + *

+ * Before accessing this array, the data must loaded with the loadPixels() + * function. After the array data has been modified, the updatePixels() + * function must be run to update the changes. + *

+ * Note that this is not a standard javascript array. This means that + * standard javascript functions such as slice() or + * arrayCopy() do not + * work.

+ * + * @property {Number[]} pixels + * @example + *
+ * + * let pink = color(255, 102, 204); + * loadPixels(); + * let d = pixelDensity(); + * let halfImage = 4 * (width * d) * (height / 2 * d); + * for (let i = 0; i < halfImage; i += 4) { + * pixels[i] = red(pink); + * pixels[i + 1] = green(pink); + * pixels[i + 2] = blue(pink); + * pixels[i + 3] = alpha(pink); + * } + * updatePixels(); + * + *
+ * + * @alt + * top half of canvas pink, bottom grey + * + */ + p5.prototype.pixels = []; + + /** + * Copies a region of pixels from one image to another, using a specified + * blend mode to do the operation. + * + * @method blend + * @param {p5.Image} srcImage source image + * @param {Integer} sx X coordinate of the source's upper left corner + * @param {Integer} sy Y coordinate of the source's upper left corner + * @param {Integer} sw source image width + * @param {Integer} sh source image height + * @param {Integer} dx X coordinate of the destination's upper left corner + * @param {Integer} dy Y coordinate of the destination's upper left corner + * @param {Integer} dw destination image width + * @param {Integer} dh destination image height + * @param {Constant} blendMode the blend mode. either + * BLEND, DARKEST, LIGHTEST, DIFFERENCE, + * MULTIPLY, EXCLUSION, SCREEN, REPLACE, OVERLAY, HARD_LIGHT, + * SOFT_LIGHT, DODGE, BURN, ADD or NORMAL. + * + * @example + *
+ * let img0; + * let img1; + * + * function preload() { + * img0 = loadImage('assets/rockies.jpg'); + * img1 = loadImage('assets/bricks_third.jpg'); + * } + * + * function setup() { + * background(img0); + * image(img1, 0, 0); + * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST); + * } + *
+ *
+ * let img0; + * let img1; + * + * function preload() { + * img0 = loadImage('assets/rockies.jpg'); + * img1 = loadImage('assets/bricks_third.jpg'); + * } + * + * function setup() { + * background(img0); + * image(img1, 0, 0); + * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST); + * } + *
+ *
+ * let img0; + * let img1; + * + * function preload() { + * img0 = loadImage('assets/rockies.jpg'); + * img1 = loadImage('assets/bricks_third.jpg'); + * } + * + * function setup() { + * background(img0); + * image(img1, 0, 0); + * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD); + * } + *
+ * + * @alt + * image of rocky mountains. Brick images on left and right. Right overexposed + * image of rockies. Brickwall images on left and right. Right mortar transparent + * image of rockies. Brickwall images on left and right. Right translucent + * + * + */ + /** + * @method blend + * @param {Integer} sx + * @param {Integer} sy + * @param {Integer} sw + * @param {Integer} sh + * @param {Integer} dx + * @param {Integer} dy + * @param {Integer} dw + * @param {Integer} dh + * @param {Constant} blendMode + */ + p5.prototype.blend = function() { + p5._validateParameters('blend', arguments); + if (this._renderer) { + this._renderer.blend.apply(this._renderer, arguments); + } else { + p5.Renderer2D.prototype.blend.apply(this, arguments); + } + }; + + /** + * Copies a region of the canvas to another region of the canvas + * and copies a region of pixels from an image used as the srcImg parameter + * into the canvas srcImage is specified this is used as the source. If + * the source and destination regions aren't the same size, it will + * automatically resize source pixels to fit the specified + * target region. + * + * @method copy + * @param {p5.Image|p5.Element} srcImage source image + * @param {Integer} sx X coordinate of the source's upper left corner + * @param {Integer} sy Y coordinate of the source's upper left corner + * @param {Integer} sw source image width + * @param {Integer} sh source image height + * @param {Integer} dx X coordinate of the destination's upper left corner + * @param {Integer} dy Y coordinate of the destination's upper left corner + * @param {Integer} dw destination image width + * @param {Integer} dh destination image height + * + * @example + *
+ * let img; + * + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * background(img); + * copy(img, 7, 22, 10, 10, 35, 25, 50, 50); + * stroke(255); + * noFill(); + * // Rectangle shows area being copied + * rect(7, 22, 10, 10); + * } + *
+ * + * @alt + * image of rocky mountains. Brick images on left and right. Right overexposed + * image of rockies. Brickwall images on left and right. Right mortar transparent + * image of rockies. Brickwall images on left and right. Right translucent + * + */ + /** + * @method copy + * @param {Integer} sx + * @param {Integer} sy + * @param {Integer} sw + * @param {Integer} sh + * @param {Integer} dx + * @param {Integer} dy + * @param {Integer} dw + * @param {Integer} dh + */ + p5.prototype.copy = function() { + p5._validateParameters('copy', arguments); + p5.Renderer2D.prototype.copy.apply(this._renderer, arguments); + }; + + /** + * Applies a filter to the canvas. + *

+ * + * The presets options are: + *

+ * + * THRESHOLD + * Converts the image to black and white pixels depending if they are above or + * below the threshold defined by the level parameter. The parameter must be + * between 0.0 (black) and 1.0 (white). If no level is specified, 0.5 is used. + *

+ * + * GRAY + * Converts any colors in the image to grayscale equivalents. No parameter + * is used. + *

+ * + * OPAQUE + * Sets the alpha channel to entirely opaque. No parameter is used. + *

+ * + * INVERT + * Sets each pixel to its inverse value. No parameter is used. + *

+ * + * POSTERIZE + * Limits each channel of the image to the number of colors specified as the + * parameter. The parameter can be set to values between 2 and 255, but + * results are most noticeable in the lower ranges. + *

+ * + * BLUR + * Executes a Gaussian blur with the level parameter specifying the extent + * of the blurring. If no parameter is used, the blur is equivalent to + * Gaussian blur of radius 1. Larger values increase the blur. + *

+ * + * ERODE + * Reduces the light areas. No parameter is used. + *

+ * + * DILATE + * Increases the light areas. No parameter is used. + * + * @method filter + * @param {Constant} filterType either THRESHOLD, GRAY, OPAQUE, INVERT, + * POSTERIZE, BLUR, ERODE, DILATE or BLUR. + * See Filters.js for docs on + * each available filter + * @param {Number} [filterParam] an optional parameter unique + * to each filter, see above + * + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * filter(THRESHOLD); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * filter(GRAY); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * filter(OPAQUE); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * filter(INVERT); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * filter(POSTERIZE, 3); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * filter(DILATE); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * filter(BLUR, 3); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/bricks.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * filter(ERODE); + * } + * + *
+ * + * @alt + * black and white image of a brick wall. + * greyscale image of a brickwall + * image of a brickwall + * jade colored image of a brickwall + * red and pink image of a brickwall + * image of a brickwall + * blurry image of a brickwall + * image of a brickwall + * image of a brickwall with less detail + * + */ + p5.prototype.filter = function(operation, value) { + p5._validateParameters('filter', arguments); + if (this.canvas !== undefined) { + Filters.apply(this.canvas, Filters[operation], value); + } else { + Filters.apply(this.elt, Filters[operation], value); + } + }; + + /** + * Get a region of pixels, or a single pixel, from the canvas. + * + * Returns an array of [R,G,B,A] values for any pixel or grabs a section of + * an image. If no parameters are specified, the entire image is returned. + * Use the x and y parameters to get the value of one pixel. Get a section of + * the display window by specifying additional w and h parameters. When + * getting an image, the x and y parameters define the coordinates for the + * upper-left corner of the image, regardless of the current imageMode(). + *

+ * Getting the color of a single pixel with get(x, y) is easy, but not as fast + * as grabbing the data directly from pixels[]. The equivalent statement to + * get(x, y) using pixels[] with pixel density d is + * ```javascript + * let x, y, d; // set these to the coordinates + * let off = (y * width + x) * d * 4; + * let components = [ + * pixels[off], + * pixels[off + 1], + * pixels[off + 2], + * pixels[off + 3] + * ]; + * print(components); + * ``` + *

+ * + * See the reference for pixels[] for more information. + * + * If you want to extract an array of colors or a subimage from an p5.Image object, + * take a look at p5.Image.get() + * + * @method get + * @param {Number} x x-coordinate of the pixel + * @param {Number} y y-coordinate of the pixel + * @param {Number} w width + * @param {Number} h height + * @return {p5.Image} the rectangle p5.Image + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * let c = get(); + * image(c, width / 2, 0); + * } + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + * function setup() { + * image(img, 0, 0); + * let c = get(50, 90); + * fill(c); + * noStroke(); + * rect(25, 25, 50, 50); + * } + * + *
+ * + * @alt + * 2 images of the rocky mountains, side-by-side + * Image of the rocky mountains with 50x50 green rect in center of canvas + * + */ + /** + * @method get + * @return {p5.Image} the whole p5.Image + */ + /** + * @method get + * @param {Number} x + * @param {Number} y + * @return {Number[]} color of pixel at x,y in array format [R, G, B, A] + */ + p5.prototype.get = function(x, y, w, h) { + p5._validateParameters('get', arguments); + return this._renderer.get.apply(this._renderer, arguments); + }; + + /** + * Loads the pixel data for the display window into the pixels[] array. This + * function must always be called before reading from or writing to pixels[]. + * Note that only changes made with set() or direct manipulation of pixels[] + * will occur. + * + * @method loadPixels + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * image(img, 0, 0, width, height); + * let d = pixelDensity(); + * let halfImage = 4 * (width * d) * (height * d / 2); + * loadPixels(); + * for (let i = 0; i < halfImage; i++) { + * pixels[i + halfImage] = pixels[i]; + * } + * updatePixels(); + * } + * + *
+ * + * @alt + * two images of the rocky mountains. one on top, one on bottom of canvas. + * + */ + p5.prototype.loadPixels = function() { + p5._validateParameters('loadPixels', arguments); + this._renderer.loadPixels(); + }; + + /** + *

Changes the color of any pixel, or writes an image directly to the + * display window.

+ *

The x and y parameters specify the pixel to change and the c parameter + * specifies the color value. This can be a p5.Color object, or [R, G, B, A] + * pixel array. It can also be a single grayscale value. + * When setting an image, the x and y parameters define the coordinates for + * the upper-left corner of the image, regardless of the current imageMode(). + *

+ *

+ * After using set(), you must call updatePixels() for your changes to appear. + * This should be called once all pixels have been set, and must be called before + * calling .get() or drawing the image. + *

+ *

Setting the color of a single pixel with set(x, y) is easy, but not as + * fast as putting the data directly into pixels[]. Setting the pixels[] + * values directly may be complicated when working with a retina display, + * but will perform better when lots of pixels need to be set directly on + * every loop.

+ *

See the reference for pixels[] for more information.

+ * + * @method set + * @param {Number} x x-coordinate of the pixel + * @param {Number} y y-coordinate of the pixel + * @param {Number|Number[]|Object} c insert a grayscale value | a pixel array | + * a p5.Color object | a p5.Image to copy + * @example + *
+ * + * let black = color(0); + * set(30, 20, black); + * set(85, 20, black); + * set(85, 75, black); + * set(30, 75, black); + * updatePixels(); + * + *
+ * + *
+ * + * for (let i = 30; i < width - 15; i++) { + * for (let j = 20; j < height - 25; j++) { + * let c = color(204 - j, 153 - i, 0); + * set(i, j, c); + * } + * } + * updatePixels(); + * + *
+ * + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * set(0, 0, img); + * updatePixels(); + * line(0, 0, width, height); + * line(0, height, width, 0); + * } + * + *
+ * + * @alt + * 4 black points in the shape of a square middle-right of canvas. + * square with orangey-brown gradient lightening at bottom right. + * image of the rocky mountains. with lines like an 'x' through the center. + */ + p5.prototype.set = function(x, y, imgOrCol) { + this._renderer.set(x, y, imgOrCol); + }; + /** + * Updates the display window with the data in the pixels[] array. + * Use in conjunction with loadPixels(). If you're only reading pixels from + * the array, there's no need to call updatePixels() — updating is only + * necessary to apply changes. updatePixels() should be called anytime the + * pixels array is manipulated or set() is called, and only changes made with + * set() or direct changes to pixels[] will occur. + * + * @method updatePixels + * @param {Number} [x] x-coordinate of the upper-left corner of region + * to update + * @param {Number} [y] y-coordinate of the upper-left corner of region + * to update + * @param {Number} [w] width of region to update + * @param {Number} [h] height of region to update + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/rockies.jpg'); + * } + * + * function setup() { + * image(img, 0, 0, width, height); + * let d = pixelDensity(); + * let halfImage = 4 * (width * d) * (height * d / 2); + * loadPixels(); + * for (let i = 0; i < halfImage; i++) { + * pixels[i + halfImage] = pixels[i]; + * } + * updatePixels(); + * } + * + *
+ * @alt + * two images of the rocky mountains. one on top, one on bottom of canvas. + */ + p5.prototype.updatePixels = function(x, y, w, h) { + p5._validateParameters('updatePixels', arguments); + // graceful fail - if loadPixels() or set() has not been called, pixel + // array will be empty, ignore call to updatePixels() + if (this.pixels.length === 0) { + return; + } + this._renderer.updatePixels(x, y, w, h); + }; + + module.exports = p5; + }, + { '../color/p5.Color': 16, '../core/main': 24, './filters': 43 } + ], + 48: [ + function(_dereq_, module, exports) { + /** + * @module IO + * @submodule Input + * @for p5 + * @requires core + */ + + /* globals Request: false */ + /* globals Headers: false */ + + 'use strict'; + function _typeof(obj) { + if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { + _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + _typeof = function _typeof(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : typeof obj; + }; + } + return _typeof(obj); + } + + var p5 = _dereq_('../core/main'); + _dereq_('whatwg-fetch'); + _dereq_('es6-promise').polyfill(); + var fetchJsonp = _dereq_('fetch-jsonp'); + _dereq_('../core/error_helpers'); + + /** + * Loads a JSON file from a file or a URL, and returns an Object. + * Note that even if the JSON file contains an Array, an Object will be + * returned with index numbers as keys. + * + * This method is asynchronous, meaning it may not finish before the next + * line in your sketch is executed. JSONP is supported via a polyfill and you + * can pass in as the second argument an object with definitions of the json + * callback following the syntax specified here. + * + * This method is suitable for fetching files up to size of 64MB. + * @method loadJSON + * @param {String} path name of the file or url to load + * @param {Object} [jsonpOptions] options object for jsonp related settings + * @param {String} [datatype] "json" or "jsonp" + * @param {function} [callback] function to be executed after + * loadJSON() completes, data is passed + * in as first argument + * @param {function} [errorCallback] function to be executed if + * there is an error, response is passed + * in as first argument + * @return {Object|Array} JSON data + * @example + * + *

Calling loadJSON() inside preload() guarantees to complete the + * operation before setup() and draw() are called.

+ * + *
+ * // Examples use USGS Earthquake API: + * // https://earthquake.usgs.gov/fdsnws/event/1/#methods + * let earthquakes; + * function preload() { + * // Get the most recent earthquake in the database + * let url = + 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' + + * 'summary/all_day.geojson'; + * earthquakes = loadJSON(url); + * } + * + * function setup() { + * noLoop(); + * } + * + * function draw() { + * background(200); + * // Get the magnitude and name of the earthquake out of the loaded JSON + * let earthquakeMag = earthquakes.features[0].properties.mag; + * let earthquakeName = earthquakes.features[0].properties.place; + * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); + * textAlign(CENTER); + * text(earthquakeName, 0, height - 30, width, 30); + * } + *
+ * + * + *

Outside of preload(), you may supply a callback function to handle the + * object:

+ *
+ * function setup() { + * noLoop(); + * let url = + 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' + + * 'summary/all_day.geojson'; + * loadJSON(url, drawEarthquake); + * } + * + * function draw() { + * background(200); + * } + * + * function drawEarthquake(earthquakes) { + * // Get the magnitude and name of the earthquake out of the loaded JSON + * let earthquakeMag = earthquakes.features[0].properties.mag; + * let earthquakeName = earthquakes.features[0].properties.place; + * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); + * textAlign(CENTER); + * text(earthquakeName, 0, height - 30, width, 30); + * } + *
+ * + * @alt + * 50x50 ellipse that changes from black to white depending on the current humidity + * 50x50 ellipse that changes from black to white depending on the current humidity + * + */ + /** + * @method loadJSON + * @param {String} path + * @param {String} datatype + * @param {function} [callback] + * @param {function} [errorCallback] + * @return {Object|Array} + */ + /** + * @method loadJSON + * @param {String} path + * @param {function} callback + * @param {function} [errorCallback] + * @return {Object|Array} + */ + p5.prototype.loadJSON = function() { + p5._validateParameters('loadJSON', arguments); + var path = arguments[0]; + var callback; + var errorCallback; + var options; + + var ret = {}; // object needed for preload + var t = 'json'; + + // check for explicit data type argument + for (var i = 1; i < arguments.length; i++) { + var arg = arguments[i]; + if (typeof arg === 'string') { + if (arg === 'jsonp' || arg === 'json') { + t = arg; + } + } else if (typeof arg === 'function') { + if (!callback) { + callback = arg; + } else { + errorCallback = arg; + } + } else if ( + _typeof(arg) === 'object' && + (arg.hasOwnProperty('jsonpCallback') || + arg.hasOwnProperty('jsonpCallbackFunction')) + ) { + t = 'jsonp'; + options = arg; + } + } + + var self = this; + this.httpDo( + path, + 'GET', + options, + t, + function(resp) { + for (var k in resp) { + ret[k] = resp[k]; + } + if (typeof callback !== 'undefined') { + callback(resp); + } + + self._decrementPreload(); + }, + function(err) { + // Error handling + p5._friendlyFileLoadError(5, path); + + if (errorCallback) { + errorCallback(err); + } else { + throw err; + } + } + ); + + return ret; + }; + + /** + * Reads the contents of a file and creates a String array of its individual + * lines. If the name of the file is used as the parameter, as in the above + * example, the file must be located in the sketch directory/folder. + *

+ * Alternatively, the file maybe be loaded from anywhere on the local + * computer using an absolute path (something that starts with / on Unix and + * Linux, or a drive letter on Windows), or the filename parameter can be a + * URL for a file found on a network. + *

+ * This method is asynchronous, meaning it may not finish before the next + * line in your sketch is executed. + * + * This method is suitable for fetching files up to size of 64MB. + * @method loadStrings + * @param {String} filename name of the file or url to load + * @param {function} [callback] function to be executed after loadStrings() + * completes, Array is passed in as first + * argument + * @param {function} [errorCallback] function to be executed if + * there is an error, response is passed + * in as first argument + * @return {String[]} Array of Strings + * @example + * + *

Calling loadStrings() inside preload() guarantees to complete the + * operation before setup() and draw() are called.

+ * + *
+ * let result; + * function preload() { + * result = loadStrings('assets/test.txt'); + * } + + * function setup() { + * background(200); + * let ind = floor(random(result.length)); + * text(result[ind], 10, 10, 80, 80); + * } + *
+ * + *

Outside of preload(), you may supply a callback function to handle the + * object:

+ * + *
+ * function setup() { + * loadStrings('assets/test.txt', pickString); + * } + * + * function pickString(result) { + * background(200); + * let ind = floor(random(result.length)); + * text(result[ind], 10, 10, 80, 80); + * } + *
+ * + * @alt + * randomly generated text from a file, for example "i smell like butter" + * randomly generated text from a file, for example "i have three feet" + * + */ + p5.prototype.loadStrings = function() { + p5._validateParameters('loadStrings', arguments); + + var ret = []; + var callback, errorCallback; + + for (var i = 1; i < arguments.length; i++) { + var arg = arguments[i]; + if (typeof arg === 'function') { + if (typeof callback === 'undefined') { + callback = arg; + } else if (typeof errorCallback === 'undefined') { + errorCallback = arg; + } + } + } + + var self = this; + p5.prototype.httpDo.call( + this, + arguments[0], + 'GET', + 'text', + function(data) { + // split lines handling mac/windows/linux endings + var lines = data + .replace(/\r\n/g, '\r') + .replace(/\n/g, '\r') + .split(/\r/); + Array.prototype.push.apply(ret, lines); + + if (typeof callback !== 'undefined') { + callback(ret); + } + + self._decrementPreload(); + }, + function(err) { + // Error handling + p5._friendlyFileLoadError(3, arguments[0]); + + if (errorCallback) { + errorCallback(err); + } else { + throw err; + } + } + ); + + return ret; + }; + + /** + *

Reads the contents of a file or URL and creates a p5.Table object with + * its values. If a file is specified, it must be located in the sketch's + * "data" folder. The filename parameter can also be a URL to a file found + * online. By default, the file is assumed to be comma-separated (in CSV + * format). Table only looks for a header row if the 'header' option is + * included.

+ * + *

Possible options include: + *

    + *
  • csv - parse the table as comma-separated values
  • + *
  • tsv - parse the table as tab-separated values
  • + *
  • header - this table has a header (title) row
  • + *
+ *

+ * + *

When passing in multiple options, pass them in as separate parameters, + * seperated by commas. For example: + *

+ * + * loadTable('my_csv_file.csv', 'csv', 'header'); + * + *

+ * + *

All files loaded and saved use UTF-8 encoding.

+ * + *

This method is asynchronous, meaning it may not finish before the next + * line in your sketch is executed. Calling loadTable() inside preload() + * guarantees to complete the operation before setup() and draw() are called. + *

Outside of preload(), you may supply a callback function to handle the + * object:

+ *

+ * + * This method is suitable for fetching files up to size of 64MB. + * @method loadTable + * @param {String} filename name of the file or URL to load + * @param {String} options "header" "csv" "tsv" + * @param {function} [callback] function to be executed after + * loadTable() completes. On success, the + * Table object is passed in as the + * first argument. + * @param {function} [errorCallback] function to be executed if + * there is an error, response is passed + * in as first argument + * @return {Object} Table object containing data + * + * @example + *
+ * + * // Given the following CSV file called "mammals.csv" + * // located in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * //the file can be remote + * //table = loadTable("http://p5js.org/reference/assets/mammals.csv", + * // "csv", "header"); + * } + * + * function setup() { + * //count the columns + * print(table.getRowCount() + ' total rows in table'); + * print(table.getColumnCount() + ' total columns in table'); + * + * print(table.getColumn('name')); + * //["Goat", "Leopard", "Zebra"] + * + * //cycle through the table + * for (let r = 0; r < table.getRowCount(); r++) + * for (let c = 0; c < table.getColumnCount(); c++) { + * print(table.getString(r, c)); + * } + * } + * + *
+ * + * @alt + * randomly generated text from a file, for example "i smell like butter" + * randomly generated text from a file, for example "i have three feet" + * + */ + /** + * @method loadTable + * @param {String} filename + * @param {function} [callback] + * @param {function} [errorCallback] + * @return {Object} + */ + p5.prototype.loadTable = function(path) { + var callback; + var errorCallback; + var options = []; + var header = false; + var ext = path.substring(path.lastIndexOf('.') + 1, path.length); + var sep = ','; + var separatorSet = false; + + if (ext === 'tsv') { + //Only need to check extension is tsv because csv is default + sep = '\t'; + } + + for (var i = 1; i < arguments.length; i++) { + if (typeof arguments[i] === 'function') { + if (typeof callback === 'undefined') { + callback = arguments[i]; + } else if (typeof errorCallback === 'undefined') { + errorCallback = arguments[i]; + } + } else if (typeof arguments[i] === 'string') { + options.push(arguments[i]); + if (arguments[i] === 'header') { + header = true; + } + if (arguments[i] === 'csv') { + if (separatorSet) { + throw new Error('Cannot set multiple separator types.'); + } else { + sep = ','; + separatorSet = true; + } + } else if (arguments[i] === 'tsv') { + if (separatorSet) { + throw new Error('Cannot set multiple separator types.'); + } else { + sep = '\t'; + separatorSet = true; + } + } + } + } + + var t = new p5.Table(); + + var self = this; + this.httpDo( + path, + 'GET', + 'table', + function(resp) { + var state = {}; + + // define constants + var PRE_TOKEN = 0, + MID_TOKEN = 1, + POST_TOKEN = 2, + POST_RECORD = 4; + + var QUOTE = '"', + CR = '\r', + LF = '\n'; + + var records = []; + var offset = 0; + var currentRecord = null; + var currentChar; + + var tokenBegin = function tokenBegin() { + state.currentState = PRE_TOKEN; + state.token = ''; + }; + + var tokenEnd = function tokenEnd() { + currentRecord.push(state.token); + tokenBegin(); + }; + + var recordBegin = function recordBegin() { + state.escaped = false; + currentRecord = []; + tokenBegin(); + }; + + var recordEnd = function recordEnd() { + state.currentState = POST_RECORD; + records.push(currentRecord); + currentRecord = null; + }; + + for (;;) { + currentChar = resp[offset++]; + + // EOF + if (currentChar == null) { + if (state.escaped) { + throw new Error('Unclosed quote in file.'); + } + if (currentRecord) { + tokenEnd(); + recordEnd(); + break; + } + } + if (currentRecord === null) { + recordBegin(); + } + + // Handle opening quote + if (state.currentState === PRE_TOKEN) { + if (currentChar === QUOTE) { + state.escaped = true; + state.currentState = MID_TOKEN; + continue; + } + state.currentState = MID_TOKEN; + } + + // mid-token and escaped, look for sequences and end quote + if (state.currentState === MID_TOKEN && state.escaped) { + if (currentChar === QUOTE) { + if (resp[offset] === QUOTE) { + state.token += QUOTE; + offset++; + } else { + state.escaped = false; + state.currentState = POST_TOKEN; + } + } else if (currentChar === CR) { + continue; + } else { + state.token += currentChar; + } + continue; + } + + // fall-through: mid-token or post-token, not escaped + if (currentChar === CR) { + if (resp[offset] === LF) { + offset++; + } + tokenEnd(); + recordEnd(); + } else if (currentChar === LF) { + tokenEnd(); + recordEnd(); + } else if (currentChar === sep) { + tokenEnd(); + } else if (state.currentState === MID_TOKEN) { + state.token += currentChar; + } + } + + // set up column names + if (header) { + t.columns = records.shift(); + } else { + for (i = 0; i < records[0].length; i++) { + t.columns[i] = 'null'; + } + } + var row; + for (i = 0; i < records.length; i++) { + //Handles row of 'undefined' at end of some CSVs + if (records[i].length === 1) { + if (records[i][0] === 'undefined' || records[i][0] === '') { + continue; + } + } + row = new p5.TableRow(); + row.arr = records[i]; + row.obj = makeObject(records[i], t.columns); + t.addRow(row); + } + if (typeof callback === 'function') { + callback(t); + } + + self._decrementPreload(); + }, + function(err) { + // Error handling + p5._friendlyFileLoadError(2, path); + + if (errorCallback) { + errorCallback(err); + } else { + console.error(err); + } + } + ); + + return t; + }; + + // helper function to turn a row into a JSON object + function makeObject(row, headers) { + var ret = {}; + headers = headers || []; + if (typeof headers === 'undefined') { + for (var j = 0; j < row.length; j++) { + headers[j.toString()] = j; + } + } + for (var i = 0; i < headers.length; i++) { + var key = headers[i]; + var val = row[i]; + ret[key] = val; + } + return ret; + } + + /** + * Reads the contents of a file and creates an XML object with its values. + * If the name of the file is used as the parameter, as in the above example, + * the file must be located in the sketch directory/folder. + * + * Alternatively, the file maybe be loaded from anywhere on the local + * computer using an absolute path (something that starts with / on Unix and + * Linux, or a drive letter on Windows), or the filename parameter can be a + * URL for a file found on a network. + * + * This method is asynchronous, meaning it may not finish before the next + * line in your sketch is executed. Calling loadXML() inside preload() + * guarantees to complete the operation before setup() and draw() are called. + * + * Outside of preload(), you may supply a callback function to handle the + * object. + * + * This method is suitable for fetching files up to size of 64MB. + * @method loadXML + * @param {String} filename name of the file or URL to load + * @param {function} [callback] function to be executed after loadXML() + * completes, XML object is passed in as + * first argument + * @param {function} [errorCallback] function to be executed if + * there is an error, response is passed + * in as first argument + * @return {Object} XML object containing data + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let children = xml.getChildren('animal'); + * + * for (let i = 0; i < children.length; i++) { + * let id = children[i].getNum('id'); + * let coloring = children[i].getString('species'); + * let name = children[i].getContent(); + * print(id + ', ' + coloring + ', ' + name); + * } + * } + * + * // Sketch prints: + * // 0, Capra hircus, Goat + * // 1, Panthera pardus, Leopard + * // 2, Equus zebra, Zebra + *
+ * + * @alt + * no image displayed + * + */ + p5.prototype.loadXML = function() { + var ret = new p5.XML(); + var callback, errorCallback; + + for (var i = 1; i < arguments.length; i++) { + var arg = arguments[i]; + if (typeof arg === 'function') { + if (typeof callback === 'undefined') { + callback = arg; + } else if (typeof errorCallback === 'undefined') { + errorCallback = arg; + } + } + } + + var self = this; + this.httpDo( + arguments[0], + 'GET', + 'xml', + function(xml) { + for (var key in xml) { + ret[key] = xml[key]; + } + if (typeof callback !== 'undefined') { + callback(ret); + } + + self._decrementPreload(); + }, + function(err) { + // Error handling + p5._friendlyFileLoadError(1, arguments[0]); + + if (errorCallback) { + errorCallback(err); + } else { + throw err; + } + } + ); + + return ret; + }; + + /** + * This method is suitable for fetching files up to size of 64MB. + * @method loadBytes + * @param {string} file name of the file or URL to load + * @param {function} [callback] function to be executed after loadBytes() + * completes + * @param {function} [errorCallback] function to be executed if there + * is an error + * @returns {Object} an object whose 'bytes' property will be the loaded buffer + * + * @example + *
+ * let data; + * + * function preload() { + * data = loadBytes('assets/mammals.xml'); + * } + * + * function setup() { + * for (let i = 0; i < 5; i++) { + * console.log(data.bytes[i].toString(16)); + * } + * } + *
+ * + * @alt + * no image displayed + * + */ + p5.prototype.loadBytes = function(file, callback, errorCallback) { + var ret = {}; + + var self = this; + this.httpDo( + file, + 'GET', + 'arrayBuffer', + function(arrayBuffer) { + ret.bytes = new Uint8Array(arrayBuffer); + + if (typeof callback === 'function') { + callback(ret); + } + + self._decrementPreload(); + }, + function(err) { + // Error handling + p5._friendlyFileLoadError(6, file); + + if (errorCallback) { + errorCallback(err); + } else { + throw err; + } + } + ); + + return ret; + }; + + /** + * Method for executing an HTTP GET request. If data type is not specified, + * p5 will try to guess based on the URL, defaulting to text. This is equivalent to + * calling httpDo(path, 'GET'). The 'binary' datatype will return + * a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer + * which can be used to initialize typed arrays (such as Uint8Array). + * + * @method httpGet + * @param {String} path name of the file or url to load + * @param {String} [datatype] "json", "jsonp", "binary", "arrayBuffer", + * "xml", or "text" + * @param {Object|Boolean} [data] param data passed sent with request + * @param {function} [callback] function to be executed after + * httpGet() completes, data is passed in + * as first argument + * @param {function} [errorCallback] function to be executed if + * there is an error, response is passed + * in as first argument + * @return {Promise} A promise that resolves with the data when the operation + * completes successfully or rejects with the error after + * one occurs. + * @example + *
+ * // Examples use USGS Earthquake API: + * // https://earthquake.usgs.gov/fdsnws/event/1/#methods + * let earthquakes; + * function preload() { + * // Get the most recent earthquake in the database + * let url = + 'https://earthquake.usgs.gov/fdsnws/event/1/query?' + + * 'format=geojson&limit=1&orderby=time'; + * httpGet(url, 'jsonp', false, function(response) { + * // when the HTTP request completes, populate the variable that holds the + * // earthquake data used in the visualization. + * earthquakes = response; + * }); + * } + * + * function draw() { + * if (!earthquakes) { + * // Wait until the earthquake data has loaded before drawing. + * return; + * } + * background(200); + * // Get the magnitude and name of the earthquake out of the loaded JSON + * let earthquakeMag = earthquakes.features[0].properties.mag; + * let earthquakeName = earthquakes.features[0].properties.place; + * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10); + * textAlign(CENTER); + * text(earthquakeName, 0, height - 30, width, 30); + * noLoop(); + * } + *
+ */ + /** + * @method httpGet + * @param {String} path + * @param {Object|Boolean} data + * @param {function} [callback] + * @param {function} [errorCallback] + * @return {Promise} + */ + /** + * @method httpGet + * @param {String} path + * @param {function} callback + * @param {function} [errorCallback] + * @return {Promise} + */ + p5.prototype.httpGet = function() { + p5._validateParameters('httpGet', arguments); + + var args = Array.prototype.slice.call(arguments); + args.splice(1, 0, 'GET'); + return p5.prototype.httpDo.apply(this, args); + }; + + /** + * Method for executing an HTTP POST request. If data type is not specified, + * p5 will try to guess based on the URL, defaulting to text. This is equivalent to + * calling httpDo(path, 'POST'). + * + * @method httpPost + * @param {String} path name of the file or url to load + * @param {String} [datatype] "json", "jsonp", "xml", or "text". + * If omitted, httpPost() will guess. + * @param {Object|Boolean} [data] param data passed sent with request + * @param {function} [callback] function to be executed after + * httpPost() completes, data is passed in + * as first argument + * @param {function} [errorCallback] function to be executed if + * there is an error, response is passed + * in as first argument + * @return {Promise} A promise that resolves with the data when the operation + * completes successfully or rejects with the error after + * one occurs. + * + * @example + *
+ * + * // Examples use jsonplaceholder.typicode.com for a Mock Data API + * + * let url = 'https://jsonplaceholder.typicode.com/posts'; + * let postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is way cool.' }; + * + * function setup() { + * createCanvas(800, 800); + * } + * + * function mousePressed() { + * // Pick new random color values + * let r = random(255); + * let g = random(255); + * let b = random(255); + * + * httpPost(url, 'json', postData, function(result) { + * strokeWeight(2); + * stroke(r, g, b); + * fill(r, g, b, 127); + * ellipse(mouseX, mouseY, 200, 200); + * text(result.body, mouseX, mouseY); + * }); + * } + * + *
+ * + * + *
+ * let url = 'https://invalidURL'; // A bad URL that will cause errors + * let postData = { title: 'p5 Clicked!', body: 'p5.js is way cool.' }; + * + * function setup() { + * createCanvas(800, 800); + * } + * + * function mousePressed() { + * // Pick new random color values + * let r = random(255); + * let g = random(255); + * let b = random(255); + * + * httpPost( + * url, + * 'json', + * postData, + * function(result) { + * // ... won't be called + * }, + * function(error) { + * strokeWeight(2); + * stroke(r, g, b); + * fill(r, g, b, 127); + * text(error.toString(), mouseX, mouseY); + * } + * ); + * } + *
+ * + */ + /** + * @method httpPost + * @param {String} path + * @param {Object|Boolean} data + * @param {function} [callback] + * @param {function} [errorCallback] + * @return {Promise} + */ + /** + * @method httpPost + * @param {String} path + * @param {function} callback + * @param {function} [errorCallback] + * @return {Promise} + */ + p5.prototype.httpPost = function() { + p5._validateParameters('httpPost', arguments); + + var args = Array.prototype.slice.call(arguments); + args.splice(1, 0, 'POST'); + return p5.prototype.httpDo.apply(this, args); + }; + + /** + * Method for executing an HTTP request. If data type is not specified, + * p5 will try to guess based on the URL, defaulting to text.

+ * For more advanced use, you may also pass in the path as the first argument + * and a object as the second argument, the signature follows the one specified + * in the Fetch API specification. + * This method is suitable for fetching files up to size of 64MB when "GET" is used. + * + * @method httpDo + * @param {String} path name of the file or url to load + * @param {String} [method] either "GET", "POST", or "PUT", + * defaults to "GET" + * @param {String} [datatype] "json", "jsonp", "xml", or "text" + * @param {Object} [data] param data passed sent with request + * @param {function} [callback] function to be executed after + * httpGet() completes, data is passed in + * as first argument + * @param {function} [errorCallback] function to be executed if + * there is an error, response is passed + * in as first argument + * @return {Promise} A promise that resolves with the data when the operation + * completes successfully or rejects with the error after + * one occurs. + * + * @example + *
+ * + * // Examples use USGS Earthquake API: + * // https://earthquake.usgs.gov/fdsnws/event/1/#methods + * + * // displays an animation of all USGS earthquakes + * let earthquakes; + * let eqFeatureIndex = 0; + * + * function preload() { + * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson'; + * httpDo( + * url, + * { + * method: 'GET', + * // Other Request options, like special headers for apis + * headers: { authorization: 'Bearer secretKey' } + * }, + * function(res) { + * earthquakes = res; + * } + * ); + * } + * + * function draw() { + * // wait until the data is loaded + * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) { + * return; + * } + * clear(); + * + * let feature = earthquakes.features[eqFeatureIndex]; + * let mag = feature.properties.mag; + * let rad = mag / 11 * ((width + height) / 2); + * fill(255, 0, 0, 100); + * ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad); + * + * if (eqFeatureIndex >= earthquakes.features.length) { + * eqFeatureIndex = 0; + * } else { + * eqFeatureIndex += 1; + * } + * } + * + *
+ */ + /** + * @method httpDo + * @param {String} path + * @param {Object} options Request object options as documented in the + * "fetch" API + * reference + * @param {function} [callback] + * @param {function} [errorCallback] + * @return {Promise} + */ + p5.prototype.httpDo = function() { + var type; + var callback; + var errorCallback; + var request; + var promise; + var jsonpOptions = {}; + var cbCount = 0; + var contentType = 'text/plain'; + // Trim the callbacks off the end to get an idea of how many arguments are passed + for (var i = arguments.length - 1; i > 0; i--) { + if (typeof arguments[i] === 'function') { + cbCount++; + } else { + break; + } + } + // The number of arguments minus callbacks + var argsCount = arguments.length - cbCount; + var path = arguments[0]; + if ( + argsCount === 2 && + typeof path === 'string' && + _typeof(arguments[1]) === 'object' + ) { + // Intended for more advanced use, pass in Request parameters directly + request = new Request(path, arguments[1]); + callback = arguments[2]; + errorCallback = arguments[3]; + } else { + // Provided with arguments + var method = 'GET'; + var data; + + for (var j = 1; j < arguments.length; j++) { + var a = arguments[j]; + if (typeof a === 'string') { + if (a === 'GET' || a === 'POST' || a === 'PUT' || a === 'DELETE') { + method = a; + } else if ( + a === 'json' || + a === 'jsonp' || + a === 'binary' || + a === 'arrayBuffer' || + a === 'xml' || + a === 'text' || + a === 'table' + ) { + type = a; + } else { + data = a; + } + } else if (typeof a === 'number') { + data = a.toString(); + } else if (_typeof(a) === 'object') { + if ( + a.hasOwnProperty('jsonpCallback') || + a.hasOwnProperty('jsonpCallbackFunction') + ) { + for (var attr in a) { + jsonpOptions[attr] = a[attr]; + } + } else if (a instanceof p5.XML) { + data = a.serialize(); + contentType = 'application/xml'; + } else { + data = JSON.stringify(a); + contentType = 'application/json'; + } + } else if (typeof a === 'function') { + if (!callback) { + callback = a; + } else { + errorCallback = a; + } + } + } + + request = new Request(path, { + method: method, + mode: 'cors', + body: data, + headers: new Headers({ + 'Content-Type': contentType + }) + }); + } + // do some sort of smart type checking + if (!type) { + if (path.indexOf('json') !== -1) { + type = 'json'; + } else if (path.indexOf('xml') !== -1) { + type = 'xml'; + } else { + type = 'text'; + } + } + + if (type === 'jsonp') { + promise = fetchJsonp(path, jsonpOptions); + } else { + promise = fetch(request); + } + promise = promise.then(function(res) { + if (!res.ok) { + var err = new Error(res.body); + err.status = res.status; + err.ok = false; + throw err; + } else { + var fileSize = 0; + if (type !== 'jsonp') { + fileSize = res.headers.get('content-length'); + } + if (fileSize && fileSize > 64000000) { + p5._friendlyFileLoadError(7, path); + } + switch (type) { + case 'json': + case 'jsonp': + return res.json(); + case 'binary': + return res.blob(); + case 'arrayBuffer': + return res.arrayBuffer(); + case 'xml': + return res.text().then(function(text) { + var parser = new DOMParser(); + var xml = parser.parseFromString(text, 'text/xml'); + return new p5.XML(xml.documentElement); + }); + default: + return res.text(); + } + } + }); + promise.then(callback || function() {}); + promise.catch(errorCallback || console.error); + return promise; + }; + + /** + * @module IO + * @submodule Output + * @for p5 + */ + + window.URL = window.URL || window.webkitURL; + + // private array of p5.PrintWriter objects + p5.prototype._pWriters = []; + + /** + * @method createWriter + * @param {String} name name of the file to be created + * @param {String} [extension] + * @return {p5.PrintWriter} + * @example + *
+ * + * function setup() { + * createCanvas(100, 100); + * background(200); + * text('click here to save', 10, 10, 70, 80); + * } + * + * function mousePressed() { + * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + * var writer = createWriter('squares.txt'); + * for (let i = 0; i < 10; i++) { + * writer.print(i * i); + * } + * writer.close(); + * writer.clear(); + * } + * } + * + *
+ */ + p5.prototype.createWriter = function(name, extension) { + var newPW; + // check that it doesn't already exist + for (var i in p5.prototype._pWriters) { + if (p5.prototype._pWriters[i].name === name) { + // if a p5.PrintWriter w/ this name already exists... + // return p5.prototype._pWriters[i]; // return it w/ contents intact. + // or, could return a new, empty one with a unique name: + newPW = new p5.PrintWriter(name + this.millis(), extension); + p5.prototype._pWriters.push(newPW); + return newPW; + } + } + newPW = new p5.PrintWriter(name, extension); + p5.prototype._pWriters.push(newPW); + return newPW; + }; + + /** + * @class p5.PrintWriter + * @param {String} filename + * @param {String} [extension] + */ + p5.PrintWriter = function(filename, extension) { + var self = this; + this.name = filename; + this.content = ''; + //Changed to write because it was being overloaded by function below. + /** + * Writes data to the PrintWriter stream + * @method write + * @param {Array} data all data to be written by the PrintWriter + * @example + *
+ * + * // creates a file called 'newFile.txt' + * let writer = createWriter('newFile.txt'); + * // write 'Hello world!'' to the file + * writer.write(['Hello world!']); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ *
+ * + * // creates a file called 'newFile2.txt' + * let writer = createWriter('newFile2.txt'); + * // write 'apples,bananas,123' to the file + * writer.write(['apples', 'bananas', 123]); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ *
+ * + * // creates a file called 'newFile3.txt' + * let writer = createWriter('newFile3.txt'); + * // write 'My name is: Teddy' to the file + * writer.write('My name is:'); + * writer.write(' Teddy'); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ */ + this.write = function(data) { + this.content += data; + }; + /** + * Writes data to the PrintWriter stream, and adds a new line at the end + * @method print + * @param {Array} data all data to be printed by the PrintWriter + * @example + *
+ * + * // creates a file called 'newFile.txt' + * let writer = createWriter('newFile.txt'); + * // creates a file containing + * // My name is: + * // Teddy + * writer.print('My name is:'); + * writer.print('Teddy'); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ *
+ * + * let writer; + * + * function setup() { + * createCanvas(400, 400); + * // create a PrintWriter + * writer = createWriter('newFile.txt'); + * } + * + * function draw() { + * // print all mouseX and mouseY coordinates to the stream + * writer.print([mouseX, mouseY]); + * } + * + * function mouseClicked() { + * // close the PrintWriter and save the file + * writer.close(); + * } + * + *
+ */ + this.print = function(data) { + this.content += data + '\n'; + }; + /** + * Clears the data already written to the PrintWriter object + * @method clear + * @example + *
+ * // create writer object + * let writer = createWriter('newFile.txt'); + * writer.write(['clear me']); + * // clear writer object here + * writer.clear(); + * // close writer + * writer.close(); + *
+ * + */ + this.clear = function() { + this.content = ''; + }; + /** + * Closes the PrintWriter + * @method close + * @example + *
+ * + * // create a file called 'newFile.txt' + * let writer = createWriter('newFile.txt'); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ *
+ * + * // create a file called 'newFile2.txt' + * let writer = createWriter('newFile2.txt'); + * // write some data to the file + * writer.write([100, 101, 102]); + * // close the PrintWriter and save the file + * writer.close(); + * + *
+ */ + this.close = function() { + // convert String to Array for the writeFile Blob + var arr = []; + arr.push(this.content); + p5.prototype.writeFile(arr, filename, extension); + // remove from _pWriters array and delete self + for (var i in p5.prototype._pWriters) { + if (p5.prototype._pWriters[i].name === this.name) { + // remove from _pWriters array + p5.prototype._pWriters.splice(i, 1); + } + } + self.clear(); + self = {}; + }; + }; + + /** + * @module IO + * @submodule Output + * @for p5 + */ + + // object, filename, options --> saveJSON, saveStrings, + // filename, [extension] [canvas] --> saveImage + + /** + *

Save an image, text, json, csv, wav, or html. Prompts download to + * the client's computer. Note that it is not recommended to call save() + * within draw if it's looping, as the save() function will open a new save + * dialog every frame.

+ *

The default behavior is to save the canvas as an image. You can + * optionally specify a filename. + * For example:

+ *

+           * save();
+           * save('myCanvas.jpg'); // save a specific canvas with a filename
+           * 
+ * + *

Alternately, the first parameter can be a pointer to a canvas + * p5.Element, an Array of Strings, + * an Array of JSON, a JSON object, a p5.Table, a p5.Image, or a + * p5.SoundFile (requires p5.sound). The second parameter is a filename + * (including extension). The third parameter is for options specific + * to this type of object. This method will save a file that fits the + * given parameters. For example:

+ * + *

+           * // Saves canvas as an image
+           * save('myCanvas.jpg');
+           *
+           * // Saves pImage as a png image
+           * let img = createImage(10, 10);
+           * save(img, 'my.png');
+           *
+           * // Saves canvas as an image
+           * let cnv = createCanvas(100, 100);
+           * save(cnv, 'myCanvas.jpg');
+           *
+           * // Saves p5.Renderer object as an image
+           * let gb = createGraphics(100, 100);
+           * save(gb, 'myGraphics.jpg');
+           *
+           * let myTable = new p5.Table();
+           *
+           * // Saves table as html file
+           * save(myTable, 'myTable.html');
+           *
+           * // Comma Separated Values
+           * save(myTable, 'myTable.csv');
+           *
+           * // Tab Separated Values
+           * save(myTable, 'myTable.tsv');
+           *
+           * let myJSON = { a: 1, b: true };
+           *
+           * // Saves pretty JSON
+           * save(myJSON, 'my.json');
+           *
+           * // Optimizes JSON filesize
+           * save(myJSON, 'my.json', true);
+           *
+           * // Saves array of strings to a text file with line breaks after each item
+           * let arrayOfStrings = ['a', 'b'];
+           * save(arrayOfStrings, 'my.txt');
+           * 
+ * + * @method save + * @param {Object|String} [objectOrFilename] If filename is provided, will + * save canvas as an image with + * either png or jpg extension + * depending on the filename. + * If object is provided, will + * save depending on the object + * and filename (see examples + * above). + * @param {String} [filename] If an object is provided as the first + * parameter, then the second parameter + * indicates the filename, + * and should include an appropriate + * file extension (see examples above). + * @param {Boolean|String} [options] Additional options depend on + * filetype. For example, when saving JSON, + * true indicates that the + * output will be optimized for filesize, + * rather than readability. + */ + p5.prototype.save = function(object, _filename, _options) { + // parse the arguments and figure out which things we are saving + var args = arguments; + // ================================================= + // OPTION 1: saveCanvas... + + // if no arguments are provided, save canvas + var cnv = this._curElement ? this._curElement.elt : this.elt; + if (args.length === 0) { + p5.prototype.saveCanvas(cnv); + return; + } else if (args[0] instanceof p5.Renderer || args[0] instanceof p5.Graphics) { + // otherwise, parse the arguments + + // if first param is a p5Graphics, then saveCanvas + p5.prototype.saveCanvas(args[0].elt, args[1], args[2]); + return; + } else if (args.length === 1 && typeof args[0] === 'string') { + // if 1st param is String and only one arg, assume it is canvas filename + p5.prototype.saveCanvas(cnv, args[0]); + } else { + // ================================================= + // OPTION 2: extension clarifies saveStrings vs. saveJSON + var extension = _checkFileExtension(args[1], args[2])[1]; + switch (extension) { + case 'json': + p5.prototype.saveJSON(args[0], args[1], args[2]); + return; + case 'txt': + p5.prototype.saveStrings(args[0], args[1], args[2]); + return; + // ================================================= + // OPTION 3: decide based on object... + default: + if (args[0] instanceof Array) { + p5.prototype.saveStrings(args[0], args[1], args[2]); + } else if (args[0] instanceof p5.Table) { + p5.prototype.saveTable(args[0], args[1], args[2]); + } else if (args[0] instanceof p5.Image) { + p5.prototype.saveCanvas(args[0].canvas, args[1]); + } else if (args[0] instanceof p5.SoundFile) { + p5.prototype.saveSound(args[0], args[1], args[2], args[3]); + } + } + } + }; + + /** + * Writes the contents of an Array or a JSON object to a .json file. + * The file saving process and location of the saved file will + * vary between web browsers. + * + * @method saveJSON + * @param {Array|Object} json + * @param {String} filename + * @param {Boolean} [optimize] If true, removes line breaks + * and spaces from the output + * file to optimize filesize + * (but not readability). + * @example + *
+ * let json = {}; // new JSON Object + * + * json.id = 0; + * json.species = 'Panthera leo'; + * json.name = 'Lion'; + * + * function setup() { + * createCanvas(100, 100); + * background(200); + * text('click here to save', 10, 10, 70, 80); + * } + * + * function mousePressed() { + * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + * saveJSON(json, 'lion.json'); + * } + * } + * + * // saves the following to a file called "lion.json": + * // { + * // "id": 0, + * // "species": "Panthera leo", + * // "name": "Lion" + * // } + *
+ * + * @alt + * no image displayed + * + */ + p5.prototype.saveJSON = function(json, filename, opt) { + p5._validateParameters('saveJSON', arguments); + var stringify; + if (opt) { + stringify = JSON.stringify(json); + } else { + stringify = JSON.stringify(json, undefined, 2); + } + this.saveStrings(stringify.split('\n'), filename, 'json'); + }; + + p5.prototype.saveJSONObject = p5.prototype.saveJSON; + p5.prototype.saveJSONArray = p5.prototype.saveJSON; + + /** + * Writes an array of Strings to a text file, one line per String. + * The file saving process and location of the saved file will + * vary between web browsers. + * + * @method saveStrings + * @param {String[]} list string array to be written + * @param {String} filename filename for output + * @param {String} [extension] the filename's extension + * @example + *
+ * let words = 'apple bear cat dog'; + * + * // .split() outputs an Array + * let list = split(words, ' '); + * + * function setup() { + * createCanvas(100, 100); + * background(200); + * text('click here to save', 10, 10, 70, 80); + * } + * + * function mousePressed() { + * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) { + * saveStrings(list, 'nouns.txt'); + * } + * } + * + * // Saves the following to a file called 'nouns.txt': + * // + * // apple + * // bear + * // cat + * // dog + *
+ * + * @alt + * no image displayed + * + */ + p5.prototype.saveStrings = function(list, filename, extension) { + p5._validateParameters('saveStrings', arguments); + var ext = extension || 'txt'; + var pWriter = this.createWriter(filename, ext); + for (var i = 0; i < list.length; i++) { + if (i < list.length - 1) { + pWriter.print(list[i]); + } else { + pWriter.print(list[i]); + } + } + pWriter.close(); + pWriter.clear(); + }; + + // ======= + // HELPERS + // ======= + + function escapeHelper(content) { + return content + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + } + + /** + * Writes the contents of a Table object to a file. Defaults to a + * text file with comma-separated-values ('csv') but can also + * use tab separation ('tsv'), or generate an HTML table ('html'). + * The file saving process and location of the saved file will + * vary between web browsers. + * + * @method saveTable + * @param {p5.Table} Table the Table object to save to a file + * @param {String} filename the filename to which the Table should be saved + * @param {String} [options] can be one of "tsv", "csv", or "html" + * @example + *
+ * let table; + * + * function setup() { + * table = new p5.Table(); + * + * table.addColumn('id'); + * table.addColumn('species'); + * table.addColumn('name'); + * + * let newRow = table.addRow(); + * newRow.setNum('id', table.getRowCount() - 1); + * newRow.setString('species', 'Panthera leo'); + * newRow.setString('name', 'Lion'); + * + * // To save, un-comment next line then click 'run' + * // saveTable(table, 'new.csv'); + * } + * + * // Saves the following to a file called 'new.csv': + * // id,species,name + * // 0,Panthera leo,Lion + *
+ * + * @alt + * no image displayed + * + */ + p5.prototype.saveTable = function(table, filename, options) { + p5._validateParameters('saveTable', arguments); + var ext; + if (options === undefined) { + ext = filename.substring(filename.lastIndexOf('.') + 1, filename.length); + } else { + ext = options; + } + var pWriter = this.createWriter(filename, ext); + + var header = table.columns; + + var sep = ','; // default to CSV + if (ext === 'tsv') { + sep = '\t'; + } + if (ext !== 'html') { + // make header if it has values + if (header[0] !== '0') { + for (var h = 0; h < header.length; h++) { + if (h < header.length - 1) { + pWriter.write(header[h] + sep); + } else { + pWriter.write(header[h]); + } + } + pWriter.write('\n'); + } + + // make rows + for (var i = 0; i < table.rows.length; i++) { + var j; + for (j = 0; j < table.rows[i].arr.length; j++) { + if (j < table.rows[i].arr.length - 1) { + pWriter.write(table.rows[i].arr[j] + sep); + } else if (i < table.rows.length - 1) { + pWriter.write(table.rows[i].arr[j]); + } else { + pWriter.write(table.rows[i].arr[j]); + } + } + pWriter.write('\n'); + } + } else { + // otherwise, make HTML + pWriter.print(''); + pWriter.print(''); + var str = ' '); + + pWriter.print(''); + pWriter.print(' '); + + // make header if it has values + if (header[0] !== '0') { + pWriter.print(' '); + for (var k = 0; k < header.length; k++) { + var e = escapeHelper(header[k]); + pWriter.print(' '); + } + pWriter.print(' '); + } + + // make rows + for (var row = 0; row < table.rows.length; row++) { + pWriter.print(' '); + for (var col = 0; col < table.columns.length; col++) { + var entry = table.rows[row].getString(col); + var htmlEntry = escapeHelper(entry); + pWriter.print(' '); + } + pWriter.print(' '); + } + pWriter.print('
' + e); + pWriter.print('
' + htmlEntry); + pWriter.print('
'); + pWriter.print(''); + pWriter.print(''); + } + // close and clear the pWriter + pWriter.close(); + pWriter.clear(); + }; // end saveTable() + + /** + * Generate a blob of file data as a url to prepare for download. + * Accepts an array of data, a filename, and an extension (optional). + * This is a private function because it does not do any formatting, + * but it is used by saveStrings, saveJSON, saveTable etc. + * + * @param {Array} dataToDownload + * @param {String} filename + * @param {String} [extension] + * @private + */ + p5.prototype.writeFile = function(dataToDownload, filename, extension) { + var type = 'application/octet-stream'; + if (p5.prototype._isSafari()) { + type = 'text/plain'; + } + var blob = new Blob(dataToDownload, { + type: type + }); + + p5.prototype.downloadFile(blob, filename, extension); + }; + + /** + * Forces download. Accepts a url to filedata/blob, a filename, + * and an extension (optional). + * This is a private function because it does not do any formatting, + * but it is used by saveStrings, saveJSON, saveTable etc. + * + * @method downloadFile + * @private + * @param {String|Blob} data either an href generated by createObjectURL, + * or a Blob object containing the data + * @param {String} [filename] + * @param {String} [extension] + */ + p5.prototype.downloadFile = function(data, fName, extension) { + var fx = _checkFileExtension(fName, extension); + var filename = fx[0]; + + if (data instanceof Blob) { + var fileSaver = _dereq_('file-saver'); + fileSaver.saveAs(data, filename); + return; + } + + var a = document.createElement('a'); + a.href = data; + a.download = filename; + + // Firefox requires the link to be added to the DOM before click() + a.onclick = function(e) { + destroyClickedElement(e); + e.stopPropagation(); + }; + + a.style.display = 'none'; + document.body.appendChild(a); + + // Safari will open this file in the same page as a confusing Blob. + if (p5.prototype._isSafari()) { + var aText = 'Hello, Safari user! To download this file...\n'; + aText += '1. Go to File --> Save As.\n'; + aText += '2. Choose "Page Source" as the Format.\n'; + aText += '3. Name it with this extension: ."' + fx[1] + '"'; + alert(aText); + } + a.click(); + }; + + /** + * Returns a file extension, or another string + * if the provided parameter has no extension. + * + * @param {String} filename + * @param {String} [extension] + * @return {String[]} [fileName, fileExtension] + * + * @private + */ + function _checkFileExtension(filename, extension) { + if (!extension || extension === true || extension === 'true') { + extension = ''; + } + if (!filename) { + filename = 'untitled'; + } + var ext = ''; + // make sure the file will have a name, see if filename needs extension + if (filename && filename.indexOf('.') > -1) { + ext = filename.split('.').pop(); + } + // append extension if it doesn't exist + if (extension) { + if (ext !== extension) { + ext = extension; + filename = filename + '.' + ext; + } + } + return [filename, ext]; + } + p5.prototype._checkFileExtension = _checkFileExtension; + + /** + * Returns true if the browser is Safari, false if not. + * Safari makes trouble for downloading files. + * + * @return {Boolean} [description] + * @private + */ + p5.prototype._isSafari = function() { + var x = Object.prototype.toString.call(window.HTMLElement); + return x.indexOf('Constructor') > 0; + }; + + /** + * Helper function, a callback for download that deletes + * an invisible anchor element from the DOM once the file + * has been automatically downloaded. + * + * @private + */ + function destroyClickedElement(event) { + document.body.removeChild(event.target); + } + + module.exports = p5; + }, + { + '../core/error_helpers': 20, + '../core/main': 24, + 'es6-promise': 5, + 'fetch-jsonp': 6, + 'file-saver': 7, + 'whatwg-fetch': 12 + } + ], + 49: [ + function(_dereq_, module, exports) { + /** + * @module IO + * @submodule Table + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * Table Options + *

Generic class for handling tabular data, typically from a + * CSV, TSV, or other sort of spreadsheet file.

+ *

CSV files are + * + * comma separated values, often with the data in quotes. TSV + * files use tabs as separators, and usually don't bother with the + * quotes.

+ *

File names should end with .csv if they're comma separated.

+ *

A rough "spec" for CSV can be found + * here.

+ *

To load files, use the loadTable method.

+ *

To save tables to your computer, use the save method + * or the saveTable method.

+ * + * Possible options include: + *
    + *
  • csv - parse the table as comma-separated values + *
  • tsv - parse the table as tab-separated values + *
  • header - this table has a header (title) row + *
+ */ + + /** + * Table objects store data with multiple rows and columns, much + * like in a traditional spreadsheet. Tables can be generated from + * scratch, dynamically, or using data from an existing file. + * + * @class p5.Table + * @constructor + * @param {p5.TableRow[]} [rows] An array of p5.TableRow objects + */ + p5.Table = function(rows) { + /** + * @property columns {String[]} + */ + this.columns = []; + + /** + * @property rows {p5.TableRow[]} + */ + this.rows = []; + }; + + /** + * Use addRow() to add a new row of data to a p5.Table object. By default, + * an empty row is created. Typically, you would store a reference to + * the new row in a TableRow object (see newRow in the example above), + * and then set individual values using set(). + * + * If a p5.TableRow object is included as a parameter, then that row is + * duplicated and added to the table. + * + * @method addRow + * @param {p5.TableRow} [row] row to be added to the table + * @return {p5.TableRow} the row that was added + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * //add a row + * let newRow = table.addRow(); + * newRow.setString('id', table.getRowCount() - 1); + * newRow.setString('species', 'Canis Lupus'); + * newRow.setString('name', 'Wolf'); + * + * //print the results + * for (let r = 0; r < table.getRowCount(); r++) + * for (let c = 0; c < table.getColumnCount(); c++) + * print(table.getString(r, c)); + * } + * + *
+ * + * @alt + * no image displayed + * + */ + p5.Table.prototype.addRow = function(row) { + // make sure it is a valid TableRow + var r = row || new p5.TableRow(); + + if (typeof r.arr === 'undefined' || typeof r.obj === 'undefined') { + //r = new p5.prototype.TableRow(r); + throw new Error('invalid TableRow: ' + r); + } + r.table = this; + this.rows.push(r); + return r; + }; + + /** + * Removes a row from the table object. + * + * @method removeRow + * @param {Integer} id ID number of the row to remove + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * //remove the first row + * table.removeRow(0); + * + * //print the results + * for (let r = 0; r < table.getRowCount(); r++) + * for (let c = 0; c < table.getColumnCount(); c++) + * print(table.getString(r, c)); + * } + * + *
+ * + * @alt + * no image displayed + * + */ + p5.Table.prototype.removeRow = function(id) { + this.rows[id].table = null; // remove reference to table + var chunk = this.rows.splice(id + 1, this.rows.length); + this.rows.pop(); + this.rows = this.rows.concat(chunk); + }; + + /** + * Returns a reference to the specified p5.TableRow. The reference + * can then be used to get and set values of the selected row. + * + * @method getRow + * @param {Integer} rowID ID number of the row to get + * @return {p5.TableRow} p5.TableRow object + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let row = table.getRow(1); + * //print it column by column + * //note: a row is an object, not an array + * for (let c = 0; c < table.getColumnCount(); c++) { + * print(row.getString(c)); + * } + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.getRow = function(r) { + return this.rows[r]; + }; + + /** + * Gets all rows from the table. Returns an array of p5.TableRows. + * + * @method getRows + * @return {p5.TableRow[]} Array of p5.TableRows + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let rows = table.getRows(); + * + * //warning: rows is an array of objects + * for (let r = 0; r < rows.length; r++) { + * rows[r].set('name', 'Unicorn'); + * } + * + * //print the results + * for (let r = 0; r < table.getRowCount(); r++) + * for (let c = 0; c < table.getColumnCount(); c++) + * print(table.getString(r, c)); + * } + * + *
+ * + * @alt + * no image displayed + * + */ + p5.Table.prototype.getRows = function() { + return this.rows; + }; + + /** + * Finds the first row in the Table that contains the value + * provided, and returns a reference to that row. Even if + * multiple rows are possible matches, only the first matching + * row is returned. The column to search may be specified by + * either its ID or title. + * + * @method findRow + * @param {String} value The value to match + * @param {Integer|String} column ID number or title of the + * column to search + * @return {p5.TableRow} + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * //find the animal named zebra + * let row = table.findRow('Zebra', 'name'); + * //find the corresponding species + * print(row.getString('species')); + * } + * + *
+ * + * @alt + * no image displayed + * + */ + p5.Table.prototype.findRow = function(value, column) { + // try the Object + if (typeof column === 'string') { + for (var i = 0; i < this.rows.length; i++) { + if (this.rows[i].obj[column] === value) { + return this.rows[i]; + } + } + } else { + // try the Array + for (var j = 0; j < this.rows.length; j++) { + if (this.rows[j].arr[column] === value) { + return this.rows[j]; + } + } + } + // otherwise... + return null; + }; + + /** + * Finds the rows in the Table that contain the value + * provided, and returns references to those rows. Returns an + * Array, so for must be used to iterate through all the rows, + * as shown in the example above. The column to search may be + * specified by either its ID or title. + * + * @method findRows + * @param {String} value The value to match + * @param {Integer|String} column ID number or title of the + * column to search + * @return {p5.TableRow[]} An Array of TableRow objects + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * //add another goat + * let newRow = table.addRow(); + * newRow.setString('id', table.getRowCount() - 1); + * newRow.setString('species', 'Scape Goat'); + * newRow.setString('name', 'Goat'); + * + * //find the rows containing animals named Goat + * let rows = table.findRows('Goat', 'name'); + * print(rows.length + ' Goats found'); + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.findRows = function(value, column) { + var ret = []; + if (typeof column === 'string') { + for (var i = 0; i < this.rows.length; i++) { + if (this.rows[i].obj[column] === value) { + ret.push(this.rows[i]); + } + } + } else { + // try the Array + for (var j = 0; j < this.rows.length; j++) { + if (this.rows[j].arr[column] === value) { + ret.push(this.rows[j]); + } + } + } + return ret; + }; + + /** + * Finds the first row in the Table that matches the regular + * expression provided, and returns a reference to that row. + * Even if multiple rows are possible matches, only the first + * matching row is returned. The column to search may be + * specified by either its ID or title. + * + * @method matchRow + * @param {String|RegExp} regexp The regular expression to match + * @param {String|Integer} column The column ID (number) or + * title (string) + * @return {p5.TableRow} TableRow object + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * //Search using specified regex on a given column, return TableRow object + * let mammal = table.matchRow(new RegExp('ant'), 1); + * print(mammal.getString(1)); + * //Output "Panthera pardus" + * } + * + *
+ * + */ + p5.Table.prototype.matchRow = function(regexp, column) { + if (typeof column === 'number') { + for (var j = 0; j < this.rows.length; j++) { + if (this.rows[j].arr[column].match(regexp)) { + return this.rows[j]; + } + } + } else { + for (var i = 0; i < this.rows.length; i++) { + if (this.rows[i].obj[column].match(regexp)) { + return this.rows[i]; + } + } + } + return null; + }; + + /** + * Finds the rows in the Table that match the regular expression provided, + * and returns references to those rows. Returns an array, so for must be + * used to iterate through all the rows, as shown in the example. The + * column to search may be specified by either its ID or title. + * + * @method matchRows + * @param {String} regexp The regular expression to match + * @param {String|Integer} [column] The column ID (number) or + * title (string) + * @return {p5.TableRow[]} An Array of TableRow objects + * @example + *
+ * + * let table; + * + * function setup() { + * table = new p5.Table(); + * + * table.addColumn('name'); + * table.addColumn('type'); + * + * let newRow = table.addRow(); + * newRow.setString('name', 'Lion'); + * newRow.setString('type', 'Mammal'); + * + * newRow = table.addRow(); + * newRow.setString('name', 'Snake'); + * newRow.setString('type', 'Reptile'); + * + * newRow = table.addRow(); + * newRow.setString('name', 'Mosquito'); + * newRow.setString('type', 'Insect'); + * + * newRow = table.addRow(); + * newRow.setString('name', 'Lizard'); + * newRow.setString('type', 'Reptile'); + * + * let rows = table.matchRows('R.*', 'type'); + * for (let i = 0; i < rows.length; i++) { + * print(rows[i].getString('name') + ': ' + rows[i].getString('type')); + * } + * } + * // Sketch prints: + * // Snake: Reptile + * // Lizard: Reptile + * + *
+ */ + p5.Table.prototype.matchRows = function(regexp, column) { + var ret = []; + if (typeof column === 'number') { + for (var j = 0; j < this.rows.length; j++) { + if (this.rows[j].arr[column].match(regexp)) { + ret.push(this.rows[j]); + } + } + } else { + for (var i = 0; i < this.rows.length; i++) { + if (this.rows[i].obj[column].match(regexp)) { + ret.push(this.rows[i]); + } + } + } + return ret; + }; + + /** + * Retrieves all values in the specified column, and returns them + * as an array. The column may be specified by either its ID or title. + * + * @method getColumn + * @param {String|Number} column String or Number of the column to return + * @return {Array} Array of column values + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * //getColumn returns an array that can be printed directly + * print(table.getColumn('species')); + * //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"] + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.getColumn = function(value) { + var ret = []; + if (typeof value === 'string') { + for (var i = 0; i < this.rows.length; i++) { + ret.push(this.rows[i].obj[value]); + } + } else { + for (var j = 0; j < this.rows.length; j++) { + ret.push(this.rows[j].arr[value]); + } + } + return ret; + }; + + /** + * Removes all rows from a Table. While all rows are removed, + * columns and column titles are maintained. + * + * @method clearRows + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * table.clearRows(); + * print(table.getRowCount() + ' total rows in table'); + * print(table.getColumnCount() + ' total columns in table'); + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.clearRows = function() { + delete this.rows; + this.rows = []; + }; + + /** + * Use addColumn() to add a new column to a Table object. + * Typically, you will want to specify a title, so the column + * may be easily referenced later by name. (If no title is + * specified, the new column's title will be null.) + * + * @method addColumn + * @param {String} [title] title of the given column + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * table.addColumn('carnivore'); + * table.set(0, 'carnivore', 'no'); + * table.set(1, 'carnivore', 'yes'); + * table.set(2, 'carnivore', 'no'); + * + * //print the results + * for (let r = 0; r < table.getRowCount(); r++) + * for (let c = 0; c < table.getColumnCount(); c++) + * print(table.getString(r, c)); + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.addColumn = function(title) { + var t = title || null; + this.columns.push(t); + }; + + /** + * Returns the total number of columns in a Table. + * + * @method getColumnCount + * @return {Integer} Number of columns in this table + * @example + *
+ * + * // given the cvs file "blobs.csv" in /assets directory + * // ID, Name, Flavor, Shape, Color + * // Blob1, Blobby, Sweet, Blob, Pink + * // Blob2, Saddy, Savory, Blob, Blue + * + * let table; + * + * function preload() { + * table = loadTable('assets/blobs.csv'); + * } + * + * function setup() { + * createCanvas(200, 100); + * textAlign(CENTER); + * background(255); + * } + * + * function draw() { + * let numOfColumn = table.getColumnCount(); + * text('There are ' + numOfColumn + ' columns in the table.', 100, 50); + * } + * + *
+ */ + p5.Table.prototype.getColumnCount = function() { + return this.columns.length; + }; + + /** + * Returns the total number of rows in a Table. + * + * @method getRowCount + * @return {Integer} Number of rows in this table + * @example + *
+ * + * // given the cvs file "blobs.csv" in /assets directory + * // + * // ID, Name, Flavor, Shape, Color + * // Blob1, Blobby, Sweet, Blob, Pink + * // Blob2, Saddy, Savory, Blob, Blue + * + * let table; + * + * function preload() { + * table = loadTable('assets/blobs.csv'); + * } + * + * function setup() { + * createCanvas(200, 100); + * textAlign(CENTER); + * background(255); + * } + * + * function draw() { + * text('There are ' + table.getRowCount() + ' rows in the table.', 100, 50); + * } + * + *
+ */ + p5.Table.prototype.getRowCount = function() { + return this.rows.length; + }; + + /** + *

Removes any of the specified characters (or "tokens").

+ * + *

If no column is specified, then the values in all columns and + * rows are processed. A specific column may be referenced by + * either its ID or title.

+ * + * @method removeTokens + * @param {String} chars String listing characters to be removed + * @param {String|Integer} [column] Column ID (number) + * or name (string) + * + * @example + *
+ * function setup() { + * let table = new p5.Table(); + * + * table.addColumn('name'); + * table.addColumn('type'); + * + * let newRow = table.addRow(); + * newRow.setString('name', ' $Lion ,'); + * newRow.setString('type', ',,,Mammal'); + * + * newRow = table.addRow(); + * newRow.setString('name', '$Snake '); + * newRow.setString('type', ',,,Reptile'); + * + * table.removeTokens(',$ '); + * print(table.getArray()); + * } + * + * // prints: + * // 0 "Lion" "Mamal" + * // 1 "Snake" "Reptile" + *
+ */ + p5.Table.prototype.removeTokens = function(chars, column) { + var escape = function escape(s) { + return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); + }; + var charArray = []; + for (var i = 0; i < chars.length; i++) { + charArray.push(escape(chars.charAt(i))); + } + var regex = new RegExp(charArray.join('|'), 'g'); + + if (typeof column === 'undefined') { + for (var c = 0; c < this.columns.length; c++) { + for (var d = 0; d < this.rows.length; d++) { + var s = this.rows[d].arr[c]; + s = s.replace(regex, ''); + this.rows[d].arr[c] = s; + this.rows[d].obj[this.columns[c]] = s; + } + } + } else if (typeof column === 'string') { + for (var j = 0; j < this.rows.length; j++) { + var val = this.rows[j].obj[column]; + val = val.replace(regex, ''); + this.rows[j].obj[column] = val; + var pos = this.columns.indexOf(column); + this.rows[j].arr[pos] = val; + } + } else { + for (var k = 0; k < this.rows.length; k++) { + var str = this.rows[k].arr[column]; + str = str.replace(regex, ''); + this.rows[k].arr[column] = str; + this.rows[k].obj[this.columns[column]] = str; + } + } + }; + + /** + * Trims leading and trailing whitespace, such as spaces and tabs, + * from String table values. If no column is specified, then the + * values in all columns and rows are trimmed. A specific column + * may be referenced by either its ID or title. + * + * @method trim + * @param {String|Integer} [column] Column ID (number) + * or name (string) + * @example + *
+ * function setup() { + * let table = new p5.Table(); + * + * table.addColumn('name'); + * table.addColumn('type'); + * + * let newRow = table.addRow(); + * newRow.setString('name', ' Lion ,'); + * newRow.setString('type', ' Mammal '); + * + * newRow = table.addRow(); + * newRow.setString('name', ' Snake '); + * newRow.setString('type', ' Reptile '); + * + * table.trim(); + * print(table.getArray()); + * } + * + * // prints: + * // 0 "Lion" "Mamal" + * // 1 "Snake" "Reptile" + *
+ */ + p5.Table.prototype.trim = function(column) { + var regex = new RegExp(' ', 'g'); + + if (typeof column === 'undefined') { + for (var c = 0; c < this.columns.length; c++) { + for (var d = 0; d < this.rows.length; d++) { + var s = this.rows[d].arr[c]; + s = s.replace(regex, ''); + this.rows[d].arr[c] = s; + this.rows[d].obj[this.columns[c]] = s; + } + } + } else if (typeof column === 'string') { + for (var j = 0; j < this.rows.length; j++) { + var val = this.rows[j].obj[column]; + val = val.replace(regex, ''); + this.rows[j].obj[column] = val; + var pos = this.columns.indexOf(column); + this.rows[j].arr[pos] = val; + } + } else { + for (var k = 0; k < this.rows.length; k++) { + var str = this.rows[k].arr[column]; + str = str.replace(regex, ''); + this.rows[k].arr[column] = str; + this.rows[k].obj[this.columns[column]] = str; + } + } + }; + + /** + * Use removeColumn() to remove an existing column from a Table + * object. The column to be removed may be identified by either + * its title (a String) or its index value (an int). + * removeColumn(0) would remove the first column, removeColumn(1) + * would remove the second column, and so on. + * + * @method removeColumn + * @param {String|Integer} column columnName (string) or ID (number) + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * table.removeColumn('id'); + * print(table.getColumnCount()); + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.removeColumn = function(c) { + var cString; + var cNumber; + if (typeof c === 'string') { + // find the position of c in the columns + cString = c; + cNumber = this.columns.indexOf(c); + } else { + cNumber = c; + cString = this.columns[c]; + } + + var chunk = this.columns.splice(cNumber + 1, this.columns.length); + this.columns.pop(); + this.columns = this.columns.concat(chunk); + + for (var i = 0; i < this.rows.length; i++) { + var tempR = this.rows[i].arr; + var chip = tempR.splice(cNumber + 1, tempR.length); + tempR.pop(); + this.rows[i].arr = tempR.concat(chip); + delete this.rows[i].obj[cString]; + } + }; + + /** + * Stores a value in the Table's specified row and column. + * The row is specified by its ID, while the column may be specified + * by either its ID or title. + * + * @method set + * @param {Integer} row row ID + * @param {String|Integer} column column ID (Number) + * or title (String) + * @param {String|Number} value value to assign + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * table.set(0, 'species', 'Canis Lupus'); + * table.set(0, 'name', 'Wolf'); + * + * //print the results + * for (let r = 0; r < table.getRowCount(); r++) + * for (let c = 0; c < table.getColumnCount(); c++) + * print(table.getString(r, c)); + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.set = function(row, column, value) { + this.rows[row].set(column, value); + }; + + /** + * Stores a Float value in the Table's specified row and column. + * The row is specified by its ID, while the column may be specified + * by either its ID or title. + * + * @method setNum + * @param {Integer} row row ID + * @param {String|Integer} column column ID (Number) + * or title (String) + * @param {Number} value value to assign + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * table.setNum(1, 'id', 1); + * + * print(table.getColumn(0)); + * //["0", 1, "2"] + * } + * + *
+ * + *@alt + * no image displayed + */ + p5.Table.prototype.setNum = function(row, column, value) { + this.rows[row].setNum(column, value); + }; + + /** + * Stores a String value in the Table's specified row and column. + * The row is specified by its ID, while the column may be specified + * by either its ID or title. + * + * @method setString + * @param {Integer} row row ID + * @param {String|Integer} column column ID (Number) + * or title (String) + * @param {String} value value to assign + * @example + *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * //add a row + * let newRow = table.addRow(); + * newRow.setString('id', table.getRowCount() - 1); + * newRow.setString('species', 'Canis Lupus'); + * newRow.setString('name', 'Wolf'); + * + * print(table.getArray()); + * } + *
+ * + * @alt + * no image displayed + */ + p5.Table.prototype.setString = function(row, column, value) { + this.rows[row].setString(column, value); + }; + + /** + * Retrieves a value from the Table's specified row and column. + * The row is specified by its ID, while the column may be specified by + * either its ID or title. + * + * @method get + * @param {Integer} row row ID + * @param {String|Integer} column columnName (string) or + * ID (number) + * @return {String|Number} + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * print(table.get(0, 1)); + * //Capra hircus + * print(table.get(0, 'species')); + * //Capra hircus + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.get = function(row, column) { + return this.rows[row].get(column); + }; + + /** + * Retrieves a Float value from the Table's specified row and column. + * The row is specified by its ID, while the column may be specified by + * either its ID or title. + * + * @method getNum + * @param {Integer} row row ID + * @param {String|Integer} column columnName (string) or + * ID (number) + * @return {Number} + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * print(table.getNum(1, 0) + 100); + * //id 1 + 100 = 101 + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.getNum = function(row, column) { + return this.rows[row].getNum(column); + }; + + /** + * Retrieves a String value from the Table's specified row and column. + * The row is specified by its ID, while the column may be specified by + * either its ID or title. + * + * @method getString + * @param {Integer} row row ID + * @param {String|Integer} column columnName (string) or + * ID (number) + * @return {String} + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * // table is comma separated value "CSV" + * // and has specifiying header for column labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * print(table.getString(0, 0)); // 0 + * print(table.getString(0, 1)); // Capra hircus + * print(table.getString(0, 2)); // Goat + * print(table.getString(1, 0)); // 1 + * print(table.getString(1, 1)); // Panthera pardus + * print(table.getString(1, 2)); // Leopard + * print(table.getString(2, 0)); // 2 + * print(table.getString(2, 1)); // Equus zebra + * print(table.getString(2, 2)); // Zebra + * } + * + *
+ * + *@alt + * no image displayed + * + */ + + p5.Table.prototype.getString = function(row, column) { + return this.rows[row].getString(column); + }; + + /** + * Retrieves all table data and returns as an object. If a column name is + * passed in, each row object will be stored with that attribute as its + * title. + * + * @method getObject + * @param {String} [headerColumn] Name of the column which should be used to + * title each row object (optional) + * @return {Object} + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let tableObject = table.getObject(); + * + * print(tableObject); + * //outputs an object + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.getObject = function(headerColumn) { + var tableObject = {}; + var obj, cPos, index; + + for (var i = 0; i < this.rows.length; i++) { + obj = this.rows[i].obj; + + if (typeof headerColumn === 'string') { + cPos = this.columns.indexOf(headerColumn); // index of columnID + if (cPos >= 0) { + index = obj[headerColumn]; + tableObject[index] = obj; + } else { + throw new Error('This table has no column named "' + headerColumn + '"'); + } + } else { + tableObject[i] = this.rows[i].obj; + } + } + return tableObject; + }; + + /** + * Retrieves all table data and returns it as a multidimensional array. + * + * @method getArray + * @return {Array} + * + * @example + *
+ * + * // Given the CSV file "mammals.csv" + * // in the project's "assets" folder + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leoperd + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * // table is comma separated value "CSV" + * // and has specifiying header for column labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let tableArray = table.getArray(); + * for (let i = 0; i < tableArray.length; i++) { + * print(tableArray[i]); + * } + * } + * + *
+ * + *@alt + * no image displayed + * + */ + p5.Table.prototype.getArray = function() { + var tableArray = []; + for (var i = 0; i < this.rows.length; i++) { + tableArray.push(this.rows[i].arr); + } + return tableArray; + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 50: [ + function(_dereq_, module, exports) { + /** + * @module IO + * @submodule Table + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * A TableRow object represents a single row of data values, + * stored in columns, from a table. + * + * A Table Row contains both an ordered array, and an unordered + * JSON object. + * + * @class p5.TableRow + * @constructor + * @param {String} [str] optional: populate the row with a + * string of values, separated by the + * separator + * @param {String} [separator] comma separated values (csv) by default + */ + p5.TableRow = function(str, separator) { + var arr = []; + var obj = {}; + if (str) { + separator = separator || ','; + arr = str.split(separator); + } + for (var i = 0; i < arr.length; i++) { + var key = i; + var val = arr[i]; + obj[key] = val; + } + this.arr = arr; + this.obj = obj; + this.table = null; + }; + + /** + * Stores a value in the TableRow's specified column. + * The column may be specified by either its ID or title. + * + * @method set + * @param {String|Integer} column Column ID (Number) + * or Title (String) + * @param {String|Number} value The value to be stored + * + * @example + *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let rows = table.getRows(); + * for (let r = 0; r < rows.length; r++) { + * rows[r].set('name', 'Unicorn'); + * } + * + * //print the results + * print(table.getArray()); + * } + *
+ * + * @alt + * no image displayed + */ + p5.TableRow.prototype.set = function(column, value) { + // if typeof column is string, use .obj + if (typeof column === 'string') { + var cPos = this.table.columns.indexOf(column); // index of columnID + if (cPos >= 0) { + this.obj[column] = value; + this.arr[cPos] = value; + } else { + throw new Error('This table has no column named "' + column + '"'); + } + } else { + // if typeof column is number, use .arr + if (column < this.table.columns.length) { + this.arr[column] = value; + var cTitle = this.table.columns[column]; + this.obj[cTitle] = value; + } else { + throw new Error('Column #' + column + ' is out of the range of this table'); + } + } + }; + + /** + * Stores a Float value in the TableRow's specified column. + * The column may be specified by either its ID or title. + * + * @method setNum + * @param {String|Integer} column Column ID (Number) + * or Title (String) + * @param {Number|String} value The value to be stored + * as a Float + * @example + *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let rows = table.getRows(); + * for (let r = 0; r < rows.length; r++) { + * rows[r].setNum('id', r + 10); + * } + * + * print(table.getArray()); + * } + *
+ * + * @alt + * no image displayed + */ + p5.TableRow.prototype.setNum = function(column, value) { + var floatVal = parseFloat(value); + this.set(column, floatVal); + }; + + /** + * Stores a String value in the TableRow's specified column. + * The column may be specified by either its ID or title. + * + * @method setString + * @param {String|Integer} column Column ID (Number) + * or Title (String) + * @param {String|Number|Boolean|Object} value The value to be stored + * as a String + * @example + *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let rows = table.getRows(); + * for (let r = 0; r < rows.length; r++) { + * let name = rows[r].getString('name'); + * rows[r].setString('name', 'A ' + name + ' named George'); + * } + * + * print(table.getArray()); + * } + *
+ * + * @alt + * no image displayed + */ + p5.TableRow.prototype.setString = function(column, value) { + var stringVal = value.toString(); + this.set(column, stringVal); + }; + + /** + * Retrieves a value from the TableRow's specified column. + * The column may be specified by either its ID or title. + * + * @method get + * @param {String|Integer} column columnName (string) or + * ID (number) + * @return {String|Number} + * + * @example + *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let names = []; + * let rows = table.getRows(); + * for (let r = 0; r < rows.length; r++) { + * names.push(rows[r].get('name')); + * } + * + * print(names); + * } + *
+ * + * @alt + * no image displayed + */ + p5.TableRow.prototype.get = function(column) { + if (typeof column === 'string') { + return this.obj[column]; + } else { + return this.arr[column]; + } + }; + + /** + * Retrieves a Float value from the TableRow's specified + * column. The column may be specified by either its ID or + * title. + * + * @method getNum + * @param {String|Integer} column columnName (string) or + * ID (number) + * @return {Number} Float Floating point number + * @example + *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let rows = table.getRows(); + * let minId = Infinity; + * let maxId = -Infinity; + * for (let r = 0; r < rows.length; r++) { + * let id = rows[r].getNum('id'); + * minId = min(minId, id); + * maxId = min(maxId, id); + * } + * print('minimum id = ' + minId + ', maximum id = ' + maxId); + * } + *
+ * + * @alt + * no image displayed + */ + p5.TableRow.prototype.getNum = function(column) { + var ret; + if (typeof column === 'string') { + ret = parseFloat(this.obj[column]); + } else { + ret = parseFloat(this.arr[column]); + } + + if (ret.toString() === 'NaN') { + throw 'Error: ' + this.obj[column] + ' is NaN (Not a Number)'; + } + return ret; + }; + + /** + * Retrieves an String value from the TableRow's specified + * column. The column may be specified by either its ID or + * title. + * + * @method getString + * @param {String|Integer} column columnName (string) or + * ID (number) + * @return {String} String + * @example + *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder: + * // + * // id,species,name + * // 0,Capra hircus,Goat + * // 1,Panthera pardus,Leopard + * // 2,Equus zebra,Zebra + * + * let table; + * + * function preload() { + * //my table is comma separated value "csv" + * //and has a header specifying the columns labels + * table = loadTable('assets/mammals.csv', 'csv', 'header'); + * } + * + * function setup() { + * let rows = table.getRows(); + * let longest = ''; + * for (let r = 0; r < rows.length; r++) { + * let species = rows[r].getString('species'); + * if (longest.length < species.length) { + * longest = species; + * } + * } + * + * print('longest: ' + longest); + * } + *
+ * + * @alt + * no image displayed + */ + p5.TableRow.prototype.getString = function(column) { + if (typeof column === 'string') { + return this.obj[column].toString(); + } else { + return this.arr[column].toString(); + } + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 51: [ + function(_dereq_, module, exports) { + /** + * @module IO + * @submodule XML + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * XML is a representation of an XML object, able to parse XML code. Use + * loadXML() to load external XML files and create XML objects. + * + * @class p5.XML + * @constructor + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let children = xml.getChildren('animal'); + * + * for (let i = 0; i < children.length; i++) { + * let id = children[i].getNum('id'); + * let coloring = children[i].getString('species'); + * let name = children[i].getContent(); + * print(id + ', ' + coloring + ', ' + name); + * } + * } + * + * // Sketch prints: + * // 0, Capra hircus, Goat + * // 1, Panthera pardus, Leopard + * // 2, Equus zebra, Zebra + *
+ * + * @alt + * no image displayed + * + */ + p5.XML = function(DOM) { + if (!DOM) { + var xmlDoc = document.implementation.createDocument(null, 'doc'); + this.DOM = xmlDoc.createElement('root'); + } else { + this.DOM = DOM; + } + }; + + /** + * Gets a copy of the element's parent. Returns the parent as another + * p5.XML object. + * + * @method getParent + * @return {p5.XML} element parent + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let children = xml.getChildren('animal'); + * let parent = children[1].getParent(); + * print(parent.getName()); + * } + * + * // Sketch prints: + * // mammals + *
+ */ + p5.XML.prototype.getParent = function() { + return new p5.XML(this.DOM.parentElement); + }; + + /** + * Gets the element's full name, which is returned as a String. + * + * @method getName + * @return {String} the name of the node + * @example<animal + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * print(xml.getName()); + * } + * + * // Sketch prints: + * // mammals + *
+ */ + p5.XML.prototype.getName = function() { + return this.DOM.tagName; + }; + + /** + * Sets the element's name, which is specified as a String. + * + * @method setName + * @param {String} the new name of the node + * @example<animal + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * print(xml.getName()); + * xml.setName('fish'); + * print(xml.getName()); + * } + * + * // Sketch prints: + * // mammals + * // fish + *
+ */ + p5.XML.prototype.setName = function(name) { + var content = this.DOM.innerHTML; + var attributes = this.DOM.attributes; + var xmlDoc = document.implementation.createDocument(null, 'default'); + var newDOM = xmlDoc.createElement(name); + newDOM.innerHTML = content; + for (var i = 0; i < attributes.length; i++) { + newDOM.setAttribute(attributes[i].nodeName, attributes.nodeValue); + } + this.DOM = newDOM; + }; + + /** + * Checks whether or not the element has any children, and returns the result + * as a boolean. + * + * @method hasChildren + * @return {boolean} + * @example<animal + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * print(xml.hasChildren()); + * } + * + * // Sketch prints: + * // true + *
+ */ + p5.XML.prototype.hasChildren = function() { + return this.DOM.children.length > 0; + }; + + /** + * Get the names of all of the element's children, and returns the names as an + * array of Strings. This is the same as looping through and calling getName() + * on each child element individually. + * + * @method listChildren + * @return {String[]} names of the children of the element + * @example<animal + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * print(xml.listChildren()); + * } + * + * // Sketch prints: + * // ["animal", "animal", "animal"] + *
+ */ + p5.XML.prototype.listChildren = function() { + var arr = []; + for (var i = 0; i < this.DOM.childNodes.length; i++) { + arr.push(this.DOM.childNodes[i].nodeName); + } + return arr; + }; + + /** + * Returns all of the element's children as an array of p5.XML objects. When + * the name parameter is specified, then it will return all children that match + * that name. + * + * @method getChildren + * @param {String} [name] element name + * @return {p5.XML[]} children of the element + * @example<animal + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let animals = xml.getChildren('animal'); + * + * for (let i = 0; i < animals.length; i++) { + * print(animals[i].getContent()); + * } + * } + * + * // Sketch prints: + * // "Goat" + * // "Leopard" + * // "Zebra" + *
+ */ + p5.XML.prototype.getChildren = function(param) { + if (param) { + return elementsToP5XML(this.DOM.getElementsByTagName(param)); + } else { + return elementsToP5XML(this.DOM.children); + } + }; + + function elementsToP5XML(elements) { + var arr = []; + for (var i = 0; i < elements.length; i++) { + arr.push(new p5.XML(elements[i])); + } + return arr; + } + + /** + * Returns the first of the element's children that matches the name parameter + * or the child of the given index.It returns undefined if no matching + * child is found. + * + * @method getChild + * @param {String|Integer} name element name or index + * @return {p5.XML} + * @example<animal + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.getContent()); + * } + * + * // Sketch prints: + * // "Goat" + *
+ *
+ * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let secondChild = xml.getChild(1); + * print(secondChild.getContent()); + * } + * + * // Sketch prints: + * // "Leopard" + *
+ */ + p5.XML.prototype.getChild = function(param) { + if (typeof param === 'string') { + for (var i = 0; i < this.DOM.children.length; i++) { + var child = this.DOM.children[i]; + if (child.tagName === param) return new p5.XML(child); + } + } else { + return new p5.XML(this.DOM.children[param]); + } + }; + + /** + * Appends a new child to the element. The child can be specified with + * either a String, which will be used as the new tag's name, or as a + * reference to an existing p5.XML object. + * A reference to the newly created child is returned as an p5.XML object. + * + * @method addChild + * @param {p5.XML} node a p5.XML Object which will be the child to be added + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let child = new p5.XML(); + * child.setName('animal'); + * child.setAttribute('id', '3'); + * child.setAttribute('species', 'Ornithorhynchus anatinus'); + * child.setContent('Platypus'); + * xml.addChild(child); + * + * let animals = xml.getChildren('animal'); + * print(animals[animals.length - 1].getContent()); + * } + * + * // Sketch prints: + * // "Goat" + * // "Leopard" + * // "Zebra" + *
+ */ + p5.XML.prototype.addChild = function(node) { + if (node instanceof p5.XML) { + this.DOM.appendChild(node.DOM); + } else { + // PEND + } + }; + + /** + * Removes the element specified by name or index. + * + * @method removeChild + * @param {String|Integer} name element name or index + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * xml.removeChild('animal'); + * let children = xml.getChildren(); + * for (let i = 0; i < children.length; i++) { + * print(children[i].getContent()); + * } + * } + * + * // Sketch prints: + * // "Leopard" + * // "Zebra" + *
+ *
+ * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * xml.removeChild(1); + * let children = xml.getChildren(); + * for (let i = 0; i < children.length; i++) { + * print(children[i].getContent()); + * } + * } + * + * // Sketch prints: + * // "Goat" + * // "Zebra" + *
+ */ + p5.XML.prototype.removeChild = function(param) { + var ind = -1; + if (typeof param === 'string') { + for (var i = 0; i < this.DOM.children.length; i++) { + if (this.DOM.children[i].tagName === param) { + ind = i; + break; + } + } + } else { + ind = param; + } + if (ind !== -1) { + this.DOM.removeChild(this.DOM.children[ind]); + } + }; + + /** + * Counts the specified element's number of attributes, returned as an Number. + * + * @method getAttributeCount + * @return {Integer} + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.getAttributeCount()); + * } + * + * // Sketch prints: + * // 2 + *
+ */ + p5.XML.prototype.getAttributeCount = function() { + return this.DOM.attributes.length; + }; + + /** + * Gets all of the specified element's attributes, and returns them as an + * array of Strings. + * + * @method listAttributes + * @return {String[]} an array of strings containing the names of attributes + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.listAttributes()); + * } + * + * // Sketch prints: + * // ["id", "species"] + *
+ */ + p5.XML.prototype.listAttributes = function() { + var arr = []; + for (var i = 0; i < this.DOM.attributes.length; i++) { + var attribute = this.DOM.attributes[i]; + arr.push(attribute.nodeName); + } + return arr; + }; + + /** + * Checks whether or not an element has the specified attribute. + * + * @method hasAttribute + * @param {String} the attribute to be checked + * @return {boolean} true if attribute found else false + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.hasAttribute('species')); + * print(firstChild.hasAttribute('color')); + * } + * + * // Sketch prints: + * // true + * // false + *
+ */ + p5.XML.prototype.hasAttribute = function(name) { + var obj = {}; + for (var i = 0; i < this.DOM.attributes.length; i++) { + var attribute = this.DOM.attributes[i]; + obj[attribute.nodeName] = attribute.nodeValue; + } + return obj[name] ? true : false; + }; + + /** + * Returns an attribute value of the element as an Number. If the defaultValue + * parameter is specified and the attribute doesn't exist, then defaultValue + * is returned. If no defaultValue is specified and the attribute doesn't + * exist, the value 0 is returned. + * + * @method getNum + * @param {String} name the non-null full name of the attribute + * @param {Number} [defaultValue] the default value of the attribute + * @return {Number} + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.getNum('id')); + * } + * + * // Sketch prints: + * // 0 + *
+ */ + p5.XML.prototype.getNum = function(name, defaultValue) { + var obj = {}; + for (var i = 0; i < this.DOM.attributes.length; i++) { + var attribute = this.DOM.attributes[i]; + obj[attribute.nodeName] = attribute.nodeValue; + } + return Number(obj[name]) || defaultValue || 0; + }; + + /** + * Returns an attribute value of the element as an String. If the defaultValue + * parameter is specified and the attribute doesn't exist, then defaultValue + * is returned. If no defaultValue is specified and the attribute doesn't + * exist, null is returned. + * + * @method getString + * @param {String} name the non-null full name of the attribute + * @param {Number} [defaultValue] the default value of the attribute + * @return {String} + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.getString('species')); + * } + * + * // Sketch prints: + * // "Capra hircus" + *
+ */ + p5.XML.prototype.getString = function(name, defaultValue) { + var obj = {}; + for (var i = 0; i < this.DOM.attributes.length; i++) { + var attribute = this.DOM.attributes[i]; + obj[attribute.nodeName] = attribute.nodeValue; + } + return obj[name] ? String(obj[name]) : defaultValue || null; + }; + + /** + * Sets the content of an element's attribute. The first parameter specifies + * the attribute name, while the second specifies the new content. + * + * @method setAttribute + * @param {String} name the full name of the attribute + * @param {Number|String|Boolean} value the value of the attribute + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.getString('species')); + * firstChild.setAttribute('species', 'Jamides zebra'); + * print(firstChild.getString('species')); + * } + * + * // Sketch prints: + * // "Capra hircus" + * // "Jamides zebra" + *
+ */ + p5.XML.prototype.setAttribute = function(name, value) { + this.DOM.setAttribute(name, value); + }; + + /** + * Returns the content of an element. If there is no such content, + * defaultValue is returned if specified, otherwise null is returned. + * + * @method getContent + * @param {String} [defaultValue] value returned if no content is found + * @return {String} + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.getContent()); + * } + * + * // Sketch prints: + * // "Goat" + *
+ */ + p5.XML.prototype.getContent = function(defaultValue) { + var str; + str = this.DOM.textContent; + str = str.replace(/\s\s+/g, ','); + return str || defaultValue || null; + }; + + /** + * Sets the element's content. + * + * @method setContent + * @param {String} text the new content + * @example + *
+ * // The following short XML file called "mammals.xml" is parsed + * // in the code below. + * // + * // + * // <mammals> + * // <animal id="0" species="Capra hircus">Goat</animal> + * // <animal id="1" species="Panthera pardus">Leopard</animal> + * // <animal id="2" species="Equus zebra">Zebra</animal> + * // </mammals> + * + * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * let firstChild = xml.getChild('animal'); + * print(firstChild.getContent()); + * firstChild.setContent('Mountain Goat'); + * print(firstChild.getContent()); + * } + * + * // Sketch prints: + * // "Goat" + * // "Mountain Goat" + *
+ */ + p5.XML.prototype.setContent = function(content) { + if (!this.DOM.children.length) { + this.DOM.textContent = content; + } + }; + + /** + * Serializes the element into a string. This function is useful for preparing + * the content to be sent over a http request or saved to file. + * + * @method serialize + * @return {String} Serialized string of the element + * @example + *
+ * let xml; + * + * function preload() { + * xml = loadXML('assets/mammals.xml'); + * } + * + * function setup() { + * print(xml.serialize()); + * } + * + * // Sketch prints: + * // + * // Goat + * // Leopard + * // Zebra + * // + *
+ */ + p5.XML.prototype.serialize = function() { + var xmlSerializer = new XMLSerializer(); + return xmlSerializer.serializeToString(this.DOM); + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 52: [ + function(_dereq_, module, exports) { + /** + * @module Math + * @submodule Calculation + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * Calculates the absolute value (magnitude) of a number. Maps to Math.abs(). + * The absolute value of a number is always positive. + * + * @method abs + * @param {Number} n number to compute + * @return {Number} absolute value of given number + * @example + *
+ * function setup() { + * let x = -3; + * let y = abs(x); + * + * print(x); // -3 + * print(y); // 3 + * } + *
+ * + * @alt + * no image displayed + * + */ + p5.prototype.abs = Math.abs; + + /** + * Calculates the closest int value that is greater than or equal to the + * value of the parameter. Maps to Math.ceil(). For example, ceil(9.03) + * returns the value 10. + * + * @method ceil + * @param {Number} n number to round up + * @return {Integer} rounded up number + * @example + *
+ * function draw() { + * background(200); + * // map, mouseX between 0 and 5. + * let ax = map(mouseX, 0, 100, 0, 5); + * let ay = 66; + * + * //Get the ceiling of the mapped number. + * let bx = ceil(map(mouseX, 0, 100, 0, 5)); + * let by = 33; + * + * // Multiply the mapped numbers by 20 to more easily + * // see the changes. + * stroke(0); + * fill(0); + * line(0, ay, ax * 20, ay); + * line(0, by, bx * 20, by); + * + * // Reformat the float returned by map and draw it. + * noStroke(); + * text(nfc(ax, 2), ax, ay - 5); + * text(nfc(bx, 1), bx, by - 5); + * } + *
+ * + * @alt + * 2 horizontal lines & number sets. increase with mouse x. bottom to 2 decimals + * + */ + p5.prototype.ceil = Math.ceil; + + /** + * Constrains a value between a minimum and maximum value. + * + * @method constrain + * @param {Number} n number to constrain + * @param {Number} low minimum limit + * @param {Number} high maximum limit + * @return {Number} constrained number + * @example + *
+ * function draw() { + * background(200); + * + * let leftWall = 25; + * let rightWall = 75; + * + * // xm is just the mouseX, while + * // xc is the mouseX, but constrained + * // between the leftWall and rightWall! + * let xm = mouseX; + * let xc = constrain(mouseX, leftWall, rightWall); + * + * // Draw the walls. + * stroke(150); + * line(leftWall, 0, leftWall, height); + * line(rightWall, 0, rightWall, height); + * + * // Draw xm and xc as circles. + * noStroke(); + * fill(150); + * ellipse(xm, 33, 9, 9); // Not Constrained + * fill(0); + * ellipse(xc, 66, 9, 9); // Constrained + * } + *
+ * + * @alt + * 2 vertical lines. 2 ellipses move with mouse X 1 does not move passed lines + * + */ + p5.prototype.constrain = function(n, low, high) { + p5._validateParameters('constrain', arguments); + return Math.max(Math.min(n, high), low); + }; + + /** + * Calculates the distance between two points, in either two or three dimensions. + * + * @method dist + * @param {Number} x1 x-coordinate of the first point + * @param {Number} y1 y-coordinate of the first point + * @param {Number} x2 x-coordinate of the second point + * @param {Number} y2 y-coordinate of the second point + * @return {Number} distance between the two points + * + * @example + *
+ * // Move your mouse inside the canvas to see the + * // change in distance between two points! + * function draw() { + * background(200); + * fill(0); + * + * let x1 = 10; + * let y1 = 90; + * let x2 = mouseX; + * let y2 = mouseY; + * + * line(x1, y1, x2, y2); + * ellipse(x1, y1, 7, 7); + * ellipse(x2, y2, 7, 7); + * + * // d is the length of the line + * // the distance from point 1 to point 2. + * let d = int(dist(x1, y1, x2, y2)); + * + * // Let's write d along the line we are drawing! + * push(); + * translate((x1 + x2) / 2, (y1 + y2) / 2); + * rotate(atan2(y2 - y1, x2 - x1)); + * text(nfc(d, 1), 0, -5); + * pop(); + * // Fancy! + * } + *
+ * + * @alt + * 2 ellipses joined by line. 1 ellipse moves with mouse X&Y. Distance displayed. + */ + /** + * @method dist + * @param {Number} x1 + * @param {Number} y1 + * @param {Number} z1 z-coordinate of the first point + * @param {Number} x2 + * @param {Number} y2 + * @param {Number} z2 z-coordinate of the second point + * @return {Number} distance between the two points + */ + p5.prototype.dist = function() { + p5._validateParameters('dist', arguments); + if (arguments.length === 4) { + //2D + return hypot(arguments[2] - arguments[0], arguments[3] - arguments[1]); + } else if (arguments.length === 6) { + //3D + return hypot( + arguments[3] - arguments[0], + arguments[4] - arguments[1], + arguments[5] - arguments[2] + ); + } + }; + + /** + * Returns Euler's number e (2.71828...) raised to the power of the n + * parameter. Maps to Math.exp(). + * + * @method exp + * @param {Number} n exponent to raise + * @return {Number} e^n + * @example + *
+ * function draw() { + * background(200); + * + * // Compute the exp() function with a value between 0 and 2 + * let xValue = map(mouseX, 0, width, 0, 2); + * let yValue = exp(xValue); + * + * let y = map(yValue, 0, 8, height, 0); + * + * let legend = 'exp (' + nfc(xValue, 3) + ')\n= ' + nf(yValue, 1, 4); + * stroke(150); + * line(mouseX, y, mouseX, height); + * fill(0); + * text(legend, 5, 15); + * noStroke(); + * ellipse(mouseX, y, 7, 7); + * + * // Draw the exp(x) curve, + * // over the domain of x from 0 to 2 + * noFill(); + * stroke(0); + * beginShape(); + * for (let x = 0; x < width; x++) { + * xValue = map(x, 0, width, 0, 2); + * yValue = exp(xValue); + * y = map(yValue, 0, 8, height, 0); + * vertex(x, y); + * } + * + * endShape(); + * line(0, 0, 0, height); + * line(0, height - 1, width, height - 1); + * } + *
+ * + * @alt + * ellipse moves along a curve with mouse x. e^n displayed. + * + */ + p5.prototype.exp = Math.exp; + + /** + * Calculates the closest int value that is less than or equal to the + * value of the parameter. Maps to Math.floor(). + * + * @method floor + * @param {Number} n number to round down + * @return {Integer} rounded down number + * @example + *
+ * function draw() { + * background(200); + * //map, mouseX between 0 and 5. + * let ax = map(mouseX, 0, 100, 0, 5); + * let ay = 66; + * + * //Get the floor of the mapped number. + * let bx = floor(map(mouseX, 0, 100, 0, 5)); + * let by = 33; + * + * // Multiply the mapped numbers by 20 to more easily + * // see the changes. + * stroke(0); + * fill(0); + * line(0, ay, ax * 20, ay); + * line(0, by, bx * 20, by); + * + * // Reformat the float returned by map and draw it. + * noStroke(); + * text(nfc(ax, 2), ax, ay - 5); + * text(nfc(bx, 1), bx, by - 5); + * } + *
+ * + * @alt + * 2 horizontal lines & number sets. increase with mouse x. bottom to 2 decimals + * + */ + p5.prototype.floor = Math.floor; + + /** + * Calculates a number between two numbers at a specific increment. The amt + * parameter is the amount to interpolate between the two values where 0.0 + * equal to the first point, 0.1 is very near the first point, 0.5 is + * half-way in between, and 1.0 is equal to the second point. If the + * value of amt is more than 1.0 or less than 0.0, the number will be + * calculated accordingly in the ratio of the two given numbers. The lerp + * function is convenient for creating motion along a straight + * path and for drawing dotted lines. + * + * @method lerp + * @param {Number} start first value + * @param {Number} stop second value + * @param {Number} amt number + * @return {Number} lerped value + * @example + *
+ * function setup() { + * background(200); + * let a = 20; + * let b = 80; + * let c = lerp(a, b, 0.2); + * let d = lerp(a, b, 0.5); + * let e = lerp(a, b, 0.8); + * + * let y = 50; + * + * strokeWeight(5); + * stroke(0); // Draw the original points in black + * point(a, y); + * point(b, y); + * + * stroke(100); // Draw the lerp points in gray + * point(c, y); + * point(d, y); + * point(e, y); + * } + *
+ * + * @alt + * 5 points horizontally staggered mid-canvas. mid 3 are grey, outer black + * + */ + p5.prototype.lerp = function(start, stop, amt) { + p5._validateParameters('lerp', arguments); + return amt * (stop - start) + start; + }; + + /** + * Calculates the natural logarithm (the base-e logarithm) of a number. This + * function expects the n parameter to be a value greater than 0.0. Maps to + * Math.log(). + * + * @method log + * @param {Number} n number greater than 0 + * @return {Number} natural logarithm of n + * @example + *
+ * function draw() { + * background(200); + * let maxX = 2.8; + * let maxY = 1.5; + * + * // Compute the natural log of a value between 0 and maxX + * let xValue = map(mouseX, 0, width, 0, maxX); + * let yValue, y; + * if (xValue > 0) { + // Cannot take the log of a negative number. + * yValue = log(xValue); + * y = map(yValue, -maxY, maxY, height, 0); + * + * // Display the calculation occurring. + * let legend = 'log(' + nf(xValue, 1, 2) + ')\n= ' + nf(yValue, 1, 3); + * stroke(150); + * line(mouseX, y, mouseX, height); + * fill(0); + * text(legend, 5, 15); + * noStroke(); + * ellipse(mouseX, y, 7, 7); + * } + * + * // Draw the log(x) curve, + * // over the domain of x from 0 to maxX + * noFill(); + * stroke(0); + * beginShape(); + * for (let x = 0; x < width; x++) { + * xValue = map(x, 0, width, 0, maxX); + * yValue = log(xValue); + * y = map(yValue, -maxY, maxY, height, 0); + * vertex(x, y); + * } + * endShape(); + * line(0, 0, 0, height); + * line(0, height / 2, width, height / 2); + * } + *
+ * + * @alt + * ellipse moves along a curve with mouse x. natural logarithm of n displayed. + * + */ + p5.prototype.log = Math.log; + + /** + * Calculates the magnitude (or length) of a vector. A vector is a direction + * in space commonly used in computer graphics and linear algebra. Because it + * has no "start" position, the magnitude of a vector can be thought of as + * the distance from the coordinate 0,0 to its x,y value. Therefore, mag() is + * a shortcut for writing dist(0, 0, x, y). + * + * @method mag + * @param {Number} a first value + * @param {Number} b second value + * @return {Number} magnitude of vector from (0,0) to (a,b) + * @example + *
+ * function setup() { + * let x1 = 20; + * let x2 = 80; + * let y1 = 30; + * let y2 = 70; + * + * line(0, 0, x1, y1); + * print(mag(x1, y1)); // Prints "36.05551275463989" + * line(0, 0, x2, y1); + * print(mag(x2, y1)); // Prints "85.44003745317531" + * line(0, 0, x1, y2); + * print(mag(x1, y2)); // Prints "72.80109889280519" + * line(0, 0, x2, y2); + * print(mag(x2, y2)); // Prints "106.3014581273465" + * } + *
+ * + * @alt + * 4 lines of different length radiate from top left of canvas. + * + */ + p5.prototype.mag = function(x, y) { + p5._validateParameters('mag', arguments); + return hypot(x, y); + }; + + /** + * Re-maps a number from one range to another. + *

+ * In the first example above, the number 25 is converted from a value in the + * range of 0 to 100 into a value that ranges from the left edge of the + * window (0) to the right edge (width). + * + * @method map + * @param {Number} value the incoming value to be converted + * @param {Number} start1 lower bound of the value's current range + * @param {Number} stop1 upper bound of the value's current range + * @param {Number} start2 lower bound of the value's target range + * @param {Number} stop2 upper bound of the value's target range + * @param {Boolean} [withinBounds] constrain the value to the newly mapped range + * @return {Number} remapped number + * @example + *
+ * let value = 25; + * let m = map(value, 0, 100, 0, width); + * ellipse(m, 50, 10, 10); +
+ * + *
+ * function setup() { + * noStroke(); + * } + * + * function draw() { + * background(204); + * let x1 = map(mouseX, 0, width, 25, 75); + * ellipse(x1, 25, 25, 25); + * //This ellipse is constrained to the 0-100 range + * //after setting withinBounds to true + * let x2 = map(mouseX, 0, width, 0, 100, true); + * ellipse(x2, 75, 25, 25); + * } +
+ * + * @alt + * 10 by 10 white ellipse with in mid left canvas + * 2 25 by 25 white ellipses move with mouse x. Bottom has more range from X + * + */ + p5.prototype.map = function(n, start1, stop1, start2, stop2, withinBounds) { + p5._validateParameters('map', arguments); + var newval = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2; + if (!withinBounds) { + return newval; + } + if (start2 < stop2) { + return this.constrain(newval, start2, stop2); + } else { + return this.constrain(newval, stop2, start2); + } + }; + + /** + * Determines the largest value in a sequence of numbers, and then returns + * that value. max() accepts any number of Number parameters, or an Array + * of any length. + * + * @method max + * @param {Number} n0 Number to compare + * @param {Number} n1 Number to compare + * @return {Number} maximum Number + * @example + *
+ * function setup() { + * // Change the elements in the array and run the sketch + * // to show how max() works! + * let numArray = [2, 1, 5, 4, 8, 9]; + * fill(0); + * noStroke(); + * text('Array Elements', 0, 10); + * // Draw all numbers in the array + * let spacing = 15; + * let elemsY = 25; + * for (let i = 0; i < numArray.length; i++) { + * text(numArray[i], i * spacing, elemsY); + * } + * let maxX = 33; + * let maxY = 80; + * // Draw the Maximum value in the array. + * textSize(32); + * text(max(numArray), maxX, maxY); + * } + *
+ * + * @alt + * Small text at top reads: Array Elements 2 1 5 4 8 9. Large text at center: 9 + * + */ + /** + * @method max + * @param {Number[]} nums Numbers to compare + * @return {Number} + */ + p5.prototype.max = function() { + p5._validateParameters('max', arguments); + if (arguments[0] instanceof Array) { + return Math.max.apply(null, arguments[0]); + } else { + return Math.max.apply(null, arguments); + } + }; + + /** + * Determines the smallest value in a sequence of numbers, and then returns + * that value. min() accepts any number of Number parameters, or an Array + * of any length. + * + * @method min + * @param {Number} n0 Number to compare + * @param {Number} n1 Number to compare + * @return {Number} minimum Number + * @example + *
+ * function setup() { + * // Change the elements in the array and run the sketch + * // to show how min() works! + * let numArray = [2, 1, 5, 4, 8, 9]; + * fill(0); + * noStroke(); + * text('Array Elements', 0, 10); + * // Draw all numbers in the array + * let spacing = 15; + * let elemsY = 25; + * for (let i = 0; i < numArray.length; i++) { + * text(numArray[i], i * spacing, elemsY); + * } + * let maxX = 33; + * let maxY = 80; + * // Draw the Minimum value in the array. + * textSize(32); + * text(min(numArray), maxX, maxY); + * } + *
+ * + * @alt + * Small text at top reads: Array Elements 2 1 5 4 8 9. Large text at center: 1 + * + */ + /** + * @method min + * @param {Number[]} nums Numbers to compare + * @return {Number} + */ + p5.prototype.min = function() { + p5._validateParameters('min', arguments); + if (arguments[0] instanceof Array) { + return Math.min.apply(null, arguments[0]); + } else { + return Math.min.apply(null, arguments); + } + }; + + /** + * Normalizes a number from another range into a value between 0 and 1. + * Identical to map(value, low, high, 0, 1). + * Numbers outside of the range are not clamped to 0 and 1, because + * out-of-range values are often intentional and useful. (See the example above.) + * + * @method norm + * @param {Number} value incoming value to be normalized + * @param {Number} start lower bound of the value's current range + * @param {Number} stop upper bound of the value's current range + * @return {Number} normalized number + * @example + *
+ * function draw() { + * background(200); + * let currentNum = mouseX; + * let lowerBound = 0; + * let upperBound = width; //100; + * let normalized = norm(currentNum, lowerBound, upperBound); + * let lineY = 70; + * stroke(3); + * line(0, lineY, width, lineY); + * //Draw an ellipse mapped to the non-normalized value. + * noStroke(); + * fill(50); + * let s = 7; // ellipse size + * ellipse(currentNum, lineY, s, s); + * + * // Draw the guide + * let guideY = lineY + 15; + * text('0', 0, guideY); + * textAlign(RIGHT); + * text('100', width, guideY); + * + * // Draw the normalized value + * textAlign(LEFT); + * fill(0); + * textSize(32); + * let normalY = 40; + * let normalX = 20; + * text(normalized, normalX, normalY); + * } + *
+ * + * @alt + * ellipse moves with mouse. 0 shown left & 100 right and updating values center + * + */ + p5.prototype.norm = function(n, start, stop) { + p5._validateParameters('norm', arguments); + return this.map(n, start, stop, 0, 1); + }; + + /** + * Facilitates exponential expressions. The pow() function is an efficient + * way of multiplying numbers by themselves (or their reciprocals) in large + * quantities. For example, pow(3, 5) is equivalent to the expression + * 3*3*3*3*3 and pow(3, -5) is equivalent to 1 / 3*3*3*3*3. Maps to + * Math.pow(). + * + * @method pow + * @param {Number} n base of the exponential expression + * @param {Number} e power by which to raise the base + * @return {Number} n^e + * @example + *
+ * function setup() { + * //Exponentially increase the size of an ellipse. + * let eSize = 3; // Original Size + * let eLoc = 10; // Original Location + * + * ellipse(eLoc, eLoc, eSize, eSize); + * + * ellipse(eLoc * 2, eLoc * 2, pow(eSize, 2), pow(eSize, 2)); + * + * ellipse(eLoc * 4, eLoc * 4, pow(eSize, 3), pow(eSize, 3)); + * + * ellipse(eLoc * 8, eLoc * 8, pow(eSize, 4), pow(eSize, 4)); + * } + *
+ * + * @alt + * small to large ellipses radiating from top left of canvas + * + */ + p5.prototype.pow = Math.pow; + + /** + * Calculates the integer closest to the n parameter. For example, + * round(133.8) returns the value 134. Maps to Math.round(). + * + * @method round + * @param {Number} n number to round + * @return {Integer} rounded number + * @example + *
+ * function draw() { + * background(200); + * //map, mouseX between 0 and 5. + * let ax = map(mouseX, 0, 100, 0, 5); + * let ay = 66; + * + * // Round the mapped number. + * let bx = round(map(mouseX, 0, 100, 0, 5)); + * let by = 33; + * + * // Multiply the mapped numbers by 20 to more easily + * // see the changes. + * stroke(0); + * fill(0); + * line(0, ay, ax * 20, ay); + * line(0, by, bx * 20, by); + * + * // Reformat the float returned by map and draw it. + * noStroke(); + * text(nfc(ax, 2), ax, ay - 5); + * text(nfc(bx, 1), bx, by - 5); + * } + *
+ * + * @alt + * horizontal center line squared values displayed on top and regular on bottom. + * + */ + p5.prototype.round = Math.round; + + /** + * Squares a number (multiplies a number by itself). The result is always a + * positive number, as multiplying two negative numbers always yields a + * positive result. For example, -1 * -1 = 1. + * + * @method sq + * @param {Number} n number to square + * @return {Number} squared number + * @example + *
+ * function draw() { + * background(200); + * let eSize = 7; + * let x1 = map(mouseX, 0, width, 0, 10); + * let y1 = 80; + * let x2 = sq(x1); + * let y2 = 20; + * + * // Draw the non-squared. + * line(0, y1, width, y1); + * ellipse(x1, y1, eSize, eSize); + * + * // Draw the squared. + * line(0, y2, width, y2); + * ellipse(x2, y2, eSize, eSize); + * + * // Draw dividing line. + * stroke(100); + * line(0, height / 2, width, height / 2); + * + * // Draw text. + * let spacing = 15; + * noStroke(); + * fill(0); + * text('x = ' + x1, 0, y1 + spacing); + * text('sq(x) = ' + x2, 0, y2 + spacing); + * } + *
+ * + * @alt + * horizontal center line squared values displayed on top and regular on bottom. + * + */ + p5.prototype.sq = function(n) { + return n * n; + }; + + /** + * Calculates the square root of a number. The square root of a number is + * always positive, even though there may be a valid negative root. The + * square root s of number a is such that s*s = a. It is the opposite of + * squaring. Maps to Math.sqrt(). + * + * @method sqrt + * @param {Number} n non-negative number to square root + * @return {Number} square root of number + * @example + *
+ * function draw() { + * background(200); + * let eSize = 7; + * let x1 = mouseX; + * let y1 = 80; + * let x2 = sqrt(x1); + * let y2 = 20; + * + * // Draw the non-squared. + * line(0, y1, width, y1); + * ellipse(x1, y1, eSize, eSize); + * + * // Draw the squared. + * line(0, y2, width, y2); + * ellipse(x2, y2, eSize, eSize); + * + * // Draw dividing line. + * stroke(100); + * line(0, height / 2, width, height / 2); + * + * // Draw text. + * noStroke(); + * fill(0); + * let spacing = 15; + * text('x = ' + x1, 0, y1 + spacing); + * text('sqrt(x) = ' + x2, 0, y2 + spacing); + * } + *
+ * + * @alt + * horizontal center line squareroot values displayed on top and regular on bottom. + * + */ + p5.prototype.sqrt = Math.sqrt; + + // Calculate the length of the hypotenuse of a right triangle + // This won't under- or overflow in intermediate steps + // https://en.wikipedia.org/wiki/Hypot + function hypot(x, y, z) { + // Use the native implementation if it's available + if (typeof Math.hypot === 'function') { + return Math.hypot.apply(null, arguments); + } + + // Otherwise use the V8 implementation + // https://github.com/v8/v8/blob/8cd3cf297287e581a49e487067f5cbd991b27123/src/js/math.js#L217 + var length = arguments.length; + var args = []; + var max = 0; + for (var i = 0; i < length; i++) { + var n = arguments[i]; + n = +n; + if (n === Infinity || n === -Infinity) { + return Infinity; + } + n = Math.abs(n); + if (n > max) { + max = n; + } + args[i] = n; + } + + if (max === 0) { + max = 1; + } + var sum = 0; + var compensation = 0; + for (var j = 0; j < length; j++) { + var m = args[j] / max; + var summand = m * m - compensation; + var preliminary = sum + summand; + compensation = preliminary - sum - summand; + sum = preliminary; + } + return Math.sqrt(sum) * max; + } + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 53: [ + function(_dereq_, module, exports) { + /** + * @module Math + * @submodule Math + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * Creates a new p5.Vector (the datatype for storing vectors). This provides a + * two or three dimensional vector, specifically a Euclidean (also known as + * geometric) vector. A vector is an entity that has both magnitude and + * direction. + * + * @method createVector + * @param {Number} [x] x component of the vector + * @param {Number} [y] y component of the vector + * @param {Number} [z] z component of the vector + * @return {p5.Vector} + * @example + *
+ * function setup() { + * createCanvas(100, 100, WEBGL); + * noStroke(); + * fill(255, 102, 204); + * } + * + * function draw() { + * background(255); + * pointLight(color(255), createVector(sin(millis() / 1000) * 20, -40, -10)); + * scale(0.75); + * sphere(); + * } + *
+ * + * @alt + * a purple sphere lit by a point light oscillating horizontally + */ + p5.prototype.createVector = function(x, y, z) { + if (this instanceof p5) { + return new p5.Vector(this, arguments); + } else { + return new p5.Vector(x, y, z); + } + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 54: [ + function(_dereq_, module, exports) { + ////////////////////////////////////////////////////////////// + + // http://mrl.nyu.edu/~perlin/noise/ + // Adapting from PApplet.java + // which was adapted from toxi + // which was adapted from the german demo group farbrausch + // as used in their demo "art": http://www.farb-rausch.de/fr010src.zip + + // someday we might consider using "improved noise" + // http://mrl.nyu.edu/~perlin/paper445.pdf + // See: https://github.com/shiffman/The-Nature-of-Code-Examples-p5.js/ + // blob/master/introduction/Noise1D/noise.js + + /** + * @module Math + * @submodule Noise + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + var PERLIN_YWRAPB = 4; + var PERLIN_YWRAP = 1 << PERLIN_YWRAPB; + var PERLIN_ZWRAPB = 8; + var PERLIN_ZWRAP = 1 << PERLIN_ZWRAPB; + var PERLIN_SIZE = 4095; + + var perlin_octaves = 4; // default to medium smooth + var perlin_amp_falloff = 0.5; // 50% reduction/octave + + var scaled_cosine = function scaled_cosine(i) { + return 0.5 * (1.0 - Math.cos(i * Math.PI)); + }; + + var perlin; // will be initialized lazily by noise() or noiseSeed() + + /** + * Returns the Perlin noise value at specified coordinates. Perlin noise is + * a random sequence generator producing a more natural ordered, harmonic + * succession of numbers compared to the standard random() function. + * It was invented by Ken Perlin in the 1980s and been used since in + * graphical applications to produce procedural textures, natural motion, + * shapes, terrains etc.

The main difference to the + * random() function is that Perlin noise is defined in an infinite + * n-dimensional space where each pair of coordinates corresponds to a + * fixed semi-random value (fixed only for the lifespan of the program; see + * the noiseSeed() function). p5.js can compute 1D, 2D and 3D noise, + * depending on the number of coordinates given. The resulting value will + * always be between 0.0 and 1.0. The noise value can be animated by moving + * through the noise space as demonstrated in the example above. The 2nd + * and 3rd dimension can also be interpreted as time.

The actual + * noise is structured similar to an audio signal, in respect to the + * function's use of frequencies. Similar to the concept of harmonics in + * physics, perlin noise is computed over several octaves which are added + * together for the final result.

Another way to adjust the + * character of the resulting sequence is the scale of the input + * coordinates. As the function works within an infinite space the value of + * the coordinates doesn't matter as such, only the distance between + * successive coordinates does (eg. when using noise() within a + * loop). As a general rule the smaller the difference between coordinates, + * the smoother the resulting noise sequence will be. Steps of 0.005-0.03 + * work best for most applications, but this will differ depending on use. + * + * + * @method noise + * @param {Number} x x-coordinate in noise space + * @param {Number} [y] y-coordinate in noise space + * @param {Number} [z] z-coordinate in noise space + * @return {Number} Perlin noise value (between 0 and 1) at specified + * coordinates + * @example + *
+ * + * let xoff = 0.0; + * + * function draw() { + * background(204); + * xoff = xoff + 0.01; + * let n = noise(xoff) * width; + * line(n, 0, n, height); + * } + * + *
+ *
+ * let noiseScale=0.02; + * + * function draw() { + * background(0); + * for (let x=0; x < width; x++) { + * let noiseVal = noise((mouseX+x)*noiseScale, mouseY*noiseScale); + * stroke(noiseVal*255); + * line(x, mouseY+noiseVal*80, x, height); + * } + * } + * + *
+ * + * @alt + * vertical line moves left to right with updating noise values. + * horizontal wave pattern effected by mouse x-position & updating noise values. + * + */ + + p5.prototype.noise = function(x, y, z) { + y = y || 0; + z = z || 0; + + if (perlin == null) { + perlin = new Array(PERLIN_SIZE + 1); + for (var i = 0; i < PERLIN_SIZE + 1; i++) { + perlin[i] = Math.random(); + } + } + + if (x < 0) { + x = -x; + } + if (y < 0) { + y = -y; + } + if (z < 0) { + z = -z; + } + + var xi = Math.floor(x), + yi = Math.floor(y), + zi = Math.floor(z); + var xf = x - xi; + var yf = y - yi; + var zf = z - zi; + var rxf, ryf; + + var r = 0; + var ampl = 0.5; + + var n1, n2, n3; + + for (var o = 0; o < perlin_octaves; o++) { + var of = xi + (yi << PERLIN_YWRAPB) + (zi << PERLIN_ZWRAPB); + + rxf = scaled_cosine(xf); + ryf = scaled_cosine(yf); + + n1 = perlin[of & PERLIN_SIZE]; + n1 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n1); + n2 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE]; + n2 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n2); + n1 += ryf * (n2 - n1); + + of += PERLIN_ZWRAP; + n2 = perlin[of & PERLIN_SIZE]; + n2 += rxf * (perlin[(of + 1) & PERLIN_SIZE] - n2); + n3 = perlin[(of + PERLIN_YWRAP) & PERLIN_SIZE]; + n3 += rxf * (perlin[(of + PERLIN_YWRAP + 1) & PERLIN_SIZE] - n3); + n2 += ryf * (n3 - n2); + + n1 += scaled_cosine(zf) * (n2 - n1); + + r += n1 * ampl; + ampl *= perlin_amp_falloff; + xi <<= 1; + xf *= 2; + yi <<= 1; + yf *= 2; + zi <<= 1; + zf *= 2; + + if (xf >= 1.0) { + xi++; + xf--; + } + if (yf >= 1.0) { + yi++; + yf--; + } + if (zf >= 1.0) { + zi++; + zf--; + } + } + return r; + }; + + /** + * + * Adjusts the character and level of detail produced by the Perlin noise + * function. Similar to harmonics in physics, noise is computed over + * several octaves. Lower octaves contribute more to the output signal and + * as such define the overall intensity of the noise, whereas higher octaves + * create finer grained details in the noise sequence. + *

+ * By default, noise is computed over 4 octaves with each octave contributing + * exactly half than its predecessor, starting at 50% strength for the 1st + * octave. This falloff amount can be changed by adding an additional function + * parameter. Eg. a falloff factor of 0.75 means each octave will now have + * 75% impact (25% less) of the previous lower octave. Any value between + * 0.0 and 1.0 is valid, however note that values greater than 0.5 might + * result in greater than 1.0 values returned by noise(). + *

+ * By changing these parameters, the signal created by the noise() + * function can be adapted to fit very specific needs and characteristics. + * + * @method noiseDetail + * @param {Number} lod number of octaves to be used by the noise + * @param {Number} falloff falloff factor for each octave + * @example + *
+ * + * let noiseVal; + * let noiseScale = 0.02; + * + * function setup() { + * createCanvas(100, 100); + * } + * + * function draw() { + * background(0); + * for (let y = 0; y < height; y++) { + * for (let x = 0; x < width / 2; x++) { + * noiseDetail(2, 0.2); + * noiseVal = noise((mouseX + x) * noiseScale, (mouseY + y) * noiseScale); + * stroke(noiseVal * 255); + * point(x, y); + * noiseDetail(8, 0.65); + * noiseVal = noise( + * (mouseX + x + width / 2) * noiseScale, + * (mouseY + y) * noiseScale + * ); + * stroke(noiseVal * 255); + * point(x + width / 2, y); + * } + * } + * } + * + *
+ * + * @alt + * 2 vertical grey smokey patterns affected my mouse x-position and noise. + * + */ + p5.prototype.noiseDetail = function(lod, falloff) { + if (lod > 0) { + perlin_octaves = lod; + } + if (falloff > 0) { + perlin_amp_falloff = falloff; + } + }; + + /** + * Sets the seed value for noise(). By default, noise() + * produces different results each time the program is run. Set the + * value parameter to a constant to return the same pseudo-random + * numbers each time the software is run. + * + * @method noiseSeed + * @param {Number} seed the seed value + * @example + *
+ * let xoff = 0.0; + * + * function setup() { + * noiseSeed(99); + * stroke(0, 10); + * } + * + * function draw() { + * xoff = xoff + .01; + * let n = noise(xoff) * width; + * line(n, 0, n, height); + * } + * + *
+ * + * @alt + * vertical grey lines drawing in pattern affected by noise. + * + */ + p5.prototype.noiseSeed = function(seed) { + // Linear Congruential Generator + // Variant of a Lehman Generator + var lcg = (function() { + // Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes + // m is basically chosen to be large (as it is the max period) + // and for its relationships to a and c + var m = 4294967296; + // a - 1 should be divisible by m's prime factors + var a = 1664525; + // c and m should be co-prime + var c = 1013904223; + var seed, z; + return { + setSeed: function setSeed(val) { + // pick a random seed if val is undefined or null + // the >>> 0 casts the seed to an unsigned 32-bit integer + z = seed = (val == null ? Math.random() * m : val) >>> 0; + }, + getSeed: function getSeed() { + return seed; + }, + rand: function rand() { + // define the recurrence relationship + z = (a * z + c) % m; + // return a float in [0, 1) + // if z = m then z / m = 0 therefore (z % m) / m < 1 always + return z / m; + } + }; + })(); + + lcg.setSeed(seed); + perlin = new Array(PERLIN_SIZE + 1); + for (var i = 0; i < PERLIN_SIZE + 1; i++) { + perlin[i] = lcg.rand(); + } + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 55: [ + function(_dereq_, module, exports) { + /** + * @module Math + * @submodule Math + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + + /** + * A class to describe a two or three dimensional vector, specifically + * a Euclidean (also known as geometric) vector. A vector is an entity + * that has both magnitude and direction. The datatype, however, stores + * the components of the vector (x, y for 2D, and x, y, z for 3D). The magnitude + * and direction can be accessed via the methods mag() and heading(). + *

+ * In many of the p5.js examples, you will see p5.Vector used to describe a + * position, velocity, or acceleration. For example, if you consider a rectangle + * moving across the screen, at any given instant it has a position (a vector + * that points from the origin to its location), a velocity (the rate at which + * the object's position changes per time unit, expressed as a vector), and + * acceleration (the rate at which the object's velocity changes per time + * unit, expressed as a vector). + *

+ * Since vectors represent groupings of values, we cannot simply use + * traditional addition/multiplication/etc. Instead, we'll need to do some + * "vector" math, which is made easy by the methods inside the p5.Vector class. + * + * @class p5.Vector + * @param {Number} [x] x component of the vector + * @param {Number} [y] y component of the vector + * @param {Number} [z] z component of the vector + * @example + *
+ * + * let v1 = createVector(40, 50); + * let v2 = createVector(40, 50); + * + * ellipse(v1.x, v1.y, 50, 50); + * ellipse(v2.x, v2.y, 50, 50); + * v1.add(v2); + * ellipse(v1.x, v1.y, 50, 50); + * + *
+ * + * @alt + * 2 white ellipses. One center-left the other bottom right and off canvas + * + */ + p5.Vector = function Vector() { + var x, y, z; + // This is how it comes in with createVector() + if (arguments[0] instanceof p5) { + // save reference to p5 if passed in + this.p5 = arguments[0]; + x = arguments[1][0] || 0; + y = arguments[1][1] || 0; + z = arguments[1][2] || 0; + // This is what we'll get with new p5.Vector() + } else { + x = arguments[0] || 0; + y = arguments[1] || 0; + z = arguments[2] || 0; + } + /** + * The x component of the vector + * @property x {Number} + */ + this.x = x; + /** + * The y component of the vector + * @property y {Number} + */ + this.y = y; + /** + * The z component of the vector + * @property z {Number} + */ + this.z = z; + }; + + /** + * Returns a string representation of a vector v by calling String(v) + * or v.toString(). This method is useful for logging vectors in the + * console. + * @method toString + * @return {String} + * @example + *
+ * + * function setup() { + * let v = createVector(20, 30); + * print(String(v)); // prints "p5.Vector Object : [20, 30, 0]" + * } + * + *
+ * + *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(0, 0); + * let v1 = createVector(mouseX, mouseY); + * drawArrow(v0, v1, 'black'); + * + * noStroke(); + * text(v1.toString(), 10, 25, 90, 75); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.toString = function p5VectorToString() { + return 'p5.Vector Object : [' + this.x + ', ' + this.y + ', ' + this.z + ']'; + }; + + /** + * Sets the x, y, and z component of the vector using two or three separate + * variables, the data from a p5.Vector, or the values from a float array. + * @method set + * @param {Number} [x] the x component of the vector + * @param {Number} [y] the y component of the vector + * @param {Number} [z] the z component of the vector + * @chainable + * @example + *
+ * + * function setup() { + * let v = createVector(1, 2, 3); + * v.set(4, 5, 6); // Sets vector to [4, 5, 6] + * + * let v1 = createVector(0, 0, 0); + * let arr = [1, 2, 3]; + * v1.set(arr); // Sets vector to [1, 2, 3] + * } + * + *
+ * + *
+ * + * let v0, v1; + * function setup() { + * createCanvas(100, 100); + * + * v0 = createVector(0, 0); + * v1 = createVector(50, 50); + * } + * + * function draw() { + * background(240); + * + * drawArrow(v0, v1, 'black'); + * v1.set(v1.x + random(-1, 1), v1.y + random(-1, 1)); + * + * noStroke(); + * text('x: ' + round(v1.x) + ' y: ' + round(v1.y), 20, 90); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + /** + * @method set + * @param {p5.Vector|Number[]} value the vector to set + * @chainable + */ + p5.Vector.prototype.set = function set(x, y, z) { + if (x instanceof p5.Vector) { + this.x = x.x || 0; + this.y = x.y || 0; + this.z = x.z || 0; + return this; + } + if (x instanceof Array) { + this.x = x[0] || 0; + this.y = x[1] || 0; + this.z = x[2] || 0; + return this; + } + this.x = x || 0; + this.y = y || 0; + this.z = z || 0; + return this; + }; + + /** + * Gets a copy of the vector, returns a p5.Vector object. + * + * @method copy + * @return {p5.Vector} the copy of the p5.Vector object + * @example + *
+ * + * let v1 = createVector(1, 2, 3); + * let v2 = v1.copy(); + * print(v1.x === v2.x && v1.y === v2.y && v1.z === v2.z); + * // Prints "true" + * + *
+ */ + p5.Vector.prototype.copy = function copy() { + if (this.p5) { + return new p5.Vector(this.p5, [this.x, this.y, this.z]); + } else { + return new p5.Vector(this.x, this.y, this.z); + } + }; + + /** + * Adds x, y, and z components to a vector, adds one vector to another, or + * adds two independent vectors together. The version of the method that adds + * two vectors together is a static method and returns a p5.Vector, the others + * acts directly on the vector. See the examples for more context. + * + * @method add + * @param {Number} x the x component of the vector to be added + * @param {Number} [y] the y component of the vector to be added + * @param {Number} [z] the z component of the vector to be added + * @chainable + * @example + *
+ * + * let v = createVector(1, 2, 3); + * v.add(4, 5, 6); + * // v's components are set to [5, 7, 9] + * + *
+ * + *
+ * + * // Static method + * let v1 = createVector(1, 2, 3); + * let v2 = createVector(2, 3, 4); + * + * let v3 = p5.Vector.add(v1, v2); + * // v3 has components [3, 5, 7] + * print(v3); + * + *
+ * + *
+ * + * // red vector + blue vector = purple vector + * function draw() { + * background(240); + * + * let v0 = createVector(0, 0); + * let v1 = createVector(mouseX, mouseY); + * drawArrow(v0, v1, 'red'); + * + * let v2 = createVector(-30, 20); + * drawArrow(v1, v2, 'blue'); + * + * let v3 = p5.Vector.add(v1, v2); + * drawArrow(v0, v3, 'purple'); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + /** + * @method add + * @param {p5.Vector|Number[]} value the vector to add + * @chainable + */ + p5.Vector.prototype.add = function add(x, y, z) { + if (x instanceof p5.Vector) { + this.x += x.x || 0; + this.y += x.y || 0; + this.z += x.z || 0; + return this; + } + if (x instanceof Array) { + this.x += x[0] || 0; + this.y += x[1] || 0; + this.z += x[2] || 0; + return this; + } + this.x += x || 0; + this.y += y || 0; + this.z += z || 0; + return this; + }; + + /** + * Subtracts x, y, and z components from a vector, subtracts one vector from + * another, or subtracts two independent vectors. The version of the method + * that subtracts two vectors is a static method and returns a p5.Vector, the + * other acts directly on the vector. See the examples for more context. + * + * @method sub + * @param {Number} x the x component of the vector to subtract + * @param {Number} [y] the y component of the vector to subtract + * @param {Number} [z] the z component of the vector to subtract + * @chainable + * @example + *
+ * + * let v = createVector(4, 5, 6); + * v.sub(1, 1, 1); + * // v's components are set to [3, 4, 5] + * + *
+ * + *
+ * + * // Static method + * let v1 = createVector(2, 3, 4); + * let v2 = createVector(1, 2, 3); + * + * let v3 = p5.Vector.sub(v1, v2); + * // v3 has components [1, 1, 1] + * print(v3); + * + *
+ * + *
+ * + * // red vector - blue vector = purple vector + * function draw() { + * background(240); + * + * let v0 = createVector(0, 0); + * let v1 = createVector(70, 50); + * drawArrow(v0, v1, 'red'); + * + * let v2 = createVector(mouseX, mouseY); + * drawArrow(v0, v2, 'blue'); + * + * let v3 = p5.Vector.sub(v1, v2); + * drawArrow(v2, v3, 'purple'); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + /** + * @method sub + * @param {p5.Vector|Number[]} value the vector to subtract + * @chainable + */ + p5.Vector.prototype.sub = function sub(x, y, z) { + if (x instanceof p5.Vector) { + this.x -= x.x || 0; + this.y -= x.y || 0; + this.z -= x.z || 0; + return this; + } + if (x instanceof Array) { + this.x -= x[0] || 0; + this.y -= x[1] || 0; + this.z -= x[2] || 0; + return this; + } + this.x -= x || 0; + this.y -= y || 0; + this.z -= z || 0; + return this; + }; + + /** + * Multiply the vector by a scalar. The static version of this method + * creates a new p5.Vector while the non static version acts on the vector + * directly. See the examples for more context. + * + * @method mult + * @param {Number} n the number to multiply with the vector + * @chainable + * @example + *
+ * + * let v = createVector(1, 2, 3); + * v.mult(2); + * // v's components are set to [2, 4, 6] + * + *
+ * + *
+ * + * // Static method + * let v1 = createVector(1, 2, 3); + * let v2 = p5.Vector.mult(v1, 2); + * // v2 has components [2, 4, 6] + * print(v2); + * + *
+ * + *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(50, 50); + * let v1 = createVector(25, -25); + * drawArrow(v0, v1, 'red'); + * + * let num = map(mouseX, 0, width, -2, 2, true); + * let v2 = p5.Vector.mult(v1, num); + * drawArrow(v0, v2, 'blue'); + * + * noStroke(); + * text('multiplied by ' + num.toFixed(2), 5, 90); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.mult = function mult(n) { + if (!(typeof n === 'number' && isFinite(n))) { + console.warn( + 'p5.Vector.prototype.mult:', + 'n is undefined or not a finite number' + ); + + return this; + } + this.x *= n; + this.y *= n; + this.z *= n; + return this; + }; + + /** + * Divide the vector by a scalar. The static version of this method creates a + * new p5.Vector while the non static version acts on the vector directly. + * See the examples for more context. + * + * @method div + * @param {number} n the number to divide the vector by + * @chainable + * @example + *
+ * + * let v = createVector(6, 4, 2); + * v.div(2); //v's components are set to [3, 2, 1] + * + *
+ * + *
+ * + * // Static method + * let v1 = createVector(6, 4, 2); + * let v2 = p5.Vector.div(v1, 2); + * // v2 has components [3, 2, 1] + * print(v2); + * + *
+ * + *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(0, 100); + * let v1 = createVector(50, -50); + * drawArrow(v0, v1, 'red'); + * + * let num = map(mouseX, 0, width, 10, 0.5, true); + * let v2 = p5.Vector.div(v1, num); + * drawArrow(v0, v2, 'blue'); + * + * noStroke(); + * text('divided by ' + num.toFixed(2), 10, 90); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.div = function div(n) { + if (!(typeof n === 'number' && isFinite(n))) { + console.warn( + 'p5.Vector.prototype.div:', + 'n is undefined or not a finite number' + ); + + return this; + } + if (n === 0) { + console.warn('p5.Vector.prototype.div:', 'divide by 0'); + return this; + } + this.x /= n; + this.y /= n; + this.z /= n; + return this; + }; + + /** + * Calculates the magnitude (length) of the vector and returns the result as + * a float (this is simply the equation sqrt(x*x + y*y + z*z).) + * + * @method mag + * @return {Number} magnitude of the vector + * @example + *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(0, 0); + * let v1 = createVector(mouseX, mouseY); + * drawArrow(v0, v1, 'black'); + * + * noStroke(); + * text('vector length: ' + v1.mag().toFixed(2), 10, 70, 90, 30); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ *
+ * + * let v = createVector(20.0, 30.0, 40.0); + * let m = v.mag(); + * print(m); // Prints "53.85164807134504" + * + *
+ */ + p5.Vector.prototype.mag = function mag() { + return Math.sqrt(this.magSq()); + }; + + /** + * Calculates the squared magnitude of the vector and returns the result + * as a float (this is simply the equation (x*x + y*y + z*z).) + * Faster if the real length is not required in the + * case of comparing vectors, etc. + * + * @method magSq + * @return {number} squared magnitude of the vector + * @example + *
+ * + * // Static method + * let v1 = createVector(6, 4, 2); + * print(v1.magSq()); // Prints "56" + * + *
+ * + *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(0, 0); + * let v1 = createVector(mouseX, mouseY); + * drawArrow(v0, v1, 'black'); + * + * noStroke(); + * text('vector length squared: ' + v1.magSq().toFixed(2), 10, 45, 90, 55); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.magSq = function magSq() { + var x = this.x; + var y = this.y; + var z = this.z; + return x * x + y * y + z * z; + }; + + /** + * Calculates the dot product of two vectors. The version of the method + * that computes the dot product of two independent vectors is a static + * method. See the examples for more context. + * + * + * @method dot + * @param {Number} x x component of the vector + * @param {Number} [y] y component of the vector + * @param {Number} [z] z component of the vector + * @return {Number} the dot product + * + * @example + *
+ * + * let v1 = createVector(1, 2, 3); + * let v2 = createVector(2, 3, 4); + * + * print(v1.dot(v2)); // Prints "20" + * + *
+ * + *
+ * + * //Static method + * let v1 = createVector(1, 2, 3); + * let v2 = createVector(3, 2, 1); + * print(p5.Vector.dot(v1, v2)); // Prints "10" + * + *
+ */ + /** + * @method dot + * @param {p5.Vector} value value component of the vector or a p5.Vector + * @return {Number} + */ + p5.Vector.prototype.dot = function dot(x, y, z) { + if (x instanceof p5.Vector) { + return this.dot(x.x, x.y, x.z); + } + return this.x * (x || 0) + this.y * (y || 0) + this.z * (z || 0); + }; + + /** + * Calculates and returns a vector composed of the cross product between + * two vectors. Both the static and non static methods return a new p5.Vector. + * See the examples for more context. + * + * @method cross + * @param {p5.Vector} v p5.Vector to be crossed + * @return {p5.Vector} p5.Vector composed of cross product + * @example + *
+ * + * let v1 = createVector(1, 2, 3); + * let v2 = createVector(1, 2, 3); + * + * v1.cross(v2); // v's components are [0, 0, 0] + * + *
+ * + *
+ * + * // Static method + * let v1 = createVector(1, 0, 0); + * let v2 = createVector(0, 1, 0); + * + * let crossProduct = p5.Vector.cross(v1, v2); + * // crossProduct has components [0, 0, 1] + * print(crossProduct); + * + *
+ */ + p5.Vector.prototype.cross = function cross(v) { + var x = this.y * v.z - this.z * v.y; + var y = this.z * v.x - this.x * v.z; + var z = this.x * v.y - this.y * v.x; + if (this.p5) { + return new p5.Vector(this.p5, [x, y, z]); + } else { + return new p5.Vector(x, y, z); + } + }; + + /** + * Calculates the Euclidean distance between two points (considering a + * point as a vector object). + * + * @method dist + * @param {p5.Vector} v the x, y, and z coordinates of a p5.Vector + * @return {Number} the distance + * @example + *
+ * + * let v1 = createVector(1, 0, 0); + * let v2 = createVector(0, 1, 0); + * + * let distance = v1.dist(v2); // distance is 1.4142... + * print(distance); + * + *
+ * + *
+ * + * // Static method + * let v1 = createVector(1, 0, 0); + * let v2 = createVector(0, 1, 0); + * + * let distance = p5.Vector.dist(v1, v2); + * // distance is 1.4142... + * print(distance); + * + *
+ * + *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(0, 0); + * + * let v1 = createVector(70, 50); + * drawArrow(v0, v1, 'red'); + * + * let v2 = createVector(mouseX, mouseY); + * drawArrow(v0, v2, 'blue'); + * + * noStroke(); + * text('distance between vectors: ' + v2.dist(v1).toFixed(2), 5, 50, 95, 50); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.dist = function dist(v) { + return v + .copy() + .sub(this) + .mag(); + }; + + /** + * Normalize the vector to length 1 (make it a unit vector). + * + * @method normalize + * @return {p5.Vector} normalized p5.Vector + * @example + *
+ * + * let v = createVector(10, 20, 2); + * // v has components [10.0, 20.0, 2.0] + * v.normalize(); + * // v's components are set to + * // [0.4454354, 0.8908708, 0.089087084] + * + *
+ *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(50, 50); + * let v1 = createVector(mouseX - 50, mouseY - 50); + * + * drawArrow(v0, v1, 'red'); + * v1.normalize(); + * drawArrow(v0, v1.mult(35), 'blue'); + * + * noFill(); + * ellipse(50, 50, 35 * 2); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.normalize = function normalize() { + var len = this.mag(); + // here we multiply by the reciprocal instead of calling 'div()' + // since div duplicates this zero check. + if (len !== 0) this.mult(1 / len); + return this; + }; + + /** + * Limit the magnitude of this vector to the value used for the max + * parameter. + * + * @method limit + * @param {Number} max the maximum magnitude for the vector + * @chainable + * @example + *
+ * + * let v = createVector(10, 20, 2); + * // v has components [10.0, 20.0, 2.0] + * v.limit(5); + * // v's components are set to + * // [2.2271771, 4.4543543, 0.4454354] + * + *
+ *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(50, 50); + * let v1 = createVector(mouseX - 50, mouseY - 50); + * + * drawArrow(v0, v1, 'red'); + * drawArrow(v0, v1.limit(35), 'blue'); + * + * noFill(); + * ellipse(50, 50, 35 * 2); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.limit = function limit(max) { + var mSq = this.magSq(); + if (mSq > max * max) { + this.div(Math.sqrt(mSq)) //normalize it + .mult(max); + } + return this; + }; + + /** + * Set the magnitude of this vector to the value used for the len + * parameter. + * + * @method setMag + * @param {number} len the new length for this vector + * @chainable + * @example + *
+ * + * let v = createVector(10, 20, 2); + * // v has components [10.0, 20.0, 2.0] + * v.setMag(10); + * // v's components are set to [6.0, 8.0, 0.0] + * + *
+ * + *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(0, 0); + * let v1 = createVector(50, 50); + * + * drawArrow(v0, v1, 'red'); + * + * let length = map(mouseX, 0, width, 0, 141, true); + * v1.setMag(length); + * drawArrow(v0, v1, 'blue'); + * + * noStroke(); + * text('magnitude set to: ' + length.toFixed(2), 10, 70, 90, 30); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.setMag = function setMag(n) { + return this.normalize().mult(n); + }; + + /** + * Calculate the angle of rotation for this vector (only 2D vectors) + * + * @method heading + * @return {Number} the angle of rotation + * @example + *
+ * + * function setup() { + * let v1 = createVector(30, 50); + * print(v1.heading()); // 1.0303768265243125 + * + * v1 = createVector(40, 50); + * print(v1.heading()); // 0.8960553845713439 + * + * v1 = createVector(30, 70); + * print(v1.heading()); // 1.1659045405098132 + * } + * + *
+ * + *
+ * + * function draw() { + * background(240); + * + * let v0 = createVector(50, 50); + * let v1 = createVector(mouseX - 50, mouseY - 50); + * + * drawArrow(v0, v1, 'black'); + * + * let myHeading = v1.heading(); + * noStroke(); + * text( + * 'vector heading: ' + + * myHeading.toFixed(2) + + * ' radians or ' + + * degrees(myHeading).toFixed(2) + + * ' degrees', + * 10, + * 50, + * 90, + * 50 + * ); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.heading = function heading() { + var h = Math.atan2(this.y, this.x); + if (this.p5) return this.p5._fromRadians(h); + return h; + }; + + /** + * Rotate the vector by an angle (only 2D vectors), magnitude remains the + * same + * + * @method rotate + * @param {number} angle the angle of rotation + * @chainable + * @example + *
+ * + * let v = createVector(10.0, 20.0); + * // v has components [10.0, 20.0, 0.0] + * v.rotate(HALF_PI); + * // v's components are set to [-20.0, 9.999999, 0.0] + * + *
+ * + *
+ * + * let angle = 0; + * function draw() { + * background(240); + * + * let v0 = createVector(50, 50); + * let v1 = createVector(50, 0); + * + * drawArrow(v0, v1.rotate(angle), 'black'); + * angle += 0.01; + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.rotate = function rotate(a) { + var newHeading = this.heading() + a; + if (this.p5) newHeading = this.p5._toRadians(newHeading); + var mag = this.mag(); + this.x = Math.cos(newHeading) * mag; + this.y = Math.sin(newHeading) * mag; + return this; + }; + + /** + * Calculates and returns the angle (in radians) between two vectors. + * @method angleBetween + * @param {p5.Vector} value the x, y, and z components of a p5.Vector + * @return {Number} the angle between (in radians) + * @example + *
+ * + * let v1 = createVector(1, 0, 0); + * let v2 = createVector(0, 1, 0); + * + * let angle = v1.angleBetween(v2); + * // angle is PI/2 + * print(angle); + * + *
+ * + *
+ * + * function draw() { + * background(240); + * let v0 = createVector(50, 50); + * + * let v1 = createVector(50, 0); + * drawArrow(v0, v1, 'red'); + * + * let v2 = createVector(mouseX - 50, mouseY - 50); + * drawArrow(v0, v2, 'blue'); + * + * let angleBetween = v1.angleBetween(v2); + * noStroke(); + * text( + * 'angle between: ' + + * angleBetween.toFixed(2) + + * ' radians or ' + + * degrees(angleBetween).toFixed(2) + + * ' degrees', + * 10, + * 50, + * 90, + * 50 + * ); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.prototype.angleBetween = function angleBetween(v) { + var dotmagmag = this.dot(v) / (this.mag() * v.mag()); + // Mathematically speaking: the dotmagmag variable will be between -1 and 1 + // inclusive. Practically though it could be slightly outside this range due + // to floating-point rounding issues. This can make Math.acos return NaN. + // + // Solution: we'll clamp the value to the -1,1 range + var angle = Math.acos(Math.min(1, Math.max(-1, dotmagmag))); + if (this.p5) return this.p5._fromRadians(angle); + return angle; + }; + + /** + * Linear interpolate the vector to another vector + * + * @method lerp + * @param {Number} x the x component + * @param {Number} y the y component + * @param {Number} z the z component + * @param {Number} amt the amount of interpolation; some value between 0.0 + * (old vector) and 1.0 (new vector). 0.9 is very near + * the new vector. 0.5 is halfway in between. + * @chainable + * + * @example + *
+ * + * let v = createVector(1, 1, 0); + * + * v.lerp(3, 3, 0, 0.5); // v now has components [2,2,0] + * + *
+ * + *
+ * + * let v1 = createVector(0, 0, 0); + * let v2 = createVector(100, 100, 0); + * + * let v3 = p5.Vector.lerp(v1, v2, 0.5); + * // v3 has components [50,50,0] + * print(v3); + * + *
+ * + *
+ * + * let step = 0.01; + * let amount = 0; + * + * function draw() { + * background(240); + * let v0 = createVector(0, 0); + * + * let v1 = createVector(mouseX, mouseY); + * drawArrow(v0, v1, 'red'); + * + * let v2 = createVector(90, 90); + * drawArrow(v0, v2, 'blue'); + * + * if (amount > 1 || amount < 0) { + * step *= -1; + * } + * amount += step; + * let v3 = p5.Vector.lerp(v1, v2, amount); + * + * drawArrow(v0, v3, 'purple'); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + /** + * @method lerp + * @param {p5.Vector} v the p5.Vector to lerp to + * @param {Number} amt + * @chainable + */ + p5.Vector.prototype.lerp = function lerp(x, y, z, amt) { + if (x instanceof p5.Vector) { + return this.lerp(x.x, x.y, x.z, y); + } + this.x += (x - this.x) * amt || 0; + this.y += (y - this.y) * amt || 0; + this.z += (z - this.z) * amt || 0; + return this; + }; + + /** + * Return a representation of this vector as a float array. This is only + * for temporary use. If used in any other fashion, the contents should be + * copied by using the p5.Vector.copy() method to copy into your own + * array. + * + * @method array + * @return {Number[]} an Array with the 3 values + * @example + *
+ * + * function setup() { + * let v = createVector(20, 30); + * print(v.array()); // Prints : Array [20, 30, 0] + * } + * + *
+ * + *
+ * + * let v = createVector(10.0, 20.0, 30.0); + * let f = v.array(); + * print(f[0]); // Prints "10.0" + * print(f[1]); // Prints "20.0" + * print(f[2]); // Prints "30.0" + * + *
+ */ + p5.Vector.prototype.array = function array() { + return [this.x || 0, this.y || 0, this.z || 0]; + }; + + /** + * Equality check against a p5.Vector + * + * @method equals + * @param {Number} [x] the x component of the vector + * @param {Number} [y] the y component of the vector + * @param {Number} [z] the z component of the vector + * @return {Boolean} whether the vectors are equals + * @example + *
+ * + * let v1 = createVector(5, 10, 20); + * let v2 = createVector(5, 10, 20); + * let v3 = createVector(13, 10, 19); + * + * print(v1.equals(v2.x, v2.y, v2.z)); // true + * print(v1.equals(v3.x, v3.y, v3.z)); // false + * + *
+ * + *
+ * + * let v1 = createVector(10.0, 20.0, 30.0); + * let v2 = createVector(10.0, 20.0, 30.0); + * let v3 = createVector(0.0, 0.0, 0.0); + * print(v1.equals(v2)); // true + * print(v1.equals(v3)); // false + * + *
+ */ + /** + * @method equals + * @param {p5.Vector|Array} value the vector to compare + * @return {Boolean} + */ + p5.Vector.prototype.equals = function equals(x, y, z) { + var a, b, c; + if (x instanceof p5.Vector) { + a = x.x || 0; + b = x.y || 0; + c = x.z || 0; + } else if (x instanceof Array) { + a = x[0] || 0; + b = x[1] || 0; + c = x[2] || 0; + } else { + a = x || 0; + b = y || 0; + c = z || 0; + } + return this.x === a && this.y === b && this.z === c; + }; + + // Static Methods + + /** + * Make a new 2D vector from an angle + * + * @method fromAngle + * @static + * @param {Number} angle the desired angle, in radians (unaffected by angleMode) + * @param {Number} [length] the length of the new vector (defaults to 1) + * @return {p5.Vector} the new p5.Vector object + * @example + *
+ * + * function draw() { + * background(200); + * + * // Create a variable, proportional to the mouseX, + * // varying from 0-360, to represent an angle in degrees. + * let myDegrees = map(mouseX, 0, width, 0, 360); + * + * // Display that variable in an onscreen text. + * // (Note the nfc() function to truncate additional decimal places, + * // and the "\xB0" character for the degree symbol.) + * let readout = 'angle = ' + nfc(myDegrees, 1) + '\xB0'; + * noStroke(); + * fill(0); + * text(readout, 5, 15); + * + * // Create a p5.Vector using the fromAngle function, + * // and extract its x and y components. + * let v = p5.Vector.fromAngle(radians(myDegrees), 30); + * let vx = v.x; + * let vy = v.y; + * + * push(); + * translate(width / 2, height / 2); + * noFill(); + * stroke(150); + * line(0, 0, 30, 0); + * stroke(0); + * line(0, 0, vx, vy); + * pop(); + * } + * + *
+ */ + p5.Vector.fromAngle = function fromAngle(angle, length) { + if (typeof length === 'undefined') { + length = 1; + } + return new p5.Vector(length * Math.cos(angle), length * Math.sin(angle), 0); + }; + + /** + * Make a new 3D vector from a pair of ISO spherical angles + * + * @method fromAngles + * @static + * @param {Number} theta the polar angle, in radians (zero is up) + * @param {Number} phi the azimuthal angle, in radians + * (zero is out of the screen) + * @param {Number} [length] the length of the new vector (defaults to 1) + * @return {p5.Vector} the new p5.Vector object + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * fill(255); + * noStroke(); + * } + * function draw() { + * background(255); + * + * let t = millis() / 1000; + * + * // add three point lights + * pointLight(color('#f00'), p5.Vector.fromAngles(t * 1.0, t * 1.3, 100)); + * pointLight(color('#0f0'), p5.Vector.fromAngles(t * 1.1, t * 1.2, 100)); + * pointLight(color('#00f'), p5.Vector.fromAngles(t * 1.2, t * 1.1, 100)); + * + * sphere(35); + * } + * + *
+ */ + p5.Vector.fromAngles = function(theta, phi, length) { + if (typeof length === 'undefined') { + length = 1; + } + var cosPhi = Math.cos(phi); + var sinPhi = Math.sin(phi); + var cosTheta = Math.cos(theta); + var sinTheta = Math.sin(theta); + + return new p5.Vector( + length * sinTheta * sinPhi, + -length * cosTheta, + length * sinTheta * cosPhi + ); + }; + + /** + * Make a new 2D unit vector from a random angle + * + * @method random2D + * @static + * @return {p5.Vector} the new p5.Vector object + * @example + *
+ * + * let v = p5.Vector.random2D(); + * // May make v's attributes something like: + * // [0.61554617, -0.51195765, 0.0] or + * // [-0.4695841, -0.14366731, 0.0] or + * // [0.6091097, -0.22805278, 0.0] + * print(v); + * + *
+ * + *
+ * + * function setup() { + * frameRate(1); + * } + * + * function draw() { + * background(240); + * + * let v0 = createVector(50, 50); + * let v1 = p5.Vector.random2D(); + * drawArrow(v0, v1.mult(50), 'black'); + * } + * + * // draw an arrow for a vector at a given base position + * function drawArrow(base, vec, myColor) { + * push(); + * stroke(myColor); + * strokeWeight(3); + * fill(myColor); + * translate(base.x, base.y); + * line(0, 0, vec.x, vec.y); + * rotate(vec.heading()); + * let arrowSize = 7; + * translate(vec.mag() - arrowSize, 0); + * triangle(0, arrowSize / 2, 0, -arrowSize / 2, arrowSize, 0); + * pop(); + * } + * + *
+ */ + p5.Vector.random2D = function random2D() { + return this.fromAngle(Math.random() * constants.TWO_PI); + }; + + /** + * Make a new random 3D unit vector. + * + * @method random3D + * @static + * @return {p5.Vector} the new p5.Vector object + * @example + *
+ * + * let v = p5.Vector.random3D(); + * // May make v's attributes something like: + * // [0.61554617, -0.51195765, 0.599168] or + * // [-0.4695841, -0.14366731, -0.8711202] or + * // [0.6091097, -0.22805278, -0.7595902] + * print(v); + * + *
+ */ + p5.Vector.random3D = function random3D() { + var angle = Math.random() * constants.TWO_PI; + var vz = Math.random() * 2 - 1; + var vzBase = Math.sqrt(1 - vz * vz); + var vx = vzBase * Math.cos(angle); + var vy = vzBase * Math.sin(angle); + return new p5.Vector(vx, vy, vz); + }; + + // Adds two vectors together and returns a new one. + /** + * @method add + * @static + * @param {p5.Vector} v1 a p5.Vector to add + * @param {p5.Vector} v2 a p5.Vector to add + * @param {p5.Vector} target the vector to receive the result + */ + /** + * @method add + * @static + * @param {p5.Vector} v1 + * @param {p5.Vector} v2 + * @return {p5.Vector} the resulting p5.Vector + * + */ + + p5.Vector.add = function add(v1, v2, target) { + if (!target) { + target = v1.copy(); + } else { + target.set(v1); + } + target.add(v2); + return target; + }; + + /* + * Subtracts one p5.Vector from another and returns a new one. The second + * vector (v2) is subtracted from the first (v1), resulting in v1-v2. + */ + /** + * @method sub + * @static + * @param {p5.Vector} v1 a p5.Vector to subtract from + * @param {p5.Vector} v2 a p5.Vector to subtract + * @param {p5.Vector} target if undefined a new vector will be created + */ + /** + * @method sub + * @static + * @param {p5.Vector} v1 + * @param {p5.Vector} v2 + * @return {p5.Vector} the resulting p5.Vector + */ + + p5.Vector.sub = function sub(v1, v2, target) { + if (!target) { + target = v1.copy(); + } else { + target.set(v1); + } + target.sub(v2); + return target; + }; + + /** + * Multiplies a vector by a scalar and returns a new vector. + */ + /** + * @method mult + * @static + * @param {p5.Vector} v the vector to multiply + * @param {Number} n + * @param {p5.Vector} target if undefined a new vector will be created + */ + /** + * @method mult + * @static + * @param {p5.Vector} v + * @param {Number} n + * @return {p5.Vector} the resulting new p5.Vector + */ + p5.Vector.mult = function mult(v, n, target) { + if (!target) { + target = v.copy(); + } else { + target.set(v); + } + target.mult(n); + return target; + }; + + /** + * Divides a vector by a scalar and returns a new vector. + */ + /** + * @method div + * @static + * @param {p5.Vector} v the vector to divide + * @param {Number} n + * @param {p5.Vector} target if undefined a new vector will be created + */ + /** + * @method div + * @static + * @param {p5.Vector} v + * @param {Number} n + * @return {p5.Vector} the resulting new p5.Vector + */ + p5.Vector.div = function div(v, n, target) { + if (!target) { + target = v.copy(); + } else { + target.set(v); + } + target.div(n); + return target; + }; + + /** + * Calculates the dot product of two vectors. + */ + /** + * @method dot + * @static + * @param {p5.Vector} v1 the first p5.Vector + * @param {p5.Vector} v2 the second p5.Vector + * @return {Number} the dot product + */ + p5.Vector.dot = function dot(v1, v2) { + return v1.dot(v2); + }; + + /** + * Calculates the cross product of two vectors. + */ + /** + * @method cross + * @static + * @param {p5.Vector} v1 the first p5.Vector + * @param {p5.Vector} v2 the second p5.Vector + * @return {Number} the cross product + */ + p5.Vector.cross = function cross(v1, v2) { + return v1.cross(v2); + }; + + /** + * Calculates the Euclidean distance between two points (considering a + * point as a vector object). + */ + /** + * @method dist + * @static + * @param {p5.Vector} v1 the first p5.Vector + * @param {p5.Vector} v2 the second p5.Vector + * @return {Number} the distance + */ + p5.Vector.dist = function dist(v1, v2) { + return v1.dist(v2); + }; + + /** + * Linear interpolate a vector to another vector and return the result as a + * new vector. + */ + /** + * @method lerp + * @static + * @param {p5.Vector} v1 + * @param {p5.Vector} v2 + * @param {Number} amt + * @param {p5.Vector} target if undefined a new vector will be created + */ + /** + * @method lerp + * @static + * @param {p5.Vector} v1 + * @param {p5.Vector} v2 + * @param {Number} amt + * @return {Number} the lerped value + */ + p5.Vector.lerp = function lerp(v1, v2, amt, target) { + if (!target) { + target = v1.copy(); + } else { + target.set(v1); + } + target.lerp(v2, amt); + return target; + }; + + /** + * @method mag + * @param {p5.Vector} vecT the vector to return the magnitude of + * @return {Number} the magnitude of vecT + * @static + */ + p5.Vector.mag = function mag(vecT) { + var x = vecT.x, + y = vecT.y, + z = vecT.z; + var magSq = x * x + y * y + z * z; + return Math.sqrt(magSq); + }; + + module.exports = p5.Vector; + }, + { '../core/constants': 18, '../core/main': 24 } + ], + 56: [ + function(_dereq_, module, exports) { + /** + * @module Math + * @submodule Random + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + var seeded = false; + var previous = false; + var y2 = 0; + + // Linear Congruential Generator + // Variant of a Lehman Generator + var lcg = (function() { + // Set to values from glibc(useb by GCC) (https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use) + // m is basically chosen to be large (as it is the max period) + // and for its relationships to a and c + var m = 2147483647, + // a - 1 should be divisible by m's prime factors + a = 1103515245, + // c and m should be co-prime + c = 12345, + seed, + z; + return { + setSeed: function setSeed(val) { + // pick a random seed if val is undefined or null + // the >>> 0 casts the seed to an unsigned 32-bit integer + z = seed = (val == null ? Math.random() * m : val) >>> 0; + }, + getSeed: function getSeed() { + return seed; + }, + rand: function rand() { + // define the recurrence relationship + z = (a * z + c) % m; + // return a float in [0, 1) + // if z = m then z / m = 0 therefore (z % m) / m < 1 always + return z / m; + } + }; + })(); + + /** + * Sets the seed value for random(). + * + * By default, random() produces different results each time the program + * is run. Set the seed parameter to a constant to return the same + * pseudo-random numbers each time the software is run. + * + * @method randomSeed + * @param {Number} seed the seed value + * @example + *
+ * + * randomSeed(99); + * for (let i = 0; i < 100; i++) { + * let r = random(0, 255); + * stroke(r); + * line(i, 0, i, 100); + * } + * + *
+ * + * @alt + * many vertical lines drawn in white, black or grey. + * + */ + p5.prototype.randomSeed = function(seed) { + lcg.setSeed(seed); + seeded = true; + previous = false; + }; + + /** + * Return a random floating-point number. + * + * Takes either 0, 1 or 2 arguments. + * + * If no argument is given, returns a random number from 0 + * up to (but not including) 1. + * + * If one argument is given and it is a number, returns a random number from 0 + * up to (but not including) the number. + * + * If one argument is given and it is an array, returns a random element from + * that array. + * + * If two arguments are given, returns a random number from the + * first argument up to (but not including) the second argument. + * + * @method random + * @param {Number} [min] the lower bound (inclusive) + * @param {Number} [max] the upper bound (exclusive) + * @return {Number} the random number + * @example + *
+ * + * for (let i = 0; i < 100; i++) { + * let r = random(50); + * stroke(r * 5); + * line(50, i, 50 + r, i); + * } + * + *
+ *
+ * + * for (let i = 0; i < 100; i++) { + * let r = random(-50, 50); + * line(50, i, 50 + r, i); + * } + * + *
+ *
+ * + * // Get a random element from an array using the random(Array) syntax + * let words = ['apple', 'bear', 'cat', 'dog']; + * let word = random(words); // select random word + * text(word, 10, 50); // draw the word + * + *
+ * + * @alt + * 100 horizontal lines from center canvas to right. size+fill change each time + * 100 horizontal lines from center of canvas. height & side change each render + * word displayed at random. Either apple, bear, cat, or dog + * + */ + /** + * @method random + * @param {Array} choices the array to choose from + * @return {*} the random element from the array + * @example + */ + p5.prototype.random = function(min, max) { + var rand; + + if (seeded) { + rand = lcg.rand(); + } else { + rand = Math.random(); + } + if (typeof min === 'undefined') { + return rand; + } else if (typeof max === 'undefined') { + if (min instanceof Array) { + return min[Math.floor(rand * min.length)]; + } else { + return rand * min; + } + } else { + if (min > max) { + var tmp = min; + min = max; + max = tmp; + } + + return rand * (max - min) + min; + } + }; + + /** + * + * Returns a random number fitting a Gaussian, or + * normal, distribution. There is theoretically no minimum or maximum + * value that randomGaussian() might return. Rather, there is + * just a very low probability that values far from the mean will be + * returned; and a higher probability that numbers near the mean will + * be returned. + *

+ * Takes either 0, 1 or 2 arguments.
+ * If no args, returns a mean of 0 and standard deviation of 1.
+ * If one arg, that arg is the mean (standard deviation is 1).
+ * If two args, first is mean, second is standard deviation. + * + * @method randomGaussian + * @param {Number} mean the mean + * @param {Number} sd the standard deviation + * @return {Number} the random number + * @example + *
+ * + * for (let y = 0; y < 100; y++) { + * let x = randomGaussian(50, 15); + * line(50, y, x, y); + * } + * + *
+ *
+ * + * let distribution = new Array(360); + * + * function setup() { + * createCanvas(100, 100); + * for (let i = 0; i < distribution.length; i++) { + * distribution[i] = floor(randomGaussian(0, 15)); + * } + * } + * + * function draw() { + * background(204); + * + * translate(width / 2, width / 2); + * + * for (let i = 0; i < distribution.length; i++) { + * rotate(TWO_PI / distribution.length); + * stroke(0); + * let dist = abs(distribution[i]); + * line(0, 0, dist, 0); + * } + * } + * + *
+ * @alt + * 100 horizontal lines from center of canvas. height & side change each render + * black lines radiate from center of canvas. size determined each render + */ + p5.prototype.randomGaussian = function(mean, sd) { + var y1, x1, x2, w; + if (previous) { + y1 = y2; + previous = false; + } else { + do { + x1 = this.random(2) - 1; + x2 = this.random(2) - 1; + w = x1 * x1 + x2 * x2; + } while (w >= 1); + w = Math.sqrt(-2 * Math.log(w) / w); + y1 = x1 * w; + y2 = x2 * w; + previous = true; + } + + var m = mean || 0; + var s = sd || 1; + return y1 * s + m; + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 57: [ + function(_dereq_, module, exports) { + /** + * @module Math + * @submodule Trigonometry + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + + /* + * all DEGREES/RADIANS conversion should be done in the p5 instance + * if possible, using the p5._toRadians(), p5._fromRadians() methods. + */ + p5.prototype._angleMode = constants.RADIANS; + + /** + * The inverse of cos(), returns the arc cosine of a value. This function + * expects the values in the range of -1 to 1 and values are returned in + * the range 0 to PI (3.1415927). + * + * @method acos + * @param {Number} value the value whose arc cosine is to be returned + * @return {Number} the arc cosine of the given value + * + * @example + *
+ * + * let a = PI; + * let c = cos(a); + * let ac = acos(c); + * // Prints: "3.1415927 : -1.0 : 3.1415927" + * print(a + ' : ' + c + ' : ' + ac); + * + *
+ * + *
+ * + * let a = PI + PI / 4.0; + * let c = cos(a); + * let ac = acos(c); + * // Prints: "3.926991 : -0.70710665 : 2.3561943" + * print(a + ' : ' + c + ' : ' + ac); + * + *
+ */ + p5.prototype.acos = function(ratio) { + return this._fromRadians(Math.acos(ratio)); + }; + + /** + * The inverse of sin(), returns the arc sine of a value. This function + * expects the values in the range of -1 to 1 and values are returned + * in the range -PI/2 to PI/2. + * + * @method asin + * @param {Number} value the value whose arc sine is to be returned + * @return {Number} the arc sine of the given value + * + * @example + *
+ * + * let a = PI + PI / 3; + * let s = sin(a); + * let as = asin(s); + * // Prints: "1.0471976 : 0.86602545 : 1.0471976" + * print(a + ' : ' + s + ' : ' + as); + * + *
+ * + *
+ * + * let a = PI + PI / 3.0; + * let s = sin(a); + * let as = asin(s); + * // Prints: "4.1887903 : -0.86602545 : -1.0471976" + * print(a + ' : ' + s + ' : ' + as); + * + *
+ * + */ + p5.prototype.asin = function(ratio) { + return this._fromRadians(Math.asin(ratio)); + }; + + /** + * The inverse of tan(), returns the arc tangent of a value. This function + * expects the values in the range of -Infinity to Infinity (exclusive) and + * values are returned in the range -PI/2 to PI/2. + * + * @method atan + * @param {Number} value the value whose arc tangent is to be returned + * @return {Number} the arc tangent of the given value + * + * @example + *
+ * + * let a = PI + PI / 3; + * let t = tan(a); + * let at = atan(t); + * // Prints: "1.0471976 : 1.7320509 : 1.0471976" + * print(a + ' : ' + t + ' : ' + at); + * + *
+ * + *
+ * + * let a = PI + PI / 3.0; + * let t = tan(a); + * let at = atan(t); + * // Prints: "4.1887903 : 1.7320513 : 1.0471977" + * print(a + ' : ' + t + ' : ' + at); + * + *
+ * + */ + p5.prototype.atan = function(ratio) { + return this._fromRadians(Math.atan(ratio)); + }; + + /** + * Calculates the angle (in radians) from a specified point to the coordinate + * origin as measured from the positive x-axis. Values are returned as a + * float in the range from PI to -PI. The atan2() function is most often used + * for orienting geometry to the position of the cursor. + *

+ * Note: The y-coordinate of the point is the first parameter, and the + * x-coordinate is the second parameter, due the the structure of calculating + * the tangent. + * + * @method atan2 + * @param {Number} y y-coordinate of the point + * @param {Number} x x-coordinate of the point + * @return {Number} the arc tangent of the given point + * + * @example + *
+ * + * function draw() { + * background(204); + * translate(width / 2, height / 2); + * let a = atan2(mouseY - height / 2, mouseX - width / 2); + * rotate(a); + * rect(-30, -5, 60, 10); + * } + * + *
+ * + * @alt + * 60 by 10 rect at center of canvas rotates with mouse movements + * + */ + p5.prototype.atan2 = function(y, x) { + return this._fromRadians(Math.atan2(y, x)); + }; + + /** + * Calculates the cosine of an angle. This function takes into account the + * current angleMode. Values are returned in the range -1 to 1. + * + * @method cos + * @param {Number} angle the angle + * @return {Number} the cosine of the angle + * + * @example + *
+ * + * let a = 0.0; + * let inc = TWO_PI / 25.0; + * for (let i = 0; i < 25; i++) { + * line(i * 4, 50, i * 4, 50 + cos(a) * 40.0); + * a = a + inc; + * } + * + *
+ * + * @alt + * vertical black lines form wave patterns, extend-down on left and right side + * + */ + p5.prototype.cos = function(angle) { + return Math.cos(this._toRadians(angle)); + }; + + /** + * Calculates the sine of an angle. This function takes into account the + * current angleMode. Values are returned in the range -1 to 1. + * + * @method sin + * @param {Number} angle the angle + * @return {Number} the sine of the angle + * + * @example + *
+ * + * let a = 0.0; + * let inc = TWO_PI / 25.0; + * for (let i = 0; i < 25; i++) { + * line(i * 4, 50, i * 4, 50 + sin(a) * 40.0); + * a = a + inc; + * } + * + *
+ * + * @alt + * vertical black lines extend down and up from center to form wave pattern + * + */ + p5.prototype.sin = function(angle) { + return Math.sin(this._toRadians(angle)); + }; + + /** + * Calculates the tangent of an angle. This function takes into account + * the current angleMode. Values are returned in the range -1 to 1. + * + * @method tan + * @param {Number} angle the angle + * @return {Number} the tangent of the angle + * + * @example + *
+ * + * let a = 0.0; + * let inc = TWO_PI / 50.0; + * for (let i = 0; i < 100; i = i + 2) { + * line(i, 50, i, 50 + tan(a) * 2.0); + * a = a + inc; + * } + * + * + * + * @alt + * vertical black lines end down and up from center to form spike pattern + * + */ + p5.prototype.tan = function(angle) { + return Math.tan(this._toRadians(angle)); + }; + + /** + * Converts a radian measurement to its corresponding value in degrees. + * Radians and degrees are two ways of measuring the same thing. There are + * 360 degrees in a circle and 2*PI radians in a circle. For example, + * 90° = PI/2 = 1.5707964. This function does not take into account the + * current angleMode. + * + * @method degrees + * @param {Number} radians the radians value to convert to degrees + * @return {Number} the converted angle + * + * + * @example + *
+ * + * let rad = PI / 4; + * let deg = degrees(rad); + * print(rad + ' radians is ' + deg + ' degrees'); + * // Prints: 0.7853981633974483 radians is 45 degrees + * + *
+ * + */ + p5.prototype.degrees = function(angle) { + return angle * constants.RAD_TO_DEG; + }; + + /** + * Converts a degree measurement to its corresponding value in radians. + * Radians and degrees are two ways of measuring the same thing. There are + * 360 degrees in a circle and 2*PI radians in a circle. For example, + * 90° = PI/2 = 1.5707964. This function does not take into account the + * current angleMode. + * + * @method radians + * @param {Number} degrees the degree value to convert to radians + * @return {Number} the converted angle + * + * @example + *
+ * + * let deg = 45.0; + * let rad = radians(deg); + * print(deg + ' degrees is ' + rad + ' radians'); + * // Prints: 45 degrees is 0.7853981633974483 radians + * + *
+ */ + p5.prototype.radians = function(angle) { + return angle * constants.DEG_TO_RAD; + }; + + /** + * Sets the current mode of p5 to given mode. Default mode is RADIANS. + * + * @method angleMode + * @param {Constant} mode either RADIANS or DEGREES + * + * @example + *
+ * + * function draw() { + * background(204); + * angleMode(DEGREES); // Change the mode to DEGREES + * let a = atan2(mouseY - height / 2, mouseX - width / 2); + * translate(width / 2, height / 2); + * push(); + * rotate(a); + * rect(-20, -5, 40, 10); // Larger rectangle is rotating in degrees + * pop(); + * angleMode(RADIANS); // Change the mode to RADIANS + * rotate(a); // variable a stays the same + * rect(-40, -5, 20, 10); // Smaller rectangle is rotating in radians + * } + * + *
+ * + * @alt + * 40 by 10 rect in center rotates with mouse moves. 20 by 10 rect moves faster. + * + * + */ + p5.prototype.angleMode = function(mode) { + if (mode === constants.DEGREES || mode === constants.RADIANS) { + this._angleMode = mode; + } + }; + + /** + * converts angles from the current angleMode to RADIANS + * + * @method _toRadians + * @private + * @param {Number} angle + * @returns {Number} + */ + p5.prototype._toRadians = function(angle) { + if (this._angleMode === constants.DEGREES) { + return angle * constants.DEG_TO_RAD; + } + return angle; + }; + + /** + * converts angles from the current angleMode to DEGREES + * + * @method _toDegrees + * @private + * @param {Number} angle + * @returns {Number} + */ + p5.prototype._toDegrees = function(angle) { + if (this._angleMode === constants.RADIANS) { + return angle * constants.RAD_TO_DEG; + } + return angle; + }; + + /** + * converts angles from RADIANS into the current angleMode + * + * @method _fromRadians + * @private + * @param {Number} angle + * @returns {Number} + */ + p5.prototype._fromRadians = function(angle) { + if (this._angleMode === constants.DEGREES) { + return angle * constants.RAD_TO_DEG; + } + return angle; + }; + + module.exports = p5; + }, + { '../core/constants': 18, '../core/main': 24 } + ], + 58: [ + function(_dereq_, module, exports) { + /** + * @module Typography + * @submodule Attributes + * @for p5 + * @requires core + * @requires constants + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * Sets the current alignment for drawing text. Accepts two + * arguments: horizAlign (LEFT, CENTER, or RIGHT) and + * vertAlign (TOP, BOTTOM, CENTER, or BASELINE). + * + * The horizAlign parameter is in reference to the x value + * of the text() function, while the vertAlign parameter is + * in reference to the y value. + * + * So if you write textAlign(LEFT), you are aligning the left + * edge of your text to the x value you give in text(). If you + * write textAlign(RIGHT, TOP), you are aligning the right edge + * of your text to the x value and the top of edge of the text + * to the y value. + * + * @method textAlign + * @param {Constant} horizAlign horizontal alignment, either LEFT, + * CENTER, or RIGHT + * @param {Constant} [vertAlign] vertical alignment, either TOP, + * BOTTOM, CENTER, or BASELINE + * @chainable + * @example + *
+ * + * textSize(16); + * textAlign(RIGHT); + * text('ABCD', 50, 30); + * textAlign(CENTER); + * text('EFGH', 50, 50); + * textAlign(LEFT); + * text('IJKL', 50, 70); + * + *
+ * + *
+ * + * textSize(16); + * strokeWeight(0.5); + * + * line(0, 12, width, 12); + * textAlign(CENTER, TOP); + * text('TOP', 0, 12, width); + * + * line(0, 37, width, 37); + * textAlign(CENTER, CENTER); + * text('CENTER', 0, 37, width); + * + * line(0, 62, width, 62); + * textAlign(CENTER, BASELINE); + * text('BASELINE', 0, 62, width); + * + * line(0, 87, width, 87); + * textAlign(CENTER, BOTTOM); + * text('BOTTOM', 0, 87, width); + * + *
+ * + * @alt + *Letters ABCD displayed at top right, EFGH at center and IJKL at bottom left. + * The names of the four vertical alignments rendered each showing that alignment's placement relative to a horizontal line. + * + */ + /** + * @method textAlign + * @return {Object} + */ + p5.prototype.textAlign = function(horizAlign, vertAlign) { + p5._validateParameters('textAlign', arguments); + return this._renderer.textAlign.apply(this._renderer, arguments); + }; + + /** + * Sets/gets the spacing, in pixels, between lines of text. This + * setting will be used in all subsequent calls to the text() function. + * + * @method textLeading + * @param {Number} leading the size in pixels for spacing between lines + * @chainable + * + * @example + *
+ * + * // Text to display. The "\n" is a "new line" character + * let lines = 'L1\nL2\nL3'; + * textSize(12); + * + * textLeading(10); // Set leading to 10 + * text(lines, 10, 25); + * + * textLeading(20); // Set leading to 20 + * text(lines, 40, 25); + * + * textLeading(30); // Set leading to 30 + * text(lines, 70, 25); + * + *
+ * + * @alt + *set L1 L2 & L3 displayed vertically 3 times. spacing increases for each set + */ + /** + * @method textLeading + * @return {Number} + */ + p5.prototype.textLeading = function(theLeading) { + p5._validateParameters('textLeading', arguments); + return this._renderer.textLeading.apply(this._renderer, arguments); + }; + + /** + * Sets/gets the current font size. This size will be used in all subsequent + * calls to the text() function. Font size is measured in pixels. + * + * @method textSize + * @param {Number} theSize the size of the letters in units of pixels + * @chainable + * + * @example + *
+ * + * textSize(12); + * text('Font Size 12', 10, 30); + * textSize(14); + * text('Font Size 14', 10, 60); + * textSize(16); + * text('Font Size 16', 10, 90); + * + *
+ * + * @alt + *Font Size 12 displayed small, Font Size 14 medium & Font Size 16 large + */ + /** + * @method textSize + * @return {Number} + */ + p5.prototype.textSize = function(theSize) { + p5._validateParameters('textSize', arguments); + return this._renderer.textSize.apply(this._renderer, arguments); + }; + + /** + * Sets/gets the style of the text for system fonts to NORMAL, ITALIC, BOLD or BOLDITALIC. + * Note: this may be is overridden by CSS styling. For non-system fonts + * (opentype, truetype, etc.) please load styled fonts instead. + * + * @method textStyle + * @param {Constant} theStyle styling for text, either NORMAL, + * ITALIC, BOLD or BOLDITALIC + * @chainable + * @example + *
+ * + * strokeWeight(0); + * textSize(12); + * textStyle(NORMAL); + * text('Font Style Normal', 10, 15); + * textStyle(ITALIC); + * text('Font Style Italic', 10, 40); + * textStyle(BOLD); + * text('Font Style Bold', 10, 65); + * textStyle(BOLDITALIC); + * text('Font Style Bold Italic', 10, 90); + * + *
+ * + * @alt + *words Font Style Normal displayed normally, Italic in italic, bold in bold and bold italic in bold italics. + */ + /** + * @method textStyle + * @return {String} + */ + p5.prototype.textStyle = function(theStyle) { + p5._validateParameters('textStyle', arguments); + return this._renderer.textStyle.apply(this._renderer, arguments); + }; + + /** + * Calculates and returns the width of any character or text string. + * + * @method textWidth + * @param {String} theText the String of characters to measure + * @return {Number} + * @example + *
+ * + * textSize(28); + * + * let aChar = 'P'; + * let cWidth = textWidth(aChar); + * text(aChar, 0, 40); + * line(cWidth, 0, cWidth, 50); + * + * let aString = 'p5.js'; + * let sWidth = textWidth(aString); + * text(aString, 0, 85); + * line(sWidth, 50, sWidth, 100); + * + *
+ * + * @alt + *Letter P and p5.js are displayed with vertical lines at end. P is wide + * + */ + p5.prototype.textWidth = function(theText) { + p5._validateParameters('textWidth', arguments); + if (theText.length === 0) { + return 0; + } + return this._renderer.textWidth.apply(this._renderer, arguments); + }; + + /** + * Returns the ascent of the current font at its current size. The ascent + * represents the distance, in pixels, of the tallest character above + * the baseline. + * @method textAscent + * @return {Number} + * @example + *
+ * + * let base = height * 0.75; + * let scalar = 0.8; // Different for each font + * + * textSize(32); // Set initial text size + * let asc = textAscent() * scalar; // Calc ascent + * line(0, base - asc, width, base - asc); + * text('dp', 0, base); // Draw text on baseline + * + * textSize(64); // Increase text size + * asc = textAscent() * scalar; // Recalc ascent + * line(40, base - asc, width, base - asc); + * text('dp', 40, base); // Draw text on baseline + * + *
+ */ + p5.prototype.textAscent = function() { + p5._validateParameters('textAscent', arguments); + return this._renderer.textAscent(); + }; + + /** + * Returns the descent of the current font at its current size. The descent + * represents the distance, in pixels, of the character with the longest + * descender below the baseline. + * @method textDescent + * @return {Number} + * @example + *
+ * + * let base = height * 0.75; + * let scalar = 0.8; // Different for each font + * + * textSize(32); // Set initial text size + * let desc = textDescent() * scalar; // Calc ascent + * line(0, base + desc, width, base + desc); + * text('dp', 0, base); // Draw text on baseline + * + * textSize(64); // Increase text size + * desc = textDescent() * scalar; // Recalc ascent + * line(40, base + desc, width, base + desc); + * text('dp', 40, base); // Draw text on baseline + * + *
+ */ + p5.prototype.textDescent = function() { + p5._validateParameters('textDescent', arguments); + return this._renderer.textDescent(); + }; + + /** + * Helper function to measure ascent and descent. + */ + p5.prototype._updateTextMetrics = function() { + return this._renderer._updateTextMetrics(); + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 59: [ + function(_dereq_, module, exports) { + /** + * @module Typography + * @submodule Loading & Displaying + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + var opentype = _dereq_('opentype.js'); + + _dereq_('../core/error_helpers'); + + /** + * Loads an opentype font file (.otf, .ttf) from a file or a URL, + * and returns a PFont Object. This method is asynchronous, + * meaning it may not finish before the next line in your sketch + * is executed. + *

+ * The path to the font should be relative to the HTML file + * that links in your sketch. Loading fonts from a URL or other + * remote location may be blocked due to your browser's built-in + * security. + * + * @method loadFont + * @param {String} path name of the file or url to load + * @param {Function} [callback] function to be executed after + * loadFont() completes + * @param {Function} [onError] function to be executed if + * an error occurs + * @return {p5.Font} p5.Font object + * @example + * + *

Calling loadFont() inside preload() guarantees that the load + * operation will have completed before setup() and draw() are called.

+ * + *
+ * let myFont; + * function preload() { + * myFont = loadFont('assets/inconsolata.otf'); + * } + * + * function setup() { + * fill('#ED225D'); + * textFont(myFont); + * textSize(36); + * text('p5*js', 10, 50); + * } + *
+ * + * Outside of preload(), you may supply a callback function to handle the + * object: + * + *
+ * function setup() { + * loadFont('assets/inconsolata.otf', drawText); + * } + * + * function drawText(font) { + * fill('#ED225D'); + * textFont(font, 36); + * text('p5*js', 10, 50); + * } + *
+ * + *

You can also use the font filename string (without the file extension) to style other HTML + * elements.

+ * + *
+ * function preload() { + * loadFont('assets/inconsolata.otf'); + * } + * + * function setup() { + * let myDiv = createDiv('hello there'); + * myDiv.style('font-family', 'Inconsolata'); + * } + *
+ * + * @alt + * p5*js in p5's theme dark pink + * p5*js in p5's theme dark pink + * + */ + p5.prototype.loadFont = function(path, onSuccess, onError) { + p5._validateParameters('loadFont', arguments); + var p5Font = new p5.Font(this); + + var self = this; + opentype.load(path, function(err, font) { + if (err) { + p5._friendlyFileLoadError(4, path); + if (typeof onError !== 'undefined') { + return onError(err); + } + console.error(err, path); + return; + } + + p5Font.font = font; + + if (typeof onSuccess !== 'undefined') { + onSuccess(p5Font); + } + + self._decrementPreload(); + + // check that we have an acceptable font type + var validFontTypes = ['ttf', 'otf', 'woff', 'woff2'], + fileNoPath = path + .split('\\') + .pop() + .split('/') + .pop(), + lastDotIdx = fileNoPath.lastIndexOf('.'), + fontFamily, + newStyle, + fileExt = lastDotIdx < 1 ? null : fileNoPath.substr(lastDotIdx + 1); + + // if so, add it to the DOM (name-only) for use with p5.dom + if (validFontTypes.indexOf(fileExt) > -1) { + fontFamily = fileNoPath.substr(0, lastDotIdx); + newStyle = document.createElement('style'); + newStyle.appendChild( + document.createTextNode( + '\n@font-face {' + + '\nfont-family: ' + + fontFamily + + ';\nsrc: url(' + + path + + ');\n}\n' + ) + ); + + document.head.appendChild(newStyle); + } + }); + + return p5Font; + }; + + /** + * Draws text to the screen. Displays the information specified in the first + * parameter on the screen in the position specified by the additional + * parameters. A default font will be used unless a font is set with the + * textFont() function and a default size will be used unless a font is set + * with textSize(). Change the color of the text with the fill() function. + * Change the outline of the text with the stroke() and strokeWeight() + * functions. + *

+ * The text displays in relation to the textAlign() function, which gives the + * option to draw to the left, right, and center of the coordinates. + *

+ * The x2 and y2 parameters define a rectangular area to display within and + * may only be used with string data. When these parameters are specified, + * they are interpreted based on the current rectMode() setting. Text that + * does not fit completely within the rectangle specified will not be drawn + * to the screen. If x2 and y2 are not specified, the baseline alignment is the + * default, which means that the text will be drawn upwards from x and y. + *

+ * WEBGL: Only opentype/truetype fonts are supported. You must load a font using the + * loadFont() method (see the example above). + * stroke() currently has no effect in webgl mode. + * + * @method text + * @param {String|Object|Array|Number|Boolean} str the alphanumeric + * symbols to be displayed + * @param {Number} x x-coordinate of text + * @param {Number} y y-coordinate of text + * @param {Number} [x2] by default, the width of the text box, + * see rectMode() for more info + * @param {Number} [y2] by default, the height of the text box, + * see rectMode() for more info + * @chainable + * @example + *
+ * + * textSize(32); + * text('word', 10, 30); + * fill(0, 102, 153); + * text('word', 10, 60); + * fill(0, 102, 153, 51); + * text('word', 10, 90); + * + *
+ *
+ * + * let s = 'The quick brown fox jumped over the lazy dog.'; + * fill(50); + * text(s, 10, 10, 70, 80); // Text wraps within text box + * + *
+ * + *
+ * + * let inconsolata; + * function preload() { + * inconsolata = loadFont('assets/inconsolata.otf'); + * } + * function setup() { + * createCanvas(100, 100, WEBGL); + * textFont(inconsolata); + * textSize(width / 3); + * textAlign(CENTER, CENTER); + * } + * function draw() { + * background(0); + * let time = millis(); + * rotateX(time / 1000); + * rotateZ(time / 1234); + * text('p5.js', 0, 0); + * } + * + *
+ * + * @alt + *'word' displayed 3 times going from black, blue to translucent blue + * The quick brown fox jumped over the lazy dog. + * the text 'p5.js' spinning in 3d + * + */ + p5.prototype.text = function(str, x, y, maxWidth, maxHeight) { + p5._validateParameters('text', arguments); + return !(this._renderer._doFill || this._renderer._doStroke) + ? this + : this._renderer.text.apply(this._renderer, arguments); + }; + + /** + * Sets the current font that will be drawn with the text() function. + *

+ * WEBGL: Only fonts loaded via loadFont() are supported. + * + * @method textFont + * @return {Object} the current font + * + * @example + *
+ * + * fill(0); + * textSize(12); + * textFont('Georgia'); + * text('Georgia', 12, 30); + * textFont('Helvetica'); + * text('Helvetica', 12, 60); + * + *
+ *
+ * + * let fontRegular, fontItalic, fontBold; + * function preload() { + * fontRegular = loadFont('assets/Regular.otf'); + * fontItalic = loadFont('assets/Italic.ttf'); + * fontBold = loadFont('assets/Bold.ttf'); + * } + * function setup() { + * background(210); + * fill(0) + .strokeWeight(0) + .textSize(10); + * textFont(fontRegular); + * text('Font Style Normal', 10, 30); + * textFont(fontItalic); + * text('Font Style Italic', 10, 50); + * textFont(fontBold); + * text('Font Style Bold', 10, 70); + * } + * + *
+ * + * @alt + *words Font Style Normal displayed normally, Italic in italic and bold in bold + */ + /** + * @method textFont + * @param {Object|String} font a font loaded via loadFont(), or a String + * representing a web safe font (a font + * that is generally available across all systems) + * @param {Number} [size] the font size to use + * @chainable + */ + p5.prototype.textFont = function(theFont, theSize) { + p5._validateParameters('textFont', arguments); + if (arguments.length) { + if (!theFont) { + throw new Error('null font passed to textFont'); + } + + this._renderer._setProperty('_textFont', theFont); + + if (theSize) { + this._renderer._setProperty('_textSize', theSize); + this._renderer._setProperty( + '_textLeading', + theSize * constants._DEFAULT_LEADMULT + ); + } + + return this._renderer._applyTextProperties(); + } + + return this._renderer._textFont; + }; + + module.exports = p5; + }, + { + '../core/constants': 18, + '../core/error_helpers': 20, + '../core/main': 24, + 'opentype.js': 10 + } + ], + 60: [ + function(_dereq_, module, exports) { + /** + * This module defines the p5.Font class and functions for + * drawing text to the display canvas. + * @module Typography + * @submodule Font + * @requires core + * @requires constants + */ + + 'use strict'; + function _typeof(obj) { + if (typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol') { + _typeof = function _typeof(obj) { + return typeof obj; + }; + } else { + _typeof = function _typeof(obj) { + return obj && + typeof Symbol === 'function' && + obj.constructor === Symbol && + obj !== Symbol.prototype + ? 'symbol' + : typeof obj; + }; + } + return _typeof(obj); + } + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + + /** + * Base class for font handling + * @class p5.Font + * @param {p5} [pInst] pointer to p5 instance + */ + p5.Font = function(p) { + this.parent = p; + + this.cache = {}; + + /** + * Underlying opentype font implementation + * @property font + */ + this.font = undefined; + }; + + /** + * Returns a tight bounding box for the given text string using this + * font (currently only supports single lines) + * + * @method textBounds + * @param {String} line a line of text + * @param {Number} x x-position + * @param {Number} y y-position + * @param {Number} [fontSize] font size to use (optional) Default is 12. + * @param {Object} [options] opentype options (optional) + * opentype fonts contains alignment and baseline options. + * Default is 'LEFT' and 'alphabetic' + * + * + * @return {Object} a rectangle object with properties: x, y, w, h + * + * @example + *
+ * + * let font; + * let textString = 'Lorem ipsum dolor sit amet.'; + * function preload() { + * font = loadFont('./assets/Regular.otf'); + * } + * function setup() { + * background(210); + * + * let bbox = font.textBounds(textString, 10, 30, 12); + * fill(255); + * stroke(0); + * rect(bbox.x, bbox.y, bbox.w, bbox.h); + * fill(0); + * noStroke(); + * + * textFont(font); + * textSize(12); + * text(textString, 10, 30); + * } + * + *
+ * + * @alt + *words Lorem ipsum dol go off canvas and contained by white bounding box + * + */ + p5.Font.prototype.textBounds = function(str, x, y, fontSize, opts) { + x = x !== undefined ? x : 0; + y = y !== undefined ? y : 0; + + // Check cache for existing bounds. Take into consideration the text alignment + // settings. Default alignment should match opentype's origin: left-aligned & + // alphabetic baseline. + var p = (opts && opts.renderer && opts.renderer._pInst) || this.parent, + ctx = p._renderer.drawingContext, + alignment = ctx.textAlign || constants.LEFT, + baseline = ctx.textBaseline || constants.BASELINE, + cacheResults = false, + result, + key; + + fontSize = fontSize || p._renderer._textSize; + + // NOTE: cache disabled for now pending further discussion of #3436 + if (cacheResults) { + key = cacheKey('textBounds', str, x, y, fontSize, alignment, baseline); + result = this.cache[key]; + } + + if (!result) { + var minX, + minY, + maxX, + maxY, + pos, + xCoords = [], + yCoords = [], + scale = this._scale(fontSize); + + this.font.forEachGlyph(str, x, y, fontSize, opts, function( + glyph, + gX, + gY, + gFontSize + ) { + var gm = glyph.getMetrics(); + xCoords.push(gX + gm.xMin * scale); + xCoords.push(gX + gm.xMax * scale); + yCoords.push(gY + -gm.yMin * scale); + yCoords.push(gY + -gm.yMax * scale); + }); + + minX = Math.min.apply(null, xCoords); + minY = Math.min.apply(null, yCoords); + maxX = Math.max.apply(null, xCoords); + maxY = Math.max.apply(null, yCoords); + + result = { + x: minX, + y: minY, + h: maxY - minY, + w: maxX - minX, + advance: minX - x + }; + + // Bounds are now calculated, so shift the x & y to match alignment settings + pos = this._handleAlignment( + p._renderer, + str, + result.x, + result.y, + result.w + result.advance + ); + + result.x = pos.x; + result.y = pos.y; + + if (cacheResults) { + this.cache[key] = result; + } + } + + return result; + }; + + /** + * Computes an array of points following the path for specified text + * + * @method textToPoints + * @param {String} txt a line of text + * @param {Number} x x-position + * @param {Number} y y-position + * @param {Number} fontSize font size to use (optional) + * @param {Object} [options] an (optional) object that can contain: + * + *
sampleFactor - the ratio of path-length to number of samples + * (default=.1); higher values yield more points and are therefore + * more precise + * + *
simplifyThreshold - if set to a non-zero value, collinear points will be + * be removed from the polygon; the value represents the threshold angle to use + * when determining whether two edges are collinear + * + * @return {Array} an array of points, each with x, y, alpha (the path angle) + * @example + *
+ * + * let font; + * function preload() { + * font = loadFont('assets/inconsolata.otf'); + * } + * + * let points; + * let bounds; + * function setup() { + * createCanvas(100, 100); + * stroke(0); + * fill(255, 104, 204); + * + * points = font.textToPoints('p5', 0, 0, 10, { + * sampleFactor: 5, + * simplifyThreshold: 0 + * }); + * bounds = font.textBounds(' p5 ', 0, 0, 10); + * } + * + * function draw() { + * background(255); + * beginShape(); + * translate(-bounds.x * width / bounds.w, -bounds.y * height / bounds.h); + * for (let i = 0; i < points.length; i++) { + * let p = points[i]; + * vertex( + * p.x * width / bounds.w + + * sin(20 * p.y / bounds.h + millis() / 1000) * width / 30, + * p.y * height / bounds.h + * ); + * } + * endShape(CLOSE); + * } + * + *
+ * + */ + p5.Font.prototype.textToPoints = function(txt, x, y, fontSize, options) { + var xoff = 0, + result = [], + glyphs = this._getGlyphs(txt); + + function isSpace(i) { + return ( + (glyphs[i].name && glyphs[i].name === 'space') || + (txt.length === glyphs.length && txt[i] === ' ') || + (glyphs[i].index && glyphs[i].index === 3) + ); + } + + fontSize = fontSize || this.parent._renderer._textSize; + + for (var i = 0; i < glyphs.length; i++) { + if (!isSpace(i)) { + // fix to #1817, #2069 + + var gpath = glyphs[i].getPath(x, y, fontSize), + paths = splitPaths(gpath.commands); + + for (var j = 0; j < paths.length; j++) { + var pts = pathToPoints(paths[j], options); + + for (var k = 0; k < pts.length; k++) { + pts[k].x += xoff; + result.push(pts[k]); + } + } + } + + xoff += glyphs[i].advanceWidth * this._scale(fontSize); + } + + return result; + }; + + // ----------------------------- End API ------------------------------ + + /** + * Returns the set of opentype glyphs for the supplied string. + * + * Note that there is not a strict one-to-one mapping between characters + * and glyphs, so the list of returned glyphs can be larger or smaller + * than the length of the given string. + * + * @private + * @param {String} str the string to be converted + * @return {Array} the opentype glyphs + */ + p5.Font.prototype._getGlyphs = function(str) { + return this.font.stringToGlyphs(str); + }; + + /** + * Returns an opentype path for the supplied string and position. + * + * @private + * @param {String} line a line of text + * @param {Number} x x-position + * @param {Number} y y-position + * @param {Object} options opentype options (optional) + * @return {Object} the opentype path + */ + p5.Font.prototype._getPath = function(line, x, y, options) { + var p = (options && options.renderer && options.renderer._pInst) || this.parent, + renderer = p._renderer, + pos = this._handleAlignment(renderer, line, x, y); + + return this.font.getPath(line, pos.x, pos.y, renderer._textSize, options); + }; + + /* + * Creates an SVG-formatted path-data string + * (See http://www.w3.org/TR/SVG/paths.html#PathData) + * from the given opentype path or string/position + * + * @param {Object} path an opentype path, OR the following: + * + * @param {String} line a line of text + * @param {Number} x x-position + * @param {Number} y y-position + * @param {Object} options opentype options (optional), set options.decimals + * to set the decimal precision of the path-data + * + * @return {Object} this p5.Font object + */ + p5.Font.prototype._getPathData = function(line, x, y, options) { + var decimals = 3; + + // create path from string/position + if (typeof line === 'string' && arguments.length > 2) { + line = this._getPath(line, x, y, options); + } else if (_typeof(x) === 'object') { + // handle options specified in 2nd arg + options = x; + } + + // handle svg arguments + if (options && typeof options.decimals === 'number') { + decimals = options.decimals; + } + + return line.toPathData(decimals); + }; + + /* + * Creates an SVG element, as a string, + * from the given opentype path or string/position + * + * @param {Object} path an opentype path, OR the following: + * + * @param {String} line a line of text + * @param {Number} x x-position + * @param {Number} y y-position + * @param {Object} options opentype options (optional), set options.decimals + * to set the decimal precision of the path-data in the element, + * options.fill to set the fill color for the element, + * options.stroke to set the stroke color for the element, + * options.strokeWidth to set the strokeWidth for the element. + * + * @return {Object} this p5.Font object + */ + p5.Font.prototype._getSVG = function(line, x, y, options) { + var decimals = 3; + + // create path from string/position + if (typeof line === 'string' && arguments.length > 2) { + line = this._getPath(line, x, y, options); + } else if (_typeof(x) === 'object') { + // handle options specified in 2nd arg + options = x; + } + + // handle svg arguments + if (options) { + if (typeof options.decimals === 'number') { + decimals = options.decimals; + } + if (typeof options.strokeWidth === 'number') { + line.strokeWidth = options.strokeWidth; + } + if (typeof options.fill !== 'undefined') { + line.fill = options.fill; + } + if (typeof options.stroke !== 'undefined') { + line.stroke = options.stroke; + } + } + + return line.toSVG(decimals); + }; + + /* + * Renders an opentype path or string/position + * to the current graphics context + * + * @param {Object} path an opentype path, OR the following: + * + * @param {String} line a line of text + * @param {Number} x x-position + * @param {Number} y y-position + * @param {Object} options opentype options (optional) + * + * @return {p5.Font} this p5.Font object + */ + p5.Font.prototype._renderPath = function(line, x, y, options) { + var pdata, + pg = (options && options.renderer) || this.parent._renderer, + ctx = pg.drawingContext; + + if (_typeof(line) === 'object' && line.commands) { + pdata = line.commands; + } else { + //pos = handleAlignment(p, ctx, line, x, y); + pdata = this._getPath(line, x, y, options).commands; + } + + ctx.beginPath(); + for (var i = 0; i < pdata.length; i += 1) { + var cmd = pdata[i]; + if (cmd.type === 'M') { + ctx.moveTo(cmd.x, cmd.y); + } else if (cmd.type === 'L') { + ctx.lineTo(cmd.x, cmd.y); + } else if (cmd.type === 'C') { + ctx.bezierCurveTo(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); + } else if (cmd.type === 'Q') { + ctx.quadraticCurveTo(cmd.x1, cmd.y1, cmd.x, cmd.y); + } else if (cmd.type === 'Z') { + ctx.closePath(); + } + } + + // only draw stroke if manually set by user + if (pg._doStroke && pg._strokeSet) { + ctx.stroke(); + } + + if (pg._doFill) { + // if fill hasn't been set by user, use default-text-fill + if (!pg._fillSet) { + pg._setFill(constants._DEFAULT_TEXT_FILL); + } + ctx.fill(); + } + + return this; + }; + + p5.Font.prototype._textWidth = function(str, fontSize) { + return this.font.getAdvanceWidth(str, fontSize); + }; + + p5.Font.prototype._textAscent = function(fontSize) { + return this.font.ascender * this._scale(fontSize); + }; + + p5.Font.prototype._textDescent = function(fontSize) { + return -this.font.descender * this._scale(fontSize); + }; + + p5.Font.prototype._scale = function(fontSize) { + return 1 / this.font.unitsPerEm * (fontSize || this.parent._renderer._textSize); + }; + + p5.Font.prototype._handleAlignment = function(renderer, line, x, y, textWidth) { + var fontSize = renderer._textSize; + + if (typeof textWidth === 'undefined') { + textWidth = this._textWidth(line, fontSize); + } + + switch (renderer._textAlign) { + case constants.CENTER: + x -= textWidth / 2; + break; + case constants.RIGHT: + x -= textWidth; + break; + } + + switch (renderer._textBaseline) { + case constants.TOP: + y += this._textAscent(fontSize); + break; + case constants.CENTER: + y += this._textAscent(fontSize) / 2; + break; + case constants.BOTTOM: + y -= this._textDescent(fontSize); + break; + } + + return { x: x, y: y }; + }; + + // path-utils + + function pathToPoints(cmds, options) { + var opts = parseOpts(options, { + sampleFactor: 0.1, + simplifyThreshold: 0 + }); + + var len = pointAtLength(cmds, 0, 1), // total-length + t = len / (len * opts.sampleFactor), + pts = []; + + for (var i = 0; i < len; i += t) { + pts.push(pointAtLength(cmds, i)); + } + + if (opts.simplifyThreshold) { + simplify(pts, opts.simplifyThreshold); + } + + return pts; + } + + function simplify(pts, angle) { + angle = typeof angle === 'undefined' ? 0 : angle; + + var num = 0; + for (var i = pts.length - 1; pts.length > 3 && i >= 0; --i) { + if (collinear(at(pts, i - 1), at(pts, i), at(pts, i + 1), angle)) { + // Remove the middle point + pts.splice(i % pts.length, 1); + num++; + } + } + return num; + } + + function splitPaths(cmds) { + var paths = [], + current; + for (var i = 0; i < cmds.length; i++) { + if (cmds[i].type === 'M') { + if (current) { + paths.push(current); + } + current = []; + } + current.push(cmdToArr(cmds[i])); + } + paths.push(current); + + return paths; + } + + function cmdToArr(cmd) { + var arr = [cmd.type]; + if (cmd.type === 'M' || cmd.type === 'L') { + // moveto or lineto + arr.push(cmd.x, cmd.y); + } else if (cmd.type === 'C') { + arr.push(cmd.x1, cmd.y1, cmd.x2, cmd.y2, cmd.x, cmd.y); + } else if (cmd.type === 'Q') { + arr.push(cmd.x1, cmd.y1, cmd.x, cmd.y); + } + // else if (cmd.type === 'Z') { /* no-op */ } + return arr; + } + + function parseOpts(options, defaults) { + if (_typeof(options) !== 'object') { + options = defaults; + } else { + for (var key in defaults) { + if (typeof options[key] === 'undefined') { + options[key] = defaults[key]; + } + } + } + return options; + } + + //////////////////////// Helpers //////////////////////////// + + function at(v, i) { + var s = v.length; + return v[i < 0 ? i % s + s : i % s]; + } + + function collinear(a, b, c, thresholdAngle) { + if (!thresholdAngle) { + return areaTriangle(a, b, c) === 0; + } + + if (typeof collinear.tmpPoint1 === 'undefined') { + collinear.tmpPoint1 = []; + collinear.tmpPoint2 = []; + } + + var ab = collinear.tmpPoint1, + bc = collinear.tmpPoint2; + ab.x = b.x - a.x; + ab.y = b.y - a.y; + bc.x = c.x - b.x; + bc.y = c.y - b.y; + + var dot = ab.x * bc.x + ab.y * bc.y, + magA = Math.sqrt(ab.x * ab.x + ab.y * ab.y), + magB = Math.sqrt(bc.x * bc.x + bc.y * bc.y), + angle = Math.acos(dot / (magA * magB)); + + return angle < thresholdAngle; + } + + function areaTriangle(a, b, c) { + return (b[0] - a[0]) * (c[1] - a[1]) - (c[0] - a[0]) * (b[1] - a[1]); + } + + // Portions of below code copyright 2008 Dmitry Baranovskiy (via MIT license) + + function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) { + var t1 = 1 - t, + t13 = Math.pow(t1, 3), + t12 = Math.pow(t1, 2), + t2 = t * t, + t3 = t2 * t, + x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x, + y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y, + mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x), + my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y), + nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x), + ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y), + ax = t1 * p1x + t * c1x, + ay = t1 * p1y + t * c1y, + cx = t1 * c2x + t * p2x, + cy = t1 * c2y + t * p2y, + alpha = 90 - Math.atan2(mx - nx, my - ny) * 180 / Math.PI; + + if (mx > nx || my < ny) { + alpha += 180; + } + + return { + x: x, + y: y, + m: { x: mx, y: my }, + n: { x: nx, y: ny }, + start: { x: ax, y: ay }, + end: { x: cx, y: cy }, + alpha: alpha + }; + } + + function getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) { + return length == null + ? bezlen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) + : findDotsAtSegment( + p1x, + p1y, + c1x, + c1y, + c2x, + c2y, + p2x, + p2y, + getTatLen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) + ); + } + + function pointAtLength(path, length, istotal) { + path = path2curve(path); + var x, + y, + p, + l, + sp = '', + subpaths = {}, + point, + len = 0; + for (var i = 0, ii = path.length; i < ii; i++) { + p = path[i]; + if (p[0] === 'M') { + x = +p[1]; + y = +p[2]; + } else { + l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]); + if (len + l > length) { + if (!istotal) { + point = getPointAtSegmentLength( + x, + y, + p[1], + p[2], + p[3], + p[4], + p[5], + p[6], + length - len + ); + + return { x: point.x, y: point.y, alpha: point.alpha }; + } + } + len += l; + x = +p[5]; + y = +p[6]; + } + sp += p.shift() + p; + } + subpaths.end = sp; + + point = istotal + ? len + : findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1); + + if (point.alpha) { + point = { x: point.x, y: point.y, alpha: point.alpha }; + } + + return point; + } + + function pathToAbsolute(pathArray) { + var res = [], + x = 0, + y = 0, + mx = 0, + my = 0, + start = 0; + if (!pathArray) { + // console.warn("Unexpected state: undefined pathArray"); // shouldn't happen + return res; + } + if (pathArray[0][0] === 'M') { + x = +pathArray[0][1]; + y = +pathArray[0][2]; + mx = x; + my = y; + start++; + res[0] = ['M', x, y]; + } + + var dots, + crz = + pathArray.length === 3 && + pathArray[0][0] === 'M' && + pathArray[1][0].toUpperCase() === 'R' && + pathArray[2][0].toUpperCase() === 'Z'; + + for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) { + res.push((r = [])); + pa = pathArray[i]; + if (pa[0] !== String.prototype.toUpperCase.call(pa[0])) { + r[0] = String.prototype.toUpperCase.call(pa[0]); + switch (r[0]) { + case 'A': + r[1] = pa[1]; + r[2] = pa[2]; + r[3] = pa[3]; + r[4] = pa[4]; + r[5] = pa[5]; + r[6] = +(pa[6] + x); + r[7] = +(pa[7] + y); + break; + case 'V': + r[1] = +pa[1] + y; + break; + case 'H': + r[1] = +pa[1] + x; + break; + case 'R': + dots = [x, y].concat(pa.slice(1)); + for (var j = 2, jj = dots.length; j < jj; j++) { + dots[j] = +dots[j] + x; + dots[++j] = +dots[j] + y; + } + res.pop(); + res = res.concat(catmullRom2bezier(dots, crz)); + break; + case 'M': + mx = +pa[1] + x; + my = +pa[2] + y; + break; + default: + for (j = 1, jj = pa.length; j < jj; j++) { + r[j] = +pa[j] + (j % 2 ? x : y); + } + } + } else if (pa[0] === 'R') { + dots = [x, y].concat(pa.slice(1)); + res.pop(); + res = res.concat(catmullRom2bezier(dots, crz)); + r = ['R'].concat(pa.slice(-2)); + } else { + for (var k = 0, kk = pa.length; k < kk; k++) { + r[k] = pa[k]; + } + } + switch (r[0]) { + case 'Z': + x = mx; + y = my; + break; + case 'H': + x = r[1]; + break; + case 'V': + y = r[1]; + break; + case 'M': + mx = r[r.length - 2]; + my = r[r.length - 1]; + break; + default: + x = r[r.length - 2]; + y = r[r.length - 1]; + } + } + return res; + } + + function path2curve(path, path2) { + var p = pathToAbsolute(path), + p2 = path2 && pathToAbsolute(path2); + var attrs = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null }; + var attrs2 = { x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null }; + var pcoms1 = []; // path commands of original path p + var pcoms2 = []; // path commands of original path p2 + var ii; + + var processPath = function processPath(path, d, pcom) { + var nx, + ny, + tq = { T: 1, Q: 1 }; + if (!path) { + return ['C', d.x, d.y, d.x, d.y, d.x, d.y]; + } + if (!(path[0] in tq)) { + d.qx = d.qy = null; + } + switch (path[0]) { + case 'M': + d.X = path[1]; + d.Y = path[2]; + break; + case 'A': + path = ['C'].concat(a2c.apply(0, [d.x, d.y].concat(path.slice(1)))); + break; + case 'S': + if (pcom === 'C' || pcom === 'S') { + nx = d.x * 2 - d.bx; + ny = d.y * 2 - d.by; + } else { + nx = d.x; + ny = d.y; + } + path = ['C', nx, ny].concat(path.slice(1)); + break; + case 'T': + if (pcom === 'Q' || pcom === 'T') { + d.qx = d.x * 2 - d.qx; + d.qy = d.y * 2 - d.qy; + } else { + d.qx = d.x; + d.qy = d.y; + } + path = ['C'].concat(q2c(d.x, d.y, d.qx, d.qy, path[1], path[2])); + break; + case 'Q': + d.qx = path[1]; + d.qy = path[2]; + path = ['C'].concat(q2c(d.x, d.y, path[1], path[2], path[3], path[4])); + + break; + case 'L': + path = ['C'].concat(l2c(d.x, d.y, path[1], path[2])); + break; + case 'H': + path = ['C'].concat(l2c(d.x, d.y, path[1], d.y)); + break; + case 'V': + path = ['C'].concat(l2c(d.x, d.y, d.x, path[1])); + break; + case 'Z': + path = ['C'].concat(l2c(d.x, d.y, d.X, d.Y)); + break; + } + + return path; + }, + fixArc = function fixArc(pp, i) { + if (pp[i].length > 7) { + pp[i].shift(); + var pi = pp[i]; + while (pi.length) { + pcoms1[i] = 'A'; + if (p2) { + pcoms2[i] = 'A'; + } + pp.splice(i++, 0, ['C'].concat(pi.splice(0, 6))); + } + pp.splice(i, 1); + ii = Math.max(p.length, (p2 && p2.length) || 0); + } + }, + fixM = function fixM(path1, path2, a1, a2, i) { + if (path1 && path2 && path1[i][0] === 'M' && path2[i][0] !== 'M') { + path2.splice(i, 0, ['M', a2.x, a2.y]); + a1.bx = 0; + a1.by = 0; + a1.x = path1[i][1]; + a1.y = path1[i][2]; + ii = Math.max(p.length, (p2 && p2.length) || 0); + } + }; + + var pfirst = ''; // temporary holder for original path command + var pcom = ''; // holder for previous path command of original path + + ii = Math.max(p.length, (p2 && p2.length) || 0); + for (var i = 0; i < ii; i++) { + if (p[i]) { + pfirst = p[i][0]; + } // save current path command + + if (pfirst !== 'C') { + pcoms1[i] = pfirst; // Save current path command + if (i) { + pcom = pcoms1[i - 1]; + } // Get previous path command pcom + } + p[i] = processPath(p[i], attrs, pcom); + + if (pcoms1[i] !== 'A' && pfirst === 'C') { + pcoms1[i] = 'C'; + } + + fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1 + + if (p2) { + // the same procedures is done to p2 + if (p2[i]) { + pfirst = p2[i][0]; + } + if (pfirst !== 'C') { + pcoms2[i] = pfirst; + if (i) { + pcom = pcoms2[i - 1]; + } + } + p2[i] = processPath(p2[i], attrs2, pcom); + + if (pcoms2[i] !== 'A' && pfirst === 'C') { + pcoms2[i] = 'C'; + } + + fixArc(p2, i); + } + fixM(p, p2, attrs, attrs2, i); + fixM(p2, p, attrs2, attrs, i); + var seg = p[i], + seg2 = p2 && p2[i], + seglen = seg.length, + seg2len = p2 && seg2.length; + attrs.x = seg[seglen - 2]; + attrs.y = seg[seglen - 1]; + attrs.bx = parseFloat(seg[seglen - 4]) || attrs.x; + attrs.by = parseFloat(seg[seglen - 3]) || attrs.y; + attrs2.bx = p2 && (parseFloat(seg2[seg2len - 4]) || attrs2.x); + attrs2.by = p2 && (parseFloat(seg2[seg2len - 3]) || attrs2.y); + attrs2.x = p2 && seg2[seg2len - 2]; + attrs2.y = p2 && seg2[seg2len - 1]; + } + + return p2 ? [p, p2] : p; + } + + function a2c(x1, y1, rx, ry, angle, lac, sweep_flag, x2, y2, recursive) { + // for more information of where this Math came from visit: + // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes + var PI = Math.PI, + _120 = PI * 120 / 180, + f1, + f2, + cx, + cy, + rad = PI / 180 * (+angle || 0), + res = [], + xy, + rotate = function rotate(x, y, rad) { + var X = x * Math.cos(rad) - y * Math.sin(rad), + Y = x * Math.sin(rad) + y * Math.cos(rad); + return { x: X, y: Y }; + }; + if (!recursive) { + xy = rotate(x1, y1, -rad); + x1 = xy.x; + y1 = xy.y; + xy = rotate(x2, y2, -rad); + x2 = xy.x; + y2 = xy.y; + var x = (x1 - x2) / 2, + y = (y1 - y2) / 2, + h = x * x / (rx * rx) + y * y / (ry * ry); + if (h > 1) { + h = Math.sqrt(h); + rx = h * rx; + ry = h * ry; + } + var rx2 = rx * rx, + ry2 = ry * ry; + var k = + (lac === sweep_flag ? -1 : 1) * + Math.sqrt( + Math.abs( + (rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x) + ) + ); + + cx = k * rx * y / ry + (x1 + x2) / 2; + cy = k * -ry * x / rx + (y1 + y2) / 2; + f1 = Math.asin(((y1 - cy) / ry).toFixed(9)); + f2 = Math.asin(((y2 - cy) / ry).toFixed(9)); + + f1 = x1 < cx ? PI - f1 : f1; + f2 = x2 < cx ? PI - f2 : f2; + + if (f1 < 0) { + f1 = PI * 2 + f1; + } + if (f2 < 0) { + f2 = PI * 2 + f2; + } + + if (sweep_flag && f1 > f2) { + f1 = f1 - PI * 2; + } + if (!sweep_flag && f2 > f1) { + f2 = f2 - PI * 2; + } + } else { + f1 = recursive[0]; + f2 = recursive[1]; + cx = recursive[2]; + cy = recursive[3]; + } + var df = f2 - f1; + if (Math.abs(df) > _120) { + var f2old = f2, + x2old = x2, + y2old = y2; + f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1); + x2 = cx + rx * Math.cos(f2); + y2 = cy + ry * Math.sin(f2); + res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [ + f2, + f2old, + cx, + cy + ]); + } + df = f2 - f1; + var c1 = Math.cos(f1), + s1 = Math.sin(f1), + c2 = Math.cos(f2), + s2 = Math.sin(f2), + t = Math.tan(df / 4), + hx = 4 / 3 * rx * t, + hy = 4 / 3 * ry * t, + m1 = [x1, y1], + m2 = [x1 + hx * s1, y1 - hy * c1], + m3 = [x2 + hx * s2, y2 - hy * c2], + m4 = [x2, y2]; + m2[0] = 2 * m1[0] - m2[0]; + m2[1] = 2 * m1[1] - m2[1]; + if (recursive) { + return [m2, m3, m4].concat(res); + } else { + res = [m2, m3, m4] + .concat(res) + .join() + .split(','); + var newres = []; + for (var i = 0, ii = res.length; i < ii; i++) { + newres[i] = + i % 2 + ? rotate(res[i - 1], res[i], rad).y + : rotate(res[i], res[i + 1], rad).x; + } + return newres; + } + } + + // http://schepers.cc/getting-to-the-point + function catmullRom2bezier(crp, z) { + var d = []; + for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) { + var p = [ + { + x: +crp[i - 2], + y: +crp[i - 1] + }, + + { + x: +crp[i], + y: +crp[i + 1] + }, + + { + x: +crp[i + 2], + y: +crp[i + 3] + }, + + { + x: +crp[i + 4], + y: +crp[i + 5] + } + ]; + + if (z) { + if (!i) { + p[0] = { + x: +crp[iLen - 2], + y: +crp[iLen - 1] + }; + } else if (iLen - 4 === i) { + p[3] = { + x: +crp[0], + y: +crp[1] + }; + } else if (iLen - 2 === i) { + p[2] = { + x: +crp[0], + y: +crp[1] + }; + + p[3] = { + x: +crp[2], + y: +crp[3] + }; + } + } else { + if (iLen - 4 === i) { + p[3] = p[2]; + } else if (!i) { + p[0] = { + x: +crp[i], + y: +crp[i + 1] + }; + } + } + d.push([ + 'C', + (-p[0].x + 6 * p[1].x + p[2].x) / 6, + (-p[0].y + 6 * p[1].y + p[2].y) / 6, + (p[1].x + 6 * p[2].x - p[3].x) / 6, + (p[1].y + 6 * p[2].y - p[3].y) / 6, + p[2].x, + p[2].y + ]); + } + + return d; + } + + function l2c(x1, y1, x2, y2) { + return [x1, y1, x2, y2, x2, y2]; + } + + function q2c(x1, y1, ax, ay, x2, y2) { + var _13 = 1 / 3, + _23 = 2 / 3; + return [ + _13 * x1 + _23 * ax, + _13 * y1 + _23 * ay, + _13 * x2 + _23 * ax, + _13 * y2 + _23 * ay, + x2, + y2 + ]; + } + + function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) { + if (z == null) { + z = 1; + } + z = z > 1 ? 1 : z < 0 ? 0 : z; + var z2 = z / 2; + var n = 12; + var Tvalues = [ + -0.1252, + 0.1252, + -0.3678, + 0.3678, + -0.5873, + 0.5873, + -0.7699, + 0.7699, + -0.9041, + 0.9041, + -0.9816, + 0.9816 + ]; + + var sum = 0; + var Cvalues = [ + 0.2491, + 0.2491, + 0.2335, + 0.2335, + 0.2032, + 0.2032, + 0.1601, + 0.1601, + 0.1069, + 0.1069, + 0.0472, + 0.0472 + ]; + + for (var i = 0; i < n; i++) { + var ct = z2 * Tvalues[i] + z2, + xbase = base3(ct, x1, x2, x3, x4), + ybase = base3(ct, y1, y2, y3, y4), + comb = xbase * xbase + ybase * ybase; + sum += Cvalues[i] * Math.sqrt(comb); + } + return z2 * sum; + } + + function getTatLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) { + if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) { + return; + } + var t = 1, + step = t / 2, + t2 = t - step, + l, + e = 0.01; + l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2); + while (Math.abs(l - ll) > e) { + step /= 2; + t2 += (l < ll ? 1 : -1) * step; + l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2); + } + return t2; + } + + function base3(t, p1, p2, p3, p4) { + var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4, + t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3; + return t * t2 - 3 * p1 + 3 * p2; + } + + function cacheKey() { + var hash = ''; + for (var i = arguments.length - 1; i >= 0; --i) { + hash += '?' + arguments[i]; + } + return hash; + } + + module.exports = p5; + }, + { '../core/constants': 18, '../core/main': 24 } + ], + 61: [ + function(_dereq_, module, exports) { + /** + * @module Data + * @submodule Array Functions + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * Adds a value to the end of an array. Extends the length of + * the array by one. Maps to Array.push(). + * + * @method append + * @deprecated Use array.push(value) instead. + * @param {Array} array Array to append + * @param {any} value to be added to the Array + * @return {Array} the array that was appended to + * @example + *
+ * function setup() { + * var myArray = ['Mango', 'Apple', 'Papaya']; + * print(myArray); // ['Mango', 'Apple', 'Papaya'] + * + * append(myArray, 'Peach'); + * print(myArray); // ['Mango', 'Apple', 'Papaya', 'Peach'] + * } + *
+ */ + p5.prototype.append = function(array, value) { + array.push(value); + return array; + }; + + /** + * Copies an array (or part of an array) to another array. The src array is + * copied to the dst array, beginning at the position specified by + * srcPosition and into the position specified by dstPosition. The number of + * elements to copy is determined by length. Note that copying values + * overwrites existing values in the destination array. To append values + * instead of overwriting them, use concat(). + *

+ * The simplified version with only two arguments, arrayCopy(src, dst), + * copies an entire array to another of the same size. It is equivalent to + * arrayCopy(src, 0, dst, 0, src.length). + *

+ * Using this function is far more efficient for copying array data than + * iterating through a for() loop and copying each element individually. + * + * @method arrayCopy + * @deprecated + * @param {Array} src the source Array + * @param {Integer} srcPosition starting position in the source Array + * @param {Array} dst the destination Array + * @param {Integer} dstPosition starting position in the destination Array + * @param {Integer} length number of Array elements to be copied + * + * @example + *
+ * var src = ['A', 'B', 'C']; + * var dst = [1, 2, 3]; + * var srcPosition = 1; + * var dstPosition = 0; + * var length = 2; + * + * print(src); // ['A', 'B', 'C'] + * print(dst); // [ 1 , 2 , 3 ] + * + * arrayCopy(src, srcPosition, dst, dstPosition, length); + * print(dst); // ['B', 'C', 3] + *
+ */ + /** + * @method arrayCopy + * @deprecated Use arr1.copyWithin(arr2) instead. + * @param {Array} src + * @param {Array} dst + * @param {Integer} [length] + */ + p5.prototype.arrayCopy = function(src, srcPosition, dst, dstPosition, length) { + // the index to begin splicing from dst array + var start; + var end; + + if (typeof length !== 'undefined') { + end = Math.min(length, src.length); + start = dstPosition; + src = src.slice(srcPosition, end + srcPosition); + } else { + if (typeof dst !== 'undefined') { + // src, dst, length + // rename so we don't get confused + end = dst; + end = Math.min(end, src.length); + } else { + // src, dst + end = src.length; + } + + start = 0; + // rename so we don't get confused + dst = srcPosition; + src = src.slice(0, end); + } + + // Since we are not returning the array and JavaScript is pass by reference + // we must modify the actual values of the array + // instead of reassigning arrays + Array.prototype.splice.apply(dst, [start, end].concat(src)); + }; + + /** + * Concatenates two arrays, maps to Array.concat(). Does not modify the + * input arrays. + * + * @method concat + * @deprecated Use arr1.concat(arr2) instead. + * @param {Array} a first Array to concatenate + * @param {Array} b second Array to concatenate + * @return {Array} concatenated array + * + * @example + *
+ * function setup() { + * var arr1 = ['A', 'B', 'C']; + * var arr2 = [1, 2, 3]; + * + * print(arr1); // ['A','B','C'] + * print(arr2); // [1,2,3] + * + * var arr3 = concat(arr1, arr2); + * + * print(arr1); // ['A','B','C'] + * print(arr2); // [1, 2, 3] + * print(arr3); // ['A','B','C', 1, 2, 3] + * } + *
+ */ + p5.prototype.concat = function(list0, list1) { + return list0.concat(list1); + }; + + /** + * Reverses the order of an array, maps to Array.reverse() + * + * @method reverse + * @deprecated Use array.reverse() instead. + * @param {Array} list Array to reverse + * @return {Array} the reversed list + * @example + *
+ * function setup() { + * var myArray = ['A', 'B', 'C']; + * print(myArray); // ['A','B','C'] + * + * reverse(myArray); + * print(myArray); // ['C','B','A'] + * } + *
+ */ + p5.prototype.reverse = function(list) { + return list.reverse(); + }; + + /** + * Decreases an array by one element and returns the shortened array, + * maps to Array.pop(). + * + * @method shorten + * @deprecated Use array.pop() instead. + * @param {Array} list Array to shorten + * @return {Array} shortened Array + * @example + *
+ * function setup() { + * var myArray = ['A', 'B', 'C']; + * print(myArray); // ['A', 'B', 'C'] + * var newArray = shorten(myArray); + * print(myArray); // ['A','B','C'] + * print(newArray); // ['A','B'] + * } + *
+ */ + p5.prototype.shorten = function(list) { + list.pop(); + return list; + }; + + /** + * Randomizes the order of the elements of an array. Implements + * + * Fisher-Yates Shuffle Algorithm. + * + * @method shuffle + * @param {Array} array Array to shuffle + * @param {Boolean} [bool] modify passed array + * @return {Array} shuffled Array + * @example + *
+ * function setup() { + * var regularArr = ['ABC', 'def', createVector(), TAU, Math.E]; + * print(regularArr); + * shuffle(regularArr, true); // force modifications to passed array + * print(regularArr); + * + * // By default shuffle() returns a shuffled cloned array: + * var newArr = shuffle(regularArr); + * print(regularArr); + * print(newArr); + * } + *
+ */ + p5.prototype.shuffle = function(arr, bool) { + var isView = ArrayBuffer && ArrayBuffer.isView && ArrayBuffer.isView(arr); + arr = bool || isView ? arr : arr.slice(); + + var rnd, + tmp, + idx = arr.length; + while (idx > 1) { + rnd = (Math.random() * idx) | 0; + + tmp = arr[--idx]; + arr[idx] = arr[rnd]; + arr[rnd] = tmp; + } + + return arr; + }; + + /** + * Sorts an array of numbers from smallest to largest, or puts an array of + * words in alphabetical order. The original array is not modified; a + * re-ordered array is returned. The count parameter states the number of + * elements to sort. For example, if there are 12 elements in an array and + * count is set to 5, only the first 5 elements in the array will be sorted. + * + * @method sort + * @deprecated Use array.sort() instead. + * @param {Array} list Array to sort + * @param {Integer} [count] number of elements to sort, starting from 0 + * @return {Array} the sorted list + * + * @example + *
+ * function setup() { + * var words = ['banana', 'apple', 'pear', 'lime']; + * print(words); // ['banana', 'apple', 'pear', 'lime'] + * var count = 4; // length of array + * + * words = sort(words, count); + * print(words); // ['apple', 'banana', 'lime', 'pear'] + * } + *
+ *
+ * function setup() { + * var numbers = [2, 6, 1, 5, 14, 9, 8, 12]; + * print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12] + * var count = 5; // Less than the length of the array + * + * numbers = sort(numbers, count); + * print(numbers); // [1,2,5,6,14,9,8,12] + * } + *
+ */ + p5.prototype.sort = function(list, count) { + var arr = count ? list.slice(0, Math.min(count, list.length)) : list; + var rest = count ? list.slice(Math.min(count, list.length)) : []; + if (typeof arr[0] === 'string') { + arr = arr.sort(); + } else { + arr = arr.sort(function(a, b) { + return a - b; + }); + } + return arr.concat(rest); + }; + + /** + * Inserts a value or an array of values into an existing array. The first + * parameter specifies the initial array to be modified, and the second + * parameter defines the data to be inserted. The third parameter is an index + * value which specifies the array position from which to insert data. + * (Remember that array index numbering starts at zero, so the first position + * is 0, the second position is 1, and so on.) + * + * @method splice + * @deprecated Use array.splice() instead. + * @param {Array} list Array to splice into + * @param {any} value value to be spliced in + * @param {Integer} position in the array from which to insert data + * @return {Array} the list + * + * @example + *
+ * function setup() { + * var myArray = [0, 1, 2, 3, 4]; + * var insArray = ['A', 'B', 'C']; + * print(myArray); // [0, 1, 2, 3, 4] + * print(insArray); // ['A','B','C'] + * + * splice(myArray, insArray, 3); + * print(myArray); // [0,1,2,'A','B','C',3,4] + * } + *
+ */ + p5.prototype.splice = function(list, value, index) { + // note that splice returns spliced elements and not an array + Array.prototype.splice.apply(list, [index, 0].concat(value)); + + return list; + }; + + /** + * Extracts an array of elements from an existing array. The list parameter + * defines the array from which the elements will be copied, and the start + * and count parameters specify which elements to extract. If no count is + * given, elements will be extracted from the start to the end of the array. + * When specifying the start, remember that the first array element is 0. + * This function does not change the source array. + * + * @method subset + * @deprecated Use array.slice() instead. + * @param {Array} list Array to extract from + * @param {Integer} start position to begin + * @param {Integer} [count] number of values to extract + * @return {Array} Array of extracted elements + * + * @example + *
+ * function setup() { + * var myArray = [1, 2, 3, 4, 5]; + * print(myArray); // [1, 2, 3, 4, 5] + * + * var sub1 = subset(myArray, 0, 3); + * var sub2 = subset(myArray, 2, 2); + * print(sub1); // [1,2,3] + * print(sub2); // [3,4] + * } + *
+ */ + p5.prototype.subset = function(list, start, count) { + if (typeof count !== 'undefined') { + return list.slice(start, start + count); + } else { + return list.slice(start, list.length); + } + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 62: [ + function(_dereq_, module, exports) { + /** + * @module Data + * @submodule Conversion + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * Converts a string to its floating point representation. The contents of a + * string must resemble a number, or NaN (not a number) will be returned. + * For example, float("1234.56") evaluates to 1234.56, but float("giraffe") + * will return NaN. + * + * When an array of values is passed in, then an array of floats of the same + * length is returned. + * + * @method float + * @param {String} str float string to parse + * @return {Number} floating point representation of string + * @example + *
+ * var str = '20'; + * var diameter = float(str); + * ellipse(width / 2, height / 2, diameter, diameter); + *
+ *
+ * print(float('10.31')); // 10.31 + * print(float('Infinity')); // Infinity + * print(float('-Infinity')); // -Infinity + *
+ * + * @alt + * 20 by 20 white ellipse in the center of the canvas + * + */ + p5.prototype.float = function(str) { + if (str instanceof Array) { + return str.map(parseFloat); + } + return parseFloat(str); + }; + + /** + * Converts a boolean, string, or float to its integer representation. + * When an array of values is passed in, then an int array of the same length + * is returned. + * + * @method int + * @param {String|Boolean|Number} n value to parse + * @param {Integer} [radix] the radix to convert to (default: 10) + * @return {Number} integer representation of value + * + * @example + *
+ * print(int('10')); // 10 + * print(int(10.31)); // 10 + * print(int(-10)); // -10 + * print(int(true)); // 1 + * print(int(false)); // 0 + * print(int([false, true, '10.3', 9.8])); // [0, 1, 10, 9] + * print(int(Infinity)); // Infinity + * print(int('-Infinity')); // -Infinity + *
+ */ + /** + * @method int + * @param {Array} ns values to parse + * @return {Number[]} integer representation of values + */ + p5.prototype.int = function(n, radix) { + radix = radix || 10; + if (n === Infinity || n === 'Infinity') { + return Infinity; + } else if (n === -Infinity || n === '-Infinity') { + return -Infinity; + } else if (typeof n === 'string') { + return parseInt(n, radix); + } else if (typeof n === 'number') { + return n | 0; + } else if (typeof n === 'boolean') { + return n ? 1 : 0; + } else if (n instanceof Array) { + return n.map(function(n) { + return p5.prototype.int(n, radix); + }); + } + }; + + /** + * Converts a boolean, string or number to its string representation. + * When an array of values is passed in, then an array of strings of the same + * length is returned. + * + * @method str + * @param {String|Boolean|Number|Array} n value to parse + * @return {String} string representation of value + * @example + *
+ * print(str('10')); // "10" + * print(str(10.31)); // "10.31" + * print(str(-10)); // "-10" + * print(str(true)); // "true" + * print(str(false)); // "false" + * print(str([true, '10.3', 9.8])); // [ "true", "10.3", "9.8" ] + *
+ */ + p5.prototype.str = function(n) { + if (n instanceof Array) { + return n.map(p5.prototype.str); + } else { + return String(n); + } + }; + + /** + * Converts a number or string to its boolean representation. + * For a number, any non-zero value (positive or negative) evaluates to true, + * while zero evaluates to false. For a string, the value "true" evaluates to + * true, while any other value evaluates to false. When an array of number or + * string values is passed in, then a array of booleans of the same length is + * returned. + * + * @method boolean + * @param {String|Boolean|Number|Array} n value to parse + * @return {Boolean} boolean representation of value + * @example + *
+ * print(boolean(0)); // false + * print(boolean(1)); // true + * print(boolean('true')); // true + * print(boolean('abcd')); // false + * print(boolean([0, 12, 'true'])); // [false, true, true] + *
+ */ + p5.prototype.boolean = function(n) { + if (typeof n === 'number') { + return n !== 0; + } else if (typeof n === 'string') { + return n.toLowerCase() === 'true'; + } else if (typeof n === 'boolean') { + return n; + } else if (n instanceof Array) { + return n.map(p5.prototype.boolean); + } + }; + + /** + * Converts a number, string representation of a number, or boolean to its byte + * representation. A byte can be only a whole number between -128 and 127, so + * when a value outside of this range is converted, it wraps around to the + * corresponding byte representation. When an array of number, string or boolean + * values is passed in, then an array of bytes the same length is returned. + * + * @method byte + * @param {String|Boolean|Number} n value to parse + * @return {Number} byte representation of value + * + * @example + *
+ * print(byte(127)); // 127 + * print(byte(128)); // -128 + * print(byte(23.4)); // 23 + * print(byte('23.4')); // 23 + * print(byte('hello')); // NaN + * print(byte(true)); // 1 + * print(byte([0, 255, '100'])); // [0, -1, 100] + *
+ */ + /** + * @method byte + * @param {Array} ns values to parse + * @return {Number[]} array of byte representation of values + */ + p5.prototype.byte = function(n) { + var nn = p5.prototype.int(n, 10); + if (typeof nn === 'number') { + return (nn + 128) % 256 - 128; + } else if (nn instanceof Array) { + return nn.map(p5.prototype.byte); + } + }; + + /** + * Converts a number or string to its corresponding single-character + * string representation. If a string parameter is provided, it is first + * parsed as an integer and then translated into a single-character string. + * When an array of number or string values is passed in, then an array of + * single-character strings of the same length is returned. + * + * @method char + * @param {String|Number} n value to parse + * @return {String} string representation of value + * + * @example + *
+ * print(char(65)); // "A" + * print(char('65')); // "A" + * print(char([65, 66, 67])); // [ "A", "B", "C" ] + * print(join(char([65, 66, 67]), '')); // "ABC" + *
+ */ + /** + * @method char + * @param {Array} ns values to parse + * @return {String[]} array of string representation of values + */ + p5.prototype.char = function(n) { + if (typeof n === 'number' && !isNaN(n)) { + return String.fromCharCode(n); + } else if (n instanceof Array) { + return n.map(p5.prototype.char); + } else if (typeof n === 'string') { + return p5.prototype.char(parseInt(n, 10)); + } + }; + + /** + * Converts a single-character string to its corresponding integer + * representation. When an array of single-character string values is passed + * in, then an array of integers of the same length is returned. + * + * @method unchar + * @param {String} n value to parse + * @return {Number} integer representation of value + * + * @example + *
+ * print(unchar('A')); // 65 + * print(unchar(['A', 'B', 'C'])); // [ 65, 66, 67 ] + * print(unchar(split('ABC', ''))); // [ 65, 66, 67 ] + *
+ */ + /** + * @method unchar + * @param {Array} ns values to parse + * @return {Number[]} integer representation of values + */ + p5.prototype.unchar = function(n) { + if (typeof n === 'string' && n.length === 1) { + return n.charCodeAt(0); + } else if (n instanceof Array) { + return n.map(p5.prototype.unchar); + } + }; + + /** + * Converts a number to a string in its equivalent hexadecimal notation. If a + * second parameter is passed, it is used to set the number of characters to + * generate in the hexadecimal notation. When an array is passed in, an + * array of strings in hexadecimal notation of the same length is returned. + * + * @method hex + * @param {Number} n value to parse + * @param {Number} [digits] + * @return {String} hexadecimal string representation of value + * + * @example + *
+ * print(hex(255)); // "000000FF" + * print(hex(255, 6)); // "0000FF" + * print(hex([0, 127, 255], 6)); // [ "000000", "00007F", "0000FF" ] + * print(Infinity); // "FFFFFFFF" + * print(-Infinity); // "00000000" + *
+ */ + /** + * @method hex + * @param {Number[]} ns array of values to parse + * @param {Number} [digits] + * @return {String[]} hexadecimal string representation of values + */ + p5.prototype.hex = function(n, digits) { + digits = digits === undefined || digits === null ? (digits = 8) : digits; + if (n instanceof Array) { + return n.map(function(n) { + return p5.prototype.hex(n, digits); + }); + } else if (n === Infinity || n === -Infinity) { + var c = n === Infinity ? 'F' : '0'; + return c.repeat(digits); + } else if (typeof n === 'number') { + if (n < 0) { + n = 0xffffffff + n + 1; + } + var hex = Number(n) + .toString(16) + .toUpperCase(); + while (hex.length < digits) { + hex = '0' + hex; + } + if (hex.length >= digits) { + hex = hex.substring(hex.length - digits, hex.length); + } + return hex; + } + }; + + /** + * Converts a string representation of a hexadecimal number to its equivalent + * integer value. When an array of strings in hexadecimal notation is passed + * in, an array of integers of the same length is returned. + * + * @method unhex + * @param {String} n value to parse + * @return {Number} integer representation of hexadecimal value + * + * @example + *
+ * print(unhex('A')); // 10 + * print(unhex('FF')); // 255 + * print(unhex(['FF', 'AA', '00'])); // [ 255, 170, 0 ] + *
+ */ + /** + * @method unhex + * @param {Array} ns values to parse + * @return {Number[]} integer representations of hexadecimal value + */ + p5.prototype.unhex = function(n) { + if (n instanceof Array) { + return n.map(p5.prototype.unhex); + } else { + return parseInt('0x' + n, 16); + } + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 63: [ + function(_dereq_, module, exports) { + /** + * @module Data + * @submodule String Functions + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + _dereq_('../core/error_helpers'); + + //return p5; //LM is this a mistake? + + /** + * Combines an array of Strings into one String, each separated by the + * character(s) used for the separator parameter. To join arrays of ints or + * floats, it's necessary to first convert them to Strings using nf() or + * nfs(). + * + * @method join + * @param {Array} list array of Strings to be joined + * @param {String} separator String to be placed between each item + * @return {String} joined String + * @example + *
+ * + * var array = ['Hello', 'world!']; + * var separator = ' '; + * var message = join(array, separator); + * text(message, 5, 50); + * + *
+ * + * @alt + * "hello world!" displayed middle left of canvas. + * + */ + p5.prototype.join = function(list, separator) { + p5._validateParameters('join', arguments); + return list.join(separator); + }; + + /** + * This function is used to apply a regular expression to a piece of text, + * and return matching groups (elements found inside parentheses) as a + * String array. If there are no matches, a null value will be returned. + * If no groups are specified in the regular expression, but the sequence + * matches, an array of length 1 (with the matched text as the first element + * of the array) will be returned. + *

+ * To use the function, first check to see if the result is null. If the + * result is null, then the sequence did not match at all. If the sequence + * did match, an array is returned. + *

+ * If there are groups (specified by sets of parentheses) in the regular + * expression, then the contents of each will be returned in the array. + * Element [0] of a regular expression match returns the entire matching + * string, and the match groups start at element [1] (the first group is [1], + * the second [2], and so on). + * + * @method match + * @param {String} str the String to be searched + * @param {String} regexp the regexp to be used for matching + * @return {String[]} Array of Strings found + * @example + *
+ * + * var string = 'Hello p5js*!'; + * var regexp = 'p5js\\*'; + * var m = match(string, regexp); + * text(m, 5, 50); + * + *
+ * + * @alt + * "p5js*" displayed middle left of canvas. + * + */ + p5.prototype.match = function(str, reg) { + p5._validateParameters('match', arguments); + return str.match(reg); + }; + + /** + * This function is used to apply a regular expression to a piece of text, + * and return a list of matching groups (elements found inside parentheses) + * as a two-dimensional String array. If there are no matches, a null value + * will be returned. If no groups are specified in the regular expression, + * but the sequence matches, a two dimensional array is still returned, but + * the second dimension is only of length one. + *

+ * To use the function, first check to see if the result is null. If the + * result is null, then the sequence did not match at all. If the sequence + * did match, a 2D array is returned. + *

+ * If there are groups (specified by sets of parentheses) in the regular + * expression, then the contents of each will be returned in the array. + * Assuming a loop with counter variable i, element [i][0] of a regular + * expression match returns the entire matching string, and the match groups + * start at element [i][1] (the first group is [i][1], the second [i][2], + * and so on). + * + * @method matchAll + * @param {String} str the String to be searched + * @param {String} regexp the regexp to be used for matching + * @return {String[]} 2d Array of Strings found + * @example + *
+ * + * var string = 'Hello p5js*! Hello world!'; + * var regexp = 'Hello'; + * matchAll(string, regexp); + * + *
+ */ + p5.prototype.matchAll = function(str, reg) { + p5._validateParameters('matchAll', arguments); + var re = new RegExp(reg, 'g'); + var match = re.exec(str); + var matches = []; + while (match !== null) { + matches.push(match); + // matched text: match[0] + // match start: match.index + // capturing group n: match[n] + match = re.exec(str); + } + return matches; + }; + + /** + * Utility function for formatting numbers into strings. There are two + * versions: one for formatting floats, and one for formatting ints. + * The values for the digits, left, and right parameters should always + * be positive integers. + * (NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter + * if greater than the current length of the number. + * For example if number is 123.2 and left parameter passed is 4 which is greater than length of 123 + * (integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than + * the result will be 123.200. + * + * @method nf + * @param {Number|String} num the Number to format + * @param {Integer|String} [left] number of digits to the left of the + * decimal point + * @param {Integer|String} [right] number of digits to the right of the + * decimal point + * @return {String} formatted String + * + * @example + *
+ * + * var myFont; + * function preload() { + * myFont = loadFont('assets/fonts/inconsolata.ttf'); + * } + * function setup() { + * background(200); + * var num1 = 321; + * var num2 = -1321; + * + * noStroke(); + * fill(0); + * textFont(myFont); + * textSize(22); + * + * text(nf(num1, 4, 2), 10, 30); + * text(nf(num2, 4, 2), 10, 80); + * // Draw dividing line + * stroke(120); + * line(0, 50, width, 50); + * } + * + *
+ * + * @alt + * "0321.00" middle top, -1321.00" middle bottom canvas + */ + /** + * @method nf + * @param {Array} nums the Numbers to format + * @param {Integer|String} [left] + * @param {Integer|String} [right] + * @return {String[]} formatted Strings + */ + p5.prototype.nf = function(nums, left, right) { + p5._validateParameters('nf', arguments); + if (nums instanceof Array) { + return nums.map(function(x) { + return doNf(x, left, right); + }); + } else { + var typeOfFirst = Object.prototype.toString.call(nums); + if (typeOfFirst === '[object Arguments]') { + if (nums.length === 3) { + return this.nf(nums[0], nums[1], nums[2]); + } else if (nums.length === 2) { + return this.nf(nums[0], nums[1]); + } else { + return this.nf(nums[0]); + } + } else { + return doNf(nums, left, right); + } + } + }; + + function doNf(num, left, right) { + var neg = num < 0; + var n = neg ? num.toString().substring(1) : num.toString(); + var decimalInd = n.indexOf('.'); + var intPart = decimalInd !== -1 ? n.substring(0, decimalInd) : n; + var decPart = decimalInd !== -1 ? n.substring(decimalInd + 1) : ''; + var str = neg ? '-' : ''; + if (typeof right !== 'undefined') { + var decimal = ''; + if (decimalInd !== -1 || right - decPart.length > 0) { + decimal = '.'; + } + if (decPart.length > right) { + decPart = decPart.substring(0, right); + } + for (var i = 0; i < left - intPart.length; i++) { + str += '0'; + } + str += intPart; + str += decimal; + str += decPart; + for (var j = 0; j < right - decPart.length; j++) { + str += '0'; + } + return str; + } else { + for (var k = 0; k < Math.max(left - intPart.length, 0); k++) { + str += '0'; + } + str += n; + return str; + } + } + + /** + * Utility function for formatting numbers into strings and placing + * appropriate commas to mark units of 1000. There are two versions: one + * for formatting ints, and one for formatting an array of ints. The value + * for the right parameter should always be a positive integer. + * + * @method nfc + * @param {Number|String} num the Number to format + * @param {Integer|String} [right] number of digits to the right of the + * decimal point + * @return {String} formatted String + * + * @example + *
+ * + * function setup() { + * background(200); + * var num = 11253106.115; + * var numArr = [1, 1, 2]; + * + * noStroke(); + * fill(0); + * textSize(12); + * + * // Draw formatted numbers + * text(nfc(num, 4), 10, 30); + * text(nfc(numArr, 2), 10, 80); + * + * // Draw dividing line + * stroke(120); + * line(0, 50, width, 50); + * } + * + *
+ * + * @alt + * "11,253,106.115" top middle and "1.00,1.00,2.00" displayed bottom mid + */ + /** + * @method nfc + * @param {Array} nums the Numbers to format + * @param {Integer|String} [right] + * @return {String[]} formatted Strings + */ + p5.prototype.nfc = function(num, right) { + p5._validateParameters('nfc', arguments); + if (num instanceof Array) { + return num.map(function(x) { + return doNfc(x, right); + }); + } else { + return doNfc(num, right); + } + }; + function doNfc(num, right) { + num = num.toString(); + var dec = num.indexOf('.'); + var rem = dec !== -1 ? num.substring(dec) : ''; + var n = dec !== -1 ? num.substring(0, dec) : num; + n = n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); + if (right === 0) { + rem = ''; + } else if (typeof right !== 'undefined') { + if (right > rem.length) { + rem += dec === -1 ? '.' : ''; + var len = right - rem.length + 1; + for (var i = 0; i < len; i++) { + rem += '0'; + } + } else { + rem = rem.substring(0, right + 1); + } + } + return n + rem; + } + + /** + * Utility function for formatting numbers into strings. Similar to nf() but + * puts a "+" in front of positive numbers and a "-" in front of negative + * numbers. There are two versions: one for formatting floats, and one for + * formatting ints. The values for left, and right parameters + * should always be positive integers. + * + * @method nfp + * @param {Number} num the Number to format + * @param {Integer} [left] number of digits to the left of the decimal + * point + * @param {Integer} [right] number of digits to the right of the + * decimal point + * @return {String} formatted String + * + * @example + *
+ * + * function setup() { + * background(200); + * var num1 = 11253106.115; + * var num2 = -11253106.115; + * + * noStroke(); + * fill(0); + * textSize(12); + * + * // Draw formatted numbers + * text(nfp(num1, 4, 2), 10, 30); + * text(nfp(num2, 4, 2), 10, 80); + * + * // Draw dividing line + * stroke(120); + * line(0, 50, width, 50); + * } + * + *
+ * + * @alt + * "+11253106.11" top middle and "-11253106.11" displayed bottom middle + */ + /** + * @method nfp + * @param {Number[]} nums the Numbers to format + * @param {Integer} [left] + * @param {Integer} [right] + * @return {String[]} formatted Strings + */ + p5.prototype.nfp = function() { + p5._validateParameters('nfp', arguments); + var nfRes = p5.prototype.nf.apply(this, arguments); + if (nfRes instanceof Array) { + return nfRes.map(addNfp); + } else { + return addNfp(nfRes); + } + }; + + function addNfp(num) { + return parseFloat(num) > 0 ? '+' + num.toString() : num.toString(); + } + + /** + * Utility function for formatting numbers into strings. Similar to nf() but + * puts an additional "_" (space) in front of positive numbers just in case to align it with negative + * numbers which includes "-" (minus) sign. + * The main usecase of nfs() can be seen when one wants to align the digits (place values) of a non-negative + * number with some negative number (See the example to get a clear picture). + * There are two versions: one for formatting float, and one for formatting int. + * The values for the digits, left, and right parameters should always be positive integers. + * (IMP): The result on the canvas basically the expected alignment can vary based on the typeface you are using. + * (NOTE): Be cautious when using left and right parameters as it prepends numbers of 0's if the parameter + * if greater than the current length of the number. + * For example if number is 123.2 and left parameter passed is 4 which is greater than length of 123 + * (integer part) i.e 3 than result will be 0123.2. Same case for right parameter i.e. if right is 3 than + * the result will be 123.200. + * + * @method nfs + * @param {Number} num the Number to format + * @param {Integer} [left] number of digits to the left of the decimal + * point + * @param {Integer} [right] number of digits to the right of the + * decimal point + * @return {String} formatted String + * + * @example + *
+ * + * var myFont; + * function preload() { + * myFont = loadFont('assets/fonts/inconsolata.ttf'); + * } + * function setup() { + * background(200); + * var num1 = 321; + * var num2 = -1321; + * + * noStroke(); + * fill(0); + * textFont(myFont); + * textSize(22); + * + * // nfs() aligns num1 (positive number) with num2 (negative number) by + * // adding a blank space in front of the num1 (positive number) + * // [left = 4] in num1 add one 0 in front, to align the digits with num2 + * // [right = 2] in num1 and num2 adds two 0's after both numbers + * // To see the differences check the example of nf() too. + * text(nfs(num1, 4, 2), 10, 30); + * text(nfs(num2, 4, 2), 10, 80); + * // Draw dividing line + * stroke(120); + * line(0, 50, width, 50); + * } + * + *
+ * + * @alt + * "0321.00" top middle and "-1321.00" displayed bottom middle + */ + /** + * @method nfs + * @param {Array} nums the Numbers to format + * @param {Integer} [left] + * @param {Integer} [right] + * @return {String[]} formatted Strings + */ + p5.prototype.nfs = function() { + p5._validateParameters('nfs', arguments); + var nfRes = p5.prototype.nf.apply(this, arguments); + if (nfRes instanceof Array) { + return nfRes.map(addNfs); + } else { + return addNfs(nfRes); + } + }; + + function addNfs(num) { + return parseFloat(num) >= 0 ? ' ' + num.toString() : num.toString(); + } + + /** + * The split() function maps to String.split(), it breaks a String into + * pieces using a character or string as the delimiter. The delim parameter + * specifies the character or characters that mark the boundaries between + * each piece. A String[] array is returned that contains each of the pieces. + * + * The splitTokens() function works in a similar fashion, except that it + * splits using a range of characters instead of a specific character or + * sequence. + * + * @method split + * @param {String} value the String to be split + * @param {String} delim the String used to separate the data + * @return {String[]} Array of Strings + * @example + *
+ * + * var names = 'Pat,Xio,Alex'; + * var splitString = split(names, ','); + * text(splitString[0], 5, 30); + * text(splitString[1], 5, 50); + * text(splitString[2], 5, 70); + * + *
+ * + * @alt + * "pat" top left, "Xio" mid left and "Alex" displayed bottom left + * + */ + p5.prototype.split = function(str, delim) { + p5._validateParameters('split', arguments); + return str.split(delim); + }; + + /** + * The splitTokens() function splits a String at one or many character + * delimiters or "tokens." The delim parameter specifies the character or + * characters to be used as a boundary. + *

+ * If no delim characters are specified, any whitespace character is used to + * split. Whitespace characters include tab (\t), line feed (\n), carriage + * return (\r), form feed (\f), and space. + * + * @method splitTokens + * @param {String} value the String to be split + * @param {String} [delim] list of individual Strings that will be used as + * separators + * @return {String[]} Array of Strings + * @example + *
+ * + * function setup() { + * var myStr = 'Mango, Banana, Lime'; + * var myStrArr = splitTokens(myStr, ','); + * + * print(myStrArr); // prints : ["Mango"," Banana"," Lime"] + * } + * + *
+ */ + p5.prototype.splitTokens = function(value, delims) { + p5._validateParameters('splitTokens', arguments); + var d; + if (typeof delims !== 'undefined') { + var str = delims; + var sqc = /\]/g.exec(str); + var sqo = /\[/g.exec(str); + if (sqo && sqc) { + str = str.slice(0, sqc.index) + str.slice(sqc.index + 1); + sqo = /\[/g.exec(str); + str = str.slice(0, sqo.index) + str.slice(sqo.index + 1); + d = new RegExp('[\\[' + str + '\\]]', 'g'); + } else if (sqc) { + str = str.slice(0, sqc.index) + str.slice(sqc.index + 1); + d = new RegExp('[' + str + '\\]]', 'g'); + } else if (sqo) { + str = str.slice(0, sqo.index) + str.slice(sqo.index + 1); + d = new RegExp('[' + str + '\\[]', 'g'); + } else { + d = new RegExp('[' + str + ']', 'g'); + } + } else { + d = /\s/g; + } + return value.split(d).filter(function(n) { + return n; + }); + }; + + /** + * Removes whitespace characters from the beginning and end of a String. In + * addition to standard whitespace characters such as space, carriage return, + * and tab, this function also removes the Unicode "nbsp" character. + * + * @method trim + * @param {String} str a String to be trimmed + * @return {String} a trimmed String + * + * @example + *
+ * + * var string = trim(' No new lines\n '); + * text(string + ' here', 2, 50); + * + *
+ * + * @alt + * "No new lines here" displayed center canvas + */ + /** + * @method trim + * @param {Array} strs an Array of Strings to be trimmed + * @return {String[]} an Array of trimmed Strings + */ + p5.prototype.trim = function(str) { + p5._validateParameters('trim', arguments); + if (str instanceof Array) { + return str.map(this.trim); + } else { + return str.trim(); + } + }; + + module.exports = p5; + }, + { '../core/error_helpers': 20, '../core/main': 24 } + ], + 64: [ + function(_dereq_, module, exports) { + /** + * @module IO + * @submodule Time & Date + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * p5.js communicates with the clock on your computer. The day() function + * returns the current day as a value from 1 - 31. + * + * @method day + * @return {Integer} the current day + * @example + *
+ * + * var d = day(); + * text('Current day: \n' + d, 5, 50); + * + *
+ * + * @alt + * Current day is displayed + * + */ + p5.prototype.day = function() { + return new Date().getDate(); + }; + + /** + * p5.js communicates with the clock on your computer. The hour() function + * returns the current hour as a value from 0 - 23. + * + * @method hour + * @return {Integer} the current hour + * @example + *
+ * + * var h = hour(); + * text('Current hour:\n' + h, 5, 50); + * + *
+ * + * @alt + * Current hour is displayed + * + */ + p5.prototype.hour = function() { + return new Date().getHours(); + }; + + /** + * p5.js communicates with the clock on your computer. The minute() function + * returns the current minute as a value from 0 - 59. + * + * @method minute + * @return {Integer} the current minute + * @example + *
+ * + * var m = minute(); + * text('Current minute: \n' + m, 5, 50); + * + *
+ * + * @alt + * Current minute is displayed + * + */ + p5.prototype.minute = function() { + return new Date().getMinutes(); + }; + + /** + * Returns the number of milliseconds (thousandths of a second) since + * starting the program. This information is often used for timing events and + * animation sequences. + * + * @method millis + * @return {Number} the number of milliseconds since starting the program + * @example + *
+ * + * var millisecond = millis(); + * text('Milliseconds \nrunning: \n' + millisecond, 5, 40); + * + *
+ * + * @alt + * number of milliseconds since program has started displayed + * + */ + p5.prototype.millis = function() { + return window.performance.now(); + }; + + /** + * p5.js communicates with the clock on your computer. The month() function + * returns the current month as a value from 1 - 12. + * + * @method month + * @return {Integer} the current month + * @example + *
+ * + * var m = month(); + * text('Current month: \n' + m, 5, 50); + * + *
+ * + * @alt + * Current month is displayed + * + */ + p5.prototype.month = function() { + return new Date().getMonth() + 1; //January is 0! + }; + + /** + * p5.js communicates with the clock on your computer. The second() function + * returns the current second as a value from 0 - 59. + * + * @method second + * @return {Integer} the current second + * @example + *
+ * + * var s = second(); + * text('Current second: \n' + s, 5, 50); + * + *
+ * + * @alt + * Current second is displayed + * + */ + p5.prototype.second = function() { + return new Date().getSeconds(); + }; + + /** + * p5.js communicates with the clock on your computer. The year() function + * returns the current year as an integer (2014, 2015, 2016, etc). + * + * @method year + * @return {Integer} the current year + * @example + *
+ * + * var y = year(); + * text('Current year: \n' + y, 5, 50); + * + *
+ * + * @alt + * Current year is displayed + * + */ + p5.prototype.year = function() { + return new Date().getFullYear(); + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 65: [ + function(_dereq_, module, exports) { + /** + * @module Shape + * @submodule 3D Primitives + * @for p5 + * @requires core + * @requires p5.Geometry + */ + + 'use strict'; + var p5 = _dereq_('../core/main'); + _dereq_('./p5.Geometry'); + var constants = _dereq_('../core/constants'); + + /** + * Draw a plane with given a width and height + * @method plane + * @param {Number} [width] width of the plane + * @param {Number} [height] height of the plane + * @param {Integer} [detailX] Optional number of triangle + * subdivisions in x-dimension + * @param {Integer} [detailY] Optional number of triangle + * subdivisions in y-dimension + * @chainable + * @example + *
+ * + * // draw a plane + * // with width 50 and height 50 + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * plane(50, 50); + * } + * + *
+ * + * @alt + * Nothing displayed on canvas + * Rotating interior view of a box with sides that change color. + * 3d red and green gradient. + * Rotating interior view of a cylinder with sides that change color. + * Rotating view of a cylinder with sides that change color. + * 3d red and green gradient. + * rotating view of a multi-colored cylinder with concave sides. + */ + p5.prototype.plane = function(width, height, detailX, detailY) { + this._assert3d('plane'); + p5._validateParameters('plane', arguments); + if (typeof width === 'undefined') { + width = 50; + } + if (typeof height === 'undefined') { + height = width; + } + + if (typeof detailX === 'undefined') { + detailX = 1; + } + if (typeof detailY === 'undefined') { + detailY = 1; + } + + var gId = 'plane|' + detailX + '|' + detailY; + + if (!this._renderer.geometryInHash(gId)) { + var _plane = function _plane() { + var u, v, p; + for (var i = 0; i <= this.detailY; i++) { + v = i / this.detailY; + for (var j = 0; j <= this.detailX; j++) { + u = j / this.detailX; + p = new p5.Vector(u - 0.5, v - 0.5, 0); + this.vertices.push(p); + this.uvs.push(u, v); + } + } + }; + var planeGeom = new p5.Geometry(detailX, detailY, _plane); + planeGeom.computeFaces().computeNormals(); + if (detailX <= 1 && detailY <= 1) { + planeGeom._makeTriangleEdges()._edgesToVertices(); + } else { + console.log( + 'Cannot draw stroke on plane objects with more' + + ' than 1 detailX or 1 detailY' + ); + } + this._renderer.createBuffers(gId, planeGeom); + } + + this._renderer.drawBuffersScaled(gId, width, height, 1); + return this; + }; + + /** + * Draw a box with given width, height and depth + * @method box + * @param {Number} [width] width of the box + * @param {Number} [Height] height of the box + * @param {Number} [depth] depth of the box + * @param {Integer} [detailX] Optional number of triangle + * subdivisions in x-dimension + * @param {Integer} [detailY] Optional number of triangle + * subdivisions in y-dimension + * @chainable + * @example + *
+ * + * // draw a spinning box + * // with width, height and depth of 50 + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * box(50); + * } + * + *
+ */ + p5.prototype.box = function(width, height, depth, detailX, detailY) { + this._assert3d('box'); + p5._validateParameters('box', arguments); + if (typeof width === 'undefined') { + width = 50; + } + if (typeof height === 'undefined') { + height = width; + } + if (typeof depth === 'undefined') { + depth = height; + } + + var perPixelLighting = + this._renderer.attributes && this._renderer.attributes.perPixelLighting; + if (typeof detailX === 'undefined') { + detailX = perPixelLighting ? 1 : 4; + } + if (typeof detailY === 'undefined') { + detailY = perPixelLighting ? 1 : 4; + } + + var gId = 'box|' + detailX + '|' + detailY; + if (!this._renderer.geometryInHash(gId)) { + var _box = function _box() { + var cubeIndices = [ + [0, 4, 2, 6], // -1, 0, 0],// -x + [1, 3, 5, 7], // +1, 0, 0],// +x + [0, 1, 4, 5], // 0, -1, 0],// -y + [2, 6, 3, 7], // 0, +1, 0],// +y + [0, 2, 1, 3], // 0, 0, -1],// -z + [4, 5, 6, 7] // 0, 0, +1] // +z + ]; + //using strokeIndices instead of faces for strokes + //to avoid diagonal stroke lines across face of box + this.strokeIndices = [ + [0, 1], + [1, 3], + [3, 2], + [6, 7], + [8, 9], + [9, 11], + [14, 15], + [16, 17], + [17, 19], + [18, 19], + [20, 21], + [22, 23] + ]; + + for (var i = 0; i < cubeIndices.length; i++) { + var cubeIndex = cubeIndices[i]; + var v = i * 4; + for (var j = 0; j < 4; j++) { + var d = cubeIndex[j]; + //inspired by lightgl: + //https://github.com/evanw/lightgl.js + //octants:https://en.wikipedia.org/wiki/Octant_(solid_geometry) + var octant = new p5.Vector( + ((d & 1) * 2 - 1) / 2, + ((d & 2) - 1) / 2, + ((d & 4) / 2 - 1) / 2 + ); + + this.vertices.push(octant); + this.uvs.push(j & 1, (j & 2) / 2); + } + this.faces.push([v, v + 1, v + 2]); + this.faces.push([v + 2, v + 1, v + 3]); + } + }; + var boxGeom = new p5.Geometry(detailX, detailY, _box); + boxGeom.computeNormals(); + if (detailX <= 4 && detailY <= 4) { + boxGeom._makeTriangleEdges()._edgesToVertices(); + } else { + console.log( + 'Cannot draw stroke on box objects with more' + + ' than 4 detailX or 4 detailY' + ); + } + //initialize our geometry buffer with + //the key val pair: + //geometry Id, Geom object + this._renderer.createBuffers(gId, boxGeom); + } + this._renderer.drawBuffersScaled(gId, width, height, depth); + + return this; + }; + + /** + * Draw a sphere with given radius + * @method sphere + * @param {Number} [radius] radius of circle + * @param {Integer} [detailX] number of segments, + * the more segments the smoother geometry + * default is 24 + * @param {Integer} [detailY] number of segments, + * the more segments the smoother geometry + * default is 16 + * @chainable + * @example + *
+ * + * // draw a sphere with radius 40 + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * sphere(40); + * } + * + *
+ */ + p5.prototype.sphere = function(radius, detailX, detailY) { + this._assert3d('sphere'); + p5._validateParameters('sphere', arguments); + if (typeof radius === 'undefined') { + radius = 50; + } + if (typeof detailX === 'undefined') { + detailX = 24; + } + if (typeof detailY === 'undefined') { + detailY = 16; + } + + this.ellipsoid(radius, radius, radius, detailX, detailY); + + return this; + }; + + /** + * @private + * Helper function for creating both cones and cyllinders + * Will only generate well-defined geometry when bottomRadius, height > 0 + * and topRadius >= 0 + * If topRadius == 0, topCap should be false + */ + var _truncatedCone = function _truncatedCone( + bottomRadius, + topRadius, + height, + detailX, + detailY, + bottomCap, + topCap + ) { + bottomRadius = bottomRadius <= 0 ? 1 : bottomRadius; + topRadius = topRadius < 0 ? 0 : topRadius; + height = height <= 0 ? bottomRadius : height; + detailX = detailX < 3 ? 3 : detailX; + detailY = detailY < 1 ? 1 : detailY; + bottomCap = bottomCap === undefined ? true : bottomCap; + topCap = topCap === undefined ? topRadius !== 0 : topCap; + var start = bottomCap ? -2 : 0; + var end = detailY + (topCap ? 2 : 0); + //ensure constant slant for interior vertex normals + var slant = Math.atan2(bottomRadius - topRadius, height); + var sinSlant = Math.sin(slant); + var cosSlant = Math.cos(slant); + var yy, ii, jj; + for (yy = start; yy <= end; ++yy) { + var v = yy / detailY; + var y = height * v; + var ringRadius; + if (yy < 0) { + //for the bottomCap edge + y = 0; + v = 0; + ringRadius = bottomRadius; + } else if (yy > detailY) { + //for the topCap edge + y = height; + v = 1; + ringRadius = topRadius; + } else { + //for the middle + ringRadius = bottomRadius + (topRadius - bottomRadius) * v; + } + if (yy === -2 || yy === detailY + 2) { + //center of bottom or top caps + ringRadius = 0; + } + + y -= height / 2; //shift coordiate origin to the center of object + for (ii = 0; ii < detailX; ++ii) { + var u = ii / detailX; + var ur = 2 * Math.PI * u; + var sur = Math.sin(ur); + var cur = Math.cos(ur); + + //VERTICES + this.vertices.push(new p5.Vector(sur * ringRadius, y, cur * ringRadius)); + + //VERTEX NORMALS + var vertexNormal; + if (yy < 0) { + vertexNormal = new p5.Vector(0, -1, 0); + } else if (yy > detailY && topRadius) { + vertexNormal = new p5.Vector(0, 1, 0); + } else { + vertexNormal = new p5.Vector(sur * cosSlant, sinSlant, cur * cosSlant); + } + this.vertexNormals.push(vertexNormal); + //UVs + this.uvs.push(u, v); + } + } + + var startIndex = 0; + if (bottomCap) { + for (jj = 0; jj < detailX; ++jj) { + var nextjj = (jj + 1) % detailX; + this.faces.push([ + startIndex + jj, + startIndex + detailX + nextjj, + startIndex + detailX + jj + ]); + } + startIndex += detailX * 2; + } + for (yy = 0; yy < detailY; ++yy) { + for (ii = 0; ii < detailX; ++ii) { + var nextii = (ii + 1) % detailX; + this.faces.push([ + startIndex + ii, + startIndex + nextii, + startIndex + detailX + nextii + ]); + + this.faces.push([ + startIndex + ii, + startIndex + detailX + nextii, + startIndex + detailX + ii + ]); + } + startIndex += detailX; + } + if (topCap) { + startIndex += detailX; + for (ii = 0; ii < detailX; ++ii) { + this.faces.push([ + startIndex + ii, + startIndex + (ii + 1) % detailX, + startIndex + detailX + ]); + } + } + }; + + /** + * Draw a cylinder with given radius and height + * @method cylinder + * @param {Number} [radius] radius of the surface + * @param {Number} [height] height of the cylinder + * @param {Integer} [detailX] number of segments, + * the more segments the smoother geometry + * default is 24 + * @param {Integer} [detailY] number of segments in y-dimension, + * the more segments the smoother geometry + * default is 1 + * @param {Boolean} [bottomCap] whether to draw the bottom of the cylinder + * @param {Boolean} [topCap] whether to draw the top of the cylinder + * @chainable + * @example + *
+ * + * // draw a spinning cylinder + * // with radius 20 and height 50 + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * rotateX(frameCount * 0.01); + * rotateZ(frameCount * 0.01); + * cylinder(20, 50); + * } + * + *
+ */ + p5.prototype.cylinder = function( + radius, + height, + detailX, + detailY, + bottomCap, + topCap + ) { + this._assert3d('cylinder'); + p5._validateParameters('cylinder', arguments); + if (typeof radius === 'undefined') { + radius = 50; + } + if (typeof height === 'undefined') { + height = radius; + } + if (typeof detailX === 'undefined') { + detailX = 24; + } + if (typeof detailY === 'undefined') { + detailY = 1; + } + if (typeof topCap === 'undefined') { + topCap = true; + } + if (typeof bottomCap === 'undefined') { + bottomCap = true; + } + + var gId = + 'cylinder|' + detailX + '|' + detailY + '|' + bottomCap + '|' + topCap; + if (!this._renderer.geometryInHash(gId)) { + var cylinderGeom = new p5.Geometry(detailX, detailY); + _truncatedCone.call( + cylinderGeom, + 1, + 1, + 1, + detailX, + detailY, + bottomCap, + topCap + ); + + // normals are computed in call to _truncatedCone + if (detailX <= 24 && detailY <= 16) { + cylinderGeom._makeTriangleEdges()._edgesToVertices(); + } else { + console.log( + 'Cannot draw stroke on cylinder objects with more' + + ' than 24 detailX or 16 detailY' + ); + } + this._renderer.createBuffers(gId, cylinderGeom); + } + + this._renderer.drawBuffersScaled(gId, radius, height, radius); + + return this; + }; + + /** + * Draw a cone with given radius and height + * @method cone + * @param {Number} [radius] radius of the bottom surface + * @param {Number} [height] height of the cone + * @param {Integer} [detailX] number of segments, + * the more segments the smoother geometry + * default is 24 + * @param {Integer} [detailY] number of segments, + * the more segments the smoother geometry + * default is 1 + * @param {Boolean} [cap] whether to draw the base of the cone + * @chainable + * @example + *
+ * + * // draw a spinning cone + * // with radius 40 and height 70 + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * rotateX(frameCount * 0.01); + * rotateZ(frameCount * 0.01); + * cone(40, 70); + * } + * + *
+ */ + p5.prototype.cone = function(radius, height, detailX, detailY, cap) { + this._assert3d('cone'); + p5._validateParameters('cone', arguments); + if (typeof radius === 'undefined') { + radius = 50; + } + if (typeof height === 'undefined') { + height = radius; + } + if (typeof detailX === 'undefined') { + detailX = 24; + } + if (typeof detailY === 'undefined') { + detailY = 1; + } + if (typeof cap === 'undefined') { + cap = true; + } + + var gId = 'cone|' + detailX + '|' + detailY + '|' + cap; + if (!this._renderer.geometryInHash(gId)) { + var coneGeom = new p5.Geometry(detailX, detailY); + _truncatedCone.call(coneGeom, 1, 0, 1, detailX, detailY, cap, false); + if (detailX <= 24 && detailY <= 16) { + coneGeom._makeTriangleEdges()._edgesToVertices(); + } else { + console.log( + 'Cannot draw stroke on cone objects with more' + + ' than 24 detailX or 16 detailY' + ); + } + this._renderer.createBuffers(gId, coneGeom); + } + + this._renderer.drawBuffersScaled(gId, radius, height, radius); + + return this; + }; + + /** + * Draw an ellipsoid with given radius + * @method ellipsoid + * @param {Number} [radiusx] x-radius of ellipsoid + * @param {Number} [radiusy] y-radius of ellipsoid + * @param {Number} [radiusz] z-radius of ellipsoid + * @param {Integer} [detailX] number of segments, + * the more segments the smoother geometry + * default is 24. Avoid detail number above + * 150, it may crash the browser. + * @param {Integer} [detailY] number of segments, + * the more segments the smoother geometry + * default is 16. Avoid detail number above + * 150, it may crash the browser. + * @chainable + * @example + *
+ * + * // draw an ellipsoid + * // with radius 30, 40 and 40. + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * ellipsoid(30, 40, 40); + * } + * + *
+ */ + p5.prototype.ellipsoid = function(radiusX, radiusY, radiusZ, detailX, detailY) { + this._assert3d('ellipsoid'); + p5._validateParameters('ellipsoid', arguments); + if (typeof radiusX === 'undefined') { + radiusX = 50; + } + if (typeof radiusY === 'undefined') { + radiusY = radiusX; + } + if (typeof radiusZ === 'undefined') { + radiusZ = radiusX; + } + + if (typeof detailX === 'undefined') { + detailX = 24; + } + if (typeof detailY === 'undefined') { + detailY = 16; + } + + var gId = 'ellipsoid|' + detailX + '|' + detailY; + + if (!this._renderer.geometryInHash(gId)) { + var _ellipsoid = function _ellipsoid() { + for (var i = 0; i <= this.detailY; i++) { + var v = i / this.detailY; + var phi = Math.PI * v - Math.PI / 2; + var cosPhi = Math.cos(phi); + var sinPhi = Math.sin(phi); + + for (var j = 0; j <= this.detailX; j++) { + var u = j / this.detailX; + var theta = 2 * Math.PI * u; + var cosTheta = Math.cos(theta); + var sinTheta = Math.sin(theta); + var p = new p5.Vector(cosPhi * sinTheta, sinPhi, cosPhi * cosTheta); + this.vertices.push(p); + this.vertexNormals.push(p); + this.uvs.push(u, v); + } + } + }; + var ellipsoidGeom = new p5.Geometry(detailX, detailY, _ellipsoid); + ellipsoidGeom.computeFaces(); + if (detailX <= 24 && detailY <= 24) { + ellipsoidGeom._makeTriangleEdges()._edgesToVertices(); + } else { + console.log( + 'Cannot draw stroke on ellipsoids with more' + + ' than 24 detailX or 24 detailY' + ); + } + this._renderer.createBuffers(gId, ellipsoidGeom); + } + + this._renderer.drawBuffersScaled(gId, radiusX, radiusY, radiusZ); + + return this; + }; + + /** + * Draw a torus with given radius and tube radius + * @method torus + * @param {Number} [radius] radius of the whole ring + * @param {Number} [tubeRadius] radius of the tube + * @param {Integer} [detailX] number of segments in x-dimension, + * the more segments the smoother geometry + * default is 24 + * @param {Integer} [detailY] number of segments in y-dimension, + * the more segments the smoother geometry + * default is 16 + * @chainable + * @example + *
+ * + * // draw a spinning torus + * // with ring radius 30 and tube radius 15 + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * torus(30, 15); + * } + * + *
+ */ + p5.prototype.torus = function(radius, tubeRadius, detailX, detailY) { + this._assert3d('torus'); + p5._validateParameters('torus', arguments); + if (typeof radius === 'undefined') { + radius = 50; + } else if (!radius) { + return; // nothing to draw + } + + if (typeof tubeRadius === 'undefined') { + tubeRadius = 10; + } else if (!tubeRadius) { + return; // nothing to draw + } + + if (typeof detailX === 'undefined') { + detailX = 24; + } + if (typeof detailY === 'undefined') { + detailY = 16; + } + + var tubeRatio = (tubeRadius / radius).toPrecision(4); + var gId = 'torus|' + tubeRatio + '|' + detailX + '|' + detailY; + + if (!this._renderer.geometryInHash(gId)) { + var _torus = function _torus() { + for (var i = 0; i <= this.detailY; i++) { + var v = i / this.detailY; + var phi = 2 * Math.PI * v; + var cosPhi = Math.cos(phi); + var sinPhi = Math.sin(phi); + var r = 1 + tubeRatio * cosPhi; + + for (var j = 0; j <= this.detailX; j++) { + var u = j / this.detailX; + var theta = 2 * Math.PI * u; + var cosTheta = Math.cos(theta); + var sinTheta = Math.sin(theta); + + var p = new p5.Vector(r * cosTheta, r * sinTheta, tubeRatio * sinPhi); + + var n = new p5.Vector(cosPhi * cosTheta, cosPhi * sinTheta, sinPhi); + + this.vertices.push(p); + this.vertexNormals.push(n); + this.uvs.push(u, v); + } + } + }; + var torusGeom = new p5.Geometry(detailX, detailY, _torus); + torusGeom.computeFaces(); + if (detailX <= 24 && detailY <= 16) { + torusGeom._makeTriangleEdges()._edgesToVertices(); + } else { + console.log( + 'Cannot draw strokes on torus object with more' + + ' than 24 detailX or 16 detailY' + ); + } + this._renderer.createBuffers(gId, torusGeom); + } + this._renderer.drawBuffersScaled(gId, radius, radius, radius); + + return this; + }; + + /////////////////////// + /// 2D primitives + ///////////////////////// + + /** + * Draws a point, a coordinate in space at the dimension of one pixel, + * given x, y and z coordinates. The color of the point is determined + * by the current stroke, while the point size is determined by current + * stroke weight. + * @private + * @param {Number} x x-coordinate of point + * @param {Number} y y-coordinate of point + * @param {Number} z z-coordinate of point + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(50); + * stroke(255); + * strokeWeight(4); + * point(25, 0); + * strokeWeight(3); + * point(-25, 0); + * strokeWeight(2); + * point(0, 25); + * strokeWeight(1); + * point(0, -25); + * } + * + *
+ */ + p5.RendererGL.prototype.point = function(x, y, z) { + if (typeof z === 'undefined') { + z = 0; + } + + var _vertex = []; + _vertex.push(new p5.Vector(x, y, z)); + this._drawPoints(_vertex, this._pointVertexBuffer); + + return this; + }; + + p5.RendererGL.prototype.triangle = function(args) { + var x1 = args[0], + y1 = args[1]; + var x2 = args[2], + y2 = args[3]; + var x3 = args[4], + y3 = args[5]; + + var gId = 'tri'; + if (!this.geometryInHash(gId)) { + var _triangle = function _triangle() { + var vertices = []; + vertices.push(new p5.Vector(0, 0, 0)); + vertices.push(new p5.Vector(0, 1, 0)); + vertices.push(new p5.Vector(1, 0, 0)); + this.strokeIndices = [[0, 1], [1, 2], [2, 0]]; + this.vertices = vertices; + this.faces = [[0, 1, 2]]; + this.uvs = [0, 0, 0, 1, 1, 1]; + }; + var triGeom = new p5.Geometry(1, 1, _triangle); + triGeom._makeTriangleEdges()._edgesToVertices(); + triGeom.computeNormals(); + this.createBuffers(gId, triGeom); + } + + // only one triangle is cached, one point is at the origin, and the + // two adjacent sides are tne unit vectors along the X & Y axes. + // + // this matrix multiplication transforms those two unit vectors + // onto the required vector prior to rendering, and moves the + // origin appropriately. + var uMVMatrix = this.uMVMatrix.copy(); + try { + // prettier-ignore + var mult = new p5.Matrix([ + x2 - x1, y2 - y1, 0, 0, // the resulting unit X-axis + x3 - x1, y3 - y1, 0, 0, // the resulting unit Y-axis + 0, 0, 1, 0, // the resulting unit Z-axis (unchanged) + x1, y1, 0, 1 // the resulting origin + ]).mult(this.uMVMatrix); + + this.uMVMatrix = mult; + + this.drawBuffers(gId); + } finally { + this.uMVMatrix = uMVMatrix; + } + + return this; + }; + + p5.RendererGL.prototype.ellipse = function(args) { + this.arc( + args[0], + args[1], + args[2], + args[3], + 0, + constants.TWO_PI, + constants.OPEN, + args[4] + ); + }; + + p5.RendererGL.prototype.arc = function(args) { + var x = arguments[0]; + var y = arguments[1]; + var width = arguments[2]; + var height = arguments[3]; + var start = arguments[4]; + var stop = arguments[5]; + var mode = arguments[6]; + var detail = arguments[7] || 25; + + var shape; + var gId; + + // check if it is an ellipse or an arc + if (Math.abs(stop - start) >= constants.TWO_PI) { + shape = 'ellipse'; + gId = shape + '|' + detail + '|'; + } else { + shape = 'arc'; + gId = shape + '|' + start + '|' + stop + '|' + mode + '|' + detail + '|'; + } + + if (!this.geometryInHash(gId)) { + var _arc = function _arc() { + this.strokeIndices = []; + + // if the start and stop angles are not the same, push vertices to the array + if (start.toFixed(10) !== stop.toFixed(10)) { + // if the mode specified is PIE or null, push the mid point of the arc in vertices + if (mode === constants.PIE || typeof mode === 'undefined') { + this.vertices.push(new p5.Vector(0.5, 0.5, 0)); + this.uvs.push([0.5, 0.5]); + } + + // vertices for the perimeter of the circle + for (var i = 0; i <= detail; i++) { + var u = i / detail; + var theta = (stop - start) * u + start; + + var _x = 0.5 + Math.cos(theta) / 2; + var _y = 0.5 + Math.sin(theta) / 2; + + this.vertices.push(new p5.Vector(_x, _y, 0)); + this.uvs.push([_x, _y]); + + if (i < detail - 1) { + this.faces.push([0, i + 1, i + 2]); + this.strokeIndices.push([i + 1, i + 2]); + } + } + + // check the mode specified in order to push vertices and faces, different for each mode + switch (mode) { + case constants.PIE: + this.faces.push([ + 0, + this.vertices.length - 2, + this.vertices.length - 1 + ]); + + this.strokeIndices.push([0, 1]); + this.strokeIndices.push([ + this.vertices.length - 2, + this.vertices.length - 1 + ]); + + this.strokeIndices.push([0, this.vertices.length - 1]); + break; + + case constants.CHORD: + this.strokeIndices.push([0, 1]); + this.strokeIndices.push([0, this.vertices.length - 1]); + break; + + case constants.OPEN: + this.strokeIndices.push([0, 1]); + break; + + default: + this.faces.push([ + 0, + this.vertices.length - 2, + this.vertices.length - 1 + ]); + + this.strokeIndices.push([ + this.vertices.length - 2, + this.vertices.length - 1 + ]); + } + } + }; + + var arcGeom = new p5.Geometry(detail, 1, _arc); + arcGeom.computeNormals(); + + if (detail <= 50) { + arcGeom._makeTriangleEdges()._edgesToVertices(arcGeom); + } else { + console.log('Cannot stroke ' + shape + ' with more than 50 detail'); + } + + this.createBuffers(gId, arcGeom); + } + + var uMVMatrix = this.uMVMatrix.copy(); + + try { + this.uMVMatrix.translate([x, y, 0]); + this.uMVMatrix.scale(width, height, 1); + + this.drawBuffers(gId); + } finally { + this.uMVMatrix = uMVMatrix; + } + + return this; + }; + + p5.RendererGL.prototype.rect = function(args) { + var perPixelLighting = this._pInst._glAttributes.perPixelLighting; + var x = args[0]; + var y = args[1]; + var width = args[2]; + var height = args[3]; + var detailX = args[4] || (perPixelLighting ? 1 : 24); + var detailY = args[5] || (perPixelLighting ? 1 : 16); + var gId = 'rect|' + detailX + '|' + detailY; + if (!this.geometryInHash(gId)) { + var _rect = function _rect() { + for (var i = 0; i <= this.detailY; i++) { + var v = i / this.detailY; + for (var j = 0; j <= this.detailX; j++) { + var u = j / this.detailX; + var p = new p5.Vector(u, v, 0); + this.vertices.push(p); + this.uvs.push(u, v); + } + } + // using stroke indices to avoid stroke over face(s) of rectangle + if (detailX > 0 && detailY > 0) { + this.strokeIndices = [ + [0, detailX], + [detailX, (detailX + 1) * (detailY + 1) - 1], + [(detailX + 1) * (detailY + 1) - 1, (detailX + 1) * detailY], + [(detailX + 1) * detailY, 0] + ]; + } + }; + var rectGeom = new p5.Geometry(detailX, detailY, _rect); + rectGeom + .computeFaces() + .computeNormals() + ._makeTriangleEdges() + ._edgesToVertices(); + this.createBuffers(gId, rectGeom); + } + + // only a single rectangle (of a given detail) is cached: a square with + // opposite corners at (0,0) & (1,1). + // + // before rendering, this square is scaled & moved to the required location. + var uMVMatrix = this.uMVMatrix.copy(); + try { + this.uMVMatrix.translate([x, y, 0]); + this.uMVMatrix.scale(width, height, 1); + + this.drawBuffers(gId); + } finally { + this.uMVMatrix = uMVMatrix; + } + return this; + }; + + // prettier-ignore + p5.RendererGL.prototype.quad = function (x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4) { + var gId = + 'quad|' + + x1 + + '|' + + y1 + + '|' + + z1 + + '|' + + x2 + + '|' + + y2 + + '|' + + z2 + + '|' + + x3 + + '|' + + y3 + + '|' + + z3 + + '|' + + x4 + + '|' + + y4 + + '|' + + z4; + if (!this.geometryInHash(gId)) { + var _quad = function _quad() { + this.vertices.push(new p5.Vector(x1, y1, z1)); + this.vertices.push(new p5.Vector(x2, y2, z2)); + this.vertices.push(new p5.Vector(x3, y3, z3)); + this.vertices.push(new p5.Vector(x4, y4, z4)); + this.uvs.push(0, 0, 1, 0, 1, 1, 0, 1); + this.strokeIndices = [[0, 1], [1, 2], [2, 3], [3, 0]]; + }; + var quadGeom = new p5.Geometry(2, 2, _quad); + quadGeom. + computeNormals(). + _makeTriangleEdges(). + _edgesToVertices(); + quadGeom.faces = [[0, 1, 2], [2, 3, 0]]; + this.createBuffers(gId, quadGeom); + } + this.drawBuffers(gId); + return this; +}; + + //this implementation of bezier curve + //is based on Bernstein polynomial + // pretier-ignore + p5.RendererGL.prototype.bezier = function( + x1, + y1, + z1, // x2 + x2, // y2 + y2, // x3 + z2, // y3 + x3, // x4 + y3, // y4 + z3, + x4, + y4, + z4 + ) { + if (arguments.length === 8) { + y4 = y3; + x4 = x3; + y3 = z2; + x3 = y2; + y2 = x2; + x2 = z1; + z1 = z2 = z3 = z4 = 0; + } + var bezierDetail = this._pInst._bezierDetail || 20; //value of Bezier detail + this.beginShape(); + for (var i = 0; i <= bezierDetail; i++) { + var c1 = Math.pow(1 - i / bezierDetail, 3); + var c2 = 3 * (i / bezierDetail) * Math.pow(1 - i / bezierDetail, 2); + var c3 = 3 * Math.pow(i / bezierDetail, 2) * (1 - i / bezierDetail); + var c4 = Math.pow(i / bezierDetail, 3); + this.vertex( + x1 * c1 + x2 * c2 + x3 * c3 + x4 * c4, + y1 * c1 + y2 * c2 + y3 * c3 + y4 * c4, + z1 * c1 + z2 * c2 + z3 * c3 + z4 * c4 + ); + } + this.endShape(); + return this; + }; + + // pretier-ignore + p5.RendererGL.prototype.curve = function( + x1, + y1, + z1, // x2 + x2, // y2 + y2, // x3 + z2, // y3 + x3, // x4 + y3, // y4 + z3, + x4, + y4, + z4 + ) { + if (arguments.length === 8) { + x4 = x3; + y4 = y3; + x3 = y2; + y3 = x2; + x2 = z1; + y2 = x2; + z1 = z2 = z3 = z4 = 0; + } + var curveDetail = this._pInst._curveDetail; + this.beginShape(); + for (var i = 0; i <= curveDetail; i++) { + var c1 = Math.pow(i / curveDetail, 3) * 0.5; + var c2 = Math.pow(i / curveDetail, 2) * 0.5; + var c3 = i / curveDetail * 0.5; + var c4 = 0.5; + var vx = + c1 * (-x1 + 3 * x2 - 3 * x3 + x4) + + c2 * (2 * x1 - 5 * x2 + 4 * x3 - x4) + + c3 * (-x1 + x3) + + c4 * (2 * x2); + var vy = + c1 * (-y1 + 3 * y2 - 3 * y3 + y4) + + c2 * (2 * y1 - 5 * y2 + 4 * y3 - y4) + + c3 * (-y1 + y3) + + c4 * (2 * y2); + var vz = + c1 * (-z1 + 3 * z2 - 3 * z3 + z4) + + c2 * (2 * z1 - 5 * z2 + 4 * z3 - z4) + + c3 * (-z1 + z3) + + c4 * (2 * z2); + this.vertex(vx, vy, vz); + } + this.endShape(); + return this; + }; + + /** + * Draw a line given two points + * @private + * @param {Number} x0 x-coordinate of first vertex + * @param {Number} y0 y-coordinate of first vertex + * @param {Number} z0 z-coordinate of first vertex + * @param {Number} x1 x-coordinate of second vertex + * @param {Number} y1 y-coordinate of second vertex + * @param {Number} z1 z-coordinate of second vertex + * @chainable + * @example + *
+ * + * //draw a line + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * // Use fill instead of stroke to change the color of shape. + * fill(255, 0, 0); + * line(10, 10, 0, 60, 60, 20); + * } + * + *
+ */ + p5.RendererGL.prototype.line = function() { + if (arguments.length === 6) { + this.beginShape(); + this.vertex(arguments[0], arguments[1], arguments[2]); + this.vertex(arguments[3], arguments[4], arguments[5]); + this.endShape(); + } else if (arguments.length === 4) { + this.beginShape(); + this.vertex(arguments[0], arguments[1], 0); + this.vertex(arguments[2], arguments[3], 0); + this.endShape(); + } + return this; + }; + + p5.RendererGL.prototype.bezierVertex = function() { + if (this.immediateMode._bezierVertex.length === 0) { + throw Error('vertex() must be used once before calling bezierVertex()'); + } else { + var w_x = []; + var w_y = []; + var w_z = []; + var t, _x, _y, _z, i; + var argLength = arguments.length; + + t = 0; + + if ( + this._lookUpTableBezier.length === 0 || + this._lutBezierDetail !== this._pInst._curveDetail + ) { + this._lookUpTableBezier = []; + this._lutBezierDetail = this._pInst._curveDetail; + var step = 1 / this._lutBezierDetail; + var start = 0; + var end = 1; + var j = 0; + while (start < 1) { + t = parseFloat(start.toFixed(6)); + this._lookUpTableBezier[j] = this._bezierCoefficients(t); + if (end.toFixed(6) === step.toFixed(6)) { + t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6)); + ++j; + this._lookUpTableBezier[j] = this._bezierCoefficients(t); + break; + } + start += step; + end -= step; + ++j; + } + } + + var LUTLength = this._lookUpTableBezier.length; + + if (argLength === 6) { + this.isBezier = true; + + w_x = [ + this.immediateMode._bezierVertex[0], + arguments[0], + arguments[2], + arguments[4] + ]; + + w_y = [ + this.immediateMode._bezierVertex[1], + arguments[1], + arguments[3], + arguments[5] + ]; + + for (i = 0; i < LUTLength; i++) { + _x = + w_x[0] * this._lookUpTableBezier[i][0] + + w_x[1] * this._lookUpTableBezier[i][1] + + w_x[2] * this._lookUpTableBezier[i][2] + + w_x[3] * this._lookUpTableBezier[i][3]; + _y = + w_y[0] * this._lookUpTableBezier[i][0] + + w_y[1] * this._lookUpTableBezier[i][1] + + w_y[2] * this._lookUpTableBezier[i][2] + + w_y[3] * this._lookUpTableBezier[i][3]; + this.vertex(_x, _y); + } + this.immediateMode._bezierVertex[0] = arguments[4]; + this.immediateMode._bezierVertex[1] = arguments[5]; + } else if (argLength === 9) { + this.isBezier = true; + + w_x = [ + this.immediateMode._bezierVertex[0], + arguments[0], + arguments[3], + arguments[6] + ]; + + w_y = [ + this.immediateMode._bezierVertex[1], + arguments[1], + arguments[4], + arguments[7] + ]; + + w_z = [ + this.immediateMode._bezierVertex[2], + arguments[2], + arguments[5], + arguments[8] + ]; + + for (i = 0; i < LUTLength; i++) { + _x = + w_x[0] * this._lookUpTableBezier[i][0] + + w_x[1] * this._lookUpTableBezier[i][1] + + w_x[2] * this._lookUpTableBezier[i][2] + + w_x[3] * this._lookUpTableBezier[i][3]; + _y = + w_y[0] * this._lookUpTableBezier[i][0] + + w_y[1] * this._lookUpTableBezier[i][1] + + w_y[2] * this._lookUpTableBezier[i][2] + + w_y[3] * this._lookUpTableBezier[i][3]; + _z = + w_z[0] * this._lookUpTableBezier[i][0] + + w_z[1] * this._lookUpTableBezier[i][1] + + w_z[2] * this._lookUpTableBezier[i][2] + + w_z[3] * this._lookUpTableBezier[i][3]; + this.vertex(_x, _y, _z); + } + this.immediateMode._bezierVertex[0] = arguments[6]; + this.immediateMode._bezierVertex[1] = arguments[7]; + this.immediateMode._bezierVertex[2] = arguments[8]; + } + } + }; + + p5.RendererGL.prototype.quadraticVertex = function() { + if (this.immediateMode._quadraticVertex.length === 0) { + throw Error('vertex() must be used once before calling quadraticVertex()'); + } else { + var w_x = []; + var w_y = []; + var w_z = []; + var t, _x, _y, _z, i; + var argLength = arguments.length; + + t = 0; + + if ( + this._lookUpTableQuadratic.length === 0 || + this._lutQuadraticDetail !== this._pInst._curveDetail + ) { + this._lookUpTableQuadratic = []; + this._lutQuadraticDetail = this._pInst._curveDetail; + var step = 1 / this._lutQuadraticDetail; + var start = 0; + var end = 1; + var j = 0; + while (start < 1) { + t = parseFloat(start.toFixed(6)); + this._lookUpTableQuadratic[j] = this._quadraticCoefficients(t); + if (end.toFixed(6) === step.toFixed(6)) { + t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6)); + ++j; + this._lookUpTableQuadratic[j] = this._quadraticCoefficients(t); + break; + } + start += step; + end -= step; + ++j; + } + } + + var LUTLength = this._lookUpTableQuadratic.length; + + if (argLength === 4) { + this.isQuadratic = true; + + w_x = [this.immediateMode._quadraticVertex[0], arguments[0], arguments[2]]; + + w_y = [this.immediateMode._quadraticVertex[1], arguments[1], arguments[3]]; + + for (i = 0; i < LUTLength; i++) { + _x = + w_x[0] * this._lookUpTableQuadratic[i][0] + + w_x[1] * this._lookUpTableQuadratic[i][1] + + w_x[2] * this._lookUpTableQuadratic[i][2]; + _y = + w_y[0] * this._lookUpTableQuadratic[i][0] + + w_y[1] * this._lookUpTableQuadratic[i][1] + + w_y[2] * this._lookUpTableQuadratic[i][2]; + this.vertex(_x, _y); + } + + this.immediateMode._quadraticVertex[0] = arguments[2]; + this.immediateMode._quadraticVertex[1] = arguments[3]; + } else if (argLength === 6) { + this.isQuadratic = true; + + w_x = [this.immediateMode._quadraticVertex[0], arguments[0], arguments[3]]; + + w_y = [this.immediateMode._quadraticVertex[1], arguments[1], arguments[4]]; + + w_z = [this.immediateMode._quadraticVertex[2], arguments[2], arguments[5]]; + + for (i = 0; i < LUTLength; i++) { + _x = + w_x[0] * this._lookUpTableQuadratic[i][0] + + w_x[1] * this._lookUpTableQuadratic[i][1] + + w_x[2] * this._lookUpTableQuadratic[i][2]; + _y = + w_y[0] * this._lookUpTableQuadratic[i][0] + + w_y[1] * this._lookUpTableQuadratic[i][1] + + w_y[2] * this._lookUpTableQuadratic[i][2]; + _z = + w_z[0] * this._lookUpTableQuadratic[i][0] + + w_z[1] * this._lookUpTableQuadratic[i][1] + + w_z[2] * this._lookUpTableQuadratic[i][2]; + this.vertex(_x, _y, _z); + } + + this.immediateMode._quadraticVertex[0] = arguments[3]; + this.immediateMode._quadraticVertex[1] = arguments[4]; + this.immediateMode._quadraticVertex[2] = arguments[5]; + } + } + }; + + p5.RendererGL.prototype.curveVertex = function() { + var w_x = []; + var w_y = []; + var w_z = []; + var t, _x, _y, _z, i; + t = 0; + var argLength = arguments.length; + + if ( + this._lookUpTableBezier.length === 0 || + this._lutBezierDetail !== this._pInst._curveDetail + ) { + this._lookUpTableBezier = []; + this._lutBezierDetail = this._pInst._curveDetail; + var step = 1 / this._lutBezierDetail; + var start = 0; + var end = 1; + var j = 0; + while (start < 1) { + t = parseFloat(start.toFixed(6)); + this._lookUpTableBezier[j] = this._bezierCoefficients(t); + if (end.toFixed(6) === step.toFixed(6)) { + t = parseFloat(end.toFixed(6)) + parseFloat(start.toFixed(6)); + ++j; + this._lookUpTableBezier[j] = this._bezierCoefficients(t); + break; + } + start += step; + end -= step; + ++j; + } + } + + var LUTLength = this._lookUpTableBezier.length; + + if (argLength === 2) { + this.immediateMode._curveVertex.push(arguments[0]); + this.immediateMode._curveVertex.push(arguments[1]); + if (this.immediateMode._curveVertex.length === 8) { + this.isCurve = true; + w_x = this._bezierToCatmull([ + this.immediateMode._curveVertex[0], + this.immediateMode._curveVertex[2], + this.immediateMode._curveVertex[4], + this.immediateMode._curveVertex[6] + ]); + + w_y = this._bezierToCatmull([ + this.immediateMode._curveVertex[1], + this.immediateMode._curveVertex[3], + this.immediateMode._curveVertex[5], + this.immediateMode._curveVertex[7] + ]); + + for (i = 0; i < LUTLength; i++) { + _x = + w_x[0] * this._lookUpTableBezier[i][0] + + w_x[1] * this._lookUpTableBezier[i][1] + + w_x[2] * this._lookUpTableBezier[i][2] + + w_x[3] * this._lookUpTableBezier[i][3]; + _y = + w_y[0] * this._lookUpTableBezier[i][0] + + w_y[1] * this._lookUpTableBezier[i][1] + + w_y[2] * this._lookUpTableBezier[i][2] + + w_y[3] * this._lookUpTableBezier[i][3]; + this.vertex(_x, _y); + } + for (i = 0; i < argLength; i++) { + this.immediateMode._curveVertex.shift(); + } + } + } else if (argLength === 3) { + this.immediateMode._curveVertex.push(arguments[0]); + this.immediateMode._curveVertex.push(arguments[1]); + this.immediateMode._curveVertex.push(arguments[2]); + if (this.immediateMode._curveVertex.length === 12) { + this.isCurve = true; + w_x = this._bezierToCatmull([ + this.immediateMode._curveVertex[0], + this.immediateMode._curveVertex[3], + this.immediateMode._curveVertex[6], + this.immediateMode._curveVertex[9] + ]); + + w_y = this._bezierToCatmull([ + this.immediateMode._curveVertex[1], + this.immediateMode._curveVertex[4], + this.immediateMode._curveVertex[7], + this.immediateMode._curveVertex[10] + ]); + + w_z = this._bezierToCatmull([ + this.immediateMode._curveVertex[2], + this.immediateMode._curveVertex[5], + this.immediateMode._curveVertex[8], + this.immediateMode._curveVertex[11] + ]); + + for (i = 0; i < LUTLength; i++) { + _x = + w_x[0] * this._lookUpTableBezier[i][0] + + w_x[1] * this._lookUpTableBezier[i][1] + + w_x[2] * this._lookUpTableBezier[i][2] + + w_x[3] * this._lookUpTableBezier[i][3]; + _y = + w_y[0] * this._lookUpTableBezier[i][0] + + w_y[1] * this._lookUpTableBezier[i][1] + + w_y[2] * this._lookUpTableBezier[i][2] + + w_y[3] * this._lookUpTableBezier[i][3]; + _z = + w_z[0] * this._lookUpTableBezier[i][0] + + w_z[1] * this._lookUpTableBezier[i][1] + + w_z[2] * this._lookUpTableBezier[i][2] + + w_z[3] * this._lookUpTableBezier[i][3]; + this.vertex(_x, _y, _z); + } + for (i = 0; i < argLength; i++) { + this.immediateMode._curveVertex.shift(); + } + } + } + }; + + p5.RendererGL.prototype.image = function( + img, + sx, + sy, + sWidth, + sHeight, + dx, + dy, + dWidth, + dHeight + ) { + this._pInst.push(); + + this._pInst.texture(img); + this._pInst.textureMode(constants.NORMAL); + + var u0 = 0; + if (sx <= img.width) { + u0 = sx / img.width; + } + + var u1 = 1; + if (sx + sWidth <= img.width) { + u1 = (sx + sWidth) / img.width; + } + + var v0 = 0; + if (sy <= img.height) { + v0 = sy / img.height; + } + + var v1 = 1; + if (sy + sHeight <= img.height) { + v1 = (sy + sHeight) / img.height; + } + + this.beginShape(); + this.vertex(dx, dy, 0, u0, v0); + this.vertex(dx + dWidth, dy, 0, u1, v0); + this.vertex(dx + dWidth, dy + dHeight, 0, u1, v1); + this.vertex(dx, dy + dHeight, 0, u0, v1); + this.endShape(constants.CLOSE); + + this._pInst.pop(); + }; + + module.exports = p5; + }, + { '../core/constants': 18, '../core/main': 24, './p5.Geometry': 71 } + ], + 66: [ + function(_dereq_, module, exports) { + /** + * @module Lights, Camera + * @submodule Interaction + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + + /** + * Allows movement around a 3D sketch using a mouse or trackpad. Left-clicking + * and dragging will rotate the camera position about the center of the sketch, + * right-clicking and dragging will pan the camera position without rotation, + * and using the mouse wheel (scrolling) will move the camera closer or further + * from the center of the sketch. This function can be called with parameters + * dictating sensitivity to mouse movement along the X and Y axes. Calling + * this function without parameters is equivalent to calling orbitControl(1,1). + * To reverse direction of movement in either axis, enter a negative number + * for sensitivity. + * @method orbitControl + * @for p5 + * @param {Number} [sensitivityX] sensitivity to mouse movement along X axis + * @param {Number} [sensitivityY] sensitivity to mouse movement along Y axis + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * normalMaterial(); + * } + * function draw() { + * background(200); + * orbitControl(); + * rotateY(0.5); + * box(30, 50); + * } + * + *
+ * + * @alt + * Camera orbits around a box when mouse is hold-clicked & then moved. + */ + + // implementation based on three.js 'orbitControls': + // https://github.com/mrdoob/three.js/blob/dev/examples/js/controls/OrbitControls.js + p5.prototype.orbitControl = function(sensitivityX, sensitivityY) { + this._assert3d('orbitControl'); + p5._validateParameters('orbitControl', arguments); + + // If the mouse is not in bounds of the canvas, disable all behaviors: + var mouseInCanvas = + this.mouseX < this.width && + this.mouseX > 0 && + this.mouseY < this.height && + this.mouseY > 0; + if (!mouseInCanvas) return; + + var cam = this._renderer._curCamera; + + if (typeof sensitivityX === 'undefined') { + sensitivityX = 1; + } + if (typeof sensitivityY === 'undefined') { + sensitivityY = sensitivityX; + } + + // default right-mouse and mouse-wheel behaviors (context menu and scrolling, + // respectively) are disabled here to allow use of those events for panning and + // zooming + + // disable context menu for canvas element and add 'contextMenuDisabled' + // flag to p5 instance + if (this.contextMenuDisabled !== true) { + this.canvas.oncontextmenu = function() { + return false; + }; + this._setProperty('contextMenuDisabled', true); + } + + // disable default scrolling behavior on the canvas element and add + // 'wheelDefaultDisabled' flag to p5 instance + if (this.wheelDefaultDisabled !== true) { + this.canvas.onwheel = function() { + return false; + }; + this._setProperty('wheelDefaultDisabled', true); + } + + var scaleFactor = this.height < this.width ? this.height : this.width; + + // ZOOM if there is a change in mouseWheelDelta + if (this._mouseWheelDeltaY !== this._pmouseWheelDeltaY) { + // zoom according to direction of mouseWheelDeltaY rather than value + if (this._mouseWheelDeltaY > 0) { + this._renderer._curCamera._orbit(0, 0, 0.5 * scaleFactor); + } else { + this._renderer._curCamera._orbit(0, 0, -0.5 * scaleFactor); + } + } + + if (this.mouseIsPressed) { + // ORBIT BEHAVIOR + if (this.mouseButton === this.LEFT) { + var deltaTheta = -sensitivityX * (this.mouseX - this.pmouseX) / scaleFactor; + var deltaPhi = sensitivityY * (this.mouseY - this.pmouseY) / scaleFactor; + this._renderer._curCamera._orbit(deltaTheta, deltaPhi, 0); + } else if (this.mouseButton === this.RIGHT) { + // PANNING BEHAVIOR along X/Z camera axes and restricted to X/Z plane + // in world space + var local = cam._getLocalAxes(); + + // normalize portions along X/Z axes + var xmag = Math.sqrt(local.x[0] * local.x[0] + local.x[2] * local.x[2]); + if (xmag !== 0) { + local.x[0] /= xmag; + local.x[2] /= xmag; + } + + // normalize portions along X/Z axes + var ymag = Math.sqrt(local.y[0] * local.y[0] + local.y[2] * local.y[2]); + if (ymag !== 0) { + local.y[0] /= ymag; + local.y[2] /= ymag; + } + + // move along those vectors by amount controlled by mouseX, pmouseY + var dx = -1 * sensitivityX * (this.mouseX - this.pmouseX); + var dz = -1 * sensitivityY * (this.mouseY - this.pmouseY); + + // restrict movement to XZ plane in world space + cam.setPosition( + cam.eyeX + dx * local.x[0] + dz * local.z[0], + cam.eyeY, + cam.eyeZ + dx * local.x[2] + dz * local.z[2] + ); + } + } + return this; + }; + + /** + * debugMode() helps visualize 3D space by adding a grid to indicate where the + * ‘ground’ is in a sketch and an axes icon which indicates the +X, +Y, and +Z + * directions. This function can be called without parameters to create a + * default grid and axes icon, or it can be called according to the examples + * above to customize the size and position of the grid and/or axes icon. The + * grid is drawn using the most recently set stroke color and weight. To + * specify these parameters, add a call to stroke() and strokeWeight() + * just before the end of the draw() loop. + * + * By default, the grid will run through the origin (0,0,0) of the sketch + * along the XZ plane + * and the axes icon will be offset from the origin. Both the grid and axes + * icon will be sized according to the current canvas size. Note that because the + * grid runs parallel to the default camera view, it is often helpful to use + * debugMode along with orbitControl to allow full view of the grid. + * @method debugMode + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + * normalMaterial(); + * debugMode(); + * } + * + * function draw() { + * background(200); + * orbitControl(); + * box(15, 30); + * // Press the spacebar to turn debugMode off! + * if (keyIsDown(32)) { + * noDebugMode(); + * } + * } + * + *
+ * @alt + * a 3D box is centered on a grid in a 3D sketch. an icon + * indicates the direction of each axis: a red line points +X, + * a green line +Y, and a blue line +Z. the grid and icon disappear when the + * spacebar is pressed. + * + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + * normalMaterial(); + * debugMode(GRID); + * } + * + * function draw() { + * background(200); + * orbitControl(); + * box(15, 30); + * } + * + *
+ * @alt + * a 3D box is centered on a grid in a 3D sketch. + * + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + * normalMaterial(); + * debugMode(AXES); + * } + * + * function draw() { + * background(200); + * orbitControl(); + * box(15, 30); + * } + * + *
+ * @alt + * a 3D box is centered in a 3D sketch. an icon + * indicates the direction of each axis: a red line points +X, + * a green line +Y, and a blue line +Z. + * + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + * normalMaterial(); + * debugMode(GRID, 100, 10, 0, 0, 0); + * } + * + * function draw() { + * background(200); + * orbitControl(); + * box(15, 30); + * } + * + *
+ * @alt + * a 3D box is centered on a grid in a 3D sketch + * + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + * normalMaterial(); + * debugMode(100, 10, 0, 0, 0, 20, 0, -40, 0); + * } + * + * function draw() { + * noStroke(); + * background(200); + * orbitControl(); + * box(15, 30); + * // set the stroke color and weight for the grid! + * stroke(255, 0, 150); + * strokeWeight(0.8); + * } + * + *
+ * @alt + * a 3D box is centered on a grid in a 3D sketch. an icon + * indicates the direction of each axis: a red line points +X, + * a green line +Y, and a blue line +Z. + */ + + /** + * @method debugMode + * @param {Constant} mode either GRID or AXES + */ + + /** + * @method debugMode + * @param {Constant} mode + * @param {Number} [gridSize] size of one side of the grid + * @param {Number} [gridDivisions] number of divisions in the grid + * @param {Number} [xOff] X axis offset from origin (0,0,0) + * @param {Number} [yOff] Y axis offset from origin (0,0,0) + * @param {Number} [zOff] Z axis offset from origin (0,0,0) + */ + + /** + * @method debugMode + * @param {Constant} mode + * @param {Number} [axesSize] size of axes icon + * @param {Number} [xOff] + * @param {Number} [yOff] + * @param {Number} [zOff] + */ + + /** + * @method debugMode + * @param {Number} [gridSize] + * @param {Number} [gridDivisions] + * @param {Number} [gridXOff] + * @param {Number} [gridYOff] + * @param {Number} [gridZOff] + * @param {Number} [axesSize] + * @param {Number} [axesXOff] + * @param {Number} [axesYOff] + * @param {Number} [axesZOff] + */ + + p5.prototype.debugMode = function() { + this._assert3d('debugMode'); + p5._validateParameters('debugMode', arguments); + + // start by removing existing 'post' registered debug methods + for (var i = this._registeredMethods.post.length - 1; i >= 0; i--) { + // test for equality... + if ( + this._registeredMethods.post[i].toString() === this._grid().toString() || + this._registeredMethods.post[i].toString() === this._axesIcon().toString() + ) { + this._registeredMethods.post.splice(i, 1); + } + } + + // then add new debugMode functions according to the argument list + if (arguments[0] === constants.GRID) { + this.registerMethod( + 'post', + this._grid.call( + this, + arguments[1], + arguments[2], + arguments[3], + arguments[4], + arguments[5] + ) + ); + } else if (arguments[0] === constants.AXES) { + this.registerMethod( + 'post', + this._axesIcon.call( + this, + arguments[1], + arguments[2], + arguments[3], + arguments[4] + ) + ); + } else { + this.registerMethod( + 'post', + this._grid.call( + this, + arguments[0], + arguments[1], + arguments[2], + arguments[3], + arguments[4] + ) + ); + + this.registerMethod( + 'post', + this._axesIcon.call( + this, + arguments[5], + arguments[6], + arguments[7], + arguments[8] + ) + ); + } + }; + + /** + * Turns off debugMode() in a 3D sketch. + * @method noDebugMode + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * camera(0, -30, 100, 0, 0, 0, 0, 1, 0); + * normalMaterial(); + * debugMode(); + * } + * + * function draw() { + * background(200); + * orbitControl(); + * box(15, 30); + * // Press the spacebar to turn debugMode off! + * if (keyIsDown(32)) { + * noDebugMode(); + * } + * } + * + *
+ * @alt + * a 3D box is centered on a grid in a 3D sketch. an icon + * indicates the direction of each axis: a red line points +X, + * a green line +Y, and a blue line +Z. the grid and icon disappear when the + * spacebar is pressed. + */ + p5.prototype.noDebugMode = function() { + this._assert3d('noDebugMode'); + + // start by removing existing 'post' registered debug methods + for (var i = this._registeredMethods.post.length - 1; i >= 0; i--) { + // test for equality... + if ( + this._registeredMethods.post[i].toString() === this._grid().toString() || + this._registeredMethods.post[i].toString() === this._axesIcon().toString() + ) { + this._registeredMethods.post.splice(i, 1); + } + } + }; + + /** + * For use with debugMode + * @private + * @method _grid + * @param {Number} [size] size of grid sides + * @param {Number} [div] number of grid divisions + * @param {Number} [xOff] offset of grid center from origin in X axis + * @param {Number} [yOff] offset of grid center from origin in Y axis + * @param {Number} [zOff] offset of grid center from origin in Z axis + */ + p5.prototype._grid = function(size, numDivs, xOff, yOff, zOff) { + if (typeof size === 'undefined') { + size = this.width / 2; + } + if (typeof numDivs === 'undefined') { + // ensure at least 2 divisions + numDivs = Math.round(size / 30) < 4 ? 4 : Math.round(size / 30); + } + if (typeof xOff === 'undefined') { + xOff = 0; + } + if (typeof yOff === 'undefined') { + yOff = 0; + } + if (typeof zOff === 'undefined') { + zOff = 0; + } + + var spacing = size / numDivs; + var halfSize = size / 2; + + return function() { + this.push(); + this.stroke( + this._renderer.curStrokeColor[0] * 255, + this._renderer.curStrokeColor[1] * 255, + this._renderer.curStrokeColor[2] * 255 + ); + + this._renderer.uMVMatrix.set( + this._renderer._curCamera.cameraMatrix.mat4[0], + this._renderer._curCamera.cameraMatrix.mat4[1], + this._renderer._curCamera.cameraMatrix.mat4[2], + this._renderer._curCamera.cameraMatrix.mat4[3], + this._renderer._curCamera.cameraMatrix.mat4[4], + this._renderer._curCamera.cameraMatrix.mat4[5], + this._renderer._curCamera.cameraMatrix.mat4[6], + this._renderer._curCamera.cameraMatrix.mat4[7], + this._renderer._curCamera.cameraMatrix.mat4[8], + this._renderer._curCamera.cameraMatrix.mat4[9], + this._renderer._curCamera.cameraMatrix.mat4[10], + this._renderer._curCamera.cameraMatrix.mat4[11], + this._renderer._curCamera.cameraMatrix.mat4[12], + this._renderer._curCamera.cameraMatrix.mat4[13], + this._renderer._curCamera.cameraMatrix.mat4[14], + this._renderer._curCamera.cameraMatrix.mat4[15] + ); + + // Lines along X axis + for (var q = 0; q <= numDivs; q++) { + this.beginShape(this.LINES); + this.vertex(-halfSize + xOff, yOff, q * spacing - halfSize + zOff); + this.vertex(+halfSize + xOff, yOff, q * spacing - halfSize + zOff); + this.endShape(); + } + + // Lines along Z axis + for (var i = 0; i <= numDivs; i++) { + this.beginShape(this.LINES); + this.vertex(i * spacing - halfSize + xOff, yOff, -halfSize + zOff); + this.vertex(i * spacing - halfSize + xOff, yOff, +halfSize + zOff); + this.endShape(); + } + + this.pop(); + }; + }; + + /** + * For use with debugMode + * @private + * @method _axesIcon + * @param {Number} [size] size of axes icon lines + * @param {Number} [xOff] offset of icon from origin in X axis + * @param {Number} [yOff] offset of icon from origin in Y axis + * @param {Number} [zOff] offset of icon from origin in Z axis + */ + p5.prototype._axesIcon = function(size, xOff, yOff, zOff) { + if (typeof size === 'undefined') { + size = this.width / 20 > 40 ? this.width / 20 : 40; + } + if (typeof xOff === 'undefined') { + xOff = -this.width / 4; + } + if (typeof yOff === 'undefined') { + yOff = xOff; + } + if (typeof zOff === 'undefined') { + zOff = xOff; + } + + return function() { + this.push(); + this._renderer.uMVMatrix.set( + this._renderer._curCamera.cameraMatrix.mat4[0], + this._renderer._curCamera.cameraMatrix.mat4[1], + this._renderer._curCamera.cameraMatrix.mat4[2], + this._renderer._curCamera.cameraMatrix.mat4[3], + this._renderer._curCamera.cameraMatrix.mat4[4], + this._renderer._curCamera.cameraMatrix.mat4[5], + this._renderer._curCamera.cameraMatrix.mat4[6], + this._renderer._curCamera.cameraMatrix.mat4[7], + this._renderer._curCamera.cameraMatrix.mat4[8], + this._renderer._curCamera.cameraMatrix.mat4[9], + this._renderer._curCamera.cameraMatrix.mat4[10], + this._renderer._curCamera.cameraMatrix.mat4[11], + this._renderer._curCamera.cameraMatrix.mat4[12], + this._renderer._curCamera.cameraMatrix.mat4[13], + this._renderer._curCamera.cameraMatrix.mat4[14], + this._renderer._curCamera.cameraMatrix.mat4[15] + ); + + // X axis + this.strokeWeight(2); + this.stroke(255, 0, 0); + this.beginShape(this.LINES); + this.vertex(xOff, yOff, zOff); + this.vertex(xOff + size, yOff, zOff); + this.endShape(); + // Y axis + this.stroke(0, 255, 0); + this.beginShape(this.LINES); + this.vertex(xOff, yOff, zOff); + this.vertex(xOff, yOff + size, zOff); + this.endShape(); + // Z axis + this.stroke(0, 0, 255); + this.beginShape(this.LINES); + this.vertex(xOff, yOff, zOff); + this.vertex(xOff, yOff, zOff + size); + this.endShape(); + this.pop(); + }; + }; + + module.exports = p5; + }, + { '../core/constants': 18, '../core/main': 24 } + ], + 67: [ + function(_dereq_, module, exports) { + /** + * @module Lights, Camera + * @submodule Lights + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * Creates an ambient light with a color + * + * @method ambientLight + * @param {Number} v1 red or hue value relative to + * the current color range + * @param {Number} v2 green or saturation value + * relative to the current color range + * @param {Number} v3 blue or brightness value + * relative to the current color range + * @param {Number} [alpha] the alpha value + * @chainable + * + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(0); + * ambientLight(150); + * ambientMaterial(250); + * noStroke(); + * sphere(40); + * } + * + *
+ * + * @alt + * evenly distributed light across a sphere + * + */ + + /** + * @method ambientLight + * @param {String} value a color string + * @chainable + */ + + /** + * @method ambientLight + * @param {Number} gray a gray value + * @param {Number} [alpha] + * @chainable + */ + + /** + * @method ambientLight + * @param {Number[]} values an array containing the red,green,blue & + * and alpha components of the color + * @chainable + */ + + /** + * @method ambientLight + * @param {p5.Color} color the ambient light color + * @chainable + */ + p5.prototype.ambientLight = function(v1, v2, v3, a) { + this._assert3d('ambientLight'); + p5._validateParameters('ambientLight', arguments); + var color = this.color.apply(this, arguments); + + this._renderer.ambientLightColors.push( + color._array[0], + color._array[1], + color._array[2] + ); + + this._renderer._enableLighting = true; + + return this; + }; + + /** + * Creates a directional light with a color and a direction + * @method directionalLight + * @param {Number} v1 red or hue value (depending on the current + * color mode), + * @param {Number} v2 green or saturation value + * @param {Number} v3 blue or brightness value + * @param {p5.Vector} position the direction of the light + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(0); + * //move your mouse to change light direction + * let dirX = (mouseX / width - 0.5) * 2; + * let dirY = (mouseY / height - 0.5) * 2; + * directionalLight(250, 250, 250, -dirX, -dirY, -1); + * noStroke(); + * sphere(40); + * } + * + *
+ * + * @alt + * light source on canvas changeable with mouse position + * + */ + + /** + * @method directionalLight + * @param {Number[]|String|p5.Color} color color Array, CSS color string, + * or p5.Color value + * @param {Number} x x axis direction + * @param {Number} y y axis direction + * @param {Number} z z axis direction + * @chainable + */ + + /** + * @method directionalLight + * @param {Number[]|String|p5.Color} color + * @param {p5.Vector} position + * @chainable + */ + + /** + * @method directionalLight + * @param {Number} v1 + * @param {Number} v2 + * @param {Number} v3 + * @param {Number} x + * @param {Number} y + * @param {Number} z + * @chainable + */ + p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) { + this._assert3d('directionalLight'); + p5._validateParameters('directionalLight', arguments); + + //@TODO: check parameters number + var color; + if (v1 instanceof p5.Color) { + color = v1; + } else { + color = this.color(v1, v2, v3); + } + + var _x, _y, _z; + var v = arguments[arguments.length - 1]; + if (typeof v === 'number') { + _x = arguments[arguments.length - 3]; + _y = arguments[arguments.length - 2]; + _z = arguments[arguments.length - 1]; + } else { + _x = v.x; + _y = v.y; + _z = v.z; + } + + // normalize direction + var l = Math.sqrt(_x * _x + _y * _y + _z * _z); + this._renderer.directionalLightDirections.push(_x / l, _y / l, _z / l); + + this._renderer.directionalLightColors.push( + color._array[0], + color._array[1], + color._array[2] + ); + + this._renderer._enableLighting = true; + + return this; + }; + + /** + * Creates a point light with a color and a light position + * @method pointLight + * @param {Number} v1 red or hue value (depending on the current + * color mode), + * @param {Number} v2 green or saturation value + * @param {Number} v3 blue or brightness value + * @param {Number} x x axis position + * @param {Number} y y axis position + * @param {Number} z z axis position + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(0); + * //move your mouse to change light position + * let locX = mouseX - width / 2; + * let locY = mouseY - height / 2; + * // to set the light position, + * // think of the world's coordinate as: + * // -width/2,-height/2 -------- width/2,-height/2 + * // | | + * // | 0,0 | + * // | | + * // -width/2,height/2--------width/2,height/2 + * pointLight(250, 250, 250, locX, locY, 50); + * noStroke(); + * sphere(40); + * } + * + *
+ * + * @alt + * spot light on canvas changes position with mouse + * + */ + + /** + * @method pointLight + * @param {Number} v1 + * @param {Number} v2 + * @param {Number} v3 + * @param {p5.Vector} position the position of the light + * @chainable + */ + + /** + * @method pointLight + * @param {Number[]|String|p5.Color} color color Array, CSS color string, + * or p5.Color value + * @param {Number} x + * @param {Number} y + * @param {Number} z + * @chainable + */ + + /** + * @method pointLight + * @param {Number[]|String|p5.Color} color + * @param {p5.Vector} position + * @chainable + */ + p5.prototype.pointLight = function(v1, v2, v3, x, y, z) { + this._assert3d('pointLight'); + p5._validateParameters('pointLight', arguments); + + //@TODO: check parameters number + var color; + if (v1 instanceof p5.Color) { + color = v1; + } else { + color = this.color(v1, v2, v3); + } + + var _x, _y, _z; + var v = arguments[arguments.length - 1]; + if (typeof v === 'number') { + _x = arguments[arguments.length - 3]; + _y = arguments[arguments.length - 2]; + _z = arguments[arguments.length - 1]; + } else { + _x = v.x; + _y = v.y; + _z = v.z; + } + + this._renderer.pointLightPositions.push(_x, _y, _z); + this._renderer.pointLightColors.push( + color._array[0], + color._array[1], + color._array[2] + ); + + this._renderer._enableLighting = true; + + return this; + }; + + /** + * Sets the default ambient and directional light. The defaults are ambientLight(128, 128, 128) and directionalLight(128, 128, 128, 0, 0, -1). Lights need to be included in the draw() to remain persistent in a looping program. Placing them in the setup() of a looping program will cause them to only have an effect the first time through the loop. + * @method lights + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(0); + * lights(); + * rotateX(millis() / 1000); + * rotateY(millis() / 1000); + * rotateZ(millis() / 1000); + * box(); + * } + * + *
+ * + * @alt + * the light is partially ambient and partially directional + */ + p5.prototype.lights = function() { + this._assert3d('lights'); + this.ambientLight(128, 128, 128); + this.directionalLight(128, 128, 128, 0, 0, -1); + return this; + }; + + /** + * Sets the falloff rates for point lights. It affects only the elements which are created after it in the code. + * The default value is lightFalloff(1.0, 0.0, 0.0), and the parameters are used to calculate the falloff with the following equation: + * + * d = distance from light position to vertex position + * + * falloff = 1 / (CONSTANT + d \* LINEAR + ( d \* d ) \* QUADRATIC) + * + * @method lightFalloff + * @param {Number} constant constant value for determining falloff + * @param {Number} linear linear value for determining falloff + * @param {Number} quadratic quadratic value for determining falloff + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * noStroke(); + * } + * function draw() { + * background(0); + * let locX = mouseX - width / 2; + * let locY = mouseY - height / 2; + * translate(-25, 0, 0); + * lightFalloff(1, 0, 0); + * pointLight(250, 250, 250, locX, locY, 50); + * sphere(20); + * translate(50, 0, 0); + * lightFalloff(0.9, 0.01, 0); + * pointLight(250, 250, 250, locX, locY, 50); + * sphere(20); + * } + * + *
+ * + * @alt + * Two spheres with different falloff values show different intensity of light + * + */ + p5.prototype.lightFalloff = function( + constantAttenuation, + linearAttenuation, + quadraticAttenuation + ) { + this._assert3d('lightFalloff'); + p5._validateParameters('lightFalloff', arguments); + + if (constantAttenuation < 0) { + constantAttenuation = 0; + console.warn( + 'Value of constant argument in lightFalloff() should be never be negative. Set to 0.' + ); + } + + if (linearAttenuation < 0) { + linearAttenuation = 0; + console.warn( + 'Value of linear argument in lightFalloff() should be never be negative. Set to 0.' + ); + } + + if (quadraticAttenuation < 0) { + quadraticAttenuation = 0; + console.warn( + 'Value of quadratic argument in lightFalloff() should be never be negative. Set to 0.' + ); + } + + if ( + constantAttenuation === 0 && + linearAttenuation === 0 && + quadraticAttenuation === 0 + ) { + constantAttenuation = 1; + console.warn( + 'Either one of the three arguments in lightFalloff() should be greater than zero. Set constant argument to 1.' + ); + } + + this._renderer.constantAttenuation = constantAttenuation; + this._renderer.linearAttenuation = linearAttenuation; + this._renderer.quadraticAttenuation = quadraticAttenuation; + + return this; + }; + + module.exports = p5; + }, + { '../core/main': 24 } + ], + 68: [ + function(_dereq_, module, exports) { + /** + * @module Shape + * @submodule 3D Models + * @for p5 + * @requires core + * @requires p5.Geometry + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + _dereq_('./p5.Geometry'); + + /** + * Load a 3d model from an OBJ or STL file. + *

+ * One of the limitations of the OBJ and STL format is that it doesn't have a built-in + * sense of scale. This means that models exported from different programs might + * be very different sizes. If your model isn't displaying, try calling + * loadModel() with the normalized parameter set to true. This will resize the + * model to a scale appropriate for p5. You can also make additional changes to + * the final size of your model with the scale() function. + * + * Also, the support for colored STL files is not present. STL files with color will be + * rendered without color properties. + * + * @method loadModel + * @param {String} path Path of the model to be loaded + * @param {Boolean} normalize If true, scale the model to a + * standardized size when loading + * @param {function(p5.Geometry)} [successCallback] Function to be called + * once the model is loaded. Will be passed + * the 3D model object. + * @param {function(Event)} [failureCallback] called with event error if + * the model fails to load. + * @return {p5.Geometry} the p5.Geometry object + * + * @example + *
+ * + * //draw a spinning octahedron + * let octahedron; + * + * function preload() { + * octahedron = loadModel('assets/octahedron.obj'); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * model(octahedron); + * } + * + *
+ * + * @alt + * Vertically rotating 3-d octahedron. + * + * @example + *
+ * + * //draw a spinning teapot + * let teapot; + * + * function preload() { + * // Load model with normalise parameter set to true + * teapot = loadModel('assets/teapot.obj', true); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * scale(0.4); // Scaled to make model fit into canvas + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * normalMaterial(); // For effect + * model(teapot); + * } + * + *
+ * + * @alt + * Vertically rotating 3-d teapot with red, green and blue gradient. + */ + /** + * @method loadModel + * @param {String} path + * @param {function(p5.Geometry)} [successCallback] + * @param {function(Event)} [failureCallback] + * @return {p5.Geometry} the p5.Geometry object + */ + p5.prototype.loadModel = function(path) { + p5._validateParameters('loadModel', arguments); + var normalize; + var successCallback; + var failureCallback; + if (typeof arguments[1] === 'boolean') { + normalize = arguments[1]; + successCallback = arguments[2]; + failureCallback = arguments[3]; + } else { + normalize = false; + successCallback = arguments[1]; + failureCallback = arguments[2]; + } + + var fileType = path.slice(-4); + var model = new p5.Geometry(); + model.gid = path + '|' + normalize; + var self = this; + + if (fileType === '.stl') { + this.httpDo( + path, + 'GET', + 'arrayBuffer', + function(arrayBuffer) { + parseSTL(model, arrayBuffer); + + if (normalize) { + model.normalize(); + } + self._decrementPreload(); + if (typeof successCallback === 'function') { + successCallback(model); + } + }.bind(this), + failureCallback + ); + } else if (fileType === '.obj') { + this.loadStrings( + path, + function(strings) { + parseObj(model, strings); + + if (normalize) { + model.normalize(); + } + + self._decrementPreload(); + if (typeof successCallback === 'function') { + successCallback(model); + } + }.bind(this), + failureCallback + ); + } else { + p5._friendlyFileLoadError(3, path); + + if (failureCallback) { + failureCallback(); + } else { + console.error( + 'Sorry, the file type is invalid. Only OBJ and STL files are supported.' + ); + } + } + return model; + }; + + /** + * Parse OBJ lines into model. For reference, this is what a simple model of a + * square might look like: + * + * v -0.5 -0.5 0.5 + * v -0.5 -0.5 -0.5 + * v -0.5 0.5 -0.5 + * v -0.5 0.5 0.5 + * + * f 4 3 2 1 + */ + function parseObj(model, lines) { + // OBJ allows a face to specify an index for a vertex (in the above example), + // but it also allows you to specify a custom combination of vertex, UV + // coordinate, and vertex normal. So, "3/4/3" would mean, "use vertex 3 with + // UV coordinate 4 and vertex normal 3". In WebGL, every vertex with different + // parameters must be a different vertex, so loadedVerts is used to + // temporarily store the parsed vertices, normals, etc., and indexedVerts is + // used to map a specific combination (keyed on, for example, the string + // "3/4/3"), to the actual index of the newly created vertex in the final + // object. + var loadedVerts = { + v: [], + vt: [], + vn: [] + }; + + var indexedVerts = {}; + + for (var line = 0; line < lines.length; ++line) { + // Each line is a separate object (vertex, face, vertex normal, etc) + // For each line, split it into tokens on whitespace. The first token + // describes the type. + var tokens = lines[line].trim().split(/\b\s+/); + + if (tokens.length > 0) { + if (tokens[0] === 'v' || tokens[0] === 'vn') { + // Check if this line describes a vertex or vertex normal. + // It will have three numeric parameters. + var vertex = new p5.Vector( + parseFloat(tokens[1]), + parseFloat(tokens[2]), + parseFloat(tokens[3]) + ); + + loadedVerts[tokens[0]].push(vertex); + } else if (tokens[0] === 'vt') { + // Check if this line describes a texture coordinate. + // It will have two numeric parameters. + var texVertex = [parseFloat(tokens[1]), parseFloat(tokens[2])]; + loadedVerts[tokens[0]].push(texVertex); + } else if (tokens[0] === 'f') { + // Check if this line describes a face. + // OBJ faces can have more than three points. Triangulate points. + for (var tri = 3; tri < tokens.length; ++tri) { + var face = []; + + var vertexTokens = [1, tri - 1, tri]; + + for (var tokenInd = 0; tokenInd < vertexTokens.length; ++tokenInd) { + // Now, convert the given token into an index + var vertString = tokens[vertexTokens[tokenInd]]; + var vertIndex = 0; + + // TODO: Faces can technically use negative numbers to refer to the + // previous nth vertex. I haven't seen this used in practice, but + // it might be good to implement this in the future. + + if (indexedVerts[vertString] !== undefined) { + vertIndex = indexedVerts[vertString]; + } else { + var vertParts = vertString.split('/'); + for (var i = 0; i < vertParts.length; i++) { + vertParts[i] = parseInt(vertParts[i]) - 1; + } + + vertIndex = indexedVerts[vertString] = model.vertices.length; + model.vertices.push(loadedVerts.v[vertParts[0]].copy()); + if (loadedVerts.vt[vertParts[1]]) { + model.uvs.push(loadedVerts.vt[vertParts[1]].slice()); + } else { + model.uvs.push([0, 0]); + } + + if (loadedVerts.vn[vertParts[2]]) { + model.vertexNormals.push(loadedVerts.vn[vertParts[2]].copy()); + } + } + + face.push(vertIndex); + } + + if (face[0] !== face[1] && face[0] !== face[2] && face[1] !== face[2]) { + model.faces.push(face); + } + } + } + } + } + // If the model doesn't have normals, compute the normals + if (model.vertexNormals.length === 0) { + model.computeNormals(); + } + + return model; + } + + /** + * STL files can be of two types, ASCII and Binary, + * + * We need to convert the arrayBuffer to an array of strings, + * to parse it as an ASCII file. + */ + function parseSTL(model, buffer) { + if (isBinary(buffer)) { + parseBinarySTL(model, buffer); + } else { + var reader = new DataView(buffer); + + if (!('TextDecoder' in window)) { + console.warn( + 'Sorry, ASCII STL loading only works in browsers that support TextDecoder (https://caniuse.com/#feat=textencoder)' + ); + + return model; + } + + var decoder = new TextDecoder('utf-8'); + var lines = decoder.decode(reader); + var lineArray = lines.split('\n'); + parseASCIISTL(model, lineArray); + } + return model; + } + + /** + * This function checks if the file is in ASCII format or in Binary format + * + * It is done by searching keyword `solid` at the start of the file. + * + * An ASCII STL data must begin with `solid` as the first six bytes. + * However, ASCII STLs lacking the SPACE after the `d` are known to be + * plentiful. So, check the first 5 bytes for `solid`. + * + * Several encodings, such as UTF-8, precede the text with up to 5 bytes: + * https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding + * Search for `solid` to start anywhere after those prefixes. + */ + function isBinary(data) { + var reader = new DataView(data); + + // US-ASCII ordinal values for `s`, `o`, `l`, `i`, `d` + var solid = [115, 111, 108, 105, 100]; + for (var off = 0; off < 5; off++) { + // If "solid" text is matched to the current offset, declare it to be an ASCII STL. + if (matchDataViewAt(solid, reader, off)) return false; + } + + // Couldn't find "solid" text at the beginning; it is binary STL. + return true; + } + + /** + * This function matches the `query` at the provided `offset` + */ + function matchDataViewAt(query, reader, offset) { + // Check if each byte in query matches the corresponding byte from the current offset + for (var i = 0, il = query.length; i < il; i++) { + if (query[i] !== reader.getUint8(offset + i, false)) return false; + } + + return true; + } + + /** + * This function parses the Binary STL files. + * https://en.wikipedia.org/wiki/STL_%28file_format%29#Binary_STL + * + * Currently there is no support for the colors provided in STL files. + */ + function parseBinarySTL(model, buffer) { + var reader = new DataView(buffer); + + // Number of faces is present following the header + var faces = reader.getUint32(80, true); + var r, + g, + b, + hasColors = false, + colors; + var defaultR, defaultG, defaultB; + + // Binary files contain 80-byte header, which is generally ignored. + for (var index = 0; index < 80 - 10; index++) { + // Check for `COLOR=` + if ( + reader.getUint32(index, false) === 0x434f4c4f /*COLO*/ && + reader.getUint8(index + 4) === 0x52 /*'R'*/ && + reader.getUint8(index + 5) === 0x3d /*'='*/ + ) { + hasColors = true; + colors = []; + + defaultR = reader.getUint8(index + 6) / 255; + defaultG = reader.getUint8(index + 7) / 255; + defaultB = reader.getUint8(index + 8) / 255; + // To be used when color support is added + // alpha = reader.getUint8(index + 9) / 255; + } + } + var dataOffset = 84; + var faceLength = 12 * 4 + 2; + + // Iterate the faces + for (var face = 0; face < faces; face++) { + var start = dataOffset + face * faceLength; + var normalX = reader.getFloat32(start, true); + var normalY = reader.getFloat32(start + 4, true); + var normalZ = reader.getFloat32(start + 8, true); + + if (hasColors) { + var packedColor = reader.getUint16(start + 48, true); + + if ((packedColor & 0x8000) === 0) { + // facet has its own unique color + r = (packedColor & 0x1f) / 31; + g = ((packedColor >> 5) & 0x1f) / 31; + b = ((packedColor >> 10) & 0x1f) / 31; + } else { + r = defaultR; + g = defaultG; + b = defaultB; + } + } + + for (var i = 1; i <= 3; i++) { + var vertexstart = start + i * 12; + + var newVertex = new p5.Vector( + reader.getFloat32(vertexstart, true), + reader.getFloat32(vertexstart + 8, true), + reader.getFloat32(vertexstart + 4, true) + ); + + model.vertices.push(newVertex); + + if (hasColors) { + colors.push(r, g, b); + } + } + + var newNormal = new p5.Vector(normalX, normalY, normalZ); + + model.vertexNormals.push(newNormal, newNormal, newNormal); + + model.faces.push([3 * face, 3 * face + 1, 3 * face + 2]); + } + if (hasColors) { + // add support for colors here. + } + return model; + } + + /** + * ASCII STL file starts with `solid 'nameOfFile'` + * Then contain the normal of the face, starting with `facet normal` + * Next contain a keyword indicating the start of face vertex, `outer loop` + * Next comes the three vertex, starting with `vertex x y z` + * Vertices ends with `endloop` + * Face ends with `endfacet` + * Next face starts with `facet normal` + * The end of the file is indicated by `endsolid` + */ + function parseASCIISTL(model, lines) { + var state = ''; + var curVertexIndex = []; + var newNormal, newVertex; + + for (var iterator = 0; iterator < lines.length; ++iterator) { + var line = lines[iterator].trim(); + var parts = line.split(' '); + + for (var partsiterator = 0; partsiterator < parts.length; ++partsiterator) { + if (parts[partsiterator] === '') { + // Ignoring multiple whitespaces + parts.splice(partsiterator, 1); + } + } + + if (parts.length === 0) { + // Remove newline + continue; + } + + switch (state) { + case '': // First run + if (parts[0] !== 'solid') { + // Invalid state + console.error(line); + console.error('Invalid state "' + parts[0] + '", should be "solid"'); + return; + } else { + state = 'solid'; + } + break; + + case 'solid': // First face + if (parts[0] !== 'facet' || parts[1] !== 'normal') { + // Invalid state + console.error(line); + console.error( + 'Invalid state "' + parts[0] + '", should be "facet normal"' + ); + + return; + } else { + // Push normal for first face + newNormal = new p5.Vector( + parseFloat(parts[2]), + parseFloat(parts[3]), + parseFloat(parts[4]) + ); + + model.vertexNormals.push(newNormal, newNormal, newNormal); + state = 'facet normal'; + } + break; + + case 'facet normal': // After normal is defined + if (parts[0] !== 'outer' || parts[1] !== 'loop') { + // Invalid State + console.error(line); + console.error( + 'Invalid state "' + parts[0] + '", should be "outer loop"' + ); + + return; + } else { + // Next should be vertices + state = 'vertex'; + } + break; + + case 'vertex': + if (parts[0] === 'vertex') { + //Vertex of triangle + newVertex = new p5.Vector( + parseFloat(parts[1]), + parseFloat(parts[2]), + parseFloat(parts[3]) + ); + + model.vertices.push(newVertex); + curVertexIndex.push(model.vertices.indexOf(newVertex)); + } else if (parts[0] === 'endloop') { + // End of vertices + model.faces.push(curVertexIndex); + curVertexIndex = []; + state = 'endloop'; + } else { + // Invalid State + console.error(line); + console.error( + 'Invalid state "' + parts[0] + '", should be "vertex" or "endloop"' + ); + + return; + } + break; + + case 'endloop': + if (parts[0] !== 'endfacet') { + // End of face + console.error(line); + console.error('Invalid state "' + parts[0] + '", should be "endfacet"'); + + return; + } else { + state = 'endfacet'; + } + break; + + case 'endfacet': + if (parts[0] === 'endsolid') { + // End of solid + } else if (parts[0] === 'facet' && parts[1] === 'normal') { + // Next face + newNormal = new p5.Vector( + parseFloat(parts[2]), + parseFloat(parts[3]), + parseFloat(parts[4]) + ); + + model.vertexNormals.push(newNormal, newNormal, newNormal); + state = 'facet normal'; + } else { + // Invalid State + console.error(line); + console.error( + 'Invalid state "' + + parts[0] + + '", should be "endsolid" or "facet normal"' + ); + + return; + } + break; + + default: + console.error('Invalid state "' + state + '"'); + break; + } + } + return model; + } + + /** + * Render a 3d model to the screen. + * + * @method model + * @param {p5.Geometry} model Loaded 3d model to be rendered + * @example + *
+ * + * //draw a spinning octahedron + * let octahedron; + * + * function preload() { + * octahedron = loadModel('assets/octahedron.obj'); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * model(octahedron); + * } + * + *
+ * + * @alt + * Vertically rotating 3-d octahedron. + * + */ + p5.prototype.model = function(model) { + this._assert3d('model'); + p5._validateParameters('model', arguments); + if (model.vertices.length > 0) { + if (!this._renderer.geometryInHash(model.gid)) { + model._makeTriangleEdges()._edgesToVertices(); + this._renderer.createBuffers(model.gid, model); + } + + this._renderer.drawBuffers(model.gid); + } + }; + + module.exports = p5; + }, + { '../core/main': 24, './p5.Geometry': 71 } + ], + 69: [ + function(_dereq_, module, exports) { + /** + * @module Lights, Camera + * @submodule Material + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + _dereq_('./p5.Texture'); + + /** + * Loads a custom shader from the provided vertex and fragment + * shader paths. The shader files are loaded asynchronously in the + * background, so this method should be used in preload(). + * + * For now, there are three main types of shaders. p5 will automatically + * supply appropriate vertices, normals, colors, and lighting attributes + * if the parameters defined in the shader match the names. + * + * @method loadShader + * @param {String} vertFilename path to file containing vertex shader + * source code + * @param {String} fragFilename path to file containing fragment shader + * source code + * @param {function} [callback] callback to be executed after loadShader + * completes. On success, the Shader object is passed as the first argument. + * @param {function} [errorCallback] callback to be executed when an error + * occurs inside loadShader. On error, the error is passed as the first + * argument. + * @return {p5.Shader} a shader object created from the provided + * vertex and fragment shader files. + * + * @example + *
+ * + * let mandel; + * function preload() { + * // load the shader definitions from files + * mandel = loadShader('assets/shader.vert', 'assets/shader.frag'); + * } + * function setup() { + * createCanvas(100, 100, WEBGL); + * // use the shader + * shader(mandel); + * noStroke(); + * mandel.setUniform('p', [-0.74364388703, 0.13182590421]); + * } + * + * function draw() { + * mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000)))); + * quad(-1, -1, 1, -1, 1, 1, -1, 1); + * } + * + *
+ * + * @alt + * zooming Mandelbrot set. a colorful, infinitely detailed fractal. + */ + p5.prototype.loadShader = function( + vertFilename, + fragFilename, + callback, + errorCallback + ) { + p5._validateParameters('loadShader', arguments); + if (!errorCallback) { + errorCallback = console.error; + } + + var loadedShader = new p5.Shader(); + + var self = this; + var loadedFrag = false; + var loadedVert = false; + + var onLoad = function onLoad() { + self._decrementPreload(); + if (callback) { + callback(loadedShader); + } + }; + + this.loadStrings( + vertFilename, + function(result) { + loadedShader._vertSrc = result.join('\n'); + loadedVert = true; + if (loadedFrag) { + onLoad(); + } + }, + errorCallback + ); + + this.loadStrings( + fragFilename, + function(result) { + loadedShader._fragSrc = result.join('\n'); + loadedFrag = true; + if (loadedVert) { + onLoad(); + } + }, + errorCallback + ); + + return loadedShader; + }; + + /** + * @method createShader + * @param {String} vertSrc source code for the vertex shader + * @param {String} fragSrc source code for the fragment shader + * @returns {p5.Shader} a shader object created from the provided + * vertex and fragment shaders. + * + * @example + *
+ * + * // the 'varying's are shared between both vertex & fragment shaders + * let varying = 'precision highp float; varying vec2 vPos;'; + * + * // the vertex shader is called for each vertex + * let vs = + * varying + + * 'attribute vec3 aPosition;' + + * 'void main() { vPos = (gl_Position = vec4(aPosition,1.0)).xy; }'; + * + * // the fragment shader is called for each pixel + * let fs = + * varying + + * 'uniform vec2 p;' + + * 'uniform float r;' + + * 'const int I = 500;' + + * 'void main() {' + + * ' vec2 c = p + vPos * r, z = c;' + + * ' float n = 0.0;' + + * ' for (int i = I; i > 0; i --) {' + + * ' if(z.x*z.x+z.y*z.y > 4.0) {' + + * ' n = float(i)/float(I);' + + * ' break;' + + * ' }' + + * ' z = vec2(z.x*z.x-z.y*z.y, 2.0*z.x*z.y) + c;' + + * ' }' + + * ' gl_FragColor = vec4(0.5-cos(n*17.0)/2.0,0.5-cos(n*13.0)/2.0,0.5-cos(n*23.0)/2.0,1.0);' + + * '}'; + * + * let mandel; + * function setup() { + * createCanvas(100, 100, WEBGL); + * + * // create and initialize the shader + * mandel = createShader(vs, fs); + * shader(mandel); + * noStroke(); + * + * // 'p' is the center point of the Mandelbrot image + * mandel.setUniform('p', [-0.74364388703, 0.13182590421]); + * } + * + * function draw() { + * // 'r' is the size of the image in Mandelbrot-space + * mandel.setUniform('r', 1.5 * exp(-6.5 * (1 + sin(millis() / 2000)))); + * quad(-1, -1, 1, -1, 1, 1, -1, 1); + * } + * + *
+ * + * @alt + * zooming Mandelbrot set. a colorful, infinitely detailed fractal. + */ + p5.prototype.createShader = function(vertSrc, fragSrc) { + this._assert3d('createShader'); + p5._validateParameters('createShader', arguments); + return new p5.Shader(this._renderer, vertSrc, fragSrc); + }; + + /** + * The shader() function lets the user provide a custom shader + * to fill in shapes in WEBGL mode. Users can create their + * own shaders by loading vertex and fragment shaders with + * loadShader(). + * + * @method shader + * @chainable + * @param {p5.Shader} [s] the desired p5.Shader to use for rendering + * shapes. + * + * @example + *
+ * + * // Click within the image to toggle + * // the shader used by the quad shape + * // Note: for an alternative approach to the same example, + * // involving changing uniforms please refer to: + * // https://p5js.org/reference/#/p5.Shader/setUniform + * + * let redGreen; + * let orangeBlue; + * let showRedGreen = false; + * + * function preload() { + * // note that we are using two instances + * // of the same vertex and fragment shaders + * redGreen = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); + * orangeBlue = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * + * // initialize the colors for redGreen shader + * shader(redGreen); + * redGreen.setUniform('colorCenter', [1.0, 0.0, 0.0]); + * redGreen.setUniform('colorBackground', [0.0, 1.0, 0.0]); + * + * // initialize the colors for orangeBlue shader + * shader(orangeBlue); + * orangeBlue.setUniform('colorCenter', [1.0, 0.5, 0.0]); + * orangeBlue.setUniform('colorBackground', [0.226, 0.0, 0.615]); + * + * noStroke(); + * } + * + * function draw() { + * // update the offset values for each shader, + * // moving orangeBlue in vertical and redGreen + * // in horizontal direction + * orangeBlue.setUniform('offset', [0, sin(millis() / 2000) + 1]); + * redGreen.setUniform('offset', [sin(millis() / 2000), 1]); + * + * if (showRedGreen === true) { + * shader(redGreen); + * } else { + * shader(orangeBlue); + * } + * quad(-1, -1, 1, -1, 1, 1, -1, 1); + * } + * + * function mouseClicked() { + * showRedGreen = !showRedGreen; + * } + * + *
+ * + * @alt + * canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed. + */ + p5.prototype.shader = function(s) { + this._assert3d('shader'); + p5._validateParameters('shader', arguments); + + if (s._renderer === undefined) { + s._renderer = this._renderer; + } + + if (s.isStrokeShader()) { + this._renderer.userStrokeShader = s; + } else { + this._renderer.userFillShader = s; + this._renderer._useNormalMaterial = false; + } + + s.init(); + + return this; + }; + + /** + * This function restores the default shaders in WEBGL mode. Code that runs + * after resetShader() will not be affected by previously defined + * shaders. Should be run after shader(). + * + * @method resetShader + * @chainable + */ + p5.prototype.resetShader = function() { + this._renderer.userFillShader = this._renderer.userStrokeShader = null; + return this; + }; + + /** + * Normal material for geometry. You can view all + * possible materials in this + * example. + * @method normalMaterial + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(200); + * normalMaterial(); + * sphere(40); + * } + * + *
+ * + * @alt + * Red, green and blue gradient. + * + */ + p5.prototype.normalMaterial = function() { + this._assert3d('normalMaterial'); + p5._validateParameters('normalMaterial', arguments); + this._renderer.drawMode = constants.FILL; + this._renderer._useSpecularMaterial = false; + this._renderer._useNormalMaterial = true; + this._renderer.curFillColor = [1, 1, 1, 1]; + this._renderer._setProperty('_doFill', true); + this.noStroke(); + return this; + }; + + /** + * Texture for geometry. You can view other possible materials in this + * example. + * @method texture + * @param {p5.Image|p5.MediaElement|p5.Graphics} tex 2-dimensional graphics + * to render as texture + * @chainable + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(0); + * rotateZ(frameCount * 0.01); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * //pass image as texture + * texture(img); + * box(200, 200, 200); + * } + * + *
+ * + *
+ * + * let pg; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * pg = createGraphics(200, 200); + * pg.textSize(75); + * } + * + * function draw() { + * background(0); + * pg.background(255); + * pg.text('hello!', 0, 100); + * //pass image as texture + * texture(pg); + * rotateX(0.5); + * noStroke(); + * plane(50); + * } + * + *
+ * + *
+ * + * let vid; + * function preload() { + * vid = createVideo('assets/fingers.mov'); + * vid.hide(); + * } + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(0); + * //pass video frame as texture + * texture(vid); + * rect(-40, -40, 80, 80); + * } + * + * function mousePressed() { + * vid.loop(); + * } + * + *
+ * + * @alt + * Rotating view of many images umbrella and grid roof on a 3d plane + * black canvas + * black canvas + * + */ + p5.prototype.texture = function(tex) { + this._assert3d('texture'); + p5._validateParameters('texture', arguments); + + this._renderer.drawMode = constants.TEXTURE; + this._renderer._useSpecularMaterial = false; + this._renderer._useNormalMaterial = false; + this._renderer._tex = tex; + this._renderer._setProperty('_doFill', true); + + return this; + }; + + /** + * Sets the coordinate space for texture mapping. The default mode is IMAGE + * which refers to the actual coordinates of the image. + * NORMAL refers to a normalized space of values ranging from 0 to 1. + * This function only works in WEBGL mode. + * + * With IMAGE, if an image is 100 x 200 pixels, mapping the image onto the entire + * size of a quad would require the points (0,0) (100, 0) (100,200) (0,200). + * The same mapping in NORMAL is (0,0) (1,0) (1,1) (0,1). + * @method textureMode + * @param {Constant} mode either IMAGE or NORMAL + * @example + *
+ * + * let img; + * + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * texture(img); + * textureMode(NORMAL); + * beginShape(); + * vertex(-50, -50, 0, 0); + * vertex(50, -50, 1, 0); + * vertex(50, 50, 1, 1); + * vertex(-50, 50, 0, 1); + * endShape(); + * } + * + *
+ * + * @alt + * the underside of a white umbrella and gridded ceiling above + * + *
+ * + * let img; + * + * function preload() { + * img = loadImage('assets/laDefense.jpg'); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * texture(img); + * textureMode(NORMAL); + * beginShape(); + * vertex(-50, -50, 0, 0); + * vertex(50, -50, img.width, 0); + * vertex(50, 50, img.width, img.height); + * vertex(-50, 50, 0, img.height); + * endShape(); + * } + * + *
+ * + * @alt + * the underside of a white umbrella and gridded ceiling above + * + */ + p5.prototype.textureMode = function(mode) { + if (mode !== constants.IMAGE && mode !== constants.NORMAL) { + console.warn( + 'You tried to set ' + mode + ' textureMode only supports IMAGE & NORMAL ' + ); + } else { + this._renderer.textureMode = mode; + } + }; + + /** + * Sets the global texture wrapping mode. This controls how textures behave + * when their uv's go outside of the 0 - 1 range. There are three options: + * CLAMP, REPEAT, and MIRROR. + * + * CLAMP causes the pixels at the edge of the texture to extend to the bounds + * REPEAT causes the texture to tile repeatedly until reaching the bounds + * MIRROR works similarly to REPEAT but it flips the texture with every new tile + * + * REPEAT & MIRROR are only available if the texture + * is a power of two size (128, 256, 512, 1024, etc.). + * + * This method will affect all textures in your sketch until a subsequent + * textureWrap call is made. + * + * If only one argument is provided, it will be applied to both the + * horizontal and vertical axes. + * @method textureWrap + * @param {Constant} wrapX either CLAMP, REPEAT, or MIRROR + * @param {Constant} [wrapY] either CLAMP, REPEAT, or MIRROR + * @example + *
+ * + * let img; + * function preload() { + * img = loadImage('assets/rockies128.jpg'); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * textureWrap(MIRROR); + * } + * + * function draw() { + * background(0); + * + * let dX = mouseX; + * let dY = mouseY; + * + * let u = lerp(1.0, 2.0, dX); + * let v = lerp(1.0, 2.0, dY); + * + * scale(width / 2); + * + * texture(img); + * + * beginShape(TRIANGLES); + * vertex(-1, -1, 0, 0, 0); + * vertex(1, -1, 0, u, 0); + * vertex(1, 1, 0, u, v); + * + * vertex(1, 1, 0, u, v); + * vertex(-1, 1, 0, 0, v); + * vertex(-1, -1, 0, 0, 0); + * endShape(); + * } + * + *
+ * + * @alt + * an image of the rocky mountains repeated in mirrored tiles + * + */ + p5.prototype.textureWrap = function(wrapX, wrapY) { + wrapY = wrapY || wrapX; + + this._renderer.textureWrapX = wrapX; + this._renderer.textureWrapY = wrapY; + + var textures = this._renderer.textures; + for (var i = 0; i < textures.length; i++) { + textures[i].setWrapMode(wrapX, wrapY); + } + }; + + /** + * Ambient material for geometry with a given color. You can view all + * possible materials in this + * example. + * @method ambientMaterial + * @param {Number} v1 gray value, red or hue value + * (depending on the current color mode), + * @param {Number} [v2] green or saturation value + * @param {Number} [v3] blue or brightness value + * @param {Number} [a] opacity + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(0); + * noStroke(); + * ambientLight(200); + * ambientMaterial(70, 130, 230); + * sphere(40); + * } + * + *
+ * + * @alt + * radiating light source from top right of canvas + * + */ + /** + * @method ambientMaterial + * @param {Number[]|String|p5.Color} color color, color Array, or CSS color string + * @chainable + */ + p5.prototype.ambientMaterial = function(v1, v2, v3, a) { + this._assert3d('ambientMaterial'); + p5._validateParameters('ambientMaterial', arguments); + + var color = p5.prototype.color.apply(this, arguments); + this._renderer.curFillColor = color._array; + this._renderer._useSpecularMaterial = false; + this._renderer._useNormalMaterial = false; + this._renderer._enableLighting = true; + this._renderer._tex = null; + + return this; + }; + + /** + * Specular material for geometry with a given color. You can view all + * possible materials in this + * example. + * @method specularMaterial + * @param {Number} v1 gray value, red or hue value + * (depending on the current color mode), + * @param {Number} [v2] green or saturation value + * @param {Number} [v3] blue or brightness value + * @param {Number} [a] opacity + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(0); + * noStroke(); + * ambientLight(50); + * pointLight(250, 250, 250, 100, 100, 30); + * specularMaterial(250); + * sphere(40); + * } + * + *
+ * + * @alt + * diffused radiating light source from top right of canvas + * + */ + /** + * @method specularMaterial + * @param {Number[]|String|p5.Color} color color Array, or CSS color string + * @chainable + */ + p5.prototype.specularMaterial = function(v1, v2, v3, a) { + this._assert3d('specularMaterial'); + p5._validateParameters('specularMaterial', arguments); + + var color = p5.prototype.color.apply(this, arguments); + this._renderer.curFillColor = color._array; + this._renderer._useSpecularMaterial = true; + this._renderer._useNormalMaterial = false; + this._renderer._enableLighting = true; + this._renderer._tex = null; + + return this; + }; + + /** + * Sets the amount of gloss in the surface of shapes. + * Used in combination with specularMaterial() in setting + * the material properties of shapes. The default and minimum value is 1. + * @method shininess + * @param {Number} shine Degree of Shininess. + * Defaults to 1. + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(0); + * noStroke(); + * let locX = mouseX - width / 2; + * let locY = mouseY - height / 2; + * ambientLight(60, 60, 60); + * pointLight(255, 255, 255, locX, locY, 50); + * specularMaterial(250); + * translate(-25, 0, 0); + * shininess(1); + * sphere(20); + * translate(50, 0, 0); + * shininess(20); + * sphere(20); + * } + * + *
+ * @alt + * Shininess on Camera changes position with mouse + */ + p5.prototype.shininess = function(shine) { + this._assert3d('shininess'); + p5._validateParameters('shininess', arguments); + + if (shine < 1) { + shine = 1; + } + this._renderer._useShininess = shine; + return this; + }; + + /** + * @private blends colors according to color components. + * If alpha value is less than 1, we need to enable blending + * on our gl context. Otherwise opaque objects need to a depthMask. + * @param {Number[]} color [description] + * @return {Number[]]} Normalized numbers array + */ + p5.RendererGL.prototype._applyColorBlend = function(colors) { + var gl = this.GL; + + var isTexture = this.drawMode === constants.TEXTURE; + if (isTexture || colors[colors.length - 1] < 1.0) { + gl.depthMask(isTexture); + gl.enable(gl.BLEND); + this._applyBlendMode(); + } else { + gl.depthMask(true); + gl.disable(gl.BLEND); + } + return colors; + }; + + /** + * @private sets blending in gl context to curBlendMode + * @param {Number[]} color [description] + * @return {Number[]]} Normalized numbers array + */ + p5.RendererGL.prototype._applyBlendMode = function() { + var gl = this.GL; + switch (this.curBlendMode) { + case constants.BLEND: + case constants.ADD: + gl.blendEquation(gl.FUNC_ADD); + gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + break; + case constants.MULTIPLY: + gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD); + gl.blendFuncSeparate(gl.ZERO, gl.SRC_COLOR, gl.ONE, gl.ONE); + break; + case constants.SCREEN: + gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD); + gl.blendFuncSeparate(gl.ONE_MINUS_DST_COLOR, gl.ONE, gl.ONE, gl.ONE); + break; + case constants.EXCLUSION: + gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD); + gl.blendFuncSeparate( + gl.ONE_MINUS_DST_COLOR, + gl.ONE_MINUS_SRC_COLOR, + gl.ONE, + gl.ONE + ); + + break; + case constants.REPLACE: + gl.blendEquation(gl.FUNC_ADD); + gl.blendFunc(gl.ONE, gl.ZERO); + break; + case constants.SUBTRACT: + gl.blendEquationSeparate(gl.FUNC_REVERSE_SUBTRACT, gl.FUNC_ADD); + gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE, gl.ONE, gl.ONE); + break; + case constants.DARKEST: + if (this.blendExt) { + gl.blendEquationSeparate(this.blendExt.MIN_EXT, gl.FUNC_ADD); + gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE); + } else { + console.warn( + 'blendMode(DARKEST) does not work in your browser in WEBGL mode.' + ); + } + break; + case constants.LIGHTEST: + if (this.blendExt) { + gl.blendEquationSeparate(this.blendExt.MAX_EXT, gl.FUNC_ADD); + gl.blendFuncSeparate(gl.ONE, gl.ONE, gl.ONE, gl.ONE); + } else { + console.warn( + 'blendMode(LIGHTEST) does not work in your browser in WEBGL mode.' + ); + } + break; + default: + console.error( + 'Oops! Somehow RendererGL set curBlendMode to an unsupported mode.' + ); + + break; + } + }; + + module.exports = p5; + }, + { '../core/constants': 18, '../core/main': 24, './p5.Texture': 77 } + ], + 70: [ + function(_dereq_, module, exports) { + /** + * @module Lights, Camera + * @submodule Camera + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + //////////////////////////////////////////////////////////////////////////////// + // p5.Prototype Methods + //////////////////////////////////////////////////////////////////////////////// + + /** + * Sets the camera position for a 3D sketch. Parameters for this function define + * the position for the camera, the center of the sketch (where the camera is + * pointing), and an up direction (the orientation of the camera). + * + * When called with no arguments, this function creates a default camera + * equivalent to + * camera(0, 0, (height/2.0) / tan(PI*30.0 / 180.0), 0, 0, 0, 0, 1, 0); + * @method camera + * @for p5 + * @param {Number} [x] camera position value on x axis + * @param {Number} [y] camera position value on y axis + * @param {Number} [z] camera position value on z axis + * @param {Number} [centerX] x coordinate representing center of the sketch + * @param {Number} [centerY] y coordinate representing center of the sketch + * @param {Number} [centerZ] z coordinate representing center of the sketch + * @param {Number} [upX] x component of direction 'up' from camera + * @param {Number} [upY] y component of direction 'up' from camera + * @param {Number} [upZ] z component of direction 'up' from camera + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * function draw() { + * background(204); + * //move the camera away from the plane by a sin wave + * camera(0, 0, 20 + sin(frameCount * 0.01) * 10, 0, 0, 0, 0, 1, 0); + * plane(10, 10); + * } + * + *
+ * + * @alt + * White square repeatedly grows to fill canvas and then shrinks. + * + */ + p5.prototype.camera = function() { + this._assert3d('camera'); + p5._validateParameters('camera', arguments); + this._renderer._curCamera.camera.apply(this._renderer._curCamera, arguments); + return this; + }; + + /** + * Sets a perspective projection for the camera in a 3D sketch. This projection + * represents depth through foreshortening: objects that are close to the camera + * appear their actual size while those that are further away from the camera + * appear smaller. The parameters to this function define the viewing frustum + * (the truncated pyramid within which objects are seen by the camera) through + * vertical field of view, aspect ratio (usually width/height), and near and far + * clipping planes. + * + * When called with no arguments, the defaults + * provided are equivalent to + * perspective(PI/3.0, width/height, eyeZ/10.0, eyeZ*10.0), where eyeZ + * is equal to ((height/2.0) / tan(PI*60.0/360.0)); + * @method perspective + * @for p5 + * @param {Number} [fovy] camera frustum vertical field of view, + * from bottom to top of view, in angleMode units + * @param {Number} [aspect] camera frustum aspect ratio + * @param {Number} [near] frustum near plane length + * @param {Number} [far] frustum far plane length + * @chainable + * @example + *
+ * + * //drag the mouse to look around! + * //you will see there's a vanishing point + * function setup() { + * createCanvas(100, 100, WEBGL); + * perspective(PI / 3.0, width / height, 0.1, 500); + * } + * function draw() { + * background(200); + * orbitControl(); + * normalMaterial(); + * + * rotateX(-0.3); + * rotateY(-0.2); + * translate(0, 0, -50); + * + * push(); + * translate(-15, 0, sin(frameCount / 30) * 95); + * box(30); + * pop(); + * push(); + * translate(15, 0, sin(frameCount / 30 + PI) * 95); + * box(30); + * pop(); + * } + * + *
+ * + * @alt + * two colored 3D boxes move back and forth, rotating as mouse is dragged. + * + */ + p5.prototype.perspective = function() { + this._assert3d('perspective'); + p5._validateParameters('perspective', arguments); + this._renderer._curCamera.perspective.apply( + this._renderer._curCamera, + arguments + ); + + return this; + }; + + /** + * Sets an orthographic projection for the camera in a 3D sketch and defines a + * box-shaped viewing frustum within which objects are seen. In this projection, + * all objects with the same dimension appear the same size, regardless of + * whether they are near or far from the camera. The parameters to this + * function specify the viewing frustum where left and right are the minimum and + * maximum x values, top and bottom are the minimum and maximum y values, and near + * and far are the minimum and maximum z values. If no parameters are given, the + * default is used: ortho(-width/2, width/2, -height/2, height/2). + * @method ortho + * @for p5 + * @param {Number} [left] camera frustum left plane + * @param {Number} [right] camera frustum right plane + * @param {Number} [bottom] camera frustum bottom plane + * @param {Number} [top] camera frustum top plane + * @param {Number} [near] camera frustum near plane + * @param {Number} [far] camera frustum far plane + * @chainable + * @example + *
+ * + * //drag the mouse to look around! + * //there's no vanishing point + * function setup() { + * createCanvas(100, 100, WEBGL); + * ortho(-width / 2, width / 2, height / 2, -height / 2, 0, 500); + * } + * function draw() { + * background(200); + * orbitControl(); + * normalMaterial(); + * + * rotateX(0.2); + * rotateY(-0.2); + * push(); + * translate(-15, 0, sin(frameCount / 30) * 65); + * box(30); + * pop(); + * push(); + * translate(15, 0, sin(frameCount / 30 + PI) * 65); + * box(30); + * pop(); + * } + * + *
+ * + * @alt + * two 3D boxes move back and forth along same plane, rotating as mouse is dragged. + * + */ + p5.prototype.ortho = function() { + this._assert3d('ortho'); + p5._validateParameters('ortho', arguments); + this._renderer._curCamera.ortho.apply(this._renderer._curCamera, arguments); + return this; + }; + + //////////////////////////////////////////////////////////////////////////////// + // p5.Camera + //////////////////////////////////////////////////////////////////////////////// + + /** + * Creates a new p5.Camera object and tells the + * renderer to use that camera. + * Returns the p5.Camera object. + * @method createCamera + * @return {p5.Camera} The newly created camera object. + * @for p5 + */ + p5.prototype.createCamera = function() { + this._assert3d('createCamera'); + var _cam = new p5.Camera(this._renderer); + + // compute default camera settings, then set a default camera + _cam._computeCameraDefaultSettings(); + _cam._setDefaultCamera(); + + // set renderer current camera to the new camera + this._renderer._curCamera = _cam; + + return _cam; + }; + + /** + * This class describes a camera for use in p5's + * + * WebGL mode. It contains camera position, orientation, and projection + * information necessary for rendering a 3D scene. + * + * New p5.Camera objects can be made through the + * createCamera() function and controlled through + * the methods described below. A camera created in this way will use a default + * position in the scene and a default perspective projection until these + * properties are changed through the various methods available. It is possible + * to create multiple cameras, in which case the current camera + * can be set through the setCamera() method. + * + * + * Note: + * The methods below operate in two coordinate systems: the 'world' coordinate + * system describe positions in terms of their relationship to the origin along + * the X, Y and Z axes whereas the camera's 'local' coordinate system + * describes positions from the camera's point of view: left-right, up-down, + * and forward-backward. The move() method, + * for instance, moves the camera along its own axes, whereas the + * setPosition() + * method sets the camera's position in world-space. + * + * + * @class p5.Camera + * @param {rendererGL} rendererGL instance of WebGL renderer + * @example + *
+ * + * let cam; + * let delta = 0.01; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * normalMaterial(); + * cam = createCamera(); + * // set initial pan angle + * cam.pan(-0.8); + * } + * + * function draw() { + * background(200); + * + * // pan camera according to angle 'delta' + * cam.pan(delta); + * + * // every 160 frames, switch direction + * if (frameCount % 160 === 0) { + * delta *= -1; + * } + * + * rotateX(frameCount * 0.01); + * translate(-100, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * } + * + *
+ * + * @alt + * camera view pans left and right across a series of rotating 3D boxes. + * + */ + p5.Camera = function(renderer) { + this._renderer = renderer; + + this.cameraType = 'default'; + + this.cameraMatrix = new p5.Matrix(); + this.projMatrix = new p5.Matrix(); + }; + + //////////////////////////////////////////////////////////////////////////////// + // Camera Projection Methods + //////////////////////////////////////////////////////////////////////////////// + + /** + * Sets a perspective projection for a p5.Camera object and sets parameters + * for that projection according to perspective() + * syntax. + * @method perspective + * @for p5.Camera + */ + p5.Camera.prototype.perspective = function(fovy, aspect, near, far) { + if (typeof fovy === 'undefined') { + fovy = this.defaultCameraFOV; + // this avoids issue where setting angleMode(DEGREES) before calling + // perspective leads to a smaller than expected FOV (because + // _computeCameraDefaultSettings computes in radians) + this.cameraFOV = fovy; + } else { + this.cameraFOV = this._renderer._pInst._toRadians(fovy); + } + if (typeof aspect === 'undefined') { + aspect = this.defaultAspectRatio; + } + if (typeof near === 'undefined') { + near = this.defaultCameraNear; + } + if (typeof far === 'undefined') { + far = this.defaultCameraFar; + } + + if (near <= 0.0001) { + near = 0.01; + console.log( + 'Avoid perspective near plane values close to or below 0. ' + + 'Setting value to 0.01.' + ); + } + + if (far < near) { + console.log( + 'Perspective far plane value is less than near plane value. ' + + 'Nothing will be shown.' + ); + } + + this.aspectRatio = aspect; + this.cameraNear = near; + this.cameraFar = far; + + this.projMatrix = p5.Matrix.identity(); + + var f = 1.0 / Math.tan(this.cameraFOV / 2); + var nf = 1.0 / (this.cameraNear - this.cameraFar); + + // prettier-ignore + this.projMatrix.set(f / aspect, 0, 0, 0, + 0, -f, 0, 0, + 0, 0, (far + near) * nf, -1, + 0, 0, 2 * far * near * nf, 0); + + if (this._isActive()) { + this._renderer.uPMatrix.set( + this.projMatrix.mat4[0], + this.projMatrix.mat4[1], + this.projMatrix.mat4[2], + this.projMatrix.mat4[3], + this.projMatrix.mat4[4], + this.projMatrix.mat4[5], + this.projMatrix.mat4[6], + this.projMatrix.mat4[7], + this.projMatrix.mat4[8], + this.projMatrix.mat4[9], + this.projMatrix.mat4[10], + this.projMatrix.mat4[11], + this.projMatrix.mat4[12], + this.projMatrix.mat4[13], + this.projMatrix.mat4[14], + this.projMatrix.mat4[15] + ); + } + + this.cameraType = 'custom'; + }; + + /** + * Sets an orthographic projection for a p5.Camera object and sets parameters + * for that projection according to ortho() syntax. + * @method ortho + * @for p5.Camera + */ + p5.Camera.prototype.ortho = function(left, right, bottom, top, near, far) { + if (left === undefined) left = -this._renderer.width / 2; + if (right === undefined) right = +this._renderer.width / 2; + if (bottom === undefined) bottom = -this._renderer.height / 2; + if (top === undefined) top = +this._renderer.height / 2; + if (near === undefined) near = 0; + if (far === undefined) + far = Math.max(this._renderer.width, this._renderer.height); + + var w = right - left; + var h = top - bottom; + var d = far - near; + + var x = +2.0 / w; + var y = +2.0 / h; + var z = -2.0 / d; + + var tx = -(right + left) / w; + var ty = -(top + bottom) / h; + var tz = -(far + near) / d; + + this.projMatrix = p5.Matrix.identity(); + + // prettier-ignore + this.projMatrix.set(x, 0, 0, 0, + 0, -y, 0, 0, + 0, 0, z, 0, + tx, ty, tz, 1); + + if (this._isActive()) { + this._renderer.uPMatrix.set( + this.projMatrix.mat4[0], + this.projMatrix.mat4[1], + this.projMatrix.mat4[2], + this.projMatrix.mat4[3], + this.projMatrix.mat4[4], + this.projMatrix.mat4[5], + this.projMatrix.mat4[6], + this.projMatrix.mat4[7], + this.projMatrix.mat4[8], + this.projMatrix.mat4[9], + this.projMatrix.mat4[10], + this.projMatrix.mat4[11], + this.projMatrix.mat4[12], + this.projMatrix.mat4[13], + this.projMatrix.mat4[14], + this.projMatrix.mat4[15] + ); + } + + this.cameraType = 'custom'; + }; + + //////////////////////////////////////////////////////////////////////////////// + // Camera Orientation Methods + //////////////////////////////////////////////////////////////////////////////// + + /** + * Rotate camera view about arbitrary axis defined by x,y,z + * based on http://learnwebgl.brown37.net/07_cameras/camera_rotating_motion.html + * @method _rotateView + * @private + */ + p5.Camera.prototype._rotateView = function(a, x, y, z) { + var centerX = this.centerX; + var centerY = this.centerY; + var centerZ = this.centerZ; + + // move center by eye position such that rotation happens around eye position + centerX -= this.eyeX; + centerY -= this.eyeY; + centerZ -= this.eyeZ; + + var rotation = p5.Matrix.identity(this._renderer._pInst); + rotation.rotate(this._renderer._pInst._toRadians(a), x, y, z); + + // prettier-ignore + var rotatedCenter = [ + centerX * rotation.mat4[0] + centerY * rotation.mat4[4] + centerZ * rotation.mat4[8], + centerX * rotation.mat4[1] + centerY * rotation.mat4[5] + centerZ * rotation.mat4[9], + centerX * rotation.mat4[2] + centerY * rotation.mat4[6] + centerZ * rotation.mat4[10]]; + + // add eye position back into center + rotatedCenter[0] += this.eyeX; + rotatedCenter[1] += this.eyeY; + rotatedCenter[2] += this.eyeZ; + + this.camera( + this.eyeX, + this.eyeY, + this.eyeZ, + rotatedCenter[0], + rotatedCenter[1], + rotatedCenter[2], + this.upX, + this.upY, + this.upZ + ); + }; + + /** + * Panning rotates the camera view to the left and right. + * @method pan + * @param {Number} angle amount to rotate camera in current + * angleMode units. + * Greater than 0 values rotate counterclockwise (to the left). + * @example + *
+ * + * let cam; + * let delta = 0.01; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * normalMaterial(); + * cam = createCamera(); + * // set initial pan angle + * cam.pan(-0.8); + * } + * + * function draw() { + * background(200); + * + * // pan camera according to angle 'delta' + * cam.pan(delta); + * + * // every 160 frames, switch direction + * if (frameCount % 160 === 0) { + * delta *= -1; + * } + * + * rotateX(frameCount * 0.01); + * translate(-100, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * } + * + *
+ * + * @alt + * camera view pans left and right across a series of rotating 3D boxes. + * + */ + p5.Camera.prototype.pan = function(amount) { + var local = this._getLocalAxes(); + this._rotateView(amount, local.y[0], local.y[1], local.y[2]); + }; + + /** + * Tilting rotates the camera view up and down. + * @method tilt + * @param {Number} angle amount to rotate camera in current + * angleMode units. + * Greater than 0 values rotate counterclockwise (to the left). + * @example + *
+ * + * let cam; + * let delta = 0.01; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * normalMaterial(); + * cam = createCamera(); + * // set initial tilt + * cam.tilt(-0.8); + * } + * + * function draw() { + * background(200); + * + * // pan camera according to angle 'delta' + * cam.tilt(delta); + * + * // every 160 frames, switch direction + * if (frameCount % 160 === 0) { + * delta *= -1; + * } + * + * rotateY(frameCount * 0.01); + * translate(0, -100, 0); + * box(20); + * translate(0, 35, 0); + * box(20); + * translate(0, 35, 0); + * box(20); + * translate(0, 35, 0); + * box(20); + * translate(0, 35, 0); + * box(20); + * translate(0, 35, 0); + * box(20); + * translate(0, 35, 0); + * box(20); + * } + * + *
+ * + * @alt + * camera view tilts up and down across a series of rotating 3D boxes. + */ + p5.Camera.prototype.tilt = function(amount) { + var local = this._getLocalAxes(); + this._rotateView(amount, local.x[0], local.x[1], local.x[2]); + }; + + /** + * Reorients the camera to look at a position in world space. + * @method lookAt + * @for p5.Camera + * @param {Number} x x position of a point in world space + * @param {Number} y y position of a point in world space + * @param {Number} z z position of a point in world space + * @example + *
+ * + * let cam; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * normalMaterial(); + * cam = createCamera(); + * } + * + * function draw() { + * background(200); + * + * // look at a new random point every 60 frames + * if (frameCount % 60 === 0) { + * cam.lookAt(random(-100, 100), random(-50, 50), 0); + * } + * + * rotateX(frameCount * 0.01); + * translate(-100, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * } + * + *
+ * + * @alt + * camera view of rotating 3D cubes changes to look at a new random + * point every second . + */ + p5.Camera.prototype.lookAt = function(x, y, z) { + this.camera( + this.eyeX, + this.eyeY, + this.eyeZ, + x, + y, + z, + this.upX, + this.upY, + this.upZ + ); + }; + + //////////////////////////////////////////////////////////////////////////////// + // Camera Position Methods + //////////////////////////////////////////////////////////////////////////////// + + /** + * Sets a camera's position and orientation. This is equivalent to calling + * camera() on a p5.Camera object. + * @method camera + * @for p5.Camera + */ + p5.Camera.prototype.camera = function( + eyeX, + eyeY, + eyeZ, + centerX, + centerY, + centerZ, + upX, + upY, + upZ + ) { + if (typeof eyeX === 'undefined') { + eyeX = this.defaultEyeX; + eyeY = this.defaultEyeY; + eyeZ = this.defaultEyeZ; + centerX = eyeX; + centerY = eyeY; + centerZ = 0; + upX = 0; + upY = 1; + upZ = 0; + } + + this.eyeX = eyeX; + this.eyeY = eyeY; + this.eyeZ = eyeZ; + + this.centerX = centerX; + this.centerY = centerY; + this.centerZ = centerZ; + + this.upX = upX; + this.upY = upY; + this.upZ = upZ; + + var local = this._getLocalAxes(); + + // the camera affects the model view matrix, insofar as it + // inverse translates the world to the eye position of the camera + // and rotates it. + // prettier-ignore + this.cameraMatrix.set(local.x[0], local.y[0], local.z[0], 0, + local.x[1], local.y[1], local.z[1], 0, + local.x[2], local.y[2], local.z[2], 0, + 0, 0, 0, 1); + + var tx = -eyeX; + var ty = -eyeY; + var tz = -eyeZ; + + this.cameraMatrix.translate([tx, ty, tz]); + + if (this._isActive()) { + this._renderer.uMVMatrix.set( + this.cameraMatrix.mat4[0], + this.cameraMatrix.mat4[1], + this.cameraMatrix.mat4[2], + this.cameraMatrix.mat4[3], + this.cameraMatrix.mat4[4], + this.cameraMatrix.mat4[5], + this.cameraMatrix.mat4[6], + this.cameraMatrix.mat4[7], + this.cameraMatrix.mat4[8], + this.cameraMatrix.mat4[9], + this.cameraMatrix.mat4[10], + this.cameraMatrix.mat4[11], + this.cameraMatrix.mat4[12], + this.cameraMatrix.mat4[13], + this.cameraMatrix.mat4[14], + this.cameraMatrix.mat4[15] + ); + } + return this; + }; + + /** + * Move camera along its local axes while maintaining current camera orientation. + * @method move + * @param {Number} x amount to move along camera's left-right axis + * @param {Number} y amount to move along camera's up-down axis + * @param {Number} z amount to move along camera's forward-backward axis + * @example + *
+ * + * // see the camera move along its own axes while maintaining its orientation + * let cam; + * let delta = 0.5; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * normalMaterial(); + * cam = createCamera(); + * } + * + * function draw() { + * background(200); + * + * // move the camera along its local axes + * cam.move(delta, delta, 0); + * + * // every 100 frames, switch direction + * if (frameCount % 150 === 0) { + * delta *= -1; + * } + * + * translate(-10, -10, 0); + * box(50, 8, 50); + * translate(15, 15, 0); + * box(50, 8, 50); + * translate(15, 15, 0); + * box(50, 8, 50); + * translate(15, 15, 0); + * box(50, 8, 50); + * translate(15, 15, 0); + * box(50, 8, 50); + * translate(15, 15, 0); + * box(50, 8, 50); + * } + * + *
+ * + * @alt + * camera view moves along a series of 3D boxes, maintaining the same + * orientation throughout the move + */ + p5.Camera.prototype.move = function(x, y, z) { + var local = this._getLocalAxes(); + + // scale local axes by movement amounts + // based on http://learnwebgl.brown37.net/07_cameras/camera_linear_motion.html + var dx = [local.x[0] * x, local.x[1] * x, local.x[2] * x]; + var dy = [local.y[0] * y, local.y[1] * y, local.y[2] * y]; + var dz = [local.z[0] * z, local.z[1] * z, local.z[2] * z]; + + this.camera( + this.eyeX + dx[0] + dy[0] + dz[0], + this.eyeY + dx[1] + dy[1] + dz[1], + this.eyeZ + dx[2] + dy[2] + dz[2], + this.centerX + dx[0] + dy[0] + dz[0], + this.centerY + dx[1] + dy[1] + dz[1], + this.centerZ + dx[2] + dy[2] + dz[2], + 0, + 1, + 0 + ); + }; + + /** + * Set camera position in world-space while maintaining current camera + * orientation. + * @method setPosition + * @param {Number} x x position of a point in world space + * @param {Number} y y position of a point in world space + * @param {Number} z z position of a point in world space + * @example + *
+ * + * // press '1' '2' or '3' keys to set camera position + * + * let cam; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * normalMaterial(); + * cam = createCamera(); + * } + * + * function draw() { + * background(200); + * + * // '1' key + * if (keyIsDown(49)) { + * cam.setPosition(30, 0, 80); + * } + * // '2' key + * if (keyIsDown(50)) { + * cam.setPosition(0, 0, 80); + * } + * // '3' key + * if (keyIsDown(51)) { + * cam.setPosition(-30, 0, 80); + * } + * + * box(20); + * } + * + *
+ * + * @alt + * camera position changes as the user presses keys, altering view of a 3D box + */ + p5.Camera.prototype.setPosition = function(x, y, z) { + var diffX = x - this.eyeX; + var diffY = y - this.eyeY; + var diffZ = z - this.eyeZ; + + this.camera( + x, + y, + z, + this.centerX + diffX, + this.centerY + diffY, + this.centerZ + diffZ, + 0, + 1, + 0 + ); + }; + + //////////////////////////////////////////////////////////////////////////////// + // Camera Helper Methods + //////////////////////////////////////////////////////////////////////////////// + + // @TODO: combine this function with _setDefaultCamera to compute these values + // as-needed + p5.Camera.prototype._computeCameraDefaultSettings = function() { + this.defaultCameraFOV = 60 / 180 * Math.PI; + this.defaultAspectRatio = this._renderer.width / this._renderer.height; + this.defaultEyeX = 0; + this.defaultEyeY = 0; + this.defaultEyeZ = + this._renderer.height / 2.0 / Math.tan(this.defaultCameraFOV / 2.0); + this.defaultCenterX = 0; + this.defaultCenterY = 0; + this.defaultCenterZ = 0; + this.defaultCameraNear = this.defaultEyeZ * 0.1; + this.defaultCameraFar = this.defaultEyeZ * 10; + }; + + //detect if user didn't set the camera + //then call this function below + p5.Camera.prototype._setDefaultCamera = function() { + this.cameraFOV = this.defaultCameraFOV; + this.aspectRatio = this.defaultAspectRatio; + this.eyeX = this.defaultEyeX; + this.eyeY = this.defaultEyeY; + this.eyeZ = this.defaultEyeZ; + this.centerX = this.defaultCenterX; + this.centerY = this.defaultCenterY; + this.centerZ = this.defaultCenterZ; + this.upX = 0; + this.upY = 1; + this.upZ = 0; + this.cameraNear = this.defaultCameraNear; + this.cameraFar = this.defaultCameraFar; + + this.perspective(); + this.camera(); + + this.cameraType = 'default'; + }; + + p5.Camera.prototype._resize = function() { + // If we're using the default camera, update the aspect ratio + if (this.cameraType === 'default') { + this._computeCameraDefaultSettings(); + this._setDefaultCamera(); + } else { + this.perspective( + this.cameraFOV, + this._renderer.width / this._renderer.height + ); + } + }; + + /** + * Returns a copy of a camera. + * @method copy + * @private + */ + p5.Camera.prototype.copy = function() { + var _cam = new p5.Camera(this._renderer); + _cam.cameraFOV = this.cameraFOV; + _cam.aspectRatio = this.aspectRatio; + _cam.eyeX = this.eyeX; + _cam.eyeY = this.eyeY; + _cam.eyeZ = this.eyeZ; + _cam.centerX = this.centerX; + _cam.centerY = this.centerY; + _cam.centerZ = this.centerZ; + _cam.cameraNear = this.cameraNear; + _cam.cameraFar = this.cameraFar; + + _cam.cameraType = this.cameraType; + + _cam.cameraMatrix = this.cameraMatrix.copy(); + _cam.projMatrix = this.projMatrix.copy(); + + return _cam; + }; + + /** + * Returns a camera's local axes: left-right, up-down, and forward-backward, + * as defined by vectors in world-space. + * @method _getLocalAxes + * @private + */ + p5.Camera.prototype._getLocalAxes = function() { + // calculate camera local Z vector + var z0 = this.eyeX - this.centerX; + var z1 = this.eyeY - this.centerY; + var z2 = this.eyeZ - this.centerZ; + + // normalize camera local Z vector + var eyeDist = Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2); + if (eyeDist !== 0) { + z0 /= eyeDist; + z1 /= eyeDist; + z2 /= eyeDist; + } + + // calculate camera Y vector + var y0 = this.upX; + var y1 = this.upY; + var y2 = this.upZ; + + // compute camera local X vector as up vector (local Y) cross local Z + var x0 = y1 * z2 - y2 * z1; + var x1 = -y0 * z2 + y2 * z0; + var x2 = y0 * z1 - y1 * z0; + + // recompute y = z cross x + y0 = z1 * x2 - z2 * x1; + y1 = -z0 * x2 + z2 * x0; + y2 = z0 * x1 - z1 * x0; + + // cross product gives area of parallelogram, which is < 1.0 for + // non-perpendicular unit-length vectors; so normalize x, y here: + var xmag = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2); + if (xmag !== 0) { + x0 /= xmag; + x1 /= xmag; + x2 /= xmag; + } + + var ymag = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2); + if (ymag !== 0) { + y0 /= ymag; + y1 /= ymag; + y2 /= ymag; + } + + return { + x: [x0, x1, x2], + y: [y0, y1, y2], + z: [z0, z1, z2] + }; + }; + + /** + * Orbits the camera about center point. For use with orbitControl(). + * @method _orbit + * @private + * @param {Number} dTheta change in spherical coordinate theta + * @param {Number} dPhi change in spherical coordinate phi + * @param {Number} dRadius change in radius + */ + p5.Camera.prototype._orbit = function(dTheta, dPhi, dRadius) { + var diffX = this.eyeX - this.centerX; + var diffY = this.eyeY - this.centerY; + var diffZ = this.eyeZ - this.centerZ; + + // get spherical coorinates for current camera position about origin + var camRadius = Math.sqrt(diffX * diffX + diffY * diffY + diffZ * diffZ); + // from https://github.com/mrdoob/three.js/blob/dev/src/math/Spherical.js#L72-L73 + var camTheta = Math.atan2(diffX, diffZ); // equatorial angle + var camPhi = Math.acos(Math.max(-1, Math.min(1, diffY / camRadius))); // polar angle + + // add change + camTheta += dTheta; + camPhi += dPhi; + camRadius += dRadius; + + // prevent zooming through the center: + if (camRadius < 0) { + camRadius = 0.1; + } + + // prevent rotation over the zenith / under bottom + if (camPhi > Math.PI) { + camPhi = Math.PI; + } else if (camPhi <= 0) { + camPhi = 0.001; + } + + // from https://github.com/mrdoob/three.js/blob/dev/src/math/Vector3.js#L628-L632 + var _x = Math.sin(camPhi) * camRadius * Math.sin(camTheta); + var _y = Math.cos(camPhi) * camRadius; + var _z = Math.sin(camPhi) * camRadius * Math.cos(camTheta); + + this.camera( + _x + this.centerX, + _y + this.centerY, + _z + this.centerZ, + this.centerX, + this.centerY, + this.centerZ, + 0, + 1, + 0 + ); + }; + + /** + * Returns true if camera is currently attached to renderer. + * @method _isActive + * @private + */ + p5.Camera.prototype._isActive = function() { + return this === this._renderer._curCamera; + }; + + /** + * Sets rendererGL's current camera to a p5.Camera object. Allows switching + * between multiple cameras. + * @method setCamera + * @param {p5.Camera} cam p5.Camera object + * @for p5 + * @example + *
+ * + * let cam1, cam2; + * let currentCamera; + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * normalMaterial(); + * + * cam1 = createCamera(); + * cam2 = createCamera(); + * cam2.setPosition(30, 0, 50); + * cam2.lookAt(0, 0, 0); + * cam2.ortho(); + * + * // set variable for previously active camera: + * currentCamera = 1; + * } + * + * function draw() { + * background(200); + * + * // camera 1: + * cam1.lookAt(0, 0, 0); + * cam1.setPosition(sin(frameCount / 60) * 200, 0, 100); + * + * // every 100 frames, switch between the two cameras + * if (frameCount % 100 === 0) { + * if (currentCamera === 1) { + * setCamera(cam1); + * currentCamera = 0; + * } else { + * setCamera(cam2); + * currentCamera = 1; + * } + * } + * + * drawBoxes(); + * } + * + * function drawBoxes() { + * rotateX(frameCount * 0.01); + * translate(-100, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * translate(35, 0, 0); + * box(20); + * } + * + *
+ * + * @alt + * Canvas switches between two camera views, each showing a series of spinning + * 3D boxes. + */ + p5.prototype.setCamera = function(cam) { + this._renderer._curCamera = cam; + + // set the projection matrix (which is not normally updated each frame) + this._renderer.uPMatrix.set( + cam.projMatrix.mat4[0], + cam.projMatrix.mat4[1], + cam.projMatrix.mat4[2], + cam.projMatrix.mat4[3], + cam.projMatrix.mat4[4], + cam.projMatrix.mat4[5], + cam.projMatrix.mat4[6], + cam.projMatrix.mat4[7], + cam.projMatrix.mat4[8], + cam.projMatrix.mat4[9], + cam.projMatrix.mat4[10], + cam.projMatrix.mat4[11], + cam.projMatrix.mat4[12], + cam.projMatrix.mat4[13], + cam.projMatrix.mat4[14], + cam.projMatrix.mat4[15] + ); + }; + + module.exports = p5.Camera; + }, + { '../core/main': 24 } + ], + 71: [ + function(_dereq_, module, exports) { + //some of the functions are adjusted from Three.js(http://threejs.org) + + 'use strict'; + + var p5 = _dereq_('../core/main'); + /** + * p5 Geometry class + * @class p5.Geometry + * @constructor + * @param {Integer} [detailX] number of vertices on horizontal surface + * @param {Integer} [detailY] number of vertices on horizontal surface + * @param {function} [callback] function to call upon object instantiation. + * + */ + p5.Geometry = function(detailX, detailY, callback) { + //an array containing every vertex + //@type [p5.Vector] + this.vertices = []; + + //an array containing every vertex for stroke drawing + this.lineVertices = []; + + //an array 1 normal per lineVertex with + //final position representing which direction to + //displace for strokeWeight + //[[0,0,-1,1], [0,1,0,-1] ...]; + this.lineNormals = []; + + //an array containing 1 normal per vertex + //@type [p5.Vector] + //[p5.Vector, p5.Vector, p5.Vector,p5.Vector, p5.Vector, p5.Vector,...] + this.vertexNormals = []; + //an array containing each three vertex indices that form a face + //[[0, 1, 2], [2, 1, 3], ...] + this.faces = []; + //a 2D array containing uvs for every vertex + //[[0.0,0.0],[1.0,0.0], ...] + this.uvs = []; + // a 2D array containing edge connectivity pattern for create line vertices + //based on faces for most objects; + this.edges = []; + this.detailX = detailX !== undefined ? detailX : 1; + this.detailY = detailY !== undefined ? detailY : 1; + + this.dirtyFlags = {}; + + if (callback instanceof Function) { + callback.call(this); + } + return this; // TODO: is this a constructor? + }; + + p5.Geometry.prototype.reset = function() { + this.lineVertices.length = 0; + this.lineNormals.length = 0; + + this.vertices.length = 0; + this.edges.length = 0; + this.vertexColors.length = 0; + this.vertexNormals.length = 0; + this.uvs.length = 0; + + this.dirtyFlags = {}; + }; + + /** + * @method computeFaces + * @chainable + */ + p5.Geometry.prototype.computeFaces = function() { + this.faces.length = 0; + var sliceCount = this.detailX + 1; + var a, b, c, d; + for (var i = 0; i < this.detailY; i++) { + for (var j = 0; j < this.detailX; j++) { + a = i * sliceCount + j; // + offset; + b = i * sliceCount + j + 1; // + offset; + c = (i + 1) * sliceCount + j + 1; // + offset; + d = (i + 1) * sliceCount + j; // + offset; + this.faces.push([a, b, d]); + this.faces.push([d, b, c]); + } + } + return this; + }; + + p5.Geometry.prototype._getFaceNormal = function(faceId) { + //This assumes that vA->vB->vC is a counter-clockwise ordering + var face = this.faces[faceId]; + var vA = this.vertices[face[0]]; + var vB = this.vertices[face[1]]; + var vC = this.vertices[face[2]]; + var ab = p5.Vector.sub(vB, vA); + var ac = p5.Vector.sub(vC, vA); + var n = p5.Vector.cross(ab, ac); + var ln = p5.Vector.mag(n); + var sinAlpha = ln / (p5.Vector.mag(ab) * p5.Vector.mag(ac)); + if (sinAlpha === 0 || isNaN(sinAlpha)) { + console.warn( + 'p5.Geometry.prototype._getFaceNormal:', + 'face has colinear sides or a repeated vertex' + ); + + return n; + } + if (sinAlpha > 1) sinAlpha = 1; // handle float rounding error + return n.mult(Math.asin(sinAlpha) / ln); + }; + /** + * computes smooth normals per vertex as an average of each + * face. + * @method computeNormals + * @chainable + */ + p5.Geometry.prototype.computeNormals = function() { + var vertexNormals = this.vertexNormals; + var vertices = this.vertices; + var faces = this.faces; + var iv; + + // initialize the vertexNormals array with empty vectors + vertexNormals.length = 0; + for (iv = 0; iv < vertices.length; ++iv) { + vertexNormals.push(new p5.Vector()); + } + + // loop through all the faces adding its normal to the normal + // of each of its vertices + for (var f = 0; f < faces.length; ++f) { + var face = faces[f]; + var faceNormal = this._getFaceNormal(f); + + // all three vertices get the normal added + for (var fv = 0; fv < 3; ++fv) { + var vertexIndex = face[fv]; + vertexNormals[vertexIndex].add(faceNormal); + } + } + + // normalize the normals + for (iv = 0; iv < vertices.length; ++iv) { + vertexNormals[iv].normalize(); + } + + return this; + }; + + /** + * Averages the vertex normals. Used in curved + * surfaces + * @method averageNormals + * @chainable + */ + p5.Geometry.prototype.averageNormals = function() { + for (var i = 0; i <= this.detailY; i++) { + var offset = this.detailX + 1; + var temp = p5.Vector.add( + this.vertexNormals[i * offset], + this.vertexNormals[i * offset + this.detailX] + ); + + temp = p5.Vector.div(temp, 2); + this.vertexNormals[i * offset] = temp; + this.vertexNormals[i * offset + this.detailX] = temp; + } + return this; + }; + + /** + * Averages pole normals. Used in spherical primitives + * @method averagePoleNormals + * @chainable + */ + p5.Geometry.prototype.averagePoleNormals = function() { + //average the north pole + var sum = new p5.Vector(0, 0, 0); + for (var i = 0; i < this.detailX; i++) { + sum.add(this.vertexNormals[i]); + } + sum = p5.Vector.div(sum, this.detailX); + + for (i = 0; i < this.detailX; i++) { + this.vertexNormals[i] = sum; + } + + //average the south pole + sum = new p5.Vector(0, 0, 0); + for ( + i = this.vertices.length - 1; + i > this.vertices.length - 1 - this.detailX; + i-- + ) { + sum.add(this.vertexNormals[i]); + } + sum = p5.Vector.div(sum, this.detailX); + + for ( + i = this.vertices.length - 1; + i > this.vertices.length - 1 - this.detailX; + i-- + ) { + this.vertexNormals[i] = sum; + } + return this; + }; + + /** + * Create a 2D array for establishing stroke connections + * @private + * @chainable + */ + p5.Geometry.prototype._makeTriangleEdges = function() { + this.edges.length = 0; + if (Array.isArray(this.strokeIndices)) { + for (var i = 0, max = this.strokeIndices.length; i < max; i++) { + this.edges.push(this.strokeIndices[i]); + } + } else { + for (var j = 0; j < this.faces.length; j++) { + this.edges.push([this.faces[j][0], this.faces[j][1]]); + this.edges.push([this.faces[j][1], this.faces[j][2]]); + this.edges.push([this.faces[j][2], this.faces[j][0]]); + } + } + return this; + }; + + /** + * Create 4 vertices for each stroke line, two at the beginning position + * and two at the end position. These vertices are displaced relative to + * that line's normal on the GPU + * @private + * @chainable + */ + p5.Geometry.prototype._edgesToVertices = function() { + this.lineVertices.length = 0; + this.lineNormals.length = 0; + + for (var i = 0; i < this.edges.length; i++) { + var begin = this.vertices[this.edges[i][0]]; + var end = this.vertices[this.edges[i][1]]; + var dir = end + .copy() + .sub(begin) + .normalize(); + var a = begin.array(); + var b = begin.array(); + var c = end.array(); + var d = end.array(); + var dirAdd = dir.array(); + var dirSub = dir.array(); + // below is used to displace the pair of vertices at beginning and end + // in opposite directions + dirAdd.push(1); + dirSub.push(-1); + this.lineNormals.push(dirAdd, dirSub, dirAdd, dirAdd, dirSub, dirSub); + this.lineVertices.push(a, b, c, c, b, d); + } + return this; + }; + + /** + * Modifies all vertices to be centered within the range -100 to 100. + * @method normalize + * @chainable + */ + p5.Geometry.prototype.normalize = function() { + if (this.vertices.length > 0) { + // Find the corners of our bounding box + var maxPosition = this.vertices[0].copy(); + var minPosition = this.vertices[0].copy(); + + for (var i = 0; i < this.vertices.length; i++) { + maxPosition.x = Math.max(maxPosition.x, this.vertices[i].x); + minPosition.x = Math.min(minPosition.x, this.vertices[i].x); + maxPosition.y = Math.max(maxPosition.y, this.vertices[i].y); + minPosition.y = Math.min(minPosition.y, this.vertices[i].y); + maxPosition.z = Math.max(maxPosition.z, this.vertices[i].z); + minPosition.z = Math.min(minPosition.z, this.vertices[i].z); + } + + var center = p5.Vector.lerp(maxPosition, minPosition, 0.5); + var dist = p5.Vector.sub(maxPosition, minPosition); + var longestDist = Math.max(Math.max(dist.x, dist.y), dist.z); + var scale = 200 / longestDist; + + for (i = 0; i < this.vertices.length; i++) { + this.vertices[i].sub(center); + this.vertices[i].mult(scale); + } + } + return this; + }; + + module.exports = p5.Geometry; + }, + { '../core/main': 24 } + ], + 72: [ + function(_dereq_, module, exports) { + /** + * @requires constants + * @todo see methods below needing further implementation. + * future consideration: implement SIMD optimizations + * when browser compatibility becomes available + * https://developer.mozilla.org/en-US/docs/Web/JavaScript/ + * Reference/Global_Objects/SIMD + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + var GLMAT_ARRAY_TYPE = Array; + var isMatrixArray = function isMatrixArray(x) { + return x instanceof Array; + }; + if (typeof Float32Array !== 'undefined') { + GLMAT_ARRAY_TYPE = Float32Array; + isMatrixArray = function isMatrixArray(x) { + return x instanceof Array || x instanceof Float32Array; + }; + } + + /** + * A class to describe a 4x4 matrix + * for model and view matrix manipulation in the p5js webgl renderer. + * @class p5.Matrix + * @private + * @constructor + * @param {Array} [mat4] array literal of our 4x4 matrix + */ + p5.Matrix = function() { + var args = new Array(arguments.length); + for (var i = 0; i < args.length; ++i) { + args[i] = arguments[i]; + } + + // This is default behavior when object + // instantiated using createMatrix() + // @todo implement createMatrix() in core/math.js + if (args.length && args[args.length - 1] instanceof p5) { + this.p5 = args[args.length - 1]; + } + + if (args[0] === 'mat3') { + this.mat3 = Array.isArray(args[1]) + ? args[1] + : new GLMAT_ARRAY_TYPE([1, 0, 0, 0, 1, 0, 0, 0, 1]); + } else { + this.mat4 = Array.isArray(args[0]) + ? args[0] + : new GLMAT_ARRAY_TYPE([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]); + } + return this; + }; + + /** + * Sets the x, y, and z component of the vector using two or three separate + * variables, the data from a p5.Matrix, or the values from a float array. + * + * @method set + * @param {p5.Matrix|Float32Array|Number[]} [inMatrix] the input p5.Matrix or + * an Array of length 16 + * @chainable + */ + /** + * @method set + * @param {Number[]} elements 16 numbers passed by value to avoid + * array copying. + * @chainable + */ + p5.Matrix.prototype.set = function(inMatrix) { + if (inMatrix instanceof p5.Matrix) { + this.mat4 = inMatrix.mat4; + return this; + } else if (isMatrixArray(inMatrix)) { + this.mat4 = inMatrix; + return this; + } else if (arguments.length === 16) { + this.mat4[0] = arguments[0]; + this.mat4[1] = arguments[1]; + this.mat4[2] = arguments[2]; + this.mat4[3] = arguments[3]; + this.mat4[4] = arguments[4]; + this.mat4[5] = arguments[5]; + this.mat4[6] = arguments[6]; + this.mat4[7] = arguments[7]; + this.mat4[8] = arguments[8]; + this.mat4[9] = arguments[9]; + this.mat4[10] = arguments[10]; + this.mat4[11] = arguments[11]; + this.mat4[12] = arguments[12]; + this.mat4[13] = arguments[13]; + this.mat4[14] = arguments[14]; + this.mat4[15] = arguments[15]; + } + return this; + }; + + /** + * Gets a copy of the vector, returns a p5.Matrix object. + * + * @method get + * @return {p5.Matrix} the copy of the p5.Matrix object + */ + p5.Matrix.prototype.get = function() { + return new p5.Matrix(this.mat4, this.p5); + }; + + /** + * return a copy of a matrix + * @method copy + * @return {p5.Matrix} the result matrix + */ + p5.Matrix.prototype.copy = function() { + var copied = new p5.Matrix(this.p5); + copied.mat4[0] = this.mat4[0]; + copied.mat4[1] = this.mat4[1]; + copied.mat4[2] = this.mat4[2]; + copied.mat4[3] = this.mat4[3]; + copied.mat4[4] = this.mat4[4]; + copied.mat4[5] = this.mat4[5]; + copied.mat4[6] = this.mat4[6]; + copied.mat4[7] = this.mat4[7]; + copied.mat4[8] = this.mat4[8]; + copied.mat4[9] = this.mat4[9]; + copied.mat4[10] = this.mat4[10]; + copied.mat4[11] = this.mat4[11]; + copied.mat4[12] = this.mat4[12]; + copied.mat4[13] = this.mat4[13]; + copied.mat4[14] = this.mat4[14]; + copied.mat4[15] = this.mat4[15]; + return copied; + }; + + /** + * return an identity matrix + * @method identity + * @return {p5.Matrix} the result matrix + */ + p5.Matrix.identity = function(pInst) { + return new p5.Matrix(pInst); + }; + + /** + * transpose according to a given matrix + * @method transpose + * @param {p5.Matrix|Float32Array|Number[]} a the matrix to be + * based on to transpose + * @chainable + */ + p5.Matrix.prototype.transpose = function(a) { + var a01, a02, a03, a12, a13, a23; + if (a instanceof p5.Matrix) { + a01 = a.mat4[1]; + a02 = a.mat4[2]; + a03 = a.mat4[3]; + a12 = a.mat4[6]; + a13 = a.mat4[7]; + a23 = a.mat4[11]; + + this.mat4[0] = a.mat4[0]; + this.mat4[1] = a.mat4[4]; + this.mat4[2] = a.mat4[8]; + this.mat4[3] = a.mat4[12]; + this.mat4[4] = a01; + this.mat4[5] = a.mat4[5]; + this.mat4[6] = a.mat4[9]; + this.mat4[7] = a.mat4[13]; + this.mat4[8] = a02; + this.mat4[9] = a12; + this.mat4[10] = a.mat4[10]; + this.mat4[11] = a.mat4[14]; + this.mat4[12] = a03; + this.mat4[13] = a13; + this.mat4[14] = a23; + this.mat4[15] = a.mat4[15]; + } else if (isMatrixArray(a)) { + a01 = a[1]; + a02 = a[2]; + a03 = a[3]; + a12 = a[6]; + a13 = a[7]; + a23 = a[11]; + + this.mat4[0] = a[0]; + this.mat4[1] = a[4]; + this.mat4[2] = a[8]; + this.mat4[3] = a[12]; + this.mat4[4] = a01; + this.mat4[5] = a[5]; + this.mat4[6] = a[9]; + this.mat4[7] = a[13]; + this.mat4[8] = a02; + this.mat4[9] = a12; + this.mat4[10] = a[10]; + this.mat4[11] = a[14]; + this.mat4[12] = a03; + this.mat4[13] = a13; + this.mat4[14] = a23; + this.mat4[15] = a[15]; + } + return this; + }; + + /** + * invert matrix according to a give matrix + * @method invert + * @param {p5.Matrix|Float32Array|Number[]} a the matrix to be + * based on to invert + * @chainable + */ + p5.Matrix.prototype.invert = function(a) { + var a00, a01, a02, a03, a10, a11, a12, a13; + var a20, a21, a22, a23, a30, a31, a32, a33; + if (a instanceof p5.Matrix) { + a00 = a.mat4[0]; + a01 = a.mat4[1]; + a02 = a.mat4[2]; + a03 = a.mat4[3]; + a10 = a.mat4[4]; + a11 = a.mat4[5]; + a12 = a.mat4[6]; + a13 = a.mat4[7]; + a20 = a.mat4[8]; + a21 = a.mat4[9]; + a22 = a.mat4[10]; + a23 = a.mat4[11]; + a30 = a.mat4[12]; + a31 = a.mat4[13]; + a32 = a.mat4[14]; + a33 = a.mat4[15]; + } else if (isMatrixArray(a)) { + a00 = a[0]; + a01 = a[1]; + a02 = a[2]; + a03 = a[3]; + a10 = a[4]; + a11 = a[5]; + a12 = a[6]; + a13 = a[7]; + a20 = a[8]; + a21 = a[9]; + a22 = a[10]; + a23 = a[11]; + a30 = a[12]; + a31 = a[13]; + a32 = a[14]; + a33 = a[15]; + } + var b00 = a00 * a11 - a01 * a10; + var b01 = a00 * a12 - a02 * a10; + var b02 = a00 * a13 - a03 * a10; + var b03 = a01 * a12 - a02 * a11; + var b04 = a01 * a13 - a03 * a11; + var b05 = a02 * a13 - a03 * a12; + var b06 = a20 * a31 - a21 * a30; + var b07 = a20 * a32 - a22 * a30; + var b08 = a20 * a33 - a23 * a30; + var b09 = a21 * a32 - a22 * a31; + var b10 = a21 * a33 - a23 * a31; + var b11 = a22 * a33 - a23 * a32; + + // Calculate the determinant + var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06; + + if (!det) { + return null; + } + det = 1.0 / det; + + this.mat4[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det; + this.mat4[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det; + this.mat4[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det; + this.mat4[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det; + this.mat4[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det; + this.mat4[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det; + this.mat4[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det; + this.mat4[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det; + this.mat4[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det; + this.mat4[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det; + this.mat4[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det; + this.mat4[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det; + this.mat4[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det; + this.mat4[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det; + this.mat4[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det; + this.mat4[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det; + + return this; + }; + + /** + * Inverts a 3x3 matrix + * @method invert3x3 + * @chainable + */ + p5.Matrix.prototype.invert3x3 = function() { + var a00 = this.mat3[0]; + var a01 = this.mat3[1]; + var a02 = this.mat3[2]; + var a10 = this.mat3[3]; + var a11 = this.mat3[4]; + var a12 = this.mat3[5]; + var a20 = this.mat3[6]; + var a21 = this.mat3[7]; + var a22 = this.mat3[8]; + var b01 = a22 * a11 - a12 * a21; + var b11 = -a22 * a10 + a12 * a20; + var b21 = a21 * a10 - a11 * a20; + + // Calculate the determinant + var det = a00 * b01 + a01 * b11 + a02 * b21; + if (!det) { + return null; + } + det = 1.0 / det; + this.mat3[0] = b01 * det; + this.mat3[1] = (-a22 * a01 + a02 * a21) * det; + this.mat3[2] = (a12 * a01 - a02 * a11) * det; + this.mat3[3] = b11 * det; + this.mat3[4] = (a22 * a00 - a02 * a20) * det; + this.mat3[5] = (-a12 * a00 + a02 * a10) * det; + this.mat3[6] = b21 * det; + this.mat3[7] = (-a21 * a00 + a01 * a20) * det; + this.mat3[8] = (a11 * a00 - a01 * a10) * det; + return this; + }; + + /** + * transposes a 3x3 p5.Matrix by a mat3 + * @method transpose3x3 + * @param {Number[]} mat3 1-dimensional array + * @chainable + */ + p5.Matrix.prototype.transpose3x3 = function(mat3) { + var a01 = mat3[1], + a02 = mat3[2], + a12 = mat3[5]; + this.mat3[1] = mat3[3]; + this.mat3[2] = mat3[6]; + this.mat3[3] = a01; + this.mat3[5] = mat3[7]; + this.mat3[6] = a02; + this.mat3[7] = a12; + return this; + }; + + /** + * converts a 4x4 matrix to its 3x3 inverse transform + * commonly used in MVMatrix to NMatrix conversions. + * @method invertTranspose + * @param {p5.Matrix} mat4 the matrix to be based on to invert + * @chainable + * @todo finish implementation + */ + p5.Matrix.prototype.inverseTranspose = function(matrix) { + if (this.mat3 === undefined) { + console.error('sorry, this function only works with mat3'); + } else { + //convert mat4 -> mat3 + this.mat3[0] = matrix.mat4[0]; + this.mat3[1] = matrix.mat4[1]; + this.mat3[2] = matrix.mat4[2]; + this.mat3[3] = matrix.mat4[4]; + this.mat3[4] = matrix.mat4[5]; + this.mat3[5] = matrix.mat4[6]; + this.mat3[6] = matrix.mat4[8]; + this.mat3[7] = matrix.mat4[9]; + this.mat3[8] = matrix.mat4[10]; + } + + var inverse = this.invert3x3(); + // check inverse succeeded + if (inverse) { + inverse.transpose3x3(this.mat3); + } else { + // in case of singularity, just zero the matrix + for (var i = 0; i < 9; i++) { + this.mat3[i] = 0; + } + } + return this; + }; + + /** + * inspired by Toji's mat4 determinant + * @method determinant + * @return {Number} Determinant of our 4x4 matrix + */ + p5.Matrix.prototype.determinant = function() { + var d00 = this.mat4[0] * this.mat4[5] - this.mat4[1] * this.mat4[4], + d01 = this.mat4[0] * this.mat4[6] - this.mat4[2] * this.mat4[4], + d02 = this.mat4[0] * this.mat4[7] - this.mat4[3] * this.mat4[4], + d03 = this.mat4[1] * this.mat4[6] - this.mat4[2] * this.mat4[5], + d04 = this.mat4[1] * this.mat4[7] - this.mat4[3] * this.mat4[5], + d05 = this.mat4[2] * this.mat4[7] - this.mat4[3] * this.mat4[6], + d06 = this.mat4[8] * this.mat4[13] - this.mat4[9] * this.mat4[12], + d07 = this.mat4[8] * this.mat4[14] - this.mat4[10] * this.mat4[12], + d08 = this.mat4[8] * this.mat4[15] - this.mat4[11] * this.mat4[12], + d09 = this.mat4[9] * this.mat4[14] - this.mat4[10] * this.mat4[13], + d10 = this.mat4[9] * this.mat4[15] - this.mat4[11] * this.mat4[13], + d11 = this.mat4[10] * this.mat4[15] - this.mat4[11] * this.mat4[14]; + + // Calculate the determinant + return d00 * d11 - d01 * d10 + d02 * d09 + d03 * d08 - d04 * d07 + d05 * d06; + }; + + /** + * multiply two mat4s + * @method mult + * @param {p5.Matrix|Float32Array|Number[]} multMatrix The matrix + * we want to multiply by + * @chainable + */ + p5.Matrix.prototype.mult = function(multMatrix) { + var _src; + + if (multMatrix === this || multMatrix === this.mat4) { + _src = this.copy().mat4; // only need to allocate in this rare case + } else if (multMatrix instanceof p5.Matrix) { + _src = multMatrix.mat4; + } else if (isMatrixArray(multMatrix)) { + _src = multMatrix; + } else if (arguments.length === 16) { + _src = arguments; + } else { + return; // nothing to do. + } + + // each row is used for the multiplier + var b0 = this.mat4[0], + b1 = this.mat4[1], + b2 = this.mat4[2], + b3 = this.mat4[3]; + this.mat4[0] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12]; + this.mat4[1] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13]; + this.mat4[2] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14]; + this.mat4[3] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15]; + + b0 = this.mat4[4]; + b1 = this.mat4[5]; + b2 = this.mat4[6]; + b3 = this.mat4[7]; + this.mat4[4] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12]; + this.mat4[5] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13]; + this.mat4[6] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14]; + this.mat4[7] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15]; + + b0 = this.mat4[8]; + b1 = this.mat4[9]; + b2 = this.mat4[10]; + b3 = this.mat4[11]; + this.mat4[8] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12]; + this.mat4[9] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13]; + this.mat4[10] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14]; + this.mat4[11] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15]; + + b0 = this.mat4[12]; + b1 = this.mat4[13]; + b2 = this.mat4[14]; + b3 = this.mat4[15]; + this.mat4[12] = b0 * _src[0] + b1 * _src[4] + b2 * _src[8] + b3 * _src[12]; + this.mat4[13] = b0 * _src[1] + b1 * _src[5] + b2 * _src[9] + b3 * _src[13]; + this.mat4[14] = b0 * _src[2] + b1 * _src[6] + b2 * _src[10] + b3 * _src[14]; + this.mat4[15] = b0 * _src[3] + b1 * _src[7] + b2 * _src[11] + b3 * _src[15]; + + return this; + }; + + p5.Matrix.prototype.apply = function(multMatrix) { + var _src; + + if (multMatrix === this || multMatrix === this.mat4) { + _src = this.copy().mat4; // only need to allocate in this rare case + } else if (multMatrix instanceof p5.Matrix) { + _src = multMatrix.mat4; + } else if (isMatrixArray(multMatrix)) { + _src = multMatrix; + } else if (arguments.length === 16) { + _src = arguments; + } else { + return; // nothing to do. + } + + var mat4 = this.mat4; + + // each row is used for the multiplier + var m0 = mat4[0]; + var m4 = mat4[4]; + var m8 = mat4[8]; + var m12 = mat4[12]; + mat4[0] = _src[0] * m0 + _src[1] * m4 + _src[2] * m8 + _src[3] * m12; + mat4[4] = _src[4] * m0 + _src[5] * m4 + _src[6] * m8 + _src[7] * m12; + mat4[8] = _src[8] * m0 + _src[9] * m4 + _src[10] * m8 + _src[11] * m12; + mat4[12] = _src[12] * m0 + _src[13] * m4 + _src[14] * m8 + _src[15] * m12; + + var m1 = mat4[1]; + var m5 = mat4[5]; + var m9 = mat4[9]; + var m13 = mat4[13]; + mat4[1] = _src[0] * m1 + _src[1] * m5 + _src[2] * m9 + _src[3] * m13; + mat4[5] = _src[4] * m1 + _src[5] * m5 + _src[6] * m9 + _src[7] * m13; + mat4[9] = _src[8] * m1 + _src[9] * m5 + _src[10] * m9 + _src[11] * m13; + mat4[13] = _src[12] * m1 + _src[13] * m5 + _src[14] * m9 + _src[15] * m13; + + var m2 = mat4[2]; + var m6 = mat4[6]; + var m10 = mat4[10]; + var m14 = mat4[14]; + mat4[2] = _src[0] * m2 + _src[1] * m6 + _src[2] * m10 + _src[3] * m14; + mat4[6] = _src[4] * m2 + _src[5] * m6 + _src[6] * m10 + _src[7] * m14; + mat4[10] = _src[8] * m2 + _src[9] * m6 + _src[10] * m10 + _src[11] * m14; + mat4[14] = _src[12] * m2 + _src[13] * m6 + _src[14] * m10 + _src[15] * m14; + + var m3 = mat4[3]; + var m7 = mat4[7]; + var m11 = mat4[11]; + var m15 = mat4[15]; + mat4[3] = _src[0] * m3 + _src[1] * m7 + _src[2] * m11 + _src[3] * m15; + mat4[7] = _src[4] * m3 + _src[5] * m7 + _src[6] * m11 + _src[7] * m15; + mat4[11] = _src[8] * m3 + _src[9] * m7 + _src[10] * m11 + _src[11] * m15; + mat4[15] = _src[12] * m3 + _src[13] * m7 + _src[14] * m11 + _src[15] * m15; + + return this; + }; + + /** + * scales a p5.Matrix by scalars or a vector + * @method scale + * @param {p5.Vector|Float32Array|Number[]} s vector to scale by + * @chainable + */ + p5.Matrix.prototype.scale = function(x, y, z) { + if (x instanceof p5.Vector) { + // x is a vector, extract the components from it. + y = x.y; + z = x.z; + x = x.x; // must be last + } else if (x instanceof Array) { + // x is an array, extract the components from it. + y = x[1]; + z = x[2]; + x = x[0]; // must be last + } + + this.mat4[0] *= x; + this.mat4[1] *= x; + this.mat4[2] *= x; + this.mat4[3] *= x; + this.mat4[4] *= y; + this.mat4[5] *= y; + this.mat4[6] *= y; + this.mat4[7] *= y; + this.mat4[8] *= z; + this.mat4[9] *= z; + this.mat4[10] *= z; + this.mat4[11] *= z; + + return this; + }; + + /** + * rotate our Matrix around an axis by the given angle. + * @method rotate + * @param {Number} a The angle of rotation in radians + * @param {p5.Vector|Number[]} axis the axis(es) to rotate around + * @chainable + * inspired by Toji's gl-matrix lib, mat4 rotation + */ + p5.Matrix.prototype.rotate = function(a, x, y, z) { + if (x instanceof p5.Vector) { + // x is a vector, extract the components from it. + y = x.y; + z = x.z; + x = x.x; //must be last + } else if (x instanceof Array) { + // x is an array, extract the components from it. + y = x[1]; + z = x[2]; + x = x[0]; //must be last + } + + var len = Math.sqrt(x * x + y * y + z * z); + x *= 1 / len; + y *= 1 / len; + z *= 1 / len; + + var a00 = this.mat4[0]; + var a01 = this.mat4[1]; + var a02 = this.mat4[2]; + var a03 = this.mat4[3]; + var a10 = this.mat4[4]; + var a11 = this.mat4[5]; + var a12 = this.mat4[6]; + var a13 = this.mat4[7]; + var a20 = this.mat4[8]; + var a21 = this.mat4[9]; + var a22 = this.mat4[10]; + var a23 = this.mat4[11]; + + //sin,cos, and tan of respective angle + var sA = Math.sin(a); + var cA = Math.cos(a); + var tA = 1 - cA; + // Construct the elements of the rotation matrix + var b00 = x * x * tA + cA; + var b01 = y * x * tA + z * sA; + var b02 = z * x * tA - y * sA; + var b10 = x * y * tA - z * sA; + var b11 = y * y * tA + cA; + var b12 = z * y * tA + x * sA; + var b20 = x * z * tA + y * sA; + var b21 = y * z * tA - x * sA; + var b22 = z * z * tA + cA; + + // rotation-specific matrix multiplication + this.mat4[0] = a00 * b00 + a10 * b01 + a20 * b02; + this.mat4[1] = a01 * b00 + a11 * b01 + a21 * b02; + this.mat4[2] = a02 * b00 + a12 * b01 + a22 * b02; + this.mat4[3] = a03 * b00 + a13 * b01 + a23 * b02; + this.mat4[4] = a00 * b10 + a10 * b11 + a20 * b12; + this.mat4[5] = a01 * b10 + a11 * b11 + a21 * b12; + this.mat4[6] = a02 * b10 + a12 * b11 + a22 * b12; + this.mat4[7] = a03 * b10 + a13 * b11 + a23 * b12; + this.mat4[8] = a00 * b20 + a10 * b21 + a20 * b22; + this.mat4[9] = a01 * b20 + a11 * b21 + a21 * b22; + this.mat4[10] = a02 * b20 + a12 * b21 + a22 * b22; + this.mat4[11] = a03 * b20 + a13 * b21 + a23 * b22; + + return this; + }; + + /** + * @todo finish implementing this method! + * translates + * @method translate + * @param {Number[]} v vector to translate by + * @chainable + */ + p5.Matrix.prototype.translate = function(v) { + var x = v[0], + y = v[1], + z = v[2] || 0; + this.mat4[12] += this.mat4[0] * x + this.mat4[4] * y + this.mat4[8] * z; + this.mat4[13] += this.mat4[1] * x + this.mat4[5] * y + this.mat4[9] * z; + this.mat4[14] += this.mat4[2] * x + this.mat4[6] * y + this.mat4[10] * z; + this.mat4[15] += this.mat4[3] * x + this.mat4[7] * y + this.mat4[11] * z; + }; + + p5.Matrix.prototype.rotateX = function(a) { + this.rotate(a, 1, 0, 0); + }; + p5.Matrix.prototype.rotateY = function(a) { + this.rotate(a, 0, 1, 0); + }; + p5.Matrix.prototype.rotateZ = function(a) { + this.rotate(a, 0, 0, 1); + }; + + /** + * sets the perspective matrix + * @method perspective + * @param {Number} fovy [description] + * @param {Number} aspect [description] + * @param {Number} near near clipping plane + * @param {Number} far far clipping plane + * @chainable + */ + p5.Matrix.prototype.perspective = function(fovy, aspect, near, far) { + var f = 1.0 / Math.tan(fovy / 2), + nf = 1 / (near - far); + + this.mat4[0] = f / aspect; + this.mat4[1] = 0; + this.mat4[2] = 0; + this.mat4[3] = 0; + this.mat4[4] = 0; + this.mat4[5] = f; + this.mat4[6] = 0; + this.mat4[7] = 0; + this.mat4[8] = 0; + this.mat4[9] = 0; + this.mat4[10] = (far + near) * nf; + this.mat4[11] = -1; + this.mat4[12] = 0; + this.mat4[13] = 0; + this.mat4[14] = 2 * far * near * nf; + this.mat4[15] = 0; + + return this; + }; + + /** + * sets the ortho matrix + * @method ortho + * @param {Number} left [description] + * @param {Number} right [description] + * @param {Number} bottom [description] + * @param {Number} top [description] + * @param {Number} near near clipping plane + * @param {Number} far far clipping plane + * @chainable + */ + p5.Matrix.prototype.ortho = function(left, right, bottom, top, near, far) { + var lr = 1 / (left - right), + bt = 1 / (bottom - top), + nf = 1 / (near - far); + this.mat4[0] = -2 * lr; + this.mat4[1] = 0; + this.mat4[2] = 0; + this.mat4[3] = 0; + this.mat4[4] = 0; + this.mat4[5] = -2 * bt; + this.mat4[6] = 0; + this.mat4[7] = 0; + this.mat4[8] = 0; + this.mat4[9] = 0; + this.mat4[10] = 2 * nf; + this.mat4[11] = 0; + this.mat4[12] = (left + right) * lr; + this.mat4[13] = (top + bottom) * bt; + this.mat4[14] = (far + near) * nf; + this.mat4[15] = 1; + + return this; + }; + + /** + * PRIVATE + */ + // matrix methods adapted from: + // https://developer.mozilla.org/en-US/docs/Web/WebGL/ + // gluPerspective + // + // function _makePerspective(fovy, aspect, znear, zfar){ + // var ymax = znear * Math.tan(fovy * Math.PI / 360.0); + // var ymin = -ymax; + // var xmin = ymin * aspect; + // var xmax = ymax * aspect; + // return _makeFrustum(xmin, xmax, ymin, ymax, znear, zfar); + // } + + //// + //// glFrustum + //// + //function _makeFrustum(left, right, bottom, top, znear, zfar){ + // var X = 2*znear/(right-left); + // var Y = 2*znear/(top-bottom); + // var A = (right+left)/(right-left); + // var B = (top+bottom)/(top-bottom); + // var C = -(zfar+znear)/(zfar-znear); + // var D = -2*zfar*znear/(zfar-znear); + // var frustrumMatrix =[ + // X, 0, A, 0, + // 0, Y, B, 0, + // 0, 0, C, D, + // 0, 0, -1, 0 + //]; + //return frustrumMatrix; + // } + + // function _setMVPMatrices(){ + ////an identity matrix + ////@TODO use the p5.Matrix class to abstract away our MV matrices and + ///other math + //var _mvMatrix = + //[ + // 1.0,0.0,0.0,0.0, + // 0.0,1.0,0.0,0.0, + // 0.0,0.0,1.0,0.0, + // 0.0,0.0,0.0,1.0 + //]; + + module.exports = p5.Matrix; + }, + { '../core/main': 24 } + ], + 73: [ + function(_dereq_, module, exports) { + /** + * Welcome to RendererGL Immediate Mode. + * Immediate mode is used for drawing custom shapes + * from a set of vertices. Immediate Mode is activated + * when you call beginShape() & de-activated when you call endShape(). + * Immediate mode is a style of programming borrowed + * from OpenGL's (now-deprecated) immediate mode. + * It differs from p5.js' default, Retained Mode, which caches + * geometries and buffers on the CPU to reduce the number of webgl + * draw calls. Retained mode is more efficient & performative, + * however, Immediate Mode is useful for sketching quick + * geometric ideas. + */ + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + + /** + * Begin shape drawing. This is a helpful way of generating + * custom shapes quickly. However in WEBGL mode, application + * performance will likely drop as a result of too many calls to + * beginShape() / endShape(). As a high performance alternative, + * please use p5.js geometry primitives. + * @private + * @method beginShape + * @param {Number} mode webgl primitives mode. beginShape supports the + * following modes: + * POINTS,LINES,LINE_STRIP,LINE_LOOP,TRIANGLES, + * TRIANGLE_STRIP,and TRIANGLE_FAN. + * @chainable + */ + p5.RendererGL.prototype.beginShape = function(mode) { + //default shape mode is line_strip + this.immediateMode.shapeMode = mode !== undefined ? mode : constants.LINE_STRIP; + //if we haven't yet initialized our + //immediateMode vertices & buffers, create them now! + if (this.immediateMode.vertices === undefined) { + this.immediateMode.vertices = []; + this.immediateMode.edges = []; + this.immediateMode.lineVertices = []; + this.immediateMode.vertexColors = []; + this.immediateMode.lineNormals = []; + this.immediateMode.uvCoords = []; + this.immediateMode.vertexBuffer = this.GL.createBuffer(); + this.immediateMode.colorBuffer = this.GL.createBuffer(); + this.immediateMode.uvBuffer = this.GL.createBuffer(); + this.immediateMode.lineVertexBuffer = this.GL.createBuffer(); + this.immediateMode.lineNormalBuffer = this.GL.createBuffer(); + this.immediateMode.pointVertexBuffer = this.GL.createBuffer(); + this.immediateMode._bezierVertex = []; + this.immediateMode._quadraticVertex = []; + this.immediateMode._curveVertex = []; + this.immediateMode._isCoplanar = true; + this.immediateMode._testIfCoplanar = null; + } else { + this.immediateMode.vertices.length = 0; + this.immediateMode.edges.length = 0; + this.immediateMode.lineVertices.length = 0; + this.immediateMode.lineNormals.length = 0; + this.immediateMode.vertexColors.length = 0; + this.immediateMode.uvCoords.length = 0; + } + this.isImmediateDrawing = true; + return this; + }; + /** + * adds a vertex to be drawn in a custom Shape. + * @private + * @method vertex + * @param {Number} x x-coordinate of vertex + * @param {Number} y y-coordinate of vertex + * @param {Number} z z-coordinate of vertex + * @chainable + * @TODO implement handling of p5.Vector args + */ + p5.RendererGL.prototype.vertex = function(x, y) { + var z, u, v; + + // default to (x, y) mode: all other arugments assumed to be 0. + z = u = v = 0; + + if (arguments.length === 3) { + // (x, y, z) mode: (u, v) assumed to be 0. + z = arguments[2]; + } else if (arguments.length === 4) { + // (x, y, u, v) mode: z assumed to be 0. + u = arguments[2]; + v = arguments[3]; + } else if (arguments.length === 5) { + // (x, y, z, u, v) mode + z = arguments[2]; + u = arguments[3]; + v = arguments[4]; + } + if (this.immediateMode._testIfCoplanar == null) { + this.immediateMode._testIfCoplanar = z; + } else if (this.immediateMode._testIfCoplanar !== z) { + this.immediateMode._isCoplanar = false; + } + var vert = new p5.Vector(x, y, z); + this.immediateMode.vertices.push(vert); + var vertexColor = this.curFillColor || [0.5, 0.5, 0.5, 1.0]; + this.immediateMode.vertexColors.push( + vertexColor[0], + vertexColor[1], + vertexColor[2], + vertexColor[3] + ); + + if (this.textureMode === constants.IMAGE) { + if (this._tex !== null) { + if (this._tex.width > 0 && this._tex.height > 0) { + u /= this._tex.width; + v /= this._tex.height; + } + } else if (this._tex === null && arguments.length >= 4) { + // Only throw this warning if custom uv's have been provided + console.warn( + 'You must first call texture() before using' + + ' vertex() with image based u and v coordinates' + ); + } + } + + this.immediateMode.uvCoords.push(u, v); + + this.immediateMode._bezierVertex[0] = x; + this.immediateMode._bezierVertex[1] = y; + this.immediateMode._bezierVertex[2] = z; + + this.immediateMode._quadraticVertex[0] = x; + this.immediateMode._quadraticVertex[1] = y; + this.immediateMode._quadraticVertex[2] = z; + + return this; + }; + + /** + * End shape drawing and render vertices to screen. + * @chainable + */ + p5.RendererGL.prototype.endShape = function( + mode, + isCurve, + isBezier, + isQuadratic, + isContour, + shapeKind + ) { + if (this.immediateMode.shapeMode === constants.POINTS) { + this._drawPoints( + this.immediateMode.vertices, + this.immediateMode.pointVertexBuffer + ); + } else if (this.immediateMode.vertices.length > 1) { + if (this._doStroke && this.drawMode !== constants.TEXTURE) { + if (this.immediateMode.shapeMode === constants.TRIANGLE_STRIP) { + var i; + for (i = 0; i < this.immediateMode.vertices.length - 2; i++) { + this.immediateMode.edges.push([i, i + 1]); + this.immediateMode.edges.push([i, i + 2]); + } + this.immediateMode.edges.push([i, i + 1]); + } else if (this.immediateMode.shapeMode === constants.TRIANGLES) { + for (i = 0; i < this.immediateMode.vertices.length - 2; i = i + 3) { + this.immediateMode.edges.push([i, i + 1]); + this.immediateMode.edges.push([i + 1, i + 2]); + this.immediateMode.edges.push([i + 2, i]); + } + } else if (this.immediateMode.shapeMode === constants.LINES) { + for (i = 0; i < this.immediateMode.vertices.length - 1; i = i + 2) { + this.immediateMode.edges.push([i, i + 1]); + } + } else { + for (i = 0; i < this.immediateMode.vertices.length - 1; i++) { + this.immediateMode.edges.push([i, i + 1]); + } + } + if (mode === constants.CLOSE) { + this.immediateMode.edges.push([ + this.immediateMode.vertices.length - 1, + 0 + ]); + } + + p5.Geometry.prototype._edgesToVertices.call(this.immediateMode); + this._drawStrokeImmediateMode(); + } + + if (this._doFill && this.immediateMode.shapeMode !== constants.LINES) { + if ( + this.isBezier || + this.isQuadratic || + this.isCurve || + (this.immediateMode.shapeMode === constants.LINE_STRIP && + this.drawMode === constants.FILL && + this.immediateMode._isCoplanar === true) + ) { + this.immediateMode.shapeMode = constants.TRIANGLES; + var contours = [ + new Float32Array(this._vToNArray(this.immediateMode.vertices)) + ]; + + var polyTriangles = this._triangulate(contours); + this.immediateMode.vertices = []; + for ( + var j = 0, polyTriLength = polyTriangles.length; + j < polyTriLength; + j = j + 3 + ) { + this.vertex( + polyTriangles[j], + polyTriangles[j + 1], + polyTriangles[j + 2] + ); + } + } + if (this.immediateMode.vertices.length > 0) { + this._drawFillImmediateMode( + mode, + isCurve, + isBezier, + isQuadratic, + isContour, + shapeKind + ); + } + } + } + //clear out our vertexPositions & colors arrays + //after rendering + this.immediateMode.vertices.length = 0; + this.immediateMode.vertexColors.length = 0; + this.immediateMode.uvCoords.length = 0; + this.isImmediateDrawing = false; + this.isBezier = false; + this.isQuadratic = false; + this.isCurve = false; + this.immediateMode._bezierVertex.length = 0; + this.immediateMode._quadraticVertex.length = 0; + this.immediateMode._curveVertex.length = 0; + this.immediateMode._isCoplanar = true; + this.immediateMode._testIfCoplanar = null; + + return this; + }; + + p5.RendererGL.prototype._drawFillImmediateMode = function( + mode, + isCurve, + isBezier, + isQuadratic, + isContour, + shapeKind + ) { + var gl = this.GL; + var shader = this._getImmediateFillShader(); + this._setFillUniforms(shader); + + // initialize the fill shader's 'aPosition' buffer + if (shader.attributes.aPosition) { + //vertex position Attribute + this._bindBuffer( + this.immediateMode.vertexBuffer, + gl.ARRAY_BUFFER, + this._vToNArray(this.immediateMode.vertices), + Float32Array, + gl.DYNAMIC_DRAW + ); + + shader.enableAttrib(shader.attributes.aPosition, 3); + } + + // initialize the fill shader's 'aVertexColor' buffer + if (this.drawMode === constants.FILL && shader.attributes.aVertexColor) { + this._bindBuffer( + this.immediateMode.colorBuffer, + gl.ARRAY_BUFFER, + this.immediateMode.vertexColors, + Float32Array, + gl.DYNAMIC_DRAW + ); + + shader.enableAttrib(shader.attributes.aVertexColor, 4); + } + + // initialize the fill shader's 'aTexCoord' buffer + if (this.drawMode === constants.TEXTURE && shader.attributes.aTexCoord) { + //texture coordinate Attribute + this._bindBuffer( + this.immediateMode.uvBuffer, + gl.ARRAY_BUFFER, + this.immediateMode.uvCoords, + Float32Array, + gl.DYNAMIC_DRAW + ); + + shader.enableAttrib(shader.attributes.aTexCoord, 2); + } + + //if (true || mode) { + if (this.drawMode === constants.FILL || this.drawMode === constants.TEXTURE) { + switch (this.immediateMode.shapeMode) { + case constants.LINE_STRIP: + case constants.LINES: + this.immediateMode.shapeMode = constants.TRIANGLE_FAN; + break; + } + } else { + switch (this.immediateMode.shapeMode) { + case constants.LINE_STRIP: + case constants.LINES: + this.immediateMode.shapeMode = constants.LINE_LOOP; + break; + } + } + //} + //QUADS & QUAD_STRIP are not supported primitives modes + //in webgl. + if ( + this.immediateMode.shapeMode === constants.QUADS || + this.immediateMode.shapeMode === constants.QUAD_STRIP + ) { + throw new Error( + 'sorry, ' + + this.immediateMode.shapeMode + + ' not yet implemented in webgl mode.' + ); + } else { + this._applyColorBlend(this.curFillColor); + gl.enable(gl.BLEND); + gl.drawArrays( + this.immediateMode.shapeMode, + 0, + this.immediateMode.vertices.length + ); + + this._pixelsState._pixelsDirty = true; + } + // todo / optimizations? leave bound until another shader is set? + shader.unbindShader(); + }; + + p5.RendererGL.prototype._drawStrokeImmediateMode = function() { + var gl = this.GL; + var shader = this._getImmediateStrokeShader(); + this._setStrokeUniforms(shader); + + // initialize the stroke shader's 'aPosition' buffer + if (shader.attributes.aPosition) { + this._bindBuffer( + this.immediateMode.lineVertexBuffer, + gl.ARRAY_BUFFER, + this._flatten(this.immediateMode.lineVertices), + Float32Array, + gl.STATIC_DRAW + ); + + shader.enableAttrib(shader.attributes.aPosition, 3); + } + + // initialize the stroke shader's 'aDirection' buffer + if (shader.attributes.aDirection) { + this._bindBuffer( + this.immediateMode.lineNormalBuffer, + gl.ARRAY_BUFFER, + this._flatten(this.immediateMode.lineNormals), + Float32Array, + gl.STATIC_DRAW + ); + + shader.enableAttrib(shader.attributes.aDirection, 4); + } + + this._applyColorBlend(this.curStrokeColor); + gl.drawArrays(gl.TRIANGLES, 0, this.immediateMode.lineVertices.length); + + this._pixelsState._pixelsDirty = true; + + shader.unbindShader(); + }; + + module.exports = p5.RendererGL; + }, + { '../core/constants': 18, '../core/main': 24 } + ], + 74: [ + function(_dereq_, module, exports) { + //Retained Mode. The default mode for rendering 3D primitives + //in WEBGL. + 'use strict'; + + var p5 = _dereq_('../core/main'); + _dereq_('./p5.RendererGL'); + + // a render buffer definition + function BufferDef(size, src, dst, attr, map) { + this.size = size; // the number of FLOATs in each vertex + this.src = src; // the name of the model's source array + this.dst = dst; // the name of the geometry's buffer + this.attr = attr; // the name of the vertex attribute + this.map = map; // optional, a transformation function to apply to src + } + + var _flatten = p5.RendererGL.prototype._flatten; + var _vToNArray = p5.RendererGL.prototype._vToNArray; + + var strokeBuffers = [ + new BufferDef(3, 'lineVertices', 'lineVertexBuffer', 'aPosition', _flatten), + new BufferDef(4, 'lineNormals', 'lineNormalBuffer', 'aDirection', _flatten) + ]; + + var fillBuffers = [ + new BufferDef(3, 'vertices', 'vertexBuffer', 'aPosition', _vToNArray), + new BufferDef(3, 'vertexNormals', 'normalBuffer', 'aNormal', _vToNArray), + new BufferDef(4, 'vertexColors', 'colorBuffer', 'aMaterialColor'), + new BufferDef(3, 'vertexAmbients', 'ambientBuffer', 'aAmbientColor'), + //new BufferDef(3, 'vertexSpeculars', 'specularBuffer', 'aSpecularColor'), + new BufferDef(2, 'uvs', 'uvBuffer', 'aTexCoord', _flatten) + ]; + + p5.RendererGL._textBuffers = [ + new BufferDef(3, 'vertices', 'vertexBuffer', 'aPosition', _vToNArray), + new BufferDef(2, 'uvs', 'uvBuffer', 'aTexCoord', _flatten) + ]; + + var hashCount = 0; + /** + * _initBufferDefaults + * @private + * @description initializes buffer defaults. runs each time a new geometry is + * registered + * @param {String} gId key of the geometry object + * @returns {Object} a new buffer object + */ + p5.RendererGL.prototype._initBufferDefaults = function(gId) { + this._freeBuffers(gId); + + //@TODO remove this limit on hashes in gHash + hashCount++; + if (hashCount > 1000) { + var key = Object.keys(this.gHash)[0]; + delete this.gHash[key]; + hashCount--; + } + + //create a new entry in our gHash + return (this.gHash[gId] = {}); + }; + + p5.RendererGL.prototype._freeBuffers = function(gId) { + var buffers = this.gHash[gId]; + if (!buffers) { + return; + } + + delete this.gHash[gId]; + hashCount--; + + var gl = this.GL; + if (buffers.indexBuffer) { + gl.deleteBuffer(buffers.indexBuffer); + } + + function freeBuffers(defs) { + for (var i = 0; i < defs.length; i++) { + var def = defs[i]; + if (buffers[def.dst]) { + gl.deleteBuffer(buffers[def.dst]); + buffers[def.dst] = null; + } + } + } + + // free all the buffers + freeBuffers(strokeBuffers); + freeBuffers(fillBuffers); + }; + + p5.RendererGL.prototype._prepareBuffers = function(buffers, shader, defs) { + var model = buffers.model; + var attributes = shader.attributes; + var gl = this.GL; + + // loop through each of the buffer definitions + for (var i = 0; i < defs.length; i++) { + var def = defs[i]; + + var attr = attributes[def.attr]; + if (!attr) continue; + + var buffer = buffers[def.dst]; + + // check if the model has the appropriate source array + var src = model[def.src]; + if (src) { + // check if we need to create the GL buffer + var createBuffer = !buffer; + if (createBuffer) { + // create and remember the buffer + buffers[def.dst] = buffer = gl.createBuffer(); + } + // bind the buffer + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + + // check if we need to fill the buffer with data + if (createBuffer || model.dirtyFlags[def.src] !== false) { + var map = def.map; + // get the values from the model, possibly transformed + var values = map ? map(src) : src; + + // fill the buffer with the values + this._bindBuffer(buffer, gl.ARRAY_BUFFER, values); + + // mark the model's source array as clean + model.dirtyFlags[def.src] = false; + } + // enable the attribute + shader.enableAttrib(attr, def.size); + } else { + if (buffer) { + // remove the unused buffer + gl.deleteBuffer(buffer); + buffers[def.dst] = null; + } + // disable the vertex + gl.disableVertexAttribArray(attr.index); + } + } + }; + + /** + * creates a buffers object that holds the WebGL render buffers + * for a geometry. + * @private + * @param {String} gId key of the geometry object + * @param {p5.Geometry} model contains geometry data + */ + p5.RendererGL.prototype.createBuffers = function(gId, model) { + var gl = this.GL; + //initialize the gl buffers for our geom groups + var buffers = this._initBufferDefaults(gId); + buffers.model = model; + + var indexBuffer = buffers.indexBuffer; + + if (model.faces.length) { + // allocate space for faces + if (!indexBuffer) indexBuffer = buffers.indexBuffer = gl.createBuffer(); + var vals = p5.RendererGL.prototype._flatten(model.faces); + this._bindBuffer(indexBuffer, gl.ELEMENT_ARRAY_BUFFER, vals, Uint16Array); + + // the vertex count is based on the number of faces + buffers.vertexCount = model.faces.length * 3; + } else { + // the index buffer is unused, remove it + if (indexBuffer) { + gl.deleteBuffer(indexBuffer); + buffers.indexBuffer = null; + } + // the vertex count comes directly from the model + buffers.vertexCount = model.vertices ? model.vertices.length : 0; + } + + buffers.lineVertexCount = model.lineVertices ? model.lineVertices.length : 0; + + return buffers; + }; + + /** + * Draws buffers given a geometry key ID + * @private + * @param {String} gId ID in our geom hash + * @chainable + */ + p5.RendererGL.prototype.drawBuffers = function(gId) { + var gl = this.GL; + var buffers = this.gHash[gId]; + + if (this._doStroke && buffers.lineVertexCount > 0) { + var strokeShader = this._getRetainedStrokeShader(); + this._setStrokeUniforms(strokeShader); + this._prepareBuffers(buffers, strokeShader, strokeBuffers); + this._applyColorBlend(this.curStrokeColor); + this._drawArrays(gl.TRIANGLES, gId); + strokeShader.unbindShader(); + } + + if (this._doFill) { + var fillShader = this._getRetainedFillShader(); + this._setFillUniforms(fillShader); + this._prepareBuffers(buffers, fillShader, fillBuffers); + if (buffers.indexBuffer) { + //vertex index buffer + this._bindBuffer(buffers.indexBuffer, gl.ELEMENT_ARRAY_BUFFER); + } + this._applyColorBlend(this.curFillColor); + this._drawElements(gl.TRIANGLES, gId); + fillShader.unbindShader(); + } + return this; + }; + + /** + * Calls drawBuffers() with a scaled model/view matrix. + * + * This is used by various 3d primitive methods (in primitives.js, eg. plane, + * box, torus, etc...) to allow caching of un-scaled geometries. Those + * geometries are generally created with unit-length dimensions, cached as + * such, and then scaled appropriately in this method prior to rendering. + * + * @private + * @method drawBuffersScaled + * @param {String} gId ID in our geom hash + * @param {Number} scaleX the amount to scale in the X direction + * @param {Number} scaleY the amount to scale in the Y direction + * @param {Number} scaleZ the amount to scale in the Z direction + */ + p5.RendererGL.prototype.drawBuffersScaled = function( + gId, + scaleX, + scaleY, + scaleZ + ) { + var uMVMatrix = this.uMVMatrix.copy(); + try { + this.uMVMatrix.scale(scaleX, scaleY, scaleZ); + this.drawBuffers(gId); + } finally { + this.uMVMatrix = uMVMatrix; + } + }; + + p5.RendererGL.prototype._drawArrays = function(drawMode, gId) { + this.GL.drawArrays(drawMode, 0, this.gHash[gId].lineVertexCount); + this._pixelsState._pixelsDirty = true; + return this; + }; + + p5.RendererGL.prototype._drawElements = function(drawMode, gId) { + var buffers = this.gHash[gId]; + var gl = this.GL; + // render the fill + if (buffers.indexBuffer) { + // we're drawing faces + gl.drawElements(gl.TRIANGLES, buffers.vertexCount, gl.UNSIGNED_SHORT, 0); + } else { + // drawing vertices + gl.drawArrays(drawMode || gl.TRIANGLES, 0, buffers.vertexCount); + } + this._pixelsState._pixelsDirty = true; + }; + + p5.RendererGL.prototype._drawPoints = function(vertices, vertexBuffer) { + var gl = this.GL; + var pointShader = this._getImmediatePointShader(); + this._setPointUniforms(pointShader); + + this._bindBuffer( + vertexBuffer, + gl.ARRAY_BUFFER, + this._vToNArray(vertices), + Float32Array, + gl.STATIC_DRAW + ); + + pointShader.enableAttrib(pointShader.attributes.aPosition, 3); + + gl.drawArrays(gl.Points, 0, vertices.length); + + pointShader.unbindShader(); + this._pixelsState._pixelsDirty = true; + }; + + module.exports = p5.RendererGL; + }, + { '../core/main': 24, './p5.RendererGL': 75 } + ], + 75: [ + function(_dereq_, module, exports) { + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + var libtess = _dereq_('libtess'); + _dereq_('./p5.Shader'); + _dereq_('./p5.Camera'); + _dereq_('../core/p5.Renderer'); + _dereq_('./p5.Matrix'); + + var lightingShader = + 'precision mediump float;\n\nuniform mat4 uViewMatrix;\n\nuniform bool uUseLighting;\n\nuniform int uAmbientLightCount;\nuniform vec3 uAmbientColor[8];\n\nuniform int uDirectionalLightCount;\nuniform vec3 uLightingDirection[8];\nuniform vec3 uDirectionalColor[8];\n\nuniform int uPointLightCount;\nuniform vec3 uPointLightLocation[8];\nuniform vec3 uPointLightColor[8];\n\nuniform bool uSpecular;\nuniform float uShininess;\n\nuniform float uConstantAttenuation;\nuniform float uLinearAttenuation;\nuniform float uQuadraticAttenuation;\n\nconst float specularFactor = 2.0;\nconst float diffuseFactor = 0.73;\n\nstruct LightResult {\n float specular;\n float diffuse;\n};\n\nfloat _phongSpecular(\n vec3 lightDirection,\n vec3 viewDirection,\n vec3 surfaceNormal,\n float shininess) {\n\n vec3 R = reflect(lightDirection, surfaceNormal);\n return pow(max(0.0, dot(R, viewDirection)), shininess);\n}\n\nfloat _lambertDiffuse(vec3 lightDirection, vec3 surfaceNormal) {\n return max(0.0, dot(-lightDirection, surfaceNormal));\n}\n\nLightResult _light(vec3 viewDirection, vec3 normal, vec3 lightVector) {\n\n vec3 lightDir = normalize(lightVector);\n\n //compute our diffuse & specular terms\n LightResult lr;\n if (uSpecular)\n lr.specular = _phongSpecular(lightDir, viewDirection, normal, uShininess);\n lr.diffuse = _lambertDiffuse(lightDir, normal);\n return lr;\n}\n\nvoid totalLight(\n vec3 modelPosition,\n vec3 normal,\n out vec3 totalDiffuse,\n out vec3 totalSpecular\n) {\n\n totalSpecular = vec3(0.0);\n\n if (!uUseLighting) {\n totalDiffuse = vec3(1.0);\n return;\n }\n\n totalDiffuse = vec3(0.0);\n\n vec3 viewDirection = normalize(-modelPosition);\n\n for (int j = 0; j < 8; j++) {\n if (j < uDirectionalLightCount) {\n vec3 lightVector = (uViewMatrix * vec4(uLightingDirection[j], 0.0)).xyz;\n vec3 lightColor = uDirectionalColor[j];\n LightResult result = _light(viewDirection, normal, lightVector);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor;\n }\n\n if (j < uPointLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uPointLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n //calculate attenuation\n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n vec3 lightColor = lightFalloff * uPointLightColor[j];\n\n LightResult result = _light(viewDirection, normal, lightVector);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor;\n }\n }\n\n totalDiffuse *= diffuseFactor;\n totalSpecular *= specularFactor;\n}\n'; + + var defaultShaders = { + immediateVert: + 'attribute vec3 aPosition;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uResolution;\nuniform float uPointSize;\n\nvarying vec4 vColor;\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vColor = aVertexColor;\n gl_PointSize = uPointSize;\n}\n', + vertexColorVert: + 'attribute vec3 aPosition;\nattribute vec4 aVertexColor;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nvarying vec4 vColor;\n\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vColor = aVertexColor;\n}\n', + vertexColorFrag: + 'precision mediump float;\nvarying vec4 vColor;\nvoid main(void) {\n gl_FragColor = vColor;\n}', + normalVert: + 'attribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nvarying vec3 vVertexNormal;\nvarying highp vec2 vVertTexCoord;\n\nvoid main(void) {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vVertexNormal = normalize(vec3( uNormalMatrix * aNormal ));\n vVertTexCoord = aTexCoord;\n}\n', + normalFrag: + 'precision mediump float;\nvarying vec3 vVertexNormal;\nvoid main(void) {\n gl_FragColor = vec4(vVertexNormal, 1.0);\n}', + basicFrag: + 'precision mediump float;\nuniform vec4 uMaterialColor;\nvoid main(void) {\n gl_FragColor = uMaterialColor;\n}', + lightVert: + lightingShader + + '// include lighting.glgl\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nvarying highp vec2 vVertTexCoord;\nvarying vec3 vDiffuseColor;\nvarying vec3 vSpecularColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * viewModelPosition;\n\n vec3 vertexNormal = normalize(uNormalMatrix * aNormal);\n vVertTexCoord = aTexCoord;\n\n totalLight(viewModelPosition.xyz, vertexNormal, vDiffuseColor, vSpecularColor);\n\n for (int i = 0; i < 8; i++) {\n if (i < uAmbientLightCount) {\n vDiffuseColor += uAmbientColor[i];\n }\n }\n}\n', + lightTextureFrag: + 'precision mediump float;\n\nuniform vec4 uMaterialColor;\nuniform vec4 uTint;\nuniform sampler2D uSampler;\nuniform bool isTexture;\n\nvarying highp vec2 vVertTexCoord;\nvarying vec3 vDiffuseColor;\nvarying vec3 vSpecularColor;\n\nvoid main(void) {\n gl_FragColor = isTexture ? texture2D(uSampler, vVertTexCoord) * (uTint / vec4(255, 255, 255, 255)) : uMaterialColor;\n gl_FragColor.rgb = gl_FragColor.rgb * vDiffuseColor + vSpecularColor;\n}', + phongVert: + 'precision mediump float;\nprecision mediump int;\n\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nuniform vec3 uAmbientColor[8];\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\nuniform int uAmbientLightCount;\n\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\nvarying vec3 vViewPosition;\nvarying vec3 vAmbientColor;\n\nvoid main(void) {\n\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);\n\n // Pass varyings to fragment shader\n vViewPosition = viewModelPosition.xyz;\n gl_Position = uProjectionMatrix * viewModelPosition; \n\n vNormal = uNormalMatrix * aNormal;\n vTexCoord = aTexCoord;\n\n // TODO: this should be a uniform\n vAmbientColor = vec3(0.0);\n for (int i = 0; i < 8; i++) {\n if (i < uAmbientLightCount) {\n vAmbientColor += uAmbientColor[i];\n }\n }\n}\n', + phongFrag: + lightingShader + + '// include lighting.glgl\n\nuniform vec4 uMaterialColor;\nuniform sampler2D uSampler;\nuniform bool isTexture;\n\nvarying vec3 vNormal;\nvarying vec2 vTexCoord;\nvarying vec3 vViewPosition;\nvarying vec3 vAmbientColor;\n\nvoid main(void) {\n\n vec3 diffuse;\n vec3 specular;\n totalLight(vViewPosition, normalize(vNormal), diffuse, specular);\n\n gl_FragColor = isTexture ? texture2D(uSampler, vTexCoord) : uMaterialColor;\n gl_FragColor.rgb = gl_FragColor.rgb * (diffuse + vAmbientColor) + specular;\n}', + fontVert: + "precision mediump float;\n\nattribute vec3 aPosition;\nattribute vec2 aTexCoord;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nuniform vec4 uGlyphRect;\nuniform float uGlyphOffset;\n\nvarying vec2 vTexCoord;\nvarying float w;\n\nvoid main() {\n vec4 positionVec4 = vec4(aPosition, 1.0);\n\n // scale by the size of the glyph's rectangle\n positionVec4.xy *= uGlyphRect.zw - uGlyphRect.xy;\n\n // move to the corner of the glyph\n positionVec4.xy += uGlyphRect.xy;\n\n // move to the letter's line offset\n positionVec4.x += uGlyphOffset;\n \n gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n vTexCoord = aTexCoord;\n w = gl_Position.w;\n}\n", + fontFrag: + "#extension GL_OES_standard_derivatives : enable\nprecision mediump float;\n\n#if 0\n // simulate integer math using floats\n\t#define int float\n\t#define ivec2 vec2\n\t#define INT(x) float(x)\n\n\tint ifloor(float v) { return floor(v); }\n\tivec2 ifloor(vec2 v) { return floor(v); }\n\n#else\n // use native integer math\n\tprecision highp int;\n\t#define INT(x) x\n\n\tint ifloor(float v) { return int(v); }\n\tint ifloor(int v) { return v; }\n\tivec2 ifloor(vec2 v) { return ivec2(v); }\n\n#endif\n\nuniform sampler2D uSamplerStrokes;\nuniform sampler2D uSamplerRowStrokes;\nuniform sampler2D uSamplerRows;\nuniform sampler2D uSamplerColStrokes;\nuniform sampler2D uSamplerCols;\n\nuniform ivec2 uStrokeImageSize;\nuniform ivec2 uCellsImageSize;\nuniform ivec2 uGridImageSize;\n\nuniform ivec2 uGridOffset;\nuniform ivec2 uGridSize;\nuniform vec4 uMaterialColor;\n\nvarying vec2 vTexCoord;\n\n// some helper functions\nint round(float v) { return ifloor(v + 0.5); }\nivec2 round(vec2 v) { return ifloor(v + 0.5); }\nfloat saturate(float v) { return clamp(v, 0.0, 1.0); }\nvec2 saturate(vec2 v) { return clamp(v, 0.0, 1.0); }\n\nint mul(float v1, int v2) {\n return ifloor(v1 * float(v2));\n}\n\nivec2 mul(vec2 v1, ivec2 v2) {\n return ifloor(v1 * vec2(v2) + 0.5);\n}\n\n// unpack a 16-bit integer from a float vec2\nint getInt16(vec2 v) {\n ivec2 iv = round(v * 255.0);\n return iv.x * INT(128) + iv.y;\n}\n\nvec2 pixelScale;\nvec2 coverage = vec2(0.0);\nvec2 weight = vec2(0.5);\nconst float minDistance = 1.0/8192.0;\nconst float hardness = 1.05; // amount of antialias\n\n// the maximum number of curves in a glyph\nconst int N = INT(250);\n\n// retrieves an indexed pixel from a sampler\nvec4 getTexel(sampler2D sampler, int pos, ivec2 size) {\n int width = size.x;\n int y = ifloor(pos / width);\n int x = pos - y * width; // pos % width\n\n return texture2D(sampler, (vec2(x, y) + 0.5) / vec2(size));\n}\n\nvoid calulateCrossings(vec2 p0, vec2 p1, vec2 p2, out vec2 C1, out vec2 C2) {\n\n // get the coefficients of the quadratic in t\n vec2 a = p0 - p1 * 2.0 + p2;\n vec2 b = p0 - p1;\n vec2 c = p0 - vTexCoord;\n\n // found out which values of 't' it crosses the axes\n vec2 surd = sqrt(max(vec2(0.0), b * b - a * c));\n vec2 t1 = ((b - surd) / a).yx;\n vec2 t2 = ((b + surd) / a).yx;\n\n // approximate straight lines to avoid rounding errors\n if (abs(a.y) < 0.001)\n t1.x = t2.x = c.y / (2.0 * b.y);\n\n if (abs(a.x) < 0.001)\n t1.y = t2.y = c.x / (2.0 * b.x);\n\n // plug into quadratic formula to find the corrdinates of the crossings\n C1 = ((a * t1 - b * 2.0) * t1 + c) * pixelScale;\n C2 = ((a * t2 - b * 2.0) * t2 + c) * pixelScale;\n}\n\nvoid coverageX(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n // determine on which side of the x-axis the points lie\n bool y0 = p0.y > vTexCoord.y;\n bool y1 = p1.y > vTexCoord.y;\n bool y2 = p2.y > vTexCoord.y;\n\n // could web be under the curve (after t1)?\n if (y1 ? !y2 : y0) {\n // add the coverage for t1\n coverage.x += saturate(C1.x + 0.5);\n // calculate the anti-aliasing for t1\n weight.x = min(weight.x, abs(C1.x));\n }\n\n // are we outside the curve (after t2)?\n if (y1 ? !y0 : y2) {\n // subtract the coverage for t2\n coverage.x -= saturate(C2.x + 0.5);\n // calculate the anti-aliasing for t2\n weight.x = min(weight.x, abs(C2.x));\n }\n}\n\n// this is essentially the same as coverageX, but with the axes swapped\nvoid coverageY(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n bool x0 = p0.x > vTexCoord.x;\n bool x1 = p1.x > vTexCoord.x;\n bool x2 = p2.x > vTexCoord.x;\n\n if (x1 ? !x2 : x0) {\n coverage.y -= saturate(C1.y + 0.5);\n weight.y = min(weight.y, abs(C1.y));\n }\n\n if (x1 ? !x0 : x2) {\n coverage.y += saturate(C2.y + 0.5);\n weight.y = min(weight.y, abs(C2.y));\n }\n}\n\nvoid main() {\n\n // calculate the pixel scale based on screen-coordinates\n pixelScale = hardness / fwidth(vTexCoord);\n\n // which grid cell is this pixel in?\n ivec2 gridCoord = ifloor(vTexCoord * vec2(uGridSize));\n\n // intersect curves in this row\n {\n // the index into the row info bitmap\n int rowIndex = gridCoord.y + uGridOffset.y;\n // fetch the info texel\n vec4 rowInfo = getTexel(uSamplerRows, rowIndex, uGridImageSize);\n // unpack the rowInfo\n int rowStrokeIndex = getInt16(rowInfo.xy);\n int rowStrokeCount = getInt16(rowInfo.zw);\n\n for (int iRowStroke = INT(0); iRowStroke < N; iRowStroke++) {\n if (iRowStroke >= rowStrokeCount)\n break;\n\n // each stroke is made up of 3 points: the start and control point\n // and the start of the next curve.\n // fetch the indices of this pair of strokes:\n vec4 strokeIndices = getTexel(uSamplerRowStrokes, rowStrokeIndex++, uCellsImageSize);\n\n // unpack the stroke index\n int strokePos = getInt16(strokeIndices.xy);\n\n // fetch the two strokes\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n\n // calculate the coverage\n coverageX(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n // intersect curves in this column\n {\n int colIndex = gridCoord.x + uGridOffset.x;\n vec4 colInfo = getTexel(uSamplerCols, colIndex, uGridImageSize);\n int colStrokeIndex = getInt16(colInfo.xy);\n int colStrokeCount = getInt16(colInfo.zw);\n \n for (int iColStroke = INT(0); iColStroke < N; iColStroke++) {\n if (iColStroke >= colStrokeCount)\n break;\n\n vec4 strokeIndices = getTexel(uSamplerColStrokes, colStrokeIndex++, uCellsImageSize);\n\n int strokePos = getInt16(strokeIndices.xy);\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n coverageY(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n weight = saturate(1.0 - weight * 2.0);\n float distance = max(weight.x + weight.y, minDistance); // manhattan approx.\n float antialias = abs(dot(coverage, weight) / distance);\n float cover = min(abs(coverage.x), abs(coverage.y));\n gl_FragColor = uMaterialColor;\n gl_FragColor.a *= saturate(max(antialias, cover));\n}", + lineVert: + "/*\n Part of the Processing project - http://processing.org\n Copyright (c) 2012-15 The Processing Foundation\n Copyright (c) 2004-12 Ben Fry and Casey Reas\n Copyright (c) 2001-04 Massachusetts Institute of Technology\n This library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation, version 2.1.\n This library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n You should have received a copy of the GNU Lesser General\n Public License along with this library; if not, write to the\n Free Software Foundation, Inc., 59 Temple Place, Suite 330,\n Boston, MA 02111-1307 USA\n*/\n\n#define PROCESSING_LINE_SHADER\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uStrokeWeight;\n\nuniform vec4 uViewport;\n\nattribute vec4 aPosition;\nattribute vec4 aDirection;\n \nvoid main() {\n // using a scale <1 moves the lines towards the camera\n // in order to prevent popping effects due to half of\n // the line disappearing behind the geometry faces.\n vec3 scale = vec3(0.9995);\n\n vec4 posp = uModelViewMatrix * aPosition;\n vec4 posq = uModelViewMatrix * (aPosition + vec4(aDirection.xyz, 0));\n\n // Moving vertices slightly toward the camera\n // to avoid depth-fighting with the fill triangles.\n // Discussed here:\n // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 \n posp.xyz = posp.xyz * scale;\n posq.xyz = posq.xyz * scale;\n\n vec4 p = uProjectionMatrix * posp;\n vec4 q = uProjectionMatrix * posq;\n\n // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])\n // screen_p = (p.xy/p.w + <1,1>) * 0.5 * uViewport.zw\n\n // prevent division by W by transforming the tangent formula (div by 0 causes\n // the line to disappear, see https://github.com/processing/processing/issues/5183)\n // t = screen_q - screen_p\n //\n // tangent is normalized and we don't care which aDirection it points to (+-)\n // t = +- normalize( screen_q - screen_p )\n // t = +- normalize( (q.xy/q.w+<1,1>)*0.5*uViewport.zw - (p.xy/p.w+<1,1>)*0.5*uViewport.zw )\n //\n // extract common factor, <1,1> - <1,1> cancels out\n // t = +- normalize( (q.xy/q.w - p.xy/p.w) * 0.5 * uViewport.zw )\n //\n // convert to common divisor\n // t = +- normalize( ((q.xy*p.w - p.xy*q.w) / (p.w*q.w)) * 0.5 * uViewport.zw )\n //\n // remove the common scalar divisor/factor, not needed due to normalize and +-\n // (keep uViewport - can't remove because it has different components for x and y\n // and corrects for aspect ratio, see https://github.com/processing/processing/issues/5181)\n // t = +- normalize( (q.xy*p.w - p.xy*q.w) * uViewport.zw )\n\n vec2 tangent = normalize((q.xy*p.w - p.xy*q.w) * uViewport.zw);\n\n // flip tangent to normal (it's already normalized)\n vec2 normal = vec2(-tangent.y, tangent.x);\n\n float thickness = aDirection.w * uStrokeWeight;\n vec2 offset = normal * thickness / 2.0;\n\n // Perspective ---\n // convert from world to clip by multiplying with projection scaling factor\n // to get the right thickness (see https://github.com/processing/processing/issues/5182)\n // invert Y, projections in Processing invert Y\n vec2 perspScale = (uProjectionMatrix * vec4(1, -1, 0, 0)).xy;\n\n // No Perspective ---\n // multiply by W (to cancel out division by W later in the pipeline) and\n // convert from screen to clip (derived from clip to screen above)\n vec2 noPerspScale = p.w / (0.5 * uViewport.zw);\n\n //gl_Position.xy = p.xy + offset.xy * mix(noPerspScale, perspScale, float(perspective > 0));\n gl_Position.xy = p.xy + offset.xy * perspScale;\n gl_Position.zw = p.zw;\n}\n", + lineFrag: + 'precision mediump float;\nprecision mediump int;\n\nuniform vec4 uMaterialColor;\n\nvoid main() {\n gl_FragColor = uMaterialColor;\n}', + pointVert: + 'attribute vec3 aPosition;\nuniform float uPointSize;\nvarying float vStrokeWeight;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nvoid main() {\n\tvec4 positionVec4 = vec4(aPosition, 1.0);\n\tgl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;\n\tgl_PointSize = uPointSize;\n\tvStrokeWeight = uPointSize;\n}', + pointFrag: + 'precision mediump float;\nprecision mediump int;\nuniform vec4 uMaterialColor;\nvarying float vStrokeWeight;\n\nvoid main(){\n\tfloat mask = 0.0;\n\n\t// make a circular mask using the gl_PointCoord (goes from 0 - 1 on a point)\n // might be able to get a nicer edge on big strokeweights with smoothstep but slightly less performant\n\n\tmask = step(0.98, length(gl_PointCoord * 2.0 - 1.0));\n\n\t// if strokeWeight is 1 or less lets just draw a square\n\t// this prevents weird artifacting from carving circles when our points are really small\n\t// if strokeWeight is larger than 1, we just use it as is\n\n\tmask = mix(0.0, mask, clamp(floor(vStrokeWeight - 0.5),0.0,1.0));\n\n\t// throw away the borders of the mask\n // otherwise we get weird alpha blending issues\n\n\tif(mask > 0.98){\n discard;\n \t}\n\n \tgl_FragColor = vec4(uMaterialColor.rgb * (1.0 - mask), uMaterialColor.a) ;\n}' + }; + + /** + * 3D graphics class + * @private + * @class p5.RendererGL + * @constructor + * @extends p5.Renderer + * @todo extend class to include public method for offscreen + * rendering (FBO). + * + */ + p5.RendererGL = function(elt, pInst, isMainCanvas, attr) { + p5.Renderer.call(this, elt, pInst, isMainCanvas); + this._setAttributeDefaults(pInst); + this._initContext(); + this.isP3D = true; //lets us know we're in 3d mode + this.GL = this.drawingContext; + + // lights + this._enableLighting = false; + + this.ambientLightColors = []; + this.directionalLightDirections = []; + this.directionalLightColors = []; + + this.pointLightPositions = []; + this.pointLightColors = []; + + this.drawMode = constants.FILL; + this.curFillColor = [1, 1, 1, 1]; + this.curStrokeColor = [0, 0, 0, 1]; + this.curBlendMode = constants.BLEND; + this.blendExt = this.GL.getExtension('EXT_blend_minmax'); + + this._useSpecularMaterial = false; + this._useNormalMaterial = false; + this._useShininess = 1; + + this._tint = [255, 255, 255, 255]; + + // lightFalloff variables + this.constantAttenuation = 1; + this.linearAttenuation = 0; + this.quadraticAttenuation = 0; + + /** + * model view, projection, & normal + * matrices + */ + this.uMVMatrix = new p5.Matrix(); + this.uPMatrix = new p5.Matrix(); + this.uNMatrix = new p5.Matrix('mat3'); + + // Camera + this._curCamera = new p5.Camera(this); + this._curCamera._computeCameraDefaultSettings(); + this._curCamera._setDefaultCamera(); + + //Geometry & Material hashes + this.gHash = {}; + + this._defaultLightShader = undefined; + this._defaultImmediateModeShader = undefined; + this._defaultNormalShader = undefined; + this._defaultColorShader = undefined; + this._defaultPointShader = undefined; + + this._pointVertexBuffer = this.GL.createBuffer(); + + this.userFillShader = undefined; + this.userStrokeShader = undefined; + this.userPointShader = undefined; + + //Imediate Mode + //default drawing is done in Retained Mode + this.isImmediateDrawing = false; + this.immediateMode = {}; + + this.pointSize = 5.0; //default point size + this.curStrokeWeight = 1; + + // array of textures created in this gl context via this.getTexture(src) + this.textures = []; + + this.textureMode = constants.IMAGE; + // default wrap settings + this.textureWrapX = constants.CLAMP; + this.textureWrapY = constants.CLAMP; + this._tex = null; + this._curveTightness = 6; + + // lookUpTable for coefficients needed to be calculated for bezierVertex, same are used for curveVertex + this._lookUpTableBezier = []; + // lookUpTable for coefficients needed to be calculated for quadraticVertex + this._lookUpTableQuadratic = []; + + // current curveDetail in the Bezier lookUpTable + this._lutBezierDetail = 0; + // current curveDetail in the Quadratic lookUpTable + this._lutQuadraticDetail = 0; + + this._tessy = this._initTessy(); + + this.fontInfos = {}; + + return this; + }; + + p5.RendererGL.prototype = Object.create(p5.Renderer.prototype); + + ////////////////////////////////////////////// + // Setting + ////////////////////////////////////////////// + + p5.RendererGL.prototype._setAttributeDefaults = function(pInst) { + var defaults = { + alpha: true, + depth: true, + stencil: true, + antialias: false, + premultipliedAlpha: false, + preserveDrawingBuffer: true, + perPixelLighting: false + }; + + if (pInst._glAttributes === null) { + pInst._glAttributes = defaults; + } else { + pInst._glAttributes = Object.assign(defaults, pInst._glAttributes); + } + return; + }; + + p5.RendererGL.prototype._initContext = function() { + try { + this.drawingContext = + this.canvas.getContext('webgl', this._pInst._glAttributes) || + this.canvas.getContext('experimental-webgl', this._pInst._glAttributes); + if (this.drawingContext === null) { + throw new Error('Error creating webgl context'); + } else { + var gl = this.drawingContext; + gl.enable(gl.DEPTH_TEST); + gl.depthFunc(gl.LEQUAL); + gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); + this._viewport = this.drawingContext.getParameter( + this.drawingContext.VIEWPORT + ); + } + } catch (er) { + throw er; + } + }; + + //This is helper function to reset the context anytime the attributes + //are changed with setAttributes() + + p5.RendererGL.prototype._resetContext = function(options, callback) { + var w = this.width; + var h = this.height; + var defaultId = this.canvas.id; + var isPGraphics = this._pInst instanceof p5.Graphics; + + if (isPGraphics) { + var pg = this._pInst; + pg.canvas.parentNode.removeChild(pg.canvas); + pg.canvas = document.createElement('canvas'); + var node = pg._pInst._userNode || document.body; + node.appendChild(pg.canvas); + p5.Element.call(pg, pg.canvas, pg._pInst); + pg.width = w; + pg.height = h; + } else { + var c = this.canvas; + if (c) { + c.parentNode.removeChild(c); + } + c = document.createElement('canvas'); + c.id = defaultId; + if (this._pInst._userNode) { + this._pInst._userNode.appendChild(c); + } else { + document.body.appendChild(c); + } + this._pInst.canvas = c; + } + + var renderer = new p5.RendererGL(this._pInst.canvas, this._pInst, !isPGraphics); + + this._pInst._setProperty('_renderer', renderer); + renderer.resize(w, h); + renderer._applyDefaults(); + + if (!isPGraphics) { + this._pInst._elements.push(renderer); + } + + if (typeof callback === 'function') { + //setTimeout with 0 forces the task to the back of the queue, this ensures that + //we finish switching out the renderer + setTimeout(function() { + callback.apply(window._renderer, options); + }, 0); + } + }; + /** + * @module Rendering + * @submodule Rendering + * @for p5 + */ + /** + * Set attributes for the WebGL Drawing context. + * This is a way of adjusting how the WebGL + * renderer works to fine-tune the display and performance. + *

+ * Note that this will reinitialize the drawing context + * if called after the WebGL canvas is made. + *

+ * If an object is passed as the parameter, all attributes + * not declared in the object will be set to defaults. + *

+ * The available attributes are: + *
+ * alpha - indicates if the canvas contains an alpha buffer + * default is true + *

+ * depth - indicates whether the drawing buffer has a depth buffer + * of at least 16 bits - default is true + *

+ * stencil - indicates whether the drawing buffer has a stencil buffer + * of at least 8 bits + *

+ * antialias - indicates whether or not to perform anti-aliasing + * default is false + *

+ * premultipliedAlpha - indicates that the page compositor will assume + * the drawing buffer contains colors with pre-multiplied alpha + * default is false + *

+ * preserveDrawingBuffer - if true the buffers will not be cleared and + * and will preserve their values until cleared or overwritten by author + * (note that p5 clears automatically on draw loop) + * default is true + *

+ * perPixelLighting - if true, per-pixel lighting will be used in the + * lighting shader. + * default is false + *

+ * @method setAttributes + * @for p5 + * @param {String} key Name of attribute + * @param {Boolean} value New value of named attribute + * @example + *
+ * + * function setup() { + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(255); + * push(); + * rotateZ(frameCount * 0.02); + * rotateX(frameCount * 0.02); + * rotateY(frameCount * 0.02); + * fill(0, 0, 0); + * box(50); + * pop(); + * } + * + *
+ *
+ * Now with the antialias attribute set to true. + *
+ *
+ * + * function setup() { + * setAttributes('antialias', true); + * createCanvas(100, 100, WEBGL); + * } + * + * function draw() { + * background(255); + * push(); + * rotateZ(frameCount * 0.02); + * rotateX(frameCount * 0.02); + * rotateY(frameCount * 0.02); + * fill(0, 0, 0); + * box(50); + * pop(); + * } + * + *
+ * + *
+ * + * // press the mouse button to enable perPixelLighting + * function setup() { + * createCanvas(100, 100, WEBGL); + * noStroke(); + * fill(255); + * } + * + * var lights = [ + * { c: '#f00', t: 1.12, p: 1.91, r: 0.2 }, + * { c: '#0f0', t: 1.21, p: 1.31, r: 0.2 }, + * { c: '#00f', t: 1.37, p: 1.57, r: 0.2 }, + * { c: '#ff0', t: 1.12, p: 1.91, r: 0.7 }, + * { c: '#0ff', t: 1.21, p: 1.31, r: 0.7 }, + * { c: '#f0f', t: 1.37, p: 1.57, r: 0.7 } + * ]; + * + * function draw() { + * var t = millis() / 1000 + 1000; + * background(0); + * directionalLight(color('#222'), 1, 1, 1); + * + * for (var i = 0; i < lights.length; i++) { + * var light = lights[i]; + * pointLight( + * color(light.c), + * p5.Vector.fromAngles(t * light.t, t * light.p, width * light.r) + * ); + * } + * + * specularMaterial(255); + * sphere(width * 0.1); + * + * rotateX(t * 0.77); + * rotateY(t * 0.83); + * rotateZ(t * 0.91); + * torus(width * 0.3, width * 0.07, 24, 10); + * } + * + * function mousePressed() { + * setAttributes('perPixelLighting', true); + * noStroke(); + * fill(255); + * } + * function mouseReleased() { + * setAttributes('perPixelLighting', false); + * noStroke(); + * fill(255); + * } + * + *
+ * + * @alt a rotating cube with smoother edges + */ + /** + * @method setAttributes + * @for p5 + * @param {Object} obj object with key-value pairs + */ + + p5.prototype.setAttributes = function(key, value) { + if (typeof this._glAttributes === 'undefined') { + console.log( + 'You are trying to use setAttributes on a p5.Graphics object ' + + 'that does not use a WEBGL renderer.' + ); + + return; + } + var unchanged = true; + if (typeof value !== 'undefined') { + //first time modifying the attributes + if (this._glAttributes === null) { + this._glAttributes = {}; + } + if (this._glAttributes[key] !== value) { + //changing value of previously altered attribute + this._glAttributes[key] = value; + unchanged = false; + } + //setting all attributes with some change + } else if (key instanceof Object) { + if (this._glAttributes !== key) { + this._glAttributes = key; + unchanged = false; + } + } + //@todo_FES + if (!this._renderer.isP3D || unchanged) { + return; + } + + if (!this._setupDone) { + for (var x in this._renderer.gHash) { + if (this._renderer.gHash.hasOwnProperty(x)) { + console.error( + 'Sorry, Could not set the attributes, you need to call setAttributes() ' + + 'before calling the other drawing methods in setup()' + ); + + return; + } + } + } + + this.push(); + this._renderer._resetContext(); + this.pop(); + + if (this._renderer._curCamera) { + this._renderer._curCamera._renderer = this._renderer; + } + }; + + /** + * @class p5.RendererGL + */ + + p5.RendererGL.prototype._update = function() { + // reset model view and apply initial camera transform + // (containing only look at info; no projection). + this.uMVMatrix.set( + this._curCamera.cameraMatrix.mat4[0], + this._curCamera.cameraMatrix.mat4[1], + this._curCamera.cameraMatrix.mat4[2], + this._curCamera.cameraMatrix.mat4[3], + this._curCamera.cameraMatrix.mat4[4], + this._curCamera.cameraMatrix.mat4[5], + this._curCamera.cameraMatrix.mat4[6], + this._curCamera.cameraMatrix.mat4[7], + this._curCamera.cameraMatrix.mat4[8], + this._curCamera.cameraMatrix.mat4[9], + this._curCamera.cameraMatrix.mat4[10], + this._curCamera.cameraMatrix.mat4[11], + this._curCamera.cameraMatrix.mat4[12], + this._curCamera.cameraMatrix.mat4[13], + this._curCamera.cameraMatrix.mat4[14], + this._curCamera.cameraMatrix.mat4[15] + ); + + // reset light data for new frame. + + this.ambientLightColors.length = 0; + this.directionalLightDirections.length = 0; + this.directionalLightColors.length = 0; + + this.pointLightPositions.length = 0; + this.pointLightColors.length = 0; + + this._enableLighting = false; + + //reset tint value for new frame + this._tint = [255, 255, 255, 255]; + }; + + /** + * [background description] + */ + p5.RendererGL.prototype.background = function() { + var _col = this._pInst.color.apply(this._pInst, arguments); + var _r = _col.levels[0] / 255; + var _g = _col.levels[1] / 255; + var _b = _col.levels[2] / 255; + var _a = _col.levels[3] / 255; + this.GL.clearColor(_r, _g, _b, _a); + this.GL.depthMask(true); + this.GL.clear(this.GL.COLOR_BUFFER_BIT | this.GL.DEPTH_BUFFER_BIT); + this._pixelsState._pixelsDirty = true; + }; + + ////////////////////////////////////////////// + // COLOR + ////////////////////////////////////////////// + /** + * Basic fill material for geometry with a given color + * @method fill + * @class p5.RendererGL + * @param {Number|Number[]|String|p5.Color} v1 gray value, + * red or hue value (depending on the current color mode), + * or color Array, or CSS color string + * @param {Number} [v2] green or saturation value + * @param {Number} [v3] blue or brightness value + * @param {Number} [a] opacity + * @chainable + * @example + *
+ * + * function setup() { + * createCanvas(200, 200, WEBGL); + * } + * + * function draw() { + * background(0); + * noStroke(); + * fill(100, 100, 240); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * box(75, 75, 75); + * } + * + *
+ * + * @alt + * black canvas with purple cube spinning + * + */ + p5.RendererGL.prototype.fill = function(v1, v2, v3, a) { + //see material.js for more info on color blending in webgl + var color = p5.prototype.color.apply(this._pInst, arguments); + this.curFillColor = color._array; + this.drawMode = constants.FILL; + this._useNormalMaterial = false; + this._tex = null; + }; + + /** + * Basic stroke material for geometry with a given color + * @method stroke + * @param {Number|Number[]|String|p5.Color} v1 gray value, + * red or hue value (depending on the current color mode), + * or color Array, or CSS color string + * @param {Number} [v2] green or saturation value + * @param {Number} [v3] blue or brightness value + * @param {Number} [a] opacity + * @example + *
+ * + * function setup() { + * createCanvas(200, 200, WEBGL); + * } + * + * function draw() { + * background(0); + * stroke(240, 150, 150); + * fill(100, 100, 240); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * box(75, 75, 75); + * } + * + *
+ * + * @alt + * black canvas with purple cube with pink outline spinning + * + */ + p5.RendererGL.prototype.stroke = function(r, g, b, a) { + //@todo allow transparency in stroking currently doesn't have + //any impact and causes problems with specularMaterial + arguments[3] = 255; + var color = p5.prototype.color.apply(this._pInst, arguments); + this.curStrokeColor = color._array; + }; + + p5.RendererGL.prototype.strokeCap = function(cap) { + // @TODO : to be implemented + console.error('Sorry, strokeCap() is not yet implemented in WEBGL mode'); + }; + + p5.RendererGL.prototype.blendMode = function(mode) { + if ( + mode === constants.DARKEST || + mode === constants.LIGHTEST || + mode === constants.ADD || + mode === constants.BLEND || + mode === constants.SUBTRACT || + mode === constants.SCREEN || + mode === constants.EXCLUSION || + mode === constants.REPLACE || + mode === constants.MULTIPLY + ) + this.curBlendMode = mode; + else if ( + mode === constants.BURN || + mode === constants.OVERLAY || + mode === constants.HARD_LIGHT || + mode === constants.SOFT_LIGHT || + mode === constants.DODGE + ) { + console.warn( + 'BURN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, and DODGE only work for blendMode in 2D mode.' + ); + } + }; + + /** + * Change weight of stroke + * @method strokeWeight + * @param {Number} stroke weight to be used for drawing + * @example + *
+ * + * function setup() { + * createCanvas(200, 400, WEBGL); + * setAttributes('antialias', true); + * } + * + * function draw() { + * background(0); + * noStroke(); + * translate(0, -100, 0); + * stroke(240, 150, 150); + * fill(100, 100, 240); + * push(); + * strokeWeight(8); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * sphere(75); + * pop(); + * push(); + * translate(0, 200, 0); + * strokeWeight(1); + * rotateX(frameCount * 0.01); + * rotateY(frameCount * 0.01); + * sphere(75); + * pop(); + * } + * + *
+ * + * @alt + * black canvas with two purple rotating spheres with pink + * outlines the sphere on top has much heavier outlines, + * + */ + p5.RendererGL.prototype.strokeWeight = function(w) { + if (this.curStrokeWeight !== w) { + this.pointSize = w; + this.curStrokeWeight = w; + } + }; + + // x,y are canvas-relative (pre-scaled by _pixelDensity) + p5.RendererGL.prototype._getPixel = function(x, y) { + var pixelsState = this._pixelsState; + var imageData, index; + if (pixelsState._pixelsDirty) { + imageData = new Uint8Array(4); + // prettier-ignore + this.drawingContext.readPixels( + x, y, 1, 1, + this.drawingContext.RGBA, this.drawingContext.UNSIGNED_BYTE, + imageData); + + index = 0; + } else { + imageData = pixelsState.pixels; + index = (Math.floor(x) + Math.floor(y) * this.canvas.width) * 4; + } + return [ + imageData[index + 0], + imageData[index + 1], + imageData[index + 2], + imageData[index + 3] + ]; + }; + + /** + * Loads the pixels data for this canvas into the pixels[] attribute. + * Note that updatePixels() and set() do not work. + * Any pixel manipulation must be done directly to the pixels[] array. + * + * @private + * @method loadPixels + * + */ + + p5.RendererGL.prototype.loadPixels = function() { + var pixelsState = this._pixelsState; + if (!pixelsState._pixelsDirty) return; + pixelsState._pixelsDirty = false; + + //@todo_FES + if (this._pInst._glAttributes.preserveDrawingBuffer !== true) { + console.log( + 'loadPixels only works in WebGL when preserveDrawingBuffer ' + 'is true.' + ); + + return; + } + + //if there isn't a renderer-level temporary pixels buffer + //make a new one + var pixels = pixelsState.pixels; + var len = this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4; + if (!(pixels instanceof Uint8Array) || pixels.length !== len) { + pixels = new Uint8Array(len); + this._pixelsState._setProperty('pixels', pixels); + } + + var pd = this._pInst._pixelDensity; + // prettier-ignore + this.GL.readPixels( + 0, 0, this.width * pd, this.height * pd, + this.GL.RGBA, this.GL.UNSIGNED_BYTE, + pixels); + }; + + ////////////////////////////////////////////// + // HASH | for geometry + ////////////////////////////////////////////// + + p5.RendererGL.prototype.geometryInHash = function(gId) { + return this.gHash[gId] !== undefined; + }; + + /** + * [resize description] + * @private + * @param {Number} w [description] + * @param {Number} h [description] + */ + p5.RendererGL.prototype.resize = function(w, h) { + p5.Renderer.prototype.resize.call(this, w, h); + this.GL.viewport(0, 0, this.GL.drawingBufferWidth, this.GL.drawingBufferHeight); + + this._viewport = this.GL.getParameter(this.GL.VIEWPORT); + + this._curCamera._resize(); + + //resize pixels buffer + var pixelsState = this._pixelsState; + pixelsState._pixelsDirty = true; + if (typeof pixelsState.pixels !== 'undefined') { + pixelsState._setProperty( + 'pixels', + new Uint8Array(this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4) + ); + } + }; + + /** + * clears color and depth buffers + * with r,g,b,a + * @private + * @param {Number} r normalized red val. + * @param {Number} g normalized green val. + * @param {Number} b normalized blue val. + * @param {Number} a normalized alpha val. + */ + p5.RendererGL.prototype.clear = function() { + var _r = arguments[0] || 0; + var _g = arguments[1] || 0; + var _b = arguments[2] || 0; + var _a = arguments[3] || 0; + this.GL.clearColor(_r, _g, _b, _a); + this.GL.clear(this.GL.COLOR_BUFFER_BIT | this.GL.DEPTH_BUFFER_BIT); + this._pixelsState._pixelsDirty = true; + }; + + p5.RendererGL.prototype.applyMatrix = function(a, b, c, d, e, f) { + if (arguments.length === 16) { + p5.Matrix.prototype.apply.apply(this.uMVMatrix, arguments); + } else { + // prettier-ignore + this.uMVMatrix.apply([ + a, b, 0, 0, + c, d, 0, 0, + 0, 0, 1, 0, + e, f, 0, 1]); + } + }; + + /** + * [translate description] + * @private + * @param {Number} x [description] + * @param {Number} y [description] + * @param {Number} z [description] + * @chainable + * @todo implement handle for components or vector as args + */ + p5.RendererGL.prototype.translate = function(x, y, z) { + if (x instanceof p5.Vector) { + z = x.z; + y = x.y; + x = x.x; + } + this.uMVMatrix.translate([x, y, z]); + return this; + }; + + /** + * Scales the Model View Matrix by a vector + * @private + * @param {Number | p5.Vector | Array} x [description] + * @param {Number} [y] y-axis scalar + * @param {Number} [z] z-axis scalar + * @chainable + */ + p5.RendererGL.prototype.scale = function(x, y, z) { + this.uMVMatrix.scale(x, y, z); + return this; + }; + + p5.RendererGL.prototype.rotate = function(rad, axis) { + if (typeof axis === 'undefined') { + return this.rotateZ(rad); + } + p5.Matrix.prototype.rotate.apply(this.uMVMatrix, arguments); + return this; + }; + + p5.RendererGL.prototype.rotateX = function(rad) { + this.rotate(rad, 1, 0, 0); + return this; + }; + + p5.RendererGL.prototype.rotateY = function(rad) { + this.rotate(rad, 0, 1, 0); + return this; + }; + + p5.RendererGL.prototype.rotateZ = function(rad) { + this.rotate(rad, 0, 0, 1); + return this; + }; + + p5.RendererGL.prototype.push = function() { + // get the base renderer style + var style = p5.Renderer.prototype.push.apply(this); + + // add webgl-specific style properties + var properties = style.properties; + + properties.uMVMatrix = this.uMVMatrix.copy(); + properties.uPMatrix = this.uPMatrix.copy(); + properties._curCamera = this._curCamera; + + // make a copy of the current camera for the push state + // this preserves any references stored using 'createCamera' + this._curCamera = this._curCamera.copy(); + + properties.ambientLightColors = this.ambientLightColors.slice(); + + properties.directionalLightDirections = this.directionalLightDirections.slice(); + properties.directionalLightColors = this.directionalLightColors.slice(); + + properties.pointLightPositions = this.pointLightPositions.slice(); + properties.pointLightColors = this.pointLightColors.slice(); + + properties.userFillShader = this.userFillShader; + properties.userStrokeShader = this.userStrokeShader; + properties.userPointShader = this.userPointShader; + + properties.pointSize = this.pointSize; + properties.curStrokeWeight = this.curStrokeWeight; + properties.curStrokeColor = this.curStrokeColor; + properties.curFillColor = this.curFillColor; + + properties._useSpecularMaterial = this._useSpecularMaterial; + properties._useShininess = this._useShininess; + + properties.constantAttenuation = this.constantAttenuation; + properties.linearAttenuation = this.linearAttenuation; + properties.quadraticAttenuation = this.quadraticAttenuation; + + properties._enableLighting = this._enableLighting; + properties._useNormalMaterial = this._useNormalMaterial; + properties._tex = this._tex; + properties.drawMode = this.drawMode; + + return style; + }; + + p5.RendererGL.prototype.resetMatrix = function() { + this.uMVMatrix = p5.Matrix.identity(this._pInst); + return this; + }; + + ////////////////////////////////////////////// + // SHADER + ////////////////////////////////////////////// + + /* + * shaders are created and cached on a per-renderer basis, + * on the grounds that each renderer will have its own gl context + * and the shader must be valid in that context. + */ + + p5.RendererGL.prototype._getImmediateStrokeShader = function() { + // select the stroke shader to use + var stroke = this.userStrokeShader; + if (!stroke || !stroke.isStrokeShader()) { + return this._getLineShader(); + } + return stroke; + }; + + p5.RendererGL.prototype._getRetainedStrokeShader = + p5.RendererGL.prototype._getImmediateStrokeShader; + + /* + * selects which fill shader should be used based on renderer state, + * for use with begin/endShape and immediate vertex mode. + */ + p5.RendererGL.prototype._getImmediateFillShader = function() { + if (this._useNormalMaterial) { + console.log( + 'Sorry, normalMaterial() does not currently work with custom WebGL geometry' + + ' created with beginShape(). Falling back to standard fill material.' + ); + + return this._getImmediateModeShader(); + } + + var fill = this.userFillShader; + if (this._enableLighting) { + if (!fill || !fill.isLightShader()) { + return this._getLightShader(); + } + } else if (this._tex) { + if (!fill || !fill.isTextureShader()) { + return this._getLightShader(); + } + } else if (!fill /*|| !fill.isColorShader()*/) { + return this._getImmediateModeShader(); + } + return fill; + }; + + /* + * selects which fill shader should be used based on renderer state + * for retained mode. + */ + p5.RendererGL.prototype._getRetainedFillShader = function() { + if (this._useNormalMaterial) { + return this._getNormalShader(); + } + + var fill = this.userFillShader; + if (this._enableLighting) { + if (!fill || !fill.isLightShader()) { + return this._getLightShader(); + } + } else if (this._tex) { + if (!fill || !fill.isTextureShader()) { + return this._getLightShader(); + } + } else if (!fill /* || !fill.isColorShader()*/) { + return this._getColorShader(); + } + return fill; + }; + + p5.RendererGL.prototype._getImmediatePointShader = function() { + // select the point shader to use + var point = this.userPointShader; + if (!point || !point.isPointShader()) { + return this._getPointShader(); + } + return point; + }; + + p5.RendererGL.prototype._getRetainedLineShader = + p5.RendererGL.prototype._getImmediateLineShader; + + p5.RendererGL.prototype._getLightShader = function() { + if (!this._defaultLightShader) { + if (this._pInst._glAttributes.perPixelLighting) { + this._defaultLightShader = new p5.Shader( + this, + defaultShaders.phongVert, + defaultShaders.phongFrag + ); + } else { + this._defaultLightShader = new p5.Shader( + this, + defaultShaders.lightVert, + defaultShaders.lightTextureFrag + ); + } + } + + return this._defaultLightShader; + }; + + p5.RendererGL.prototype._getImmediateModeShader = function() { + if (!this._defaultImmediateModeShader) { + this._defaultImmediateModeShader = new p5.Shader( + this, + defaultShaders.immediateVert, + defaultShaders.vertexColorFrag + ); + } + + return this._defaultImmediateModeShader; + }; + + p5.RendererGL.prototype._getNormalShader = function() { + if (!this._defaultNormalShader) { + this._defaultNormalShader = new p5.Shader( + this, + defaultShaders.normalVert, + defaultShaders.normalFrag + ); + } + + return this._defaultNormalShader; + }; + + p5.RendererGL.prototype._getColorShader = function() { + if (!this._defaultColorShader) { + this._defaultColorShader = new p5.Shader( + this, + defaultShaders.normalVert, + defaultShaders.basicFrag + ); + } + + return this._defaultColorShader; + }; + + p5.RendererGL.prototype._getPointShader = function() { + if (!this._defaultPointShader) { + this._defaultPointShader = new p5.Shader( + this, + defaultShaders.pointVert, + defaultShaders.pointFrag + ); + } + return this._defaultPointShader; + }; + + p5.RendererGL.prototype._getLineShader = function() { + if (!this._defaultLineShader) { + this._defaultLineShader = new p5.Shader( + this, + defaultShaders.lineVert, + defaultShaders.lineFrag + ); + } + + return this._defaultLineShader; + }; + + p5.RendererGL.prototype._getFontShader = function() { + if (!this._defaultFontShader) { + this.GL.getExtension('OES_standard_derivatives'); + this._defaultFontShader = new p5.Shader( + this, + defaultShaders.fontVert, + defaultShaders.fontFrag + ); + } + return this._defaultFontShader; + }; + + p5.RendererGL.prototype._getEmptyTexture = function() { + if (!this._emptyTexture) { + // a plain white texture RGBA, full alpha, single pixel. + var im = new p5.Image(1, 1); + im.set(0, 0, 255); + this._emptyTexture = new p5.Texture(this, im); + } + return this._emptyTexture; + }; + + p5.RendererGL.prototype.getTexture = function(img) { + var textures = this.textures; + for (var it = 0; it < textures.length; ++it) { + var texture = textures[it]; + if (texture.src === img) return texture; + } + + var tex = new p5.Texture(this, img); + textures.push(tex); + return tex; + }; + + p5.RendererGL.prototype._setStrokeUniforms = function(strokeShader) { + strokeShader.bindShader(); + + // set the uniform values + strokeShader.setUniform('uMaterialColor', this.curStrokeColor); + strokeShader.setUniform('uStrokeWeight', this.curStrokeWeight); + }; + + p5.RendererGL.prototype._setFillUniforms = function(fillShader) { + fillShader.bindShader(); + + // TODO: optimize + fillShader.setUniform('uMaterialColor', this.curFillColor); + fillShader.setUniform('isTexture', !!this._tex); + if (this._tex) { + fillShader.setUniform('uSampler', this._tex); + } + fillShader.setUniform('uTint', this._tint); + + fillShader.setUniform('uSpecular', this._useSpecularMaterial); + fillShader.setUniform('uShininess', this._useShininess); + + fillShader.setUniform('uUseLighting', this._enableLighting); + + var pointLightCount = this.pointLightColors.length / 3; + fillShader.setUniform('uPointLightCount', pointLightCount); + fillShader.setUniform('uPointLightLocation', this.pointLightPositions); + fillShader.setUniform('uPointLightColor', this.pointLightColors); + + var directionalLightCount = this.directionalLightColors.length / 3; + fillShader.setUniform('uDirectionalLightCount', directionalLightCount); + fillShader.setUniform('uLightingDirection', this.directionalLightDirections); + fillShader.setUniform('uDirectionalColor', this.directionalLightColors); + + // TODO: sum these here... + var ambientLightCount = this.ambientLightColors.length / 3; + fillShader.setUniform('uAmbientLightCount', ambientLightCount); + fillShader.setUniform('uAmbientColor', this.ambientLightColors); + + fillShader.setUniform('uConstantAttenuation', this.constantAttenuation); + fillShader.setUniform('uLinearAttenuation', this.linearAttenuation); + fillShader.setUniform('uQuadraticAttenuation', this.quadraticAttenuation); + + fillShader.bindTextures(); + }; + + p5.RendererGL.prototype._setPointUniforms = function(pointShader) { + pointShader.bindShader(); + + // set the uniform values + pointShader.setUniform('uMaterialColor', this.curStrokeColor); + // @todo is there an instance where this isn't stroke weight? + // should be they be same var? + pointShader.setUniform('uPointSize', this.pointSize); + }; + + /* Binds a buffer to the drawing context + * when passed more than two arguments it also updates or initializes + * the data associated with the buffer + */ + p5.RendererGL.prototype._bindBuffer = function( + buffer, + target, + values, + type, + usage + ) { + if (!target) target = this.GL.ARRAY_BUFFER; + this.GL.bindBuffer(target, buffer); + if (values !== undefined) { + var data = new (type || Float32Array)(values); + this.GL.bufferData(target, data, usage || this.GL.STATIC_DRAW); + } + }; + + /////////////////////////////// + //// UTILITY FUNCTIONS + ////////////////////////////// + /** + * turn a two dimensional array into one dimensional array + * @private + * @param {Array} arr 2-dimensional array + * @return {Array} 1-dimensional array + * [[1, 2, 3],[4, 5, 6]] -> [1, 2, 3, 4, 5, 6] + */ + p5.RendererGL.prototype._flatten = function(arr) { + //when empty, return empty + if (arr.length === 0) { + return []; + } else if (arr.length > 20000) { + //big models , load slower to avoid stack overflow + //faster non-recursive flatten via axelduch + //stackoverflow.com/questions/27266550/how-to-flatten-nested-array-in-javascript + var toString = Object.prototype.toString; + var arrayTypeStr = '[object Array]'; + var result = []; + var nodes = arr.slice(); + var node; + node = nodes.pop(); + do { + if (toString.call(node) === arrayTypeStr) { + nodes.push.apply(nodes, node); + } else { + result.push(node); + } + } while (nodes.length && (node = nodes.pop()) !== undefined); + result.reverse(); // we reverse result to restore the original order + return result; + } else { + //otherwise if model within limits for browser + //use faster recursive loading + return [].concat.apply([], arr); + } + }; + + /** + * turn a p5.Vector Array into a one dimensional number array + * @private + * @param {p5.Vector[]} arr an array of p5.Vector + * @return {Number[]} a one dimensional array of numbers + * [p5.Vector(1, 2, 3), p5.Vector(4, 5, 6)] -> + * [1, 2, 3, 4, 5, 6] + */ + p5.RendererGL.prototype._vToNArray = function(arr) { + var ret = []; + for (var i = 0; i < arr.length; i++) { + var item = arr[i]; + ret.push(item.x, item.y, item.z); + } + return ret; + }; + + /** + * ensures that p5 is using a 3d renderer. throws an error if not. + */ + p5.prototype._assert3d = function(name) { + if (!this._renderer.isP3D) + throw new Error( + name + + "() is only supported in WEBGL mode. If you'd like to use 3D graphics" + + ' and WebGL, see https://p5js.org/examples/form-3d-primitives.html' + + ' for more information.' + ); + }; + + // function to initialize GLU Tesselator + + p5.RendererGL.prototype._initTessy = function initTesselator() { + // function called for each vertex of tesselator output + function vertexCallback(data, polyVertArray) { + polyVertArray[polyVertArray.length] = data[0]; + polyVertArray[polyVertArray.length] = data[1]; + polyVertArray[polyVertArray.length] = data[2]; + } + + function begincallback(type) { + if (type !== libtess.primitiveType.GL_TRIANGLES) { + console.log('expected TRIANGLES but got type: ' + type); + } + } + + function errorcallback(errno) { + console.log('error callback'); + console.log('error number: ' + errno); + } + // callback for when segments intersect and must be split + function combinecallback(coords, data, weight) { + return [coords[0], coords[1], coords[2]]; + } + + function edgeCallback(flag) { + // don't really care about the flag, but need no-strip/no-fan behavior + } + + var tessy = new libtess.GluTesselator(); + tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_VERTEX_DATA, vertexCallback); + tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_BEGIN, begincallback); + tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_ERROR, errorcallback); + tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_COMBINE, combinecallback); + tessy.gluTessCallback(libtess.gluEnum.GLU_TESS_EDGE_FLAG, edgeCallback); + + return tessy; + }; + + p5.RendererGL.prototype._triangulate = function(contours) { + // libtess will take 3d verts and flatten to a plane for tesselation + // since only doing 2d tesselation here, provide z=1 normal to skip + // iterating over verts only to get the same answer. + // comment out to test normal-generation code + this._tessy.gluTessNormal(0, 0, 1); + + var triangleVerts = []; + this._tessy.gluTessBeginPolygon(triangleVerts); + + for (var i = 0; i < contours.length; i++) { + this._tessy.gluTessBeginContour(); + var contour = contours[i]; + for (var j = 0; j < contour.length; j += 3) { + var coords = [contour[j], contour[j + 1], contour[j + 2]]; + this._tessy.gluTessVertex(coords, coords); + } + this._tessy.gluTessEndContour(); + } + + // finish polygon + this._tessy.gluTessEndPolygon(); + + return triangleVerts; + }; + + // function to calculate BezierVertex Coefficients + p5.RendererGL.prototype._bezierCoefficients = function(t) { + var t2 = t * t; + var t3 = t2 * t; + var mt = 1 - t; + var mt2 = mt * mt; + var mt3 = mt2 * mt; + return [mt3, 3 * mt2 * t, 3 * mt * t2, t3]; + }; + + // function to calculate QuadraticVertex Coefficients + p5.RendererGL.prototype._quadraticCoefficients = function(t) { + var t2 = t * t; + var mt = 1 - t; + var mt2 = mt * mt; + return [mt2, 2 * mt * t, t2]; + }; + + // function to convert Bezier coordinates to Catmull Rom Splines + p5.RendererGL.prototype._bezierToCatmull = function(w) { + var p1 = w[1]; + var p2 = w[1] + (w[2] - w[0]) / this._curveTightness; + var p3 = w[2] - (w[3] - w[1]) / this._curveTightness; + var p4 = w[2]; + var p = [p1, p2, p3, p4]; + return p; + }; + + module.exports = p5.RendererGL; + }, + { + '../core/constants': 18, + '../core/main': 24, + '../core/p5.Renderer': 27, + './p5.Camera': 70, + './p5.Matrix': 72, + './p5.Shader': 76, + libtess: 9 + } + ], + 76: [ + function(_dereq_, module, exports) { + /** + * This module defines the p5.Shader class + * @module Lights, Camera + * @submodule Shaders + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + + /** + * Shader class for WEBGL Mode + * @class p5.Shader + * @param {p5.RendererGL} renderer an instance of p5.RendererGL that + * will provide the GL context for this new p5.Shader + * @param {String} vertSrc source code for the vertex shader (as a string) + * @param {String} fragSrc source code for the fragment shader (as a string) + */ + p5.Shader = function(renderer, vertSrc, fragSrc) { + // TODO: adapt this to not take ids, but rather, + // to take the source for a vertex and fragment shader + // to enable custom shaders at some later date + this._renderer = renderer; + this._vertSrc = vertSrc; + this._fragSrc = fragSrc; + this._vertShader = -1; + this._fragShader = -1; + this._glProgram = 0; + this._loadedAttributes = false; + this.attributes = {}; + this._loadedUniforms = false; + this.uniforms = {}; + this._bound = false; + this.samplers = []; + }; + + /** + * Creates, compiles, and links the shader based on its + * sources for the vertex and fragment shaders (provided + * to the constructor). Populates known attributes and + * uniforms from the shader. + * @method init + * @chainable + * @private + */ + p5.Shader.prototype.init = function() { + if (this._glProgram === 0 /* or context is stale? */) { + var gl = this._renderer.GL; + + // @todo: once custom shading is allowed, + // friendly error messages should be used here to share + // compiler and linker errors. + + //set up the shader by + // 1. creating and getting a gl id for the shader program, + // 2. compliling its vertex & fragment sources, + // 3. linking the vertex and fragment shaders + this._vertShader = gl.createShader(gl.VERTEX_SHADER); + //load in our default vertex shader + gl.shaderSource(this._vertShader, this._vertSrc); + gl.compileShader(this._vertShader); + // if our vertex shader failed compilation? + if (!gl.getShaderParameter(this._vertShader, gl.COMPILE_STATUS)) { + console.error( + 'Yikes! An error occurred compiling the vertex shader:' + + gl.getShaderInfoLog(this._vertShader) + ); + + return null; + } + + this._fragShader = gl.createShader(gl.FRAGMENT_SHADER); + //load in our material frag shader + gl.shaderSource(this._fragShader, this._fragSrc); + gl.compileShader(this._fragShader); + // if our frag shader failed compilation? + if (!gl.getShaderParameter(this._fragShader, gl.COMPILE_STATUS)) { + console.error( + 'Darn! An error occurred compiling the fragment shader:' + + gl.getShaderInfoLog(this._fragShader) + ); + + return null; + } + + this._glProgram = gl.createProgram(); + gl.attachShader(this._glProgram, this._vertShader); + gl.attachShader(this._glProgram, this._fragShader); + gl.linkProgram(this._glProgram); + if (!gl.getProgramParameter(this._glProgram, gl.LINK_STATUS)) { + console.error( + 'Snap! Error linking shader program: ' + + gl.getProgramInfoLog(this._glProgram) + ); + } + + this._loadAttributes(); + this._loadUniforms(); + } + return this; + }; + + /** + * Queries the active attributes for this shader and loads + * their names and locations into the attributes array. + * @method _loadAttributes + * @private + */ + p5.Shader.prototype._loadAttributes = function() { + if (this._loadedAttributes) { + return; + } + + this.attributes = {}; + + var gl = this._renderer.GL; + + var numAttributes = gl.getProgramParameter( + this._glProgram, + gl.ACTIVE_ATTRIBUTES + ); + + for (var i = 0; i < numAttributes; ++i) { + var attributeInfo = gl.getActiveAttrib(this._glProgram, i); + var name = attributeInfo.name; + var location = gl.getAttribLocation(this._glProgram, name); + var attribute = {}; + attribute.name = name; + attribute.location = location; + attribute.index = i; + attribute.type = attributeInfo.type; + attribute.size = attributeInfo.size; + this.attributes[name] = attribute; + } + + this._loadedAttributes = true; + }; + + /** + * Queries the active uniforms for this shader and loads + * their names and locations into the uniforms array. + * @method _loadUniforms + * @private + */ + p5.Shader.prototype._loadUniforms = function() { + if (this._loadedUniforms) { + return; + } + + var gl = this._renderer.GL; + + // Inspect shader and cache uniform info + var numUniforms = gl.getProgramParameter(this._glProgram, gl.ACTIVE_UNIFORMS); + + var samplerIndex = 0; + for (var i = 0; i < numUniforms; ++i) { + var uniformInfo = gl.getActiveUniform(this._glProgram, i); + var uniform = {}; + uniform.location = gl.getUniformLocation(this._glProgram, uniformInfo.name); + uniform.size = uniformInfo.size; + var uniformName = uniformInfo.name; + //uniforms thats are arrays have their name returned as + //someUniform[0] which is a bit silly so we trim it + //off here. The size property tells us that its an array + //so we dont lose any information by doing this + if (uniformInfo.size > 1) { + uniformName = uniformName.substring(0, uniformName.indexOf('[0]')); + } + uniform.name = uniformName; + uniform.type = uniformInfo.type; + if (uniform.type === gl.SAMPLER_2D) { + uniform.samplerIndex = samplerIndex; + samplerIndex++; + this.samplers.push(uniform); + } + this.uniforms[uniformName] = uniform; + } + this._loadedUniforms = true; + }; + + p5.Shader.prototype.compile = function() { + // TODO + }; + + /** + * initializes (if needed) and binds the shader program. + * @method bindShader + * @private + */ + p5.Shader.prototype.bindShader = function() { + this.init(); + if (!this._bound) { + this.useProgram(); + this._bound = true; + + this._setMatrixUniforms(); + + this.setUniform('uViewport', this._renderer._viewport); + } + }; + + /** + * @method unbindShader + * @chainable + * @private + */ + p5.Shader.prototype.unbindShader = function() { + if (this._bound) { + this.unbindTextures(); + //this._renderer.GL.useProgram(0); ?? + this._bound = false; + } + return this; + }; + + p5.Shader.prototype.bindTextures = function() { + var gl = this._renderer.GL; + for (var i = 0; i < this.samplers.length; i++) { + var uniform = this.samplers[i]; + var tex = uniform.texture; + if (tex === undefined) { + // user hasn't yet supplied a texture for this slot. + // (or there may not be one--maybe just lighting), + // so we supply a default texture instead. + tex = this._renderer._getEmptyTexture(); + } + gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex); + tex.bindTexture(); + tex.update(); + gl.uniform1i(uniform.location, uniform.samplerIndex); + } + }; + + p5.Shader.prototype.updateTextures = function() { + for (var i = 0; i < this.samplers.length; i++) { + var uniform = this.samplers[i]; + var tex = uniform.texture; + if (tex) { + tex.update(); + } + } + }; + + p5.Shader.prototype.unbindTextures = function() { + // TODO: migrate stuff from material.js here + // - OR - have material.js define this function + }; + + p5.Shader.prototype._setMatrixUniforms = function() { + this.setUniform('uProjectionMatrix', this._renderer.uPMatrix.mat4); + this.setUniform('uModelViewMatrix', this._renderer.uMVMatrix.mat4); + this.setUniform('uViewMatrix', this._renderer._curCamera.cameraMatrix.mat4); + if (this.uniforms.uNormalMatrix) { + this._renderer.uNMatrix.inverseTranspose(this._renderer.uMVMatrix); + this.setUniform('uNormalMatrix', this._renderer.uNMatrix.mat3); + } + }; + + /** + * @method useProgram + * @chainable + * @private + */ + p5.Shader.prototype.useProgram = function() { + var gl = this._renderer.GL; + gl.useProgram(this._glProgram); + return this; + }; + + /** + * Wrapper around gl.uniform functions. + * As we store uniform info in the shader we can use that + * to do type checking on the supplied data and call + * the appropriate function. + * @method setUniform + * @chainable + * @param {String} uniformName the name of the uniform in the + * shader program + * @param {Object|Number|Boolean|Number[]} data the data to be associated + * with that uniform; type varies (could be a single numerical value, array, + * matrix, or texture / sampler reference) + * + * @example + *
+ * + * // Click within the image to toggle the value of uniforms + * // Note: for an alternative approach to the same example, + * // involving toggling between shaders please refer to: + * // https://p5js.org/reference/#/p5/shader + * + * let grad; + * let showRedGreen = false; + * + * function preload() { + * // note that we are using two instances + * // of the same vertex and fragment shaders + * grad = loadShader('assets/shader.vert', 'assets/shader-gradient.frag'); + * } + * + * function setup() { + * createCanvas(100, 100, WEBGL); + * shader(grad); + * noStroke(); + * } + * + * function draw() { + * // update the offset values for each scenario, + * // moving the "grad" shader in either vertical or + * // horizontal direction each with differing colors + * + * if (showRedGreen === true) { + * grad.setUniform('colorCenter', [1, 0, 0]); + * grad.setUniform('colorBackground', [0, 1, 0]); + * grad.setUniform('offset', [sin(millis() / 2000), 1]); + * } else { + * grad.setUniform('colorCenter', [1, 0.5, 0]); + * grad.setUniform('colorBackground', [0.226, 0, 0.615]); + * grad.setUniform('offset', [0, sin(millis() / 2000) + 1]); + * } + * quad(-1, -1, 1, -1, 1, 1, -1, 1); + * } + * + * function mouseClicked() { + * showRedGreen = !showRedGreen; + * } + * + *
+ * + * @alt + * canvas toggles between a circular gradient of orange and blue vertically. and a circular gradient of red and green moving horizontally when mouse is clicked/pressed. + */ + p5.Shader.prototype.setUniform = function(uniformName, data) { + //@todo update all current gl.uniformXX calls + + var uniform = this.uniforms[uniformName]; + if (!uniform) { + return; + } + + var location = uniform.location; + + var gl = this._renderer.GL; + this.useProgram(); + + switch (uniform.type) { + case gl.BOOL: + if (data === true) { + gl.uniform1i(location, 1); + } else { + gl.uniform1i(location, 0); + } + break; + case gl.INT: + if (uniform.size > 1) { + data.length && gl.uniform1iv(location, data); + } else { + gl.uniform1i(location, data); + } + break; + case gl.FLOAT: + if (uniform.size > 1) { + data.length && gl.uniform1fv(location, data); + } else { + gl.uniform1f(location, data); + } + break; + case gl.FLOAT_MAT3: + gl.uniformMatrix3fv(location, false, data); + break; + case gl.FLOAT_MAT4: + gl.uniformMatrix4fv(location, false, data); + break; + case gl.FLOAT_VEC2: + if (uniform.size > 1) { + data.length && gl.uniform2fv(location, data); + } else { + gl.uniform2f(location, data[0], data[1]); + } + break; + case gl.FLOAT_VEC3: + if (uniform.size > 1) { + data.length && gl.uniform3fv(location, data); + } else { + gl.uniform3f(location, data[0], data[1], data[2]); + } + break; + case gl.FLOAT_VEC4: + if (uniform.size > 1) { + data.length && gl.uniform4fv(location, data); + } else { + gl.uniform4f(location, data[0], data[1], data[2], data[3]); + } + break; + case gl.INT_VEC2: + if (uniform.size > 1) { + data.length && gl.uniform2iv(location, data); + } else { + gl.uniform2i(location, data[0], data[1]); + } + break; + case gl.INT_VEC3: + if (uniform.size > 1) { + data.length && gl.uniform3iv(location, data); + } else { + gl.uniform3i(location, data[0], data[1], data[2]); + } + break; + case gl.INT_VEC4: + if (uniform.size > 1) { + data.length && gl.uniform4iv(location, data); + } else { + gl.uniform4i(location, data[0], data[1], data[2], data[3]); + } + break; + case gl.SAMPLER_2D: + gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex); + uniform.texture = this._renderer.getTexture(data); + gl.uniform1i(uniform.location, uniform.samplerIndex); + break; + //@todo complete all types + } + return this; + }; + + /* NONE OF THIS IS FAST OR EFFICIENT BUT BEAR WITH ME + * + * these shader "type" query methods are used by various + * facilities of the renderer to determine if changing + * the shader type for the required action (for example, + * do we need to load the default lighting shader if the + * current shader cannot handle lighting?) + * + **/ + + p5.Shader.prototype.isLightShader = function() { + return ( + this.attributes.aNormal !== undefined || + this.uniforms.uUseLighting !== undefined || + this.uniforms.uAmbientLightCount !== undefined || + this.uniforms.uDirectionalLightCount !== undefined || + this.uniforms.uPointLightCount !== undefined || + this.uniforms.uAmbientColor !== undefined || + this.uniforms.uDirectionalColor !== undefined || + this.uniforms.uPointLightLocation !== undefined || + this.uniforms.uPointLightColor !== undefined || + this.uniforms.uLightingDirection !== undefined || + this.uniforms.uSpecular !== undefined + ); + }; + + p5.Shader.prototype.isTextureShader = function() { + return this.samplerIndex > 0; + }; + + p5.Shader.prototype.isColorShader = function() { + return ( + this.attributes.aVertexColor !== undefined || + this.uniforms.uMaterialColor !== undefined + ); + }; + + p5.Shader.prototype.isTexLightShader = function() { + return this.isLightShader() && this.isTextureShader(); + }; + + p5.Shader.prototype.isStrokeShader = function() { + return this.uniforms.uStrokeWeight !== undefined; + }; + + /** + * @method enableAttrib + * @chainable + * @private + */ + p5.Shader.prototype.enableAttrib = function( + attr, + size, + type, + normalized, + stride, + offset + ) { + if (attr) { + if ( + typeof IS_MINIFIED === 'undefined' && + this.attributes[attr.name] !== attr + ) { + console.warn( + 'The attribute "' + + attr.name + + '"passed to enableAttrib does not belong to this shader.' + ); + } + var loc = attr.location; + if (loc !== -1) { + var gl = this._renderer.GL; + gl.enableVertexAttribArray(loc); + gl.vertexAttribPointer( + loc, + size, + type || gl.FLOAT, + normalized || false, + stride || 0, + offset || 0 + ); + } + } + return this; + }; + + module.exports = p5.Shader; + }, + { '../core/main': 24 } + ], + 77: [ + function(_dereq_, module, exports) { + /** + * This module defines the p5.Texture class + * @module Lights, Camera + * @submodule Material + * @for p5 + * @requires core + */ + + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + + /** + * Texture class for WEBGL Mode + * @private + * @class p5.Texture + * @param {p5.RendererGL} renderer an instance of p5.RendererGL that + * will provide the GL context for this new p5.Texture + * @param {p5.Image|p5.Graphics|p5.Element|p5.MediaElement|ImageData} [obj] the + * object containing the image data to store in the texture. + */ + p5.Texture = function(renderer, obj) { + this._renderer = renderer; + + var gl = this._renderer.GL; + + this.src = obj; + this.glTex = undefined; + this.glTarget = gl.TEXTURE_2D; + this.glFormat = gl.RGBA; + this.mipmaps = false; + this.glMinFilter = gl.LINEAR; + this.glMagFilter = gl.LINEAR; + this.glWrapS = gl.CLAMP_TO_EDGE; + this.glWrapT = gl.CLAMP_TO_EDGE; + + // used to determine if this texture might need constant updating + // because it is a video or gif. + this.isSrcMediaElement = + typeof p5.MediaElement !== 'undefined' && obj instanceof p5.MediaElement; + this._videoPrevUpdateTime = 0; + this.isSrcHTMLElement = + typeof p5.Element !== 'undefined' && + obj instanceof p5.Element && + !(obj instanceof p5.Graphics); + this.isSrcP5Image = obj instanceof p5.Image; + this.isSrcP5Graphics = obj instanceof p5.Graphics; + this.isImageData = typeof ImageData !== 'undefined' && obj instanceof ImageData; + + var textureData = this._getTextureDataFromSource(); + this.width = textureData.width; + this.height = textureData.height; + + this.init(textureData); + return this; + }; + + p5.Texture.prototype._getTextureDataFromSource = function() { + var textureData; + if (this.isSrcP5Image) { + // param is a p5.Image + textureData = this.src.canvas; + } else if ( + this.isSrcMediaElement || + this.isSrcP5Graphics || + this.isSrcHTMLElement + ) { + // if param is a video HTML element + textureData = this.src.elt; + } else if (this.isImageData) { + textureData = this.src; + } + return textureData; + }; + + /** + * Initializes common texture parameters, creates a gl texture, + * tries to upload the texture for the first time if data is + * already available. + * @private + * @method init + */ + p5.Texture.prototype.init = function(data) { + var gl = this._renderer.GL; + this.glTex = gl.createTexture(); + + this.glWrapS = this._renderer.textureWrapX; + this.glWrapT = this._renderer.textureWrapY; + + this.setWrapMode(this.glWrapS, this.glWrapT); + this.bindTexture(); + + //gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter); + + if ( + this.width === 0 || + this.height === 0 || + (this.isSrcMediaElement && !this.src.loadedmetadata) + ) { + // assign a 1x1 empty texture initially, because data is not yet ready, + // so that no errors occur in gl console! + var tmpdata = new Uint8Array([1, 1, 1, 1]); + gl.texImage2D( + this.glTarget, + 0, + gl.RGBA, + 1, + 1, + 0, + this.glFormat, + gl.UNSIGNED_BYTE, + tmpdata + ); + } else { + // data is ready: just push the texture! + gl.texImage2D( + this.glTarget, + 0, + this.glFormat, + this.glFormat, + gl.UNSIGNED_BYTE, + data + ); + } + }; + + /** + * Checks if the source data for this texture has changed (if it's + * easy to do so) and reuploads the texture if necessary. If it's not + * possible or to expensive to do a calculation to determine wheter or + * not the data has occurred, this method simply re-uploads the texture. + * @method update + */ + p5.Texture.prototype.update = function() { + var data = this.src; + if (data.width === 0 || data.height === 0) { + return false; // nothing to do! + } + + var textureData = this._getTextureDataFromSource(); + var updated = false; + + var gl = this._renderer.GL; + // pull texture from data, make sure width & height are appropriate + if (textureData.width !== this.width || textureData.height !== this.height) { + updated = true; + + // make sure that if the width and height of this.src have changed + // for some reason, we update our metadata and upload the texture again + this.width = textureData.width; + this.height = textureData.height; + + if (this.isSrcP5Image) { + data.setModified(false); + } else if (this.isSrcMediaElement || this.isSrcHTMLElement) { + // on the first frame the metadata comes in, the size will be changed + // from 0 to actual size, but pixels may not be available. + // flag for update in a future frame. + // if we don't do this, a paused video, for example, may not + // send the first frame to texture memory. + data.setModified(true); + } + } else if (this.isSrcP5Image) { + // for an image, we only update if the modified field has been set, + // for example, by a call to p5.Image.set + if (data.isModified()) { + updated = true; + data.setModified(false); + } + } else if (this.isSrcMediaElement) { + // for a media element (video), we'll check if the current time in + // the video frame matches the last time. if it doesn't match, the + // video has advanced or otherwise been taken to a new frame, + // and we need to upload it. + if (data.isModified()) { + // p5.MediaElement may have also had set/updatePixels, etc. called + // on it and should be updated, or may have been set for the first + // time! + updated = true; + data.setModified(false); + } else if (data.loadedmetadata) { + // if the meta data has been loaded, we can ask the video + // what it's current position (in time) is. + if (this._videoPrevUpdateTime !== data.time()) { + // update the texture in gpu mem only if the current + // video timestamp does not match the timestamp of the last + // time we uploaded this texture (and update the time we + // last uploaded, too) + this._videoPrevUpdateTime = data.time(); + updated = true; + } + } + } else if (this.isImageData) { + if (data._dirty) { + data._dirty = false; + updated = true; + } + } else { + /* data instanceof p5.Graphics, probably */ + // there is not enough information to tell if the texture can be + // conditionally updated; so to be safe, we just go ahead and upload it. + updated = true; + } + + if (updated) { + this.bindTexture(); + gl.texImage2D( + this.glTarget, + 0, + this.glFormat, + this.glFormat, + gl.UNSIGNED_BYTE, + textureData + ); + } + + return updated; + }; + + /** + * Binds the texture to the appropriate GL target. + * @method bindTexture + */ + p5.Texture.prototype.bindTexture = function() { + // bind texture using gl context + glTarget and + // generated gl texture object + var gl = this._renderer.GL; + gl.bindTexture(this.glTarget, this.glTex); + + return this; + }; + + /** + * Unbinds the texture from the appropriate GL target. + * @method unbindTexture + */ + p5.Texture.prototype.unbindTexture = function() { + // unbind per above, disable texturing on glTarget + var gl = this._renderer.GL; + gl.bindTexture(this.glTarget, null); + }; + + /** + * Sets how a texture is be interpolated when upscaled or downscaled. + * Nearest filtering uses nearest neighbor scaling when interpolating + * Linear filtering uses WebGL's linear scaling when interpolating + * @method setInterpolation + * @param {String} downScale Specifies the texture filtering when + * textures are shrunk. Options are LINEAR or NEAREST + * @param {String} upScale Specifies the texture filtering when + * textures are magnified. Options are LINEAR or NEAREST + * @todo implement mipmapping filters + */ + p5.Texture.prototype.setInterpolation = function(downScale, upScale) { + var gl = this._renderer.GL; + + if (downScale === constants.NEAREST) { + this.glMinFilter = gl.NEAREST; + } else { + this.glMinFilter = gl.LINEAR; + } + + if (upScale === constants.NEAREST) { + this.glMagFilter = gl.NEAREST; + } else { + this.glMagFilter = gl.LINEAR; + } + + this.bindTexture(); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, this.glMinFilter); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, this.glMagFilter); + this.unbindTexture(); + }; + + /** + * Sets the texture wrapping mode. This controls how textures behave + * when their uv's go outside of the 0 - 1 range. There are three options: + * CLAMP, REPEAT, and MIRROR. REPEAT & MIRROR are only available if the texture + * is a power of two size (128, 256, 512, 1024, etc.). + * @method setWrapMode + * @param {String} wrapX Controls the horizontal texture wrapping behavior + * @param {String} wrapY Controls the vertical texture wrapping behavior + */ + p5.Texture.prototype.setWrapMode = function(wrapX, wrapY) { + var gl = this._renderer.GL; + + // for webgl 1 we need to check if the texture is power of two + // if it isn't we will set the wrap mode to CLAMP + // webgl2 will support npot REPEAT and MIRROR but we don't check for it yet + var isPowerOfTwo = function isPowerOfTwo(x) { + return (x & (x - 1)) === 0; + }; + + var widthPowerOfTwo = isPowerOfTwo(this.width); + var heightPowerOfTwo = isPowerOfTwo(this.height); + + if (wrapX === constants.REPEAT) { + if (widthPowerOfTwo && heightPowerOfTwo) { + this.glWrapS = gl.REPEAT; + } else { + console.warn( + 'You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead' + ); + + this.glWrapS = gl.CLAMP_TO_EDGE; + } + } else if (wrapX === constants.MIRROR) { + if (widthPowerOfTwo && heightPowerOfTwo) { + this.glWrapS = gl.MIRRORED_REPEAT; + } else { + console.warn( + 'You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead' + ); + + this.glWrapS = gl.CLAMP_TO_EDGE; + } + } else { + // falling back to default if didn't get a proper mode + this.glWrapS = gl.CLAMP_TO_EDGE; + } + + if (wrapY === constants.REPEAT) { + if (widthPowerOfTwo && heightPowerOfTwo) { + this.glWrapT = gl.REPEAT; + } else { + console.warn( + 'You tried to set the wrap mode to REPEAT but the texture size is not a power of two. Setting to CLAMP instead' + ); + + this.glWrapT = gl.CLAMP_TO_EDGE; + } + } else if (wrapY === constants.MIRROR) { + if (widthPowerOfTwo && heightPowerOfTwo) { + this.glWrapT = gl.MIRRORED_REPEAT; + } else { + console.warn( + 'You tried to set the wrap mode to MIRROR but the texture size is not a power of two. Setting to CLAMP instead' + ); + + this.glWrapT = gl.CLAMP_TO_EDGE; + } + } else { + // falling back to default if didn't get a proper mode + this.glWrapT = gl.CLAMP_TO_EDGE; + } + + this.bindTexture(); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.glWrapS); + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.glWrapT); + this.unbindTexture(); + }; + + module.exports = p5.Texture; + }, + { '../core/constants': 18, '../core/main': 24 } + ], + 78: [ + function(_dereq_, module, exports) { + 'use strict'; + + var p5 = _dereq_('../core/main'); + var constants = _dereq_('../core/constants'); + _dereq_('./p5.Shader'); + _dereq_('./p5.RendererGL.Retained'); + + // Text/Typography + // @TODO: + p5.RendererGL.prototype._applyTextProperties = function() { + //@TODO finish implementation + //console.error('text commands not yet implemented in webgl'); + }; + + p5.RendererGL.prototype.textWidth = function(s) { + if (this._isOpenType()) { + return this._textFont._textWidth(s, this._textSize); + } + + return 0; // TODO: error + }; + + // rendering constants + + // the number of rows/columns dividing each glyph + var charGridWidth = 9; + var charGridHeight = charGridWidth; + + // size of the image holding the bezier stroke info + var strokeImageWidth = 64; + var strokeImageHeight = 64; + + // size of the image holding the stroke indices for each row/col + var gridImageWidth = 64; + var gridImageHeight = 64; + + // size of the image holding the offset/length of each row/col stripe + var cellImageWidth = 64; + var cellImageHeight = 64; + + /** + * @private + * @class ImageInfos + * @param {Integer} width + * @param {Integer} height + * + * the ImageInfos class holds a list of ImageDatas of a given size. + */ + function ImageInfos(width, height) { + this.width = width; + this.height = height; + this.infos = []; // the list of images + + /** + * + * @method findImage + * @param {Integer} space + * @return {Object} contains the ImageData, and pixel index into that + * ImageData where the free space was allocated. + * + * finds free space of a given size in the ImageData list + */ + this.findImage = function(space) { + var imageSize = this.width * this.height; + if (space > imageSize) throw new Error('font is too complex to render in 3D'); + + // search through the list of images, looking for one with + // anough unused space. + var imageInfo, imageData; + for (var ii = this.infos.length - 1; ii >= 0; --ii) { + var imageInfoTest = this.infos[ii]; + if (imageInfoTest.index + space < imageSize) { + // found one + imageInfo = imageInfoTest; + imageData = imageInfoTest.imageData; + break; + } + } + + if (!imageInfo) { + try { + // create a new image + imageData = new ImageData(this.width, this.height); + } catch (err) { + // for browsers that don't support ImageData constructors (ie IE11) + // create an ImageData using the old method + var canvas = document.getElementsByTagName('canvas')[0]; + var created = !canvas; + if (!canvas) { + // create a temporary canvas + canvas = document.createElement('canvas'); + canvas.style.display = 'none'; + document.body.appendChild(canvas); + } + var ctx = canvas.getContext('2d'); + if (ctx) { + imageData = ctx.createImageData(this.width, this.height); + } + if (created) { + // distroy the temporary canvas, if necessary + document.body.removeChild(canvas); + } + } + // construct & dd the new image info + imageInfo = { index: 0, imageData: imageData }; + this.infos.push(imageInfo); + } + + var index = imageInfo.index; + imageInfo.index += space; // move to the start of the next image + imageData._dirty = true; + return { imageData: imageData, index: index }; + }; + } + + /** + * @function setPixel + * @param {Object} imageInfo + * @param {Number} r + * @param {Number} g + * @param {Number} b + * @param {Number} a + * + * writes the next pixel into an indexed ImageData + */ + function setPixel(imageInfo, r, g, b, a) { + var imageData = imageInfo.imageData; + var pixels = imageData.data; + var index = imageInfo.index++ * 4; + pixels[index++] = r; + pixels[index++] = g; + pixels[index++] = b; + pixels[index++] = a; + } + + var SQRT3 = Math.sqrt(3); + + /** + * @private + * @class FontInfo + * @param {Object} font an opentype.js font object + * + * contains cached images and glyph information for an opentype font + */ + var FontInfo = function FontInfo(font) { + this.font = font; + // the bezier curve coordinates + this.strokeImageInfos = new ImageInfos(strokeImageWidth, strokeImageHeight); + // lists of curve indices for each row/column slice + this.colDimImageInfos = new ImageInfos(gridImageWidth, gridImageHeight); + this.rowDimImageInfos = new ImageInfos(gridImageWidth, gridImageHeight); + // the offset & length of each row/col slice in the glyph + this.colCellImageInfos = new ImageInfos(cellImageWidth, cellImageHeight); + this.rowCellImageInfos = new ImageInfos(cellImageWidth, cellImageHeight); + + // the cached information for each glyph + this.glyphInfos = {}; + + /** + * @method getGlyphInfo + * @param {Glyph} glyph the x positions of points in the curve + * @returns {Object} the glyphInfo for that glyph + * + * calculates rendering info for a glyph, including the curve information, + * row & column stripes compiled into textures. + */ + + this.getGlyphInfo = function(glyph) { + // check the cache + var gi = this.glyphInfos[glyph.index]; + if (gi) return gi; + + // get the bounding box of the glyph from opentype.js + var bb = glyph.getBoundingBox(); + var xMin = bb.x1; + var yMin = bb.y1; + var gWidth = bb.x2 - xMin; + var gHeight = bb.y2 - yMin; + var cmds = glyph.path.commands; + // don't bother rendering invisible glyphs + if (gWidth === 0 || gHeight === 0 || !cmds.length) { + return (this.glyphInfos[glyph.index] = {}); + } + + var i; + var strokes = []; // the strokes in this glyph + var rows = []; // the indices of strokes in each row + var cols = []; // the indices of strokes in each column + for (i = charGridWidth - 1; i >= 0; --i) { + cols.push([]); + } + for (i = charGridHeight - 1; i >= 0; --i) { + rows.push([]); + } + + /** + * @function push + * @param {Number[]} xs the x positions of points in the curve + * @param {Number[]} ys the y positions of points in the curve + * @param {Object} v the curve information + * + * adds a curve to the rows & columns that it intersects with + */ + function push(xs, ys, v) { + var index = strokes.length; // the index of this stroke + strokes.push(v); // add this stroke to the list + + /** + * @function minMax + * @param {Number[]} rg the list of values to compare + * @param {Number} min the initial minimum value + * @param {Number} max the initial maximum value + * + * find the minimum & maximum value in a list of values + */ + function minMax(rg, min, max) { + for (var i = rg.length; i-- > 0; ) { + var v = rg[i]; + if (min > v) min = v; + if (max < v) max = v; + } + return { min: min, max: max }; + } + + // loop through the rows & columns that the curve intersects + // adding the curve to those slices + var mmX = minMax(xs, 1, 0); + var ixMin = Math.max(Math.floor(mmX.min * charGridWidth), 0); + var ixMax = Math.min(Math.ceil(mmX.max * charGridWidth), charGridWidth); + for (var iCol = ixMin; iCol < ixMax; ++iCol) { + cols[iCol].push(index); + } + + var mmY = minMax(ys, 1, 0); + var iyMin = Math.max(Math.floor(mmY.min * charGridHeight), 0); + var iyMax = Math.min(Math.ceil(mmY.max * charGridHeight), charGridHeight); + for (var iRow = iyMin; iRow < iyMax; ++iRow) { + rows[iRow].push(index); + } + } + + /** + * @function clamp + * @param {Number} v the value to clamp + * @param {Number} min the minimum value + * @param {Number} max the maxmimum value + * + * clamps a value between a minimum & maximum value + */ + function clamp(v, min, max) { + if (v < min) return min; + if (v > max) return max; + return v; + } + + /** + * @function byte + * @param {Number} v the value to scale + * + * converts a floating-point number in the range 0-1 to a byte 0-255 + */ + function byte(v) { + return clamp(255 * v, 0, 255); + } + + /** + * @private + * @class Cubic + * @param {Number} p0 the start point of the curve + * @param {Number} c0 the first control point + * @param {Number} c1 the second control point + * @param {Number} p1 the end point + * + * a cubic curve + */ + function Cubic(p0, c0, c1, p1) { + this.p0 = p0; + this.c0 = c0; + this.c1 = c1; + this.p1 = p1; + + /** + * @method toQuadratic + * @return {Object} the quadratic approximation + * + * converts the cubic to a quadtratic approximation by + * picking an appropriate quadratic control point + */ + this.toQuadratic = function() { + return { + x: this.p0.x, + y: this.p0.y, + x1: this.p1.x, + y1: this.p1.y, + cx: ((this.c0.x + this.c1.x) * 3 - (this.p0.x + this.p1.x)) / 4, + cy: ((this.c0.y + this.c1.y) * 3 - (this.p0.y + this.p1.y)) / 4 + }; + }; + + /** + * @method quadError + * @return {Number} the error + * + * calculates the magnitude of error of this curve's + * quadratic approximation. + */ + this.quadError = function() { + return ( + p5.Vector.sub( + p5.Vector.sub(this.p1, this.p0), + p5.Vector.mult(p5.Vector.sub(this.c1, this.c0), 3) + ).mag() / 2 + ); + }; + + /** + * @method split + * @param {Number} t the value (0-1) at which to split + * @return {Cubic} the second part of the curve + * + * splits the cubic into two parts at a point 't' along the curve. + * this cubic keeps its start point and its end point becomes the + * point at 't'. the 'end half is returned. + */ + this.split = function(t) { + var m1 = p5.Vector.lerp(this.p0, this.c0, t); + var m2 = p5.Vector.lerp(this.c0, this.c1, t); + var mm1 = p5.Vector.lerp(m1, m2, t); + + this.c1 = p5.Vector.lerp(this.c1, this.p1, t); + this.c0 = p5.Vector.lerp(m2, this.c1, t); + var pt = p5.Vector.lerp(mm1, this.c0, t); + var part1 = new Cubic(this.p0, m1, mm1, pt); + this.p0 = pt; + return part1; + }; + + /** + * @method splitInflections + * @return {Cubic[]} the non-inflecting pieces of this cubic + * + * returns an array containing 0, 1 or 2 cubics split resulting + * from splitting this cubic at its inflection points. + * this cubic is (potentially) altered and returned in the list. + */ + this.splitInflections = function() { + var a = p5.Vector.sub(this.c0, this.p0); + var b = p5.Vector.sub(p5.Vector.sub(this.c1, this.c0), a); + var c = p5.Vector.sub( + p5.Vector.sub(p5.Vector.sub(this.p1, this.c1), a), + p5.Vector.mult(b, 2) + ); + + var cubics = []; + + // find the derivative coefficients + var A = b.x * c.y - b.y * c.x; + if (A !== 0) { + var B = a.x * c.y - a.y * c.x; + var C = a.x * b.y - a.y * b.x; + var disc = B * B - 4 * A * C; + if (disc >= 0) { + if (A < 0) { + A = -A; + B = -B; + C = -C; + } + + var Q = Math.sqrt(disc); + var t0 = (-B - Q) / (2 * A); // the first inflection point + var t1 = (-B + Q) / (2 * A); // the second inflection point + + // test if the first inflection point lies on the curve + if (t0 > 0 && t0 < 1) { + // split at the first inflection point + cubics.push(this.split(t0)); + // scale t2 into the second part + t1 = 1 - (1 - t1) / (1 - t0); + } + + // test if the second inflection point lies on the curve + if (t1 > 0 && t1 < 1) { + // split at the second inflection point + cubics.push(this.split(t1)); + } + } + } + + cubics.push(this); + return cubics; + }; + } + + /** + * @function cubicToQuadratics + * @param {Number} x0 + * @param {Number} y0 + * @param {Number} cx0 + * @param {Number} cy0 + * @param {Number} cx1 + * @param {Number} cy1 + * @param {Number} x1 + * @param {Number} y1 + * @returns {Cubic[]} an array of cubics whose quadratic approximations + * closely match the civen cubic. + * + * converts a cubic curve to a list of quadratics. + */ + function cubicToQuadratics(x0, y0, cx0, cy0, cx1, cy1, x1, y1) { + // create the Cubic object and split it at its inflections + var cubics = new Cubic( + new p5.Vector(x0, y0), + new p5.Vector(cx0, cy0), + new p5.Vector(cx1, cy1), + new p5.Vector(x1, y1) + ).splitInflections(); + + var qs = []; // the final list of quadratics + var precision = 30 / SQRT3; + + // for each of the non-inflected pieces of the original cubic + for (var i = 0; i < cubics.length; i++) { + var cubic = cubics[i]; + + // the cubic is iteratively split in 3 pieces: + // the first piece is accumulated in 'qs', the result. + // the last piece is accumulated in 'tail', temporarily. + // the middle piece is repeatedly split again, while necessary. + var tail = []; + + var t3; + for (;;) { + // calculate this cubic's precision + t3 = precision / cubic.quadError(); + if (t3 >= 0.5 * 0.5 * 0.5) { + break; // not too bad, we're done + } + + // find a split point based on the error + var t = Math.pow(t3, 1.0 / 3.0); + // split the cubic in 3 + var start = cubic.split(t); + var middle = cubic.split(1 - t / (1 - t)); + + qs.push(start); // the first part + tail.push(cubic); // the last part + cubic = middle; // iterate on the middle piece + } + + if (t3 < 1) { + // a little excess error, split the middle in two + qs.push(cubic.split(0.5)); + } + // add the middle piece to the result + qs.push(cubic); + + // finally add the tail, reversed, onto the result + Array.prototype.push.apply(qs, tail.reverse()); + } + + return qs; + } + + /** + * @function pushLine + * @param {Number} x0 + * @param {Number} y0 + * @param {Number} x1 + * @param {Number} y1 + * + * add a straight line to the row/col grid of a glyph + */ + function pushLine(x0, y0, x1, y1) { + var mx = (x0 + x1) / 2; + var my = (y0 + y1) / 2; + push([x0, x1], [y0, y1], { x: x0, y: y0, cx: mx, cy: my }); + } + + /** + * @function samePoint + * @param {Number} x0 + * @param {Number} y0 + * @param {Number} x1 + * @param {Number} y1 + * @return {Boolean} true if the two points are sufficiently close + * + * tests if two points are close enough to be considered the same + */ + function samePoint(x0, y0, x1, y1) { + return Math.abs(x1 - x0) < 0.00001 && Math.abs(y1 - y0) < 0.00001; + } + + var x0, y0, xs, ys; + for (var iCmd = 0; iCmd < cmds.length; ++iCmd) { + var cmd = cmds[iCmd]; + // scale the coordinates to the range 0-1 + var x1 = (cmd.x - xMin) / gWidth; + var y1 = (cmd.y - yMin) / gHeight; + + // don't bother if this point is the same as the last + if (samePoint(x0, y0, x1, y1)) continue; + + switch (cmd.type) { + case 'M': // move + xs = x1; + ys = y1; + break; + case 'L': // line + pushLine(x0, y0, x1, y1); + break; + case 'Q': // quadratic + var cx = (cmd.x1 - xMin) / gWidth; + var cy = (cmd.y1 - yMin) / gHeight; + push([x0, x1, cx], [y0, y1, cy], { x: x0, y: y0, cx: cx, cy: cy }); + break; + case 'Z': // end + if (!samePoint(x0, y0, xs, ys)) { + // add an extra line closing the loop, if necessary + pushLine(x0, y0, xs, ys); + strokes.push({ x: xs, y: ys }); + } else { + strokes.push({ x: x0, y: y0 }); + } + break; + case 'C': // cubic + var cx1 = (cmd.x1 - xMin) / gWidth; + var cy1 = (cmd.y1 - yMin) / gHeight; + var cx2 = (cmd.x2 - xMin) / gWidth; + var cy2 = (cmd.y2 - yMin) / gHeight; + var qs = cubicToQuadratics(x0, y0, cx1, cy1, cx2, cy2, x1, y1); + for (var iq = 0; iq < qs.length; iq++) { + var q = qs[iq].toQuadratic(); + push([q.x, q.x1, q.cx], [q.y, q.y1, q.cy], q); + } + break; + default: + throw new Error('unknown command type: ' + cmd.type); + } + + x0 = x1; + y0 = y1; + } + + // allocate space for the strokes + var strokeCount = strokes.length; + var strokeImageInfo = this.strokeImageInfos.findImage(strokeCount); + var strokeOffset = strokeImageInfo.index; + + // fill the stroke image + for (var il = 0; il < strokeCount; ++il) { + var s = strokes[il]; + setPixel(strokeImageInfo, byte(s.x), byte(s.y), byte(s.cx), byte(s.cy)); + } + + /** + * @function layout + * @param {Number[][]} dim + * @param {ImageInfo[]} dimImageInfos + * @param {ImageInfo[]} cellImageInfos + * @return {Object} + * + * lays out the curves in a dimension (row or col) into two + * images, one for the indices of the curves themselves, and + * one containing the offset and length of those index spans. + */ + function layout(dim, dimImageInfos, cellImageInfos) { + var dimLength = dim.length; // the number of slices in this dimension + var dimImageInfo = dimImageInfos.findImage(dimLength); + var dimOffset = dimImageInfo.index; + // calculate the total number of stroke indices in this dimension + var totalStrokes = 0; + for (var id = 0; id < dimLength; ++id) { + totalStrokes += dim[id].length; + } + + // allocate space for the stroke indices + var cellImageInfo = cellImageInfos.findImage(totalStrokes); + + // for each slice in the glyph + for (var i = 0; i < dimLength; ++i) { + var strokeIndices = dim[i]; + var strokeCount = strokeIndices.length; + var cellLineIndex = cellImageInfo.index; + + // write the offset and count into the glyph slice image + setPixel( + dimImageInfo, + cellLineIndex >> 7, + cellLineIndex & 0x7f, + strokeCount >> 7, + strokeCount & 0x7f + ); + + // for each stroke index in that slice + for (var iil = 0; iil < strokeCount; ++iil) { + // write the stroke index into the slice's image + var strokeIndex = strokeIndices[iil] + strokeOffset; + setPixel(cellImageInfo, strokeIndex >> 7, strokeIndex & 0x7f, 0, 0); + } + } + + return { + cellImageInfo: cellImageInfo, + dimOffset: dimOffset, + dimImageInfo: dimImageInfo + }; + } + + // initialize the info for this glyph + gi = this.glyphInfos[glyph.index] = { + glyph: glyph, + uGlyphRect: [bb.x1, -bb.y1, bb.x2, -bb.y2], + strokeImageInfo: strokeImageInfo, + strokes: strokes, + colInfo: layout(cols, this.colDimImageInfos, this.colCellImageInfos), + rowInfo: layout(rows, this.rowDimImageInfos, this.rowCellImageInfos) + }; + + gi.uGridOffset = [gi.colInfo.dimOffset, gi.rowInfo.dimOffset]; + return gi; + }; + }; + + p5.RendererGL.prototype._renderText = function(p, line, x, y, maxY) { + if (!this._textFont || typeof this._textFont === 'string') { + console.log( + 'WEBGL: you must load and set a font before drawing text. See `loadFont` and `textFont` for more details.' + ); + + return; + } + if (y >= maxY || !this._doFill) { + return; // don't render lines beyond our maxY position + } + + if (!this._isOpenType()) { + console.log('WEBGL: only opentype fonts are supported'); + return p; + } + + p.push(); // fix to #803 + + // remember this state, so it can be restored later + var doStroke = this._doStroke; + var drawMode = this.drawMode; + + this._doStroke = false; + this.drawMode = constants.TEXTURE; + + // get the cached FontInfo object + var font = this._textFont.font; + var fontInfo = this._textFont._fontInfo; + if (!fontInfo) { + fontInfo = this._textFont._fontInfo = new FontInfo(font); + } + + // calculate the alignment and move/scale the view accordingly + var pos = this._textFont._handleAlignment(this, line, x, y); + var fontSize = this._textSize; + var scale = fontSize / font.unitsPerEm; + this.translate(pos.x, pos.y, 0); + this.scale(scale, scale, 1); + + // initialize the font shader + var gl = this.GL; + var initializeShader = !this._defaultFontShader; + var sh = this._getFontShader(); + sh.init(); + sh.bindShader(); // first time around, bind the shader fully + + if (initializeShader) { + // these are constants, really. just initialize them one-time. + sh.setUniform('uGridImageSize', [gridImageWidth, gridImageHeight]); + sh.setUniform('uCellsImageSize', [cellImageWidth, cellImageHeight]); + sh.setUniform('uStrokeImageSize', [strokeImageWidth, strokeImageHeight]); + sh.setUniform('uGridSize', [charGridWidth, charGridHeight]); + } + this._applyColorBlend(this.curFillColor); + + var g = this.gHash['glyph']; + if (!g) { + // create the geometry for rendering a quad + var geom = (this._textGeom = new p5.Geometry(1, 1, function() { + for (var i = 0; i <= 1; i++) { + for (var j = 0; j <= 1; j++) { + this.vertices.push(new p5.Vector(j, i, 0)); + this.uvs.push(j, i); + } + } + })); + geom.computeFaces().computeNormals(); + g = this.createBuffers('glyph', geom); + } + + // bind the shader buffers + this._prepareBuffers(g, sh, p5.RendererGL._textBuffers); + this._bindBuffer(g.indexBuffer, gl.ELEMENT_ARRAY_BUFFER); + + // this will have to do for now... + sh.setUniform('uMaterialColor', this.curFillColor); + + try { + var dx = 0; // the x position in the line + var glyphPrev = null; // the previous glyph, used for kerning + // fetch the glyphs in the line of text + var glyphs = font.stringToGlyphs(line); + for (var ig = 0; ig < glyphs.length; ++ig) { + var glyph = glyphs[ig]; + // kern + if (glyphPrev) dx += font.getKerningValue(glyphPrev, glyph); + + var gi = fontInfo.getGlyphInfo(glyph); + if (gi.uGlyphRect) { + var rowInfo = gi.rowInfo; + var colInfo = gi.colInfo; + sh.setUniform('uSamplerStrokes', gi.strokeImageInfo.imageData); + sh.setUniform('uSamplerRowStrokes', rowInfo.cellImageInfo.imageData); + sh.setUniform('uSamplerRows', rowInfo.dimImageInfo.imageData); + sh.setUniform('uSamplerColStrokes', colInfo.cellImageInfo.imageData); + sh.setUniform('uSamplerCols', colInfo.dimImageInfo.imageData); + sh.setUniform('uGridOffset', gi.uGridOffset); + sh.setUniform('uGlyphRect', gi.uGlyphRect); + sh.setUniform('uGlyphOffset', dx); + + sh.bindTextures(); // afterwards, only textures need updating + + // draw it + gl.drawElements(gl.TRIANGLES, 6, this.GL.UNSIGNED_SHORT, 0); + } + dx += glyph.advanceWidth; + glyphPrev = glyph; + } + } finally { + // clean up + sh.unbindShader(); + + this._doStroke = doStroke; + this.drawMode = drawMode; + + p.pop(); + } + + this._pixelsState._pixelsDirty = true; + return p; + }; + }, + { + '../core/constants': 18, + '../core/main': 24, + './p5.RendererGL.Retained': 74, + './p5.Shader': 76 + } + ] + }, + {}, + [13] + )(13); +}); diff --git a/resources/public/js/optimized/clojure/string.cljs b/resources/public/js/optimized/clojure/string.cljs new file mode 100644 index 0000000..26f63f2 --- /dev/null +++ b/resources/public/js/optimized/clojure/string.cljs @@ -0,0 +1,289 @@ +; Copyright (c) Rich Hickey. All rights reserved. +; The use and distribution terms for this software are covered by the +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +; which can be found in the file epl-v10.html at the root of this distribution. +; By using this software in any fashion, you are agreeing to be bound by +; the terms of this license. +; You must not remove this notice, or any other, from this software. + +(ns clojure.string + (:refer-clojure :exclude [replace reverse]) + (:require [goog.string :as gstring]) + (:import [goog.string StringBuffer])) + +(defn- seq-reverse + [coll] + (reduce conj () coll)) + +(def ^:private re-surrogate-pair + (js/RegExp. "([\\uD800-\\uDBFF])([\\uDC00-\\uDFFF])" "g")) + +(defn reverse + "Returns s with its characters reversed." + [s] + (-> (.replace s re-surrogate-pair "$2$1") + (.. (split "") (reverse) (join "")))) + +(defn- replace-all + [s re replacement] + (let [r (js/RegExp. (.-source re) + (cond-> "g" + (.-ignoreCase re) (str "i") + (.-multiline re) (str "m") + (.-unicode re) (str "u")))] + (.replace s r replacement))) + +(defn- replace-with + [f] + (fn [& args] + (let [matches (drop-last 2 args)] + (if (= (count matches) 1) + (f (first matches)) + (f (vec matches)))))) + +(defn replace + "Replaces all instance of match with replacement in s. + + match/replacement can be: + + string / string + pattern / (string or function of match). + + See also replace-first. + + The replacement is literal (i.e. none of its characters are treated + specially) for all cases above except pattern / string. + + For pattern / string, $1, $2, etc. in the replacement string are + substituted with the string that matched the corresponding + parenthesized group in the pattern. + + Example: + (clojure.string/replace \"Almost Pig Latin\" #\"\\b(\\w)(\\w+)\\b\" \"$2$1ay\") + -> \"lmostAay igPay atinLay\"" + [s match replacement] + (cond + (string? match) + (.replace s (js/RegExp. (gstring/regExpEscape match) "g") replacement) + + (instance? js/RegExp match) + (if (string? replacement) + (replace-all s match replacement) + (replace-all s match (replace-with replacement))) + + :else (throw (str "Invalid match arg: " match)))) + +(defn replace-first + "Replaces the first instance of match with replacement in s. + + match/replacement can be: + + string / string + pattern / (string or function of match). + + See also replace. + + The replacement is literal (i.e. none of its characters are treated + specially) for all cases above except pattern / string. + + For pattern / string, $1, $2, etc. in the replacement string are + substituted with the string that matched the corresponding + parenthesized group in the pattern. + + Example: + (clojure.string/replace-first \"swap first two words\" + #\"(\\w+)(\\s+)(\\w+)\" \"$3$2$1\") + -> \"first swap two words\"" + [s match replacement] + (.replace s match replacement)) + +(defn join + "Returns a string of all elements in coll, as returned by (seq coll), + separated by an optional separator." + ([coll] + (loop [sb (StringBuffer.) coll (seq coll)] + (if-not (nil? coll) + (recur (. sb (append (str (first coll)))) (next coll)) + (.toString sb)))) + ([separator coll] + (loop [sb (StringBuffer.) coll (seq coll)] + (if-not (nil? coll) + (do + (. sb (append (str (first coll)))) + (let [coll (next coll)] + (when-not (nil? coll) + (. sb (append separator))) + (recur sb coll))) + (.toString sb))))) + +(defn upper-case + "Converts string to all upper-case." + [s] + (.toUpperCase s)) + +(defn lower-case + "Converts string to all lower-case." + [s] + (.toLowerCase s)) + +(defn capitalize + "Converts first character of the string to upper-case, all other + characters to lower-case." + [s] + (gstring/capitalize s)) + +;; The JavaScript split function takes a limit argument but the return +;; value is not the same as the Java split function. +;; +;; Java: (.split "a-b-c" #"-" 2) => ["a" "b-c"] +;; JavaScript: (.split "a-b-c" #"-" 2) => ["a" "b"] +;; +;; For consistency, the three arg version has been implemented to +;; mimic Java's behavior. + +(defn- pop-last-while-empty + [v] + (loop [v v] + (if (identical? "" (peek v)) + (recur (pop v)) + v))) + +(defn- discard-trailing-if-needed + [limit v] + (if (and (== 0 limit) (< 1 (count v))) + (pop-last-while-empty v) + v)) + +(defn- split-with-empty-regex + [s limit] + (if (or (<= limit 0) (>= limit (+ 2 (count s)))) + (conj (vec (cons "" (map str (seq s)))) "") + (condp == limit + 1 (vector s) + 2 (vector "" s) + (let [c (- limit 2)] + (conj (vec (cons "" (subvec (vec (map str (seq s))) 0 c))) (subs s c)))))) + +(defn split + "Splits string on a regular expression. Optional argument limit is + the maximum number of splits. Not lazy. Returns vector of the splits." + ([s re] + (split s re 0)) + ([s re limit] + (discard-trailing-if-needed limit + (if (identical? "/(?:)/" (str re)) + (split-with-empty-regex s limit) + (if (< limit 1) + (vec (.split (str s) re)) + (loop [s s + limit limit + parts []] + (if (== 1 limit) + (conj parts s) + (let [m (re-find re s)] + (if-not (nil? m) + (let [index (.indexOf s m)] + (recur (.substring s (+ index (count m))) + (dec limit) + (conj parts (.substring s 0 index)))) + (conj parts s)))))))))) + +(defn split-lines + "Splits s on \\n or \\r\\n." + [s] + (split s #"\n|\r\n")) + +(defn trim + "Removes whitespace from both ends of string." + [s] + (gstring/trim s)) + +(defn triml + "Removes whitespace from the left side of string." + [s] + (gstring/trimLeft s)) + +(defn trimr + "Removes whitespace from the right side of string." + [s] + (gstring/trimRight s)) + +(defn trim-newline + "Removes all trailing newline \\n or return \\r characters from + string. Similar to Perl's chomp." + [s] + (loop [index (.-length s)] + (if (zero? index) + "" + (let [ch (get s (dec index))] + (if (or (identical? \newline ch) + (identical? \return ch)) + (recur (dec index)) + (.substring s 0 index)))))) + +(defn ^boolean blank? + "True is s is nil, empty, or contains only whitespace." + [s] + (gstring/isEmptySafe s)) + +(defn escape + "Return a new string, using cmap to escape each character ch + from s as follows: + + If (cmap ch) is nil, append ch to the new string. + If (cmap ch) is non-nil, append (str (cmap ch)) instead." + [s cmap] + (let [buffer (StringBuffer.) + length (.-length s)] + (loop [index 0] + (if (== length index) + (. buffer (toString)) + (let [ch (.charAt s index) + replacement (get cmap ch)] + (if-not (nil? replacement) + (.append buffer (str replacement)) + (.append buffer ch)) + (recur (inc index))))))) + +(defn index-of + "Return index of value (string or char) in s, optionally searching + forward from from-index or nil if not found." + ([s value] + (let [result (.indexOf s value)] + (if (neg? result) + nil + result))) + ([s value from-index] + (let [result (.indexOf s value from-index)] + (if (neg? result) + nil + result)))) + +(defn last-index-of + "Return last index of value (string or char) in s, optionally + searching backward from from-index or nil if not found." + ([s value] + (let [result (.lastIndexOf s value)] + (if (neg? result) + nil + result))) + ([s value from-index] + (let [result (.lastIndexOf s value from-index)] + (if (neg? result) + nil + result)))) + +(defn ^boolean starts-with? + "True if s starts with substr." + [s substr] + (gstring/startsWith s substr)) + +(defn ^boolean ends-with? + "True if s ends with substr." + [s substr] + (gstring/endsWith s substr)) + +(defn ^boolean includes? + "True if s includes substr." + [s substr] + (gstring/contains s substr)) diff --git a/resources/public/js/optimized/clojure/string.js b/resources/public/js/optimized/clojure/string.js new file mode 100644 index 0000000..373d4f9 --- /dev/null +++ b/resources/public/js/optimized/clojure/string.js @@ -0,0 +1,478 @@ +// Compiled by ClojureScript 1.10.520 {:static-fns true, :optimize-constants true} +goog.provide('clojure.string'); +goog.require('cljs.core'); +goog.require('cljs.core.constants'); +goog.require('goog.string'); +goog.require('goog.string.StringBuffer'); +clojure.string.seq_reverse = (function clojure$string$seq_reverse(coll){ +return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3(cljs.core.conj,cljs.core.List.EMPTY,coll); +}); +clojure.string.re_surrogate_pair = (new RegExp("([\\uD800-\\uDBFF])([\\uDC00-\\uDFFF])","g")); +/** + * Returns s with its characters reversed. + */ +clojure.string.reverse = (function clojure$string$reverse(s){ +return s.replace(clojure.string.re_surrogate_pair,"$2$1").split("").reverse().join(""); +}); +clojure.string.replace_all = (function clojure$string$replace_all(s,re,replacement){ +var r = (new RegExp(re.source,(function (){var G__5537 = "g"; +var G__5537__$1 = (cljs.core.truth_(re.ignoreCase)?[G__5537,"i"].join(''):G__5537); +var G__5537__$2 = (cljs.core.truth_(re.multiline)?[G__5537__$1,"m"].join(''):G__5537__$1); +if(cljs.core.truth_(re.unicode)){ +return [G__5537__$2,"u"].join(''); +} else { +return G__5537__$2; +} +})())); +return s.replace(r,replacement); +}); +clojure.string.replace_with = (function clojure$string$replace_with(f){ +return (function() { +var G__5540__delegate = function (args){ +var matches = cljs.core.drop_last.cljs$core$IFn$_invoke$arity$2((2),args); +if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.count(matches),(1))){ +var G__5538 = cljs.core.first(matches); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__5538) : f.call(null,G__5538)); +} else { +var G__5539 = cljs.core.vec(matches); +return (f.cljs$core$IFn$_invoke$arity$1 ? f.cljs$core$IFn$_invoke$arity$1(G__5539) : f.call(null,G__5539)); +} +}; +var G__5540 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__5541__i = 0, G__5541__a = new Array(arguments.length - 0); +while (G__5541__i < G__5541__a.length) {G__5541__a[G__5541__i] = arguments[G__5541__i + 0]; ++G__5541__i;} + args = new cljs.core.IndexedSeq(G__5541__a,0,null); +} +return G__5540__delegate.call(this,args);}; +G__5540.cljs$lang$maxFixedArity = 0; +G__5540.cljs$lang$applyTo = (function (arglist__5542){ +var args = cljs.core.seq(arglist__5542); +return G__5540__delegate(args); +}); +G__5540.cljs$core$IFn$_invoke$arity$variadic = G__5540__delegate; +return G__5540; +})() +; +}); +/** + * Replaces all instance of match with replacement in s. + * + * match/replacement can be: + * + * string / string + * pattern / (string or function of match). + * + * See also replace-first. + * + * The replacement is literal (i.e. none of its characters are treated + * specially) for all cases above except pattern / string. + * + * For pattern / string, $1, $2, etc. in the replacement string are + * substituted with the string that matched the corresponding + * parenthesized group in the pattern. + * + * Example: + * (clojure.string/replace "Almost Pig Latin" #"\b(\w)(\w+)\b" "$2$1ay") + * -> "lmostAay igPay atinLay" + */ +clojure.string.replace = (function clojure$string$replace(s,match,replacement){ +if(typeof match === 'string'){ +return s.replace((new RegExp(goog.string.regExpEscape(match),"g")),replacement); +} else { +if((match instanceof RegExp)){ +if(typeof replacement === 'string'){ +return clojure.string.replace_all(s,match,replacement); +} else { +return clojure.string.replace_all(s,match,clojure.string.replace_with(replacement)); +} +} else { +throw ["Invalid match arg: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(match)].join(''); + +} +} +}); +/** + * Replaces the first instance of match with replacement in s. + * + * match/replacement can be: + * + * string / string + * pattern / (string or function of match). + * + * See also replace. + * + * The replacement is literal (i.e. none of its characters are treated + * specially) for all cases above except pattern / string. + * + * For pattern / string, $1, $2, etc. in the replacement string are + * substituted with the string that matched the corresponding + * parenthesized group in the pattern. + * + * Example: + * (clojure.string/replace-first "swap first two words" + * #"(\w+)(\s+)(\w+)" "$3$2$1") + * -> "first swap two words" + */ +clojure.string.replace_first = (function clojure$string$replace_first(s,match,replacement){ +return s.replace(match,replacement); +}); +/** + * Returns a string of all elements in coll, as returned by (seq coll), + * separated by an optional separator. + */ +clojure.string.join = (function clojure$string$join(var_args){ +var G__5544 = arguments.length; +switch (G__5544) { +case 1: +return clojure.string.join.cljs$core$IFn$_invoke$arity$1((arguments[(0)])); + +break; +case 2: +return clojure.string.join.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +clojure.string.join.cljs$core$IFn$_invoke$arity$1 = (function (coll){ +var sb = (new goog.string.StringBuffer()); +var coll__$1 = cljs.core.seq(coll); +while(true){ +if((!((coll__$1 == null)))){ +var G__5546 = sb.append(cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.first(coll__$1))); +var G__5547 = cljs.core.next(coll__$1); +sb = G__5546; +coll__$1 = G__5547; +continue; +} else { +return sb.toString(); +} +break; +} +}); + +clojure.string.join.cljs$core$IFn$_invoke$arity$2 = (function (separator,coll){ +var sb = (new goog.string.StringBuffer()); +var coll__$1 = cljs.core.seq(coll); +while(true){ +if((!((coll__$1 == null)))){ +sb.append(cljs.core.str.cljs$core$IFn$_invoke$arity$1(cljs.core.first(coll__$1))); + +var coll__$2 = cljs.core.next(coll__$1); +if((coll__$2 == null)){ +} else { +sb.append(separator); +} + +var G__5548 = sb; +var G__5549 = coll__$2; +sb = G__5548; +coll__$1 = G__5549; +continue; +} else { +return sb.toString(); +} +break; +} +}); + +clojure.string.join.cljs$lang$maxFixedArity = 2; + +/** + * Converts string to all upper-case. + */ +clojure.string.upper_case = (function clojure$string$upper_case(s){ +return s.toUpperCase(); +}); +/** + * Converts string to all lower-case. + */ +clojure.string.lower_case = (function clojure$string$lower_case(s){ +return s.toLowerCase(); +}); +/** + * Converts first character of the string to upper-case, all other + * characters to lower-case. + */ +clojure.string.capitalize = (function clojure$string$capitalize(s){ +return goog.string.capitalize(s); +}); +clojure.string.pop_last_while_empty = (function clojure$string$pop_last_while_empty(v){ +var v__$1 = v; +while(true){ +if(("" === cljs.core.peek(v__$1))){ +var G__5550 = cljs.core.pop(v__$1); +v__$1 = G__5550; +continue; +} else { +return v__$1; +} +break; +} +}); +clojure.string.discard_trailing_if_needed = (function clojure$string$discard_trailing_if_needed(limit,v){ +if(((((0) === limit)) && (((1) < cljs.core.count(v))))){ +return clojure.string.pop_last_while_empty(v); +} else { +return v; +} +}); +clojure.string.split_with_empty_regex = (function clojure$string$split_with_empty_regex(s,limit){ +if((((limit <= (0))) || ((limit >= ((2) + cljs.core.count(s)))))){ +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(cljs.core.vec(cljs.core.cons("",cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.str,cljs.core.seq(s)))),""); +} else { +var pred__5551 = cljs.core._EQ__EQ_; +var expr__5552 = limit; +if(cljs.core.truth_((pred__5551.cljs$core$IFn$_invoke$arity$2 ? pred__5551.cljs$core$IFn$_invoke$arity$2((1),expr__5552) : pred__5551.call(null,(1),expr__5552)))){ +return (new cljs.core.PersistentVector(null,1,(5),cljs.core.PersistentVector.EMPTY_NODE,[s],null)); +} else { +if(cljs.core.truth_((pred__5551.cljs$core$IFn$_invoke$arity$2 ? pred__5551.cljs$core$IFn$_invoke$arity$2((2),expr__5552) : pred__5551.call(null,(2),expr__5552)))){ +return (new cljs.core.PersistentVector(null,2,(5),cljs.core.PersistentVector.EMPTY_NODE,["",s],null)); +} else { +var c = (limit - (2)); +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(cljs.core.vec(cljs.core.cons("",cljs.core.subvec.cljs$core$IFn$_invoke$arity$3(cljs.core.vec(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.str,cljs.core.seq(s))),(0),c))),cljs.core.subs.cljs$core$IFn$_invoke$arity$2(s,c)); +} +} +} +}); +/** + * Splits string on a regular expression. Optional argument limit is + * the maximum number of splits. Not lazy. Returns vector of the splits. + */ +clojure.string.split = (function clojure$string$split(var_args){ +var G__5555 = arguments.length; +switch (G__5555) { +case 2: +return clojure.string.split.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return clojure.string.split.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +clojure.string.split.cljs$core$IFn$_invoke$arity$2 = (function (s,re){ +return clojure.string.split.cljs$core$IFn$_invoke$arity$3(s,re,(0)); +}); + +clojure.string.split.cljs$core$IFn$_invoke$arity$3 = (function (s,re,limit){ +return clojure.string.discard_trailing_if_needed(limit,((("/(?:)/" === cljs.core.str.cljs$core$IFn$_invoke$arity$1(re)))?clojure.string.split_with_empty_regex(s,limit):(((limit < (1)))?cljs.core.vec(cljs.core.str.cljs$core$IFn$_invoke$arity$1(s).split(re)):(function (){var s__$1 = s; +var limit__$1 = limit; +var parts = cljs.core.PersistentVector.EMPTY; +while(true){ +if(((1) === limit__$1)){ +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(parts,s__$1); +} else { +var m = cljs.core.re_find(re,s__$1); +if((!((m == null)))){ +var index = s__$1.indexOf(m); +var G__5557 = s__$1.substring((index + cljs.core.count(m))); +var G__5558 = (limit__$1 - (1)); +var G__5559 = cljs.core.conj.cljs$core$IFn$_invoke$arity$2(parts,s__$1.substring((0),index)); +s__$1 = G__5557; +limit__$1 = G__5558; +parts = G__5559; +continue; +} else { +return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(parts,s__$1); +} +} +break; +} +})()))); +}); + +clojure.string.split.cljs$lang$maxFixedArity = 3; + +/** + * Splits s on \n or \r\n. + */ +clojure.string.split_lines = (function clojure$string$split_lines(s){ +return clojure.string.split.cljs$core$IFn$_invoke$arity$2(s,/\n|\r\n/); +}); +/** + * Removes whitespace from both ends of string. + */ +clojure.string.trim = (function clojure$string$trim(s){ +return goog.string.trim(s); +}); +/** + * Removes whitespace from the left side of string. + */ +clojure.string.triml = (function clojure$string$triml(s){ +return goog.string.trimLeft(s); +}); +/** + * Removes whitespace from the right side of string. + */ +clojure.string.trimr = (function clojure$string$trimr(s){ +return goog.string.trimRight(s); +}); +/** + * Removes all trailing newline \n or return \r characters from + * string. Similar to Perl's chomp. + */ +clojure.string.trim_newline = (function clojure$string$trim_newline(s){ +var index = s.length; +while(true){ +if((index === (0))){ +return ""; +} else { +var ch = cljs.core.get.cljs$core$IFn$_invoke$arity$2(s,(index - (1))); +if(((("\n" === ch)) || (("\r" === ch)))){ +var G__5560 = (index - (1)); +index = G__5560; +continue; +} else { +return s.substring((0),index); +} +} +break; +} +}); +/** + * True is s is nil, empty, or contains only whitespace. + */ +clojure.string.blank_QMARK_ = (function clojure$string$blank_QMARK_(s){ +return goog.string.isEmptySafe(s); +}); +/** + * Return a new string, using cmap to escape each character ch + * from s as follows: + * + * If (cmap ch) is nil, append ch to the new string. + * If (cmap ch) is non-nil, append (str (cmap ch)) instead. + */ +clojure.string.escape = (function clojure$string$escape(s,cmap){ +var buffer = (new goog.string.StringBuffer()); +var length = s.length; +var index = (0); +while(true){ +if((length === index)){ +return buffer.toString(); +} else { +var ch = s.charAt(index); +var replacement = cljs.core.get.cljs$core$IFn$_invoke$arity$2(cmap,ch); +if((!((replacement == null)))){ +buffer.append(cljs.core.str.cljs$core$IFn$_invoke$arity$1(replacement)); +} else { +buffer.append(ch); +} + +var G__5561 = (index + (1)); +index = G__5561; +continue; +} +break; +} +}); +/** + * Return index of value (string or char) in s, optionally searching + * forward from from-index or nil if not found. + */ +clojure.string.index_of = (function clojure$string$index_of(var_args){ +var G__5563 = arguments.length; +switch (G__5563) { +case 2: +return clojure.string.index_of.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return clojure.string.index_of.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +clojure.string.index_of.cljs$core$IFn$_invoke$arity$2 = (function (s,value){ +var result = s.indexOf(value); +if((result < (0))){ +return null; +} else { +return result; +} +}); + +clojure.string.index_of.cljs$core$IFn$_invoke$arity$3 = (function (s,value,from_index){ +var result = s.indexOf(value,from_index); +if((result < (0))){ +return null; +} else { +return result; +} +}); + +clojure.string.index_of.cljs$lang$maxFixedArity = 3; + +/** + * Return last index of value (string or char) in s, optionally + * searching backward from from-index or nil if not found. + */ +clojure.string.last_index_of = (function clojure$string$last_index_of(var_args){ +var G__5566 = arguments.length; +switch (G__5566) { +case 2: +return clojure.string.last_index_of.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); + +break; +case 3: +return clojure.string.last_index_of.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); + +break; +default: +throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); + +} +}); + +clojure.string.last_index_of.cljs$core$IFn$_invoke$arity$2 = (function (s,value){ +var result = s.lastIndexOf(value); +if((result < (0))){ +return null; +} else { +return result; +} +}); + +clojure.string.last_index_of.cljs$core$IFn$_invoke$arity$3 = (function (s,value,from_index){ +var result = s.lastIndexOf(value,from_index); +if((result < (0))){ +return null; +} else { +return result; +} +}); + +clojure.string.last_index_of.cljs$lang$maxFixedArity = 3; + +/** + * True if s starts with substr. + */ +clojure.string.starts_with_QMARK_ = (function clojure$string$starts_with_QMARK_(s,substr){ +return goog.string.startsWith(s,substr); +}); +/** + * True if s ends with substr. + */ +clojure.string.ends_with_QMARK_ = (function clojure$string$ends_with_QMARK_(s,substr){ +return goog.string.endsWith(s,substr); +}); +/** + * True if s includes substr. + */ +clojure.string.includes_QMARK_ = (function clojure$string$includes_QMARK_(s,substr){ +return goog.string.contains(s,substr); +}); diff --git a/resources/public/js/optimized/curlnoise/core.js b/resources/public/js/optimized/curlnoise/core.js new file mode 100644 index 0000000..40931d2 --- /dev/null +++ b/resources/public/js/optimized/curlnoise/core.js @@ -0,0 +1,560 @@ +// Compiled by ClojureScript 1.10.520 {:static-fns true, :optimize-constants true} +goog.provide('curlnoise.core'); +goog.require('cljs.core'); +goog.require('cljs.core.constants'); +goog.require('quil.core'); +goog.require('quil.middleware'); +curlnoise.core.framerate = (60); +curlnoise.core.res_x = (500); +curlnoise.core.res_y = curlnoise.core.res_x; +curlnoise.core.grid_size = (10); +curlnoise.core.alpha = (40); +curlnoise.core.renderer = cljs.core.cst$kw$p2d; +curlnoise.core.grid = (function curlnoise$core$grid(nx,ny){ + +return cljs.core.mapcat.cljs$core$IFn$_invoke$arity$variadic((function (x){ +return cljs.core.map.cljs$core$IFn$_invoke$arity$2((function (y){ +return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [x,y], null); +}),cljs.core.range.cljs$core$IFn$_invoke$arity$1(ny)); +}),cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([cljs.core.range.cljs$core$IFn$_invoke$arity$1(nx)], 0)); +}); +curlnoise.core.pix_grid = (function curlnoise$core$pix_grid(grid_size,res_x,res_y){ + +var nx = ((res_x / grid_size) | (0)); +var ny = ((res_y / grid_size) | (0)); +var offset = ((grid_size / (2)) | (0)); +var x2pix = ((function (nx,ny,offset){ +return (function (p1__6098_SHARP_){ +return (offset + quil.core.map_range(p1__6098_SHARP_,(0),nx,(0),res_x)); +});})(nx,ny,offset)) +; +var y2pix = ((function (nx,ny,offset,x2pix){ +return (function (p1__6099_SHARP_){ +return (offset + quil.core.map_range(p1__6099_SHARP_,(0),ny,(0),res_y)); +});})(nx,ny,offset,x2pix)) +; +return cljs.core.map.cljs$core$IFn$_invoke$arity$2(((function (nx,ny,offset,x2pix,y2pix){ +return (function (p__6100){ +var vec__6101 = p__6100; +var i = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6101,(0),null); +var j = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6101,(1),null); +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [i,j,x2pix(i),y2pix(j)], null); +});})(nx,ny,offset,x2pix,y2pix)) +,curlnoise.core.grid(nx,ny)); +}); +curlnoise.core.ramp = (function curlnoise$core$ramp(r){ + +if((r >= 1.0)){ +return 1.0; +} else { +if((r <= -1.0)){ +return -1.0; +} else { +var c1 = (15.0 / 8.0); +var c3 = (-10.0 / 8.0); +var c5 = (3.0 / 8.0); +return (((r * c1) + (Math.pow(r,(3)) * c3)) + (Math.pow(r,(5)) * c5)); + +} +} +}); +curlnoise.core.dist2 = (function curlnoise$core$dist2(x,y){ +return ((x * x) + (y * y)); +}); +curlnoise.core.dist = (function curlnoise$core$dist(x,y){ +var G__6104 = curlnoise.core.dist2(x,y); +return Math.sqrt(G__6104); +}); +curlnoise.core.clamp = (function curlnoise$core$clamp(v,v0,v1){ +if((v < v0)){ +return v0; +} else { +if((v > v1)){ +return v1; +} else { +return v; + +} +} +}); +curlnoise.core.setup = (function curlnoise$core$setup(){ +quil.core.background.cljs$core$IFn$_invoke$arity$1((255)); + +quil.core.frame_rate(curlnoise.core.framerate); + +var gr = quil.core.create_graphics.cljs$core$IFn$_invoke$arity$2(curlnoise.core.res_x,curlnoise.core.res_y); +var gr__575__auto___6107 = gr; +var _STAR_graphics_STAR__orig_val__6105_6108 = quil.core._STAR_graphics_STAR_; +var _STAR_graphics_STAR__temp_val__6106_6109 = gr__575__auto___6107; +quil.core._STAR_graphics_STAR_ = _STAR_graphics_STAR__temp_val__6106_6109; + +try{quil.core.begin_draw(gr__575__auto___6107); + +quil.core.background.cljs$core$IFn$_invoke$arity$2((255),curlnoise.core.alpha); + +quil.core.end_draw(gr__575__auto___6107); +}finally {quil.core._STAR_graphics_STAR_ = _STAR_graphics_STAR__orig_val__6105_6108; +} +return new cljs.core.PersistentArrayMap(null, 3, [cljs.core.cst$kw$frame,(0),cljs.core.cst$kw$grid,curlnoise.core.pix_grid(curlnoise.core.grid_size,curlnoise.core.res_x,curlnoise.core.res_y),cljs.core.cst$kw$blend,gr], null); +}); +curlnoise.core.sdf_box = (function curlnoise$core$sdf_box(px,py,bx,by){ +var bx2 = (0.5 * bx); +var by2 = (0.5 * by); +var dx = ((function (){var G__6110 = (px - bx2); +return Math.abs(G__6110); +})() - bx2); +var dy = ((function (){var G__6111 = (py - by2); +return Math.abs(G__6111); +})() - by2); +var l = (curlnoise.core.dist((function (){var x__4219__auto__ = 0.0; +var y__4220__auto__ = dx; +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +})(),(function (){var x__4219__auto__ = 0.0; +var y__4220__auto__ = dy; +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +})()) + (function (){var x__4222__auto__ = (function (){var x__4219__auto__ = dx; +var y__4220__auto__ = dy; +return ((x__4219__auto__ > y__4220__auto__) ? x__4219__auto__ : y__4220__auto__); +})(); +var y__4223__auto__ = 0.0; +return ((x__4222__auto__ < y__4223__auto__) ? x__4222__auto__ : y__4223__auto__); +})()); +return l; +}); +curlnoise.core.update_state = (function curlnoise$core$update_state(state){ +var w = quil.core.width(); +var h = quil.core.height(); +var vf = 0.1; +var scale = 400.0; +var noise_scale = (scale * 10.0); +var rad = 20.0; +var rect_rad = 100.0; +var margin = (0); +var eps = (w * 0.001); +var mx = quil.core.mouse_x(); +var my = quil.core.mouse_y(); +var f_inv = ((1) / scale); +var d0 = 150.0; +var d_mouse = ((function (w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0){ +return (function (p1__6112_SHARP_,p2__6113_SHARP_){ +if(cljs.core.truth_(quil.core.mouse_pressed_QMARK_())){ +return (curlnoise.core.dist((mx - p1__6112_SHARP_),(my - p2__6113_SHARP_)) - rad); +} else { +return 1000000.0; +} +});})(w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0)) +; +var d_border = ((function (w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse){ +return (function (p1__6114_SHARP_,p2__6115_SHARP_){ +return (rect_rad - curlnoise.core.sdf_box((p1__6114_SHARP_ - rect_rad),(p2__6115_SHARP_ - rect_rad),(w - (rect_rad * (2))),(h - (rect_rad * (2))))); +});})(w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse)) +; +var amp_fn = ((function (w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border){ +return (function (_,___$1){ +return 1.0; +});})(w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border)) +; +var mouse_drift = ((function (w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border,amp_fn){ +return (function (p1__6117_SHARP_,p2__6116_SHARP_){ +if(cljs.core.truth_(quil.core.mouse_pressed_QMARK_())){ +return (((((mx / w) - 0.5) * p2__6116_SHARP_) * 0.01) + ((((my / h) - 0.5) * p1__6117_SHARP_) * -0.01)); +} else { +return 0.0; +} +});})(w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border,amp_fn)) +; +var n_fn = ((function (w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border,amp_fn,mouse_drift){ +return (function (p1__6118_SHARP_,p2__6119_SHARP_,p3__6120_SHARP_){ +return (noise_scale * (mouse_drift(p1__6118_SHARP_,p2__6119_SHARP_) + quil.core.noise.cljs$core$IFn$_invoke$arity$3((f_inv * p1__6118_SHARP_),(f_inv * p2__6119_SHARP_),(f_inv * p3__6120_SHARP_)))); +});})(w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border,amp_fn,mouse_drift)) +; +var p_fn = ((function (w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border,amp_fn,mouse_drift,n_fn){ +return (function (p1__6121_SHARP_,p2__6122_SHARP_,p3__6123_SHARP_){ +return ((vf * amp_fn(p1__6121_SHARP_,p2__6122_SHARP_)) * n_fn(p1__6121_SHARP_,p2__6122_SHARP_,p3__6123_SHARP_)); +});})(w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border,amp_fn,mouse_drift,n_fn)) +; +var points = cljs.core.map.cljs$core$IFn$_invoke$arity$2(((function (w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border,amp_fn,mouse_drift,n_fn,p_fn){ +return (function (pt){ +var vec__6124 = pt; +var i = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6124,(0),null); +var j = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6124,(1),null); +var x = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6124,(2),null); +var y = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6124,(3),null); +var z = (cljs.core.cst$kw$frame.cljs$core$IFn$_invoke$arity$1(state) / 20.0); +var border = (((((((x > margin)) && ((x < (w - margin))))) && ((((y > margin)) && ((x < (h - margin)))))))?1.0:0.0); +var n = p_fn(x,y,z); +var n_dx = p_fn((x + eps),y,z); +var n_dy = p_fn(x,(y + eps),z); +var vx = ((n_dy - n) / eps); +var vy = ((n - n_dx) / eps); +var x2 = (x + vx); +var y2 = (y + vy); +var vec__6127 = (((((x2 < (0))) || ((x2 > w)) || ((y2 < (0))) || ((y2 > h))))?new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [quil.core.random.cljs$core$IFn$_invoke$arity$1(w),quil.core.random.cljs$core$IFn$_invoke$arity$1(h)], null):new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [x2,y2], null)); +var x3 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6127,(0),null); +var y3 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6127,(1),null); +return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [i,j,x3,y3], null); +});})(w,h,vf,scale,noise_scale,rad,rect_rad,margin,eps,mx,my,f_inv,d0,d_mouse,d_border,amp_fn,mouse_drift,n_fn,p_fn)) +,cljs.core.cst$kw$grid.cljs$core$IFn$_invoke$arity$1(state)); +return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(cljs.core.update.cljs$core$IFn$_invoke$arity$3(state,cljs.core.cst$kw$frame,cljs.core.inc),cljs.core.cst$kw$grid,points); +}); +curlnoise.core.show_fn = false; +curlnoise.core.draw_field = (function curlnoise$core$draw_field(offset,sdf,domain_xform){ +var pix = quil.core.pixels.cljs$core$IFn$_invoke$arity$0(); +var w = quil.core.width(); +var h = quil.core.height(); +var seq__6130_6170 = cljs.core.seq(curlnoise.core.grid(quil.core.width(),quil.core.height())); +var chunk__6131_6171 = null; +var count__6132_6172 = (0); +var i__6133_6173 = (0); +while(true){ +if((i__6133_6173 < count__6132_6172)){ +var point_6174 = chunk__6131_6171.cljs$core$IIndexed$_nth$arity$2(null,i__6133_6173); +var vec__6152_6175 = point_6174; +var px_6176 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6152_6175,(0),null); +var py_6177 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6152_6175,(1),null); +var vec__6155_6178 = (domain_xform.cljs$core$IFn$_invoke$arity$2 ? domain_xform.cljs$core$IFn$_invoke$arity$2(px_6176,py_6177) : domain_xform.call(null,px_6176,py_6177)); +var px2_6179 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6155_6178,(0),null); +var py2_6180 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6155_6178,(1),null); +var w2_6181 = w; +var h2_6182 = h; +var d_6183 = (sdf.cljs$core$IFn$_invoke$arity$2 ? sdf.cljs$core$IFn$_invoke$arity$2(px2_6179,py2_6180) : sdf.call(null,px2_6179,py2_6180)); +var step_6184 = (cljs.core.mod(d_6183,offset) / offset); +var val_6185 = ((step_6184 * (255)) | (0)); +var vec__6158_6186 = (((Math.abs(d_6183) >= (offset * 0.5)))?new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [val_6185,val_6185,val_6185], null):new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [val_6185,0.0,0.0], null)); +var r_6187 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6158_6186,(0),null); +var g_6188 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6158_6186,(1),null); +var b_6189 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6158_6186,(2),null); +var offset_6190__$1 = ((4) * (px_6176 + (py_6177 * w))); +(pix[offset_6190__$1] = r_6187); + +(pix[(offset_6190__$1 + (1))] = g_6188); + +(pix[(offset_6190__$1 + (2))] = b_6189); + +(pix[(offset_6190__$1 + (3))] = (255)); + + +var G__6191 = seq__6130_6170; +var G__6192 = chunk__6131_6171; +var G__6193 = count__6132_6172; +var G__6194 = (i__6133_6173 + (1)); +seq__6130_6170 = G__6191; +chunk__6131_6171 = G__6192; +count__6132_6172 = G__6193; +i__6133_6173 = G__6194; +continue; +} else { +var temp__5735__auto___6195 = cljs.core.seq(seq__6130_6170); +if(temp__5735__auto___6195){ +var seq__6130_6196__$1 = temp__5735__auto___6195; +if(cljs.core.chunked_seq_QMARK_(seq__6130_6196__$1)){ +var c__4550__auto___6197 = cljs.core.chunk_first(seq__6130_6196__$1); +var G__6198 = cljs.core.chunk_rest(seq__6130_6196__$1); +var G__6199 = c__4550__auto___6197; +var G__6200 = cljs.core.count(c__4550__auto___6197); +var G__6201 = (0); +seq__6130_6170 = G__6198; +chunk__6131_6171 = G__6199; +count__6132_6172 = G__6200; +i__6133_6173 = G__6201; +continue; +} else { +var point_6202 = cljs.core.first(seq__6130_6196__$1); +var vec__6161_6203 = point_6202; +var px_6204 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6161_6203,(0),null); +var py_6205 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6161_6203,(1),null); +var vec__6164_6206 = (domain_xform.cljs$core$IFn$_invoke$arity$2 ? domain_xform.cljs$core$IFn$_invoke$arity$2(px_6204,py_6205) : domain_xform.call(null,px_6204,py_6205)); +var px2_6207 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6164_6206,(0),null); +var py2_6208 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6164_6206,(1),null); +var w2_6209 = w; +var h2_6210 = h; +var d_6211 = (sdf.cljs$core$IFn$_invoke$arity$2 ? sdf.cljs$core$IFn$_invoke$arity$2(px2_6207,py2_6208) : sdf.call(null,px2_6207,py2_6208)); +var step_6212 = (cljs.core.mod(d_6211,offset) / offset); +var val_6213 = ((step_6212 * (255)) | (0)); +var vec__6167_6214 = (((Math.abs(d_6211) >= (offset * 0.5)))?new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [val_6213,val_6213,val_6213], null):new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [val_6213,0.0,0.0], null)); +var r_6215 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6167_6214,(0),null); +var g_6216 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6167_6214,(1),null); +var b_6217 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6167_6214,(2),null); +var offset_6218__$1 = ((4) * (px_6204 + (py_6205 * w))); +(pix[offset_6218__$1] = r_6215); + +(pix[(offset_6218__$1 + (1))] = g_6216); + +(pix[(offset_6218__$1 + (2))] = b_6217); + +(pix[(offset_6218__$1 + (3))] = (255)); + + +var G__6219 = cljs.core.next(seq__6130_6196__$1); +var G__6220 = null; +var G__6221 = (0); +var G__6222 = (0); +seq__6130_6170 = G__6219; +chunk__6131_6171 = G__6220; +count__6132_6172 = G__6221; +i__6133_6173 = G__6222; +continue; +} +} else { +} +} +break; +} + +return quil.core.update_pixels.cljs$core$IFn$_invoke$arity$0(); +}); +curlnoise.core.draw_state = (function curlnoise$core$draw_state(state){ +quil.core.image.cljs$core$IFn$_invoke$arity$3(cljs.core.cst$kw$blend.cljs$core$IFn$_invoke$arity$1(state),(0),(0)); + +var pix = quil.core.pixels.cljs$core$IFn$_invoke$arity$0(); +var w = quil.core.width(); +var h = quil.core.height(); +var color = quil.core.color.cljs$core$IFn$_invoke$arity$1((0)); +var rad = (50); +if(curlnoise.core.show_fn){ +curlnoise.core.draw_field(10.0,((function (pix,w,h,color,rad){ +return (function (p1__6223_SHARP_,p2__6224_SHARP_){ +return (rad - curlnoise.core.sdf_box(p1__6223_SHARP_,p2__6224_SHARP_,(quil.core.width() - (rad * (2))),(quil.core.height() - (rad * (2))))); +});})(pix,w,h,color,rad)) +,((function (pix,w,h,color,rad){ +return (function (p1__6225_SHARP_,p2__6226_SHARP_){ +return cljs.core.vec(new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [((p1__6225_SHARP_ - rad) - 0.0),((p2__6226_SHARP_ - rad) - 0.0)], null)); +});})(pix,w,h,color,rad)) +); +} else { +var seq__6227_6243 = cljs.core.seq(cljs.core.cst$kw$grid.cljs$core$IFn$_invoke$arity$1(state)); +var chunk__6228_6244 = null; +var count__6229_6245 = (0); +var i__6230_6246 = (0); +while(true){ +if((i__6230_6246 < count__6229_6245)){ +var point_6247 = chunk__6228_6244.cljs$core$IIndexed$_nth$arity$2(null,i__6230_6246); +var vec__6237_6248 = point_6247; +var __6249 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6237_6248,(0),null); +var __6250__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6237_6248,(1),null); +var px_6251 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6237_6248,(2),null); +var py_6252 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6237_6248,(3),null); +var ix_6253 = curlnoise.core.clamp((px_6251 | (0)),(0),(w - (1))); +var iy_6254 = curlnoise.core.clamp((py_6252 | (0)),(0),(h - (1))); +var offset_6255 = ((4) * (ix_6253 + (iy_6254 * w))); +(pix[offset_6255] = (0)); + +(pix[(offset_6255 + (1))] = (0)); + +(pix[(offset_6255 + (2))] = (0)); + +(pix[(offset_6255 + (3))] = (255)); + + +var G__6256 = seq__6227_6243; +var G__6257 = chunk__6228_6244; +var G__6258 = count__6229_6245; +var G__6259 = (i__6230_6246 + (1)); +seq__6227_6243 = G__6256; +chunk__6228_6244 = G__6257; +count__6229_6245 = G__6258; +i__6230_6246 = G__6259; +continue; +} else { +var temp__5735__auto___6260 = cljs.core.seq(seq__6227_6243); +if(temp__5735__auto___6260){ +var seq__6227_6261__$1 = temp__5735__auto___6260; +if(cljs.core.chunked_seq_QMARK_(seq__6227_6261__$1)){ +var c__4550__auto___6262 = cljs.core.chunk_first(seq__6227_6261__$1); +var G__6263 = cljs.core.chunk_rest(seq__6227_6261__$1); +var G__6264 = c__4550__auto___6262; +var G__6265 = cljs.core.count(c__4550__auto___6262); +var G__6266 = (0); +seq__6227_6243 = G__6263; +chunk__6228_6244 = G__6264; +count__6229_6245 = G__6265; +i__6230_6246 = G__6266; +continue; +} else { +var point_6267 = cljs.core.first(seq__6227_6261__$1); +var vec__6240_6268 = point_6267; +var __6269 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6240_6268,(0),null); +var __6270__$1 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6240_6268,(1),null); +var px_6271 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6240_6268,(2),null); +var py_6272 = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__6240_6268,(3),null); +var ix_6273 = curlnoise.core.clamp((px_6271 | (0)),(0),(w - (1))); +var iy_6274 = curlnoise.core.clamp((py_6272 | (0)),(0),(h - (1))); +var offset_6275 = ((4) * (ix_6273 + (iy_6274 * w))); +(pix[offset_6275] = (0)); + +(pix[(offset_6275 + (1))] = (0)); + +(pix[(offset_6275 + (2))] = (0)); + +(pix[(offset_6275 + (3))] = (255)); + + +var G__6276 = cljs.core.next(seq__6227_6261__$1); +var G__6277 = null; +var G__6278 = (0); +var G__6279 = (0); +seq__6227_6243 = G__6276; +chunk__6228_6244 = G__6277; +count__6229_6245 = G__6278; +i__6230_6246 = G__6279; +continue; +} +} else { +} +} +break; +} +} + +return quil.core.update_pixels.cljs$core$IFn$_invoke$arity$0(); +}); +curlnoise.core.settings = (function curlnoise$core$settings(){ +return quil.core.pixel_density((1)); +}); +curlnoise.core.run_sketch = (function curlnoise$core$run_sketch(){ +curlnoise.core.curlnoise = (function curlnoise$core$run_sketch_$_curlnoise(){ +return quil.sketch.sketch.cljs$core$IFn$_invoke$arity$variadic(cljs.core.prim_seq.cljs$core$IFn$_invoke$arity$2([cljs.core.cst$kw$features,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$kw$keep_DASH_on_DASH_top], null),cljs.core.cst$kw$settings,((cljs.core.fn_QMARK_(curlnoise.core.settings))?(function() { +var G__6280__delegate = function (args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(curlnoise.core.settings,args); +}; +var G__6280 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__6281__i = 0, G__6281__a = new Array(arguments.length - 0); +while (G__6281__i < G__6281__a.length) {G__6281__a[G__6281__i] = arguments[G__6281__i + 0]; ++G__6281__i;} + args = new cljs.core.IndexedSeq(G__6281__a,0,null); +} +return G__6280__delegate.call(this,args);}; +G__6280.cljs$lang$maxFixedArity = 0; +G__6280.cljs$lang$applyTo = (function (arglist__6282){ +var args = cljs.core.seq(arglist__6282); +return G__6280__delegate(args); +}); +G__6280.cljs$core$IFn$_invoke$arity$variadic = G__6280__delegate; +return G__6280; +})() +:curlnoise.core.settings),cljs.core.cst$kw$update,((cljs.core.fn_QMARK_(curlnoise.core.update_state))?(function() { +var G__6283__delegate = function (args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(curlnoise.core.update_state,args); +}; +var G__6283 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__6284__i = 0, G__6284__a = new Array(arguments.length - 0); +while (G__6284__i < G__6284__a.length) {G__6284__a[G__6284__i] = arguments[G__6284__i + 0]; ++G__6284__i;} + args = new cljs.core.IndexedSeq(G__6284__a,0,null); +} +return G__6283__delegate.call(this,args);}; +G__6283.cljs$lang$maxFixedArity = 0; +G__6283.cljs$lang$applyTo = (function (arglist__6285){ +var args = cljs.core.seq(arglist__6285); +return G__6283__delegate(args); +}); +G__6283.cljs$core$IFn$_invoke$arity$variadic = G__6283__delegate; +return G__6283; +})() +:curlnoise.core.update_state),cljs.core.cst$kw$renderer,((cljs.core.fn_QMARK_(curlnoise.core.renderer))?(function() { +var G__6286__delegate = function (args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(curlnoise.core.renderer,args); +}; +var G__6286 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__6287__i = 0, G__6287__a = new Array(arguments.length - 0); +while (G__6287__i < G__6287__a.length) {G__6287__a[G__6287__i] = arguments[G__6287__i + 0]; ++G__6287__i;} + args = new cljs.core.IndexedSeq(G__6287__a,0,null); +} +return G__6286__delegate.call(this,args);}; +G__6286.cljs$lang$maxFixedArity = 0; +G__6286.cljs$lang$applyTo = (function (arglist__6288){ +var args = cljs.core.seq(arglist__6288); +return G__6286__delegate(args); +}); +G__6286.cljs$core$IFn$_invoke$arity$variadic = G__6286__delegate; +return G__6286; +})() +:curlnoise.core.renderer),cljs.core.cst$kw$size,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [curlnoise.core.res_x,curlnoise.core.res_y], null),cljs.core.cst$kw$title,"Curl Noise",cljs.core.cst$kw$setup,((cljs.core.fn_QMARK_(curlnoise.core.setup))?(function() { +var G__6289__delegate = function (args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(curlnoise.core.setup,args); +}; +var G__6289 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__6290__i = 0, G__6290__a = new Array(arguments.length - 0); +while (G__6290__i < G__6290__a.length) {G__6290__a[G__6290__i] = arguments[G__6290__i + 0]; ++G__6290__i;} + args = new cljs.core.IndexedSeq(G__6290__a,0,null); +} +return G__6289__delegate.call(this,args);}; +G__6289.cljs$lang$maxFixedArity = 0; +G__6289.cljs$lang$applyTo = (function (arglist__6291){ +var args = cljs.core.seq(arglist__6291); +return G__6289__delegate(args); +}); +G__6289.cljs$core$IFn$_invoke$arity$variadic = G__6289__delegate; +return G__6289; +})() +:curlnoise.core.setup),cljs.core.cst$kw$middleware,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [quil.middleware.fun_mode], null),cljs.core.cst$kw$host,"curlnoise",cljs.core.cst$kw$draw,((cljs.core.fn_QMARK_(curlnoise.core.draw_state))?(function() { +var G__6292__delegate = function (args){ +return cljs.core.apply.cljs$core$IFn$_invoke$arity$2(curlnoise.core.draw_state,args); +}; +var G__6292 = function (var_args){ +var args = null; +if (arguments.length > 0) { +var G__6293__i = 0, G__6293__a = new Array(arguments.length - 0); +while (G__6293__i < G__6293__a.length) {G__6293__a[G__6293__i] = arguments[G__6293__i + 0]; ++G__6293__i;} + args = new cljs.core.IndexedSeq(G__6293__a,0,null); +} +return G__6292__delegate.call(this,args);}; +G__6292.cljs$lang$maxFixedArity = 0; +G__6292.cljs$lang$applyTo = (function (arglist__6294){ +var args = cljs.core.seq(arglist__6294); +return G__6292__delegate(args); +}); +G__6292.cljs$core$IFn$_invoke$arity$variadic = G__6292__delegate; +return G__6292; +})() +:curlnoise.core.draw_state)], 0)); +}); +goog.exportSymbol('curlnoise.core.curlnoise', curlnoise.core.curlnoise); + +if(cljs.core.truth_(cljs.core.some((function (p1__201__202__auto__){ +return cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(cljs.core.cst$kw$no_DASH_start,p1__201__202__auto__); +}),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.cst$kw$keep_DASH_on_DASH_top], null)))){ +return null; +} else { +return quil.sketch.add_sketch_to_init_list(new cljs.core.PersistentArrayMap(null, 2, [cljs.core.cst$kw$fn,curlnoise.core.curlnoise,cljs.core.cst$kw$host_DASH_id,"curlnoise"], null)); +} +}); +goog.exportSymbol('curlnoise.core.run_sketch', curlnoise.core.run_sketch); +curlnoise.core._main = (function curlnoise$core$_main(var_args){ +var args__4736__auto__ = []; +var len__4730__auto___6296 = arguments.length; +var i__4731__auto___6297 = (0); +while(true){ +if((i__4731__auto___6297 < len__4730__auto___6296)){ +args__4736__auto__.push((arguments[i__4731__auto___6297])); + +var G__6298 = (i__4731__auto___6297 + (1)); +i__4731__auto___6297 = G__6298; +continue; +} else { +} +break; +} + +var argseq__4737__auto__ = ((((0) < args__4736__auto__.length))?(new cljs.core.IndexedSeq(args__4736__auto__.slice((0)),(0),null)):null); +return curlnoise.core._main.cljs$core$IFn$_invoke$arity$variadic(argseq__4737__auto__); +}); + +curlnoise.core._main.cljs$core$IFn$_invoke$arity$variadic = (function (args){ +return curlnoise.core.run_sketch(); +}); + +curlnoise.core._main.cljs$lang$maxFixedArity = (0); + +/** @this {Function} */ +curlnoise.core._main.cljs$lang$applyTo = (function (seq6295){ +var self__4718__auto__ = this; +return self__4718__auto__.cljs$core$IFn$_invoke$arity$variadic(cljs.core.seq(seq6295)); +}); + diff --git a/resources/public/js/optimized/goog/array/array.js b/resources/public/js/optimized/goog/array/array.js new file mode 100644 index 0000000..47e0dbb --- /dev/null +++ b/resources/public/js/optimized/goog/array/array.js @@ -0,0 +1,1665 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Utilities for manipulating arrays. + * + * @author arv@google.com (Erik Arvidsson) + */ + + +goog.provide('goog.array'); + +goog.require('goog.asserts'); + + +/** + * @define {boolean} NATIVE_ARRAY_PROTOTYPES indicates whether the code should + * rely on Array.prototype functions, if available. + * + * The Array.prototype functions can be defined by external libraries like + * Prototype and setting this flag to false forces closure to use its own + * goog.array implementation. + * + * If your javascript can be loaded by a third party site and you are wary about + * relying on the prototype functions, specify + * "--define goog.NATIVE_ARRAY_PROTOTYPES=false" to the JSCompiler. + * + * Setting goog.TRUSTED_SITE to false will automatically set + * NATIVE_ARRAY_PROTOTYPES to false. + */ +goog.define('goog.NATIVE_ARRAY_PROTOTYPES', goog.TRUSTED_SITE); + + +/** + * @define {boolean} If true, JSCompiler will use the native implementation of + * array functions where appropriate (e.g., {@code Array#filter}) and remove the + * unused pure JS implementation. + */ +goog.define('goog.array.ASSUME_NATIVE_FUNCTIONS', false); + + +/** + * Returns the last element in an array without removing it. + * Same as goog.array.last. + * @param {IArrayLike|string} array The array. + * @return {T} Last item in array. + * @template T + */ +goog.array.peek = function(array) { + return array[array.length - 1]; +}; + + +/** + * Returns the last element in an array without removing it. + * Same as goog.array.peek. + * @param {IArrayLike|string} array The array. + * @return {T} Last item in array. + * @template T + */ +goog.array.last = goog.array.peek; + +// NOTE(arv): Since most of the array functions are generic it allows you to +// pass an array-like object. Strings have a length and are considered array- +// like. However, the 'in' operator does not work on strings so we cannot just +// use the array path even if the browser supports indexing into strings. We +// therefore end up splitting the string. + + +/** + * Returns the index of the first element of an array with a specified value, or + * -1 if the element is not present in the array. + * + * See {@link http://tinyurl.com/developer-mozilla-org-array-indexof} + * + * @param {IArrayLike|string} arr The array to be searched. + * @param {T} obj The object for which we are searching. + * @param {number=} opt_fromIndex The index at which to start the search. If + * omitted the search starts at index 0. + * @return {number} The index of the first matching array element. + * @template T + */ +goog.array.indexOf = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.indexOf) ? + function(arr, obj, opt_fromIndex) { + goog.asserts.assert(arr.length != null); + + return Array.prototype.indexOf.call(arr, obj, opt_fromIndex); + } : + function(arr, obj, opt_fromIndex) { + var fromIndex = opt_fromIndex == null ? + 0 : + (opt_fromIndex < 0 ? Math.max(0, arr.length + opt_fromIndex) : + opt_fromIndex); + + if (goog.isString(arr)) { + // Array.prototype.indexOf uses === so only strings should be found. + if (!goog.isString(obj) || obj.length != 1) { + return -1; + } + return arr.indexOf(obj, fromIndex); + } + + for (var i = fromIndex; i < arr.length; i++) { + if (i in arr && arr[i] === obj) return i; + } + return -1; + }; + + +/** + * Returns the index of the last element of an array with a specified value, or + * -1 if the element is not present in the array. + * + * See {@link http://tinyurl.com/developer-mozilla-org-array-lastindexof} + * + * @param {!IArrayLike|string} arr The array to be searched. + * @param {T} obj The object for which we are searching. + * @param {?number=} opt_fromIndex The index at which to start the search. If + * omitted the search starts at the end of the array. + * @return {number} The index of the last matching array element. + * @template T + */ +goog.array.lastIndexOf = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.lastIndexOf) ? + function(arr, obj, opt_fromIndex) { + goog.asserts.assert(arr.length != null); + + // Firefox treats undefined and null as 0 in the fromIndex argument which + // leads it to always return -1 + var fromIndex = opt_fromIndex == null ? arr.length - 1 : opt_fromIndex; + return Array.prototype.lastIndexOf.call(arr, obj, fromIndex); + } : + function(arr, obj, opt_fromIndex) { + var fromIndex = opt_fromIndex == null ? arr.length - 1 : opt_fromIndex; + + if (fromIndex < 0) { + fromIndex = Math.max(0, arr.length + fromIndex); + } + + if (goog.isString(arr)) { + // Array.prototype.lastIndexOf uses === so only strings should be found. + if (!goog.isString(obj) || obj.length != 1) { + return -1; + } + return arr.lastIndexOf(obj, fromIndex); + } + + for (var i = fromIndex; i >= 0; i--) { + if (i in arr && arr[i] === obj) return i; + } + return -1; + }; + + +/** + * Calls a function for each element in an array. Skips holes in the array. + * See {@link http://tinyurl.com/developer-mozilla-org-array-foreach} + * + * @param {IArrayLike|string} arr Array or array like object over + * which to iterate. + * @param {?function(this: S, T, number, ?): ?} f The function to call for every + * element. This function takes 3 arguments (the element, the index and the + * array). The return value is ignored. + * @param {S=} opt_obj The object to be used as the value of 'this' within f. + * @template T,S + */ +goog.array.forEach = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.forEach) ? + function(arr, f, opt_obj) { + goog.asserts.assert(arr.length != null); + + Array.prototype.forEach.call(arr, f, opt_obj); + } : + function(arr, f, opt_obj) { + var l = arr.length; // must be fixed during loop... see docs + var arr2 = goog.isString(arr) ? arr.split('') : arr; + for (var i = 0; i < l; i++) { + if (i in arr2) { + f.call(/** @type {?} */ (opt_obj), arr2[i], i, arr); + } + } + }; + + +/** + * Calls a function for each element in an array, starting from the last + * element rather than the first. + * + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this: S, T, number, ?): ?} f The function to call for every + * element. This function + * takes 3 arguments (the element, the index and the array). The return + * value is ignored. + * @param {S=} opt_obj The object to be used as the value of 'this' + * within f. + * @template T,S + */ +goog.array.forEachRight = function(arr, f, opt_obj) { + var l = arr.length; // must be fixed during loop... see docs + var arr2 = goog.isString(arr) ? arr.split('') : arr; + for (var i = l - 1; i >= 0; --i) { + if (i in arr2) { + f.call(/** @type {?} */ (opt_obj), arr2[i], i, arr); + } + } +}; + + +/** + * Calls a function for each element in an array, and if the function returns + * true adds the element to a new array. + * + * See {@link http://tinyurl.com/developer-mozilla-org-array-filter} + * + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?):boolean} f The function to call for + * every element. This function + * takes 3 arguments (the element, the index and the array) and must + * return a Boolean. If the return value is true the element is added to the + * result array. If it is false the element is not included. + * @param {S=} opt_obj The object to be used as the value of 'this' + * within f. + * @return {!Array} a new array in which only elements that passed the test + * are present. + * @template T,S + */ +goog.array.filter = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.filter) ? + function(arr, f, opt_obj) { + goog.asserts.assert(arr.length != null); + + return Array.prototype.filter.call(arr, f, opt_obj); + } : + function(arr, f, opt_obj) { + var l = arr.length; // must be fixed during loop... see docs + var res = []; + var resLength = 0; + var arr2 = goog.isString(arr) ? arr.split('') : arr; + for (var i = 0; i < l; i++) { + if (i in arr2) { + var val = arr2[i]; // in case f mutates arr2 + if (f.call(/** @type {?} */ (opt_obj), val, i, arr)) { + res[resLength++] = val; + } + } + } + return res; + }; + + +/** + * Calls a function for each element in an array and inserts the result into a + * new array. + * + * See {@link http://tinyurl.com/developer-mozilla-org-array-map} + * + * @param {IArrayLike|string} arr Array or array like object + * over which to iterate. + * @param {function(this:THIS, VALUE, number, ?): RESULT} f The function to call + * for every element. This function takes 3 arguments (the element, + * the index and the array) and should return something. The result will be + * inserted into a new array. + * @param {THIS=} opt_obj The object to be used as the value of 'this' within f. + * @return {!Array} a new array with the results from f. + * @template THIS, VALUE, RESULT + */ +goog.array.map = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.map) ? + function(arr, f, opt_obj) { + goog.asserts.assert(arr.length != null); + + return Array.prototype.map.call(arr, f, opt_obj); + } : + function(arr, f, opt_obj) { + var l = arr.length; // must be fixed during loop... see docs + var res = new Array(l); + var arr2 = goog.isString(arr) ? arr.split('') : arr; + for (var i = 0; i < l; i++) { + if (i in arr2) { + res[i] = f.call(/** @type {?} */ (opt_obj), arr2[i], i, arr); + } + } + return res; + }; + + +/** + * Passes every element of an array into a function and accumulates the result. + * + * See {@link http://tinyurl.com/developer-mozilla-org-array-reduce} + * + * For example: + * var a = [1, 2, 3, 4]; + * goog.array.reduce(a, function(r, v, i, arr) {return r + v;}, 0); + * returns 10 + * + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {function(this:S, R, T, number, ?) : R} f The function to call for + * every element. This function + * takes 4 arguments (the function's previous result or the initial value, + * the value of the current array element, the current array index, and the + * array itself) + * function(previousValue, currentValue, index, array). + * @param {?} val The initial value to pass into the function on the first call. + * @param {S=} opt_obj The object to be used as the value of 'this' + * within f. + * @return {R} Result of evaluating f repeatedly across the values of the array. + * @template T,S,R + */ +goog.array.reduce = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.reduce) ? + function(arr, f, val, opt_obj) { + goog.asserts.assert(arr.length != null); + if (opt_obj) { + f = goog.bind(f, opt_obj); + } + return Array.prototype.reduce.call(arr, f, val); + } : + function(arr, f, val, opt_obj) { + var rval = val; + goog.array.forEach(arr, function(val, index) { + rval = f.call(/** @type {?} */ (opt_obj), rval, val, index, arr); + }); + return rval; + }; + + +/** + * Passes every element of an array into a function and accumulates the result, + * starting from the last element and working towards the first. + * + * See {@link http://tinyurl.com/developer-mozilla-org-array-reduceright} + * + * For example: + * var a = ['a', 'b', 'c']; + * goog.array.reduceRight(a, function(r, v, i, arr) {return r + v;}, ''); + * returns 'cba' + * + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, R, T, number, ?) : R} f The function to call for + * every element. This function + * takes 4 arguments (the function's previous result or the initial value, + * the value of the current array element, the current array index, and the + * array itself) + * function(previousValue, currentValue, index, array). + * @param {?} val The initial value to pass into the function on the first call. + * @param {S=} opt_obj The object to be used as the value of 'this' + * within f. + * @return {R} Object returned as a result of evaluating f repeatedly across the + * values of the array. + * @template T,S,R + */ +goog.array.reduceRight = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.reduceRight) ? + function(arr, f, val, opt_obj) { + goog.asserts.assert(arr.length != null); + goog.asserts.assert(f != null); + if (opt_obj) { + f = goog.bind(f, opt_obj); + } + return Array.prototype.reduceRight.call(arr, f, val); + } : + function(arr, f, val, opt_obj) { + var rval = val; + goog.array.forEachRight(arr, function(val, index) { + rval = f.call(/** @type {?} */ (opt_obj), rval, val, index, arr); + }); + return rval; + }; + + +/** + * Calls f for each element of an array. If any call returns true, some() + * returns true (without checking the remaining elements). If all calls + * return false, some() returns false. + * + * See {@link http://tinyurl.com/developer-mozilla-org-array-some} + * + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?) : boolean} f The function to call for + * for every element. This function takes 3 arguments (the element, the + * index and the array) and should return a boolean. + * @param {S=} opt_obj The object to be used as the value of 'this' + * within f. + * @return {boolean} true if any element passes the test. + * @template T,S + */ +goog.array.some = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.some) ? + function(arr, f, opt_obj) { + goog.asserts.assert(arr.length != null); + + return Array.prototype.some.call(arr, f, opt_obj); + } : + function(arr, f, opt_obj) { + var l = arr.length; // must be fixed during loop... see docs + var arr2 = goog.isString(arr) ? arr.split('') : arr; + for (var i = 0; i < l; i++) { + if (i in arr2 && f.call(/** @type {?} */ (opt_obj), arr2[i], i, arr)) { + return true; + } + } + return false; + }; + + +/** + * Call f for each element of an array. If all calls return true, every() + * returns true. If any call returns false, every() returns false and + * does not continue to check the remaining elements. + * + * See {@link http://tinyurl.com/developer-mozilla-org-array-every} + * + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?) : boolean} f The function to call for + * for every element. This function takes 3 arguments (the element, the + * index and the array) and should return a boolean. + * @param {S=} opt_obj The object to be used as the value of 'this' + * within f. + * @return {boolean} false if any element fails the test. + * @template T,S + */ +goog.array.every = goog.NATIVE_ARRAY_PROTOTYPES && + (goog.array.ASSUME_NATIVE_FUNCTIONS || Array.prototype.every) ? + function(arr, f, opt_obj) { + goog.asserts.assert(arr.length != null); + + return Array.prototype.every.call(arr, f, opt_obj); + } : + function(arr, f, opt_obj) { + var l = arr.length; // must be fixed during loop... see docs + var arr2 = goog.isString(arr) ? arr.split('') : arr; + for (var i = 0; i < l; i++) { + if (i in arr2 && !f.call(/** @type {?} */ (opt_obj), arr2[i], i, arr)) { + return false; + } + } + return true; + }; + + +/** + * Counts the array elements that fulfill the predicate, i.e. for which the + * callback function returns true. Skips holes in the array. + * + * @param {!IArrayLike|string} arr Array or array like object + * over which to iterate. + * @param {function(this: S, T, number, ?): boolean} f The function to call for + * every element. Takes 3 arguments (the element, the index and the array). + * @param {S=} opt_obj The object to be used as the value of 'this' within f. + * @return {number} The number of the matching elements. + * @template T,S + */ +goog.array.count = function(arr, f, opt_obj) { + var count = 0; + goog.array.forEach(arr, function(element, index, arr) { + if (f.call(/** @type {?} */ (opt_obj), element, index, arr)) { + ++count; + } + }, opt_obj); + return count; +}; + + +/** + * Search an array for the first element that satisfies a given condition and + * return that element. + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?) : boolean} f The function to call + * for every element. This function takes 3 arguments (the element, the + * index and the array) and should return a boolean. + * @param {S=} opt_obj An optional "this" context for the function. + * @return {T|null} The first array element that passes the test, or null if no + * element is found. + * @template T,S + */ +goog.array.find = function(arr, f, opt_obj) { + var i = goog.array.findIndex(arr, f, opt_obj); + return i < 0 ? null : goog.isString(arr) ? arr.charAt(i) : arr[i]; +}; + + +/** + * Search an array for the first element that satisfies a given condition and + * return its index. + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?) : boolean} f The function to call for + * every element. This function + * takes 3 arguments (the element, the index and the array) and should + * return a boolean. + * @param {S=} opt_obj An optional "this" context for the function. + * @return {number} The index of the first array element that passes the test, + * or -1 if no element is found. + * @template T,S + */ +goog.array.findIndex = function(arr, f, opt_obj) { + var l = arr.length; // must be fixed during loop... see docs + var arr2 = goog.isString(arr) ? arr.split('') : arr; + for (var i = 0; i < l; i++) { + if (i in arr2 && f.call(/** @type {?} */ (opt_obj), arr2[i], i, arr)) { + return i; + } + } + return -1; +}; + + +/** + * Search an array (in reverse order) for the last element that satisfies a + * given condition and return that element. + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?) : boolean} f The function to call + * for every element. This function + * takes 3 arguments (the element, the index and the array) and should + * return a boolean. + * @param {S=} opt_obj An optional "this" context for the function. + * @return {T|null} The last array element that passes the test, or null if no + * element is found. + * @template T,S + */ +goog.array.findRight = function(arr, f, opt_obj) { + var i = goog.array.findIndexRight(arr, f, opt_obj); + return i < 0 ? null : goog.isString(arr) ? arr.charAt(i) : arr[i]; +}; + + +/** + * Search an array (in reverse order) for the last element that satisfies a + * given condition and return its index. + * @param {IArrayLike|string} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?) : boolean} f The function to call + * for every element. This function + * takes 3 arguments (the element, the index and the array) and should + * return a boolean. + * @param {S=} opt_obj An optional "this" context for the function. + * @return {number} The index of the last array element that passes the test, + * or -1 if no element is found. + * @template T,S + */ +goog.array.findIndexRight = function(arr, f, opt_obj) { + var l = arr.length; // must be fixed during loop... see docs + var arr2 = goog.isString(arr) ? arr.split('') : arr; + for (var i = l - 1; i >= 0; i--) { + if (i in arr2 && f.call(/** @type {?} */ (opt_obj), arr2[i], i, arr)) { + return i; + } + } + return -1; +}; + + +/** + * Whether the array contains the given object. + * @param {IArrayLike|string} arr The array to test for the presence of the + * element. + * @param {*} obj The object for which to test. + * @return {boolean} true if obj is present. + */ +goog.array.contains = function(arr, obj) { + return goog.array.indexOf(arr, obj) >= 0; +}; + + +/** + * Whether the array is empty. + * @param {IArrayLike|string} arr The array to test. + * @return {boolean} true if empty. + */ +goog.array.isEmpty = function(arr) { + return arr.length == 0; +}; + + +/** + * Clears the array. + * @param {IArrayLike} arr Array or array like object to clear. + */ +goog.array.clear = function(arr) { + // For non real arrays we don't have the magic length so we delete the + // indices. + if (!goog.isArray(arr)) { + for (var i = arr.length - 1; i >= 0; i--) { + delete arr[i]; + } + } + arr.length = 0; +}; + + +/** + * Pushes an item into an array, if it's not already in the array. + * @param {Array} arr Array into which to insert the item. + * @param {T} obj Value to add. + * @template T + */ +goog.array.insert = function(arr, obj) { + if (!goog.array.contains(arr, obj)) { + arr.push(obj); + } +}; + + +/** + * Inserts an object at the given index of the array. + * @param {IArrayLike} arr The array to modify. + * @param {*} obj The object to insert. + * @param {number=} opt_i The index at which to insert the object. If omitted, + * treated as 0. A negative index is counted from the end of the array. + */ +goog.array.insertAt = function(arr, obj, opt_i) { + goog.array.splice(arr, opt_i, 0, obj); +}; + + +/** + * Inserts at the given index of the array, all elements of another array. + * @param {IArrayLike} arr The array to modify. + * @param {IArrayLike} elementsToAdd The array of elements to add. + * @param {number=} opt_i The index at which to insert the object. If omitted, + * treated as 0. A negative index is counted from the end of the array. + */ +goog.array.insertArrayAt = function(arr, elementsToAdd, opt_i) { + goog.partial(goog.array.splice, arr, opt_i, 0).apply(null, elementsToAdd); +}; + + +/** + * Inserts an object into an array before a specified object. + * @param {Array} arr The array to modify. + * @param {T} obj The object to insert. + * @param {T=} opt_obj2 The object before which obj should be inserted. If obj2 + * is omitted or not found, obj is inserted at the end of the array. + * @template T + */ +goog.array.insertBefore = function(arr, obj, opt_obj2) { + var i; + if (arguments.length == 2 || (i = goog.array.indexOf(arr, opt_obj2)) < 0) { + arr.push(obj); + } else { + goog.array.insertAt(arr, obj, i); + } +}; + + +/** + * Removes the first occurrence of a particular value from an array. + * @param {IArrayLike} arr Array from which to remove + * value. + * @param {T} obj Object to remove. + * @return {boolean} True if an element was removed. + * @template T + */ +goog.array.remove = function(arr, obj) { + var i = goog.array.indexOf(arr, obj); + var rv; + if ((rv = i >= 0)) { + goog.array.removeAt(arr, i); + } + return rv; +}; + + +/** + * Removes the last occurrence of a particular value from an array. + * @param {!IArrayLike} arr Array from which to remove value. + * @param {T} obj Object to remove. + * @return {boolean} True if an element was removed. + * @template T + */ +goog.array.removeLast = function(arr, obj) { + var i = goog.array.lastIndexOf(arr, obj); + if (i >= 0) { + goog.array.removeAt(arr, i); + return true; + } + return false; +}; + + +/** + * Removes from an array the element at index i + * @param {IArrayLike} arr Array or array like object from which to + * remove value. + * @param {number} i The index to remove. + * @return {boolean} True if an element was removed. + */ +goog.array.removeAt = function(arr, i) { + goog.asserts.assert(arr.length != null); + + // use generic form of splice + // splice returns the removed items and if successful the length of that + // will be 1 + return Array.prototype.splice.call(arr, i, 1).length == 1; +}; + + +/** + * Removes the first value that satisfies the given condition. + * @param {IArrayLike} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?) : boolean} f The function to call + * for every element. This function + * takes 3 arguments (the element, the index and the array) and should + * return a boolean. + * @param {S=} opt_obj An optional "this" context for the function. + * @return {boolean} True if an element was removed. + * @template T,S + */ +goog.array.removeIf = function(arr, f, opt_obj) { + var i = goog.array.findIndex(arr, f, opt_obj); + if (i >= 0) { + goog.array.removeAt(arr, i); + return true; + } + return false; +}; + + +/** + * Removes all values that satisfy the given condition. + * @param {IArrayLike} arr Array or array + * like object over which to iterate. + * @param {?function(this:S, T, number, ?) : boolean} f The function to call + * for every element. This function + * takes 3 arguments (the element, the index and the array) and should + * return a boolean. + * @param {S=} opt_obj An optional "this" context for the function. + * @return {number} The number of items removed + * @template T,S + */ +goog.array.removeAllIf = function(arr, f, opt_obj) { + var removedCount = 0; + goog.array.forEachRight(arr, function(val, index) { + if (f.call(/** @type {?} */ (opt_obj), val, index, arr)) { + if (goog.array.removeAt(arr, index)) { + removedCount++; + } + } + }); + return removedCount; +}; + + +/** + * Returns a new array that is the result of joining the arguments. If arrays + * are passed then their items are added, however, if non-arrays are passed they + * will be added to the return array as is. + * + * Note that ArrayLike objects will be added as is, rather than having their + * items added. + * + * goog.array.concat([1, 2], [3, 4]) -> [1, 2, 3, 4] + * goog.array.concat(0, [1, 2]) -> [0, 1, 2] + * goog.array.concat([1, 2], null) -> [1, 2, null] + * + * There is bug in all current versions of IE (6, 7 and 8) where arrays created + * in an iframe become corrupted soon (not immediately) after the iframe is + * destroyed. This is common if loading data via goog.net.IframeIo, for example. + * This corruption only affects the concat method which will start throwing + * Catastrophic Errors (#-2147418113). + * + * See http://endoflow.com/scratch/corrupted-arrays.html for a test case. + * + * Internally goog.array should use this, so that all methods will continue to + * work on these broken array objects. + * + * @param {...*} var_args Items to concatenate. Arrays will have each item + * added, while primitives and objects will be added as is. + * @return {!Array} The new resultant array. + */ +goog.array.concat = function(var_args) { + return Array.prototype.concat.apply([], arguments); +}; + + +/** + * Returns a new array that contains the contents of all the arrays passed. + * @param {...!Array} var_args + * @return {!Array} + * @template T + */ +goog.array.join = function(var_args) { + return Array.prototype.concat.apply([], arguments); +}; + + +/** + * Converts an object to an array. + * @param {IArrayLike|string} object The object to convert to an + * array. + * @return {!Array} The object converted into an array. If object has a + * length property, every property indexed with a non-negative number + * less than length will be included in the result. If object does not + * have a length property, an empty array will be returned. + * @template T + */ +goog.array.toArray = function(object) { + var length = object.length; + + // If length is not a number the following it false. This case is kept for + // backwards compatibility since there are callers that pass objects that are + // not array like. + if (length > 0) { + var rv = new Array(length); + for (var i = 0; i < length; i++) { + rv[i] = object[i]; + } + return rv; + } + return []; +}; + + +/** + * Does a shallow copy of an array. + * @param {IArrayLike|string} arr Array or array-like object to + * clone. + * @return {!Array} Clone of the input array. + * @template T + */ +goog.array.clone = goog.array.toArray; + + +/** + * Extends an array with another array, element, or "array like" object. + * This function operates 'in-place', it does not create a new Array. + * + * Example: + * var a = []; + * goog.array.extend(a, [0, 1]); + * a; // [0, 1] + * goog.array.extend(a, 2); + * a; // [0, 1, 2] + * + * @param {Array} arr1 The array to modify. + * @param {...(Array|VALUE)} var_args The elements or arrays of elements + * to add to arr1. + * @template VALUE + */ +goog.array.extend = function(arr1, var_args) { + for (var i = 1; i < arguments.length; i++) { + var arr2 = arguments[i]; + if (goog.isArrayLike(arr2)) { + var len1 = arr1.length || 0; + var len2 = arr2.length || 0; + arr1.length = len1 + len2; + for (var j = 0; j < len2; j++) { + arr1[len1 + j] = arr2[j]; + } + } else { + arr1.push(arr2); + } + } +}; + + +/** + * Adds or removes elements from an array. This is a generic version of Array + * splice. This means that it might work on other objects similar to arrays, + * such as the arguments object. + * + * @param {IArrayLike} arr The array to modify. + * @param {number|undefined} index The index at which to start changing the + * array. If not defined, treated as 0. + * @param {number} howMany How many elements to remove (0 means no removal. A + * value below 0 is treated as zero and so is any other non number. Numbers + * are floored). + * @param {...T} var_args Optional, additional elements to insert into the + * array. + * @return {!Array} the removed elements. + * @template T + */ +goog.array.splice = function(arr, index, howMany, var_args) { + goog.asserts.assert(arr.length != null); + + return Array.prototype.splice.apply(arr, goog.array.slice(arguments, 1)); +}; + + +/** + * Returns a new array from a segment of an array. This is a generic version of + * Array slice. This means that it might work on other objects similar to + * arrays, such as the arguments object. + * + * @param {IArrayLike|string} arr The array from + * which to copy a segment. + * @param {number} start The index of the first element to copy. + * @param {number=} opt_end The index after the last element to copy. + * @return {!Array} A new array containing the specified segment of the + * original array. + * @template T + */ +goog.array.slice = function(arr, start, opt_end) { + goog.asserts.assert(arr.length != null); + + // passing 1 arg to slice is not the same as passing 2 where the second is + // null or undefined (in that case the second argument is treated as 0). + // we could use slice on the arguments object and then use apply instead of + // testing the length + if (arguments.length <= 2) { + return Array.prototype.slice.call(arr, start); + } else { + return Array.prototype.slice.call(arr, start, opt_end); + } +}; + + +/** + * Removes all duplicates from an array (retaining only the first + * occurrence of each array element). This function modifies the + * array in place and doesn't change the order of the non-duplicate items. + * + * For objects, duplicates are identified as having the same unique ID as + * defined by {@link goog.getUid}. + * + * Alternatively you can specify a custom hash function that returns a unique + * value for each item in the array it should consider unique. + * + * Runtime: N, + * Worstcase space: 2N (no dupes) + * + * @param {IArrayLike} arr The array from which to remove + * duplicates. + * @param {Array=} opt_rv An optional array in which to return the results, + * instead of performing the removal inplace. If specified, the original + * array will remain unchanged. + * @param {function(T):string=} opt_hashFn An optional function to use to + * apply to every item in the array. This function should return a unique + * value for each item in the array it should consider unique. + * @template T + */ +goog.array.removeDuplicates = function(arr, opt_rv, opt_hashFn) { + var returnArray = opt_rv || arr; + var defaultHashFn = function(item) { + // Prefix each type with a single character representing the type to + // prevent conflicting keys (e.g. true and 'true'). + return goog.isObject(item) ? 'o' + goog.getUid(item) : + (typeof item).charAt(0) + item; + }; + var hashFn = opt_hashFn || defaultHashFn; + + var seen = {}, cursorInsert = 0, cursorRead = 0; + while (cursorRead < arr.length) { + var current = arr[cursorRead++]; + var key = hashFn(current); + if (!Object.prototype.hasOwnProperty.call(seen, key)) { + seen[key] = true; + returnArray[cursorInsert++] = current; + } + } + returnArray.length = cursorInsert; +}; + + +/** + * Searches the specified array for the specified target using the binary + * search algorithm. If no opt_compareFn is specified, elements are compared + * using goog.array.defaultCompare, which compares the elements + * using the built in < and > operators. This will produce the expected + * behavior for homogeneous arrays of String(s) and Number(s). The array + * specified must be sorted in ascending order (as defined by the + * comparison function). If the array is not sorted, results are undefined. + * If the array contains multiple instances of the specified target value, any + * of these instances may be found. + * + * Runtime: O(log n) + * + * @param {IArrayLike} arr The array to be searched. + * @param {TARGET} target The sought value. + * @param {function(TARGET, VALUE): number=} opt_compareFn Optional comparison + * function by which the array is ordered. Should take 2 arguments to + * compare, and return a negative number, zero, or a positive number + * depending on whether the first argument is less than, equal to, or + * greater than the second. + * @return {number} Lowest index of the target value if found, otherwise + * (-(insertion point) - 1). The insertion point is where the value should + * be inserted into arr to preserve the sorted property. Return value >= 0 + * iff target is found. + * @template TARGET, VALUE + */ +goog.array.binarySearch = function(arr, target, opt_compareFn) { + return goog.array.binarySearch_( + arr, opt_compareFn || goog.array.defaultCompare, false /* isEvaluator */, + target); +}; + + +/** + * Selects an index in the specified array using the binary search algorithm. + * The evaluator receives an element and determines whether the desired index + * is before, at, or after it. The evaluator must be consistent (formally, + * goog.array.map(goog.array.map(arr, evaluator, opt_obj), goog.math.sign) + * must be monotonically non-increasing). + * + * Runtime: O(log n) + * + * @param {IArrayLike} arr The array to be searched. + * @param {function(this:THIS, VALUE, number, ?): number} evaluator + * Evaluator function that receives 3 arguments (the element, the index and + * the array). Should return a negative number, zero, or a positive number + * depending on whether the desired index is before, at, or after the + * element passed to it. + * @param {THIS=} opt_obj The object to be used as the value of 'this' + * within evaluator. + * @return {number} Index of the leftmost element matched by the evaluator, if + * such exists; otherwise (-(insertion point) - 1). The insertion point is + * the index of the first element for which the evaluator returns negative, + * or arr.length if no such element exists. The return value is non-negative + * iff a match is found. + * @template THIS, VALUE + */ +goog.array.binarySelect = function(arr, evaluator, opt_obj) { + return goog.array.binarySearch_( + arr, evaluator, true /* isEvaluator */, undefined /* opt_target */, + opt_obj); +}; + + +/** + * Implementation of a binary search algorithm which knows how to use both + * comparison functions and evaluators. If an evaluator is provided, will call + * the evaluator with the given optional data object, conforming to the + * interface defined in binarySelect. Otherwise, if a comparison function is + * provided, will call the comparison function against the given data object. + * + * This implementation purposefully does not use goog.bind or goog.partial for + * performance reasons. + * + * Runtime: O(log n) + * + * @param {IArrayLike} arr The array to be searched. + * @param {function(?, ?, ?): number | function(?, ?): number} compareFn + * Either an evaluator or a comparison function, as defined by binarySearch + * and binarySelect above. + * @param {boolean} isEvaluator Whether the function is an evaluator or a + * comparison function. + * @param {?=} opt_target If the function is a comparison function, then + * this is the target to binary search for. + * @param {Object=} opt_selfObj If the function is an evaluator, this is an + * optional this object for the evaluator. + * @return {number} Lowest index of the target value if found, otherwise + * (-(insertion point) - 1). The insertion point is where the value should + * be inserted into arr to preserve the sorted property. Return value >= 0 + * iff target is found. + * @private + */ +goog.array.binarySearch_ = function( + arr, compareFn, isEvaluator, opt_target, opt_selfObj) { + var left = 0; // inclusive + var right = arr.length; // exclusive + var found; + while (left < right) { + var middle = (left + right) >> 1; + var compareResult; + if (isEvaluator) { + compareResult = compareFn.call(opt_selfObj, arr[middle], middle, arr); + } else { + // NOTE(dimvar): To avoid this cast, we'd have to use function overloading + // for the type of binarySearch_, which the type system can't express yet. + compareResult = /** @type {function(?, ?): number} */ (compareFn)( + opt_target, arr[middle]); + } + if (compareResult > 0) { + left = middle + 1; + } else { + right = middle; + // We are looking for the lowest index so we can't return immediately. + found = !compareResult; + } + } + // left is the index if found, or the insertion point otherwise. + // ~left is a shorthand for -left - 1. + return found ? left : ~left; +}; + + +/** + * Sorts the specified array into ascending order. If no opt_compareFn is + * specified, elements are compared using + * goog.array.defaultCompare, which compares the elements using + * the built in < and > operators. This will produce the expected behavior + * for homogeneous arrays of String(s) and Number(s), unlike the native sort, + * but will give unpredictable results for heterogeneous lists of strings and + * numbers with different numbers of digits. + * + * This sort is not guaranteed to be stable. + * + * Runtime: Same as Array.prototype.sort + * + * @param {Array} arr The array to be sorted. + * @param {?function(T,T):number=} opt_compareFn Optional comparison + * function by which the + * array is to be ordered. Should take 2 arguments to compare, and return a + * negative number, zero, or a positive number depending on whether the + * first argument is less than, equal to, or greater than the second. + * @template T + */ +goog.array.sort = function(arr, opt_compareFn) { + // TODO(arv): Update type annotation since null is not accepted. + arr.sort(opt_compareFn || goog.array.defaultCompare); +}; + + +/** + * Sorts the specified array into ascending order in a stable way. If no + * opt_compareFn is specified, elements are compared using + * goog.array.defaultCompare, which compares the elements using + * the built in < and > operators. This will produce the expected behavior + * for homogeneous arrays of String(s) and Number(s). + * + * Runtime: Same as Array.prototype.sort, plus an additional + * O(n) overhead of copying the array twice. + * + * @param {Array} arr The array to be sorted. + * @param {?function(T, T): number=} opt_compareFn Optional comparison function + * by which the array is to be ordered. Should take 2 arguments to compare, + * and return a negative number, zero, or a positive number depending on + * whether the first argument is less than, equal to, or greater than the + * second. + * @template T + */ +goog.array.stableSort = function(arr, opt_compareFn) { + var compArr = new Array(arr.length); + for (var i = 0; i < arr.length; i++) { + compArr[i] = {index: i, value: arr[i]}; + } + var valueCompareFn = opt_compareFn || goog.array.defaultCompare; + function stableCompareFn(obj1, obj2) { + return valueCompareFn(obj1.value, obj2.value) || obj1.index - obj2.index; + } + goog.array.sort(compArr, stableCompareFn); + for (var i = 0; i < arr.length; i++) { + arr[i] = compArr[i].value; + } +}; + + +/** + * Sort the specified array into ascending order based on item keys + * returned by the specified key function. + * If no opt_compareFn is specified, the keys are compared in ascending order + * using goog.array.defaultCompare. + * + * Runtime: O(S(f(n)), where S is runtime of goog.array.sort + * and f(n) is runtime of the key function. + * + * @param {Array} arr The array to be sorted. + * @param {function(T): K} keyFn Function taking array element and returning + * a key used for sorting this element. + * @param {?function(K, K): number=} opt_compareFn Optional comparison function + * by which the keys are to be ordered. Should take 2 arguments to compare, + * and return a negative number, zero, or a positive number depending on + * whether the first argument is less than, equal to, or greater than the + * second. + * @template T,K + */ +goog.array.sortByKey = function(arr, keyFn, opt_compareFn) { + var keyCompareFn = opt_compareFn || goog.array.defaultCompare; + goog.array.sort( + arr, function(a, b) { return keyCompareFn(keyFn(a), keyFn(b)); }); +}; + + +/** + * Sorts an array of objects by the specified object key and compare + * function. If no compare function is provided, the key values are + * compared in ascending order using goog.array.defaultCompare. + * This won't work for keys that get renamed by the compiler. So use + * {'foo': 1, 'bar': 2} rather than {foo: 1, bar: 2}. + * @param {Array} arr An array of objects to sort. + * @param {string} key The object key to sort by. + * @param {Function=} opt_compareFn The function to use to compare key + * values. + */ +goog.array.sortObjectsByKey = function(arr, key, opt_compareFn) { + goog.array.sortByKey(arr, function(obj) { return obj[key]; }, opt_compareFn); +}; + + +/** + * Tells if the array is sorted. + * @param {!Array} arr The array. + * @param {?function(T,T):number=} opt_compareFn Function to compare the + * array elements. + * Should take 2 arguments to compare, and return a negative number, zero, + * or a positive number depending on whether the first argument is less + * than, equal to, or greater than the second. + * @param {boolean=} opt_strict If true no equal elements are allowed. + * @return {boolean} Whether the array is sorted. + * @template T + */ +goog.array.isSorted = function(arr, opt_compareFn, opt_strict) { + var compare = opt_compareFn || goog.array.defaultCompare; + for (var i = 1; i < arr.length; i++) { + var compareResult = compare(arr[i - 1], arr[i]); + if (compareResult > 0 || compareResult == 0 && opt_strict) { + return false; + } + } + return true; +}; + + +/** + * Compares two arrays for equality. Two arrays are considered equal if they + * have the same length and their corresponding elements are equal according to + * the comparison function. + * + * @param {IArrayLike} arr1 The first array to compare. + * @param {IArrayLike} arr2 The second array to compare. + * @param {Function=} opt_equalsFn Optional comparison function. + * Should take 2 arguments to compare, and return true if the arguments + * are equal. Defaults to {@link goog.array.defaultCompareEquality} which + * compares the elements using the built-in '===' operator. + * @return {boolean} Whether the two arrays are equal. + */ +goog.array.equals = function(arr1, arr2, opt_equalsFn) { + if (!goog.isArrayLike(arr1) || !goog.isArrayLike(arr2) || + arr1.length != arr2.length) { + return false; + } + var l = arr1.length; + var equalsFn = opt_equalsFn || goog.array.defaultCompareEquality; + for (var i = 0; i < l; i++) { + if (!equalsFn(arr1[i], arr2[i])) { + return false; + } + } + return true; +}; + + +/** + * 3-way array compare function. + * @param {!IArrayLike} arr1 The first array to + * compare. + * @param {!IArrayLike} arr2 The second array to + * compare. + * @param {function(VALUE, VALUE): number=} opt_compareFn Optional comparison + * function by which the array is to be ordered. Should take 2 arguments to + * compare, and return a negative number, zero, or a positive number + * depending on whether the first argument is less than, equal to, or + * greater than the second. + * @return {number} Negative number, zero, or a positive number depending on + * whether the first argument is less than, equal to, or greater than the + * second. + * @template VALUE + */ +goog.array.compare3 = function(arr1, arr2, opt_compareFn) { + var compare = opt_compareFn || goog.array.defaultCompare; + var l = Math.min(arr1.length, arr2.length); + for (var i = 0; i < l; i++) { + var result = compare(arr1[i], arr2[i]); + if (result != 0) { + return result; + } + } + return goog.array.defaultCompare(arr1.length, arr2.length); +}; + + +/** + * Compares its two arguments for order, using the built in < and > + * operators. + * @param {VALUE} a The first object to be compared. + * @param {VALUE} b The second object to be compared. + * @return {number} A negative number, zero, or a positive number as the first + * argument is less than, equal to, or greater than the second, + * respectively. + * @template VALUE + */ +goog.array.defaultCompare = function(a, b) { + return a > b ? 1 : a < b ? -1 : 0; +}; + + +/** + * Compares its two arguments for inverse order, using the built in < and > + * operators. + * @param {VALUE} a The first object to be compared. + * @param {VALUE} b The second object to be compared. + * @return {number} A negative number, zero, or a positive number as the first + * argument is greater than, equal to, or less than the second, + * respectively. + * @template VALUE + */ +goog.array.inverseDefaultCompare = function(a, b) { + return -goog.array.defaultCompare(a, b); +}; + + +/** + * Compares its two arguments for equality, using the built in === operator. + * @param {*} a The first object to compare. + * @param {*} b The second object to compare. + * @return {boolean} True if the two arguments are equal, false otherwise. + */ +goog.array.defaultCompareEquality = function(a, b) { + return a === b; +}; + + +/** + * Inserts a value into a sorted array. The array is not modified if the + * value is already present. + * @param {IArrayLike} array The array to modify. + * @param {VALUE} value The object to insert. + * @param {function(VALUE, VALUE): number=} opt_compareFn Optional comparison + * function by which the array is ordered. Should take 2 arguments to + * compare, and return a negative number, zero, or a positive number + * depending on whether the first argument is less than, equal to, or + * greater than the second. + * @return {boolean} True if an element was inserted. + * @template VALUE + */ +goog.array.binaryInsert = function(array, value, opt_compareFn) { + var index = goog.array.binarySearch(array, value, opt_compareFn); + if (index < 0) { + goog.array.insertAt(array, value, -(index + 1)); + return true; + } + return false; +}; + + +/** + * Removes a value from a sorted array. + * @param {!IArrayLike} array The array to modify. + * @param {VALUE} value The object to remove. + * @param {function(VALUE, VALUE): number=} opt_compareFn Optional comparison + * function by which the array is ordered. Should take 2 arguments to + * compare, and return a negative number, zero, or a positive number + * depending on whether the first argument is less than, equal to, or + * greater than the second. + * @return {boolean} True if an element was removed. + * @template VALUE + */ +goog.array.binaryRemove = function(array, value, opt_compareFn) { + var index = goog.array.binarySearch(array, value, opt_compareFn); + return (index >= 0) ? goog.array.removeAt(array, index) : false; +}; + + +/** + * Splits an array into disjoint buckets according to a splitting function. + * @param {Array} array The array. + * @param {function(this:S, T, number, !Array):?} sorter Function to call for + * every element. This takes 3 arguments (the element, the index and the + * array) and must return a valid object key (a string, number, etc), or + * undefined, if that object should not be placed in a bucket. + * @param {S=} opt_obj The object to be used as the value of 'this' within + * sorter. + * @return {!Object>} An object, with keys being all of the unique + * return values of sorter, and values being arrays containing the items for + * which the splitter returned that key. + * @template T,S + */ +goog.array.bucket = function(array, sorter, opt_obj) { + var buckets = {}; + + for (var i = 0; i < array.length; i++) { + var value = array[i]; + var key = sorter.call(/** @type {?} */ (opt_obj), value, i, array); + if (goog.isDef(key)) { + // Push the value to the right bucket, creating it if necessary. + var bucket = buckets[key] || (buckets[key] = []); + bucket.push(value); + } + } + + return buckets; +}; + + +/** + * Creates a new object built from the provided array and the key-generation + * function. + * @param {IArrayLike} arr Array or array like object over + * which to iterate whose elements will be the values in the new object. + * @param {?function(this:S, T, number, ?) : string} keyFunc The function to + * call for every element. This function takes 3 arguments (the element, the + * index and the array) and should return a string that will be used as the + * key for the element in the new object. If the function returns the same + * key for more than one element, the value for that key is + * implementation-defined. + * @param {S=} opt_obj The object to be used as the value of 'this' + * within keyFunc. + * @return {!Object} The new object. + * @template T,S + */ +goog.array.toObject = function(arr, keyFunc, opt_obj) { + var ret = {}; + goog.array.forEach(arr, function(element, index) { + ret[keyFunc.call(/** @type {?} */ (opt_obj), element, index, arr)] = + element; + }); + return ret; +}; + + +/** + * Creates a range of numbers in an arithmetic progression. + * + * Range takes 1, 2, or 3 arguments: + *
+ * range(5) is the same as range(0, 5, 1) and produces [0, 1, 2, 3, 4]
+ * range(2, 5) is the same as range(2, 5, 1) and produces [2, 3, 4]
+ * range(-2, -5, -1) produces [-2, -3, -4]
+ * range(-2, -5, 1) produces [], since stepping by 1 wouldn't ever reach -5.
+ * 
+ * + * @param {number} startOrEnd The starting value of the range if an end argument + * is provided. Otherwise, the start value is 0, and this is the end value. + * @param {number=} opt_end The optional end value of the range. + * @param {number=} opt_step The step size between range values. Defaults to 1 + * if opt_step is undefined or 0. + * @return {!Array} An array of numbers for the requested range. May be + * an empty array if adding the step would not converge toward the end + * value. + */ +goog.array.range = function(startOrEnd, opt_end, opt_step) { + var array = []; + var start = 0; + var end = startOrEnd; + var step = opt_step || 1; + if (opt_end !== undefined) { + start = startOrEnd; + end = opt_end; + } + + if (step * (end - start) < 0) { + // Sign mismatch: start + step will never reach the end value. + return []; + } + + if (step > 0) { + for (var i = start; i < end; i += step) { + array.push(i); + } + } else { + for (var i = start; i > end; i += step) { + array.push(i); + } + } + return array; +}; + + +/** + * Returns an array consisting of the given value repeated N times. + * + * @param {VALUE} value The value to repeat. + * @param {number} n The repeat count. + * @return {!Array} An array with the repeated value. + * @template VALUE + */ +goog.array.repeat = function(value, n) { + var array = []; + for (var i = 0; i < n; i++) { + array[i] = value; + } + return array; +}; + + +/** + * Returns an array consisting of every argument with all arrays + * expanded in-place recursively. + * + * @param {...*} var_args The values to flatten. + * @return {!Array} An array containing the flattened values. + */ +goog.array.flatten = function(var_args) { + var CHUNK_SIZE = 8192; + + var result = []; + for (var i = 0; i < arguments.length; i++) { + var element = arguments[i]; + if (goog.isArray(element)) { + for (var c = 0; c < element.length; c += CHUNK_SIZE) { + var chunk = goog.array.slice(element, c, c + CHUNK_SIZE); + var recurseResult = goog.array.flatten.apply(null, chunk); + for (var r = 0; r < recurseResult.length; r++) { + result.push(recurseResult[r]); + } + } + } else { + result.push(element); + } + } + return result; +}; + + +/** + * Rotates an array in-place. After calling this method, the element at + * index i will be the element previously at index (i - n) % + * array.length, for all values of i between 0 and array.length - 1, + * inclusive. + * + * For example, suppose list comprises [t, a, n, k, s]. After invoking + * rotate(array, 1) (or rotate(array, -4)), array will comprise [s, t, a, n, k]. + * + * @param {!Array} array The array to rotate. + * @param {number} n The amount to rotate. + * @return {!Array} The array. + * @template T + */ +goog.array.rotate = function(array, n) { + goog.asserts.assert(array.length != null); + + if (array.length) { + n %= array.length; + if (n > 0) { + Array.prototype.unshift.apply(array, array.splice(-n, n)); + } else if (n < 0) { + Array.prototype.push.apply(array, array.splice(0, -n)); + } + } + return array; +}; + + +/** + * Moves one item of an array to a new position keeping the order of the rest + * of the items. Example use case: keeping a list of JavaScript objects + * synchronized with the corresponding list of DOM elements after one of the + * elements has been dragged to a new position. + * @param {!IArrayLike} arr The array to modify. + * @param {number} fromIndex Index of the item to move between 0 and + * {@code arr.length - 1}. + * @param {number} toIndex Target index between 0 and {@code arr.length - 1}. + */ +goog.array.moveItem = function(arr, fromIndex, toIndex) { + goog.asserts.assert(fromIndex >= 0 && fromIndex < arr.length); + goog.asserts.assert(toIndex >= 0 && toIndex < arr.length); + // Remove 1 item at fromIndex. + var removedItems = Array.prototype.splice.call(arr, fromIndex, 1); + // Insert the removed item at toIndex. + Array.prototype.splice.call(arr, toIndex, 0, removedItems[0]); + // We don't use goog.array.insertAt and goog.array.removeAt, because they're + // significantly slower than splice. +}; + + +/** + * Creates a new array for which the element at position i is an array of the + * ith element of the provided arrays. The returned array will only be as long + * as the shortest array provided; additional values are ignored. For example, + * the result of zipping [1, 2] and [3, 4, 5] is [[1,3], [2, 4]]. + * + * This is similar to the zip() function in Python. See {@link + * http://docs.python.org/library/functions.html#zip} + * + * @param {...!IArrayLike} var_args Arrays to be combined. + * @return {!Array>} A new array of arrays created from + * provided arrays. + */ +goog.array.zip = function(var_args) { + if (!arguments.length) { + return []; + } + var result = []; + var minLen = arguments[0].length; + for (var i = 1; i < arguments.length; i++) { + if (arguments[i].length < minLen) { + minLen = arguments[i].length; + } + } + for (var i = 0; i < minLen; i++) { + var value = []; + for (var j = 0; j < arguments.length; j++) { + value.push(arguments[j][i]); + } + result.push(value); + } + return result; +}; + + +/** + * Shuffles the values in the specified array using the Fisher-Yates in-place + * shuffle (also known as the Knuth Shuffle). By default, calls Math.random() + * and so resets the state of that random number generator. Similarly, may reset + * the state of the any other specified random number generator. + * + * Runtime: O(n) + * + * @param {!Array} arr The array to be shuffled. + * @param {function():number=} opt_randFn Optional random function to use for + * shuffling. + * Takes no arguments, and returns a random number on the interval [0, 1). + * Defaults to Math.random() using JavaScript's built-in Math library. + */ +goog.array.shuffle = function(arr, opt_randFn) { + var randFn = opt_randFn || Math.random; + + for (var i = arr.length - 1; i > 0; i--) { + // Choose a random array index in [0, i] (inclusive with i). + var j = Math.floor(randFn() * (i + 1)); + + var tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } +}; + + +/** + * Returns a new array of elements from arr, based on the indexes of elements + * provided by index_arr. For example, the result of index copying + * ['a', 'b', 'c'] with index_arr [1,0,0,2] is ['b', 'a', 'a', 'c']. + * + * @param {!Array} arr The array to get a indexed copy from. + * @param {!Array} index_arr An array of indexes to get from arr. + * @return {!Array} A new array of elements from arr in index_arr order. + * @template T + */ +goog.array.copyByIndex = function(arr, index_arr) { + var result = []; + goog.array.forEach(index_arr, function(index) { result.push(arr[index]); }); + return result; +}; + + +/** + * Maps each element of the input array into zero or more elements of the output + * array. + * + * @param {!IArrayLike|string} arr Array or array like object + * over which to iterate. + * @param {function(this:THIS, VALUE, number, ?): !Array} f The function + * to call for every element. This function takes 3 arguments (the element, + * the index and the array) and should return an array. The result will be + * used to extend a new array. + * @param {THIS=} opt_obj The object to be used as the value of 'this' within f. + * @return {!Array} a new array with the concatenation of all arrays + * returned from f. + * @template THIS, VALUE, RESULT + */ +goog.array.concatMap = function(arr, f, opt_obj) { + return goog.array.concat.apply([], goog.array.map(arr, f, opt_obj)); +}; diff --git a/resources/public/js/optimized/goog/asserts/asserts.js b/resources/public/js/optimized/goog/asserts/asserts.js new file mode 100644 index 0000000..1f4b653 --- /dev/null +++ b/resources/public/js/optimized/goog/asserts/asserts.js @@ -0,0 +1,369 @@ +// Copyright 2008 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Utilities to check the preconditions, postconditions and + * invariants runtime. + * + * Methods in this package should be given special treatment by the compiler + * for type-inference. For example, goog.asserts.assert(foo) + * will restrict foo to a truthy value. + * + * The compiler has an option to disable asserts. So code like: + * + * var x = goog.asserts.assert(foo()); goog.asserts.assert(bar()); + * + * will be transformed into: + * + * var x = foo(); + * + * The compiler will leave in foo() (because its return value is used), + * but it will remove bar() because it assumes it does not have side-effects. + * + * @author agrieve@google.com (Andrew Grieve) + */ + +goog.provide('goog.asserts'); +goog.provide('goog.asserts.AssertionError'); + +goog.require('goog.debug.Error'); +goog.require('goog.dom.NodeType'); +goog.require('goog.string'); + + +/** + * @define {boolean} Whether to strip out asserts or to leave them in. + */ +goog.define('goog.asserts.ENABLE_ASSERTS', goog.DEBUG); + + + +/** + * Error object for failed assertions. + * @param {string} messagePattern The pattern that was used to form message. + * @param {!Array<*>} messageArgs The items to substitute into the pattern. + * @constructor + * @extends {goog.debug.Error} + * @final + */ +goog.asserts.AssertionError = function(messagePattern, messageArgs) { + messageArgs.unshift(messagePattern); + goog.debug.Error.call(this, goog.string.subs.apply(null, messageArgs)); + // Remove the messagePattern afterwards to avoid permanently modifying the + // passed in array. + messageArgs.shift(); + + /** + * The message pattern used to format the error message. Error handlers can + * use this to uniquely identify the assertion. + * @type {string} + */ + this.messagePattern = messagePattern; +}; +goog.inherits(goog.asserts.AssertionError, goog.debug.Error); + + +/** @override */ +goog.asserts.AssertionError.prototype.name = 'AssertionError'; + + +/** + * The default error handler. + * @param {!goog.asserts.AssertionError} e The exception to be handled. + */ +goog.asserts.DEFAULT_ERROR_HANDLER = function(e) { + throw e; +}; + + +/** + * The handler responsible for throwing or logging assertion errors. + * @private {function(!goog.asserts.AssertionError)} + */ +goog.asserts.errorHandler_ = goog.asserts.DEFAULT_ERROR_HANDLER; + + +/** + * Throws an exception with the given message and "Assertion failed" prefixed + * onto it. + * @param {string} defaultMessage The message to use if givenMessage is empty. + * @param {Array<*>} defaultArgs The substitution arguments for defaultMessage. + * @param {string|undefined} givenMessage Message supplied by the caller. + * @param {Array<*>} givenArgs The substitution arguments for givenMessage. + * @throws {goog.asserts.AssertionError} When the value is not a number. + * @private + */ +goog.asserts.doAssertFailure_ = function( + defaultMessage, defaultArgs, givenMessage, givenArgs) { + var message = 'Assertion failed'; + if (givenMessage) { + message += ': ' + givenMessage; + var args = givenArgs; + } else if (defaultMessage) { + message += ': ' + defaultMessage; + args = defaultArgs; + } + // The '' + works around an Opera 10 bug in the unit tests. Without it, + // a stack trace is added to var message above. With this, a stack trace is + // not added until this line (it causes the extra garbage to be added after + // the assertion message instead of in the middle of it). + var e = new goog.asserts.AssertionError('' + message, args || []); + goog.asserts.errorHandler_(e); +}; + + +/** + * Sets a custom error handler that can be used to customize the behavior of + * assertion failures, for example by turning all assertion failures into log + * messages. + * @param {function(!goog.asserts.AssertionError)} errorHandler + */ +goog.asserts.setErrorHandler = function(errorHandler) { + if (goog.asserts.ENABLE_ASSERTS) { + goog.asserts.errorHandler_ = errorHandler; + } +}; + + +/** + * Checks if the condition evaluates to true if goog.asserts.ENABLE_ASSERTS is + * true. + * @template T + * @param {T} condition The condition to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {T} The value of the condition. + * @throws {goog.asserts.AssertionError} When the condition evaluates to false. + */ +goog.asserts.assert = function(condition, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !condition) { + goog.asserts.doAssertFailure_( + '', null, opt_message, Array.prototype.slice.call(arguments, 2)); + } + return condition; +}; + + +/** + * Fails if goog.asserts.ENABLE_ASSERTS is true. This function is useful in case + * when we want to add a check in the unreachable area like switch-case + * statement: + * + *
+ *  switch(type) {
+ *    case FOO: doSomething(); break;
+ *    case BAR: doSomethingElse(); break;
+ *    default: goog.asserts.fail('Unrecognized type: ' + type);
+ *      // We have only 2 types - "default:" section is unreachable code.
+ *  }
+ * 
+ * + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @throws {goog.asserts.AssertionError} Failure. + */ +goog.asserts.fail = function(opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS) { + goog.asserts.errorHandler_( + new goog.asserts.AssertionError( + 'Failure' + (opt_message ? ': ' + opt_message : ''), + Array.prototype.slice.call(arguments, 1))); + } +}; + + +/** + * Checks if the value is a number if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {number} The value, guaranteed to be a number when asserts enabled. + * @throws {goog.asserts.AssertionError} When the value is not a number. + */ +goog.asserts.assertNumber = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isNumber(value)) { + goog.asserts.doAssertFailure_( + 'Expected number but got %s: %s.', [goog.typeOf(value), value], + opt_message, Array.prototype.slice.call(arguments, 2)); + } + return /** @type {number} */ (value); +}; + + +/** + * Checks if the value is a string if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {string} The value, guaranteed to be a string when asserts enabled. + * @throws {goog.asserts.AssertionError} When the value is not a string. + */ +goog.asserts.assertString = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isString(value)) { + goog.asserts.doAssertFailure_( + 'Expected string but got %s: %s.', [goog.typeOf(value), value], + opt_message, Array.prototype.slice.call(arguments, 2)); + } + return /** @type {string} */ (value); +}; + + +/** + * Checks if the value is a function if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {!Function} The value, guaranteed to be a function when asserts + * enabled. + * @throws {goog.asserts.AssertionError} When the value is not a function. + */ +goog.asserts.assertFunction = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isFunction(value)) { + goog.asserts.doAssertFailure_( + 'Expected function but got %s: %s.', [goog.typeOf(value), value], + opt_message, Array.prototype.slice.call(arguments, 2)); + } + return /** @type {!Function} */ (value); +}; + + +/** + * Checks if the value is an Object if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {!Object} The value, guaranteed to be a non-null object. + * @throws {goog.asserts.AssertionError} When the value is not an object. + */ +goog.asserts.assertObject = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isObject(value)) { + goog.asserts.doAssertFailure_( + 'Expected object but got %s: %s.', [goog.typeOf(value), value], + opt_message, Array.prototype.slice.call(arguments, 2)); + } + return /** @type {!Object} */ (value); +}; + + +/** + * Checks if the value is an Array if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {!Array} The value, guaranteed to be a non-null array. + * @throws {goog.asserts.AssertionError} When the value is not an array. + */ +goog.asserts.assertArray = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isArray(value)) { + goog.asserts.doAssertFailure_( + 'Expected array but got %s: %s.', [goog.typeOf(value), value], + opt_message, Array.prototype.slice.call(arguments, 2)); + } + return /** @type {!Array} */ (value); +}; + + +/** + * Checks if the value is a boolean if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {boolean} The value, guaranteed to be a boolean when asserts are + * enabled. + * @throws {goog.asserts.AssertionError} When the value is not a boolean. + */ +goog.asserts.assertBoolean = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !goog.isBoolean(value)) { + goog.asserts.doAssertFailure_( + 'Expected boolean but got %s: %s.', [goog.typeOf(value), value], + opt_message, Array.prototype.slice.call(arguments, 2)); + } + return /** @type {boolean} */ (value); +}; + + +/** + * Checks if the value is a DOM Element if goog.asserts.ENABLE_ASSERTS is true. + * @param {*} value The value to check. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @return {!Element} The value, likely to be a DOM Element when asserts are + * enabled. + * @throws {goog.asserts.AssertionError} When the value is not an Element. + */ +goog.asserts.assertElement = function(value, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && + (!goog.isObject(value) || value.nodeType != goog.dom.NodeType.ELEMENT)) { + goog.asserts.doAssertFailure_( + 'Expected Element but got %s: %s.', [goog.typeOf(value), value], + opt_message, Array.prototype.slice.call(arguments, 2)); + } + return /** @type {!Element} */ (value); +}; + + +/** + * Checks if the value is an instance of the user-defined type if + * goog.asserts.ENABLE_ASSERTS is true. + * + * The compiler may tighten the type returned by this function. + * + * @param {?} value The value to check. + * @param {function(new: T, ...)} type A user-defined constructor. + * @param {string=} opt_message Error message in case of failure. + * @param {...*} var_args The items to substitute into the failure message. + * @throws {goog.asserts.AssertionError} When the value is not an instance of + * type. + * @return {T} + * @template T + */ +goog.asserts.assertInstanceof = function(value, type, opt_message, var_args) { + if (goog.asserts.ENABLE_ASSERTS && !(value instanceof type)) { + goog.asserts.doAssertFailure_( + 'Expected instanceof %s but got %s.', + [goog.asserts.getType_(type), goog.asserts.getType_(value)], + opt_message, Array.prototype.slice.call(arguments, 3)); + } + return value; +}; + + +/** + * Checks that no enumerable keys are present in Object.prototype. Such keys + * would break most code that use {@code for (var ... in ...)} loops. + */ +goog.asserts.assertObjectPrototypeIsIntact = function() { + for (var key in Object.prototype) { + goog.asserts.fail(key + ' should not be enumerable in Object.prototype.'); + } +}; + + +/** + * Returns the type of a value. If a constructor is passed, and a suitable + * string cannot be found, 'unknown type name' will be returned. + * @param {*} value A constructor, object, or primitive. + * @return {string} The best display name for the value, or 'unknown type name'. + * @private + */ +goog.asserts.getType_ = function(value) { + if (value instanceof Function) { + return value.displayName || value.name || 'unknown type name'; + } else if (value instanceof Object) { + return value.constructor.displayName || value.constructor.name || + Object.prototype.toString.call(value); + } else { + return value === null ? 'null' : typeof value; + } +}; diff --git a/resources/public/js/optimized/goog/base.js b/resources/public/js/optimized/goog/base.js new file mode 100644 index 0000000..46b2f09 --- /dev/null +++ b/resources/public/js/optimized/goog/base.js @@ -0,0 +1,2921 @@ +// Copyright 2006 The Closure Library Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS-IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * @fileoverview Bootstrap for the Google JS Library (Closure). + * + * In uncompiled mode base.js will attempt to load Closure's deps file, unless + * the global CLOSURE_NO_DEPS is set to true. This allows projects + * to include their own deps file(s) from different locations. + * + * Avoid including base.js more than once. This is strictly discouraged and not + * supported. goog.require(...) won't work properly in that case. + * + * @provideGoog + */ + + +/** + * @define {boolean} Overridden to true by the compiler. + */ +var COMPILED = false; + + +/** + * Base namespace for the Closure library. Checks to see goog is already + * defined in the current scope before assigning to prevent clobbering if + * base.js is loaded more than once. + * + * @const + */ +var goog = goog || {}; + + +/** + * Reference to the global context. In most cases this will be 'window'. + */ +goog.global = this; + + +/** + * A hook for overriding the define values in uncompiled mode. + * + * In uncompiled mode, {@code CLOSURE_UNCOMPILED_DEFINES} may be defined before + * loading base.js. If a key is defined in {@code CLOSURE_UNCOMPILED_DEFINES}, + * {@code goog.define} will use the value instead of the default value. This + * allows flags to be overwritten without compilation (this is normally + * accomplished with the compiler's "define" flag). + * + * Example: + *
+ *   var CLOSURE_UNCOMPILED_DEFINES = {'goog.DEBUG': false};
+ * 
+ * + * @type {Object|undefined} + */ +goog.global.CLOSURE_UNCOMPILED_DEFINES; + + +/** + * A hook for overriding the define values in uncompiled or compiled mode, + * like CLOSURE_UNCOMPILED_DEFINES but effective in compiled code. In + * uncompiled code CLOSURE_UNCOMPILED_DEFINES takes precedence. + * + * Also unlike CLOSURE_UNCOMPILED_DEFINES the values must be number, boolean or + * string literals or the compiler will emit an error. + * + * While any @define value may be set, only those set with goog.define will be + * effective for uncompiled code. + * + * Example: + *
+ *   var CLOSURE_DEFINES = {'goog.DEBUG': false} ;
+ * 
+ * + * @type {Object|undefined} + */ +goog.global.CLOSURE_DEFINES; + + +/** + * Returns true if the specified value is not undefined. + * + * @param {?} val Variable to test. + * @return {boolean} Whether variable is defined. + */ +goog.isDef = function(val) { + // void 0 always evaluates to undefined and hence we do not need to depend on + // the definition of the global variable named 'undefined'. + return val !== void 0; +}; + +/** + * Returns true if the specified value is a string. + * @param {?} val Variable to test. + * @return {boolean} Whether variable is a string. + */ +goog.isString = function(val) { + return typeof val == 'string'; +}; + + +/** + * Returns true if the specified value is a boolean. + * @param {?} val Variable to test. + * @return {boolean} Whether variable is boolean. + */ +goog.isBoolean = function(val) { + return typeof val == 'boolean'; +}; + + +/** + * Returns true if the specified value is a number. + * @param {?} val Variable to test. + * @return {boolean} Whether variable is a number. + */ +goog.isNumber = function(val) { + return typeof val == 'number'; +}; + + +/** + * Builds an object structure for the provided namespace path, ensuring that + * names that already exist are not overwritten. For example: + * "a.b.c" -> a = {};a.b={};a.b.c={}; + * Used by goog.provide and goog.exportSymbol. + * @param {string} name name of the object that this file defines. + * @param {*=} opt_object the object to expose at the end of the path. + * @param {Object=} opt_objectToExportTo The object to add the path to; default + * is `goog.global`. + * @private + */ +goog.exportPath_ = function(name, opt_object, opt_objectToExportTo) { + var parts = name.split('.'); + var cur = opt_objectToExportTo || goog.global; + + // Internet Explorer exhibits strange behavior when throwing errors from + // methods externed in this manner. See the testExportSymbolExceptions in + // base_test.html for an example. + if (!(parts[0] in cur) && cur.execScript) { + cur.execScript('var ' + parts[0]); + } + + for (var part; parts.length && (part = parts.shift());) { + if (!parts.length && goog.isDef(opt_object)) { + // last part and we have an object; use it + cur[part] = opt_object; + } else if (cur[part] && cur[part] !== Object.prototype[part]) { + cur = cur[part]; + } else { + cur = cur[part] = {}; + } + } +}; + + +/** + * Defines a named value. In uncompiled mode, the value is retrieved from + * CLOSURE_DEFINES or CLOSURE_UNCOMPILED_DEFINES if the object is defined and + * has the property specified, and otherwise used the defined defaultValue. + * When compiled the default can be overridden using the compiler + * options or the value set in the CLOSURE_DEFINES object. + * + * @param {string} name The distinguished name to provide. + * @param {string|number|boolean} defaultValue + */ +goog.define = function(name, defaultValue) { + var value = defaultValue; + if (!COMPILED) { + if (goog.global.CLOSURE_UNCOMPILED_DEFINES && + // Anti DOM-clobbering runtime check (b/37736576). + /** @type {?} */ (goog.global.CLOSURE_UNCOMPILED_DEFINES).nodeType === + undefined && + Object.prototype.hasOwnProperty.call( + goog.global.CLOSURE_UNCOMPILED_DEFINES, name)) { + value = goog.global.CLOSURE_UNCOMPILED_DEFINES[name]; + } else if ( + goog.global.CLOSURE_DEFINES && + // Anti DOM-clobbering runtime check (b/37736576). + /** @type {?} */ (goog.global.CLOSURE_DEFINES).nodeType === undefined && + Object.prototype.hasOwnProperty.call( + goog.global.CLOSURE_DEFINES, name)) { + value = goog.global.CLOSURE_DEFINES[name]; + } + } + goog.exportPath_(name, value); +}; + + +/** + * @define {boolean} DEBUG is provided as a convenience so that debugging code + * that should not be included in a production. It can be easily stripped + * by specifying --define goog.DEBUG=false to the Closure Compiler aka + * JSCompiler. For example, most toString() methods should be declared inside an + * "if (goog.DEBUG)" conditional because they are generally used for debugging + * purposes and it is difficult for the JSCompiler to statically determine + * whether they are used. + */ +goog.define('goog.DEBUG', true); + + +/** + * @define {string} LOCALE defines the locale being used for compilation. It is + * used to select locale specific data to be compiled in js binary. BUILD rule + * can specify this value by "--define goog.LOCALE=" as a compiler + * option. + * + * Take into account that the locale code format is important. You should use + * the canonical Unicode format with hyphen as a delimiter. Language must be + * lowercase, Language Script - Capitalized, Region - UPPERCASE. + * There are few examples: pt-BR, en, en-US, sr-Latin-BO, zh-Hans-CN. + * + * See more info about locale codes here: + * http://www.unicode.org/reports/tr35/#Unicode_Language_and_Locale_Identifiers + * + * For language codes you should use values defined by ISO 693-1. See it here + * http://www.w3.org/WAI/ER/IG/ert/iso639.htm. There is only one exception from + * this rule: the Hebrew language. For legacy reasons the old code (iw) should + * be used instead of the new code (he). + * + */ +goog.define('goog.LOCALE', 'en'); // default to en + + +/** + * @define {boolean} Whether this code is running on trusted sites. + * + * On untrusted sites, several native functions can be defined or overridden by + * external libraries like Prototype, Datejs, and JQuery and setting this flag + * to false forces closure to use its own implementations when possible. + * + * If your JavaScript can be loaded by a third party site and you are wary about + * relying on non-standard implementations, specify + * "--define goog.TRUSTED_SITE=false" to the compiler. + */ +goog.define('goog.TRUSTED_SITE', true); + + +/** + * @define {boolean} Whether a project is expected to be running in strict mode. + * + * This define can be used to trigger alternate implementations compatible with + * running in EcmaScript Strict mode or warn about unavailable functionality. + * @see https://goo.gl/PudQ4y + * + */ +goog.define('goog.STRICT_MODE_COMPATIBLE', false); + + +/** + * @define {boolean} Whether code that calls {@link goog.setTestOnly} should + * be disallowed in the compilation unit. + */ +goog.define('goog.DISALLOW_TEST_ONLY_CODE', COMPILED && !goog.DEBUG); + + +/** + * @define {boolean} Whether to use a Chrome app CSP-compliant method for + * loading scripts via goog.require. @see appendScriptSrcNode_. + */ +goog.define('goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING', false); + + +/** + * Defines a namespace in Closure. + * + * A namespace may only be defined once in a codebase. It may be defined using + * goog.provide() or goog.module(). + * + * The presence of one or more goog.provide() calls in a file indicates + * that the file defines the given objects/namespaces. + * Provided symbols must not be null or undefined. + * + * In addition, goog.provide() creates the object stubs for a namespace + * (for example, goog.provide("goog.foo.bar") will create the object + * goog.foo.bar if it does not already exist). + * + * Build tools also scan for provide/require/module statements + * to discern dependencies, build dependency files (see deps.js), etc. + * + * @see goog.require + * @see goog.module + * @param {string} name Namespace provided by this file in the form + * "goog.package.part". + */ +goog.provide = function(name) { + if (goog.isInModuleLoader_()) { + throw Error('goog.provide can not be used within a goog.module.'); + } + if (!COMPILED) { + // Ensure that the same namespace isn't provided twice. + // A goog.module/goog.provide maps a goog.require to a specific file + if (goog.isProvided_(name)) { + throw Error('Namespace "' + name + '" already declared.'); + } + } + + goog.constructNamespace_(name); +}; + + +/** + * @param {string} name Namespace provided by this file in the form + * "goog.package.part". + * @param {Object=} opt_obj The object to embed in the namespace. + * @private + */ +goog.constructNamespace_ = function(name, opt_obj) { + if (!COMPILED) { + delete goog.implicitNamespaces_[name]; + + var namespace = name; + while ((namespace = namespace.substring(0, namespace.lastIndexOf('.')))) { + if (goog.getObjectByName(namespace)) { + break; + } + goog.implicitNamespaces_[namespace] = true; + } + } + + goog.exportPath_(name, opt_obj); +}; + + +/** + * Module identifier validation regexp. + * Note: This is a conservative check, it is very possible to be more lenient, + * the primary exclusion here is "/" and "\" and a leading ".", these + * restrictions are intended to leave the door open for using goog.require + * with relative file paths rather than module identifiers. + * @private + */ +goog.VALID_MODULE_RE_ = /^[a-zA-Z_$][a-zA-Z0-9._$]*$/; + + +/** + * Defines a module in Closure. + * + * Marks that this file must be loaded as a module and claims the namespace. + * + * A namespace may only be defined once in a codebase. It may be defined using + * goog.provide() or goog.module(). + * + * goog.module() has three requirements: + * - goog.module may not be used in the same file as goog.provide. + * - goog.module must be the first statement in the file. + * - only one goog.module is allowed per file. + * + * When a goog.module annotated file is loaded, it is enclosed in + * a strict function closure. This means that: + * - any variables declared in a goog.module file are private to the file + * (not global), though the compiler is expected to inline the module. + * - The code must obey all the rules of "strict" JavaScript. + * - the file will be marked as "use strict" + * + * NOTE: unlike goog.provide, goog.module does not declare any symbols by + * itself. If declared symbols are desired, use + * goog.module.declareLegacyNamespace(). + * + * + * See the public goog.module proposal: http://goo.gl/Va1hin + * + * @param {string} name Namespace provided by this file in the form + * "goog.package.part", is expected but not required. + * @return {void} + */ +goog.module = function(name) { + if (!goog.isString(name) || !name || + name.search(goog.VALID_MODULE_RE_) == -1) { + throw Error('Invalid module identifier'); + } + if (!goog.isInModuleLoader_()) { + throw Error( + 'Module ' + name + ' has been loaded incorrectly. Note, ' + + 'modules cannot be loaded as normal scripts. They require some kind of ' + + 'pre-processing step. You\'re likely trying to load a module via a ' + + 'script tag or as a part of a concatenated bundle without rewriting the ' + + 'module. For more info see: ' + + 'https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide.'); + } + if (goog.moduleLoaderState_.moduleName) { + throw Error('goog.module may only be called once per module.'); + } + + // Store the module name for the loader. + goog.moduleLoaderState_.moduleName = name; + if (!COMPILED) { + // Ensure that the same namespace isn't provided twice. + // A goog.module/goog.provide maps a goog.require to a specific file + if (goog.isProvided_(name)) { + throw Error('Namespace "' + name + '" already declared.'); + } + delete goog.implicitNamespaces_[name]; + } +}; + + +/** + * @param {string} name The module identifier. + * @return {?} The module exports for an already loaded module or null. + * + * Note: This is not an alternative to goog.require, it does not + * indicate a hard dependency, instead it is used to indicate + * an optional dependency or to access the exports of a module + * that has already been loaded. + * @suppress {missingProvide} + */ +goog.module.get = function(name) { + return goog.module.getInternal_(name); +}; + + +/** + * @param {string} name The module identifier. + * @return {?} The module exports for an already loaded module or null. + * @private + */ +goog.module.getInternal_ = function(name) { + if (!COMPILED) { + if (name in goog.loadedModules_) { + return goog.loadedModules_[name]; + } else if (!goog.implicitNamespaces_[name]) { + var ns = goog.getObjectByName(name); + return ns != null ? ns : null; + } + } + return null; +}; + + +/** + * @private {?{moduleName: (string|undefined), declareLegacyNamespace:boolean}} + */ +goog.moduleLoaderState_ = null; + + +/** + * @private + * @return {boolean} Whether a goog.module is currently being initialized. + */ +goog.isInModuleLoader_ = function() { + return goog.moduleLoaderState_ != null; +}; + + +/** + * Provide the module's exports as a globally accessible object under the + * module's declared name. This is intended to ease migration to goog.module + * for files that have existing usages. + * @suppress {missingProvide} + */ +goog.module.declareLegacyNamespace = function() { + if (!COMPILED && !goog.isInModuleLoader_()) { + throw new Error( + 'goog.module.declareLegacyNamespace must be called from ' + + 'within a goog.module'); + } + if (!COMPILED && !goog.moduleLoaderState_.moduleName) { + throw Error( + 'goog.module must be called prior to ' + + 'goog.module.declareLegacyNamespace.'); + } + goog.moduleLoaderState_.declareLegacyNamespace = true; +}; + + +/** + * Marks that the current file should only be used for testing, and never for + * live code in production. + * + * In the case of unit tests, the message may optionally be an exact namespace + * for the test (e.g. 'goog.stringTest'). The linter will then ignore the extra + * provide (if not explicitly defined in the code). + * + * @param {string=} opt_message Optional message to add to the error that's + * raised when used in production code. + */ +goog.setTestOnly = function(opt_message) { + if (goog.DISALLOW_TEST_ONLY_CODE) { + opt_message = opt_message || ''; + throw Error( + 'Importing test-only code into non-debug environment' + + (opt_message ? ': ' + opt_message : '.')); + } +}; + + +/** + * Forward declares a symbol. This is an indication to the compiler that the + * symbol may be used in the source yet is not required and may not be provided + * in compilation. + * + * The most common usage of forward declaration is code that takes a type as a + * function parameter but does not need to require it. By forward declaring + * instead of requiring, no hard dependency is made, and (if not required + * elsewhere) the namespace may never be required and thus, not be pulled + * into the JavaScript binary. If it is required elsewhere, it will be type + * checked as normal. + * + * Before using goog.forwardDeclare, please read the documentation at + * https://github.com/google/closure-compiler/wiki/Bad-Type-Annotation to + * understand the options and tradeoffs when working with forward declarations. + * + * @param {string} name The namespace to forward declare in the form of + * "goog.package.part". + */ +goog.forwardDeclare = function(name) {}; + + +/** + * Forward declare type information. Used to assign types to goog.global + * referenced object that would otherwise result in unknown type references + * and thus block property disambiguation. + */ +goog.forwardDeclare('Document'); +goog.forwardDeclare('HTMLScriptElement'); +goog.forwardDeclare('XMLHttpRequest'); + + +if (!COMPILED) { + /** + * Check if the given name has been goog.provided. This will return false for + * names that are available only as implicit namespaces. + * @param {string} name name of the object to look for. + * @return {boolean} Whether the name has been provided. + * @private + */ + goog.isProvided_ = function(name) { + return (name in goog.loadedModules_) || + (!goog.implicitNamespaces_[name] && + goog.isDefAndNotNull(goog.getObjectByName(name))); + }; + + /** + * Namespaces implicitly defined by goog.provide. For example, + * goog.provide('goog.events.Event') implicitly declares that 'goog' and + * 'goog.events' must be namespaces. + * + * @type {!Object} + * @private + */ + goog.implicitNamespaces_ = {'goog.module': true}; + + // NOTE: We add goog.module as an implicit namespace as goog.module is defined + // here and because the existing module package has not been moved yet out of + // the goog.module namespace. This satisifies both the debug loader and + // ahead-of-time dependency management. +} + + +/** + * Returns an object based on its fully qualified external name. The object + * is not found if null or undefined. If you are using a compilation pass that + * renames property names beware that using this function will not find renamed + * properties. + * + * @param {string} name The fully qualified name. + * @param {Object=} opt_obj The object within which to look; default is + * |goog.global|. + * @return {?} The value (object or primitive) or, if not found, null. + */ +goog.getObjectByName = function(name, opt_obj) { + var parts = name.split('.'); + var cur = opt_obj || goog.global; + for (var part; part = parts.shift();) { + if (goog.isDefAndNotNull(cur[part])) { + cur = cur[part]; + } else { + return null; + } + } + return cur; +}; + + +/** + * Globalizes a whole namespace, such as goog or goog.lang. + * + * @param {!Object} obj The namespace to globalize. + * @param {Object=} opt_global The object to add the properties to. + * @deprecated Properties may be explicitly exported to the global scope, but + * this should no longer be done in bulk. + */ +goog.globalize = function(obj, opt_global) { + var global = opt_global || goog.global; + for (var x in obj) { + global[x] = obj[x]; + } +}; + + +/** + * Adds a dependency from a file to the files it requires. + * @param {string} relPath The path to the js file. + * @param {!Array} provides An array of strings with + * the names of the objects this file provides. + * @param {!Array} requires An array of strings with + * the names of the objects this file requires. + * @param {boolean|!Object=} opt_loadFlags Parameters indicating + * how the file must be loaded. The boolean 'true' is equivalent + * to {'module': 'goog'} for backwards-compatibility. Valid properties + * and values include {'module': 'goog'} and {'lang': 'es6'}. + */ +goog.addDependency = function(relPath, provides, requires, opt_loadFlags) { + if (goog.DEPENDENCIES_ENABLED) { + var provide, require; + var path = relPath.replace(/\\/g, '/'); + var deps = goog.dependencies_; + if (!opt_loadFlags || typeof opt_loadFlags === 'boolean') { + opt_loadFlags = opt_loadFlags ? {'module': 'goog'} : {}; + } + for (var i = 0; provide = provides[i]; i++) { + deps.nameToPath[provide] = path; + deps.loadFlags[path] = opt_loadFlags; + } + for (var j = 0; require = requires[j]; j++) { + if (!(path in deps.requires)) { + deps.requires[path] = {}; + } + deps.requires[path][require] = true; + } + } +}; + + + + +// NOTE(nnaze): The debug DOM loader was included in base.js as an original way +// to do "debug-mode" development. The dependency system can sometimes be +// confusing, as can the debug DOM loader's asynchronous nature. +// +// With the DOM loader, a call to goog.require() is not blocking -- the script +// will not load until some point after the current script. If a namespace is +// needed at runtime, it needs to be defined in a previous script, or loaded via +// require() with its registered dependencies. +// +// User-defined namespaces may need their own deps file. For a reference on +// creating a deps file, see: +// Externally: https://developers.google.com/closure/library/docs/depswriter +// +// Because of legacy clients, the DOM loader can't be easily removed from +// base.js. Work was done to make it disableable or replaceable for +// different environments (DOM-less JavaScript interpreters like Rhino or V8, +// for example). See bootstrap/ for more information. + + +/** + * @define {boolean} Whether to enable the debug loader. + * + * If enabled, a call to goog.require() will attempt to load the namespace by + * appending a script tag to the DOM (if the namespace has been registered). + * + * If disabled, goog.require() will simply assert that the namespace has been + * provided (and depend on the fact that some outside tool correctly ordered + * the script). + */ +goog.define('goog.ENABLE_DEBUG_LOADER', true); + + +/** + * @param {string} msg + * @private + */ +goog.logToConsole_ = function(msg) { + if (goog.global.console) { + goog.global.console['error'](msg); + } +}; + + +/** + * Implements a system for the dynamic resolution of dependencies that works in + * parallel with the BUILD system. Note that all calls to goog.require will be + * stripped by the compiler. + * @see goog.provide + * @param {string} name Namespace to include (as was given in goog.provide()) in + * the form "goog.package.part". + * @return {?} If called within a goog.module file, the associated namespace or + * module otherwise null. + */ +goog.require = function(name) { + // If the object already exists we do not need to do anything. + if (!COMPILED) { + if (goog.ENABLE_DEBUG_LOADER && goog.IS_OLD_IE_) { + goog.maybeProcessDeferredDep_(name); + } + + if (goog.isProvided_(name)) { + if (goog.isInModuleLoader_()) { + return goog.module.getInternal_(name); + } + } else if (goog.ENABLE_DEBUG_LOADER) { + var path = goog.getPathFromDeps_(name); + if (path) { + goog.writeScripts_(path); + } else { + var errorMessage = 'goog.require could not find: ' + name; + goog.logToConsole_(errorMessage); + + throw Error(errorMessage); + } + } + + return null; + } +}; + + +/** + * Path for included scripts. + * @type {string} + */ +goog.basePath = ''; + + +/** + * A hook for overriding the base path. + * @type {string|undefined} + */ +goog.global.CLOSURE_BASE_PATH; + + +/** + * Whether to attempt to load Closure's deps file. By default, when uncompiled, + * deps files will attempt to be loaded. + * @type {boolean|undefined} + */ +goog.global.CLOSURE_NO_DEPS; + + +/** + * A function to import a single script. This is meant to be overridden when + * Closure is being run in non-HTML contexts, such as web workers. It's defined + * in the global scope so that it can be set before base.js is loaded, which + * allows deps.js to be imported properly. + * + * The function is passed the script source, which is a relative URI. It should + * return true if the script was imported, false otherwise. + * @type {(function(string): boolean)|undefined} + */ +goog.global.CLOSURE_IMPORT_SCRIPT; + + +/** + * Null function used for default values of callbacks, etc. + * @return {void} Nothing. + */ +goog.nullFunction = function() {}; + + +/** + * When defining a class Foo with an abstract method bar(), you can do: + * Foo.prototype.bar = goog.abstractMethod + * + * Now if a subclass of Foo fails to override bar(), an error will be thrown + * when bar() is invoked. + * + * @type {!Function} + * @throws {Error} when invoked to indicate the method should be overridden. + */ +goog.abstractMethod = function() { + throw Error('unimplemented abstract method'); +}; + + +/** + * Adds a {@code getInstance} static method that always returns the same + * instance object. + * @param {!Function} ctor The constructor for the class to add the static + * method to. + */ +goog.addSingletonGetter = function(ctor) { + // instance_ is immediately set to prevent issues with sealed constructors + // such as are encountered when a constructor is returned as the export object + // of a goog.module in unoptimized code. + ctor.instance_ = undefined; + ctor.getInstance = function() { + if (ctor.instance_) { + return ctor.instance_; + } + if (goog.DEBUG) { + // NOTE: JSCompiler can't optimize away Array#push. + goog.instantiatedSingletons_[goog.instantiatedSingletons_.length] = ctor; + } + return ctor.instance_ = new ctor; + }; +}; + + +/** + * All singleton classes that have been instantiated, for testing. Don't read + * it directly, use the {@code goog.testing.singleton} module. The compiler + * removes this variable if unused. + * @type {!Array} + * @private + */ +goog.instantiatedSingletons_ = []; + + +/** + * @define {boolean} Whether to load goog.modules using {@code eval} when using + * the debug loader. This provides a better debugging experience as the + * source is unmodified and can be edited using Chrome Workspaces or similar. + * However in some environments the use of {@code eval} is banned + * so we provide an alternative. + */ +goog.define('goog.LOAD_MODULE_USING_EVAL', true); + + +/** + * @define {boolean} Whether the exports of goog.modules should be sealed when + * possible. + */ +goog.define('goog.SEAL_MODULE_EXPORTS', goog.DEBUG); + + +/** + * The registry of initialized modules: + * the module identifier to module exports map. + * @private @const {!Object} + */ +goog.loadedModules_ = {}; + + +/** + * True if goog.dependencies_ is available. + * @const {boolean} + */ +goog.DEPENDENCIES_ENABLED = !COMPILED && goog.ENABLE_DEBUG_LOADER; + + +/** + * @define {string} How to decide whether to transpile. Valid values + * are 'always', 'never', and 'detect'. The default ('detect') is to + * use feature detection to determine which language levels need + * transpilation. + */ +// NOTE(user): we could expand this to accept a language level to bypass +// detection: e.g. goog.TRANSPILE == 'es5' would transpile ES6 files but +// would leave ES3 and ES5 files alone. +goog.define('goog.TRANSPILE', 'detect'); + + +/** + * @define {string} Path to the transpiler. Executing the script at this + * path (relative to base.js) should define a function $jscomp.transpile. + */ +goog.define('goog.TRANSPILER', 'transpile.js'); + + +if (goog.DEPENDENCIES_ENABLED) { + /** + * This object is used to keep track of dependencies and other data that is + * used for loading scripts. + * @private + * @type {{ + * loadFlags: !Object>, + * nameToPath: !Object, + * requires: !Object>, + * visited: !Object, + * written: !Object, + * deferred: !Object + * }} + */ + goog.dependencies_ = { + loadFlags: {}, // 1 to 1 + + nameToPath: {}, // 1 to 1 + + requires: {}, // 1 to many + + // Used when resolving dependencies to prevent us from visiting file twice. + visited: {}, + + written: {}, // Used to keep track of script files we have written. + + deferred: {} // Used to track deferred module evaluations in old IEs + }; + + + /** + * Tries to detect whether is in the context of an HTML document. + * @return {boolean} True if it looks like HTML document. + * @private + */ + goog.inHtmlDocument_ = function() { + /** @type {Document} */ + var doc = goog.global.document; + return doc != null && 'write' in doc; // XULDocument misses write. + }; + + + /** + * Tries to detect the base path of base.js script that bootstraps Closure. + * @private + */ + goog.findBasePath_ = function() { + if (goog.isDef(goog.global.CLOSURE_BASE_PATH) && + // Anti DOM-clobbering runtime check (b/37736576). + goog.isString(goog.global.CLOSURE_BASE_PATH)) { + goog.basePath = goog.global.CLOSURE_BASE_PATH; + return; + } else if (!goog.inHtmlDocument_()) { + return; + } + /** @type {Document} */ + var doc = goog.global.document; + // If we have a currentScript available, use it exclusively. + var currentScript = doc.currentScript; + if (currentScript) { + var scripts = [currentScript]; + } else { + var scripts = doc.getElementsByTagName('SCRIPT'); + } + // Search backwards since the current script is in almost all cases the one + // that has base.js. + for (var i = scripts.length - 1; i >= 0; --i) { + var script = /** @type {!HTMLScriptElement} */ (scripts[i]); + var src = script.src; + var qmark = src.lastIndexOf('?'); + var l = qmark == -1 ? src.length : qmark; + if (src.substr(l - 7, 7) == 'base.js') { + goog.basePath = src.substr(0, l - 7); + return; + } + } + }; + + + /** + * Imports a script if, and only if, that script hasn't already been imported. + * (Must be called at execution time) + * @param {string} src Script source. + * @param {string=} opt_sourceText The optionally source text to evaluate + * @private + */ + goog.importScript_ = function(src, opt_sourceText) { + var importScript = + goog.global.CLOSURE_IMPORT_SCRIPT || goog.writeScriptTag_; + if (importScript(src, opt_sourceText)) { + goog.dependencies_.written[src] = true; + } + }; + + + /** + * Whether the browser is IE9 or earlier, which needs special handling + * for deferred modules. + * @const @private {boolean} + */ + goog.IS_OLD_IE_ = + !!(!goog.global.atob && goog.global.document && goog.global.document.all); + + + /** + * Whether IE9 or earlier is waiting on a dependency. This ensures that + * deferred modules that have no non-deferred dependencies actually get + * loaded, since if we defer them and then never pull in a non-deferred + * script, then `goog.loadQueuedModules_` will never be called. Instead, + * if not waiting on anything we simply don't defer in the first place. + * @private {boolean} + */ + goog.oldIeWaiting_ = false; + + + /** + * Given a URL initiate retrieval and execution of a script that needs + * pre-processing. + * @param {string} src Script source URL. + * @param {boolean} isModule Whether this is a goog.module. + * @param {boolean} needsTranspile Whether this source needs transpilation. + * @private + */ + goog.importProcessedScript_ = function(src, isModule, needsTranspile) { + // In an attempt to keep browsers from timing out loading scripts using + // synchronous XHRs, put each load in its own script block. + var bootstrap = 'goog.retrieveAndExec_("' + src + '", ' + isModule + ', ' + + needsTranspile + ');'; + + goog.importScript_('', bootstrap); + }; + + + /** @private {!Array} */ + goog.queuedModules_ = []; + + + /** + * Return an appropriate module text. Suitable to insert into + * a script tag (that is unescaped). + * @param {string} srcUrl + * @param {string} scriptText + * @return {string} + * @private + */ + goog.wrapModule_ = function(srcUrl, scriptText) { + if (!goog.LOAD_MODULE_USING_EVAL || !goog.isDef(goog.global.JSON)) { + return '' + + 'goog.loadModule(function(exports) {' + + '"use strict";' + scriptText + + '\n' + // terminate any trailing single line comment. + ';return exports' + + '});' + + '\n//# sourceURL=' + srcUrl + '\n'; + } else { + return '' + + 'goog.loadModule(' + + goog.global.JSON.stringify( + scriptText + '\n//# sourceURL=' + srcUrl + '\n') + + ');'; + } + }; + + // On IE9 and earlier, it is necessary to handle + // deferred module loads. In later browsers, the + // code to be evaluated is simply inserted as a script + // block in the correct order. To eval deferred + // code at the right time, we piggy back on goog.require to call + // goog.maybeProcessDeferredDep_. + // + // The goog.requires are used both to bootstrap + // the loading process (when no deps are available) and + // declare that they should be available. + // + // Here we eval the sources, if all the deps are available + // either already eval'd or goog.require'd. This will + // be the case when all the dependencies have already + // been loaded, and the dependent module is loaded. + // + // But this alone isn't sufficient because it is also + // necessary to handle the case where there is no root + // that is not deferred. For that there we register for an event + // and trigger goog.loadQueuedModules_ handle any remaining deferred + // evaluations. + + /** + * Handle any remaining deferred goog.module evals. + * @private + */ + goog.loadQueuedModules_ = function() { + var count = goog.queuedModules_.length; + if (count > 0) { + var queue = goog.queuedModules_; + goog.queuedModules_ = []; + for (var i = 0; i < count; i++) { + var path = queue[i]; + goog.maybeProcessDeferredPath_(path); + } + } + goog.oldIeWaiting_ = false; + }; + + + /** + * Eval the named module if its dependencies are + * available. + * @param {string} name The module to load. + * @private + */ + goog.maybeProcessDeferredDep_ = function(name) { + if (goog.isDeferredModule_(name) && goog.allDepsAreAvailable_(name)) { + var path = goog.getPathFromDeps_(name); + goog.maybeProcessDeferredPath_(goog.basePath + path); + } + }; + + /** + * @param {string} name The module to check. + * @return {boolean} Whether the name represents a + * module whose evaluation has been deferred. + * @private + */ + goog.isDeferredModule_ = function(name) { + var path = goog.getPathFromDeps_(name); + var loadFlags = path && goog.dependencies_.loadFlags[path] || {}; + var languageLevel = loadFlags['lang'] || 'es3'; + if (path && (loadFlags['module'] == 'goog' || + goog.needsTranspile_(languageLevel))) { + var abspath = goog.basePath + path; + return (abspath) in goog.dependencies_.deferred; + } + return false; + }; + + /** + * @param {string} name The module to check. + * @return {boolean} Whether the name represents a + * module whose declared dependencies have all been loaded + * (eval'd or a deferred module load) + * @private + */ + goog.allDepsAreAvailable_ = function(name) { + var path = goog.getPathFromDeps_(name); + if (path && (path in goog.dependencies_.requires)) { + for (var requireName in goog.dependencies_.requires[path]) { + if (!goog.isProvided_(requireName) && + !goog.isDeferredModule_(requireName)) { + return false; + } + } + } + return true; + }; + + + /** + * @param {string} abspath + * @private + */ + goog.maybeProcessDeferredPath_ = function(abspath) { + if (abspath in goog.dependencies_.deferred) { + var src = goog.dependencies_.deferred[abspath]; + delete goog.dependencies_.deferred[abspath]; + goog.globalEval(src); + } + }; + + + /** + * Load a goog.module from the provided URL. This is not a general purpose + * code loader and does not support late loading code, that is it should only + * be used during page load. This method exists to support unit tests and + * "debug" loaders that would otherwise have inserted script tags. Under the + * hood this needs to use a synchronous XHR and is not recommeneded for + * production code. + * + * The module's goog.requires must have already been satisified; an exception + * will be thrown if this is not the case. This assumption is that no + * "deps.js" file exists, so there is no way to discover and locate the + * module-to-be-loaded's dependencies and no attempt is made to do so. + * + * There should only be one attempt to load a module. If + * "goog.loadModuleFromUrl" is called for an already loaded module, an + * exception will be throw. + * + * @param {string} url The URL from which to attempt to load the goog.module. + */ + goog.loadModuleFromUrl = function(url) { + // Because this executes synchronously, we don't need to do any additional + // bookkeeping. When "goog.loadModule" the namespace will be marked as + // having been provided which is sufficient. + goog.retrieveAndExec_(url, true, false); + }; + + + /** + * Writes a new script pointing to {@code src} directly into the DOM. + * + * NOTE: This method is not CSP-compliant. @see goog.appendScriptSrcNode_ for + * the fallback mechanism. + * + * @param {string} src The script URL. + * @private + */ + goog.writeScriptSrcNode_ = function(src) { + goog.global.document.write( + '