diff --git a/.gitignore b/.gitignore index ab0b706..7616cf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /www-root/nbproject/private/ -/nbproject/private/ \ No newline at end of file +/nbproject/private/ +/coverage/tileFuel/ +/coverage/tiles/ diff --git a/coverage/basic.html b/coverage/basic.html new file mode 100644 index 0000000..f6ea5c7 --- /dev/null +++ b/coverage/basic.html @@ -0,0 +1,23 @@ + + + Basic + + + + + + +
+ + + + + + diff --git a/coverage/carto_fuel.html b/coverage/carto_fuel.html index b183e9e..d17c76f 100644 --- a/coverage/carto_fuel.html +++ b/coverage/carto_fuel.html @@ -28,6 +28,7 @@
  • QGISの設定定義ファイル[fuel_All.qgs]をダウンロード可能です。
  • QGISの使い方」説明書をダウンロード可能です。
  • +

    diff --git a/coverage/fuel.html b/coverage/fuel.html new file mode 100644 index 0000000..698744f --- /dev/null +++ b/coverage/fuel.html @@ -0,0 +1,94 @@ + + + + + OpenStreetMap coverage (amenity=fuel) + + + + +
    +
    +

    OpenStreetMap coverage (燃料給油所を指標にした網羅率)

    +
    +

    +

    (旧版)2017-10-08時点での

    +
    +
    + +
    +
    +

    以下のデータは月に2〜3回程度の頻度で更新を行う予定です。

    +

    PostGISの使い方 

    +

    'QGIS’を使ってPostGISデータベースにあるデータを直接見ることで、GSの入力状況(入力済み/未入力)を詳細に知ることができます。マッピング計画の参考にしてください。

    + QGISでの表示
    +
      +
    • QGISの設定定義ファイル[fuel_All.qgs]をダウンロード可能です。
    • +
    • QGISの使い方」説明書をダウンロード可能です。
    • +
    + + +
    +
    +
    + +

    国土数値情報の燃料給油所位置を中心とする、200m四方の矩形領域に存在するOSMのamenity=fuelノードの評価点の合計を数える。
    +
    + 評価点;
    + blandがない ーー> 1ポイント
    + fixmeがある ーー> 1ポイント
    + blandがある ーー> 2ポイント
    +
    + 対象ノード;
    + amenity = fuel
    +
    + レベル分け:
    + 評価点の合計値をもとに以下に色分けしています。
    + 0ポイント → 赤 (未入力)
    + 1ポイント以上 → オレンジ (一次入力)
    + 2ポイント以上 → 青 (入力済)
    +

    +
    + +
    +
    + + + + + + + + + + + +
    マッピングカバー率 都道府県別
    code都道府県標本数カバー率(%)
    +
    +

    +
    +
    + + + + + + + + diff --git a/coverage/fuel.js b/coverage/fuel.js new file mode 100644 index 0000000..009e277 --- /dev/null +++ b/coverage/fuel.js @@ -0,0 +1,71 @@ +var debug = {}; + +var map = L.map('map').setView([36.131, 140.241], 8); // Kasumigaura + +//OSMレイヤー追加 +L.tileLayer( + 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { + attribution: 'Map data © OpenStreetMap', + maxZoom: 16 + } +).addTo(map); + + +var mvtSource = new L.TileLayer.MVTSource({ + url: "./tileFuel/{z}/{x}/{y}.pbf", + debug: false, + clickableLayers: ["gs_map"], + getIDForLayerFeature: function(feature) { + return feature.properties.id; + }, + + /** + * The filter function gets called when iterating though each vector tile feature (vtf). You have access + * to every property associated with a given feature (the feature, and the layer). You can also filter + * based of the context (each tile that the feature is drawn onto). + * + * Returning false skips over the feature and it is not drawn. + * + * @param feature + * @returns {boolean} + */ + filter: function(feature, context) { + if (feature.layer.name === 'gs_map') { + return true; + } + return false; + }, + + style: function (feature) { + var style = {}; + + var type = feature.type; + if (type == 1) { + //'Point' + var fixed = feature.properties.fixed; + if (fixed > 0) { + if (fixed > 49) { + style.color = 'rgba(0,255,0,1)'; + } + else { + style.color = 'rgba(255,200,0,1)'; + } + } + else { + style.color = 'rgba(255,0,0,1)'; + } + style.radius = 5; + style.selected = { + radius: 6 + }; + } + return style; + } +}); + +//Globals that we can change later. +var fillColor = 'rgba(149,139,255,0.4)'; +var strokeColor = 'rgb(20,20,20)'; + +//Add layer +map.addLayer(mvtSource); diff --git a/lib/Leaflet.MapboxVectorTile.js b/lib/Leaflet.MapboxVectorTile.js new file mode 100644 index 0000000..9abb8eb --- /dev/null +++ b/lib/Leaflet.MapboxVectorTile.js @@ -0,0 +1,4100 @@ +(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 2147483647) throw new Error('TODO: Handle numbers >= 2^30'); + // zigzag encoding + return ((num >> 1) ^ -(num & 1)); +}; + +Protobuf.prototype.readString = function() { + var bytes = this.readVarint(); + // TODO: bounds checking + var chr = String.fromCharCode; + var b = this.buf; + var p = this.pos; + var end = this.pos + bytes; + var str = ''; + while (p < end) { + if (b[p] <= 0x7F) str += chr(b[p++]); + else if (b[p] <= 0xBF) throw new Error('Invalid UTF-8 codepoint: ' + b[p]); + else if (b[p] <= 0xDF) str += chr((b[p++] & 0x1F) << 6 | (b[p++] & 0x3F)); + else if (b[p] <= 0xEF) str += chr((b[p++] & 0x1F) << 12 | (b[p++] & 0x3F) << 6 | (b[p++] & 0x3F)); + else if (b[p] <= 0xF7) p += 4; // We can't handle these codepoints in JS, so skip. + else if (b[p] <= 0xFB) p += 5; + else if (b[p] <= 0xFD) p += 6; + else throw new Error('Invalid UTF-8 codepoint: ' + b[p]); + } + this.pos += bytes; + return str; +}; + +Protobuf.prototype.readBuffer = function() { + var bytes = this.readVarint(); + var buffer = this.buf.subarray(this.pos, this.pos + bytes); + this.pos += bytes; + return buffer; +}; + +Protobuf.prototype.readPacked = function(type) { + // TODO: bounds checking + var bytes = this.readVarint(); + var end = this.pos + bytes; + var array = []; + while (this.pos < end) { + array.push(this['read' + type]()); + } + return array; +}; + +Protobuf.prototype.skip = function(val) { + // TODO: bounds checking + var type = val & 0x7; + switch (type) { + /* varint */ case Protobuf.Varint: while (this.buf[this.pos++] > 0x7f); break; + /* 64 bit */ case Protobuf.Int64: this.pos += 8; break; + /* length */ case Protobuf.Message: var bytes = this.readVarint(); this.pos += bytes; break; + /* 32 bit */ case Protobuf.Int32: this.pos += 4; break; + default: throw new Error('Unimplemented type: ' + type); + } +}; + +// === WRITING ================================================================= + +Protobuf.prototype.writeTag = function(tag, type) { + this.writeVarint((tag << 3) | type); +}; + +Protobuf.prototype.realloc = function(min) { + var length = this.buf.length; + while (length < this.pos + min) length *= 2; + if (length != this.buf.length) { + var buf = new Buffer(length); + this.buf.copy(buf); + this.buf = buf; + } +}; + +Protobuf.prototype.finish = function() { + return this.buf.slice(0, this.pos); +}; + +Protobuf.prototype.writePacked = function(type, tag, items) { + if (!items.length) return; + + var message = new Protobuf(); + for (var i = 0; i < items.length; i++) { + message['write' + type](items[i]); + } + var data = message.finish(); + + this.writeTag(tag, Protobuf.Packed); + this.writeBuffer(data); +}; + +Protobuf.prototype.writeUInt32 = function(val) { + this.realloc(4); + this.buf.writeUInt32LE(val, this.pos); + this.pos += 4; +}; + +Protobuf.prototype.writeTaggedUInt32 = function(tag, val) { + this.writeTag(tag, Protobuf.Int32); + this.writeUInt32(val); +}; + +Protobuf.prototype.writeVarint = function(val) { + val = Number(val); + if (isNaN(val)) { + val = 0; + } + + if (val <= 0x7f) { + this.realloc(1); + this.buf[this.pos++] = val; + } else if (val <= 0x3fff) { + this.realloc(2); + this.buf[this.pos++] = 0x80 | ((val >>> 0) & 0x7f); + this.buf[this.pos++] = 0x00 | ((val >>> 7) & 0x7f); + } else if (val <= 0x1ffffff) { + this.realloc(3); + this.buf[this.pos++] = 0x80 | ((val >>> 0) & 0x7f); + this.buf[this.pos++] = 0x80 | ((val >>> 7) & 0x7f); + this.buf[this.pos++] = 0x00 | ((val >>> 14) & 0x7f); + } else if (val <= 0xfffffff) { + this.realloc(4); + this.buf[this.pos++] = 0x80 | ((val >>> 0) & 0x7f); + this.buf[this.pos++] = 0x80 | ((val >>> 7) & 0x7f); + this.buf[this.pos++] = 0x80 | ((val >>> 14) & 0x7f); + this.buf[this.pos++] = 0x00 | ((val >>> 21) & 0x7f); + } else { + while (val > 0) { + var b = val & 0x7f; + val = Math.floor(val / 128); + if (val > 0) b |= 0x80 + this.realloc(1); + this.buf[this.pos++] = b; + } + } +}; + +Protobuf.prototype.writeTaggedVarint = function(tag, val) { + this.writeTag(tag, Protobuf.Varint); + this.writeVarint(val); +}; + +Protobuf.prototype.writeSVarint = function(val) { + if (val >= 0) { + this.writeVarint(val * 2); + } else { + this.writeVarint(val * -2 - 1); + } +}; + +Protobuf.prototype.writeTaggedSVarint = function(tag, val) { + this.writeTag(tag, Protobuf.Varint); + this.writeSVarint(val); +}; + +Protobuf.prototype.writeBoolean = function(val) { + this.writeVarint(Boolean(val)); +}; + +Protobuf.prototype.writeTaggedBoolean = function(tag, val) { + this.writeTaggedVarint(tag, Boolean(val)); +}; + +Protobuf.prototype.writeString = function(str) { + str = String(str); + var bytes = Buffer.byteLength(str); + this.writeVarint(bytes); + this.realloc(bytes); + this.buf.write(str, this.pos); + this.pos += bytes; +}; + +Protobuf.prototype.writeTaggedString = function(tag, str) { + this.writeTag(tag, Protobuf.String); + this.writeString(str); +}; + +Protobuf.prototype.writeFloat = function(val) { + this.realloc(4); + this.buf.writeFloatLE(val, this.pos); + this.pos += 4; +}; + +Protobuf.prototype.writeTaggedFloat = function(tag, val) { + this.writeTag(tag, Protobuf.Int32); + this.writeFloat(val); +}; + +Protobuf.prototype.writeDouble = function(val) { + this.realloc(8); + this.buf.writeDoubleLE(val, this.pos); + this.pos += 8; +}; + +Protobuf.prototype.writeTaggedDouble = function(tag, val) { + this.writeTag(tag, Protobuf.Int64); + this.writeDouble(val); +}; + +Protobuf.prototype.writeBuffer = function(buffer) { + var bytes = buffer.length; + this.writeVarint(bytes); + this.realloc(bytes); + buffer.copy(this.buf, this.pos); + this.pos += bytes; +}; + +Protobuf.prototype.writeTaggedBuffer = function(tag, buffer) { + this.writeTag(tag, Protobuf.String); + this.writeBuffer(buffer); +}; + +Protobuf.prototype.writeMessage = function(tag, protobuf) { + var buffer = protobuf.finish(); + this.writeTag(tag, Protobuf.Message); + this.writeBuffer(buffer); +}; + +}).call(this,require("buffer").Buffer) + +},{"buffer":14,"ieee754":2}],2:[function(require,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 +} + +},{}],3:[function(require,module,exports){ +'use strict'; + +module.exports = Point; + +function Point(x, y) { + this.x = x; + this.y = y; +} + +Point.prototype = { + clone: function() { return new Point(this.x, this.y); }, + + add: function(p) { return this.clone()._add(p); }, + sub: function(p) { return this.clone()._sub(p); }, + mult: function(k) { return this.clone()._mult(k); }, + div: function(k) { return this.clone()._div(k); }, + rotate: function(a) { return this.clone()._rotate(a); }, + matMult: function(m) { return this.clone()._matMult(m); }, + unit: function() { return this.clone()._unit(); }, + perp: function() { return this.clone()._perp(); }, + round: function() { return this.clone()._round(); }, + + mag: function() { + return Math.sqrt(this.x * this.x + this.y * this.y); + }, + + equals: function(p) { + return this.x === p.x && + this.y === p.y; + }, + + dist: function(p) { + return Math.sqrt(this.distSqr(p)); + }, + + distSqr: function(p) { + var dx = p.x - this.x, + dy = p.y - this.y; + return dx * dx + dy * dy; + }, + + angle: function() { + return Math.atan2(this.y, this.x); + }, + + angleTo: function(b) { + return Math.atan2(this.y - b.y, this.x - b.x); + }, + + angleWith: function(b) { + return this.angleWithSep(b.x, b.y); + }, + + // Find the angle of the two vectors, solving the formula for the cross product a x b = |a||b|sin(θ) for θ. + angleWithSep: function(x, y) { + return Math.atan2( + this.x * y - this.y * x, + this.x * x + this.y * y); + }, + + _matMult: function(m) { + var x = m[0] * this.x + m[1] * this.y, + y = m[2] * this.x + m[3] * this.y; + this.x = x; + this.y = y; + return this; + }, + + _add: function(p) { + this.x += p.x; + this.y += p.y; + return this; + }, + + _sub: function(p) { + this.x -= p.x; + this.y -= p.y; + return this; + }, + + _mult: function(k) { + this.x *= k; + this.y *= k; + return this; + }, + + _div: function(k) { + this.x /= k; + this.y /= k; + return this; + }, + + _unit: function() { + this._div(this.mag()); + return this; + }, + + _perp: function() { + var y = this.y; + this.y = this.x; + this.x = -y; + return this; + }, + + _rotate: function(angle) { + var cos = Math.cos(angle), + sin = Math.sin(angle), + x = cos * this.x - sin * this.y, + y = sin * this.x + cos * this.y; + this.x = x; + this.y = y; + return this; + }, + + _round: function() { + this.x = Math.round(this.x); + this.y = Math.round(this.y); + return this; + } +}; + +// constructs Point from an array if necessary +Point.convert = function (a) { + if (a instanceof Point) { + return a; + } + if (Array.isArray(a)) { + return new Point(a[0], a[1]); + } + return a; +}; + +},{}],4:[function(require,module,exports){ +module.exports.VectorTile = require('./lib/vectortile.js'); +module.exports.VectorTileFeature = require('./lib/vectortilefeature.js'); +module.exports.VectorTileLayer = require('./lib/vectortilelayer.js'); + +},{"./lib/vectortile.js":5,"./lib/vectortilefeature.js":6,"./lib/vectortilelayer.js":7}],5:[function(require,module,exports){ +'use strict'; + +var VectorTileLayer = require('./vectortilelayer'); + +module.exports = VectorTile; + +function VectorTile(buffer, end) { + + this.layers = {}; + this._buffer = buffer; + + end = end || buffer.length; + + while (buffer.pos < end) { + var val = buffer.readVarint(), + tag = val >> 3; + + if (tag == 3) { + var layer = this.readLayer(); + if (layer.length) this.layers[layer.name] = layer; + } else { + buffer.skip(val); + } + } +} + +VectorTile.prototype.readLayer = function() { + var buffer = this._buffer, + bytes = buffer.readVarint(), + end = buffer.pos + bytes, + layer = new VectorTileLayer(buffer, end); + + buffer.pos = end; + + return layer; +}; + +},{"./vectortilelayer":7}],6:[function(require,module,exports){ +'use strict'; + +var Point = require('point-geometry'); + +module.exports = VectorTileFeature; + +function VectorTileFeature(buffer, end, extent, keys, values) { + + this.properties = {}; + + // Public + this.extent = extent; + this.type = 0; + + // Private + this._buffer = buffer; + this._geometry = -1; + + end = end || buffer.length; + + while (buffer.pos < end) { + var val = buffer.readVarint(), + tag = val >> 3; + + if (tag == 1) { + this._id = buffer.readVarint(); + + } else if (tag == 2) { + var tagLen = buffer.readVarint(), + tagEnd = buffer.pos + tagLen; + + while (buffer.pos < tagEnd) { + var key = keys[buffer.readVarint()]; + var value = values[buffer.readVarint()]; + this.properties[key] = value; + } + + } else if (tag == 3) { + this.type = buffer.readVarint(); + + } else if (tag == 4) { + this._geometry = buffer.pos; + buffer.skip(val); + + } else { + buffer.skip(val); + } + } +} + +VectorTileFeature.types = ['Unknown', 'Point', 'LineString', 'Polygon']; + +VectorTileFeature.prototype.loadGeometry = function() { + var buffer = this._buffer; + buffer.pos = this._geometry; + + var bytes = buffer.readVarint(), + end = buffer.pos + bytes, + cmd = 1, + length = 0, + x = 0, + y = 0, + lines = [], + line; + + while (buffer.pos < end) { + if (!length) { + var cmd_length = buffer.readVarint(); + cmd = cmd_length & 0x7; + length = cmd_length >> 3; + } + + length--; + + if (cmd === 1 || cmd === 2) { + x += buffer.readSVarint(); + y += buffer.readSVarint(); + + if (cmd === 1) { + // moveTo + if (line) { + lines.push(line); + } + line = []; + } + + line.push(new Point(x, y)); + } else if (cmd === 7) { + // closePolygon + line.push(line[0].clone()); + } else { + throw new Error('unknown command ' + cmd); + } + } + + if (line) lines.push(line); + + return lines; +}; + +VectorTileFeature.prototype.bbox = function() { + var buffer = this._buffer; + buffer.pos = this._geometry; + + var bytes = buffer.readVarint(), + end = buffer.pos + bytes, + + cmd = 1, + length = 0, + x = 0, + y = 0, + x1 = Infinity, + x2 = -Infinity, + y1 = Infinity, + y2 = -Infinity; + + while (buffer.pos < end) { + if (!length) { + var cmd_length = buffer.readVarint(); + cmd = cmd_length & 0x7; + length = cmd_length >> 3; + } + + length--; + + if (cmd === 1 || cmd === 2) { + x += buffer.readSVarint(); + y += buffer.readSVarint(); + if (x < x1) x1 = x; + if (x > x2) x2 = x; + if (y < y1) y1 = y; + if (y > y2) y2 = y; + + } else if (cmd !== 7) { + throw new Error('unknown command ' + cmd); + } + } + + return [x1, y1, x2, y2]; +}; + +},{"point-geometry":3}],7:[function(require,module,exports){ +'use strict'; + +var VectorTileFeature = require('./vectortilefeature.js'); + +module.exports = VectorTileLayer; +function VectorTileLayer(buffer, end) { + // Public + this.version = 1; + this.name = null; + this.extent = 4096; + this.length = 0; + + // Private + this._buffer = buffer; + this._keys = []; + this._values = []; + this._features = []; + + var val, tag; + + end = end || buffer.length; + + while (buffer.pos < end) { + val = buffer.readVarint(); + tag = val >> 3; + + if (tag === 15) { + this.version = buffer.readVarint(); + } else if (tag === 1) { + this.name = buffer.readString(); + } else if (tag === 5) { + this.extent = buffer.readVarint(); + } else if (tag === 2) { + this.length++; + this._features.push(buffer.pos); + buffer.skip(val); + + } else if (tag === 3) { + this._keys.push(buffer.readString()); + } else if (tag === 4) { + this._values.push(this.readFeatureValue()); + } else { + buffer.skip(val); + } + } +} + +VectorTileLayer.prototype.readFeatureValue = function() { + var buffer = this._buffer, + value = null, + bytes = buffer.readVarint(), + end = buffer.pos + bytes, + val, tag; + + while (buffer.pos < end) { + val = buffer.readVarint(); + tag = val >> 3; + + if (tag == 1) { + value = buffer.readString(); + } else if (tag == 2) { + throw new Error('read float'); + } else if (tag == 3) { + value = buffer.readDouble(); + } else if (tag == 4) { + value = buffer.readVarint(); + } else if (tag == 5) { + throw new Error('read uint'); + } else if (tag == 6) { + value = buffer.readSVarint(); + } else if (tag == 7) { + value = Boolean(buffer.readVarint()); + } else { + buffer.skip(val); + } + } + + return value; +}; + +// return feature `i` from this layer as a `VectorTileFeature` +VectorTileLayer.prototype.feature = function(i) { + if (i < 0 || i >= this._features.length) throw new Error('feature index out of bounds'); + + this._buffer.pos = this._features[i]; + var end = this._buffer.readVarint() + this._buffer.pos; + + return new VectorTileFeature(this._buffer, end, this.extent, this._keys, this._values); +}; + +},{"./vectortilefeature.js":6}],8:[function(require,module,exports){ +/** + * Created by Ryan Whitley, Daniel Duarte, and Nicholas Hallahan + * on 6/03/14. + */ +var Util = require('./MVTUtil'); +var StaticLabel = require('./StaticLabel/StaticLabel.js'); + +module.exports = MVTFeature; + +function MVTFeature(mvtLayer, vtf, ctx, id, style) { + if (!vtf) return null; + + // Apply all of the properties of vtf to this object. + for (var key in vtf) { + this[key] = vtf[key]; + } + + this.mvtLayer = mvtLayer; + this.mvtSource = mvtLayer.mvtSource; + this.map = mvtLayer.mvtSource.map; + + this.id = id; + + this.layerLink = this.mvtSource.layerLink; + this.toggleEnabled = true; + this.selected = false; + + // how much we divide the coordinate from the vector tile + this.divisor = vtf.extent / ctx.tileSize; + this.extent = vtf.extent; + this.tileSize = ctx.tileSize; + + //An object to store the paths and contexts for this feature + this.tiles = {}; + + this.style = style; + + //Add to the collection + this.addTileFeature(vtf, ctx); + + var self = this; + this.map.on('zoomend', function() { + self.staticLabel = null; + }); + + if (style && style.dynamicLabel && typeof style.dynamicLabel === 'function') { + this.dynamicLabel = this.mvtSource.dynamicLabel.createFeature(this); + } + + ajax(self); +} + + +function ajax(self) { + var style = self.style; + if (style && style.ajaxSource && typeof style.ajaxSource === 'function') { + var ajaxEndpoint = style.ajaxSource(self); + if (ajaxEndpoint) { + Util.getJSON(ajaxEndpoint, function(error, response, body) { + if (error) { + throw ['ajaxSource AJAX Error', error]; + } else { + ajaxCallback(self, response); + return true; + } + }); + } + } + return false; +} + +function ajaxCallback(self, response) { + self.ajaxData = response; + + /** + * You can attach a callback function to a feature in your app + * that will get called whenever new ajaxData comes in. This + * can be used to update UI that looks at data from within a feature. + * + * setStyle may possibly have a style with a different ajaxData source, + * and you would potentially get new contextual data for your feature. + * + * TODO: This needs to be documented. + */ + if (typeof self.ajaxDataReceived === 'function') { + self.ajaxDataReceived(self, response); + } + + self._setStyle(self.mvtLayer.style); + redrawTiles(self); +} + +MVTFeature.prototype._setStyle = function(styleFn) { + this.style = styleFn(this, this.ajaxData); + + // The label gets removed, and the (re)draw, + // that is initiated by the MVTLayer creates a new label. + this.removeLabel(); +}; + +MVTFeature.prototype.setStyle = function(styleFn) { + this.ajaxData = null; + this.style = styleFn(this, null); + var hasAjaxSource = ajax(this); + if (!hasAjaxSource) { + // The label gets removed, and the (re)draw, + // that is initiated by the MVTLayer creates a new label. + this.removeLabel(); + } +}; + +MVTFeature.prototype.draw = function(canvasID) { + //Get the info from the tiles list + var tileInfo = this.tiles[canvasID]; + + var vtf = tileInfo.vtf; + var ctx = tileInfo.ctx; + + //Get the actual canvas from the parent layer's _tiles object. + var xy = canvasID.split(":").slice(1, 3).join(":"); + ctx.canvas = this.mvtLayer._tiles[xy]; + +// This could be used to directly compute the style function from the layer on every draw. +// This is much less efficient... +// this.style = this.mvtLayer.style(this); + + if (this.selected) { + var style = this.style.selected || this.style; + } else { + var style = this.style; + } + + switch (vtf.type) { + case 1: //Point + this._drawPoint(ctx, vtf.coordinates, style); + if (!this.staticLabel && typeof this.style.staticLabel === 'function') { + if (this.style.ajaxSource && !this.ajaxData) { + break; + } + this._drawStaticLabel(ctx, vtf.coordinates, style); + } + break; + + case 2: //LineString + this._drawLineString(ctx, vtf.coordinates, style); + break; + + case 3: //Polygon + this._drawPolygon(ctx, vtf.coordinates, style); + break; + + default: + throw new Error('Unmanaged type: ' + vtf.type); + } + +}; + +MVTFeature.prototype.getPathsForTile = function(canvasID) { + //Get the info from the parts list + return this.tiles[canvasID].paths; +}; + +MVTFeature.prototype.addTileFeature = function(vtf, ctx) { + //Store the important items in the tiles list + + //We only want to store info for tiles for the current map zoom. If it is tile info for another zoom level, ignore it + //Also, if there are existing tiles in the list for other zoom levels, expunge them. + var zoom = this.map.getZoom(); + + if(ctx.zoom != zoom) return; + + this.clearTileFeatures(zoom); //TODO: This iterates thru all tiles every time a new tile is added. Figure out a better way to do this. + + this.tiles[ctx.id] = { + ctx: ctx, + vtf: vtf, + paths: [] + }; + +}; + + +/** + * Clear the inner list of tile features if they don't match the given zoom. + * + * @param zoom + */ +MVTFeature.prototype.clearTileFeatures = function(zoom) { + //If stored tiles exist for other zoom levels, expunge them from the list. + for (var key in this.tiles) { + if(key.split(":")[0] != zoom) delete this.tiles[key]; + } +}; + +/** + * Redraws all of the tiles associated with a feature. Useful for + * style change and toggling. + * + * @param self + */ +function redrawTiles(self) { + //Redraw the whole tile, not just this vtf + var tiles = self.tiles; + var mvtLayer = self.mvtLayer; + + for (var id in tiles) { + var tileZoom = parseInt(id.split(':')[0]); + var mapZoom = self.map.getZoom(); + if (tileZoom === mapZoom) { + //Redraw the tile + mvtLayer.redrawTile(id); + } + } +} + +MVTFeature.prototype.toggle = function() { + if (this.selected) { + this.deselect(); + } else { + this.select(); + } +}; + +MVTFeature.prototype.select = function() { + this.selected = true; + this.mvtSource.featureSelected(this); + redrawTiles(this); + var linkedFeature = this.linkedFeature(); + if (linkedFeature && linkedFeature.staticLabel && !linkedFeature.staticLabel.selected) { + linkedFeature.staticLabel.select(); + } +}; + +MVTFeature.prototype.deselect = function() { + this.selected = false; + this.mvtSource.featureDeselected(this); + redrawTiles(this); + var linkedFeature = this.linkedFeature(); + if (linkedFeature && linkedFeature.staticLabel && linkedFeature.staticLabel.selected) { + linkedFeature.staticLabel.deselect(); + } +}; + +MVTFeature.prototype.on = function(eventType, callback) { + this._eventHandlers[eventType] = callback; +}; + +MVTFeature.prototype._drawPoint = function(ctx, coordsArray, style) { + if (!style) return; + if (!ctx || !ctx.canvas) return; + + var tile = this.tiles[ctx.id]; + + //Get radius + var radius = 1; + if (typeof style.radius === 'function') { + radius = style.radius(ctx.zoom); //Allows for scale dependent rednering + } + else{ + radius = style.radius; + } + + var p = this._tilePoint(coordsArray[0][0]); + var c = ctx.canvas; + var ctx2d; + try{ + ctx2d = c.getContext('2d'); + } + catch(e){ + console.log("_drawPoint error: " + e); + return; + } + + ctx2d.beginPath(); + ctx2d.fillStyle = style.color; + ctx2d.arc(p.x, p.y, radius, 0, Math.PI * 2); + ctx2d.closePath(); + ctx2d.fill(); + + if(style.lineWidth && style.strokeStyle){ + ctx2d.lineWidth = style.lineWidth; + ctx2d.strokeStyle = style.strokeStyle; + ctx2d.stroke(); + } + + ctx2d.restore(); + tile.paths.push([p]); +}; + +MVTFeature.prototype._drawLineString = function(ctx, coordsArray, style) { + if (!style) return; + if (!ctx || !ctx.canvas) return; + + var ctx2d = ctx.canvas.getContext('2d'); + ctx2d.strokeStyle = style.color; + ctx2d.lineWidth = style.size; + ctx2d.beginPath(); + + var projCoords = []; + var tile = this.tiles[ctx.id]; + + for (var gidx in coordsArray) { + var coords = coordsArray[gidx]; + + for (i = 0; i < coords.length; i++) { + var method = (i === 0 ? 'move' : 'line') + 'To'; + var proj = this._tilePoint(coords[i]); + projCoords.push(proj); + ctx2d[method](proj.x, proj.y); + } + } + + ctx2d.stroke(); + ctx2d.restore(); + + tile.paths.push(projCoords); +}; + +MVTFeature.prototype._drawPolygon = function(ctx, coordsArray, style) { + if (!style) return; + if (!ctx || !ctx.canvas) return; + + var ctx2d = ctx.canvas.getContext('2d'); + var outline = style.outline; + + // color may be defined via function to make choropleth work right + if (typeof style.color === 'function') { + ctx2d.fillStyle = style.color(ctx2d); + } else { + ctx2d.fillStyle = style.color; + } + + if (outline) { + ctx2d.strokeStyle = outline.color; + ctx2d.lineWidth = outline.size; + } + ctx2d.beginPath(); + + var projCoords = []; + var tile = this.tiles[ctx.id]; + + var featureLabel = this.dynamicLabel; + if (featureLabel) { + featureLabel.addTilePolys(ctx, coordsArray); + } + + for (var gidx = 0, len = coordsArray.length; gidx < len; gidx++) { + var coords = coordsArray[gidx]; + + for (var i = 0; i < coords.length; i++) { + var coord = coords[i]; + var method = (i === 0 ? 'move' : 'line') + 'To'; + var proj = this._tilePoint(coords[i]); + projCoords.push(proj); + ctx2d[method](proj.x, proj.y); + } + } + + ctx2d.closePath(); + ctx2d.fill(); + if (outline) { + ctx2d.stroke(); + } + + tile.paths.push(projCoords); + +}; + +MVTFeature.prototype._drawStaticLabel = function(ctx, coordsArray, style) { + if (!style) return; + if (!ctx) return; + + // If the corresponding layer is not on the map, + // we dont want to put on a label. + if (!this.mvtLayer._map) return; + + var vecPt = this._tilePoint(coordsArray[0][0]); + + // We're making a standard Leaflet Marker for this label. + var p = this._project(vecPt, ctx.tile.x, ctx.tile.y, this.extent, this.tileSize); //vectile pt to merc pt + var mercPt = L.point(p.x, p.y); // make into leaflet obj + var latLng = this.map.unproject(mercPt); // merc pt to latlng + + this.staticLabel = new StaticLabel(this, ctx, latLng, style); + this.mvtLayer.featureWithLabelAdded(this); +}; + +MVTFeature.prototype.removeLabel = function() { + if (!this.staticLabel) return; + this.staticLabel.remove(); + this.staticLabel = null; +}; + +/** + * Projects a vector tile point to the Spherical Mercator pixel space for a given zoom level. + * + * @param vecPt + * @param tileX + * @param tileY + * @param extent + * @param tileSize + */ +MVTFeature.prototype._project = function(vecPt, tileX, tileY, extent, tileSize) { + var xOffset = tileX * tileSize; + var yOffset = tileY * tileSize; + return { + x: Math.floor(vecPt.x + xOffset), + y: Math.floor(vecPt.y + yOffset) + }; +}; + +/** + * Takes a coordinate from a vector tile and turns it into a Leaflet Point. + * + * @param ctx + * @param coords + * @returns {eGeomType.Point} + * @private + */ +MVTFeature.prototype._tilePoint = function(coords) { + return new L.Point(coords.x / this.divisor, coords.y / this.divisor); +}; + +MVTFeature.prototype.linkedFeature = function() { + var linkedLayer = this.mvtLayer.linkedLayer(); + if(linkedLayer){ + var linkedFeature = linkedLayer.features[this.id]; + return linkedFeature; + }else{ + return null; + } +}; + + +},{"./MVTUtil":11,"./StaticLabel/StaticLabel.js":12}],9:[function(require,module,exports){ +/** + * Created by Ryan Whitley on 5/17/14. + */ +/** Forked from https://gist.github.com/DGuidi/1716010 **/ +var MVTFeature = require('./MVTFeature'); +var Util = require('./MVTUtil'); + +module.exports = L.TileLayer.Canvas.extend({ + + options: { + debug: false, + isHiddenLayer: false, + getIDForLayerFeature: function() {}, + tileSize: 256, + lineClickTolerance: 2 + }, + + _featureIsClicked: {}, + + _isPointInPoly: function(pt, poly) { + if(poly && poly.length) { + for (var c = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i) + ((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y)) + && (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x) + && (c = !c); + return c; + } + }, + + _getDistanceFromLine: function(pt, pts) { + var min = Number.POSITIVE_INFINITY; + if (pts && pts.length > 1) { + pt = L.point(pt.x, pt.y); + for (var i = 0, l = pts.length - 1; i < l; i++) { + var test = this._projectPointOnLineSegment(pt, pts[i], pts[i + 1]); + if (test.distance <= min) { + min = test.distance; + } + } + } + return min; + }, + + _projectPointOnLineSegment: function(p, r0, r1) { + var lineLength = r0.distanceTo(r1); + if (lineLength < 1) { + return {distance: p.distanceTo(r0), coordinate: r0}; + } + var u = ((p.x - r0.x) * (r1.x - r0.x) + (p.y - r0.y) * (r1.y - r0.y)) / Math.pow(lineLength, 2); + if (u < 0.0000001) { + return {distance: p.distanceTo(r0), coordinate: r0}; + } + if (u > 0.9999999) { + return {distance: p.distanceTo(r1), coordinate: r1}; + } + var a = L.point(r0.x + u * (r1.x - r0.x), r0.y + u * (r1.y - r0.y)); + return {distance: p.distanceTo(a), point: a}; + }, + + initialize: function(mvtSource, options) { + var self = this; + self.mvtSource = mvtSource; + L.Util.setOptions(this, options); + + this.style = options.style; + this.name = options.name; + this._canvasIDToFeatures = {}; + this.features = {}; + this.featuresWithLabels = []; + this._highestCount = 0; + }, + + onAdd: function(map) { + var self = this; + self.map = map; + L.TileLayer.Canvas.prototype.onAdd.call(this, map); + map.on('layerremove', function(e) { + // we only want to do stuff when the layerremove event is on this layer + if (e.layer._leaflet_id === self._leaflet_id) { + removeLabels(self); + } + }); + }, + + drawTile: function(canvas, tilePoint, zoom) { + + var ctx = { + canvas: canvas, + tile: tilePoint, + zoom: zoom, + tileSize: this.options.tileSize + }; + + ctx.id = Util.getContextID(ctx); + + if (!this._canvasIDToFeatures[ctx.id]) { + this._initializeFeaturesHash(ctx); + } + if (!this.features) { + this.features = {}; + } + + }, + + _initializeFeaturesHash: function(ctx){ + this._canvasIDToFeatures[ctx.id] = {}; + this._canvasIDToFeatures[ctx.id].features = []; + this._canvasIDToFeatures[ctx.id].canvas = ctx.canvas; + }, + + _draw: function(ctx) { + //Draw is handled by the parent MVTSource object + }, + getCanvas: function(parentCtx){ + //This gets called if a vector tile feature has already been parsed. + //We've already got the geom, just get on with the drawing. + //Need a way to pluck a canvas element from this layer given the parent layer's id. + //Wait for it to get loaded before proceeding. + var tilePoint = parentCtx.tile; + var ctx = this._tiles[tilePoint.x + ":" + tilePoint.y]; + + if(ctx){ + parentCtx.canvas = ctx; + this.redrawTile(parentCtx.id); + return; + } + + var self = this; + + //This is a timer that will wait for a criterion to return true. + //If not true within the timeout duration, it will move on. + waitFor(function () { + ctx = self._tiles[tilePoint.x + ":" + tilePoint.y]; + if(ctx) { + return true; + } + }, + function(){ + //When it finishes, do this. + ctx = self._tiles[tilePoint.x + ":" + tilePoint.y]; + parentCtx.canvas = ctx; + self.redrawTile(parentCtx.id); + + }, //when done, go to next flow + 2000); //The Timeout milliseconds. After this, give up and move on + + }, + + parseVectorTileLayer: function(vtl, ctx) { + var self = this; + var tilePoint = ctx.tile; + var layerCtx = { canvas: null, id: ctx.id, tile: ctx.tile, zoom: ctx.zoom, tileSize: ctx.tileSize}; + + //See if we can pluck the child tile from this PBF tile layer based on the master layer's tile id. + layerCtx.canvas = self._tiles[tilePoint.x + ":" + tilePoint.y]; + + + + //Initialize this tile's feature storage hash, if it hasn't already been created. Used for when filters are updated, and features are cleared to prepare for a fresh redraw. + if (!this._canvasIDToFeatures[layerCtx.id]) { + this._initializeFeaturesHash(layerCtx); + }else{ + //Clear this tile's previously saved features. + this.clearTileFeatureHash(layerCtx.id); + } + + var features = vtl.parsedFeatures; + for (var i = 0, len = features.length; i < len; i++) { + var vtf = features[i]; //vector tile feature + vtf.layer = vtl; + + /** + * Apply filter on feature if there is one. Defined in the options object + * of TileLayer.MVTSource.js + */ + var filter = self.options.filter; + if (typeof filter === 'function') { + if ( filter(vtf, layerCtx) === false ) continue; + } + + var getIDForLayerFeature; + if (typeof self.options.getIDForLayerFeature === 'function') { + getIDForLayerFeature = self.options.getIDForLayerFeature; + } else { + getIDForLayerFeature = Util.getIDForLayerFeature; + } + var uniqueID = self.options.getIDForLayerFeature(vtf) || i; + var mvtFeature = self.features[uniqueID]; + + /** + * Use layerOrdering function to apply a zIndex property to each vtf. This is defined in + * TileLayer.MVTSource.js. Used below to sort features.npm + */ + var layerOrdering = self.options.layerOrdering; + if (typeof layerOrdering === 'function') { + layerOrdering(vtf, layerCtx); //Applies a custom property to the feature, which is used after we're thru iterating to sort + } + + //Create a new MVTFeature if one doesn't already exist for this feature. + if (!mvtFeature) { + //Get a style for the feature - set it just once for each new MVTFeature + var style = self.style(vtf); + + //create a new feature + self.features[uniqueID] = mvtFeature = new MVTFeature(self, vtf, layerCtx, uniqueID, style); + if (style && style.dynamicLabel && typeof style.dynamicLabel === 'function') { + self.featuresWithLabels.push(mvtFeature); + } + } else { + //Add the new part to the existing feature + mvtFeature.addTileFeature(vtf, layerCtx); + } + + //Associate & Save this feature with this tile for later + if(layerCtx && layerCtx.id) self._canvasIDToFeatures[layerCtx.id]['features'].push(mvtFeature); + + } + + /** + * Apply sorting (zIndex) on feature if there is a function defined in the options object + * of TileLayer.MVTSource.js + */ + var layerOrdering = self.options.layerOrdering; + if (layerOrdering) { + //We've assigned the custom zIndex property when iterating above. Now just sort. + self._canvasIDToFeatures[layerCtx.id].features = self._canvasIDToFeatures[layerCtx.id].features.sort(function(a, b) { + return -(b.properties.zIndex - a.properties.zIndex) + }); + } + + self.redrawTile(layerCtx.id); + }, + + setStyle: function(styleFn) { + // refresh the number for the highest count value + // this is used only for choropleth + this._highestCount = 0; + + // lowest count should not be 0, since we want to figure out the lowest + this._lowestCount = null; + + this.style = styleFn; + for (var key in this.features) { + var feat = this.features[key]; + feat.setStyle(styleFn); + } + var z = this.map.getZoom(); + for (var key in this._tiles) { + var id = z + ':' + key; + this.redrawTile(id); + } + }, + + /** + * As counts for choropleths come in with the ajax data, + * we want to keep track of which value is the highest + * to create the color ramp for the fills of polygons. + * @param count + */ + setHighestCount: function(count) { + if (count > this._highestCount) { + this._highestCount = count; + } + }, + + /** + * Returns the highest number of all of the counts that have come in + * from setHighestCount. This is assumed to be set via ajax callbacks. + * @returns {number} + */ + getHighestCount: function() { + return this._highestCount; + }, + + setLowestCount: function(count) { + if (!this._lowestCount || count < this._lowestCount) { + this._lowestCount = count; + } + }, + + getLowestCount: function() { + return this._lowestCount; + }, + + setCountRange: function(count) { + this.setHighestCount(count); + this.setLowestCount(count); + }, + + //This is the old way. It works, but is slow for mouseover events. Fine for click events. + handleClickEvent: function(evt, cb) { + //Click happened on the GroupLayer (Manager) and passed it here + var tileID = evt.tileID.split(":").slice(1, 3).join(":"); + var zoom = evt.tileID.split(":")[0]; + var canvas = this._tiles[tileID]; + if(!canvas) (cb(evt)); //break out + var x = evt.layerPoint.x - canvas._leaflet_pos.x; + var y = evt.layerPoint.y - canvas._leaflet_pos.y; + + var tilePoint = {x: x, y: y}; + var features = this._canvasIDToFeatures[evt.tileID].features; + + var minDistance = Number.POSITIVE_INFINITY; + var nearest = null; + var j, paths, distance; + + for (var i = 0; i < features.length; i++) { + var feature = features[i]; + switch (feature.type) { + + case 1: //Point - currently rendered as circular paths. Intersect with that. + + //Find the radius of the point. + var radius = 3; + if (typeof feature.style.radius === 'function') { + radius = feature.style.radius(zoom); //Allows for scale dependent rednering + } + else{ + radius = feature.style.radius; + } + + paths = feature.getPathsForTile(evt.tileID); + for (j = 0; j < paths.length; j++) { + //Builds a circle of radius feature.style.radius (assuming circular point symbology). + if(in_circle(paths[j][0].x, paths[j][0].y, radius, x, y)){ + nearest = feature; + minDistance = 0; + } + } + break; + + case 2: //LineString + paths = feature.getPathsForTile(evt.tileID); + for (j = 0; j < paths.length; j++) { + if (feature.style) { + var distance = this._getDistanceFromLine(tilePoint, paths[j]); + var thickness = (feature.selected && feature.style.selected ? feature.style.selected.size : feature.style.size); + if (distance < thickness / 2 + this.options.lineClickTolerance && distance < minDistance) { + nearest = feature; + minDistance = distance; + } + } + } + break; + + case 3: //Polygon + paths = feature.getPathsForTile(evt.tileID); + for (j = 0; j < paths.length; j++) { + if (this._isPointInPoly(tilePoint, paths[j])) { + nearest = feature; + minDistance = 0; // point is inside the polygon, so distance is zero + } + } + break; + } + if (minDistance == 0) break; + } + + if (nearest && nearest.toggleEnabled) { + nearest.toggle(); + } + evt.feature = nearest; + cb(evt); + }, + + clearTile: function(id) { + //id is the entire zoom:x:y. we just want x:y. + var ca = id.split(":"); + var canvasId = ca[1] + ":" + ca[2]; + if (typeof this._tiles[canvasId] === 'undefined') { + console.error("typeof this._tiles[canvasId] === 'undefined'"); + return; + } + var canvas = this._tiles[canvasId]; + + var context = canvas.getContext('2d'); + context.clearRect(0, 0, canvas.width, canvas.height); + }, + + clearTileFeatureHash: function(canvasID){ + this._canvasIDToFeatures[canvasID] = { features: []}; //Get rid of all saved features + }, + + clearLayerFeatureHash: function(){ + this.features = {}; + }, + + redrawTile: function(canvasID) { + //First, clear the canvas + this.clearTile(canvasID); + + // If the features are not in the tile, then there is nothing to redraw. + // This may happen if you call redraw before features have loaded and initially + // drawn the tile. + var featfeats = this._canvasIDToFeatures[canvasID]; + if (!featfeats) { + return; + } + + //Get the features for this tile, and redraw them. + var features = featfeats.features; + + // we want to skip drawing the selected features and draw them last + var selectedFeatures = []; + + // drawing all of the non-selected features + for (var i = 0; i < features.length; i++) { + var feature = features[i]; + if (feature.selected) { + selectedFeatures.push(feature); + } else { + feature.draw(canvasID); + } + } + + // drawing the selected features last + for (var j = 0, len2 = selectedFeatures.length; j < len2; j++) { + var selFeat = selectedFeatures[j]; + selFeat.draw(canvasID); + } + }, + + _resetCanvasIDToFeatures: function(canvasID, canvas) { + + this._canvasIDToFeatures[canvasID] = {}; + this._canvasIDToFeatures[canvasID].features = []; + this._canvasIDToFeatures[canvasID].canvas = canvas; + + }, + + linkedLayer: function() { + if(this.mvtSource.layerLink) { + var linkName = this.mvtSource.layerLink(this.name); + return this.mvtSource.layers[linkName]; + } + else{ + return null; + } + }, + + featureWithLabelAdded: function(feature) { + this.featuresWithLabels.push(feature); + } + +}); + + +function removeLabels(self) { + var features = self.featuresWithLabels; + for (var i = 0, len = features.length; i < len; i++) { + var feat = features[i]; + feat.removeLabel(); + } + self.featuresWithLabels = []; +} + +function in_circle(center_x, center_y, radius, x, y) { + var square_dist = Math.pow((center_x - x), 2) + Math.pow((center_y - y), 2); + return square_dist <= Math.pow(radius, 2); +} +/** + * See https://github.com/ariya/phantomjs/blob/master/examples/waitfor.js + * + * Wait until the test condition is true or a timeout occurs. Useful for waiting + * on a server response or for a ui change (fadeIn, etc.) to occur. + * + * @param testFx javascript condition that evaluates to a boolean, + * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or + * as a callback function. + * @param onReady what to do when testFx condition is fulfilled, + * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or + * as a callback function. + * @param timeOutMillis the max amount of time to wait. If not specified, 3 sec is used. + */ +function waitFor(testFx, onReady, timeOutMillis) { + var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 3000, //< Default Max Timout is 3s + start = new Date().getTime(), + condition = (typeof (testFx) === "string" ? eval(testFx) : testFx()), //< defensive code + interval = setInterval(function () { + if ((new Date().getTime() - start < maxtimeOutMillis) && !condition) { + // If not time-out yet and condition not yet fulfilled + condition = (typeof (testFx) === "string" ? eval(testFx) : testFx()); //< defensive code + } else { + if (!condition) { + // If condition still not fulfilled (timeout but condition is 'false') + console.log("'waitFor()' timeout"); + clearInterval(interval); //< Stop this interval + typeof (onReady) === "string" ? eval(onReady) : onReady('timeout'); //< Do what it's supposed to do once the condition is fulfilled + } else { + // Condition fulfilled (timeout and/or condition is 'true') + console.log("'waitFor()' finished in " + (new Date().getTime() - start) + "ms."); + clearInterval(interval); //< Stop this interval + typeof (onReady) === "string" ? eval(onReady) : onReady('success'); //< Do what it's supposed to do once the condition is fulfilled + } + } + }, 50); //< repeat check every 50ms +}; +},{"./MVTFeature":8,"./MVTUtil":11}],10:[function(require,module,exports){ +var VectorTile = require('vector-tile').VectorTile; +var Protobuf = require('pbf'); +var Point = require('point-geometry'); +var Util = require('./MVTUtil'); +var MVTLayer = require('./MVTLayer'); + + +module.exports = L.TileLayer.MVTSource = L.TileLayer.Canvas.extend({ + + options: { + debug: false, + url: "", //URL TO Vector Tile Source, + getIDForLayerFeature: function() {}, + tileSize: 256, + visibleLayers: [], + xhrHeaders: {} + }, + layers: {}, //Keep a list of the layers contained in the PBFs + processedTiles: {}, //Keep a list of tiles that have been processed already + _eventHandlers: {}, + _triggerOnTilesLoadedEvent: true, //whether or not to fire the onTilesLoaded event when all of the tiles finish loading. + _url: "", //internal URL property + + style: function(feature) { + var style = {}; + + var type = feature.type; + switch (type) { + case 1: //'Point' + style.color = 'rgba(49,79,79,1)'; + style.radius = 5; + style.selected = { + color: 'rgba(255,255,0,0.5)', + radius: 6 + }; + break; + case 2: //'LineString' + style.color = 'rgba(161,217,155,0.8)'; + style.size = 3; + style.selected = { + color: 'rgba(255,25,0,0.5)', + size: 4 + }; + break; + case 3: //'Polygon' + style.color = 'rgba(49,79,79,1)'; + style.outline = { + color: 'rgba(161,217,155,0.8)', + size: 1 + }; + style.selected = { + color: 'rgba(255,140,0,0.3)', + outline: { + color: 'rgba(255,140,0,1)', + size: 2 + } + }; + break; + } + return style; + }, + + + initialize: function(options) { + L.Util.setOptions(this, options); + + //a list of the layers contained in the PBFs + this.layers = {}; + + // tiles currently in the viewport + this.activeTiles = {}; + + // thats that have been loaded and drawn + this.loadedTiles = {}; + + this._url = this.options.url; + + /** + * For some reason, Leaflet has some code that resets the + * z index in the options object. I'm having trouble tracking + * down exactly what does this and why, so for now, we should + * just copy the value to this.zIndex so we can have the right + * number when we make the subsequent MVTLayers. + */ + this.zIndex = options.zIndex; + + if (typeof options.style === 'function') { + this.style = options.style; + } + + if (typeof options.ajaxSource === 'function') { + this.ajaxSource = options.ajaxSource; + } + + this.layerLink = options.layerLink; + + this._eventHandlers = {}; + + this._tilesToProcess = 0; //store the max number of tiles to be loaded. Later, we can use this count to count down PBF loading. + }, + + redraw: function(triggerOnTilesLoadedEvent){ + //Only set to false if it actually is passed in as 'false' + if (triggerOnTilesLoadedEvent === false) { + this._triggerOnTilesLoadedEvent = false; + } + + L.TileLayer.Canvas.prototype.redraw.call(this); + }, + + onAdd: function(map) { + var self = this; + self.map = map; + L.TileLayer.Canvas.prototype.onAdd.call(this, map); + + var mapOnClickCallback = function(e) { + self._onClick(e); + }; + + map.on('click', mapOnClickCallback); + + map.on("layerremove", function(e) { + // check to see if the layer removed is this one + // call a method to remove the child layers (the ones that actually have something drawn on them). + if (e.layer._leaflet_id === self._leaflet_id && e.layer.removeChildLayers) { + e.layer.removeChildLayers(map); + map.off('click', mapOnClickCallback); + } + }); + + self.addChildLayers(map); + + if (typeof DynamicLabel === 'function' ) { + this.dynamicLabel = new DynamicLabel(map, this, {}); + } + + }, + + drawTile: function(canvas, tilePoint, zoom) { + var ctx = { + id: [zoom, tilePoint.x, tilePoint.y].join(":"), + canvas: canvas, + tile: tilePoint, + zoom: zoom, + tileSize: this.options.tileSize + }; + + //Capture the max number of the tiles to load here. this._tilesToProcess is an internal number we use to know when we've finished requesting PBFs. + if(this._tilesToProcess < this._tilesToLoad) this._tilesToProcess = this._tilesToLoad; + + var id = ctx.id = Util.getContextID(ctx); + this.activeTiles[id] = ctx; + + if(!this.processedTiles[ctx.zoom]) this.processedTiles[ctx.zoom] = {}; + + if (this.options.debug) { + this._drawDebugInfo(ctx); + } + this._draw(ctx); + }, + + setOpacity:function(opacity) { + this._setVisibleLayersStyle('opacity',opacity); + }, + + setZIndex:function(zIndex) { + this._setVisibleLayersStyle('zIndex',zIndex); + }, + + _setVisibleLayersStyle:function(style, value) { + for(var key in this.layers) { + this.layers[key]._tileContainer.style[style] = value; + } + }, + + _drawDebugInfo: function(ctx) { + var max = this.options.tileSize; + var g = ctx.canvas.getContext('2d'); + g.strokeStyle = '#000000'; + g.fillStyle = '#FFFF00'; + g.strokeRect(0, 0, max, max); + g.font = "12px Arial"; + g.fillRect(0, 0, 5, 5); + g.fillRect(0, max - 5, 5, 5); + g.fillRect(max - 5, 0, 5, 5); + g.fillRect(max - 5, max - 5, 5, 5); + g.fillRect(max / 2 - 5, max / 2 - 5, 10, 10); + g.strokeText(ctx.zoom + ' ' + ctx.tile.x + ' ' + ctx.tile.y, max / 2 - 30, max / 2 - 10); + }, + + _draw: function(ctx) { + var self = this; + +// //This works to skip fetching and processing tiles if they've already been processed. +// var vectorTile = this.processedTiles[ctx.zoom][ctx.id]; +// //if we've already parsed it, don't get it again. +// if(vectorTile){ +// console.log("Skipping fetching " + ctx.id); +// self.checkVectorTileLayers(parseVT(vectorTile), ctx, true); +// self.reduceTilesToProcessCount(); +// return; +// } + + if (!this._url) return; + var src = this.getTileUrl({ x: ctx.tile.x, y: ctx.tile.y, z: ctx.zoom }); + + var xhr = new XMLHttpRequest(); + xhr.onload = function() { + if (xhr.status == "200") { + + if(!xhr.response) return; + + var arrayBuffer = new Uint8Array(xhr.response); + var buf = new Protobuf(arrayBuffer); + var vt = new VectorTile(buf); + //Check the current map layer zoom. If fast zooming is occurring, then short circuit tiles that are for a different zoom level than we're currently on. + if(self.map && self.map.getZoom() != ctx.zoom) { + console.log("Fetched tile for zoom level " + ctx.zoom + ". Map is at zoom level " + self._map.getZoom()); + return; + } + self.checkVectorTileLayers(parseVT(vt), ctx); + tileLoaded(self, ctx); + } + + //either way, reduce the count of tilesToProcess tiles here + self.reduceTilesToProcessCount(); + }; + + xhr.onerror = function() { + console.log("xhr error: " + xhr.status) + }; + + xhr.open('GET', src, true); //async is true + var headers = self.options.xhrHeaders; + for (var header in headers) { + xhr.setRequestHeader(header, headers[header]) + } + xhr.responseType = 'arraybuffer'; + xhr.send(); + }, + + reduceTilesToProcessCount: function(){ + this._tilesToProcess--; + if(!this._tilesToProcess){ + //Trigger event letting us know that all PBFs have been loaded and processed (or 404'd). + if(this._eventHandlers["PBFLoad"]) this._eventHandlers["PBFLoad"](); + this._pbfLoaded(); + } + }, + + checkVectorTileLayers: function(vt, ctx, parsed) { + var self = this; + + //Check if there are specified visible layers + if(self.options.visibleLayers && self.options.visibleLayers.length > 0){ + //only let thru the layers listed in the visibleLayers array + for(var i=0; i < self.options.visibleLayers.length; i++){ + var layerName = self.options.visibleLayers[i]; + if(vt.layers[layerName]){ + //Proceed with parsing + self.prepareMVTLayers(vt.layers[layerName], layerName, ctx, parsed); + } + } + }else{ + //Parse all vt.layers + for (var key in vt.layers) { + self.prepareMVTLayers(vt.layers[key], key, ctx, parsed); + } + } + }, + + prepareMVTLayers: function(lyr ,key, ctx, parsed) { + var self = this; + + if (!self.layers[key]) { + //Create MVTLayer or MVTPointLayer for user + self.layers[key] = self.createMVTLayer(key, lyr.parsedFeatures[0].type || null); + } + + if (parsed) { + //We've already parsed it. Go get canvas and draw. + self.layers[key].getCanvas(ctx, lyr); + } else { + self.layers[key].parseVectorTileLayer(lyr, ctx); + } + + }, + + createMVTLayer: function(key, type) { + var self = this; + + var getIDForLayerFeature; + if (typeof self.options.getIDForLayerFeature === 'function') { + getIDForLayerFeature = self.options.getIDForLayerFeature; + } else { + getIDForLayerFeature = Util.getIDForLayerFeature; + } + + var options = { + getIDForLayerFeature: getIDForLayerFeature, + filter: self.options.filter, + layerOrdering: self.options.layerOrdering, + style: self.style, + name: key, + asynch: true + }; + + if (self.options.zIndex) { + options.zIndex = self.zIndex; + } + + //Take the layer and create a new MVTLayer or MVTPointLayer if one doesn't exist. + var layer = new MVTLayer(self, options).addTo(self.map); + + return layer; + }, + + getLayers: function() { + return this.layers; + }, + + hideLayer: function(id) { + if (this.layers[id]) { + this._map.removeLayer(this.layers[id]); + if(this.options.visibleLayers.indexOf("id") > -1){ + this.visibleLayers.splice(this.options.visibleLayers.indexOf("id"), 1); + } + } + }, + + showLayer: function(id) { + if (this.layers[id]) { + this._map.addLayer(this.layers[id]); + if(this.options.visibleLayers.indexOf("id") == -1){ + this.visibleLayers.push(id); + } + } + //Make sure manager layer is always in front + this.bringToFront(); + }, + + removeChildLayers: function(map){ + //Remove child layers of this group layer + for (var key in this.layers) { + var layer = this.layers[key]; + map.removeLayer(layer); + } + }, + + addChildLayers: function(map) { + var self = this; + if(self.options.visibleLayers.length > 0){ + //only let thru the layers listed in the visibleLayers array + for(var i=0; i < self.options.visibleLayers.length; i++){ + var layerName = self.options.visibleLayers[i]; + var layer = this.layers[layerName]; + if(layer){ + //Proceed with parsing + map.addLayer(layer); + } + } + }else{ + //Add all layers + for (var key in this.layers) { + var layer = this.layers[key]; + // layer is set to visible and is not already on map + if (!layer._map) { + map.addLayer(layer); + } + } + } + }, + + bind: function(eventType, callback) { + this._eventHandlers[eventType] = callback; + }, + + _onClick: function(evt) { + //Here, pass the event on to the child MVTLayer and have it do the hit test and handle the result. + var self = this; + var onClick = self.options.onClick; + var clickableLayers = self.options.clickableLayers; + var layers = self.layers; + + evt.tileID = getTileURL(evt.latlng.lat, evt.latlng.lng, this.map.getZoom()); + + // We must have an array of clickable layers, otherwise, we just pass + // the event to the public onClick callback in options. + + if(!clickableLayers){ + clickableLayers = Object.keys(self.layers); + } + + if (clickableLayers && clickableLayers.length > 0) { + for (var i = 0, len = clickableLayers.length; i < len; i++) { + var key = clickableLayers[i]; + var layer = layers[key]; + if (layer) { + layer.handleClickEvent(evt, function(evt) { + if (typeof onClick === 'function') { + onClick(evt); + } + }); + } + } + } else { + if (typeof onClick === 'function') { + onClick(evt); + } + } + + }, + + setFilter: function(filterFunction, layerName) { + //take in a new filter function. + //Propagate to child layers. + + //Add filter to all child layers if no layer is specified. + for (var key in this.layers) { + var layer = this.layers[key]; + + if (layerName){ + if(key.toLowerCase() == layerName.toLowerCase()){ + layer.options.filter = filterFunction; //Assign filter to child layer, only if name matches + //After filter is set, the old feature hashes are invalid. Clear them for next draw. + layer.clearLayerFeatureHash(); + //layer.clearTileFeatureHash(); + } + } + else{ + layer.options.filter = filterFunction; //Assign filter to child layer + //After filter is set, the old feature hashes are invalid. Clear them for next draw. + layer.clearLayerFeatureHash(); + //layer.clearTileFeatureHash(); + } + } + }, + + /** + * Take in a new style function and propogate to child layers. + * If you do not set a layer name, it resets the style for all of the layers. + * @param styleFunction + * @param layerName + */ + setStyle: function(styleFn, layerName) { + for (var key in this.layers) { + var layer = this.layers[key]; + if (layerName) { + if(key.toLowerCase() == layerName.toLowerCase()) { + layer.setStyle(styleFn); + } + } else { + layer.setStyle(styleFn); + } + } + }, + + featureSelected: function(mvtFeature) { + if (this.options.mutexToggle) { + if (this._selectedFeature) { + this._selectedFeature.deselect(); + } + this._selectedFeature = mvtFeature; + } + if (this.options.onSelect) { + this.options.onSelect(mvtFeature); + } + }, + + featureDeselected: function(mvtFeature) { + if (this.options.mutexToggle && this._selectedFeature) { + this._selectedFeature = null; + } + if (this.options.onDeselect) { + this.options.onDeselect(mvtFeature); + } + }, + + _pbfLoaded: function() { + //Fires when all tiles from this layer have been loaded and drawn (or 404'd). + + //Make sure manager layer is always in front + this.bringToFront(); + + //See if there is an event to execute + var self = this; + var onTilesLoaded = self.options.onTilesLoaded; + + if (onTilesLoaded && typeof onTilesLoaded === 'function' && this._triggerOnTilesLoadedEvent === true) { + onTilesLoaded(this); + } + self._triggerOnTilesLoadedEvent = true; //reset - if redraw() is called with the optinal 'false' parameter to temporarily disable the onTilesLoaded event from firing. This resets it back to true after a single time of firing as 'false'. + } + +}); + + +if (typeof(Number.prototype.toRad) === "undefined") { + Number.prototype.toRad = function() { + return this * Math.PI / 180; + } +} + +function getTileURL(lat, lon, zoom) { + var xtile = parseInt(Math.floor( (lon + 180) / 360 * (1< + * on 8/15/14. + */ +var Util = module.exports = {}; + +Util.getContextID = function(ctx) { + return [ctx.zoom, ctx.tile.x, ctx.tile.y].join(":"); +}; + +/** + * Default function that gets the id for a layer feature. + * Sometimes this needs to be done in a different way and + * can be specified by the user in the options for L.TileLayer.MVTSource. + * + * @param feature + * @returns {ctx.id|*|id|string|jsts.index.chain.MonotoneChain.id|number} + */ +Util.getIDForLayerFeature = function(feature) { + return feature.properties.id; +}; + +Util.getJSON = function(url, callback) { + var xmlhttp = typeof XMLHttpRequest !== 'undefined' ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); + xmlhttp.onreadystatechange = function() { + var status = xmlhttp.status; + if (xmlhttp.readyState === 4 && status >= 200 && status < 300) { + var json = JSON.parse(xmlhttp.responseText); + callback(null, json); + } else { + callback( { error: true, status: status } ); + } + }; + xmlhttp.open("GET", url, true); + xmlhttp.send(); +}; + +},{}],12:[function(require,module,exports){ +/** + * Created by Nicholas Hallahan + * on 7/31/14. + */ +var Util = require('../MVTUtil'); +module.exports = StaticLabel; + +function StaticLabel(mvtFeature, ctx, latLng, style) { + var self = this; + this.mvtFeature = mvtFeature; + this.map = mvtFeature.map; + this.zoom = ctx.zoom; + this.latLng = latLng; + this.selected = false; + + if (mvtFeature.linkedFeature) { + var linkedFeature = mvtFeature.linkedFeature(); + if (linkedFeature && linkedFeature.selected) { + self.selected = true; + } + } + + init(self, mvtFeature, ctx, latLng, style) +} + +function init(self, mvtFeature, ctx, latLng, style) { + var ajaxData = mvtFeature.ajaxData; + var sty = self.style = style.staticLabel(mvtFeature, ajaxData); + var icon = self.icon = L.divIcon({ + className: sty.cssClass || 'label-icon-text', + html: sty.html, + iconSize: sty.iconSize || [50,50] + }); + + self.marker = L.marker(latLng, {icon: icon}).addTo(self.map); + + if (self.selected) { + self.marker._icon.classList.add(self.style.cssSelectedClass || 'label-icon-text-selected'); + } + + self.marker.on('click', function(e) { + self.toggle(); + }); + + self.map.on('zoomend', function(e) { + var newZoom = e.target.getZoom(); + if (self.zoom !== newZoom) { + self.map.removeLayer(self.marker); + } + }); +} + + +StaticLabel.prototype.toggle = function() { + if (this.selected) { + this.deselect(); + } else { + this.select(); + } +}; + +StaticLabel.prototype.select = function() { + this.selected = true; + this.marker._icon.classList.add(this.style.cssSelectedClass || 'label-icon-text-selected'); + var linkedFeature = this.mvtFeature.linkedFeature(); + if (!linkedFeature.selected) linkedFeature.select(); +}; + +StaticLabel.prototype.deselect = function() { + this.selected = false; + this.marker._icon.classList.remove(this.style.cssSelectedClass || 'label-icon-text-selected'); + var linkedFeature = this.mvtFeature.linkedFeature(); + if (linkedFeature.selected) linkedFeature.deselect(); +}; + +StaticLabel.prototype.remove = function() { + if (!this.map || !this.marker) return; + this.map.removeLayer(this.marker); +}; + +},{"../MVTUtil":11}],13:[function(require,module,exports){ +/** + * Copyright (c) 2014, Spatial Development International + * All rights reserved. + * + * Source code can be found at: + * https://github.com/SpatialServer/Leaflet.MapboxVectorTile + * + * @license ISC + */ + +module.exports = require('./MVTSource'); + +},{"./MVTSource":10}],14:[function(require,module,exports){ +(function (global){ +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +/* eslint-disable no-proto */ + +var base64 = require('base64-js') +var ieee754 = require('ieee754') +var isArray = require('is-array') + +exports.Buffer = Buffer +exports.SlowBuffer = SlowBuffer +exports.INSPECT_MAX_BYTES = 50 +Buffer.poolSize = 8192 // not used by this implementation + +var rootParent = {} + +/** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Use 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+. + * + * Due to various browser bugs, sometimes the Object implementation will be used even + * when the browser supports typed arrays. + * + * Note: + * + * - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances, + * See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438. + * + * - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property + * on objects. + * + * - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function. + * + * - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of + * incorrect length in some situations. + + * We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they + * get the Object implementation, which is slower but behaves correctly. + */ +Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined + ? global.TYPED_ARRAY_SUPPORT + : typedArraySupport() + +function typedArraySupport () { + function Bar () {} + try { + var arr = new Uint8Array(1) + arr.foo = function () { return 42 } + arr.constructor = Bar + return arr.foo() === 42 && // typed array instances can be augmented + arr.constructor === Bar && // constructor can be set + typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray` + arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray` + } catch (e) { + return false + } +} + +function kMaxLength () { + return Buffer.TYPED_ARRAY_SUPPORT + ? 0x7fffffff + : 0x3fffffff +} + +/** + * Class: Buffer + * ============= + * + * The Buffer constructor returns instances of `Uint8Array` that are augmented + * with function properties for all the node `Buffer` API functions. We use + * `Uint8Array` so that square bracket notation works as expected -- it returns + * a single octet. + * + * By augmenting the instances, we can avoid modifying the `Uint8Array` + * prototype. + */ +function Buffer (arg) { + if (!(this instanceof Buffer)) { + // Avoid going through an ArgumentsAdaptorTrampoline in the common case. + if (arguments.length > 1) return new Buffer(arg, arguments[1]) + return new Buffer(arg) + } + + this.length = 0 + this.parent = undefined + + // Common case. + if (typeof arg === 'number') { + return fromNumber(this, arg) + } + + // Slightly less common case. + if (typeof arg === 'string') { + return fromString(this, arg, arguments.length > 1 ? arguments[1] : 'utf8') + } + + // Unusual. + return fromObject(this, arg) +} + +function fromNumber (that, length) { + that = allocate(that, length < 0 ? 0 : checked(length) | 0) + if (!Buffer.TYPED_ARRAY_SUPPORT) { + for (var i = 0; i < length; i++) { + that[i] = 0 + } + } + return that +} + +function fromString (that, string, encoding) { + if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8' + + // Assumption: byteLength() return value is always < kMaxLength. + var length = byteLength(string, encoding) | 0 + that = allocate(that, length) + + that.write(string, encoding) + return that +} + +function fromObject (that, object) { + if (Buffer.isBuffer(object)) return fromBuffer(that, object) + + if (isArray(object)) return fromArray(that, object) + + if (object == null) { + throw new TypeError('must start with number, buffer, array or string') + } + + if (typeof ArrayBuffer !== 'undefined') { + if (object.buffer instanceof ArrayBuffer) { + return fromTypedArray(that, object) + } + if (object instanceof ArrayBuffer) { + return fromArrayBuffer(that, object) + } + } + + if (object.length) return fromArrayLike(that, object) + + return fromJsonObject(that, object) +} + +function fromBuffer (that, buffer) { + var length = checked(buffer.length) | 0 + that = allocate(that, length) + buffer.copy(that, 0, 0, length) + return that +} + +function fromArray (that, array) { + var length = checked(array.length) | 0 + that = allocate(that, length) + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +// Duplicate of fromArray() to keep fromArray() monomorphic. +function fromTypedArray (that, array) { + var length = checked(array.length) | 0 + that = allocate(that, length) + // Truncating the elements is probably not what people expect from typed + // arrays with BYTES_PER_ELEMENT > 1 but it's compatible with the behavior + // of the old Buffer constructor. + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +function fromArrayBuffer (that, array) { + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + array.byteLength + that = Buffer._augment(new Uint8Array(array)) + } else { + // Fallback: Return an object instance of the Buffer class + that = fromTypedArray(that, new Uint8Array(array)) + } + return that +} + +function fromArrayLike (that, array) { + var length = checked(array.length) | 0 + that = allocate(that, length) + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +// Deserialize { type: 'Buffer', data: [1,2,3,...] } into a Buffer object. +// Returns a zero-length buffer for inputs that don't conform to the spec. +function fromJsonObject (that, object) { + var array + var length = 0 + + if (object.type === 'Buffer' && isArray(object.data)) { + array = object.data + length = checked(array.length) | 0 + } + that = allocate(that, length) + + for (var i = 0; i < length; i += 1) { + that[i] = array[i] & 255 + } + return that +} + +if (Buffer.TYPED_ARRAY_SUPPORT) { + Buffer.prototype.__proto__ = Uint8Array.prototype + Buffer.__proto__ = Uint8Array +} + +function allocate (that, length) { + if (Buffer.TYPED_ARRAY_SUPPORT) { + // Return an augmented `Uint8Array` instance, for best performance + that = Buffer._augment(new Uint8Array(length)) + that.__proto__ = Buffer.prototype + } else { + // Fallback: Return an object instance of the Buffer class + that.length = length + that._isBuffer = true + } + + var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1 + if (fromPool) that.parent = rootParent + + return that +} + +function checked (length) { + // Note: cannot use `length < kMaxLength` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= kMaxLength()) { + throw new RangeError('Attempt to allocate Buffer larger than maximum ' + + 'size: 0x' + kMaxLength().toString(16) + ' bytes') + } + return length | 0 +} + +function SlowBuffer (subject, encoding) { + if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding) + + var buf = new Buffer(subject, encoding) + delete buf.parent + return buf +} + +Buffer.isBuffer = function isBuffer (b) { + return !!(b != null && b._isBuffer) +} + +Buffer.compare = function compare (a, b) { + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError('Arguments must be Buffers') + } + + if (a === b) return 0 + + var x = a.length + var y = b.length + + var i = 0 + var len = Math.min(x, y) + while (i < len) { + if (a[i] !== b[i]) break + + ++i + } + + if (i !== len) { + x = a[i] + y = b[i] + } + + 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 'binary': + case 'base64': + case 'raw': + case 'ucs2': + case 'ucs-2': + case 'utf16le': + case 'utf-16le': + return true + default: + return false + } +} + +Buffer.concat = function concat (list, length) { + if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.') + + if (list.length === 0) { + return new Buffer(0) + } + + var i + if (length === undefined) { + length = 0 + for (i = 0; i < list.length; i++) { + length += list[i].length + } + } + + var buf = new Buffer(length) + var pos = 0 + for (i = 0; i < list.length; i++) { + var item = list[i] + item.copy(buf, pos) + pos += item.length + } + return buf +} + +function byteLength (string, encoding) { + if (typeof string !== 'string') string = '' + string + + var len = string.length + if (len === 0) return 0 + + // Use a for loop to avoid recursion + var loweredCase = false + for (;;) { + switch (encoding) { + case 'ascii': + case 'binary': + // Deprecated + case 'raw': + case 'raws': + 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 utf8ToBytes(string).length // assume utf8 + encoding = ('' + encoding).toLowerCase() + loweredCase = true + } + } +} +Buffer.byteLength = byteLength + +// pre-set for values that may exist in the future +Buffer.prototype.length = undefined +Buffer.prototype.parent = undefined + +function slowToString (encoding, start, end) { + var loweredCase = false + + start = start | 0 + end = end === undefined || end === Infinity ? this.length : end | 0 + + if (!encoding) encoding = 'utf8' + if (start < 0) start = 0 + if (end > this.length) end = this.length + if (end <= start) return '' + + 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 'binary': + return binarySlice(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 + } + } +} + +Buffer.prototype.toString = function toString () { + var length = this.length | 0 + if (length === 0) return '' + if (arguments.length === 0) return utf8Slice(this, 0, length) + return slowToString.apply(this, arguments) +} + +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 + if (this.length > 0) { + str = this.toString('hex', 0, max).match(/.{2}/g).join(' ') + if (this.length > max) str += ' ... ' + } + return '' +} + +Buffer.prototype.compare = function compare (b) { + if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer') + if (this === b) return 0 + return Buffer.compare(this, b) +} + +Buffer.prototype.indexOf = function indexOf (val, byteOffset) { + if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff + else if (byteOffset < -0x80000000) byteOffset = -0x80000000 + byteOffset >>= 0 + + if (this.length === 0) return -1 + if (byteOffset >= this.length) return -1 + + // Negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0) + + if (typeof val === 'string') { + if (val.length === 0) return -1 // special case: looking for empty string always fails + return String.prototype.indexOf.call(this, val, byteOffset) + } + if (Buffer.isBuffer(val)) { + return arrayIndexOf(this, val, byteOffset) + } + if (typeof val === 'number') { + if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') { + return Uint8Array.prototype.indexOf.call(this, val, byteOffset) + } + return arrayIndexOf(this, [ val ], byteOffset) + } + + function arrayIndexOf (arr, val, byteOffset) { + var foundIndex = -1 + for (var i = 0; byteOffset + i < arr.length; i++) { + if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) { + if (foundIndex === -1) foundIndex = i + if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex + } else { + foundIndex = -1 + } + } + return -1 + } + + throw new TypeError('val must be string, number or Buffer') +} + +// `get` is deprecated +Buffer.prototype.get = function get (offset) { + console.log('.get() is deprecated. Access using array indexes instead.') + return this.readUInt8(offset) +} + +// `set` is deprecated +Buffer.prototype.set = function set (v, offset) { + console.log('.set() is deprecated. Access using array indexes instead.') + return this.writeUInt8(v, offset) +} + +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 + } + } + + // must be an even number of digits + var strLen = string.length + if (strLen % 2 !== 0) throw new Error('Invalid hex string') + + if (length > strLen / 2) { + length = strLen / 2 + } + for (var i = 0; i < length; i++) { + var parsed = parseInt(string.substr(i * 2, 2), 16) + if (isNaN(parsed)) throw new Error('Invalid hex string') + 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 binaryWrite (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 + } + // legacy write(string, encoding, offset, length) - remove in v0.13 + } else { + var swap = encoding + encoding = offset + offset = length | 0 + length = swap + } + + 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 'binary': + return binaryWrite(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 binarySlice (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 + if (Buffer.TYPED_ARRAY_SUPPORT) { + newBuf = Buffer._augment(this.subarray(start, end)) + } else { + var sliceLen = end - start + newBuf = new Buffer(sliceLen, undefined) + for (var i = 0; i < sliceLen; i++) { + newBuf[i] = this[i + start] + } + } + + if (newBuf.length) newBuf.parent = this.parent || this + + 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) { + if (!noAssert) checkOffset(offset, 1, this.length) + return this[offset] +} + +Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return this[offset] | (this[offset + 1] << 8) +} + +Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 2, this.length) + return (this[offset] << 8) | this[offset + 1] +} + +Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + 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) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, true, 23, 4) +} + +Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 4, this.length) + return ieee754.read(this, offset, false, 23, 4) +} + +Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) { + if (!noAssert) checkOffset(offset, 8, this.length) + return ieee754.read(this, offset, true, 52, 8) +} + +Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) { + 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 must be a Buffer instance') + if (value > max || value < min) throw new RangeError('value 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) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 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) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 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) + if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + this[offset] = (value & 0xff) + return offset + 1 +} + +function objectWriteUInt16 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) { + buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>> + (littleEndian ? i : 1 - i) * 8 + } +} + +Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + 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) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + return offset + 2 +} + +function objectWriteUInt32 (buf, value, offset, littleEndian) { + if (value < 0) value = 0xffffffff + value + 1 + for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) { + buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff + } +} + +Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) { + value = +value + offset = offset | 0 + if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset + 3] = (value >>> 24) + this[offset + 2] = (value >>> 16) + this[offset + 1] = (value >>> 8) + this[offset] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, true) + } + 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) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + 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 = value < 0 ? 1 : 0 + this[offset] = value & 0xFF + while (++i < byteLength && (mul *= 0x100)) { + 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 = value < 0 ? 1 : 0 + this[offset + i] = value & 0xFF + while (--i >= 0 && (mul *= 0x100)) { + 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 (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value) + 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) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + } else { + objectWriteUInt16(this, value, offset, true) + } + 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) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 8) + this[offset + 1] = (value & 0xff) + } else { + objectWriteUInt16(this, value, offset, false) + } + 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) + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value & 0xff) + this[offset + 1] = (value >>> 8) + this[offset + 2] = (value >>> 16) + this[offset + 3] = (value >>> 24) + } else { + objectWriteUInt32(this, value, offset, true) + } + 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 + if (Buffer.TYPED_ARRAY_SUPPORT) { + this[offset] = (value >>> 24) + this[offset + 1] = (value >>> 16) + this[offset + 2] = (value >>> 8) + this[offset + 3] = (value & 0xff) + } else { + objectWriteUInt32(this, value, offset, false) + } + return offset + 4 +} + +function checkIEEE754 (buf, value, offset, ext, max, min) { + if (value > max || value < min) throw new RangeError('value is out of bounds') + 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) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38) + } + 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) { + if (!noAssert) { + checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308) + } + 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 (!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('sourceStart out of bounds') + 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 + var i + + if (this === target && start < targetStart && targetStart < end) { + // descending copy from end + for (i = len - 1; i >= 0; i--) { + target[i + targetStart] = this[i + start] + } + } else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) { + // ascending copy from start + for (i = 0; i < len; i++) { + target[i + targetStart] = this[i + start] + } + } else { + target._set(this.subarray(start, start + len), targetStart) + } + + return len +} + +// fill(value, start=0, end=buffer.length) +Buffer.prototype.fill = function fill (value, start, end) { + if (!value) value = 0 + if (!start) start = 0 + if (!end) end = this.length + + if (end < start) throw new RangeError('end < start') + + // Fill 0 bytes; we're done + if (end === start) return + if (this.length === 0) return + + if (start < 0 || start >= this.length) throw new RangeError('start out of bounds') + if (end < 0 || end > this.length) throw new RangeError('end out of bounds') + + var i + if (typeof value === 'number') { + for (i = start; i < end; i++) { + this[i] = value + } + } else { + var bytes = utf8ToBytes(value.toString()) + var len = bytes.length + for (i = start; i < end; i++) { + this[i] = bytes[i % len] + } + } + + return this +} + +/** + * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance. + * Added in Node 0.12. Only available in browsers that support ArrayBuffer. + */ +Buffer.prototype.toArrayBuffer = function toArrayBuffer () { + if (typeof Uint8Array !== 'undefined') { + if (Buffer.TYPED_ARRAY_SUPPORT) { + return (new Buffer(this)).buffer + } else { + var buf = new Uint8Array(this.length) + for (var i = 0, len = buf.length; i < len; i += 1) { + buf[i] = this[i] + } + return buf.buffer + } + } else { + throw new TypeError('Buffer.toArrayBuffer not supported in this browser') + } +} + +// HELPER FUNCTIONS +// ================ + +var BP = Buffer.prototype + +/** + * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods + */ +Buffer._augment = function _augment (arr) { + arr.constructor = Buffer + arr._isBuffer = true + + // save reference to original Uint8Array set method before overwriting + arr._set = arr.set + + // deprecated + arr.get = BP.get + arr.set = BP.set + + arr.write = BP.write + arr.toString = BP.toString + arr.toLocaleString = BP.toString + arr.toJSON = BP.toJSON + arr.equals = BP.equals + arr.compare = BP.compare + arr.indexOf = BP.indexOf + arr.copy = BP.copy + arr.slice = BP.slice + arr.readUIntLE = BP.readUIntLE + arr.readUIntBE = BP.readUIntBE + arr.readUInt8 = BP.readUInt8 + arr.readUInt16LE = BP.readUInt16LE + arr.readUInt16BE = BP.readUInt16BE + arr.readUInt32LE = BP.readUInt32LE + arr.readUInt32BE = BP.readUInt32BE + arr.readIntLE = BP.readIntLE + arr.readIntBE = BP.readIntBE + arr.readInt8 = BP.readInt8 + arr.readInt16LE = BP.readInt16LE + arr.readInt16BE = BP.readInt16BE + arr.readInt32LE = BP.readInt32LE + arr.readInt32BE = BP.readInt32BE + arr.readFloatLE = BP.readFloatLE + arr.readFloatBE = BP.readFloatBE + arr.readDoubleLE = BP.readDoubleLE + arr.readDoubleBE = BP.readDoubleBE + arr.writeUInt8 = BP.writeUInt8 + arr.writeUIntLE = BP.writeUIntLE + arr.writeUIntBE = BP.writeUIntBE + arr.writeUInt16LE = BP.writeUInt16LE + arr.writeUInt16BE = BP.writeUInt16BE + arr.writeUInt32LE = BP.writeUInt32LE + arr.writeUInt32BE = BP.writeUInt32BE + arr.writeIntLE = BP.writeIntLE + arr.writeIntBE = BP.writeIntBE + arr.writeInt8 = BP.writeInt8 + arr.writeInt16LE = BP.writeInt16LE + arr.writeInt16BE = BP.writeInt16BE + arr.writeInt32LE = BP.writeInt32LE + arr.writeInt32BE = BP.writeInt32BE + arr.writeFloatLE = BP.writeFloatLE + arr.writeFloatBE = BP.writeFloatBE + arr.writeDoubleLE = BP.writeDoubleLE + arr.writeDoubleBE = BP.writeDoubleBE + arr.fill = BP.fill + arr.inspect = BP.inspect + arr.toArrayBuffer = BP.toArrayBuffer + + return arr +} + +var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g + +function base64clean (str) { + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = stringtrim(str).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 stringtrim (str) { + if (str.trim) return str.trim() + return str.replace(/^\s+|\s+$/g, '') +} + +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 +} + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"base64-js":15,"ieee754":16,"is-array":17}],15:[function(require,module,exports){ +var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + +;(function (exports) { + 'use strict'; + + var Arr = (typeof Uint8Array !== 'undefined') + ? Uint8Array + : Array + + var PLUS = '+'.charCodeAt(0) + var SLASH = '/'.charCodeAt(0) + var NUMBER = '0'.charCodeAt(0) + var LOWER = 'a'.charCodeAt(0) + var UPPER = 'A'.charCodeAt(0) + var PLUS_URL_SAFE = '-'.charCodeAt(0) + var SLASH_URL_SAFE = '_'.charCodeAt(0) + + function decode (elt) { + var code = elt.charCodeAt(0) + if (code === PLUS || + code === PLUS_URL_SAFE) + return 62 // '+' + if (code === SLASH || + code === SLASH_URL_SAFE) + return 63 // '/' + if (code < NUMBER) + return -1 //no match + if (code < NUMBER + 10) + return code - NUMBER + 26 + 26 + if (code < UPPER + 26) + return code - UPPER + if (code < LOWER + 26) + return code - LOWER + 26 + } + + function b64ToByteArray (b64) { + var i, j, l, tmp, placeHolders, arr + + if (b64.length % 4 > 0) { + throw new Error('Invalid string. Length must be a multiple of 4') + } + + // the number of equal signs (place holders) + // if there are two placeholders, than the two characters before it + // represent one byte + // if there is only one, then the three characters before it represent 2 bytes + // this is just a cheap hack to not do indexOf twice + var len = b64.length + placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0 + + // base64 is 4/3 + up to two characters of the original data + arr = new Arr(b64.length * 3 / 4 - placeHolders) + + // if there are placeholders, only get up to the last complete 4 chars + l = placeHolders > 0 ? b64.length - 4 : b64.length + + var L = 0 + + function push (v) { + arr[L++] = v + } + + for (i = 0, j = 0; i < l; i += 4, j += 3) { + tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3)) + push((tmp & 0xFF0000) >> 16) + push((tmp & 0xFF00) >> 8) + push(tmp & 0xFF) + } + + if (placeHolders === 2) { + tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4) + push(tmp & 0xFF) + } else if (placeHolders === 1) { + tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2) + push((tmp >> 8) & 0xFF) + push(tmp & 0xFF) + } + + return arr + } + + function uint8ToBase64 (uint8) { + var i, + extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes + output = "", + temp, length + + function encode (num) { + return lookup.charAt(num) + } + + function tripletToBase64 (num) { + return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F) + } + + // go through the array every three bytes, we'll deal with trailing stuff later + for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) { + temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2]) + output += tripletToBase64(temp) + } + + // pad the end with zeros, but make sure to not forget the extra bytes + switch (extraBytes) { + case 1: + temp = uint8[uint8.length - 1] + output += encode(temp >> 2) + output += encode((temp << 4) & 0x3F) + output += '==' + break + case 2: + temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1]) + output += encode(temp >> 10) + output += encode((temp >> 4) & 0x3F) + output += encode((temp << 2) & 0x3F) + output += '=' + break + } + + return output + } + + exports.toByteArray = b64ToByteArray + exports.fromByteArray = uint8ToBase64 +}(typeof exports === 'undefined' ? (this.base64js = {}) : exports)) + +},{}],16:[function(require,module,exports){ +arguments[4][2][0].apply(exports,arguments) +},{"dup":2}],17:[function(require,module,exports){ + +/** + * isArray + */ + +var isArray = Array.isArray; + +/** + * toString + */ + +var str = Object.prototype.toString; + +/** + * Whether or not the given `val` + * is an array. + * + * example: + * + * isArray([]); + * // > true + * isArray(arguments); + * // > false + * isArray(''); + * // > false + * + * @param {mixed} val + * @return {bool} + */ + +module.exports = isArray || function (val) { + return !! val && '[object Array]' == str.call(val); +}; + +},{}]},{},[13]) +//# sourceMappingURL=data:application/json;charset:utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Vzci9sb2NhbC9saWIvbm9kZV9tb2R1bGVzL2Jyb3dzZXJpZnkvbm9kZV9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KTtcbiAgICB9LFxuXG4gICAgYW5nbGVUbzogZnVuY3Rpb24oYikge1xuICAgICAgICByZXR1cm4gTWF0aC5hdGFuMih0aGlzLnkgLSBiLnksIHRoaXMueCAtIGIueCk7XG4gICAgfSxcblxuICAgIGFuZ2xlV2l0aDogZnVuY3Rpb24oYikge1xuICAgICAgICByZXR1cm4gdGhpcy5hbmdsZVdpdGhTZXAoYi54LCBiLnkpO1xuICAgIH0sXG5cbiAgICAvLyBGaW5kIHRoZSBhbmdsZSBvZiB0aGUgdHdvIHZlY3RvcnMsIHNvbHZpbmcgdGhlIGZvcm11bGEgZm9yIHRoZSBjcm9zcyBwcm9kdWN0IGEgeCBiID0gfGF8fGJ8c2luKM64KSBmb3IgzrguXG4gICAgYW5nbGVXaXRoU2VwOiBmdW5jdGlvbih4LCB5KSB7XG4gICAgICAgIHJldHVybiBNYXRoLmF0YW4yKFxuICAgICAgICAgICAgdGhpcy54ICogeSAtIHRoaXMueSAqIHgsXG4gICAgICAgICAgICB0aGlzLnggKiB4ICsgdGhpcy55ICogeSk7XG4gICAgfSxcblxuICAgIF9tYXRNdWx0OiBmdW5jdGlvbihtKSB7XG4gICAgICAgIHZhciB4ID0gbVswXSAqIHRoaXMueCArIG1bMV0gKiB0aGlzLnksXG4gICAgICAgICAgICB5ID0gbVsyXSAqIHRoaXMueCArIG1bM10gKiB0aGlzLnk7XG4gICAgICAgIHRoaXMueCA9IHg7XG4gICAgICAgIHRoaXMueSA9IHk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH0sXG5cbiAgICBfYWRkOiBmdW5jdGlvbihwKSB7XG4gICAgICAgIHRoaXMueCArPSBwLng7XG4gICAgICAgIHRoaXMueSArPSBwLnk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH0sXG5cbiAgICBfc3ViOiBmdW5jdGlvbihwKSB7XG4gICAgICAgIHRoaXMueCAtPSBwLng7XG4gICAgICAgIHRoaXMueSAtPSBwLnk7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH0sXG5cbiAgICBfbXVsdDogZnVuY3Rpb24oaykge1xuICAgICAgICB0aGlzLnggKj0gaztcbiAgICAgICAgdGhpcy55ICo9IGs7XG4gICAgICAgIHJldHVybiB0aGlzO1xuICAgIH0sXG5cbiAgICBfZGl2OiBmdW5jdGlvbihrKSB7XG4gICAgICAgIHRoaXMueCAvPSBrO1xuICAgICAgICB0aGlzLnkgLz0gaztcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfSxcblxuICAgIF91bml0OiBmdW5jdGlvbigpIHtcbiAgICAgICAgdGhpcy5fZGl2KHRoaXMubWFnKCkpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9LFxuXG4gICAgX3BlcnA6IGZ1bmN0aW9uKCkge1xuICAgICAgICB2YXIgeSA9IHRoaXMueTtcbiAgICAgICAgdGhpcy55ID0gdGhpcy54O1xuICAgICAgICB0aGlzLnggPSAteTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfSxcblxuICAgIF9yb3RhdGU6IGZ1bmN0aW9uKGFuZ2xlKSB7XG4gICAgICAgIHZhciBjb3MgPSBNYXRoLmNvcyhhbmdsZSksXG4gICAgICAgICAgICBzaW4gPSBNYXRoLnNpbihhbmdsZSksXG4gICAgICAgICAgICB4ID0gY29zICogdGhpcy54IC0gc2luICogdGhpcy55LFxuICAgICAgICAgICAgeSA9IHNpbiAqIHRoaXMueCArIGNvcyAqIHRoaXMueTtcbiAgICAgICAgdGhpcy54ID0geDtcbiAgICAgICAgdGhpcy55ID0geTtcbiAgICAgICAgcmV0dXJuIHRoaXM7XG4gICAgfSxcblxuICAgIF9yb3VuZDogZnVuY3Rpb24oKSB7XG4gICAgICAgIHRoaXMueCA9IE1hdGgucm91bmQodGhpcy54KTtcbiAgICAgICAgdGhpcy55ID0gTWF0aC5yb3VuZCh0aGlzLnkpO1xuICAgICAgICByZXR1cm4gdGhpcztcbiAgICB9XG59O1xuXG4vLyBjb25zdHJ1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gICAgdmFyIHZhbCA9IGJ1ZmZlci5yZWFkVmFyaW50KCksXG4gICAgICAgICAgICB0YWcgPSB2YWwgPj4gMztcblxuICAgICAgICBpZiAodGFnID09IDEpIHtcbiAgICAgICAgICAgIHRoaXMuX2lkID0gYnVmZmVyLnJlYWRWYXJpbnQoKTtcblxuICAgICAgICB9IGVsc2UgaWYgKHRhZyA9PSAyKSB7XG4gICAgICAgICAgICB2YXIgdGFnTGVuID0gYnVmZmVyLnJlYWRWYXJpbnQoKSxcbiAgICAgICAgICAgICAgICB0YWdFbmQgPSBidWZmZXIucG9zICsgdGFnTGVuO1xuXG4gICAgICAgICAgICB3aGlsZSAoYnVmZmVyLnBvcyA8IHRhZ0VuZCkge1xuICAgICAgICAgICAgICAgIHZhciBrZXkgPSBrZXlzW2J1ZmZlci5yZWFkVmFyaW50KCldO1xuICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IHZhbHVlc1tidWZmZXIucmVhZFZhcmludCgpXTtcbiAgICAgICAgICAgICAgICB0aGlzLnByb3BlcnRpZXNba2V5XSA9IHZhbHVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgIH0gZWxzZSBpZiAodGFnID09IDMpIHtcbiAgICAgICAgICAgIHRoaXMudHlwZSA9IGJ1ZmZlci5yZWFkVmFyaW50KCk7XG5cbiAgICAgICAgfSBlbHNlIGlmICh0YWcgPT0gNCkge1xuICAgICAgICAgICAgdGhpcy5fZ2VvbWV0cnkgPSBidWZmZXIucG9zO1xuICAgICAgICAgICAgYnVmZmVyLnNraXAodmFsKTtcblxuICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgYnVmZmVyLnNraXAodmFsKTtcbiAgICAgICAgfVxuICAgIH1cbn1cblxuVmVjdG9yVGlsZUZlYXR1cmUudHlwZXMgPSBbJ1Vua25vd24nLCAnUG9pbnQnLCAnTGluZVN0cmluZycsICdQb2x5Z29uJ107XG5cblZlY3RvclRpbGVGZWF0dXJlLnByb3RvdHlwZS5sb2FkR2VvbWV0cnkgPSBmdW5jdGlvbigpIHtcbiAgICB2YXIgYnVmZmVyID0gdGhpcy5fYnVmZmVyO1xuICAgIGJ1ZmZlci5wb3MgPSB0aGlzLl9nZW9tZXRyeTtcblxuICAgIHZhciBieXRlcyA9IGJ1ZmZlci5yZWFkVmFyaW50KCksXG4gICAgICAgIGVuZCA9IGJ1ZmZlci5wb3MgKyBieXRlcyxcbiAgICAgICAgY21kID0gMSxcbiAgICAgICAgbGVuZ3RoID0gMCxcbiAgICAgICAgeCA9IDAsXG4gICAgICAgIHkgPSAwLFxuICAgICAgICBsaW5lcyA9IFtdLFxuICAgICAgICBsaW5lO1xuXG4gICAgd2hpbGUgKGJ1ZmZlci5wb3MgPCBlbmQpIHtcbiAgICAgICAgaWYgKCFsZW5ndGgpIHtcbiAgICAgICAgICAgIHZhciBjbWRfbGVuZ3RoID0gYnVmZmVyLnJlYWRWYXJpbnQoKTtcbiAgICAgICAgICAgIGNtZCA9IGNtZF9sZW5ndGggJiAweDc7XG4gICAgICAgICAgICBsZW5ndGggPSBjbWRfbGVuZ3RoID4+IDM7XG4gICAgICAgIH1cblxuICAgICAgICBsZW5ndGgtLTtcblxuICAgICAgICBpZiAoY21kID09PSAxIHx8IGNtZCA9PT0gMikge1xuICAgICAgICAgICAgeCArPSBidWZmZXIucmVhZFNWYXJpbnQoKTtcbiAgICAgICAgICAgIHkgKz0gYnVmZmVyLnJlYWRTVmFyaW50KCk7XG5cbiAgICAgICAgICAgIGlmIChjbWQgPT09IDEpIHtcbiAgICAgICAgICAgICAgICAvLyBtb3ZlVG9cbiAgICAgICAgICAgICAgICBpZiAobGluZSkge1xuICAgICAgICAgICAgICAgICAgICBsaW5lcy5wdXNoKGxpbmUpO1xuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICBsaW5lID0gW107XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGxpbmUucHVzaChuZXcgUG9pbnQoeCwgeSkpO1xuICAgICAgICB9IGVsc2UgaWYgKGNtZCA9PT0gNykge1xuICAgICAgICAgICAgLy8gY2xvc2VQb2x5Z29uXG4gICAgICAgICAgICBsaW5lLnB1c2gobGluZVswXS5jbG9uZSgpKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigndW5rbm93biBjb21tYW5kICcgKyBjbWQpO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgaWYgKGxpbmUpIGxpbmVzLnB1c2gobGluZSk7XG5cbiAgICByZXR1cm4gbGluZXM7XG59O1xuXG5WZWN0b3JUaWxlRmVhdHVyZS5wcm90b3R5cGUuYmJveCA9IGZ1bmN0aW9uKCkge1xuICAgIHZhciBidWZmZXIgPSB0aGlzLl9idWZmZXI7XG4gICAgYnVmZmVyLnBvcyA9IHRoaXMuX2dlb21ldHJ5O1xuXG4gICAgdmFyIGJ5dGVzID0gYnVmZmVyLnJlYWRWYXJpbnQoKSxcbiAgICAgICAgZW5kID0gYnVmZmVyLnBvcyArIGJ5dGVzLFxuXG4gICAgICAgIGNtZCA9IDEsXG4gICAgICAgIGxlbmd0aCA9IDAsXG4gICAgICAgIHggPSAwLFxuICAgICAgICB5ID0gMCxcbiAgICAgICAgeDEgPSBJbmZpbml0eSxcbiAgICAgICAgeDIgPSAtSW5maW5pdHksXG4gICAgICAgIHkxID0gSW5maW5pdHksXG4gICAgICAgIHkyID0gLUluZmluaXR5O1xuXG4gICAgd2hpbGUgKGJ1ZmZlci5wb3MgPCBlbmQpIHtcbiAgICAgICAgaWYgKCFsZW5ndGgpIHtcbiAgICAgICAgICAgIHZhciBjbWRfbGVuZ3RoID0gYnVmZmVyLnJlYWRWYXJpbnQoKTtcbiAgICAgICAgICAgIGNtZCA9IGNtZF9sZW5ndGggJiAweDc7XG4gICAgICAgICAgICBsZW5ndGggPSBjbWRfbGVuZ3RoID4+IDM7XG4gICAgICAgIH1cblxuICAgICAgICBsZW5ndGgtLTtcblxuICAgICAgICBpZiAoY21kID09PSAxIHx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ZSAoYnVmZmVyLnBvcyA8IGVuZCkge1xuICAgICAgICB2YWwgPSBidWZmZXIucmVhZFZhcmludCgpO1xuICAgICAgICB0YWcgPSB2YWwgPj4gMztcblxuICAgICAgICBpZiAodGFnID09PSAxNSkge1xuICAgICAgICAgICAgdGhpcy52ZXJzaW9uID0gYnVmZmVyLnJlYWRWYXJpbnQoKTtcbiAgICAgICAgfSBlbHNlIGlmICh0YWcgPT09IDEpIHtcbiAgICAgICAgICAgIHRoaXMubmFtZSA9IGJ1ZmZlci5yZWFkU3RyaW5nKCk7XG4gICAgICAgIH0gZWxzZSBpZiAodGFnID09PSA1KSB7XG4gICAgICAgICAgICB0aGlzLmV4dGVudCA9IGJ1ZmZlci5yZWFkVmFyaW50KCk7XG4gICAgICAgIH0gZWxzZSBpZiAodGFnID09PSAyKSB7XG4gICAgICAgICAgICB0aGlzLmxlbmd0aCsrO1xuICAgICAgICAgICAgdGhpcy5fZmVhdHVyZXMucHVzaChidWZmZXIucG9zKTtcbiAgICAgICAgICAgIGJ1ZmZlci5za2lwKHZhbCk7XG5cbiAgICAgICAgfSBlbHNlIGlmICh0YWcgPT09IDMpIHtcbiAgICAgICAgICAgIHRoaXMuX2tleXMucHVzaChidWZmZXIucmVhZFN0cmluZygpKTtcbiAgICAgICAgfSBlbHNlIGlmICh0YWcgPT09IDQpIHtcbiAgICAgICAgICAgIHRoaXMuX3ZhbHVlcy5wdXNoKHRoaXMucmVhZEZlYXR1cmVWYWx1ZSgpKTtcbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGJ1ZmZlci5za2lwKHZhbCk7XG4gICAgICAgIH1cbiAgICB9XG59XG5cblZlY3RvclRpbGVMYXllci5wcm90b3R5cGUucmVhZEZlYXR1cmVWYWx1ZSA9IGZ1bmN0aW9uKCkge1xuICAgIHZhciBidWZmZXIgPSB0aGlzLl9idWZmZXIsXG4gICAgICAgIHZhbHVlID0gbnVsbCxcbiAgICAgICAgYnl0ZXMgPSBidWZmZXIucm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ZCcgPyAodGhpcy5iYXNlNjRqcyA9IHt9KSA6IGV4cG9ydHMpKVxuIiwiXG4vKipcbiAqIGlzQXJyYXlcbiAqL1xuXG52YXIgaXNBcnJheSA9IEFycmF5LmlzQXJyYXk7XG5cbi8qKlxuICogdG9TdHJpbmdcbiAqL1xuXG52YXIgc3RyID0gT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZztcblxuLyoqXG4gKiBXaGV0aGVyIG9yIG5vdCB0aGUgZ2l2ZW4gYHZhbGBcbiAqIGlzIGFuIGFycmF5LlxuICpcbiAqIGV4YW1wbGU6XG4gKlxuICogICAgICAgIGlzQXJyYXkoW10pO1xuICogICAgICAgIC8vID4gdHJ1ZVxuICogICAgICAgIGlzQXJyYXkoYXJndW1lbnRzKTtcbiAqICAgICAgICAvLyA+IGZhbHNlXG4gKiAgICAgICAgaXNBcnJheSgnJyk7XG4gKiAgICAgICAgLy8gPiBmYWxzZVxuICpcbiAqIEBwYXJhbSB7bWl4ZWR9IHZhbFxuICogQHJldHVybiB7Ym9vbH1cbiAqL1xuXG5tb2R1bGUuZXhwb3J0cyA9IGlzQXJyYXkgfHwgZnVuY3Rpb24gKHZhbCkge1xuICByZXR1cm4gISEgdmFsICYmICdbb2JqZWN0IEFycmF5XScgPT0gc3RyLmNhbGwodmFsKTtcbn07XG4iXX0= diff --git a/lib/Leaflet.MapboxVectorTile.min.js b/lib/Leaflet.MapboxVectorTile.min.js new file mode 100644 index 0000000..23f0f1d --- /dev/null +++ b/lib/Leaflet.MapboxVectorTile.min.js @@ -0,0 +1,16 @@ +!function t(e,r,i){function n(o,a){if(!r[o]){if(!e[o]){var h="function"==typeof require&&require;if(!a&&h)return h(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var l=r[o]={exports:{}};e[o][0].call(l.exports,function(t){var r=e[o][1][t];return n(r?r:t)},l,l.exports,t,e,r,i)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o2147483647)throw new Error("TODO: Handle numbers >= 2^30");return t>>1^-(1&t)},i.prototype.readString=function(){for(var t=this.readVarint(),e=String.fromCharCode,r=this.buf,i=this.pos,n=this.pos+t,s="";n>i;)if(r[i]<=127)s+=e(r[i++]);else{if(r[i]<=191)throw new Error("Invalid UTF-8 codepoint: "+r[i]);if(r[i]<=223)s+=e((31&r[i++])<<6|63&r[i++]);else if(r[i]<=239)s+=e((31&r[i++])<<12|(63&r[i++])<<6|63&r[i++]);else if(r[i]<=247)i+=4;else if(r[i]<=251)i+=5;else{if(!(r[i]<=253))throw new Error("Invalid UTF-8 codepoint: "+r[i]);i+=6}}return this.pos+=t,s},i.prototype.readBuffer=function(){var t=this.readVarint(),e=this.buf.subarray(this.pos,this.pos+t);return this.pos+=t,e},i.prototype.readPacked=function(t){for(var e=this.readVarint(),r=this.pos+e,i=[];this.pos127;);break;case i.Int64:this.pos+=8;break;case i.Message:var r=this.readVarint();this.pos+=r;break;case i.Int32:this.pos+=4;break;default:throw new Error("Unimplemented type: "+e)}},i.prototype.writeTag=function(t,e){this.writeVarint(t<<3|e)},i.prototype.realloc=function(t){for(var e=this.buf.length;e=t)this.realloc(1),this.buf[this.pos++]=t;else if(16383>=t)this.realloc(2),this.buf[this.pos++]=128|t>>>0&127,this.buf[this.pos++]=0|t>>>7&127;else if(33554431>=t)this.realloc(3),this.buf[this.pos++]=128|t>>>0&127,this.buf[this.pos++]=128|t>>>7&127,this.buf[this.pos++]=0|t>>>14&127;else if(268435455>=t)this.realloc(4),this.buf[this.pos++]=128|t>>>0&127,this.buf[this.pos++]=128|t>>>7&127,this.buf[this.pos++]=128|t>>>14&127,this.buf[this.pos++]=0|t>>>21&127;else for(;t>0;){var e=127&t;t=Math.floor(t/128),t>0&&(e|=128),this.realloc(1),this.buf[this.pos++]=e}},i.prototype.writeTaggedVarint=function(t,e){this.writeTag(t,i.Varint),this.writeVarint(e)},i.prototype.writeSVarint=function(t){t>=0?this.writeVarint(2*t):this.writeVarint(-2*t-1)},i.prototype.writeTaggedSVarint=function(t,e){this.writeTag(t,i.Varint),this.writeSVarint(e)},i.prototype.writeBoolean=function(t){this.writeVarint(Boolean(t))},i.prototype.writeTaggedBoolean=function(t,e){this.writeTaggedVarint(t,Boolean(e))},i.prototype.writeString=function(t){t=String(t);var e=r.byteLength(t);this.writeVarint(e),this.realloc(e),this.buf.write(t,this.pos),this.pos+=e},i.prototype.writeTaggedString=function(t,e){this.writeTag(t,i.String),this.writeString(e)},i.prototype.writeFloat=function(t){this.realloc(4),this.buf.writeFloatLE(t,this.pos),this.pos+=4},i.prototype.writeTaggedFloat=function(t,e){this.writeTag(t,i.Int32),this.writeFloat(e)},i.prototype.writeDouble=function(t){this.realloc(8),this.buf.writeDoubleLE(t,this.pos),this.pos+=8},i.prototype.writeTaggedDouble=function(t,e){this.writeTag(t,i.Int64),this.writeDouble(e)},i.prototype.writeBuffer=function(t){var e=t.length;this.writeVarint(e),this.realloc(e),t.copy(this.buf,this.pos),this.pos+=e},i.prototype.writeTaggedBuffer=function(t,e){this.writeTag(t,i.String),this.writeBuffer(e)},i.prototype.writeMessage=function(t,e){var r=e.finish();this.writeTag(t,i.Message),this.writeBuffer(r)}}).call(this,t("buffer").Buffer)},{buffer:14,ieee754:2}],2:[function(t,e,r){r.read=function(t,e,r,i,n){var s,o,a=8*n-i-1,h=(1<>1,l=-7,f=r?n-1:0,c=r?-1:1,p=t[e+f];for(f+=c,s=p&(1<<-l)-1,p>>=-l,l+=a;l>0;s=256*s+t[e+f],f+=c,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=i;l>0;o=256*o+t[e+f],f+=c,l-=8);if(0===s)s=1-u;else{if(s===h)return o?NaN:(p?-1:1)*(1/0);o+=Math.pow(2,i),s-=u}return(p?-1:1)*o*Math.pow(2,s-i)},r.write=function(t,e,r,i,n,s){var o,a,h,u=8*s-n-1,l=(1<>1,c=23===n?Math.pow(2,-24)-Math.pow(2,-77):0,p=i?0:s-1,d=i?1:-1,y=0>e||0===e&&0>1/e?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=l):(o=Math.floor(Math.log(e)/Math.LN2),e*(h=Math.pow(2,-o))<1&&(o--,h*=2),e+=o+f>=1?c/h:c*Math.pow(2,1-f),e*h>=2&&(o++,h/=2),o+f>=l?(a=0,o=l):o+f>=1?(a=(e*h-1)*Math.pow(2,n),o+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,n),o=0));n>=8;t[r+p]=255&a,p+=d,a/=256,n-=8);for(o=o<0;t[r+p]=255&o,p+=d,o/=256,u-=8);t[r+p-d]|=128*y}},{}],3:[function(t,e,r){"use strict";function i(t,e){this.x=t,this.y=e}e.exports=i,i.prototype={clone:function(){return new i(this.x,this.y)},add:function(t){return this.clone()._add(t)},sub:function(t){return this.clone()._sub(t)},mult:function(t){return this.clone()._mult(t)},div:function(t){return this.clone()._div(t)},rotate:function(t){return this.clone()._rotate(t)},matMult:function(t){return this.clone()._matMult(t)},unit:function(){return this.clone()._unit()},perp:function(){return this.clone()._perp()},round:function(){return this.clone()._round()},mag:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},equals:function(t){return this.x===t.x&&this.y===t.y},dist:function(t){return Math.sqrt(this.distSqr(t))},distSqr:function(t){var e=t.x-this.x,r=t.y-this.y;return e*e+r*r},angle:function(){return Math.atan2(this.y,this.x)},angleTo:function(t){return Math.atan2(this.y-t.y,this.x-t.x)},angleWith:function(t){return this.angleWithSep(t.x,t.y)},angleWithSep:function(t,e){return Math.atan2(this.x*e-this.y*t,this.x*t+this.y*e)},_matMult:function(t){var e=t[0]*this.x+t[1]*this.y,r=t[2]*this.x+t[3]*this.y;return this.x=e,this.y=r,this},_add:function(t){return this.x+=t.x,this.y+=t.y,this},_sub:function(t){return this.x-=t.x,this.y-=t.y,this},_mult:function(t){return this.x*=t,this.y*=t,this},_div:function(t){return this.x/=t,this.y/=t,this},_unit:function(){return this._div(this.mag()),this},_perp:function(){var t=this.y;return this.y=this.x,this.x=-t,this},_rotate:function(t){var e=Math.cos(t),r=Math.sin(t),i=e*this.x-r*this.y,n=r*this.x+e*this.y;return this.x=i,this.y=n,this},_round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}},i.convert=function(t){return t instanceof i?t:Array.isArray(t)?new i(t[0],t[1]):t}},{}],4:[function(t,e,r){e.exports.VectorTile=t("./lib/vectortile.js"),e.exports.VectorTileFeature=t("./lib/vectortilefeature.js"),e.exports.VectorTileLayer=t("./lib/vectortilelayer.js")},{"./lib/vectortile.js":5,"./lib/vectortilefeature.js":6,"./lib/vectortilelayer.js":7}],5:[function(t,e,r){"use strict";function i(t,e){for(this.layers={},this._buffer=t,e=e||t.length;t.pos>3;if(3==i){var n=this.readLayer();n.length&&(this.layers[n.name]=n)}else t.skip(r)}}var n=t("./vectortilelayer");e.exports=i,i.prototype.readLayer=function(){var t=this._buffer,e=t.readVarint(),r=t.pos+e,i=new n(t,r);return t.pos=r,i}},{"./vectortilelayer":7}],6:[function(t,e,r){"use strict";function i(t,e,r,i,n){for(this.properties={},this.extent=r,this.type=0,this._buffer=t,this._geometry=-1,e=e||t.length;t.pos>3;if(1==o)this._id=t.readVarint();else if(2==o)for(var a=t.readVarint(),h=t.pos+a;t.pos>3}if(o--,1===s||2===s)a+=t.readSVarint(),h+=t.readSVarint(),1===s&&(e&&u.push(e),e=[]),e.push(new n(a,h));else{if(7!==s)throw new Error("unknown command "+s);e.push(e[0].clone())}}return e&&u.push(e),u},i.prototype.bbox=function(){var t=this._buffer;t.pos=this._geometry;for(var e=t.readVarint(),r=t.pos+e,i=1,n=0,s=0,o=0,a=1/0,h=-(1/0),u=1/0,l=-(1/0);t.pos>3}if(n--,1===i||2===i)s+=t.readSVarint(),o+=t.readSVarint(),a>s&&(a=s),s>h&&(h=s),u>o&&(u=o),o>l&&(l=o);else if(7!==i)throw new Error("unknown command "+i)}return[a,u,h,l]}},{"point-geometry":3}],7:[function(t,e,r){"use strict";function i(t,e){this.version=1,this.name=null,this.extent=4096,this.length=0,this._buffer=t,this._keys=[],this._values=[],this._features=[];var r,i;for(e=e||t.length;t.pos>3,15===i?this.version=t.readVarint():1===i?this.name=t.readString():5===i?this.extent=t.readVarint():2===i?(this.length++,this._features.push(t.pos),t.skip(r)):3===i?this._keys.push(t.readString()):4===i?this._values.push(this.readFeatureValue()):t.skip(r)}var n=t("./vectortilefeature.js");e.exports=i,i.prototype.readFeatureValue=function(){for(var t,e,r=this._buffer,i=null,n=r.readVarint(),s=r.pos+n;r.pos>3,1==e)i=r.readString();else{if(2==e)throw new Error("read float");if(3==e)i=r.readDouble();else if(4==e)i=r.readVarint();else{if(5==e)throw new Error("read uint");6==e?i=r.readSVarint():7==e?i=Boolean(r.readVarint()):r.skip(t)}}return i},i.prototype.feature=function(t){if(0>t||t>=this._features.length)throw new Error("feature index out of bounds");this._buffer.pos=this._features[t];var e=this._buffer.readVarint()+this._buffer.pos;return new n(this._buffer,e,this.extent,this._keys,this._values)}},{"./vectortilefeature.js":6}],8:[function(t,e,r){function n(t,e,r,i,n){if(!e)return null;for(var o in e)this[o]=e[o];this.mvtLayer=t,this.mvtSource=t.mvtSource,this.map=t.mvtSource.map,this.id=i,this.layerLink=this.mvtSource.layerLink,this.toggleEnabled=!0,this.selected=!1,this.divisor=e.extent/r.tileSize,this.extent=e.extent,this.tileSize=r.tileSize,this.tiles={},this.style=n,this.addTileFeature(e,r);var a=this;this.map.on("zoomend",function(){a.staticLabel=null}),n&&n.dynamicLabel&&"function"==typeof n.dynamicLabel&&(this.dynamicLabel=this.mvtSource.dynamicLabel.createFeature(this)),s(a)}function s(t){var e=t.style;if(e&&e.ajaxSource&&"function"==typeof e.ajaxSource){var r=e.ajaxSource(t);r&&h.getJSON(r,function(e,r,i){if(e)throw["ajaxSource AJAX Error",e];return o(t,r),!0})}return!1}function o(t,e){t.ajaxData=e,"function"==typeof t.ajaxDataReceived&&t.ajaxDataReceived(t,e),t._setStyle(t.mvtLayer.style),a(t)}function a(t){var e=t.tiles,r=t.mvtLayer;for(var i in e){var n=parseInt(i.split(":")[0]),s=t.map.getZoom();n===s&&r.redrawTile(i)}}var h=t("./MVTUtil"),u=t("./StaticLabel/StaticLabel.js");e.exports=n,n.prototype._setStyle=function(t){this.style=t(this,this.ajaxData),this.removeLabel()},n.prototype.setStyle=function(t){this.ajaxData=null,this.style=t(this,null);var e=s(this);e||this.removeLabel()},n.prototype.draw=function(t){var e=this.tiles[t],r=e.vtf,i=e.ctx,n=t.split(":").slice(1,3).join(":");if(i.canvas=this.mvtLayer._tiles[n],this.selected)var s=this.style.selected||this.style;else var s=this.style;switch(r.type){case 1:if(this._drawPoint(i,r.coordinates,s),!this.staticLabel&&"function"==typeof this.style.staticLabel){if(this.style.ajaxSource&&!this.ajaxData)break;this._drawStaticLabel(i,r.coordinates,s)}break;case 2:this._drawLineString(i,r.coordinates,s);break;case 3:this._drawPolygon(i,r.coordinates,s);break;default:throw new Error("Unmanaged type: "+r.type)}},n.prototype.getPathsForTile=function(t){return this.tiles[t].paths},n.prototype.addTileFeature=function(t,e){var r=this.map.getZoom();e.zoom==r&&(this.clearTileFeatures(r),this.tiles[e.id]={ctx:e,vtf:t,paths:[]})},n.prototype.clearTileFeatures=function(t){for(var e in this.tiles)e.split(":")[0]!=t&&delete this.tiles[e]},n.prototype.toggle=function(){this.selected?this.deselect():this.select()},n.prototype.select=function(){this.selected=!0,this.mvtSource.featureSelected(this),a(this);var t=this.linkedFeature();t&&t.staticLabel&&!t.staticLabel.selected&&t.staticLabel.select()},n.prototype.deselect=function(){this.selected=!1,this.mvtSource.featureDeselected(this),a(this);var t=this.linkedFeature();t&&t.staticLabel&&t.staticLabel.selected&&t.staticLabel.deselect()},n.prototype.on=function(t,e){this._eventHandlers[t]=e},n.prototype._drawPoint=function(t,e,r){if(r&&t&&t.canvas){var i=this.tiles[t.id],n=1;n="function"==typeof r.radius?r.radius(t.zoom):r.radius;var s,o=this._tilePoint(e[0][0]),a=t.canvas;try{s=a.getContext("2d")}catch(h){return void console.log("_drawPoint error: "+h)}s.beginPath(),s.fillStyle=r.color,s.arc(o.x,o.y,n,0,2*Math.PI),s.closePath(),s.fill(),r.lineWidth&&r.strokeStyle&&(s.lineWidth=r.lineWidth,s.strokeStyle=r.strokeStyle,s.stroke()),s.restore(),i.paths.push([o])}},n.prototype._drawLineString=function(t,e,r){if(r&&t&&t.canvas){var n=t.canvas.getContext("2d");n.strokeStyle=r.color,n.lineWidth=r.size,n.beginPath();var s=[],o=this.tiles[t.id];for(var a in e){var h=e[a];for(i=0;ih;h++)for(var l=e[h],f=0;fr;r++){var n=e[r];n.removeLabel()}t.featuresWithLabels=[]}function in_circle(t,e,r,i,n){var s=Math.pow(t-i,2)+Math.pow(e-n,2);return s<=Math.pow(r,2)}function waitFor(testFx,onReady,timeOutMillis){var maxtimeOutMillis=timeOutMillis?timeOutMillis:3e3,start=(new Date).getTime(),condition="string"==typeof testFx?eval(testFx):testFx(),interval=setInterval(function(){(new Date).getTime()-start1){t=L.point(t.x,t.y);for(var i=0,n=e.length-1;n>i;i++){var s=this._projectPointOnLineSegment(t,e[i],e[i+1]);s.distance<=r&&(r=s.distance)}}return r},_projectPointOnLineSegment:function(t,e,r){var i=e.distanceTo(r);if(1>i)return{distance:t.distanceTo(e),coordinate:e};var n=((t.x-e.x)*(r.x-e.x)+(t.y-e.y)*(r.y-e.y))/Math.pow(i,2);if(1e-7>n)return{distance:t.distanceTo(e),coordinate:e};if(n>.9999999)return{distance:t.distanceTo(r),coordinate:r};var s=L.point(e.x+n*(r.x-e.x),e.y+n*(r.y-e.y));return{distance:t.distanceTo(s),point:s}},initialize:function(t,e){var r=this;r.mvtSource=t,L.Util.setOptions(this,e),this.style=e.style,this.name=e.name,this._canvasIDToFeatures={},this.features={},this.featuresWithLabels=[],this._highestCount=0},onAdd:function(t){var e=this;e.map=t,L.TileLayer.Canvas.prototype.onAdd.call(this,t),t.on("layerremove",function(t){t.layer._leaflet_id===e._leaflet_id&&removeLabels(e)})},drawTile:function(t,e,r){var i={canvas:t,tile:e,zoom:r,tileSize:this.options.tileSize};i.id=Util.getContextID(i),this._canvasIDToFeatures[i.id]||this._initializeFeaturesHash(i),this.features||(this.features={})},_initializeFeaturesHash:function(t){this._canvasIDToFeatures[t.id]={},this._canvasIDToFeatures[t.id].features=[],this._canvasIDToFeatures[t.id].canvas=t.canvas},_draw:function(t){},getCanvas:function(t){var e=t.tile,r=this._tiles[e.x+":"+e.y];if(r)return t.canvas=r,void this.redrawTile(t.id);var i=this;waitFor(function(){return r=i._tiles[e.x+":"+e.y],r?!0:void 0},function(){r=i._tiles[e.x+":"+e.y],t.canvas=r,i.redrawTile(t.id)},2e3)},parseVectorTileLayer:function(t,e){var r=this,i=e.tile,n={canvas:null,id:e.id,tile:e.tile,zoom:e.zoom,tileSize:e.tileSize};n.canvas=r._tiles[i.x+":"+i.y],this._canvasIDToFeatures[n.id]?this.clearTileFeatureHash(n.id):this._initializeFeaturesHash(n);for(var s=t.parsedFeatures,o=0,a=s.length;a>o;o++){var h=s[o];h.layer=t;var u=r.options.filter;if("function"!=typeof u||u(h,n)!==!1){var l;l="function"==typeof r.options.getIDForLayerFeature?r.options.getIDForLayerFeature:Util.getIDForLayerFeature;var f=r.options.getIDForLayerFeature(h)||o,c=r.features[f],p=r.options.layerOrdering;if("function"==typeof p&&p(h,n),c)c.addTileFeature(h,n);else{var d=r.style(h);r.features[f]=c=new MVTFeature(r,h,n,f,d),d&&d.dynamicLabel&&"function"==typeof d.dynamicLabel&&r.featuresWithLabels.push(c)}n&&n.id&&r._canvasIDToFeatures[n.id].features.push(c)}}var p=r.options.layerOrdering;p&&(r._canvasIDToFeatures[n.id].features=r._canvasIDToFeatures[n.id].features.sort(function(t,e){return-(e.properties.zIndex-t.properties.zIndex)})),r.redrawTile(n.id)},setStyle:function(t){this._highestCount=0,this._lowestCount=null,this.style=t;for(var e in this.features){var r=this.features[e];r.setStyle(t)}var i=this.map.getZoom();for(var e in this._tiles){var n=i+":"+e;this.redrawTile(n)}},setHighestCount:function(t){t>this._highestCount&&(this._highestCount=t)},getHighestCount:function(){return this._highestCount},setLowestCount:function(t){(!this._lowestCount||ta&&(p=y,c=a)}break;case 3:for(o=y.getPathsForTile(t.tileID),s=0;so;o++){var h=i[o];h.draw(t)}}},_resetCanvasIDToFeatures:function(t,e){this._canvasIDToFeatures[t]={},this._canvasIDToFeatures[t].features=[],this._canvasIDToFeatures[t].canvas=e},linkedLayer:function(){if(this.mvtSource.layerLink){var t=this.mvtSource.layerLink(this.name);return this.mvtSource.layers[t]}return null},featureWithLabelAdded:function(t){this.featuresWithLabels.push(t)}})},{"./MVTFeature":8,"./MVTUtil":11}],10:[function(t,e,r){function i(t,e,r){var i=parseInt(Math.floor((e+180)/360*(1<r;r++){var n=t.feature(r);n.coordinates=n.loadGeometry(),t.parsedFeatures.push(n)}return t}var a=t("vector-tile").VectorTile,h=t("pbf"),u=(t("point-geometry"),t("./MVTUtil")),l=t("./MVTLayer");e.exports=L.TileLayer.MVTSource=L.TileLayer.Canvas.extend({options:{debug:!1,url:"",getIDForLayerFeature:function(){},tileSize:256,visibleLayers:[],xhrHeaders:{}},layers:{},processedTiles:{},_eventHandlers:{},_triggerOnTilesLoadedEvent:!0,_url:"",style:function(t){var e={},r=t.type;switch(r){case 1:e.color="rgba(49,79,79,1)",e.radius=5,e.selected={color:"rgba(255,255,0,0.5)",radius:6};break;case 2:e.color="rgba(161,217,155,0.8)",e.size=3,e.selected={color:"rgba(255,25,0,0.5)",size:4};break;case 3:e.color="rgba(49,79,79,1)",e.outline={color:"rgba(161,217,155,0.8)",size:1},e.selected={color:"rgba(255,140,0,0.3)",outline:{color:"rgba(255,140,0,1)",size:2}}}return e},initialize:function(t){L.Util.setOptions(this,t),this.layers={},this.activeTiles={},this.loadedTiles={},this._url=this.options.url,this.zIndex=t.zIndex,"function"==typeof t.style&&(this.style=t.style),"function"==typeof t.ajaxSource&&(this.ajaxSource=t.ajaxSource),this.layerLink=t.layerLink,this._eventHandlers={},this._tilesToProcess=0},redraw:function(t){t===!1&&(this._triggerOnTilesLoadedEvent=!1),L.TileLayer.Canvas.prototype.redraw.call(this)},onAdd:function(t){var e=this;e.map=t,L.TileLayer.Canvas.prototype.onAdd.call(this,t);var r=function(t){e._onClick(t)};t.on("click",r),t.on("layerremove",function(i){i.layer._leaflet_id===e._leaflet_id&&i.layer.removeChildLayers&&(i.layer.removeChildLayers(t),t.off("click",r))}),e.addChildLayers(t),"function"==typeof DynamicLabel&&(this.dynamicLabel=new DynamicLabel(t,this,{}))},drawTile:function(t,e,r){var i={id:[r,e.x,e.y].join(":"),canvas:t,tile:e,zoom:r,tileSize:this.options.tileSize};this._tilesToProcess0)for(var n=0;n-1&&this.visibleLayers.splice(this.options.visibleLayers.indexOf("id"),1))},showLayer:function(t){this.layers[t]&&(this._map.addLayer(this.layers[t]),-1==this.options.visibleLayers.indexOf("id")&&this.visibleLayers.push(t)),this.bringToFront()},removeChildLayers:function(t){for(var e in this.layers){var r=this.layers[e];t.removeLayer(r)}},addChildLayers:function(t){var e=this;if(e.options.visibleLayers.length>0)for(var r=0;r0)for(var o=0,a=n.length;a>o;o++){var h=n[o],u=s[h];u&&u.handleClickEvent(t,function(t){"function"==typeof r&&r(t)})}else"function"==typeof r&&r(t)},setFilter:function(t,e){for(var r in this.layers){var i=this.layers[r];e?r.toLowerCase()==e.toLowerCase()&&(i.options.filter=t,i.clearLayerFeatureHash()):(i.options.filter=t,i.clearLayerFeatureHash())}},setStyle:function(t,e){for(var r in this.layers){var i=this.layers[r];e?r.toLowerCase()==e.toLowerCase()&&i.setStyle(t):i.setStyle(t)}},featureSelected:function(t){this.options.mutexToggle&&(this._selectedFeature&&this._selectedFeature.deselect(),this._selectedFeature=t),this.options.onSelect&&this.options.onSelect(t)},featureDeselected:function(t){this.options.mutexToggle&&this._selectedFeature&&(this._selectedFeature=null),this.options.onDeselect&&this.options.onDeselect(t)},_pbfLoaded:function(){this.bringToFront();var t=this,e=t.options.onTilesLoaded;e&&"function"==typeof e&&this._triggerOnTilesLoadedEvent===!0&&e(this),t._triggerOnTilesLoadedEvent=!0}}),"undefined"==typeof Number.prototype.toRad&&(Number.prototype.toRad=function(){return this*Math.PI/180})},{"./MVTLayer":9,"./MVTUtil":11,pbf:1,"point-geometry":3,"vector-tile":4}],11:[function(t,e,r){var i=e.exports={};i.getContextID=function(t){return[t.zoom,t.tile.x,t.tile.y].join(":")},i.getIDForLayerFeature=function(t){return t.properties.id},i.getJSON=function(t,e){var r="undefined"!=typeof XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");r.onreadystatechange=function(){var t=r.status;if(4===r.readyState&&t>=200&&300>t){var i=JSON.parse(r.responseText);e(null,i)}else e({error:!0,status:t})},r.open("GET",t,!0),r.send()}},{}],12:[function(t,e,r){function i(t,e,r,i){var s=this;if(this.mvtFeature=t,this.map=t.map,this.zoom=e.zoom,this.latLng=r,this.selected=!1,t.linkedFeature){var o=t.linkedFeature();o&&o.selected&&(s.selected=!0)}n(s,t,e,r,i)}function n(t,e,r,i,n){var s=e.ajaxData,o=t.style=n.staticLabel(e,s),a=t.icon=L.divIcon({className:o.cssClass||"label-icon-text",html:o.html,iconSize:o.iconSize||[50,50]});t.marker=L.marker(i,{icon:a}).addTo(t.map),t.selected&&t.marker._icon.classList.add(t.style.cssSelectedClass||"label-icon-text-selected"),t.marker.on("click",function(e){t.toggle()}),t.map.on("zoomend",function(e){var r=e.target.getZoom();t.zoom!==r&&t.map.removeLayer(t.marker)})}t("../MVTUtil");e.exports=i,i.prototype.toggle=function(){this.selected?this.deselect():this.select()},i.prototype.select=function(){this.selected=!0,this.marker._icon.classList.add(this.style.cssSelectedClass||"label-icon-text-selected");var t=this.mvtFeature.linkedFeature();t.selected||t.select()},i.prototype.deselect=function(){this.selected=!1,this.marker._icon.classList.remove(this.style.cssSelectedClass||"label-icon-text-selected");var t=this.mvtFeature.linkedFeature();t.selected&&t.deselect()},i.prototype.remove=function(){this.map&&this.marker&&this.map.removeLayer(this.marker)}},{"../MVTUtil":11}],13:[function(t,e,r){/** + * Copyright (c) 2014, Spatial Development International + * All rights reserved. + * + * Source code can be found at: + * https://github.com/SpatialServer/Leaflet.MapboxVectorTile + * + * @license ISC + */ +e.exports=t("./MVTSource")},{"./MVTSource":10}],14:[function(t,e,r){(function(e){function i(){function t(){}try{var e=new Uint8Array(1);return e.foo=function(){return 42},e.constructor=t,42===e.foo()&&e.constructor===t&&"function"==typeof e.subarray&&0===e.subarray(1,1).byteLength}catch(r){return!1}}function n(){return s.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function s(t){return this instanceof s?(this.length=0,this.parent=void 0,"number"==typeof t?o(this,t):"string"==typeof t?a(this,t,arguments.length>1?arguments[1]:"utf8"):h(this,t)):arguments.length>1?new s(t,arguments[1]):new s(t)}function o(t,e){if(t=y(t,0>e?0:0|v(e)),!s.TYPED_ARRAY_SUPPORT)for(var r=0;e>r;r++)t[r]=0;return t}function a(t,e,r){("string"!=typeof r||""===r)&&(r="utf8");var i=0|w(e,r);return t=y(t,i),t.write(e,r),t}function h(t,e){if(s.isBuffer(e))return u(t,e);if(G(e))return l(t,e);if(null==e)throw new TypeError("must start with number, buffer, array or string");if("undefined"!=typeof ArrayBuffer){if(e.buffer instanceof ArrayBuffer)return f(t,e);if(e instanceof ArrayBuffer)return c(t,e)}return e.length?p(t,e):d(t,e)}function u(t,e){var r=0|v(e.length);return t=y(t,r),e.copy(t,0,0,r),t}function l(t,e){var r=0|v(e.length);t=y(t,r);for(var i=0;r>i;i+=1)t[i]=255&e[i];return t}function f(t,e){var r=0|v(e.length);t=y(t,r);for(var i=0;r>i;i+=1)t[i]=255&e[i];return t}function c(t,e){return s.TYPED_ARRAY_SUPPORT?(e.byteLength,t=s._augment(new Uint8Array(e))):t=f(t,new Uint8Array(e)),t}function p(t,e){var r=0|v(e.length);t=y(t,r);for(var i=0;r>i;i+=1)t[i]=255&e[i];return t}function d(t,e){var r,i=0;"Buffer"===e.type&&G(e.data)&&(r=e.data,i=0|v(r.length)),t=y(t,i);for(var n=0;i>n;n+=1)t[n]=255&r[n];return t}function y(t,e){s.TYPED_ARRAY_SUPPORT?(t=s._augment(new Uint8Array(e)),t.__proto__=s.prototype):(t.length=e,t._isBuffer=!0);var r=0!==e&&e<=s.poolSize>>>1;return r&&(t.parent=K),t}function v(t){if(t>=n())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n().toString(16)+" bytes");return 0|t}function g(t,e){if(!(this instanceof g))return new g(t,e);var r=new s(t,e);return delete r.parent,r}function w(t,e){"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var i=!1;;)switch(e){case"ascii":case"binary":case"raw":case"raws":return r;case"utf8":case"utf-8":return N(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return W(t).length;default:if(i)return N(t).length;e=(""+e).toLowerCase(),i=!0}}function b(t,e,r){var i=!1;if(e=0|e,r=void 0===r||r===1/0?this.length:0|r,t||(t="utf8"),0>e&&(e=0),r>this.length&&(r=this.length),e>=r)return"";for(;;)switch(t){case"hex":return U(this,e,r);case"utf8":case"utf-8":return S(this,e,r);case"ascii":return A(this,e,r);case"binary":return P(this,e,r);case"base64":return x(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,e,r);default:if(i)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),i=!0}}function _(t,e,r,i){r=Number(r)||0;var n=t.length-r;i?(i=Number(i),i>n&&(i=n)):i=n;var s=e.length;if(s%2!==0)throw new Error("Invalid hex string");i>s/2&&(i=s/2);for(var o=0;i>o;o++){var a=parseInt(e.substr(2*o,2),16);if(isNaN(a))throw new Error("Invalid hex string");t[r+o]=a}return o}function m(t,e,r,i){return Z(N(e,t.length-r),t,r,i)}function L(t,e,r,i){return Z(H(e),t,r,i)}function T(t,e,r,i){return L(t,e,r,i)}function E(t,e,r,i){return Z(W(e),t,r,i)}function I(t,e,r,i){return Z(q(e,t.length-r),t,r,i)}function x(t,e,r){return 0===e&&r===t.length?X.fromByteArray(t):X.fromByteArray(t.slice(e,r))}function S(t,e,r){r=Math.min(t.length,r);for(var i=[],n=e;r>n;){var s=t[n],o=null,a=s>239?4:s>223?3:s>191?2:1;if(r>=n+a){var h,u,l,f;switch(a){case 1:128>s&&(o=s);break;case 2:h=t[n+1],128===(192&h)&&(f=(31&s)<<6|63&h,f>127&&(o=f));break;case 3:h=t[n+1],u=t[n+2],128===(192&h)&&128===(192&u)&&(f=(15&s)<<12|(63&h)<<6|63&u,f>2047&&(55296>f||f>57343)&&(o=f));break;case 4:h=t[n+1],u=t[n+2],l=t[n+3],128===(192&h)&&128===(192&u)&&128===(192&l)&&(f=(15&s)<<18|(63&h)<<12|(63&u)<<6|63&l,f>65535&&1114112>f&&(o=f))}}null===o?(o=65533,a=1):o>65535&&(o-=65536,i.push(o>>>10&1023|55296),o=56320|1023&o),i.push(o),n+=a}return F(i)}function F(t){var e=t.length;if(Q>=e)return String.fromCharCode.apply(String,t);for(var r="",i=0;e>i;)r+=String.fromCharCode.apply(String,t.slice(i,i+=Q));return r}function A(t,e,r){var i="";r=Math.min(t.length,r);for(var n=e;r>n;n++)i+=String.fromCharCode(127&t[n]);return i}function P(t,e,r){var i="";r=Math.min(t.length,r);for(var n=e;r>n;n++)i+=String.fromCharCode(t[n]);return i}function U(t,e,r){var i=t.length;(!e||0>e)&&(e=0),(!r||0>r||r>i)&&(r=i);for(var n="",s=e;r>s;s++)n+=j(t[s]);return n}function R(t,e,r){for(var i=t.slice(e,r),n="",s=0;st)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function D(t,e,r,i,n,o){if(!s.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");if(e>n||o>e)throw new RangeError("value is out of bounds");if(r+i>t.length)throw new RangeError("index out of range")}function M(t,e,r,i){0>e&&(e=65535+e+1);for(var n=0,s=Math.min(t.length-r,2);s>n;n++)t[r+n]=(e&255<<8*(i?n:1-n))>>>8*(i?n:1-n)}function k(t,e,r,i){0>e&&(e=4294967295+e+1);for(var n=0,s=Math.min(t.length-r,4);s>n;n++)t[r+n]=e>>>8*(i?n:3-n)&255}function C(t,e,r,i,n,s){if(e>n||s>e)throw new RangeError("value is out of bounds");if(r+i>t.length)throw new RangeError("index out of range");if(0>r)throw new RangeError("index out of range")}function V(t,e,r,i,n){return n||C(t,e,r,4,3.4028234663852886e38,-3.4028234663852886e38),J.write(t,e,r,i,23,4),r+4}function O(t,e,r,i,n){return n||C(t,e,r,8,1.7976931348623157e308,-1.7976931348623157e308),J.write(t,e,r,i,52,8),r+8}function z(t){if(t=Y(t).replace(tt,""),t.length<2)return"";for(;t.length%4!==0;)t+="=";return t}function Y(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function j(t){return 16>t?"0"+t.toString(16):t.toString(16)}function N(t,e){e=e||1/0;for(var r,i=t.length,n=null,s=[],o=0;i>o;o++){if(r=t.charCodeAt(o),r>55295&&57344>r){if(!n){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(o+1===i){(e-=3)>-1&&s.push(239,191,189);continue}n=r;continue}if(56320>r){(e-=3)>-1&&s.push(239,191,189),n=r;continue}r=n-55296<<10|r-56320|65536}else n&&(e-=3)>-1&&s.push(239,191,189);if(n=null,128>r){if((e-=1)<0)break;s.push(r)}else if(2048>r){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(65536>r){if((e-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(1114112>r))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function H(t){for(var e=[],r=0;r>8,n=r%256,s.push(n),s.push(i);return s}function W(t){return X.toByteArray(z(t))}function Z(t,e,r,i){for(var n=0;i>n&&!(n+r>=e.length||n>=t.length);n++)e[n+r]=t[n];return n}/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ +var X=t("base64-js"),J=t("ieee754"),G=t("is-array");r.Buffer=s,r.SlowBuffer=g,r.INSPECT_MAX_BYTES=50,s.poolSize=8192;var K={};s.TYPED_ARRAY_SUPPORT=void 0!==e.TYPED_ARRAY_SUPPORT?e.TYPED_ARRAY_SUPPORT:i(),s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array),s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,i=e.length,n=0,o=Math.min(r,i);o>n&&t[n]===e[n];)++n;return n!==o&&(r=t[n],i=e[n]),i>r?-1:r>i?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!G(t))throw new TypeError("list argument must be an Array of Buffers.");if(0===t.length)return new s(0);var r;if(void 0===e)for(e=0,r=0;r0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},s.prototype.compare=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t?0:s.compare(this,t)},s.prototype.indexOf=function(t,e){function r(t,e,r){for(var i=-1,n=0;r+n2147483647?e=2147483647:-2147483648>e&&(e=-2147483648),e>>=0,0===this.length)return-1;if(e>=this.length)return-1;if(0>e&&(e=Math.max(this.length+e,0)),"string"==typeof t)return 0===t.length?-1:String.prototype.indexOf.call(this,t,e);if(s.isBuffer(t))return r(this,t,e);if("number"==typeof t)return s.TYPED_ARRAY_SUPPORT&&"function"===Uint8Array.prototype.indexOf?Uint8Array.prototype.indexOf.call(this,t,e):r(this,[t],e);throw new TypeError("val must be string, number or Buffer")},s.prototype.get=function(t){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(t)},s.prototype.set=function(t,e){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(t,e)},s.prototype.write=function(t,e,r,i){if(void 0===e)i="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)i=e,r=this.length,e=0;else if(isFinite(e))e=0|e,isFinite(r)?(r=0|r,void 0===i&&(i="utf8")):(i=r,r=void 0);else{var n=i;i=e,e=0|r,r=n}var s=this.length-e;if((void 0===r||r>s)&&(r=s),t.length>0&&(0>r||0>e)||e>this.length)throw new RangeError("attempt to write outside buffer bounds");i||(i="utf8");for(var o=!1;;)switch(i){case"hex":return _(this,t,e,r);case"utf8":case"utf-8":return m(this,t,e,r);case"ascii":return L(this,t,e,r);case"binary":return T(this,t,e,r);case"base64":return E(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,t,e,r);default:if(o)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),o=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Q=4096;s.prototype.slice=function(t,e){var r=this.length;t=~~t,e=void 0===e?r:~~e,0>t?(t+=r,0>t&&(t=0)):t>r&&(t=r),0>e?(e+=r,0>e&&(e=0)):e>r&&(e=r),t>e&&(e=t);var i;if(s.TYPED_ARRAY_SUPPORT)i=s._augment(this.subarray(t,e));else{var n=e-t;i=new s(n,void 0);for(var o=0;n>o;o++)i[o]=this[o+t]}return i.length&&(i.parent=this.parent||this),i},s.prototype.readUIntLE=function(t,e,r){t=0|t,e=0|e,r||B(t,e,this.length);for(var i=this[t],n=1,s=0;++s0&&(n*=256);)i+=this[t+--e]*n;return i},s.prototype.readUInt8=function(t,e){return e||B(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||B(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||B(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||B(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||B(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t=0|t,e=0|e,r||B(t,e,this.length);for(var i=this[t],n=1,s=0;++s=n&&(i-=Math.pow(2,8*e)),i},s.prototype.readIntBE=function(t,e,r){t=0|t,e=0|e,r||B(t,e,this.length);for(var i=e,n=1,s=this[t+--i];i>0&&(n*=256);)s+=this[t+--i]*n;return n*=128,s>=n&&(s-=Math.pow(2,8*e)),s},s.prototype.readInt8=function(t,e){return e||B(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){e||B(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){e||B(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return e||B(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||B(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||B(t,4,this.length),J.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||B(t,4,this.length),J.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||B(t,8,this.length),J.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||B(t,8,this.length),J.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,r,i){t=+t,e=0|e,r=0|r,i||D(this,t,e,r,Math.pow(2,8*r),0);var n=1,s=0;for(this[e]=255&t;++s=0&&(s*=256);)this[e+n]=t/s&255;return e+r},s.prototype.writeUInt8=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):M(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):M(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):k(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):k(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,r,i){if(t=+t,e=0|e,!i){var n=Math.pow(2,8*r-1);D(this,t,e,r,n-1,-n)}var s=0,o=1,a=0>t?1:0;for(this[e]=255&t;++s>0)-a&255;return e+r},s.prototype.writeIntBE=function(t,e,r,i){if(t=+t,e=0|e,!i){var n=Math.pow(2,8*r-1);D(this,t,e,r,n-1,-n)}var s=r-1,o=1,a=0>t?1:0;for(this[e+s]=255&t;--s>=0&&(o*=256);)this[e+s]=(t/o>>0)-a&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),0>t&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):M(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):M(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):k(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e=0|e,r||D(this,t,e,4,2147483647,-2147483648),0>t&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):k(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,r){return V(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return V(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return O(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return O(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,i){if(r||(r=0),i||0===i||(i=this.length),e>=t.length&&(e=t.length),e||(e=0),i>0&&r>i&&(i=r),i===r)return 0;if(0===t.length||0===this.length)return 0;if(0>e)throw new RangeError("targetStart out of bounds");if(0>r||r>=this.length)throw new RangeError("sourceStart out of bounds");if(0>i)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-er&&i>e)for(n=o-1;n>=0;n--)t[n+e]=this[n+r];else if(1e3>o||!s.TYPED_ARRAY_SUPPORT)for(n=0;o>n;n++)t[n+e]=this[n+r];else t._set(this.subarray(r,r+o),e);return o},s.prototype.fill=function(t,e,r){if(t||(t=0),e||(e=0),r||(r=this.length),e>r)throw new RangeError("end < start");if(r!==e&&0!==this.length){if(0>e||e>=this.length)throw new RangeError("start out of bounds");if(0>r||r>this.length)throw new RangeError("end out of bounds");var i;if("number"==typeof t)for(i=e;r>i;i++)this[i]=t;else{var n=N(t.toString()),s=n.length;for(i=e;r>i;i++)this[i]=n[i%s]}return this}},s.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(s.TYPED_ARRAY_SUPPORT)return new s(this).buffer;for(var t=new Uint8Array(this.length),e=0,r=t.length;r>e;e+=1)t[e]=this[e];return t.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var $=s.prototype;s._augment=function(t){return t.constructor=s,t._isBuffer=!0,t._set=t.set,t.get=$.get,t.set=$.set,t.write=$.write,t.toString=$.toString,t.toLocaleString=$.toString,t.toJSON=$.toJSON,t.equals=$.equals,t.compare=$.compare,t.indexOf=$.indexOf,t.copy=$.copy,t.slice=$.slice,t.readUIntLE=$.readUIntLE,t.readUIntBE=$.readUIntBE,t.readUInt8=$.readUInt8,t.readUInt16LE=$.readUInt16LE,t.readUInt16BE=$.readUInt16BE,t.readUInt32LE=$.readUInt32LE,t.readUInt32BE=$.readUInt32BE,t.readIntLE=$.readIntLE,t.readIntBE=$.readIntBE,t.readInt8=$.readInt8,t.readInt16LE=$.readInt16LE,t.readInt16BE=$.readInt16BE,t.readInt32LE=$.readInt32LE,t.readInt32BE=$.readInt32BE,t.readFloatLE=$.readFloatLE,t.readFloatBE=$.readFloatBE,t.readDoubleLE=$.readDoubleLE,t.readDoubleBE=$.readDoubleBE,t.writeUInt8=$.writeUInt8,t.writeUIntLE=$.writeUIntLE,t.writeUIntBE=$.writeUIntBE,t.writeUInt16LE=$.writeUInt16LE,t.writeUInt16BE=$.writeUInt16BE,t.writeUInt32LE=$.writeUInt32LE,t.writeUInt32BE=$.writeUInt32BE,t.writeIntLE=$.writeIntLE,t.writeIntBE=$.writeIntBE,t.writeInt8=$.writeInt8,t.writeInt16LE=$.writeInt16LE,t.writeInt16BE=$.writeInt16BE,t.writeInt32LE=$.writeInt32LE,t.writeInt32BE=$.writeInt32BE,t.writeFloatLE=$.writeFloatLE,t.writeFloatBE=$.writeFloatBE,t.writeDoubleLE=$.writeDoubleLE,t.writeDoubleBE=$.writeDoubleBE,t.fill=$.fill,t.inspect=$.inspect,t.toArrayBuffer=$.toArrayBuffer,t};var tt=/[^+\/0-9A-Za-z-_]/g}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"base64-js":15,ieee754:16,"is-array":17}],15:[function(t,e,r){var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(t){"use strict";function e(t){var e=t.charCodeAt(0);return e===o||e===f?62:e===a||e===c?63:h>e?-1:h+10>e?e-h+26+26:l+26>e?e-l:u+26>e?e-u+26:void 0}function r(t){function r(t){u[f++]=t}var i,n,o,a,h,u;if(t.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var l=t.length;h="="===t.charAt(l-2)?2:"="===t.charAt(l-1)?1:0,u=new s(3*t.length/4-h),o=h>0?t.length-4:t.length;var f=0;for(i=0,n=0;o>i;i+=4,n+=3)a=e(t.charAt(i))<<18|e(t.charAt(i+1))<<12|e(t.charAt(i+2))<<6|e(t.charAt(i+3)),r((16711680&a)>>16),r((65280&a)>>8),r(255&a);return 2===h?(a=e(t.charAt(i))<<2|e(t.charAt(i+1))>>4,r(255&a)):1===h&&(a=e(t.charAt(i))<<10|e(t.charAt(i+1))<<4|e(t.charAt(i+2))>>2,r(a>>8&255),r(255&a)),u}function n(t){function e(t){return i.charAt(t)}function r(t){return e(t>>18&63)+e(t>>12&63)+e(t>>6&63)+e(63&t)}var n,s,o,a=t.length%3,h="";for(n=0,o=t.length-a;o>n;n+=3)s=(t[n]<<16)+(t[n+1]<<8)+t[n+2],h+=r(s);switch(a){case 1:s=t[t.length-1],h+=e(s>>2),h+=e(s<<4&63),h+="==";break;case 2:s=(t[t.length-2]<<8)+t[t.length-1],h+=e(s>>10),h+=e(s>>4&63),h+=e(s<<2&63),h+="="}return h}var s="undefined"!=typeof Uint8Array?Uint8Array:Array,o="+".charCodeAt(0),a="/".charCodeAt(0),h="0".charCodeAt(0),u="a".charCodeAt(0),l="A".charCodeAt(0),f="-".charCodeAt(0),c="_".charCodeAt(0);t.toByteArray=r,t.fromByteArray=n}("undefined"==typeof r?this.base64js={}:r)},{}],16:[function(t,e,r){arguments[4][2][0].apply(r,arguments)},{dup:2}],17:[function(t,e,r){var i=Array.isArray,n=Object.prototype.toString;e.exports=i||function(t){return!!t&&"[object Array]"==n.call(t)}},{}]},{},[13]); diff --git a/lib/jquery-2.1.1.min.js b/lib/jquery-2.1.1.min.js new file mode 100644 index 0000000..e5ace11 --- /dev/null +++ b/lib/jquery-2.1.1.min.js @@ -0,0 +1,4 @@ +/*! jQuery v2.1.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ +!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.1",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="
    ",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+Math.random()}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c)},removeData:function(a,b){M.remove(a,b) +},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthx",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*\s*$/g,ib={option:[1,""],thead:[1,"","
    "],col:[2,"","
    "],tr:[2,"","
    "],td:[3,"","
    "],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(ob(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(ob(c,"script"),kb),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(hb,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function tb(a){var b=l,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||n("