/*! JointJS v0.9.7 - JavaScript diagramming library 2016-04-20
|
|
|
This Source Code Form is subject to the terms of the Mozilla Public
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
*/
|
var joint =
|
/******/ (function(modules) { // webpackBootstrap
|
/******/ // The module cache
|
/******/ var installedModules = {};
|
|
/******/ // The require function
|
/******/ function __webpack_require__(moduleId) {
|
|
/******/ // Check if module is in cache
|
/******/ if(installedModules[moduleId])
|
/******/ return installedModules[moduleId].exports;
|
|
/******/ // Create a new module (and put it into the cache)
|
/******/ var module = installedModules[moduleId] = {
|
/******/ exports: {},
|
/******/ id: moduleId,
|
/******/ loaded: false
|
/******/ };
|
|
/******/ // Execute the module function
|
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
/******/ // Flag the module as loaded
|
/******/ module.loaded = true;
|
|
/******/ // Return the exports of the module
|
/******/ return module.exports;
|
/******/ }
|
|
|
/******/ // expose the modules object (__webpack_modules__)
|
/******/ __webpack_require__.m = modules;
|
|
/******/ // expose the module cache
|
/******/ __webpack_require__.c = installedModules;
|
|
/******/ // __webpack_public_path__
|
/******/ __webpack_require__.p = "";
|
|
/******/ // Load entry module and return exports
|
/******/ return __webpack_require__(0);
|
/******/ })
|
/************************************************************************/
|
/******/ ([
|
/* 0 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function(root, factory) {
|
|
if (true) {
|
|
// For AMD.
|
|
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1), __webpack_require__(4), __webpack_require__(3)], __WEBPACK_AMD_DEFINE_RESULT__ = function(Backbone, _, $) {
|
|
Backbone.$ = $;
|
|
return factory(root, Backbone, _, $);
|
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
} else if (typeof exports !== 'undefined') {
|
|
// For Node.js or CommonJS.
|
|
var Backbone = require('backbone');
|
var _ = require('lodash');
|
var $ = Backbone.$ = require('jquery');
|
|
module.exports = factory(root, Backbone, _, $);
|
|
} else {
|
|
// As a browser global.
|
|
var Backbone = root.Backbone;
|
var _ = root._;
|
var $ = Backbone.$ = root.jQuery || root.$;
|
|
root.joint = factory(root, Backbone, _, $);
|
root.g = root.joint.g;
|
root.V = root.Vectorizer = root.joint.V;
|
}
|
|
}(this, function(root, Backbone, _, $) {
|
|
var g=function(){function a(b,c){if(!(this instanceof a))return new a(b,c);var d;void 0===c&&Object(b)!==b?(d=b.split(-1===b.indexOf("@")?" ":"@"),this.x=parseInt(d[0],10),this.y=parseInt(d[1],10)):Object(b)===b?(this.x=b.x,this.y=b.y):(this.x=b,this.y=c)}function b(c,d){return this instanceof b?(this.start=a(c),void(this.end=a(d))):new b(c,d)}function c(a,b,d,e){return this instanceof c?(void 0===b&&(b=a.y,d=a.width,e=a.height,a=a.x),this.x=a,this.y=b,this.width=d,void(this.height=e)):new c(a,b,d,e)}function d(b,c,e){return this instanceof d?(b=a(b),this.x=b.x,this.y=b.y,this.a=c,void(this.b=e)):new d(b,c,e)}var e=Math,f=e.abs,h=e.cos,i=e.sin,j=e.sqrt,k=e.min,l=e.max,m=(e.atan,e.atan2),n=(e.acos,e.round),o=e.floor,p=e.PI,q=e.random,r=function(a){return 180*a/p%360},s=function(a,b){return b=b||!1,a=b?a:a%360,a*p/180},t=function(a,b){return b*Math.round(a/b)},u=function(a){return a%360+(0>a?360:0)};a.prototype={toString:function(){return this.x+"@"+this.y},adhereToRect:function(a){return a.containsPoint(this)?this:(this.x=k(l(this.x,a.x),a.x+a.width),this.y=k(l(this.y,a.y),a.y+a.height),this)},theta:function(b){b=a(b);var c=-(b.y-this.y),d=b.x-this.x,e=10,f=0==c.toFixed(e)&&0==d.toFixed(e)?0:m(c,d);return 0>f&&(f=2*p+f),180*f/p},distance:function(a){return b(this,a).length()},manhattanDistance:function(a){return f(a.x-this.x)+f(a.y-this.y)},offset:function(a,b){return this.x+=a||0,this.y+=b||0,this},magnitude:function(){return j(this.x*this.x+this.y*this.y)||.01},update:function(a,b){return this.x=a||0,this.y=b||0,this},round:function(a){return this.x=a?this.x.toFixed(a):n(this.x),this.y=a?this.y.toFixed(a):n(this.y),this},normalize:function(a){var b=(a||1)/this.magnitude();return this.x=b*this.x,this.y=b*this.y,this},difference:function(b){return a(this.x-b.x,this.y-b.y)},bearing:function(a){return b(this,a).bearing()},toPolar:function(b){b=b&&a(b)||a(0,0);var c=this.x,d=this.y;return this.x=j((c-b.x)*(c-b.x)+(d-b.y)*(d-b.y)),this.y=s(b.theta(a(c,d))),this},rotate:function(b,c){c=(c+360)%360,this.toPolar(b),this.y+=s(c);var d=a.fromPolar(this.x,this.y,b);return this.x=d.x,this.y=d.y,this},move:function(b,c){var d=s(a(b).theta(this));return this.offset(h(d)*c,-i(d)*c)},scale:function(b,c,d){return d=d&&a(d)||a(0,0),this.x=d.x+b*(this.x-d.x),this.y=d.y+c*(this.y-d.y),this},changeInAngle:function(b,c,d){return a(this).offset(-b,-c).theta(d)-this.theta(d)},equals:function(a){return this.x===a.x&&this.y===a.y},snapToGrid:function(a,b){return this.x=t(this.x,a),this.y=t(this.y,b||a),this},reflection:function(b){return a(b).move(this,this.distance(b))},clone:function(){return a(this)},toJSON:function(){return{x:this.x,y:this.y}}},a.fromPolar=function(b,c,d){d=d&&a(d)||a(0,0);var e=f(b*h(c)),g=f(b*i(c)),j=u(r(c));return 90>j?g=-g:180>j?(e=-e,g=-g):270>j&&(e=-e),a(d.x+e,d.y+g)},a.random=function(b,c,d,e){return a(o(q()*(c-b+1)+b),o(q()*(e-d+1)+d))},b.prototype={toString:function(){return this.start.toString()+" "+this.end.toString()},length:function(){return j(this.squaredLength())},squaredLength:function(){var a=this.start.x,b=this.start.y,c=this.end.x,d=this.end.y;return(a-=c)*a+(b-=d)*b},midpoint:function(){return a((this.start.x+this.end.x)/2,(this.start.y+this.end.y)/2)},intersection:function(b){var c=a(this.end.x-this.start.x,this.end.y-this.start.y),d=a(b.end.x-b.start.x,b.end.y-b.start.y),e=c.x*d.y-c.y*d.x,f=a(b.start.x-this.start.x,b.start.y-this.start.y),g=f.x*d.y-f.y*d.x,h=f.x*c.y-f.y*c.x;if(0===e||0>g*e||0>h*e)return null;if(e>0){if(g>e||h>e)return null}else if(e>g||e>h)return null;return a(this.start.x+g*c.x/e,this.start.y+g*c.y/e)},bearing:function(){var a=s(this.start.y),b=s(this.end.y),c=this.start.x,d=this.end.x,e=s(d-c),f=i(e)*h(b),g=h(a)*i(b)-i(a)*h(b)*h(e),j=r(m(f,g)),k=["NE","E","SE","S","SW","W","NW","N"],l=j-22.5;return 0>l&&(l+=360),l=parseInt(l/45),k[l]},pointAt:function(b){var c=(1-b)*this.start.x+b*this.end.x,d=(1-b)*this.start.y+b*this.end.y;return a(c,d)},pointOffset:function(a){return((this.end.x-this.start.x)*(a.y-this.start.y)-(this.end.y-this.start.y)*(a.x-this.start.x))/2},clone:function(){return b(this)}},c.prototype={toString:function(){return this.origin().toString()+" "+this.corner().toString()},equals:function(a){var b=g.rect(this).normalize(),c=g.rect(a).normalize();return b.x===c.x&&b.y===c.y&&b.width===c.width&&b.height===c.height},origin:function(){return a(this.x,this.y)},corner:function(){return a(this.x+this.width,this.y+this.height)},topRight:function(){return a(this.x+this.width,this.y)},bottomLeft:function(){return a(this.x,this.y+this.height)},center:function(){return a(this.x+this.width/2,this.y+this.height/2)},intersect:function(a){var b=this.origin(),d=this.corner(),e=a.origin(),f=a.corner();if(f.x<=b.x||f.y<=b.y||e.x>=d.x||e.y>=d.y)return null;var g=Math.max(b.x,e.x),h=Math.max(b.y,e.y);return c(g,h,Math.min(d.x,f.x)-g,Math.min(d.y,f.y)-h)},union:function(a){var b=this.origin(),d=this.corner(),e=a.origin(),f=a.corner(),g=Math.min(b.x,e.x),h=Math.min(b.y,e.y),i=Math.max(d.x,f.x),j=Math.max(d.y,f.y);return c(g,h,i-g,j-h)},sideNearestToPoint:function(b){b=a(b);var c=b.x-this.x,d=this.x+this.width-b.x,e=b.y-this.y,f=this.y+this.height-b.y,g=c,h="left";return g>d&&(g=d,h="right"),g>e&&(g=e,h="top"),g>f&&(g=f,h="bottom"),h},containsPoint:function(b){return b=a(b),b.x>=this.x&&b.x<=this.x+this.width&&b.y>=this.y&&b.y<=this.y+this.height},containsRect:function(a){var b=c(this).normalize(),d=c(a).normalize(),e=b.width,f=b.height,g=d.width,h=d.height;if(!(e&&f&&g&&h))return!1;var i=b.x,j=b.y,k=d.x,l=d.y;return g+=k,e+=i,h+=l,f+=j,k>=i&&e>=g&&l>=j&&f>=h},pointNearestToPoint:function(b){if(b=a(b),this.containsPoint(b)){var c=this.sideNearestToPoint(b);switch(c){case"right":return a(this.x+this.width,b.y);case"left":return a(this.x,b.y);case"bottom":return a(b.x,this.y+this.height);case"top":return a(b.x,this.y)}}return b.adhereToRect(this)},intersectionWithLineFromCenterToPoint:function(c,d){c=a(c);var e,f=a(this.x+this.width/2,this.y+this.height/2);d&&c.rotate(f,d);for(var g=[b(this.origin(),this.topRight()),b(this.topRight(),this.corner()),b(this.corner(),this.bottomLeft()),b(this.bottomLeft(),this.origin())],h=b(f,c),i=g.length-1;i>=0;--i){var j=g[i].intersection(h);if(null!==j){e=j;break}}return e&&d&&e.rotate(f,-d),e},moveAndExpand:function(a){return this.x+=a.x||0,this.y+=a.y||0,this.width+=a.width||0,this.height+=a.height||0,this},round:function(a){return this.x=a?this.x.toFixed(a):n(this.x),this.y=a?this.y.toFixed(a):n(this.y),this.width=a?this.width.toFixed(a):n(this.width),this.height=a?this.height.toFixed(a):n(this.height),this},normalize:function(){var a=this.x,b=this.y,c=this.width,d=this.height;return this.width<0&&(a=this.x+this.width,c=-this.width),this.height<0&&(b=this.y+this.height,d=-this.height),this.x=a,this.y=b,this.width=c,this.height=d,this},bbox:function(a){var b=s(a||0),d=f(i(b)),e=f(h(b)),g=this.width*e+this.height*d,j=this.width*d+this.height*e;return c(this.x+(this.width-g)/2,this.y+(this.height-j)/2,g,j)},scale:function(a,b,c){var d=this.origin().scale(a,b,c);return this.x=d.x,this.y=d.y,this.width*=a,this.height*=b,this},snapToGrid:function(a,b){var c=this.origin().snapToGrid(a,b),d=this.corner().snapToGrid(a,b);return this.x=c.x,this.y=c.y,this.width=d.x-c.x,this.height=d.y-c.y,this},clone:function(){return c(this)},toJSON:function(){return{x:this.x,y:this.y,width:this.width,height:this.height}}},d.prototype={toString:function(){return a(this.x,this.y).toString()+" "+this.a+" "+this.b},bbox:function(){return c(this.x-this.a,this.y-this.b,2*this.a,2*this.b)},intersectionWithLineFromCenterToPoint:function(b,c){b=a(b),c&&b.rotate(a(this.x,this.y),c);var d,e=b.x-this.x,f=b.y-this.y;if(0===e)return d=this.bbox().pointNearestToPoint(b),c?d.rotate(a(this.x,this.y),-c):d;var g=f/e,h=g*g,i=this.a*this.a,k=this.b*this.b,l=j(1/(1/i+h/k));l=0>e?-l:l;var m=g*l;return d=a(this.x+l,this.y+m),c?d.rotate(a(this.x,this.y),-c):d},clone:function(){return d(this)}};var v={curveThroughPoints:function(a){for(var b=this.getCurveControlPoints(a),c=["M",a[0].x,a[0].y],d=0;d<b[0].length;d++)c.push("C",b[0][d].x,b[0][d].y,b[1][d].x,b[1][d].y,a[d+1].x,a[d+1].y);return c},getCurveControlPoints:function(b){var c,d=[],e=[],f=b.length-1;if(1==f)return d[0]=a((2*b[0].x+b[1].x)/3,(2*b[0].y+b[1].y)/3),e[0]=a(2*d[0].x-b[0].x,2*d[0].y-b[0].y),[d,e];var g=[];for(c=1;f-1>c;c++)g[c]=4*b[c].x+2*b[c+1].x;g[0]=b[0].x+2*b[1].x,g[f-1]=(8*b[f-1].x+b[f].x)/2;var h=this.getFirstControlPoints(g);for(c=1;f-1>c;++c)g[c]=4*b[c].y+2*b[c+1].y;g[0]=b[0].y+2*b[1].y,g[f-1]=(8*b[f-1].y+b[f].y)/2;var i=this.getFirstControlPoints(g);for(c=0;f>c;c++)d.push(a(h[c],i[c])),f-1>c?e.push(a(2*b[c+1].x-h[c+1],2*b[c+1].y-i[c+1])):e.push(a((b[f].x+h[f-1])/2,(b[f].y+i[f-1])/2));return[d,e]},getFirstControlPoints:function(a){var b=a.length,c=[],d=[],e=2;c[0]=a[0]/e;for(var f=1;b>f;f++)d[f]=1/e,e=(b-1>f?4:3.5)-d[f],c[f]=(a[f]-c[f-1])/e;for(f=1;b>f;f++)c[b-f-1]-=d[b-f]*c[b-f];return c},getInversionSolver:function(a,b,c,d){function e(a,b){var c=f[a],d=f[b];return function(e){var f=(a%3?3:1)*(b%3?3:1),g=e.x*(c.y-d.y)+e.y*(d.x-c.x)+c.x*d.y-c.y*d.x;return f*g}}var f=arguments;return function(c){var d=3*e(2,3)(b),f=e(1,3)(a)/d,g=-e(2,3)(a)/d,h=f*e(3,1)(c)+g*(e(3,0)(c)+e(2,1)(c))+e(2,0)(c),i=f*e(3,0)(c)+g*e(2,0)(c)+e(1,0)(c);return i/(i-h)}},getCurveDivider:function(a,c,d,e){return function(f){var g=b(a,c).pointAt(f),h=b(c,d).pointAt(f),i=b(d,e).pointAt(f),j=b(g,h).pointAt(f),k=b(h,i).pointAt(f),l=b(j,k).pointAt(f);return[{p0:a,p1:g,p2:j,p3:l},{p0:l,p1:k,p2:i,p3:e}]}}},w={linear:function(a,b,c){var d=a[1]-a[0],e=b[1]-b[0];return(c-a[0])/d*e+b[0]||0}};return{toDeg:r,toRad:s,snapToGrid:t,normalizeAngle:u,point:a,line:b,rect:c,ellipse:d,bezier:v,scale:w}}();
|
var V,Vectorizer;V=Vectorizer=function(){"use strict";var a="object"==typeof window&&!(!window.SVGAngle&&!document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure","1.1"));if(!a)return function(){throw new Error("SVG is required to use Vectorizer.")};var b={xmlns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink"},c="1.1",d=function(a,c,e){if(!(this instanceof d))return d.apply(Object.create(d.prototype),arguments);if(a){if(d.isV(a)&&(a=a.node),c=c||{},d.isString(a))if("svg"===a.toLowerCase())a=d.createSvgDocument();else if("<"===a[0]){var f=d.createSvgDocument(a);if(f.childNodes.length>1){var g,h,i=[];for(g=0,h=f.childNodes.length;h>g;g++){var j=f.childNodes[g];i.push(new d(document.importNode(j,!0)))}return i}a=document.importNode(f.firstChild,!0)}else a=document.createElementNS(b.xmlns,a);return this.node=a,this.node.id||(this.node.id=d.uniqueId()),this.setAttributes(c),e&&this.append(e),this}};d.prototype.getTransformToElement=function(a){return a.getScreenCTM().inverse().multiply(this.node.getScreenCTM())},d.prototype.transform=function(a){if(d.isUndefined(a))return this.node.parentNode?this.getTransformToElement(this.node.parentNode):this.node.getScreenCTM();var b=d.createSVGTransform(a);return this.node.transform.baseVal.appendItem(b),this},d.prototype.translate=function(a,b,c){c=c||{},b=b||0;var e=this.attr("transform")||"",f=d.parseTransformString(e);if(d.isUndefined(a))return f.translate;e=e.replace(/translate\([^\)]*\)/g,"").trim();var g=c.absolute?a:f.translate.tx+a,h=c.absolute?b:f.translate.ty+b,i="translate("+g+","+h+")";return this.attr("transform",(i+" "+e).trim()),this},d.prototype.rotate=function(a,b,c,e){e=e||{};var f=this.attr("transform")||"",g=d.parseTransformString(f);if(d.isUndefined(a))return g.rotate;f=f.replace(/rotate\([^\)]*\)/g,"").trim(),a%=360;var h=e.absolute?a:g.rotate.angle+a,i=void 0!==b&&void 0!==c?","+b+","+c:"",j="rotate("+h+i+")";return this.attr("transform",(f+" "+j).trim()),this},d.prototype.scale=function(a,b){b=d.isUndefined(b)?a:b;var c=this.attr("transform")||"",e=d.parseTransformString(c);if(d.isUndefined(a))return e.scale;c=c.replace(/scale\([^\)]*\)/g,"").trim();var f="scale("+a+","+b+")";return this.attr("transform",(c+" "+f).trim()),this},d.prototype.bbox=function(a,b){if(!this.node.ownerSVGElement)return{x:0,y:0,width:0,height:0};var c;try{c=this.node.getBBox(),c={x:c.x,y:c.y,width:c.width,height:c.height}}catch(e){c={x:this.node.clientLeft,y:this.node.clientTop,width:this.node.clientWidth,height:this.node.clientHeight}}if(a)return c;var f=this.getTransformToElement(b||this.node.ownerSVGElement);return d.transformRect(c,f)},d.prototype.text=function(a,b){a=d.sanitizeText(a),b=b||{};var c,e=a.split("\n"),f=0,g=this.attr("y");g||this.attr("y","0.8em"),this.attr("display",a?null:"none"),this.node.setAttributeNS("http://www.w3.org/XML/1998/namespace","xml:space","preserve"),this.node.textContent="";var h=this.node;if(b.textPath){var i=this.find("defs");0===i.length&&(i=d("defs"),this.append(i));var j=Object(b.textPath)===b.textPath?b.textPath.d:b.textPath;if(j){var k=d("path",{d:j});i.append(k)}var l=d("textPath");!b.textPath["xlink:href"]&&k&&l.attr("xlink:href","#"+k.node.id),Object(b.textPath)===b.textPath&&l.attr(b.textPath),this.append(l),h=l.node}for(var m=0,f=0;f<e.length;f++){var n=e[f],o=b.lineHeight||"1em";"auto"===b.lineHeight&&(o="1.5em");var p=d("tspan",{dy:0==f?"0em":o,x:this.attr("x")||0});if(p.addClass("v-line"),n)if(b.annotations){for(var q=0,r=d.annotateString(e[f],d.isArray(b.annotations)?b.annotations:[b.annotations],{offset:-m,includeAnnotationIndices:b.includeAnnotationIndices}),s=0;s<r.length;s++){var t=r[s];if(d.isObject(t)){var u=parseInt(t.attrs["font-size"],10);u&&u>q&&(q=u),c=d("tspan",t.attrs),b.includeAnnotationIndices&&c.attr("annotations",t.annotations),t.attrs["class"]&&c.addClass(t.attrs["class"]),c.node.textContent=t.t}else c=document.createTextNode(t||" ");p.append(c)}"auto"===b.lineHeight&&q&&0!==f&&p.attr("dy",1.2*q+"px")}else p.node.textContent=n;else p.addClass("v-empty-line"),p.node.style.opacity=0,p.node.textContent="-";d(h).append(p),m+=n.length+1}return this},d.prototype.attr=function(a,b){if(d.isUndefined(a)){for(var c=this.node.attributes,e={},f=0;f<c.length;f++)e[c[f].nodeName]=c[f].nodeValue;return e}if(d.isString(a)&&d.isUndefined(b))return this.node.getAttribute(a);if("object"==typeof a)for(var g in a)a.hasOwnProperty(g)&&d.setAttribute(this.node,g,a[g]);else d.setAttribute(this.node,a,b);return this},d.prototype.remove=function(){return this.node.parentNode&&this.node.parentNode.removeChild(this.node),this},d.prototype.empty=function(){for(;this.node.firstChild;)this.node.removeChild(this.node.firstChild);return this},d.prototype.setAttributes=function(a){var b;for(b in a)d.setAttribute(this.node,b,a[b]);return this},d.prototype.append=function(a){d.isArray(a)||(a=[a]);var b,c,e;for(b=0,c=a.length;c>b;b++)e=a[b],this.node.appendChild(d.isV(e)?e.node:e.nodeName&&e||e[0]);return this},d.prototype.prepend=function(a){return this.node.insertBefore(d.isV(a)?a.node:a,this.node.firstChild),this},d.prototype.svg=function(){return this.node instanceof window.SVGSVGElement?this:d(this.node.ownerSVGElement)},d.prototype.defs=function(){var a=this.svg().node.getElementsByTagName("defs");return a&&a.length?d(a[0]):void 0},d.prototype.clone=function(){var a=d(this.node.cloneNode(!0));return a.node.id=d.uniqueId(),a},d.prototype.findOne=function(a){var b=this.node.querySelector(a);return b?d(b):void 0},d.prototype.find=function(a){var b=[],c=this.node.querySelectorAll(a);if(c)for(var e=0;e<c.length;e++)b.push(d(c[e]));return b},d.prototype.index=function(){for(var a=0,b=this.node.previousSibling;b;)1===b.nodeType&&a++,b=b.previousSibling;return a},d.prototype.findParentByClass=function(a,b){for(var c=this.node.ownerSVGElement,e=this.node.parentNode;e&&e!==b&&e!==c;){var f=d(e);if(f.hasClass(a))return f;e=e.parentNode}return null},d.prototype.toLocalPoint=function(a,b){var c=this.svg().node,d=c.createSVGPoint();d.x=a,d.y=b;try{var e=d.matrixTransform(c.getScreenCTM().inverse()),f=this.getTransformToElement(c).inverse()}catch(g){return d}return e.matrixTransform(f)},d.prototype.translateCenterToPoint=function(a){var b=this.bbox(),c=g.rect(b).center();this.translate(a.x-c.x,a.y-c.y)},d.prototype.translateAndAutoOrient=function(a,b,c){var e=this.scale();this.attr("transform",""),this.scale(e.sx,e.sy);var f=this.svg().node,h=this.bbox(!1,c),i=f.createSVGTransform();i.setTranslate(-h.x-h.width/2,-h.y-h.height/2);var j=f.createSVGTransform(),k=g.point(a).changeInAngle(a.x-b.x,a.y-b.y,b);j.setRotate(k,0,0);var l=f.createSVGTransform(),m=g.point(a).move(b,h.width/2);l.setTranslate(a.x+(a.x-m.x),a.y+(a.y-m.y));var n=this.getTransformToElement(c),o=f.createSVGTransform();o.setMatrix(l.matrix.multiply(j.matrix.multiply(i.matrix.multiply(n))));var p=d.decomposeMatrix(o.matrix);return this.translate(p.translateX,p.translateY),this.rotate(p.rotation),this},d.prototype.animateAlongPath=function(a,b){var c=d("animateMotion",a),e=d("mpath",{"xlink:href":"#"+d(b).node.id});c.append(e),this.append(c);try{c.node.beginElement()}catch(f){if("fake"===document.documentElement.getAttribute("smiling")){var g=c.node;g.animators=[];var h=g.getAttribute("id");h&&(id2anim[h]=g);for(var i=getTargets(g),j=0,k=i.length;k>j;j++){var l=i[j],m=new Animator(g,l,j);animators.push(m),g.animators[j]=m,m.register()}}}},d.prototype.hasClass=function(a){return new RegExp("(\\s|^)"+a+"(\\s|$)").test(this.node.getAttribute("class"))},d.prototype.addClass=function(a){if(!this.hasClass(a)){var b=this.node.getAttribute("class")||"";this.node.setAttribute("class",(b+" "+a).trim())}return this},d.prototype.removeClass=function(a){if(this.hasClass(a)){var b=this.node.getAttribute("class").replace(new RegExp("(\\s|^)"+a+"(\\s|$)","g"),"$2");this.node.setAttribute("class",b)}return this},d.prototype.toggleClass=function(a,b){var c=d.isUndefined(b)?this.hasClass(a):!b;return c?this.removeClass(a):this.addClass(a),this},d.prototype.sample=function(a){a=a||1;for(var b,c=this.node,d=c.getTotalLength(),e=[],f=0;d>f;)b=c.getPointAtLength(f),e.push({x:b.x,y:b.y,distance:f}),f+=a;return e},d.prototype.convertToPath=function(){var a=d("path");a.attr(this.attr());var b=this.convertToPathData();return b&&a.attr("d",b),a},d.prototype.convertToPathData=function(){var a=this.node.tagName.toUpperCase();switch(a){case"PATH":return this.attr("d");case"LINE":return d.convertLineToPathData(this.node);case"POLYGON":return d.convertPolygonToPathData(this.node);case"POLYLINE":return d.convertPolylineToPathData(this.node);case"ELLIPSE":return d.convertEllipseToPathData(this.node);case"CIRCLE":return d.convertCircleToPathData(this.node);case"RECT":return d.convertRectToPathData(this.node)}throw new Error(a+" cannot be converted to PATH.")},d.prototype.findIntersection=function(a,b){var c=this.svg().node;b=b||c;var e=g.rect(this.bbox(!1,b)),f=e.center();if(e.intersectionWithLineFromCenterToPoint(a)){var h,i=this.node.localName.toUpperCase();if("RECT"===i){var j=g.rect(parseFloat(this.attr("x")||0),parseFloat(this.attr("y")||0),parseFloat(this.attr("width")),parseFloat(this.attr("height"))),k=this.getTransformToElement(b),l=d.decomposeMatrix(k),m=c.createSVGTransform();m.setRotate(-l.rotation,f.x,f.y);var n=d.transformRect(j,m.matrix.multiply(k));h=g.rect(n).intersectionWithLineFromCenterToPoint(a,l.rotation)}else if("PATH"===i||"POLYGON"===i||"POLYLINE"===i||"CIRCLE"===i||"ELLIPSE"===i){var o,p,q,r,s,t,u="PATH"===i?this:this.convertToPath(),v=u.sample(),w=1/0,x=[];for(o=0;o<v.length;o++)p=v[o],q=d.createSVGPoint(p.x,p.y),q=q.matrixTransform(this.getTransformToElement(b)),p=g.point(q),r=p.distance(f),s=1.1*p.distance(a),t=r+s,w>t?(w=t,x=[{sample:p,refDistance:s}]):w+1>t&&x.push({sample:p,refDistance:s});x.sort(function(a,b){return a.refDistance-b.refDistance}),x[0]&&(h=x[0].sample)}return h}},d.createSvgDocument=function(a){var e='<svg xmlns="'+b.xmlns+'" xmlns:xlink="'+b.xlink+'" version="'+c+'">'+(a||"")+"</svg>",f=d.parseXML(e,{async:!1});return f.documentElement},d.idCounter=0,d.uniqueId=function(){var a=++d.idCounter+"";return"v-"+a},d.sanitizeText=function(a){return(a||"").replace(/ /g," ")},d.isUndefined=function(a){return"undefined"==typeof a},d.isString=function(a){return"string"==typeof a},d.isObject=function(a){return a&&"object"==typeof a},d.isArray=Array.isArray,d.parseXML=function(a,b){b=b||{};var c;try{var e=new DOMParser;d.isUndefined(b.async)||(e.async=b.async),c=e.parseFromString(a,"text/xml")}catch(f){c=void 0}if(!c||c.getElementsByTagName("parsererror").length)throw new Error("Invalid XML: "+a);return c},d.setAttribute=function(a,c,d){if(c.indexOf(":")>-1){var e=c.split(":");a.setAttributeNS(b[e[0]],e[1],d)}else"id"===c?a.id=d:a.setAttribute(c,d)},d.parseTransformString=function(a){var b,c,d;if(a){var e=/[ ,]+/,f=a.match(/translate\((.*)\)/);f&&(b=f[1].split(e));var g=a.match(/rotate\((.*)\)/);g&&(c=g[1].split(e));var h=a.match(/scale\((.*)\)/);h&&(d=h[1].split(e))}var i=d&&d[0]?parseFloat(d[0]):1;return{translate:{tx:b&&b[0]?parseInt(b[0],10):0,ty:b&&b[1]?parseInt(b[1],10):0},rotate:{angle:c&&c[0]?parseInt(c[0],10):0,cx:c&&c[1]?parseInt(c[1],10):void 0,cy:c&&c[2]?parseInt(c[2],10):void 0},scale:{sx:i,sy:d&&d[1]?parseFloat(d[1]):i}}},d.deltaTransformPoint=function(a,b){var c=b.x*a.a+b.y*a.c+0,d=b.x*a.b+b.y*a.d+0;return{x:c,y:d}},d.decomposeMatrix=function(a){var b=d.deltaTransformPoint(a,{x:0,y:1}),c=d.deltaTransformPoint(a,{x:1,y:0}),e=180/Math.PI*Math.atan2(b.y,b.x)-90,f=180/Math.PI*Math.atan2(c.y,c.x);return{translateX:a.e,translateY:a.f,scaleX:Math.sqrt(a.a*a.a+a.b*a.b),scaleY:Math.sqrt(a.c*a.c+a.d*a.d),skewX:e,skewY:f,rotation:e}},d.isV=function(a){return a instanceof d},d.isVElement=d.isV;var e=d("svg").node;return d.createSVGMatrix=function(a){var b=e.createSVGMatrix();for(var c in a)b[c]=a[c];return b},d.createSVGTransform=function(a){return d.isUndefined(a)?e.createSVGTransform():(a instanceof SVGMatrix||(a=d.createSVGMatrix(a)),e.createSVGTransformFromMatrix(a))},d.createSVGPoint=function(a,b){var c=e.createSVGPoint();return c.x=a,c.y=b,c},d.transformRect=function(a,b){var c=e.createSVGPoint();c.x=a.x,c.y=a.y;var d=c.matrixTransform(b);c.x=a.x+a.width,c.y=a.y;var f=c.matrixTransform(b);c.x=a.x+a.width,c.y=a.y+a.height;var g=c.matrixTransform(b);c.x=a.x,c.y=a.y+a.height;var h=c.matrixTransform(b),i=Math.min(d.x,f.x,g.x,h.x),j=Math.max(d.x,f.x,g.x,h.x),k=Math.min(d.y,f.y,g.y,h.y),l=Math.max(d.y,f.y,g.y,h.y);return{x:i,y:k,width:j-i,height:l-k}},d.transformPoint=function(a,b){return d.createSVGPoint(a.x,a.y).matrixTransform(b)},d.styleToObject=function(a){for(var b={},c=a.split(";"),d=0;d<c.length;d++){var e=c[d],f=e.split("=");b[f[0].trim()]=f[1].trim()}return b},d.createSlicePathData=function(a,b,c,d){var e=2*Math.PI-1e-6,f=a,g=b,h=c,i=d,j=(h>i&&(j=h,h=i,i=j),i-h),k=j<Math.PI?"0":"1",l=Math.cos(h),m=Math.sin(h),n=Math.cos(i),o=Math.sin(i);return j>=e?f?"M0,"+g+"A"+g+","+g+" 0 1,1 0,"+-g+"A"+g+","+g+" 0 1,1 0,"+g+"M0,"+f+"A"+f+","+f+" 0 1,0 0,"+-f+"A"+f+","+f+" 0 1,0 0,"+f+"Z":"M0,"+g+"A"+g+","+g+" 0 1,1 0,"+-g+"A"+g+","+g+" 0 1,1 0,"+g+"Z":f?"M"+g*l+","+g*m+"A"+g+","+g+" 0 "+k+",1 "+g*n+","+g*o+"L"+f*n+","+f*o+"A"+f+","+f+" 0 "+k+",0 "+f*l+","+f*m+"Z":"M"+g*l+","+g*m+"A"+g+","+g+" 0 "+k+",1 "+g*n+","+g*o+"L0,0Z"},d.mergeAttrs=function(a,b){for(var c in b)"class"===c?a[c]=a[c]?a[c]+" "+b[c]:b[c]:"style"===c?d.isObject(a[c])&&d.isObject(b[c])?a[c]=d.mergeAttrs(a[c],b[c]):d.isObject(a[c])?a[c]=d.mergeAttrs(a[c],d.styleToObject(b[c])):d.isObject(b[c])?a[c]=d.mergeAttrs(d.styleToObject(a[c]),b[c]):a[c]=d.mergeAttrs(d.styleToObject(a[c]),d.styleToObject(b[c])):a[c]=b[c];return a},d.annotateString=function(a,b,c){b=b||[],c=c||{};for(var e,f,g,h=c.offset||0,i=[],j=[],k=0;k<a.length;k++){f=j[k]=a[k];for(var l=0;l<b.length;l++){var m=b[l],n=m.start+h,o=m.end+h;k>=n&&o>k&&(d.isObject(f)?f.attrs=d.mergeAttrs(d.mergeAttrs({},f.attrs),m.attrs):f=j[k]={t:a[k],attrs:m.attrs},c.includeAnnotationIndices&&(f.annotations||(f.annotations=[])).push(l))}g=j[k-1],g?d.isObject(f)&&d.isObject(g)?JSON.stringify(f.attrs)===JSON.stringify(g.attrs)?e.t+=f.t:(i.push(e),e=f):d.isObject(f)?(i.push(e),e=f):d.isObject(g)?(i.push(e),e=f):e=(e||"")+f:e=f}return e&&i.push(e),i},d.findAnnotationsAtIndex=function(a,b){var c=[];return a&&a.forEach(function(a){a.start<b&&b<=a.end&&c.push(a)}),c},d.findAnnotationsBetweenIndexes=function(a,b,c){var d=[];return a&&a.forEach(function(a){(b>=a.start&&b<a.end||c>a.start&&c<=a.end||a.start>=b&&a.end<c)&&d.push(a)}),d},d.shiftAnnotations=function(a,b,c){return a&&a.forEach(function(a){a.start<b&&a.end>=b?a.end+=c:a.start>=b&&(a.start+=c,a.end+=c)}),a},d.convertLineToPathData=function(a){a=d(a);var b=["M",a.attr("x1"),a.attr("y1"),"L",a.attr("x2"),a.attr("y2")].join(" ");return b},d.convertPolygonToPathData=function(a){a=d(a);var b=d.getPointsFromSvgNode(a.node);return b.length>0?d.svgPointsToPath(b):null},d.convertPolylineToPathData=function(a){var b=d.getPointsFromSvgNode(a.node);return b.length>0?d.svgPointsToPath(b):null},d.svgPointsToPath=function(a){var b;for(b=0;b<a.length;b++)a[b]=a[b].x+" "+a[b].y;return"M "+a.join(" L")+" Z"},d.getPointsFromSvgNode=function(a){var b,c=[];for(b=0;b<a.points.numberOfItems;b++)c.push(a.points.getItem(b));return c},d.KAPPA=.5522847498307935,d.convertCircleToPathData=function(a){a=d(a);var b=parseFloat(a.attr("cx"))||0,c=parseFloat(a.attr("cy"))||0,e=parseFloat(a.attr("r")),f=e*d.KAPPA,g=["M",b,c-e,"C",b+f,c-e,b+e,c-f,b+e,c,"C",b+e,c+f,b+f,c+e,b,c+e,"C",b-f,c+e,b-e,c+f,b-e,c,"C",b-e,c-f,b-f,c-e,b,c-e,"Z"].join(" ");return g},d.convertEllipseToPathData=function(a){a=d(a);var b=parseFloat(a.attr("cx"))||0,c=parseFloat(a.attr("cy"))||0,e=parseFloat(a.attr("rx")),f=parseFloat(a.attr("ry"))||e,g=e*d.KAPPA,h=f*d.KAPPA,i=["M",b,c-f,"C",b+g,c-f,b+e,c-h,b+e,c,"C",b+e,c+h,b+g,c+f,b,c+f,"C",b-g,c+f,b-e,c+h,b-e,c,"C",b-e,c-h,b-g,c-f,b,c-f,"Z"].join(" ");return i},d.convertRectToPathData=function(a){a=d(a);var b,c=parseFloat(a.attr("x"))||0,e=parseFloat(a.attr("y"))||0,f=parseFloat(a.attr("width"))||0,h=parseFloat(a.attr("height"))||0,i=parseFloat(a.attr("rx"))||0,j=parseFloat(a.attr("ry"))||0,k=g.rect(c,e,f,h);if(i||j){var l=c+f,m=e+h;b=["M",c+i,e,"L",l-i,e,"Q",l,e,l,e+j,"L",l,e+h-j,"Q",l,m,l-i,m,"L",c+i,m,"Q",c,m,c,m-i,"L",c,e+j,"Q",c,e,c+i,e,"Z"].join(" ")}else b=["M",k.origin().x,k.origin().y,"H",k.corner().x,"V",k.corner().y,"H",k.origin().x,"V",k.origin().y,"Z"].join(" ");return b},d.rectToPath=function(a){var b=a.rx||a["top-rx"]||0,c=a.rx||a["bottom-rx"]||0,d=a.ry||a["top-ry"]||0,e=a.ry||a["bottom-ry"]||0;return["M",a.x,a.y+d,"v",a.height-d-e,"a",c,e,0,0,0,c,e,"h",a.width-2*c,"a",c,e,0,0,0,c,-e,"v",-(a.height-e-d),"a",b,d,0,0,0,-b,-d,"h",-(a.width-2*b),"a",b,d,0,0,0,-b,d].join(" ")},d}();
|
var joint={version:"0.9.7",dia:{},ui:{},layout:{},shapes:{},format:{},connectors:{},highlighters:{},routers:{},mvc:{views:{}},setTheme:function(a,b){b=b||{},_.invoke(joint.mvc.views,"setTheme",a,b),joint.mvc.View.prototype.options.theme=a},env:{_results:{},_tests:{svgforeignobject:function(){return!!document.createElementNS&&/SVGForeignObject/.test({}.toString.call(document.createElementNS("http://www.w3.org/2000/svg","foreignObject")))}},addTest:function(a,b){return joint.env._tests[a]=b},test:function(a){var b=joint.env._tests[a];if(!b)throw new Error('Test not defined ("'+a+'"). Use `joint.env.addTest(name, fn) to add a new test.`');var c=joint.env._results[a];if("undefined"!=typeof c)return c;try{c=b()}catch(d){c=!1}return joint.env._results[a]=c,c}},util:{hashCode:function(a){var b=0;if(0==a.length)return b;for(var c=0;c<a.length;c++){var d=a.charCodeAt(c);b=(b<<5)-b+d,b&=b}return b},getByPath:function(a,b,c){c=c||"/";for(var d,e=b.split(c);e.length;){if(d=e.shift(),!(Object(a)===a&&d in a))return;a=a[d]}return a},setByPath:function(a,b,c,d){d=d||"/";var e=b.split(d),f=a,g=0;if(b.indexOf(d)>-1){for(var h=e.length;h-1>g;g++)f=f[e[g]]||(f[e[g]]={});f[e[h-1]]=c}else a[b]=c;return a},unsetByPath:function(a,b,c){c=c||"/";var d=b.lastIndexOf(c);if(d>-1){var e=joint.util.getByPath(a,b.substr(0,d),c);e&&delete e[b.slice(d+1)]}else delete a[b];return a},flattenObject:function(a,b,c){b=b||"/";var d={};for(var e in a)if(a.hasOwnProperty(e)){var f="object"==typeof a[e];if(f&&c&&c(a[e])&&(f=!1),f){var g=this.flattenObject(a[e],b,c);for(var h in g)g.hasOwnProperty(h)&&(d[e+b+h]=g[h])}else d[e]=a[e]}return d},uuid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"==a?b:3&b|8;return c.toString(16)})},guid:function(a){return this.guid.id=this.guid.id||1,a.id=void 0===a.id?"j_"+this.guid.id++:a.id,a.id},mixin:function(){for(var a=arguments[0],b=1,c=arguments.length;c>b;b++){var d=arguments[b];(Object(d)===d||_.isFunction(d)||null!==d&&void 0!==d)&&_.each(d,function(b,c){return this.mixin.deep&&Object(b)===b?(a[c]||(a[c]=_.isArray(b)?[]:{}),void this.mixin(a[c],b)):void(a[c]!==b&&(this.mixin.supplement&&a.hasOwnProperty(c)||(a[c]=b)))},this)}return a},supplement:function(){this.mixin.supplement=!0;var a=this.mixin.apply(this,arguments);return this.mixin.supplement=!1,a},deepMixin:function(){this.mixin.deep=!0;var a=this.mixin.apply(this,arguments);return this.mixin.deep=!1,a},deepSupplement:function(){this.mixin.deep=this.mixin.supplement=!0;var a=this.mixin.apply(this,arguments);return this.mixin.deep=this.mixin.supplement=!1,a},normalizeEvent:function(a){var b=a.originalEvent&&a.originalEvent.changedTouches&&a.originalEvent.changedTouches[0];if(b){for(var c in a)void 0===b[c]&&(b[c]=a[c]);return b}return a},nextFrame:function(){var a;if("undefined"!=typeof window&&(a=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame),!a){var b=0;a=function(a){var c=(new Date).getTime(),d=Math.max(0,16-(c-b)),e=setTimeout(function(){a(c+d)},d);return b=c+d,e}}return function(b,c){return a(c?_.bind(b,c):b)}}(),cancelFrame:function(){var a,b="undefined"!=typeof window;return b&&(a=window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.webkitCancelRequestAnimationFrame||window.msCancelAnimationFrame||window.msCancelRequestAnimationFrame||window.oCancelAnimationFrame||window.oCancelRequestAnimationFrame||window.mozCancelAnimationFrame||window.mozCancelRequestAnimationFrame),a=a||clearTimeout,b?_.bind(a,window):a}(),shapePerimeterConnectionPoint:function(a,b,c,d){var e,f;if(!c){var h=b.$(".scalable")[0],i=b.$(".rotatable")[0];h&&h.firstChild?c=h.firstChild:i&&i.firstChild&&(c=i.firstChild)}return c?(f=V(c).findIntersection(d,a.paper.viewport),f||(e=g.rect(V(c).bbox(!1,a.paper.viewport)))):(e=b.model.getBBox(),f=e.intersectionWithLineFromCenterToPoint(d)),f||e.center()},breakText:function(a,b,c,d){d=d||{};var e=b.width,f=b.height,g=d.svgDocument||V("svg").node,h=V("<text><tspan></tspan></text>").attr(c||{}).node,i=h.firstChild,j=document.createTextNode("");h.style.opacity=0,h.style.display="block",i.style.display="block",i.appendChild(j),g.appendChild(h),d.svgDocument||document.body.appendChild(g);for(var k,l=a.split(" "),m=[],n=[],o=0,p=0,q=l.length;q>o;o++){var r=l[o];if(j.data=n[p]?n[p]+" "+r:r,i.getComputedTextLength()<=e)n[p]=j.data,k&&(m[p++]=!0,k=0);else{if(!n[p]||k){var s=!!k;if(k=r.length-1,s||!k){if(!k){if(!n[p]){n=[];break}l.splice(o,2,r+l[o+1]),q--,m[p++]=!0,o--;continue}l[o]=r.substring(0,k),l[o+1]=r.substring(k)+l[o+1]}else l.splice(o,1,r.substring(0,k),r.substring(k)),q++,p&&!m[p-1]&&p--;o--;continue}p++,o--}if("undefined"!=typeof f){var t=t||1.25*h.getBBox().height;if(t*n.length>f){n.splice(Math.floor(f/t));break}}}return d.svgDocument?g.removeChild(h):document.body.removeChild(g),n.join("\n")},imageToDataUri:function(a,b){if(!a||"data:"===a.substr(0,"data:".length))return setTimeout(function(){b(null,a)},0);var c=document.createElement("canvas"),d=document.createElement("img");d.onload=function(){var e=c.getContext("2d");c.width=d.width,c.height=d.height,e.drawImage(d,0,0);try{var f=(a.split(".").pop()||"png","jpeg"),g=c.toDataURL(f)}catch(h){if(/\.svg$/.test(a)){var i=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");i.open("GET",a,!1),i.send(null);var j=i.responseText;return b(null,"data:image/svg+xml,"+encodeURIComponent(j))}console.error(d.src,"fails to convert",h)}b(null,g)},d.ononerror=function(){b(new Error("Failed to load image."))},d.src=a},getElementBBox:function(a){var b,c=$(a),d=c.offset();if(a.ownerSVGElement){b=V(a).bbox();var e=a.getBoundingClientRect(),f=(e.width-b.width)/2,g=(e.height-b.height)/2;b.x=d.left+f,b.y=d.top+g}else b={x:d.left,y:d.top,width:c.outerWidth(),height:c.outerHeight()};return b},sortElements:function(a,b){var c=$(a),d=c.map(function(){var a=this,b=a.parentNode,c=b.insertBefore(document.createTextNode(""),a.nextSibling);return function(){if(b===this)throw new Error("You can't sort elements if any one is a descendant of another.");b.insertBefore(this,c),b.removeChild(c)}});return Array.prototype.sort.call(c,b).each(function(a){d[a].call(this)})},setAttributesBySelector:function(a,b){var c=$(a);_.each(b,function(a,b){var d=c.find(b).addBack().filter(b);_.has(a,"class")&&(d.addClass(a["class"]),a=_.omit(a,"class")),d.attr(a)})},normalizeSides:function(a){return Object(a)!==a?(a=a||0,{top:a,bottom:a,left:a,right:a}):{top:a.top||0,bottom:a.bottom||0,left:a.left||0,right:a.right||0}},timing:{linear:function(a){return a},quad:function(a){return a*a},cubic:function(a){return a*a*a},inout:function(a){if(0>=a)return 0;if(a>=1)return 1;var b=a*a,c=b*a;return 4*(.5>a?c:3*(a-b)+c-.75)},exponential:function(a){return Math.pow(2,10*(a-1))},bounce:function(a){for(var b=0,c=1;1;b+=c,c/=2)if(a>=(7-4*b)/11){var d=(11-6*b-11*a)/4;return-d*d+c*c}},reverse:function(a){return function(b){return 1-a(1-b)}},reflect:function(a){return function(b){return.5*(.5>b?a(2*b):2-a(2-2*b))}},clamp:function(a,b,c){return b=b||0,c=c||1,function(d){var e=a(d);return b>e?b:e>c?c:e}},back:function(a){return a||(a=1.70158),function(b){return b*b*((a+1)*b-a)}},elastic:function(a){return a||(a=1.5),function(b){return Math.pow(2,10*(b-1))*Math.cos(20*Math.PI*a/3*b)}}},interpolate:{number:function(a,b){var c=b-a;return function(b){return a+c*b}},object:function(a,b){var c=_.keys(a);return function(d){var e,f,g={};for(e=c.length-1;-1!=e;e--)f=c[e],g[f]=a[f]+(b[f]-a[f])*d;return g}},hexColor:function(a,b){var c=parseInt(a.slice(1),16),d=parseInt(b.slice(1),16),e=255&c,f=(255&d)-e,g=65280&c,h=(65280&d)-g,i=16711680&c,j=(16711680&d)-i;return function(a){var b=e+f*a&255,c=g+h*a&65280,d=i+j*a&16711680;return"#"+(1<<24|b|c|d).toString(16).slice(1)}},unit:function(a,b){var c=/(-?[0-9]*.[0-9]*)(px|em|cm|mm|in|pt|pc|%)/,d=c.exec(a),e=c.exec(b),f=e[1].indexOf("."),g=f>0?e[1].length-f-1:0;a=+d[1];var h=+e[1]-a,i=d[2];return function(b){return(a+h*b).toFixed(g)+i}}},filter:{outline:function(a){var b='<filter><feFlood flood-color="${color}" flood-opacity="${opacity}" result="colored"/><feMorphology in="SourceAlpha" result="morphedOuter" operator="dilate" radius="${outerRadius}" /><feMorphology in="SourceAlpha" result="morphedInner" operator="dilate" radius="${innerRadius}" /><feComposite result="morphedOuterColored" in="colored" in2="morphedOuter" operator="in"/><feComposite operator="xor" in="morphedOuterColored" in2="morphedInner" result="outline"/><feMerge><feMergeNode in="outline"/><feMergeNode in="SourceGraphic"/></feMerge></filter>',c=_.isFinite(a.margin)?a.margin:2,d=_.isFinite(a.width)?a.width:1;return joint.util.template(b)({color:a.color||"blue",opacity:_.isFinite(a.opacity)?a.opacity:1,outerRadius:c+d,innerRadius:c})},highlight:function(a){var b='<filter><feFlood flood-color="${color}" flood-opacity="${opacity}" result="colored"/><feMorphology result="morphed" in="SourceGraphic" operator="dilate" radius="${width}"/><feComposite result="composed" in="colored" in2="morphed" operator="in"/><feGaussianBlur result="blured" in="composed" stdDeviation="${blur}"/><feBlend in="SourceGraphic" in2="blured" mode="normal"/></filter>';return joint.util.template(b)({color:a.color||"red",width:_.isFinite(a.width)?a.width:1,blur:_.isFinite(a.blur)?a.blur:0,opacity:_.isFinite(a.opacity)?a.opacity:1})},blur:function(a){var b=_.isFinite(a.x)?a.x:2;return joint.util.template('<filter><feGaussianBlur stdDeviation="${stdDeviation}"/></filter>')({stdDeviation:_.isFinite(a.y)?[b,a.y]:b})},dropShadow:function(a){var b="SVGFEDropShadowElement"in window?'<filter><feDropShadow stdDeviation="${blur}" dx="${dx}" dy="${dy}" flood-color="${color}" flood-opacity="${opacity}"/></filter>':'<filter><feGaussianBlur in="SourceAlpha" stdDeviation="${blur}"/><feOffset dx="${dx}" dy="${dy}" result="offsetblur"/><feFlood flood-color="${color}"/><feComposite in2="offsetblur" operator="in"/><feComponentTransfer><feFuncA type="linear" slope="${opacity}"/></feComponentTransfer><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge></filter>';return joint.util.template(b)({dx:a.dx||0,dy:a.dy||0,opacity:_.isFinite(a.opacity)?a.opacity:1,color:a.color||"black",blur:_.isFinite(a.blur)?a.blur:4})},grayscale:function(a){var b=_.isFinite(a.amount)?a.amount:1;return joint.util.template('<filter><feColorMatrix type="matrix" values="${a} ${b} ${c} 0 0 ${d} ${e} ${f} 0 0 ${g} ${b} ${h} 0 0 0 0 0 1 0"/></filter>')({a:.2126+.7874*(1-b),b:.7152-.7152*(1-b),c:.0722-.0722*(1-b),d:.2126-.2126*(1-b),e:.7152+.2848*(1-b),f:.0722-.0722*(1-b),g:.2126-.2126*(1-b),h:.0722+.9278*(1-b)})},sepia:function(a){var b=_.isFinite(a.amount)?a.amount:1;return joint.util.template('<filter><feColorMatrix type="matrix" values="${a} ${b} ${c} 0 0 ${d} ${e} ${f} 0 0 ${g} ${h} ${i} 0 0 0 0 0 1 0"/></filter>')({a:.393+.607*(1-b),b:.769-.769*(1-b),c:.189-.189*(1-b),d:.349-.349*(1-b),e:.686+.314*(1-b),f:.168-.168*(1-b),g:.272-.272*(1-b),h:.534-.534*(1-b),i:.131+.869*(1-b)})},saturate:function(a){var b=_.isFinite(a.amount)?a.amount:1;return joint.util.template('<filter><feColorMatrix type="saturate" values="${amount}"/></filter>')({amount:1-b})},hueRotate:function(a){return joint.util.template('<filter><feColorMatrix type="hueRotate" values="${angle}"/></filter>')({angle:a.angle||0})},invert:function(a){var b=_.isFinite(a.amount)?a.amount:1;return joint.util.template('<filter><feComponentTransfer><feFuncR type="table" tableValues="${amount} ${amount2}"/><feFuncG type="table" tableValues="${amount} ${amount2}"/><feFuncB type="table" tableValues="${amount} ${amount2}"/></feComponentTransfer></filter>')({amount:b,amount2:1-b})},brightness:function(a){return joint.util.template('<filter><feComponentTransfer><feFuncR type="linear" slope="${amount}"/><feFuncG type="linear" slope="${amount}"/><feFuncB type="linear" slope="${amount}"/></feComponentTransfer></filter>')({amount:_.isFinite(a.amount)?a.amount:1})},contrast:function(a){var b=_.isFinite(a.amount)?a.amount:1;return joint.util.template('<filter><feComponentTransfer><feFuncR type="linear" slope="${amount}" intercept="${amount2}"/><feFuncG type="linear" slope="${amount}" intercept="${amount2}"/><feFuncB type="linear" slope="${amount}" intercept="${amount2}"/></feComponentTransfer></filter>')({amount:b,amount2:.5-b/2})}},format:{number:function(a,b,c){function d(a){for(var b=a.length,d=[],e=0,f=c.grouping[0];b>0&&f>0;)d.push(a.substring(b-=f,b+f)),f=c.grouping[e=(e+1)%c.grouping.length];return d.reverse().join(c.thousands)}c=c||{currency:["$",""],decimal:".",thousands:",",grouping:[3]};var e=/(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i,f=e.exec(a),g=f[1]||" ",h=f[2]||">",i=f[3]||"",j=f[4]||"",k=f[5],l=+f[6],m=f[7],n=f[8],o=f[9],p=1,q="",r="",s=!1;switch(n&&(n=+n.substring(1)),(k||"0"===g&&"="===h)&&(k=g="0",h="=",m&&(l-=Math.floor((l-1)/4))),o){case"n":m=!0,o="g";break;case"%":p=100,r="%",o="f";break;case"p":p=100,r="%",o="r";break;case"b":case"o":case"x":case"X":"#"===j&&(q="0"+o.toLowerCase());case"c":case"d":s=!0,n=0;break;case"s":p=-1,o="r"}"$"===j&&(q=c.currency[0],r=c.currency[1]),"r"!=o||n||(o="g"),null!=n&&("g"==o?n=Math.max(1,Math.min(21,n)):"e"!=o&&"f"!=o||(n=Math.max(0,Math.min(20,n))));var t=k&&m;if(s&&b%1)return"";var u=0>b||0===b&&0>1/b?(b=-b,"-"):i,v=r;if(0>p){var w=this.prefix(b,n);b=w.scale(b),v=w.symbol+r}else b*=p;b=this.convert(o,b,n);var x=b.lastIndexOf("."),y=0>x?b:b.substring(0,x),z=0>x?"":c.decimal+b.substring(x+1);!k&&m&&c.grouping&&(y=d(y));var A=q.length+y.length+z.length+(t?0:u.length),B=l>A?new Array(A=l-A+1).join(g):"";return t&&(y=d(B+y)),u+=q,b=y+z,("<"===h?u+b+B:">"===h?B+u+b:"^"===h?B.substring(0,A>>=1)+u+b+B.substring(A):u+(t?b:B+b))+v},string:function(a,b){for(var c,d="{",e=!1,f=[];-1!==(c=a.indexOf(d));){var g,h,i;if(g=a.slice(0,c),e){h=g.split(":"),i=h.shift().split("."),g=b;for(var j=0;j<i.length;j++)g=g[i[j]];h.length&&(g=this.number(h,g))}f.push(g),a=a.slice(c+1),d=(e=!e)?"}":"{"}return f.push(a),f.join("")},convert:function(a,b,c){switch(a){case"b":return b.toString(2);case"c":return String.fromCharCode(b);case"o":return b.toString(8);case"x":return b.toString(16);case"X":return b.toString(16).toUpperCase();case"g":return b.toPrecision(c);case"e":return b.toExponential(c);case"f":return b.toFixed(c);case"r":return(b=this.round(b,this.precision(b,c))).toFixed(Math.max(0,Math.min(20,this.precision(b*(1+1e-15),c))));default:return b+""}},round:function(a,b){return b?Math.round(a*(b=Math.pow(10,b)))/b:Math.round(a)},precision:function(a,b){return b-(a?Math.ceil(Math.log(a)/Math.LN10):1)},prefix:function(a,b){var c=_.map(["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"],function(a,b){var c=Math.pow(10,3*Math.abs(8-b));return{scale:b>8?function(a){return a/c}:function(a){return a*c},symbol:a}}),d=0;return a&&(0>a&&(a*=-1),b&&(a=this.round(a,this.precision(a,b))),d=1+Math.floor(1e-12+Math.log(a)/Math.LN10),d=Math.max(-24,Math.min(24,3*Math.floor((0>=d?d+1:d-1)/3)))),c[8+d/3]}},template:function(a){var b=/<%= ([^ ]+) %>|\$\{ ?([^\{\} ]+) ?\}|\{\{([^\{\} ]+)\}\}/g;return function(c){return a.replace(b,function(a){for(var b=Array.prototype.slice.call(arguments),d=_.find(b.slice(1,4),function(a){return!!a}),e=d.split("."),f=c[e.shift()];!_.isUndefined(f)&&e.length;)f=f[e.shift()];return _.isUndefined(f)?"":f})}},toggleFullScreen:function(a){function b(a,b){for(var c=["webkit","moz","ms","o",""],d=0;d<c.length;d++){var e=c[d],f=e?e+b:b.substr(0,1).toLowerCase()+b.substr(1);if(!_.isUndefined(a[f]))return _.isFunction(a[f])?a[f]():a[f]}}a=a||document.body,b(document,"FullScreen")||b(document,"IsFullScreen")?b(document,"CancelFullScreen"):b(a,"RequestFullScreen")},wrapWith:function(a,b,c){if(_.isString(c)){if(!joint.util.wrappers[c])throw new Error('Unknown wrapper: "'+c+'"');c=joint.util.wrappers[c]}if(!_.isFunction(c))throw new Error("Wrapper must be a function.");_.each(b,function(b){a[b]=c(a[b])})},wrappers:{cells:function(a){return function(){var b=Array.prototype.slice.call(arguments),c=b.length>0&&_.first(b)||[],d=b.length>1&&_.last(b)||{};return _.isArray(c)||(d instanceof joint.dia.Cell?(c=b,d={}):c=_.initial(b)),a.call(this,c,d)}}}}};joint.mvc.View=Backbone.View.extend({options:{theme:"default"},theme:null,themeClassNamePrefix:"joint-theme-",requireSetThemeOverride:!1,constructor:function(a){Backbone.View.call(this,a)},initialize:function(a){this.requireSetThemeOverride=a&&!!a.theme,this.options=_.extend({},joint.mvc.View.prototype.options||{},this.options||{},a||{}),_.bindAll(this,"setTheme","onSetTheme","remove","onRemove"),joint.mvc.views[this.cid]=this,this.setTheme(this.options.theme),this._ensureElClassName(),this.init()},_ensureElClassName:function(){var a=_.result(this,"className");this.$el.addClass(a)},init:function(){},setTheme:function(a,b){return b=b||{},this.theme&&this.requireSetThemeOverride&&!b.override?void 0:(this.onSetTheme(this.theme,a),this.theme&&this.$el.removeClass(this.themeClassNamePrefix+this.theme),this.$el.addClass(this.themeClassNamePrefix+a),this.theme=a,this)},onSetTheme:function(a,b){},remove:function(){return this.onRemove(),joint.mvc.views[this.cid]=null,Backbone.View.prototype.remove.apply(this,arguments),this},onRemove:function(){}}),joint.dia.GraphCells=Backbone.Collection.extend({cellNamespace:joint.shapes,initialize:function(a,b){b.cellNamespace&&(this.cellNamespace=b.cellNamespace),this.graph=b.graph},model:function(a,b){var c=b.collection,d=c.cellNamespace,e="link"===a.type?joint.dia.Link:joint.util.getByPath(d,a.type,".")||joint.dia.Element,f=new e(a,b);return f.graph=c.graph,f},comparator:function(a){return a.get("z")||0}}),joint.dia.Graph=Backbone.Model.extend({_batches:{},initialize:function(a,b){b=b||{};var c=new joint.dia.GraphCells([],{model:b.cellModel,cellNamespace:b.cellNamespace,graph:this});Backbone.Model.prototype.set.call(this,"cells",c),c.on("all",this.trigger,this),this.on("change:z",this._sortOnChangeZ,this),this.on("batch:stop",this._onBatchStop,this),this._out={},this._in={},this._nodes={},this._edges={},c.on("add",this._restructureOnAdd,this),c.on("remove",this._restructureOnRemove,this),c.on("reset",this._restructureOnReset,this),c.on("change:source",this._restructureOnChangeSource,this),c.on("change:target",this._restructureOnChangeTarget,this),c.on("remove",this._removeCell,this)},_sortOnChangeZ:function(){this.hasActiveBatch("to-front")||this.hasActiveBatch("to-back")||this.get("cells").sort()},_onBatchStop:function(a){var b=a&&a.batchName;"to-front"!==b&&"to-back"!==b||this.hasActiveBatch(b)||this.get("cells").sort()},_restructureOnAdd:function(a){if(a.isLink()){this._edges[a.id]=!0;var b=a.get("source"),c=a.get("target");b.id&&((this._out[b.id]||(this._out[b.id]={}))[a.id]=!0),c.id&&((this._in[c.id]||(this._in[c.id]={}))[a.id]=!0)}else this._nodes[a.id]=!0},_restructureOnRemove:function(a){if(a.isLink()){delete this._edges[a.id];var b=a.get("source"),c=a.get("target");b.id&&this._out[b.id]&&this._out[b.id][a.id]&&delete this._out[b.id][a.id],c.id&&this._in[c.id]&&this._in[c.id][a.id]&&delete this._in[c.id][a.id]}else delete this._nodes[a.id]},_restructureOnReset:function(a){a=a.models,this._out={},this._in={},this._nodes={},this._edges={},_.each(a,this._restructureOnAdd,this)},_restructureOnChangeSource:function(a){var b=a.previous("source");b.id&&this._out[b.id]&&delete this._out[b.id][a.id];var c=a.get("source");c.id&&((this._out[c.id]||(this._out[c.id]={}))[a.id]=!0)},_restructureOnChangeTarget:function(a){var b=a.previous("target");b.id&&this._in[b.id]&&delete this._in[b.id][a.id];var c=a.get("target");c.id&&((this._in[c.id]||(this._in[c.id]={}))[a.id]=!0)},getOutboundEdges:function(a){return this._out&&this._out[a]||{}},getInboundEdges:function(a){return this._in&&this._in[a]||{}},toJSON:function(){var a=Backbone.Model.prototype.toJSON.apply(this,arguments);return a.cells=this.get("cells").toJSON(),a},fromJSON:function(a,b){if(!a.cells)throw new Error("Graph JSON must contain cells array.");return this.set(a,b)},set:function(a,b,c){var d;return"object"==typeof a?(d=a,c=b):(d={})[a]=b,d.hasOwnProperty("cells")&&(this.resetCells(d.cells,c),d=_.omit(d,"cells")),Backbone.Model.prototype.set.call(this,d,c)},clear:function(a){a=_.extend({},a,{clear:!0});var b=this.get("cells");if(0===b.length)return this;this.startBatch("clear",a);var c=b.sortBy(function(a){return a.isLink()?1:2});do c.shift().remove(a);while(c.length>0);return this.stopBatch("clear"),this},_prepareCell:function(a){var b;if(a instanceof Backbone.Model?(b=a.attributes,a.graph=this):b=a,!_.isString(b.type))throw new TypeError("dia.Graph: cell type must be a string.");return a},maxZIndex:function(){var a=this.get("cells").last();return a?a.get("z")||0:0},addCell:function(a,b){return _.isArray(a)?this.addCells(a,b):(a instanceof Backbone.Model?a.has("z")||a.set("z",this.maxZIndex()+1):_.isUndefined(a.z)&&(a.z=this.maxZIndex()+1),this.get("cells").add(this._prepareCell(a),b||{}),this)},addCells:function(a,b){return a.length&&(b.position=a.length,this.startBatch("add"),_.each(a,function(a){b.position--,this.addCell(a,b)},this),this.stopBatch("add")),this},resetCells:function(a,b){return this.get("cells").reset(_.map(a,this._prepareCell,this),b),this},removeCells:function(a,b){return a.length&&(this.startBatch("remove"),_.invoke(a,"remove"),this.stopBatch("remove")),this},_removeCell:function(a,b,c){c=c||{},c.clear||(c.disconnectLinks?this.disconnectLinks(a,c):this.removeLinks(a,c)),this.get("cells").remove(a,{silent:!0}),delete a.graph},getCell:function(a){return this.get("cells").get(a)},getCells:function(){return this.get("cells").toArray()},getElements:function(){return _.map(this._nodes,function(a,b){return this.getCell(b)},this)},getLinks:function(){return _.map(this._edges,function(a,b){return this.getCell(b)},this)},getFirstCell:function(){return this.get("cells").first()},getLastCell:function(){return this.get("cells").last()},getConnectedLinks:function(a,b){b=b||{};var c=b.inbound,d=b.outbound;_.isUndefined(c)&&_.isUndefined(d)&&(c=d=!0);var e=[],f={};if(d&&_.each(this.getOutboundEdges(a.id),function(a,b){f[b]||(e.push(this.getCell(b)),f[b]=!0)},this),c&&_.each(this.getInboundEdges(a.id),function(a,b){f[b]||(e.push(this.getCell(b)),f[b]=!0)},this),b.deep){var g=a.getEmbeddedCells({deep:!0}),h={};_.each(g,function(a){a.isLink()&&(h[a.id]=!0)}),_.each(g,function(a){a.isLink()||(d&&_.each(this.getOutboundEdges(a.id),function(a,b){f[b]||h[b]||(e.push(this.getCell(b)),f[b]=!0)},this),c&&_.each(this.getInboundEdges(a.id),function(a,b){f[b]||h[b]||(e.push(this.getCell(b)),f[b]=!0)},this))},this)}return e},getNeighbors:function(a,b){b=b||{};var c=b.inbound,d=b.outbound;_.isUndefined(c)&&_.isUndefined(d)&&(c=d=!0);var e=_.transform(this.getConnectedLinks(a,b),function(e,f){var g=f.get("source"),h=f.get("target"),i=f.hasLoop(b);if(c&&_.has(g,"id")&&!e[g.id]){var j=this.getCell(g.id);!i&&(!j||j===a||b.deep&&j.isEmbeddedIn(a))||(e[g.id]=j)}if(d&&_.has(h,"id")&&!e[h.id]){var k=this.getCell(h.id);!i&&(!k||k===a||b.deep&&k.isEmbeddedIn(a))||(e[h.id]=k)}},{},this);return _.values(e)},getCommonAncestor:function(){var a=_.map(arguments,function(a){for(var b=[],c=a.get("parent");c;)b.push(c),c=this.getCell(c).get("parent");return b},this);a=_.sortBy(a,"length");var b=_.find(a.shift(),function(b){return _.every(a,function(a){return _.contains(a,b)})});return this.getCell(b)},getSuccessors:function(a,b){b=b||{};var c=[];return this.search(a,function(b){b!==a&&c.push(b)},_.extend({},b,{outbound:!0})),c},cloneCells:function(a){a=_.unique(a);var b=_.transform(a,function(a,b){a[b.id]=b.clone()},{});return _.each(a,function(a){var c=b[a.id];if(c.isLink()){var d=c.get("source"),e=c.get("target");d.id&&b[d.id]&&c.prop("source/id",b[d.id].id),e.id&&b[e.id]&&c.prop("target/id",b[e.id].id)}var f=a.get("parent");f&&b[f]&&c.set("parent",b[f].id);var g=_.reduce(a.get("embeds"),function(a,c){return b[c]&&a.push(b[c].id),a},[]);_.isEmpty(g)||c.set("embeds",g)}),b},cloneSubgraph:function(a,b){var c=this.getSubgraph(a,b);return this.cloneCells(c)},getSubgraph:function(a,b){b=b||{};var c=[],d={},e=[],f=[];return _.each(a,function(a){if(d[a.id]||(c.push(a),d[a.id]=a,a.isLink()?f.push(a):e.push(a)),b.deep){var g=a.getEmbeddedCells({deep:!0});_.each(g,function(a){d[a.id]||(c.push(a),d[a.id]=a,a.isLink()?f.push(a):e.push(a))})}}),_.each(f,function(a){var b=a.get("source"),f=a.get("target");if(b.id&&!d[b.id]){var g=this.getCell(b.id);c.push(g),d[g.id]=g,e.push(g)}if(f.id&&!d[f.id]){var h=this.getCell(f.id);c.push(this.getCell(f.id)),d[h.id]=h,e.push(h)}},this),_.each(e,function(a){var e=this.getConnectedLinks(a,b);_.each(e,function(a){var b=a.get("source"),e=a.get("target");!d[a.id]&&b.id&&d[b.id]&&e.id&&d[e.id]&&(c.push(a),d[a.id]=a)})},this),c},getPredecessors:function(a,b){b=b||{};var c=[];return this.search(a,function(b){b!==a&&c.push(b)},_.extend({},b,{inbound:!0})),c},search:function(a,b,c){c=c||{},c.breadthFirst?this.bfs(a,b,c):this.dfs(a,b,c)},bfs:function(a,b,c){c=c||{};var d={},e={},f=[];for(f.push(a),e[a.id]=0;f.length>0;){var g=f.shift();if(!d[g.id]){if(d[g.id]=!0,b(g,e[g.id])===!1)return;_.each(this.getNeighbors(g,c),function(a){e[a.id]=e[g.id]+1,f.push(a)})}}},dfs:function(a,b,c,d,e){c=c||{};var f=d||{},g=e||0;b(a,g)!==!1&&(f[a.id]=!0,_.each(this.getNeighbors(a,c),function(a){f[a.id]||this.dfs(a,b,c,f,g+1)},this))},getSources:function(){var a=[];return _.each(this._nodes,function(b,c){this._in[c]&&!_.isEmpty(this._in[c])||a.push(this.getCell(c))},this),a},getSinks:function(){var a=[];return _.each(this._nodes,function(b,c){this._out[c]&&!_.isEmpty(this._out[c])||a.push(this.getCell(c))},this),a},isSource:function(a){return!this._in[a.id]||_.isEmpty(this._in[a.id])},isSink:function(a){return!this._out[a.id]||_.isEmpty(this._out[a.id])},isSuccessor:function(a,b){var c=!1;return this.search(a,function(d){return d===b&&d!==a?(c=!0,!1):void 0},{outbound:!0}),c},isPredecessor:function(a,b){var c=!1;return this.search(a,function(d){return d===b&&d!==a?(c=!0,!1):void 0},{inbound:!0}),c},isNeighbor:function(a,b,c){c=c||{};var d=c.inbound,e=c.outbound;_.isUndefined(d)&&_.isUndefined(e)&&(d=e=!0);var f=!1;return _.each(this.getConnectedLinks(a,c),function(a){var g=a.get("source"),h=a.get("target");a.hasLoop(c);return d&&_.has(g,"id")&&g.id===b.id?(f=!0,!1):e&&_.has(h,"id")&&h.id===b.id?(f=!0,!1):void 0}),f},disconnectLinks:function(a,b){_.each(this.getConnectedLinks(a),function(c){c.set(c.get("source").id===a.id?"source":"target",g.point(0,0),b)})},removeLinks:function(a,b){_.invoke(this.getConnectedLinks(a),"remove",b)},findModelsFromPoint:function(a){return _.filter(this.getElements(),function(b){return b.getBBox().containsPoint(a)})},findModelsInArea:function(a,b){b=_.defaults(b||{},{strict:!1});var c=b.strict?"containsRect":"intersect";return _.filter(this.getElements(),function(b){return a[c](b.getBBox())})},findModelsUnderElement:function(a,b){b=_.defaults(b||{},{searchBy:"bbox"});var c=a.getBBox(),d="bbox"==b.searchBy?this.findModelsInArea(c):this.findModelsFromPoint(c[b.searchBy]());return _.reject(d,function(b){return a.id==b.id||b.isEmbeddedIn(a)})},getBBox:function(a,b){return this.getCellsBBox(a||this.getElements(),b)},getCellsBBox:function(a,b){return _.reduce(a,function(a,c){return c.isLink()?a:a?a.union(c.getBBox(b)):c.getBBox(b)},null)},translate:function(a,b,c){var d=_.reject(this.getCells(),function(a){return a.isEmbedded()});_.invoke(d,"translate",a,b,c)},resize:function(a,b,c){return this.resizeCells(a,b,this.getCells(),c)},resizeCells:function(a,b,c,d){var e=this.getCellsBBox(c);if(e){var f=Math.max(a/e.width,0),g=Math.max(b/e.height,0);_.invoke(c,"scale",f,g,e.origin(),d)}return this},startBatch:function(a,b){return b=b||{},this._batches[a]=(this._batches[a]||0)+1,this.trigger("batch:start",_.extend({},b,{batchName:a}))},stopBatch:function(a,b){return b=b||{},this._batches[a]=(this._batches[a]||0)-1,this.trigger("batch:stop",_.extend({},b,{batchName:a}))},hasActiveBatch:function(a){return a?this._batches[a]:_.any(this._batches,function(a){return a>0})}}),joint.util.wrapWith(joint.dia.Graph.prototype,["resetCells","addCells","removeCells"],"cells"),joint.dia.Cell=Backbone.Model.extend({constructor:function(a,b){var c,d=a||{};this.cid=_.uniqueId("c"),this.attributes={},b&&b.collection&&(this.collection=b.collection),b&&b.parse&&(d=this.parse(d,b)||{}),(c=_.result(this,"defaults"))&&(d=_.merge({},c,d)),this.set(d,b),this.changed={},this.initialize.apply(this,arguments)},translate:function(a,b,c){throw new Error("Must define a translate() method.")},toJSON:function(){var a=this.constructor.prototype.defaults.attrs||{},b=this.attributes.attrs,c={};_.each(b,function(b,d){var e=a[d];_.each(b,function(a,b){_.isObject(a)&&!_.isArray(a)?_.each(a,function(a,f){e&&e[b]&&_.isEqual(e[b][f],a)||(c[d]=c[d]||{},(c[d][b]||(c[d][b]={}))[f]=a)}):e&&_.isEqual(e[b],a)||(c[d]=c[d]||{},c[d][b]=a)})});var d=_.cloneDeep(_.omit(this.attributes,"attrs"));return d.attrs=c,d},initialize:function(a){a&&a.id||this.set("id",joint.util.uuid(),{silent:!0}),this._transitionIds={},this.processPorts(),this.on("change:attrs",this.processPorts,this)},processPorts:function(){var a=this.ports,b={};_.each(this.get("attrs"),function(a,c){a&&a.port&&(_.isUndefined(a.port.id)?b[a.port]={id:a.port}:b[a.port.id]=a.port)});var c={};if(_.each(a,function(a,d){b[d]||(c[d]=!0)}),this.graph&&!_.isEmpty(c)){var d=this.graph.getConnectedLinks(this,{inbound:!0});_.each(d,function(a){c[a.get("target").port]&&a.remove()});var e=this.graph.getConnectedLinks(this,{outbound:!0});_.each(e,function(a){c[a.get("source").port]&&a.remove()})}this.ports=b},remove:function(a){a=a||{};var b=this.graph;b&&b.startBatch("remove");var c=this.get("parent");if(c){var d=b&&b.getCell(c);d.unembed(this)}return _.invoke(this.getEmbeddedCells(),"remove",a),this.trigger("remove",this,this.collection,a),b&&b.stopBatch("remove"),this},toFront:function(a){if(this.graph){a=a||{};var b=(this.graph.getLastCell().get("z")||0)+1;if(this.startBatch("to-front").set("z",b,a),a.deep){var c=this.getEmbeddedCells({deep:!0,breadthFirst:!0});_.each(c,function(c){c.set("z",++b,a)})}this.stopBatch("to-front")}return this},toBack:function(a){if(this.graph){a=a||{};var b=(this.graph.getFirstCell().get("z")||0)-1;if(this.startBatch("to-back"),a.deep){var c=this.getEmbeddedCells({deep:!0,breadthFirst:!0});_.eachRight(c,function(c){c.set("z",b--,a)})}this.set("z",b,a).stopBatch("to-back")}return this},embed:function(a,b){if(this===a||this.isEmbeddedIn(a))throw new Error("Recursive embedding not allowed.");this.startBatch("embed");var c=_.clone(this.get("embeds")||[]);return c[a.isLink()?"unshift":"push"](a.id),a.set("parent",this.id,b),this.set("embeds",_.uniq(c),b),this.stopBatch("embed"),this},unembed:function(a,b){return this.startBatch("unembed"),a.unset("parent",b),this.set("embeds",_.without(this.get("embeds"),a.id),b),this.stopBatch("unembed"),this},getAncestors:function(){var a=[],b=this.get("parent");if(!this.graph)return a;for(;void 0!==b;){var c=this.graph.getCell(b);if(void 0===c)break;a.push(c),b=c.get("parent")}return a},getEmbeddedCells:function(a){if(a=a||{},this.graph){var b;if(a.deep)if(a.breadthFirst){b=[];for(var c=this.getEmbeddedCells();c.length>0;){var d=c.shift();b.push(d),c.push.apply(c,d.getEmbeddedCells())}}else b=this.getEmbeddedCells(),_.each(b,function(c){b.push.apply(b,c.getEmbeddedCells(a))});else b=_.map(this.get("embeds"),this.graph.getCell,this.graph);return b}return[]},isEmbeddedIn:function(a,b){var c=_.isString(a)?a:a.id,d=this.get("parent");if(b=_.defaults({deep:!0},b),this.graph&&b.deep){for(;d;){if(d===c)return!0;d=this.graph.getCell(d).get("parent")}return!1}return d===c},isEmbedded:function(){return!!this.get("parent")},clone:function(a){if(a=a||{},a.deep)return _.values(joint.dia.Graph.prototype.cloneCells.call(null,[this].concat(this.getEmbeddedCells({deep:!0}))));var b=Backbone.Model.prototype.clone.apply(this,arguments);
|
return b.set("id",joint.util.uuid()),b.unset("embeds"),b.unset("parent"),b},prop:function(a,b,c){var d="/";if(_.isString(a)){if(arguments.length>1){var e=a,f=e.split("/"),g=f[0];if(f.shift(),c=c||{},c.propertyPath=e,c.propertyValue=b,0===f.length)return this.set(g,b,c);var h={},i=h,j=g;_.each(f,function(a){i=i[j]=_.isFinite(Number(a))?[]:{},j=a}),h=joint.util.setByPath(h,e,b,"/");var k=_.merge({},this.attributes);c.rewrite&&joint.util.unsetByPath(k,e,"/");var l=_.merge(k,h);return this.set(g,l[g],c)}return joint.util.getByPath(this.attributes,a,d)}return this.set(_.merge({},this.attributes,a),b)},removeProp:function(a,b){b=b||{},b.dirty=!0;var c=a.split("/");if(1===c.length)return this.unset(a,b);var d=c[0],e=c.slice(1).join("/"),f=_.merge({},this.get(d));return joint.util.unsetByPath(f,e,"/"),this.set(d,f,b)},attr:function(a,b,c){var d=Array.prototype.slice.call(arguments);return _.isString(a)?d[0]="attrs/"+a:d[0]={attrs:a},this.prop.apply(this,d)},removeAttr:function(a,b){return _.isArray(a)?(_.each(a,function(a){this.removeAttr(a,b)},this),this):this.removeProp("attrs/"+a,b)},transition:function(a,b,c,d){d=d||"/";var e={duration:100,delay:10,timingFunction:joint.util.timing.linear,valueFunction:joint.util.interpolate.number};c=_.extend(e,c);var f,g=0,h=_.bind(function(b){var d,e,i;g=g||b,b-=g,e=b/c.duration,1>e?this._transitionIds[a]=d=joint.util.nextFrame(h):(e=1,delete this._transitionIds[a]),i=f(c.timingFunction(e)),c.transitionId=d,this.prop(a,i,c),d||this.trigger("transition:end",this,a)},this),i=_.bind(function(e){this.stopTransitions(a),f=c.valueFunction(joint.util.getByPath(this.attributes,a,d),b),this._transitionIds[a]=joint.util.nextFrame(e),this.trigger("transition:start",this,a)},this);return _.delay(i,c.delay,h)},getTransitions:function(){return _.keys(this._transitionIds)},stopTransitions:function(a,b){b=b||"/";var c=a&&a.split(b);return _(this._transitionIds).keys().filter(c&&function(a){return _.isEqual(c,a.split(b).slice(0,c.length))}).each(function(a){joint.util.cancelFrame(this._transitionIds[a]),delete this._transitionIds[a],this.trigger("transition:end",this,a)},this),this},addTo:function(a,b){return a.addCell(this,b),this},findView:function(a){return a.findViewByModel(this)},isElement:function(){return!1},isLink:function(){return!1},startBatch:function(a,b){return this.graph&&this.graph.startBatch(a,_.extend({},b,{cell:this})),this},stopBatch:function(a,b){return this.graph&&this.graph.stopBatch(a,_.extend({},b,{cell:this})),this}}),joint.dia.CellView=joint.mvc.View.extend({tagName:"g",attributes:function(){return{"model-id":this.model.id}},constructor:function(a){a.id=a.id||joint.util.guid(this),joint.mvc.View.call(this,a)},init:function(){_.bindAll(this,"remove","update"),this.$el.data("view",this),this.listenTo(this.model,"change:attrs",this.onChangeAttrs)},onChangeAttrs:function(a,b,c){return c.dirty?this.render():this.update(a,b,c)},can:function(a){var b=_.isFunction(this.options.interactive)?this.options.interactive(this):this.options.interactive;return _.isObject(b)&&b[a]!==!1||_.isBoolean(b)&&b!==!1},_ensureElement:function(){var a;if(this.el)a=_.result(this,"el");else{var b=_.extend({id:this.id},_.result(this,"attributes"));this.className&&(b["class"]=_.result(this,"className")),a=V(_.result(this,"tagName"),b).node}this.setElement(a,!1)},_setElement:function(a){this.$el=a instanceof Backbone.$?a:Backbone.$(a),this.el=this.$el[0],this.vel=V(this.el)},findBySelector:function(a){var b="."===a?this.$el:this.$el.find(a);return b},notify:function(a){if(this.paper){var b=Array.prototype.slice.call(arguments,1);this.trigger.apply(this,[a].concat(b)),this.paper.trigger.apply(this.paper,[a,this].concat(b))}},getStrokeBBox:function(a){var b=!!a;a=a||this.el;var c,d=V(a).bbox(!1,this.paper.viewport);return c=b?V(a).attr("stroke-width"):this.model.attr("rect/stroke-width")||this.model.attr("circle/stroke-width")||this.model.attr("ellipse/stroke-width")||this.model.attr("path/stroke-width"),c=parseFloat(c)||0,g.rect(d).moveAndExpand({x:-c/2,y:-c/2,width:c,height:c})},getBBox:function(){return g.rect(this.vel.bbox())},highlight:function(a,b){return a=a?this.$(a)[0]||this.el:this.el,b=b||{},b.partial=a!=this.el,this.notify("cell:highlight",a,b),this},unhighlight:function(a,b){return a=a?this.$(a)[0]||this.el:this.el,b=b||{},b.partial=a!=this.el,this.notify("cell:unhighlight",a,b),this},findMagnet:function(a){var b=this.$(a);if(0===b.length||b[0]===this.el){var c=this.model.get("attrs")||{};if(c["."]&&c["."].magnet===!1)return;return this.el}return b.attr("magnet")?b[0]:this.findMagnet(b.parent())},applyFilter:function(a,b){var c=_.isString(a)?this.findBySelector(a):$(a),d=b.name+this.paper.svg.id+joint.util.hashCode(JSON.stringify(b));if(!this.paper.svg.getElementById(d)){var e=joint.util.filter[b.name]&&joint.util.filter[b.name](b.args||{});if(!e)throw new Error("Non-existing filter "+b.name);var f=V(e);f.attr({filterUnits:"objectBoundingBox",x:-1,y:-1,width:3,height:3}),b.attrs&&f.attr(b.attrs),f.node.id=d,V(this.paper.svg).defs().append(f)}c.each(function(){V(this).attr("filter","url(#"+d+")")})},applyGradient:function(a,b,c){var d=_.isString(a)?this.findBySelector(a):$(a),e=c.type+this.paper.svg.id+joint.util.hashCode(JSON.stringify(c));if(!this.paper.svg.getElementById(e)){var f=["<"+c.type+">",_.map(c.stops,function(a){return'<stop offset="'+a.offset+'" stop-color="'+a.color+'" stop-opacity="'+(_.isFinite(a.opacity)?a.opacity:1)+'" />'}).join(""),"</"+c.type+">"].join(""),g=V(f);c.attrs&&g.attr(c.attrs),g.node.id=e,V(this.paper.svg).defs().append(g)}d.each(function(){V(this).attr(b,"url(#"+e+")")})},getSelector:function(a,b){if(a===this.el)return b;var c=V(a).index()+1,d=a.tagName+":nth-child("+c+")";return b&&(d+=" > "+b),this.getSelector(a.parentNode,d)},pointerdblclick:function(a,b,c){this.notify("cell:pointerdblclick",a,b,c)},pointerclick:function(a,b,c){this.notify("cell:pointerclick",a,b,c)},pointerdown:function(a,b,c){this.model.graph&&(this.model.startBatch("pointer"),this._graph=this.model.graph),this.notify("cell:pointerdown",a,b,c)},pointermove:function(a,b,c){this.notify("cell:pointermove",a,b,c)},pointerup:function(a,b,c){this.notify("cell:pointerup",a,b,c),this._graph&&(this._graph.stopBatch("pointer",{cell:this.model}),delete this._graph)},mouseover:function(a){this.notify("cell:mouseover",a)},mouseout:function(a){this.notify("cell:mouseout",a)},mousewheel:function(a,b,c,d){this.notify("cell:mousewheel",a,b,c,d)},contextmenu:function(a,b,c){this.notify("cell:contextmenu",a,b,c)},onSetTheme:function(a,b){a&&this.vel.removeClass(this.themeClassNamePrefix+a),this.vel.addClass(this.themeClassNamePrefix+b)}}),joint.dia.Element=joint.dia.Cell.extend({defaults:{position:{x:0,y:0},size:{width:1,height:1},angle:0},isElement:function(){return!0},position:function(a,b,c){var d=_.isNumber(b);if(c=(d?c:a)||{},c.parentRelative){if(!this.graph)throw new Error("Element must be part of a graph.");var e=this.graph.getCell(this.get("parent")),f=e&&!e.isLink()?e.get("position"):{x:0,y:0}}if(d)return c.parentRelative&&(a+=f.x,b+=f.y),this.set("position",{x:a,y:b},c);var h=g.point(this.get("position"));return c.parentRelative?h.difference(f):h},translate:function(a,b,c){if(a=a||0,b=b||0,0===a&&0===b)return this;c=c||{},c.translateBy=c.translateBy||this.id;var d=this.get("position")||{x:0,y:0};if(c.restrictedArea&&c.translateBy===this.id){var e=this.getBBox({deep:!0}),f=c.restrictedArea,g=d.x-e.x,h=d.y-e.y,i=Math.max(f.x+g,Math.min(f.x+f.width+g-e.width,d.x+a)),j=Math.max(f.y+h,Math.min(f.y+f.height+h-e.height,d.y+b));a=i-d.x,b=j-d.y}var k={x:d.x+a,y:d.y+b};return c.tx=a,c.ty=b,c.transition?(_.isObject(c.transition)||(c.transition={}),this.transition("position",k,_.extend({},c.transition,{valueFunction:joint.util.interpolate.object}))):(this.set("position",k,c),_.invoke(this.getEmbeddedCells(),"translate",a,b,c)),this},resize:function(a,b,c){if(c=c||{},this.startBatch("resize",c),c.direction){var d=this.get("size");switch(c.direction){case"left":case"right":b=d.height;break;case"top":case"bottom":a=d.width}var e=g.normalizeAngle(this.get("angle")||0),f={"top-right":0,right:0,"top-left":1,top:1,"bottom-left":2,left:2,"bottom-right":3,bottom:3}[c.direction];c.absolute&&(f+=Math.floor((e+45)/90),f%=4);var h=this.getBBox(),i=h[["bottomLeft","corner","topRight","origin"][f]](),j=g.point(i).rotate(h.center(),-e),k=Math.sqrt(a*a+b*b)/2,l=f*Math.PI/2;l+=Math.atan(f%2==0?b/a:a/b),l-=g.toRad(e);var m=g.point.fromPolar(k,l,j),n=g.point(m).offset(a/-2,b/-2);this.set("size",{width:a,height:b},c),this.position(n.x,n.y,c)}else this.set("size",{width:a,height:b},c);return this.stopBatch("resize",c),this},scale:function(a,b,c,d){var e=this.getBBox().scale(a,b,c);return this.startBatch("scale",d),this.position(e.x,e.y,d),this.resize(e.width,e.height,d),this.stopBatch("scale"),this},fitEmbeds:function(a){if(a=a||{},!this.graph)throw new Error("Element must be part of a graph.");var b=this.getEmbeddedCells();if(b.length>0){this.startBatch("fit-embeds",a),a.deep&&_.invoke(b,"fitEmbeds",a);var c=this.graph.getCellsBBox(b),d=joint.util.normalizeSides(a.padding);c.moveAndExpand({x:-d.left,y:-d.top,width:d.right+d.left,height:d.bottom+d.top}),this.set({position:{x:c.x,y:c.y},size:{width:c.width,height:c.height}},a),this.stopBatch("fit-embeds")}return this},rotate:function(a,b,c){if(c){var d=this.getBBox().center(),e=this.get("size"),f=this.get("position");d.rotate(c,this.get("angle")-a);var g=d.x-e.width/2-f.x,h=d.y-e.height/2-f.y;this.startBatch("rotate",{angle:a,absolute:b,origin:c}),this.translate(g,h),this.rotate(a,b),this.stopBatch("rotate")}else this.set("angle",b?a:(this.get("angle")+a)%360);return this},getBBox:function(a){if(a=a||{},a.deep&&this.graph){var b=this.getEmbeddedCells({deep:!0,breadthFirst:!0});return b.push(this),this.graph.getCellsBBox(b)}var c=this.get("position"),d=this.get("size");return g.rect(c.x,c.y,d.width,d.height)}}),joint.dia.ElementView=joint.dia.CellView.extend({SPECIAL_ATTRIBUTES:["style","text","html","ref-x","ref-y","ref-dx","ref-dy","ref-width","ref-height","ref","x-alignment","y-alignment","port"],className:function(){return"element "+this.model.get("type").replace(/\./g," ")},initialize:function(){_.bindAll(this,"translate","resize","rotate"),joint.dia.CellView.prototype.initialize.apply(this,arguments),this.listenTo(this.model,"change:position",this.translate),this.listenTo(this.model,"change:size",this.resize),this.listenTo(this.model,"change:angle",this.rotate)},update:function(a,b){var c=this.model.get("attrs"),d=this.rotatableNode;if(d){var e=d.attr("transform");d.attr("transform","")}var f=[],g={};_.each(b||c,function(a,b){var c=this.findBySelector(b);if(0!==c.length){g[b]=c;var d=this.SPECIAL_ATTRIBUTES.slice();_.isObject(a.filter)&&(d.push("filter"),this.applyFilter(c,a.filter)),_.isObject(a.fill)&&(d.push("fill"),this.applyGradient(c,"fill",a.fill)),_.isObject(a.stroke)&&(d.push("stroke"),this.applyGradient(c,"stroke",a.stroke)),_.isUndefined(a.text)||(c.each(function(){V(this).text(a.text+"",{lineHeight:a.lineHeight,textPath:a.textPath,annotations:a.annotations})}),d.push("lineHeight","textPath","annotations"));var e=_.omit(a,d);c.each(function(){V(this).attr(e)}),a.port&&c.attr("port",_.isUndefined(a.port.id)?a.port:a.port.id),a.style&&c.css(a.style),_.isUndefined(a.html)||c.each(function(){$(this).html(a.html+"")}),_.isUndefined(a["ref-x"])&&_.isUndefined(a["ref-y"])&&_.isUndefined(a["ref-dx"])&&_.isUndefined(a["ref-dy"])&&_.isUndefined(a["x-alignment"])&&_.isUndefined(a["y-alignment"])&&_.isUndefined(a["ref-width"])&&_.isUndefined(a["ref-height"])||_.each(c,function(a,b,c){var d=$(a);d.selector=c.selector,f.push(d)})}},this);var h=this.model.get("size"),i={x:0,y:0,width:h.width,height:h.height};b=b||{},_.each(f,function(a){var d=b[a.selector],e=d?_.merge({},c[a.selector],d):c[a.selector];this.positionRelative(V(a[0]),i,e,g)},this),d&&d.attr("transform",e||"")},positionRelative:function(a,b,c,d){var e=c.ref,f=parseFloat(c["ref-dx"]),g=parseFloat(c["ref-dy"]),h=c["y-alignment"],i=c["x-alignment"],j=c["ref-y"],k=_.isString(j)&&"%"===j.slice(-1);j=parseFloat(j),k&&(j/=100);var l=c["ref-x"],m=_.isString(l)&&"%"===l.slice(-1);l=parseFloat(l),m&&(l/=100);var n=c["ref-width"],o=_.isString(n)&&"%"===n.slice(-1);n=parseFloat(n),o&&(n/=100);var p=c["ref-height"],q=_.isString(p)&&"%"===p.slice(-1);p=parseFloat(p),q&&(p/=100);var r=a.findParentByClass("scalable",this.el);if(e){var s;if(s=d&&d[e]?V(d[e][0]):"."===e?this.vel:this.vel.findOne(e),!s)throw new Error("dia.ElementView: reference does not exists.");b=s.bbox(!1,this.el)}a.attr("transform")&&a.attr("transform",a.attr("transform").replace(/translate\([^)]*\)/g,"").trim()||""),isFinite(n)&&(o||n>=0&&1>=n?a.attr("width",n*b.width):a.attr("width",Math.max(n+b.width,0))),isFinite(p)&&(q||p>=0&&1>=p?a.attr("height",p*b.height):a.attr("height",Math.max(p+b.height,0)));var t,u=0,v=0;if(isFinite(f)&&(r?(t=t||r.scale(),u=b.x+b.width+f/t.sx):u=b.x+b.width+f),isFinite(g)&&(r?(t=t||r.scale(),v=b.y+b.height+g/t.sy):v=b.y+b.height+g),isFinite(l)&&(m||l>0&&1>l?u=b.x+b.width*l:r?(t=t||r.scale(),u=b.x+l/t.sx):u=b.x+l),isFinite(j)&&(k||j>0&&1>j?v=b.y+b.height*j:r?(t=t||r.scale(),v=b.y+j/t.sy):v=b.y+j),!_.isUndefined(h)||!_.isUndefined(i)){var w=a.bbox(!1,this.paper.viewport);"middle"===h?v-=w.height/2:"bottom"===h?v-=w.height:isFinite(h)&&(v+=h>-1&&1>h?w.height*h:h),"middle"===i?u-=w.width/2:"right"===i?u-=w.width:isFinite(i)&&(u+=i>-1&&1>i?w.width*i:i)}a.translate(u,v)},renderMarkup:function(){var a=this.model.get("markup")||this.model.markup;if(!a)throw new Error("properties.markup is missing while the default render() implementation is used.");var b=V(a);this.vel.append(b)},render:function(){return this.$el.empty(),this.renderMarkup(),this.rotatableNode=this.vel.findOne(".rotatable"),this.scalableNode=this.vel.findOne(".scalable"),this.update(),this.resize(),this.rotate(),this.translate(),this},scale:function(a,b){this.vel.scale(a,b)},resize:function(){var a=this.model.get("size")||{width:1,height:1},b=this.model.get("angle")||0,c=this.scalableNode;if(c){var d=c.bbox(!0);c.attr("transform","scale("+a.width/(d.width||1)+","+a.height/(d.height||1)+")");var e=this.rotatableNode,f=e&&e.attr("transform");if(f&&"null"!==f){e.attr("transform",f+" rotate("+-b+","+a.width/2+","+a.height/2+")");var g=c.bbox(!1,this.paper.viewport);this.model.set("position",{x:g.x,y:g.y}),this.rotate()}this.update()}},translate:function(a,b,c){var d=this.model.get("position")||{x:0,y:0};this.vel.attr("transform","translate("+d.x+","+d.y+")")},rotate:function(){var a=this.rotatableNode;if(a){var b=this.model.get("angle")||0,c=this.model.get("size")||{width:1,height:1},d=c.width/2,e=c.height/2;a.attr("transform","rotate("+b+","+d+","+e+")")}},getBBox:function(a){if(a&&a.useModelGeometry){var b=this.model.getBBox().bbox(this.model.get("angle")),c=this.paper.viewport.getCTM();return g.rect(V.transformRect(b,c))}return joint.dia.CellView.prototype.getBBox.apply(this,arguments)},prepareEmbedding:function(a){a=a||{};var b=a.model||this.model,c=a.paper||this.paper;b.startBatch("to-front",a),b.toFront({deep:!0,ui:!0}),_.invoke(c.model.getConnectedLinks(b,{deep:!0}),"toFront",{ui:!0}),b.stopBatch("to-front");var d=b.get("parent");d&&c.model.getCell(d).unembed(b,{ui:!0})},processEmbedding:function(a){a=a||{};var b=a.model||this.model,c=a.paper||this.paper,d=c.options,e=c.model.findModelsUnderElement(b,{searchBy:d.findParentBy});d.frontParentOnly&&(e=e.slice(-1));for(var f=null,g=this._candidateEmbedView,h=e.length-1;h>=0;h--){var i=e[h];if(g&&g.model.id==i.id){f=g;break}var j=i.findView(c);if(d.validateEmbedding.call(c,this,j)){f=j;break}}f&&f!=g&&(g&&g.unhighlight(null,{embedding:!0}),this._candidateEmbedView=f.highlight(null,{embedding:!0})),!f&&g&&(g.unhighlight(null,{embedding:!0}),delete this._candidateEmbedView)},finalizeEmbedding:function(a){a=a||{};var b=this._candidateEmbedView,c=a.model||this.model,d=a.paper||this.paper;b&&(b.model.embed(c,{ui:!0}),b.unhighlight(null,{embedding:!0}),delete this._candidateEmbedView),_.invoke(d.model.getConnectedLinks(c,{deep:!0}),"reparent",{ui:!0})},pointerdown:function(a,b,c){var d=this.paper;if(a.target.getAttribute("magnet")&&this.can("addLinkFromMagnet")&&d.options.validateMagnet.call(d,this,a.target)){this.model.startBatch("add-link");var e=d.getDefaultLink(this,a.target);e.set({source:{id:this.model.id,selector:this.getSelector(a.target),port:a.target.getAttribute("port")},target:{x:b,y:c}}),d.model.addCell(e);var f=this._linkView=d.findViewByModel(e);f.pointerdown(a,b,c),f.startArrowheadMove("target",{whenNotAllowed:"remove"})}else this._dx=b,this._dy=c,this.restrictedArea=d.getRestrictedArea(this),joint.dia.CellView.prototype.pointerdown.apply(this,arguments),this.notify("element:pointerdown",a,b,c)},pointermove:function(a,b,c){if(this._linkView)this._linkView.pointermove(a,b,c);else{var d=this.paper.options.gridSize;if(this.can("elementMove")){var e=this.model.get("position"),f=g.snapToGrid(e.x,d)-e.x+g.snapToGrid(b-this._dx,d),h=g.snapToGrid(e.y,d)-e.y+g.snapToGrid(c-this._dy,d);this.model.translate(f,h,{restrictedArea:this.restrictedArea,ui:!0}),this.paper.options.embeddingMode&&(this._inProcessOfEmbedding||(this.prepareEmbedding(),this._inProcessOfEmbedding=!0),this.processEmbedding())}this._dx=g.snapToGrid(b,d),this._dy=g.snapToGrid(c,d),joint.dia.CellView.prototype.pointermove.apply(this,arguments),this.notify("element:pointermove",a,b,c)}},pointerup:function(a,b,c){this._linkView?(this._linkView.pointerup(a,b,c),this._linkView=null,this.model.stopBatch("add-link")):(this._inProcessOfEmbedding&&(this.finalizeEmbedding(),this._inProcessOfEmbedding=!1),this.notify("element:pointerup",a,b,c),joint.dia.CellView.prototype.pointerup.apply(this,arguments))}}),joint.dia.Link=joint.dia.Cell.extend({markup:['<path class="connection" stroke="black" d="M 0 0 0 0"/>','<path class="marker-source" fill="black" stroke="black" d="M 0 0 0 0"/>','<path class="marker-target" fill="black" stroke="black" d="M 0 0 0 0"/>','<path class="connection-wrap" d="M 0 0 0 0"/>','<g class="labels"/>','<g class="marker-vertices"/>','<g class="marker-arrowheads"/>','<g class="link-tools"/>'].join(""),labelMarkup:['<g class="label">',"<rect />","<text />","</g>"].join(""),toolMarkup:['<g class="link-tool">','<g class="tool-remove" event="remove">','<circle r="11" />','<path transform="scale(.8) translate(-16, -16)" d="M24.778,21.419 19.276,15.917 24.777,10.415 21.949,7.585 16.447,13.087 10.945,7.585 8.117,10.415 13.618,15.917 8.116,21.419 10.946,24.248 16.447,18.746 21.948,24.248z" />',"<title>Remove link.</title>","</g>",'<g class="tool-options" event="link:options">','<circle r="11" transform="translate(25)"/>','<path fill="white" transform="scale(.55) translate(29, -16)" d="M31.229,17.736c0.064-0.571,0.104-1.148,0.104-1.736s-0.04-1.166-0.104-1.737l-4.377-1.557c-0.218-0.716-0.504-1.401-0.851-2.05l1.993-4.192c-0.725-0.91-1.549-1.734-2.458-2.459l-4.193,1.994c-0.647-0.347-1.334-0.632-2.049-0.849l-1.558-4.378C17.165,0.708,16.588,0.667,16,0.667s-1.166,0.041-1.737,0.105L12.707,5.15c-0.716,0.217-1.401,0.502-2.05,0.849L6.464,4.005C5.554,4.73,4.73,5.554,4.005,6.464l1.994,4.192c-0.347,0.648-0.632,1.334-0.849,2.05l-4.378,1.557C0.708,14.834,0.667,15.412,0.667,16s0.041,1.165,0.105,1.736l4.378,1.558c0.217,0.715,0.502,1.401,0.849,2.049l-1.994,4.193c0.725,0.909,1.549,1.733,2.459,2.458l4.192-1.993c0.648,0.347,1.334,0.633,2.05,0.851l1.557,4.377c0.571,0.064,1.148,0.104,1.737,0.104c0.588,0,1.165-0.04,1.736-0.104l1.558-4.377c0.715-0.218,1.399-0.504,2.049-0.851l4.193,1.993c0.909-0.725,1.733-1.549,2.458-2.458l-1.993-4.193c0.347-0.647,0.633-1.334,0.851-2.049L31.229,17.736zM16,20.871c-2.69,0-4.872-2.182-4.872-4.871c0-2.69,2.182-4.872,4.872-4.872c2.689,0,4.871,2.182,4.871,4.872C20.871,18.689,18.689,20.871,16,20.871z"/>',"<title>Link options.</title>","</g>","</g>"].join(""),vertexMarkup:['<g class="marker-vertex-group" transform="translate(<%= x %>, <%= y %>)">','<circle class="marker-vertex" idx="<%= idx %>" r="10" />','<path class="marker-vertex-remove-area" idx="<%= idx %>" d="M16,5.333c-7.732,0-14,4.701-14,10.5c0,1.982,0.741,3.833,2.016,5.414L2,25.667l5.613-1.441c2.339,1.317,5.237,2.107,8.387,2.107c7.732,0,14-4.701,14-10.5C30,10.034,23.732,5.333,16,5.333z" transform="translate(5, -33)"/>','<path class="marker-vertex-remove" idx="<%= idx %>" transform="scale(.8) translate(9.5, -37)" d="M24.778,21.419 19.276,15.917 24.777,10.415 21.949,7.585 16.447,13.087 10.945,7.585 8.117,10.415 13.618,15.917 8.116,21.419 10.946,24.248 16.447,18.746 21.948,24.248z">',"<title>Remove vertex.</title>","</path>","</g>"].join(""),arrowheadMarkup:['<g class="marker-arrowhead-group marker-arrowhead-group-<%= end %>">','<path class="marker-arrowhead" end="<%= end %>" d="M 26 0 L 0 13 L 26 26 z" />',"</g>"].join(""),defaults:{type:"link",source:{},target:{}},isLink:function(){return!0},disconnect:function(){return this.set({source:g.point(0,0),target:g.point(0,0)})},label:function(a,b){a=a||0;var c=this.get("labels")||[];if(0===arguments.length||1===arguments.length)return c[a];var d=_.merge({},c[a],b),e=c.slice();return e[a]=d,this.set({labels:e})},translate:function(a,b,c){return c=c||{},c.translateBy=c.translateBy||this.id,c.tx=a,c.ty=b,this.applyToPoints(function(c){return{x:(c.x||0)+a,y:(c.y||0)+b}},c)},scale:function(a,b,c,d){return this.applyToPoints(function(d){return g.point(d).scale(a,b,c).toJSON()},d)},applyToPoints:function(a,b){if(!_.isFunction(a))throw new TypeError("dia.Link: applyToPoints expects its first parameter to be a function.");var c={},d=this.get("source");d.id||(c.source=a(d));var e=this.get("target");e.id||(c.target=a(e));var f=this.get("vertices");return f&&f.length>0&&(c.vertices=_.map(f,a)),this.set(c,b)},reparent:function(a){var b;if(this.graph){var c=this.graph.getCell(this.get("source").id),d=this.graph.getCell(this.get("target").id),e=this.graph.getCell(this.get("parent"));c&&d&&(b=this.graph.getCommonAncestor(c,d)),!e||b&&b.id===e.id||e.unembed(this,a),b&&b.embed(this,a)}return b},hasLoop:function(a){a=a||{};var b=this.get("source").id,c=this.get("target").id;if(!b||!c)return!1;var d=b===c;if(!d&&a.deep&&this.graph){var e=this.graph.getCell(b),f=this.graph.getCell(c);d=e.isEmbeddedIn(f)||f.isEmbeddedIn(e)}return d},getSourceElement:function(){var a=this.get("source");return a&&a.id&&this.graph&&this.graph.getCell(a.id)||null},getTargetElement:function(){var a=this.get("target");return a&&a.id&&this.graph&&this.graph.getCell(a.id)||null},getRelationshipAncestor:function(){var a;if(this.graph){var b=_.compact([this,this.getSourceElement(),this.getTargetElement()]);a=this.graph.getCommonAncestor.apply(this.graph,b)}return a||null},isRelationshipEmbeddedIn:function(a){var b=_.isString(a)?a:a.id,c=this.getRelationshipAncestor();return!!c&&(c.id===b||c.isEmbeddedIn(b))}}),joint.dia.LinkView=joint.dia.CellView.extend({className:function(){return _.unique(this.model.get("type").split(".").concat("link")).join(" ")},options:{shortLinkLength:100,doubleLinkTools:!1,longLinkLength:160,linkToolsOffset:40,doubleLinkToolsOffset:60,sampleInterval:50},_z:null,initialize:function(a){joint.dia.CellView.prototype.initialize.apply(this,arguments),"function"!=typeof this.constructor.prototype.watchSource&&(this.constructor.prototype.watchSource=this.createWatcher("source"),this.constructor.prototype.watchTarget=this.createWatcher("target")),this._labelCache={},this._markerCache={},this.startListening()},startListening:function(){var a=this.model;this.listenTo(a,"change:markup",this.render),this.listenTo(a,"change:smooth change:manhattan change:router change:connector",this.update),this.listenTo(a,"change:toolMarkup",this.onToolsChange),this.listenTo(a,"change:labels change:labelMarkup",this.onLabelsChange),this.listenTo(a,"change:vertices change:vertexMarkup",this.onVerticesChange),this.listenTo(a,"change:source",this.onSourceChange),this.listenTo(a,"change:target",this.onTargetChange)},onSourceChange:function(a,b,c){this.watchSource(a,b),c.translateBy&&this.model.get("target").id||(c.updateConnectionOnly=!0,this.update(this.model,null,c))},onTargetChange:function(a,b,c){this.watchTarget(a,b),c.translateBy||(c.updateConnectionOnly=!0,this.update(this.model,null,c))},onVerticesChange:function(a,b,c){this.renderVertexMarkers(),c.translateBy&&c.translateBy!==this.model.id||(c.updateConnectionOnly=!0,this.update(a,null,c))},onToolsChange:function(){this.renderTools().updateToolsPosition()},onLabelsChange:function(){this.renderLabels().updateLabelPositions()},render:function(){this.$el.empty();var a=this.model,b=V(a.get("markup")||a.markup);if(_.isArray(b)||(b=[b]),this._V={},_.each(b,function(a){var b=a.attr("class");b&&(this._V[$.camelCase(b)]=a)},this),!this._V.connection)throw new Error("link: no connection path in the markup");return this.renderTools(),this.renderVertexMarkers(),this.renderArrowheadMarkers(),this.vel.append(b),this.renderLabels(),this.watchSource(a,a.get("source")).watchTarget(a,a.get("target")).update(),this},renderLabels:function(){if(!this._V.labels)return this;this._labelCache={};var a=$(this._V.labels.node).empty(),b=this.model.get("labels")||[];if(!b.length)return this;var c=joint.util.template(this.model.get("labelMarkup")||this.model.labelMarkup),d=V(c()),e=this.can("labelMove");return _.each(b,function(b,c){var f=d.clone().node;V(f).attr("label-idx",c),e&&V(f).attr("cursor","move"),this._labelCache[c]=V(f);var g=$(f).find("text"),h=$(f).find("rect"),i=_.extend({"text-anchor":"middle","font-size":14},joint.util.getByPath(b,"attrs/text","/"));g.attr(_.omit(i,"text")),_.isUndefined(i.text)||V(g[0]).text(i.text+"",{annotations:i.annotations}),a.append(f);var j=V(g[0]).bbox(!0,a[0]);V(g[0]).translate(0,-j.height/2);var k=_.extend({fill:"white",rx:3,ry:3},joint.util.getByPath(b,"attrs/rect","/"));h.attr(_.extend(k,{x:j.x,y:j.y-j.height/2,width:j.width,height:j.height}))},this),this},renderTools:function(){if(!this._V.linkTools)return this;var a=$(this._V.linkTools.node).empty(),b=joint.util.template(this.model.get("toolMarkup")||this.model.toolMarkup),c=V(b());if(a.append(c.node),this._toolCache=c,this.options.doubleLinkTools){var d;this.model.get("doubleToolMarkup")||this.model.doubleToolMarkup?(b=joint.util.template(this.model.get("doubleToolMarkup")||this.model.doubleToolMarkup),d=V(b())):d=c.clone(),a.append(d.node),this._tool2Cache=d}return this},renderVertexMarkers:function(){if(!this._V.markerVertices)return this;var a=$(this._V.markerVertices.node).empty(),b=joint.util.template(this.model.get("vertexMarkup")||this.model.vertexMarkup);return _.each(this.model.get("vertices"),function(c,d){a.append(V(b(_.extend({idx:d},c))).node)}),this},renderArrowheadMarkers:function(){if(!this._V.markerArrowheads)return this;var a=$(this._V.markerArrowheads.node);a.empty();var b=joint.util.template(this.model.get("arrowheadMarkup")||this.model.arrowheadMarkup);return this._V.sourceArrowhead=V(b({end:"source"})),this._V.targetArrowhead=V(b({end:"target"})),a.append(this._V.sourceArrowhead.node,this._V.targetArrowhead.node),this},update:function(a,b,c){return c=c||{},c.updateConnectionOnly||this.updateAttributes(),this.updateConnection(c),this.updateLabelPositions(),this.updateToolsPosition(),this.updateArrowheadMarkers(),this.options.perpendicular=null,this.updatePostponed=!1,this},updateConnection:function(a){a=a||{};var b,c=this.model;if(a.translateBy&&c.isRelationshipEmbeddedIn(a.translateBy)){var d=a.tx||0,e=a.ty||0;b=this.route=_.map(this.route,function(a){return g.point(a).offset(d,e)}),this._translateConnectionPoints(d,e)}else b=this.route=this.findRoute(c.get("vertices")||[],a),this._findConnectionPoints(b);var f=this.getPathData(b);this._V.connection.attr("d",f),this._V.connectionWrap&&this._V.connectionWrap.attr("d",f),this._translateAndAutoOrientArrows(this._V.markerSource,this._V.markerTarget)},updateAttributes:function(){_.each(this.model.get("attrs"),function(a,b){var c=[];_.isObject(a.fill)&&(this.applyGradient(b,"fill",a.fill),c.push("fill")),_.isObject(a.stroke)&&(this.applyGradient(b,"stroke",a.stroke),c.push("stroke")),_.isObject(a.filter)&&(this.applyFilter(b,a.filter),c.push("filter")),c.length>0&&(c.unshift(a),a=_.omit.apply(_,c)),this.findBySelector(b).attr(a)},this)},_findConnectionPoints:function(a){var b,c,d,e,f=_.first(a);b=this.getConnectionPoint("source",this.model.get("source"),f||this.model.get("target")).round();var h=_.last(a);c=this.getConnectionPoint("target",this.model.get("target"),h||b).round();var i=this._markerCache;this._V.markerSource&&(i.sourceBBox=i.sourceBBox||this._V.markerSource.bbox(!0),d=g.point(b).move(f||c,i.sourceBBox.width*this._V.markerSource.scale().sx*-1).round()),this._V.markerTarget&&(i.targetBBox=i.targetBBox||this._V.markerTarget.bbox(!0),e=g.point(c).move(h||b,i.targetBBox.width*this._V.markerTarget.scale().sx*-1).round()),i.sourcePoint=d||b,i.targetPoint=e||c,this.sourcePoint=b,this.targetPoint=c},_translateConnectionPoints:function(a,b){var c=this._markerCache;c.sourcePoint.offset(a,b),c.targetPoint.offset(a,b),this.sourcePoint.offset(a,b),this.targetPoint.offset(a,b)},updateLabelPositions:function(){if(!this._V.labels)return this;var a=this.model.get("labels")||[];if(!a.length)return this;var b=this._V.connection.node,c=b.getTotalLength();if(!_.isNaN(c)){var d;_.each(a,function(a,e){var f=a.position,h=_.isObject(f)?f.distance:f,i=_.isObject(f)?f.offset:{x:0,y:0};_.isNaN(h)?h=c/2:(h=h>c?c:h,h=0>h?c+h:h,h=h>1?h:c*h);var j=b.getPointAtLength(h);if(_.isObject(i))j=g.point(j).offset(i.x,i.y);else if(_.isNumber(i)){d||(d=this._samples||this._V.connection.sample(this.options.sampleInterval));for(var k,l,m,n,o=1/0,p=0,q=d.length;q>p;p++)m=d[p],n=g.line(m,j).squaredLength(),o>n&&(o=n,k=m,l=p);var r=d[l-1],s=d[l+1],t=0;s?t=g.point(j).theta(s):r&&(t=g.point(r).theta(j)),j=g.point(j).offset(i).rotate(j,t-90)}this._labelCache[e].attr("transform","translate("+j.x+", "+j.y+")")},this)}return this},updateToolsPosition:function(){if(!this._V.linkTools)return this;var a="",b=this.options.linkToolsOffset,c=this.getConnectionLength();if(!_.isNaN(c)){c<this.options.shortLinkLength&&(a="scale(.5)",b/=2);var d=this.getPointAtLength(b);if(this._toolCache.attr("transform","translate("+d.x+", "+d.y+") "+a),this.options.doubleLinkTools&&c>=this.options.longLinkLength){var e=this.options.doubleLinkToolsOffset||b;d=this.getPointAtLength(c-e),this._tool2Cache.attr("transform","translate("+d.x+", "+d.y+") "+a),this._tool2Cache.attr("visibility","visible")}else this.options.doubleLinkTools&&this._tool2Cache.attr("visibility","hidden")}return this},updateArrowheadMarkers:function(){if(!this._V.markerArrowheads)return this;if("none"===$.css(this._V.markerArrowheads.node,"display"))return this;var a=this.getConnectionLength()<this.options.shortLinkLength?.5:1;return this._V.sourceArrowhead.scale(a),this._V.targetArrowhead.scale(a),this._translateAndAutoOrientArrows(this._V.sourceArrowhead,this._V.targetArrowhead),this},createWatcher:function(a){function b(b,d){d=d||{};var e=null,f=b.previous(a)||{};return f.id&&this.stopListening(this.paper.getModelById(f.id),"change",c),d.id&&(e=this.paper.getModelById(d.id),this.listenTo(e,"change",c)),c.call(this,e,{cacheOnly:!0}),this}var c=_.partial(this.onEndModelChange,a);return b},onEndModelChange:function(a,b,c){var d=!c.cacheOnly,e=this.model,f=e.get(a)||{};if(b){var h=this.constructor.makeSelector(f),i="source"==a?"target":"source",j=e.get(i)||{},k=j.id&&this.constructor.makeSelector(j);if(c.handleBy===this.cid&&h==k)this[a+"BBox"]=this[i+"BBox"],this[a+"View"]=this[i+"View"],this[a+"Magnet"]=this[i+"Magnet"];else if(c.translateBy){var l=this[a+"BBox"];l.x+=c.tx,l.y+=c.ty}else{var m=this.paper.findViewByModel(f.id),n=m.el.querySelector(h);this[a+"BBox"]=m.getStrokeBBox(n),this[a+"View"]=m,this[a+"Magnet"]=n}if(c.handleBy===this.cid&&c.translateBy&&e.isEmbeddedIn(b)&&!_.isEmpty(e.get("vertices"))&&(d=!1),!this.updatePostponed&&j.id){var o=this.paper.getModelById(j.id);f.id===j.id&&(c.handleBy=this.cid),
|
(c.handleBy===this.cid||c.translateBy&&o.isEmbeddedIn(c.translateBy))&&(this.updatePostponed=!0,d=!1)}}else this[a+"BBox"]=g.rect(f.x||0,f.y||0,1,1),this[a+"View"]=this[a+"Magnet"]=null;d&&(c.updateConnectionOnly=!0,this.update(e,null,c))},_translateAndAutoOrientArrows:function(a,b){a&&a.translateAndAutoOrient(this.sourcePoint,_.first(this.route)||this.targetPoint,this.paper.viewport),b&&b.translateAndAutoOrient(this.targetPoint,_.last(this.route)||this.sourcePoint,this.paper.viewport)},removeVertex:function(a){var b=_.clone(this.model.get("vertices"));return b&&b.length&&(b.splice(a,1),this.model.set("vertices",b,{ui:!0})),this},addVertex:function(a){for(var b,c=(this.model.get("vertices")||[]).slice(),d=c.slice(),e=this._V.connection.node.cloneNode(!1),f=e.getTotalLength(),g=20,h=c.length+1;h--&&(c.splice(h,0,a),V(e).attr("d",this.getPathData(this.findRoute(c))),b=e.getTotalLength(),b-f>g);)c=d.slice();return-1===h&&(h=0,c.splice(h,0,a)),this.model.set("vertices",c,{ui:!0}),h},sendToken:function(a,b,c){b=b||1e3,V(this.paper.viewport).append(a),V(a).animateAlongPath({dur:b+"ms",repeatCount:1},this._V.connection.node),_.delay(function(){V(a).remove(),c&&c()},b)},findRoute:function(a){var b=joint.routers,c=this.model.get("router"),d=this.paper.options.defaultRouter;if(!c)if(this.model.get("manhattan"))c={name:"orthogonal"};else{if(!d)return a;c=d}var e=c.args||{},f=_.isFunction(c)?c:b[c.name];if(!_.isFunction(f))throw new Error('unknown router: "'+c.name+'"');var g=f.call(this,a||[],e,this);return g},getPathData:function(a){var b=joint.connectors,c=this.model.get("connector"),d=this.paper.options.defaultConnector;c||(c=this.model.get("smooth")?{name:"smooth"}:d||{});var e=_.isFunction(c)?c:b[c.name],f=c.args||{};if(!_.isFunction(e))throw new Error('unknown connector: "'+c.name+'"');var g=e.call(this,this._markerCache.sourcePoint,this._markerCache.targetPoint,a||this.model.get("vertices")||{},f,this);return g},getConnectionPoint:function(a,b,c){var d;if(_.isEmpty(b)&&(b={x:0,y:0}),_.isEmpty(c)&&(c={x:0,y:0}),b.id){var e,f="source"===a?this.sourceBBox:this.targetBBox;if(c.id){var h="source"===a?this.targetBBox:this.sourceBBox;e=g.rect(h).intersectionWithLineFromCenterToPoint(g.rect(f).center()),e=e||g.rect(h).center()}else e=g.point(c);if(this.paper.options.perpendicularLinks||this.options.perpendicular){var i,j=g.rect(0,e.y,this.paper.options.width,1),k=g.rect(e.x,0,1,this.paper.options.height);if(j.intersect(g.rect(f)))switch(i=g.rect(f).sideNearestToPoint(e)){case"left":d=g.point(f.x,e.y);break;case"right":d=g.point(f.x+f.width,e.y);break;default:d=g.rect(f).center()}else if(k.intersect(g.rect(f)))switch(i=g.rect(f).sideNearestToPoint(e)){case"top":d=g.point(e.x,f.y);break;case"bottom":d=g.point(e.x,f.y+f.height);break;default:d=g.rect(f).center()}else d=g.rect(f).intersectionWithLineFromCenterToPoint(e),d=d||g.rect(f).center()}else if(this.paper.options.linkConnectionPoint){var l="target"===a?this.targetView:this.sourceView,m="target"===a?this.targetMagnet:this.sourceMagnet;d=this.paper.options.linkConnectionPoint(this,l,m,e)}else d=g.rect(f).intersectionWithLineFromCenterToPoint(e),d=d||g.rect(f).center()}else d=g.point(b);return d},getConnectionLength:function(){return this._V.connection.node.getTotalLength()},getPointAtLength:function(a){return this._V.connection.node.getPointAtLength(a)},_beforeArrowheadMove:function(){this._z=this.model.get("z"),this.model.toFront(),this.el.style.pointerEvents="none",this.paper.options.markAvailable&&this._markAvailableMagnets()},_afterArrowheadMove:function(){_.isNull(this._z)||(this.model.set("z",this._z,{ui:!0}),this._z=null),this.el.style.pointerEvents="visiblePainted",this.paper.options.markAvailable&&this._unmarkAvailableMagnets()},_createValidateConnectionArgs:function(a){function b(a,b){return c[f]=a,c[f+1]=a.el===b?void 0:b,c}var c=[];c[4]=a,c[5]=this;var d,e=0,f=0;"source"===a?(e=2,d="target"):(f=2,d="source");var g=this.model.get(d);return g.id&&(c[e]=this.paper.findViewByModel(g.id),c[e+1]=g.selector&&c[e].el.querySelector(g.selector)),b},_markAvailableMagnets:function(){function a(a,b){var c=a.paper,d=c.options.validateConnection;return d.apply(c,this._validateConnectionArgs(a,b))}var b=this.paper,c=b.model.getElements();this._marked={},_.chain(c).map(b.findViewByModel,b).each(function(b){var c=Array.prototype.slice.call(b.el.querySelectorAll("[magnet]"));"false"!==b.el.getAttribute("magnet")&&c.push(b.el);var d=_.filter(c,_.partial(a,b),this);d.length>0&&(_.each(d,_.partial(b.highlight,_,{magnetAvailability:!0}),b),b.highlight(null,{elementAvailability:!0}),this._marked[b.model.id]=d)},this).value()},_unmarkAvailableMagnets:function(){_.each(this._marked,function(a,b){var c=this.paper.findViewByModel(b);c&&(_.each(a,_.partial(c.unhighlight,_,{magnetAvailability:!0}),c),c.unhighlight(null,{elementAvailability:!0}))},this),this._marked=null},startArrowheadMove:function(a,b){b=_.defaults(b||{},{whenNotAllowed:"revert"}),this._action="arrowhead-move",this._whenNotAllowed=b.whenNotAllowed,this._arrowhead=a,this._initialEnd=_.clone(this.model.get(a))||{x:0,y:0},this._validateConnectionArgs=this._createValidateConnectionArgs(this._arrowhead),this._beforeArrowheadMove()},pointerdown:function(a,b,c){if(joint.dia.CellView.prototype.pointerdown.apply(this,arguments),this.notify("link:pointerdown",a,b,c),this._dx=b,this._dy=c,null==a.target.getAttribute("magnet")){var d,e=a.target.getAttribute("class"),f=a.target.parentNode.getAttribute("class");switch("label"===f?(e=f,d=a.target.parentNode):d=a.target,e){case"marker-vertex":this.can("vertexMove")&&(this._action="vertex-move",this._vertexIdx=a.target.getAttribute("idx"));break;case"marker-vertex-remove":case"marker-vertex-remove-area":this.can("vertexRemove")&&this.removeVertex(a.target.getAttribute("idx"));break;case"marker-arrowhead":this.can("arrowheadMove")&&this.startArrowheadMove(a.target.getAttribute("end"));break;case"label":this.can("labelMove")&&(this._action="label-move",this._labelIdx=parseInt(V(d).attr("label-idx"),10),this._samples=this._V.connection.sample(1),this._linkLength=this._V.connection.node.getTotalLength());break;default:var g=a.target.parentNode.getAttribute("event");g?this.can("useLinkTools")&&("remove"===g?this.model.remove():this.notify(g,a,b,c)):this.can("vertexAdd")&&(this._vertexIdx=this.addVertex({x:b,y:c}),this._action="vertex-move")}}},pointermove:function(a,b,c){switch(this._action){case"vertex-move":var d=_.clone(this.model.get("vertices"));d[this._vertexIdx]={x:b,y:c},this.model.set("vertices",d,{ui:!0});break;case"label-move":for(var e,f,h,i,j={x:b,y:c},k=(this.model.get("labels")[this._labelIdx],this._samples),l=1/0,m=0,n=k.length;n>m;m++)h=k[m],i=g.line(h,j).squaredLength(),l>i&&(l=i,e=h,f=m);var o=k[f-1],p=k[f+1],q=(g.point(e).distance(j),0);o&&p?q=g.line(o,p).pointOffset(j):o?q=g.line(o,e).pointOffset(j):p&&(q=g.line(e,p).pointOffset(j)),this.model.label(this._labelIdx,{position:{distance:e.distance/this._linkLength,offset:q}});break;case"arrowhead-move":if(this.paper.options.snapLinks){var r=this.paper.options.snapLinks.radius||50,s=this.paper.findViewsInArea({x:b-r,y:c-r,width:2*r,height:2*r});this._closestView&&this._closestView.unhighlight(this._closestEnd.selector,{connecting:!0,snapping:!0}),this._closestView=this._closestEnd=null;var t,u=Number.MAX_VALUE,v=g.point(b,c);_.each(s,function(a){"false"!==a.el.getAttribute("magnet")&&(t=a.model.getBBox().center().distance(v),r>t&&u>t&&this.paper.options.validateConnection.apply(this.paper,this._validateConnectionArgs(a,null))&&(u=t,this._closestView=a,this._closestEnd={id:a.model.id})),a.$("[magnet]").each(_.bind(function(b,c){var d=V(c).bbox(!1,this.paper.viewport);t=v.distance({x:d.x+d.width/2,y:d.y+d.height/2}),r>t&&u>t&&this.paper.options.validateConnection.apply(this.paper,this._validateConnectionArgs(a,c))&&(u=t,this._closestView=a,this._closestEnd={id:a.model.id,selector:a.getSelector(c),port:c.getAttribute("port")})},this))},this),this._closestView&&this._closestView.highlight(this._closestEnd.selector,{connecting:!0,snapping:!0}),this.model.set(this._arrowhead,this._closestEnd||{x:b,y:c},{ui:!0})}else{var w="mousemove"===a.type?a.target:document.elementFromPoint(a.clientX,a.clientY);this._targetEvent!==w&&(this._magnetUnderPointer&&this._viewUnderPointer.unhighlight(this._magnetUnderPointer,{connecting:!0}),this._viewUnderPointer=this.paper.findView(w),this._viewUnderPointer?(this._magnetUnderPointer=this._viewUnderPointer.findMagnet(w),this._magnetUnderPointer&&this.paper.options.validateConnection.apply(this.paper,this._validateConnectionArgs(this._viewUnderPointer,this._magnetUnderPointer))?this._magnetUnderPointer&&this._viewUnderPointer.highlight(this._magnetUnderPointer,{connecting:!0}):this._magnetUnderPointer=null):this._magnetUnderPointer=null),this._targetEvent=w,this.model.set(this._arrowhead,{x:b,y:c},{ui:!0})}}this._dx=b,this._dy=c,joint.dia.CellView.prototype.pointermove.apply(this,arguments),this.notify("link:pointermove",a,b,c)},pointerup:function(a,b,c){if("label-move"===this._action)this._samples=null;else if("arrowhead-move"===this._action){var d=this.paper.options,e=this._arrowhead;if(d.snapLinks)this._closestView&&this._closestView.unhighlight(this._closestEnd.selector,{connecting:!0,snapping:!0}),this._closestView=this._closestEnd=null;else{var f=this._viewUnderPointer,g=this._magnetUnderPointer;if(this._viewUnderPointer=null,this._magnetUnderPointer=null,g){f.unhighlight(g,{connecting:!0});var h=f.getSelector(g),i=g.getAttribute("port"),j={id:f.model.id};null!=h&&(j.port=i),null!=i&&(j.selector=h),this.model.set(e,j,{ui:!0})}}if(!this.paper.linkAllowed(this))switch(this._whenNotAllowed){case"remove":this.model.remove();break;case"revert":default:this.model.set(e,this._initialEnd,{ui:!0})}d.embeddingMode&&this.model.reparent()&&(this._z=null),this._afterArrowheadMove()}this._action=null,this._whenNotAllowed=null,this.notify("link:pointerup",a,b,c),joint.dia.CellView.prototype.pointerup.apply(this,arguments)}},{makeSelector:function(a){var b='[model-id="'+a.id+'"]';return a.port?b+=' [port="'+a.port+'"]':a.selector&&(b+=" "+a.selector),b}}),joint.dia.Paper=joint.mvc.View.extend({className:"paper",options:{width:800,height:600,origin:{x:0,y:0},gridSize:1,drawGrid:!1,perpendicularLinks:!1,elementView:joint.dia.ElementView,linkView:joint.dia.LinkView,snapLinks:!1,multiLinks:!0,guard:function(a,b){return!1},highlighting:{"default":{name:"stroke",options:{padding:3}},magnetAvailability:{name:"addClass",options:{className:"available-magnet"}},elementAvailability:{name:"addClass",options:{className:"available-cell"}}},preventContextMenu:!0,restrictTranslate:!1,markAvailable:!1,defaultLink:new joint.dia.Link,defaultConnector:{name:"normal"},defaultRouter:{name:"normal"},validateMagnet:function(a,b){return"passive"!==b.getAttribute("magnet")},validateConnection:function(a,b,c,d,e,f){return("target"===e?c:a)instanceof joint.dia.ElementView},embeddingMode:!1,validateEmbedding:function(a,b){return!0},findParentBy:"bbox",frontParentOnly:!0,interactive:{labelMove:!1},linkPinning:!0,clickThreshold:0,cellViewNamespace:joint.shapes,highlighterNamespace:joint.highlighters},events:{mousedown:"pointerdown",dblclick:"mousedblclick",click:"mouseclick",touchstart:"pointerdown",touchend:"mouseclick",touchmove:"pointermove",mousemove:"pointermove","mouseover .element":"cellMouseover","mouseover .link":"cellMouseover","mouseout .element":"cellMouseout","mouseout .link":"cellMouseout",contextmenu:"contextmenu",mousewheel:"mousewheel",DOMMouseScroll:"mousewheel"},_highlights:[],init:function(){_.bindAll(this,"pointerup"),this.model=this.options.model||new joint.dia.Graph,this.options.origin=_.clone(this.options.origin),this.options.defaultConnector=_.clone(this.options.defaultConnector),_.defaults(this.options.highlighting,this.constructor.prototype.options.highlighting),this.options.highlighting=_.cloneDeep(this.options.highlighting),this.svg=V("svg").node,this.viewport=V("g").addClass("viewport").node,this.defs=V("defs").node,V(this.svg).append([this.viewport,this.defs]),this.$el.append(this.svg),this.model.on("add",this.onCellAdded,this),this.model.on("remove",this.removeView,this),this.model.on("reset",this.resetViews,this),this.model.on("sort",this._onSort,this),this.model.on("batch:stop",this._onBatchStop,this),this.setOrigin(),this.setDimensions(),$(document).on("mouseup touchend",this.pointerup),this._mousemoved=0,this._views={},this.on("cell:highlight",this.onCellHighlight,this),this.on("cell:unhighlight",this.onCellUnhighlight,this)},_onSort:function(){this.model.hasActiveBatch("add")||this.sortViews()},_onBatchStop:function(a){var b=a&&a.batchName;"add"!==b||this.model.hasActiveBatch("add")||this.sortViews()},onRemove:function(){this.removeViews(),$(document).off("mouseup touchend",this.pointerup)},setDimensions:function(a,b){a=this.options.width=a||this.options.width,b=this.options.height=b||this.options.height,V(this.svg).attr({width:a,height:b}),this.trigger("resize",a,b)},setOrigin:function(a,b){this.options.origin.x=a||0,this.options.origin.y=b||0,V(this.viewport).translate(a,b,{absolute:!0}),this.trigger("translate",a,b),this.options.drawGrid&&this.drawGrid()},fitToContent:function(a,b,c,d){_.isObject(a)?(d=a,a=d.gridWidth||1,b=d.gridHeight||1,c=d.padding||0):(d=d||{},a=a||1,b=b||1,c=c||0),c=joint.util.normalizeSides(c);var e=V(this.viewport).bbox(!0,this.svg),f=V(this.viewport).scale();e.x*=f.sx,e.y*=f.sy,e.width*=f.sx,e.height*=f.sy;var g=Math.max(Math.ceil((e.width+e.x)/a),1)*a,h=Math.max(Math.ceil((e.height+e.y)/b),1)*b,i=0,j=0;("negative"==d.allowNewOrigin&&e.x<0||"positive"==d.allowNewOrigin&&e.x>=0||"any"==d.allowNewOrigin)&&(i=Math.ceil(-e.x/a)*a,i+=c.left,g+=i),("negative"==d.allowNewOrigin&&e.y<0||"positive"==d.allowNewOrigin&&e.y>=0||"any"==d.allowNewOrigin)&&(j=Math.ceil(-e.y/b)*b,j+=c.top,h+=j),g+=c.right,h+=c.bottom,g=Math.max(g,d.minWidth||0),h=Math.max(h,d.minHeight||0),g=Math.min(g,d.maxWidth||Number.MAX_VALUE),h=Math.min(h,d.maxHeight||Number.MAX_VALUE);var k=g!=this.options.width||h!=this.options.height,l=i!=this.options.origin.x||j!=this.options.origin.y;l&&this.setOrigin(i,j),k&&this.setDimensions(g,h)},scaleContentToFit:function(a){var b=this.getContentBBox();if(b.width&&b.height){a=a||{},_.defaults(a,{padding:0,preserveAspectRatio:!0,scaleGrid:null,minScale:0,maxScale:Number.MAX_VALUE});var c=a.padding,d=a.minScaleX||a.minScale,e=a.maxScaleX||a.maxScale,f=a.minScaleY||a.minScale,h=a.maxScaleY||a.maxScale,i=a.fittingBBox||{x:this.options.origin.x,y:this.options.origin.y,width:this.options.width,height:this.options.height};i=g.rect(i).moveAndExpand({x:c,y:c,width:-2*c,height:-2*c});var j=V(this.viewport).scale(),k=i.width/b.width*j.sx,l=i.height/b.height*j.sy;if(a.preserveAspectRatio&&(k=l=Math.min(k,l)),a.scaleGrid){var m=a.scaleGrid;k=m*Math.floor(k/m),l=m*Math.floor(l/m)}k=Math.min(e,Math.max(d,k)),l=Math.min(h,Math.max(f,l)),this.scale(k,l);var n=this.getContentBBox(),o=i.x-n.x,p=i.y-n.y;this.setOrigin(o,p)}},getContentBBox:function(){var a=this.viewport.getBoundingClientRect(),b=this.viewport.getScreenCTM(),c=this.viewport.getCTM();return g.rect({x:a.left-b.e+c.e,y:a.top-b.f+c.f,width:a.width,height:a.height})},getArea:function(){var a=this.viewport.getCTM().inverse(),b={x:0,y:0,width:this.options.width,height:this.options.height};return g.rect(V.transformRect(b,a))},getRestrictedArea:function(){var a;return a=_.isFunction(this.options.restrictTranslate)?this.options.restrictTranslate.apply(this,arguments):this.options.restrictTranslate===!0?this.getArea():this.options.restrictTranslate||null},createViewForModel:function(a){var b,c,d=this.options.cellViewNamespace,e=a.get("type")+"View",f=joint.util.getByPath(d,e,".");a.isLink()?(b=this.options.linkView,c=joint.dia.LinkView):(b=this.options.elementView,c=joint.dia.ElementView);var g=b.prototype instanceof Backbone.View?f||b:b.call(this,a)||f||c;return new g({model:a,interactive:this.options.interactive})},onCellAdded:function(a,b,c){if(this.options.async&&c.async!==!1&&_.isNumber(c.position)){if(this._asyncCells=this._asyncCells||[],this._asyncCells.push(a),0==c.position){if(this._frameId)throw new Error("another asynchronous rendering in progress");this.asyncRenderViews(this._asyncCells,c),delete this._asyncCells}}else this.renderView(a)},removeView:function(a){var b=this._views[a.id];return b&&(b.remove(),delete this._views[a.id]),b},renderView:function(a){var b=this._views[a.id]=this.createViewForModel(a);return V(this.viewport).append(b.el),b.paper=this,b.render(),$(b.el).find("image").on("dragstart",function(){return!1}),b},beforeRenderViews:function(a){return a.sort(function(a){return a instanceof joint.dia.Link?1:-1}),a},afterRenderViews:function(){this.sortViews()},resetViews:function(a,b){this.removeViews();var c=a.models.slice();c=this.beforeRenderViews(c,b)||c,this._frameId&&(joint.util.cancelFrame(this._frameId),delete this._frameId),this.options.async?this.asyncRenderViews(c,b):(_.each(c,this.renderView,this),this.sortViews())},removeViews:function(){_.invoke(this._views,"remove"),this._views={}},asyncBatchAdded:_.noop,asyncRenderViews:function(a,b){if(this._frameId){var c=this.options.async&&this.options.async.batchSize||50,d=a.splice(0,c),e=this.model.get("cells");_.each(d,function(a){a.collection===e&&this.renderView(a)},this),this.asyncBatchAdded()}a.length?this._frameId=joint.util.nextFrame(function(){this.asyncRenderViews(a,b)},this):(delete this._frameId,this.afterRenderViews(b),this.trigger("render:done",b))},sortViews:function(){var a=$(this.viewport).children("[model-id]"),b=this.model.get("cells");joint.util.sortElements(a,function(a,c){var d=b.get($(a).attr("model-id")),e=b.get($(c).attr("model-id"));return(d.get("z")||0)>(e.get("z")||0)?1:-1})},scale:function(a,b,c,d){b=b||a,_.isUndefined(c)&&(c=0,d=0),V(this.viewport).attr("transform","");var e=this.options.origin.x,f=this.options.origin.y;if(c||d||e||f){var g=e-c*(a-1),h=f-d*(b-1);this.setOrigin(g,h)}return V(this.viewport).scale(a,b),this.trigger("scale",a,b,c,d),this.options.drawGrid&&this.drawGrid(),this},rotate:function(a,b,c){if(_.isUndefined(b)){var d=this.viewport.getBBox();b=d.width/2,c=d.height/2}V(this.viewport).rotate(a,b,c)},findView:function(a){for(var b=_.isString(a)?this.viewport.querySelector(a):a instanceof $?a[0]:a;b&&b!==this.el&&b!==document;){var c=b.getAttribute("model-id");if(c)return this._views[c];b=b.parentNode}},findViewByModel:function(a){var b=_.isString(a)?a:a.id;return this._views[b]},findViewsFromPoint:function(a){a=g.point(a);var b=_.map(this.model.getElements(),this.findViewByModel,this);return _.filter(b,function(b){return b&&g.rect(b.vel.bbox(!1,this.viewport)).containsPoint(a)},this)},findViewsInArea:function(a,b){b=_.defaults(b||{},{strict:!1}),a=g.rect(a);var c=_.map(this.model.getElements(),this.findViewByModel,this),d=b.strict?"containsRect":"intersect";return _.filter(c,function(b){return b&&a[d](g.rect(b.vel.bbox(!1,this.viewport)))},this)},getModelById:function(a){return this.model.getCell(a)},snapToGrid:function(a){var b=V(this.viewport).toLocalPoint(a.x,a.y);return{x:g.snapToGrid(b.x,this.options.gridSize),y:g.snapToGrid(b.y,this.options.gridSize)}},clientToLocalPoint:function(a){a=g.point(a);var b=V("rect",{width:this.options.width,height:this.options.height,x:0,y:0,opacity:0});V(this.svg).prepend(b);var c=$(this.svg).offset();b.remove();var d=document.body.scrollTop||document.documentElement.scrollTop,e=document.body.scrollLeft||document.documentElement.scrollLeft;return a.offset(e-c.left,d-c.top),V.transformPoint(a,this.viewport.getCTM().inverse())},linkAllowed:function(a){var b;if(a instanceof joint.dia.Link)b=a;else{if(!(a instanceof joint.dia.LinkView))throw new Error("Must provide link model or view.");b=a.model}if(!this.options.multiLinks){var c=b.get("source"),d=b.get("target");if(c.id&&d.id){var e=b.getSourceElement();if(e){var f=this.model.getConnectedLinks(e,{outbound:!0,inbound:!1}),g=_.filter(f,function(a){var b=a.get("source"),e=a.get("target");return b&&b.id===c.id&&(!b.port||b.port===c.port)&&e&&e.id===d.id&&(!e.port||e.port===d.port)}).length;if(g>1)return!1}}}return!!(this.options.linkPinning||_.has(b.get("source"),"id")&&_.has(b.get("target"),"id"))},getDefaultLink:function(a,b){return _.isFunction(this.options.defaultLink)?this.options.defaultLink.call(this,a,b):this.options.defaultLink.clone()},resolveHighlighter:function(a){a=a||{};var b=a.highlighter,c=this.options;if(_.isUndefined(b)){var d=_.chain(a).pick("embedding","connecting","magnetAvailability","elementAvailability").keys().first().value();b=d&&c.highlighting[d]||c.highlighting["default"]}if(!b)return!1;var e=b.name,f=c.highlighterNamespace[e];if(!f)throw new Error('Unknown highlighter ("'+e+'")');if("function"!=typeof f.highlight)throw new Error('Highlighter ("'+e+'") is missing required highlight() method');if("function"!=typeof f.unhighlight)throw new Error('Highlighter ("'+e+'") is missing required unhighlight() method');return{highlighter:f,options:b.options,name:e}},onCellHighlight:function(a,b,c){if(c=this.resolveHighlighter(c)){var d=c.name+b.id+JSON.stringify(c.options);if(!this._highlights[d]){var e=c.highlighter;e.highlight(a,b,_.clone(c.options)),this._highlights[d]={cellView:a,magnetEl:b,opt:c.options,highlighter:e}}}},onCellUnhighlight:function(a,b,c){if(c=this.resolveHighlighter(c)){var d=c.name+b.id+JSON.stringify(c.options),e=this._highlights[d];e&&(e.highlighter.unhighlight(e.cellView,e.magnetEl,e.opt),this._highlights[d]=null)}},mousedblclick:function(a){a.preventDefault(),a=joint.util.normalizeEvent(a);var b=this.findView(a.target);if(!this.guard(a,b)){var c=this.snapToGrid({x:a.clientX,y:a.clientY});b?b.pointerdblclick(a,c.x,c.y):this.trigger("blank:pointerdblclick",a,c.x,c.y)}},mouseclick:function(a){if(this._mousemoved<=this.options.clickThreshold){a=joint.util.normalizeEvent(a);var b=this.findView(a.target);if(this.guard(a,b))return;var c=this.snapToGrid({x:a.clientX,y:a.clientY});b?b.pointerclick(a,c.x,c.y):this.trigger("blank:pointerclick",a,c.x,c.y)}},guard:function(a,b){return this.options.guard&&this.options.guard(a,b)?!0:b&&b.model&&b.model instanceof joint.dia.Cell?!1:this.svg!==a.target&&this.el!==a.target&&!$.contains(this.svg,a.target)},contextmenu:function(a){a=joint.util.normalizeEvent(a),this.options.preventContextMenu&&a.preventDefault();var b=this.findView(a.target);if(!this.guard(a,b)){var c=this.snapToGrid({x:a.clientX,y:a.clientY});b?b.contextmenu(a,c.x,c.y):this.trigger("blank:contextmenu",a,c.x,c.y)}},pointerdown:function(a){a=joint.util.normalizeEvent(a);var b=this.findView(a.target);if(!this.guard(a,b)){a.preventDefault(),this._mousemoved=0;var c=this.snapToGrid({x:a.clientX,y:a.clientY});b?(this.sourceView=b,b.pointerdown(a,c.x,c.y)):this.trigger("blank:pointerdown",a,c.x,c.y)}},pointermove:function(a){if(a.preventDefault(),a=joint.util.normalizeEvent(a),this.sourceView){this._mousemoved++;var b=this.snapToGrid({x:a.clientX,y:a.clientY});this.sourceView.pointermove(a,b.x,b.y)}},pointerup:function(a){a=joint.util.normalizeEvent(a);var b=this.snapToGrid({x:a.clientX,y:a.clientY});this.sourceView?(this.sourceView.pointerup(a,b.x,b.y),this.sourceView=null):this.trigger("blank:pointerup",a,b.x,b.y)},mousewheel:function(a){a=joint.util.normalizeEvent(a);var b=this.findView(a.target);if(!this.guard(a,b)){var c=a.originalEvent,d=this.snapToGrid({x:c.clientX,y:c.clientY}),e=Math.max(-1,Math.min(1,c.wheelDelta||-c.detail));b?b.mousewheel(a,d.x,d.y,e):this.trigger("blank:mousewheel",a,d.x,d.y,e)}},cellMouseover:function(a){a=joint.util.normalizeEvent(a);var b=this.findView(a.target);if(b){if(this.guard(a,b))return;b.mouseover(a)}},cellMouseout:function(a){a=joint.util.normalizeEvent(a);var b=this.findView(a.target);if(b){if(this.guard(a,b))return;b.mouseout(a)}},setGridSize:function(a){return this.options.gridSize=a,this.options.drawGrid&&this.drawGrid(),this},drawGrid:function(a){a=a||{},_.defaults(a,this.options.drawGrid,{color:"#aaa",thickness:1});var b=this.options.gridSize;if(1>=b)return void(this.el.style.backgroundImage="none");var c=V(this.viewport).scale(),d=c.sx,e=c.sy,f=this.options.origin.x,g=this.options.origin.y,h=b*d,i=b*e,j=document.createElement("canvas");j.width=h,j.height=i,h=f>=0?f%h:h+f%h,i=g>=0?g%i:i+g%i;var k=j.getContext("2d");k.beginPath(),k.rect(h,i,a.thickness*d,a.thickness*e),k.fillStyle=a.color,k.fill();var l=j.toDataURL("image/png");this.el.style.backgroundImage='url("'+l+'")'}}),joint.shapes.basic={},joint.shapes.basic.Generic=joint.dia.Element.extend({defaults:joint.util.deepSupplement({type:"basic.Generic",attrs:{".":{fill:"#ffffff",stroke:"none"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.basic.Rect=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><rect/></g><text/></g>',defaults:joint.util.deepSupplement({type:"basic.Rect",attrs:{rect:{fill:"#ffffff",stroke:"#000000",width:100,height:60},text:{fill:"#000000",text:"","font-size":14,"ref-x":.5,"ref-y":.5,"text-anchor":"middle","y-alignment":"middle","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.TextView=joint.dia.ElementView.extend({initialize:function(){joint.dia.ElementView.prototype.initialize.apply(this,arguments),this.listenTo(this.model,"change:attrs",this.resize)}}),joint.shapes.basic.Text=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><text/></g></g>',defaults:joint.util.deepSupplement({type:"basic.Text",attrs:{text:{"font-size":18,fill:"#000000"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Circle=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><circle/></g><text/></g>',defaults:joint.util.deepSupplement({type:"basic.Circle",size:{width:60,height:60},attrs:{circle:{fill:"#ffffff",stroke:"#000000",r:30,cx:30,cy:30},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-y":.5,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Ellipse=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><ellipse/></g><text/></g>',defaults:joint.util.deepSupplement({type:"basic.Ellipse",size:{width:60,height:40},attrs:{ellipse:{fill:"#ffffff",stroke:"#000000",rx:30,ry:20,cx:30,cy:20},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-y":.5,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Polygon=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><polygon/></g><text/></g>',defaults:joint.util.deepSupplement({type:"basic.Polygon",size:{width:60,height:40},attrs:{polygon:{fill:"#ffffff",stroke:"#000000"},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-dy":20,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Polyline=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><polyline/></g><text/></g>',defaults:joint.util.deepSupplement({type:"basic.Polyline",size:{width:60,height:40},attrs:{polyline:{fill:"#ffffff",stroke:"#000000"},text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-dy":20,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Image=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><image/></g><text/></g>',defaults:joint.util.deepSupplement({type:"basic.Image",attrs:{text:{"font-size":14,text:"","text-anchor":"middle","ref-x":.5,"ref-dy":20,"y-alignment":"middle",fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Path=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><path/></g><text/></g>',defaults:joint.util.deepSupplement({type:"basic.Path",size:{width:60,height:60},attrs:{path:{fill:"#ffffff",stroke:"#000000"},text:{"font-size":14,text:"","text-anchor":"middle",ref:"path","ref-x":.5,"ref-dy":10,fill:"#000000","font-family":"Arial, helvetica, sans-serif"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.basic.Rhombus=joint.shapes.basic.Path.extend({defaults:joint.util.deepSupplement({type:"basic.Rhombus",attrs:{path:{d:"M 30 0 L 60 30 30 60 0 30 z"},text:{"ref-y":.5,"y-alignment":"middle"}}},joint.shapes.basic.Path.prototype.defaults)}),joint.shapes.basic.PortsModelInterface={initialize:function(){this.updatePortsAttrs(),this.on("change:inPorts change:outPorts",this.updatePortsAttrs,this),this.constructor.__super__.constructor.__super__.initialize.apply(this,arguments)},updatePortsAttrs:function(a){if(this._portSelectors){var b=_.omit(this.get("attrs"),this._portSelectors);this.set("attrs",b,{silent:!0})}this._portSelectors=[];var c={};_.each(this.get("inPorts"),function(a,b,d){var e=this.getPortAttrs(a,b,d.length,".inPorts","in");this._portSelectors=this._portSelectors.concat(_.keys(e)),_.extend(c,e)},this),_.each(this.get("outPorts"),function(a,b,d){var e=this.getPortAttrs(a,b,d.length,".outPorts","out");this._portSelectors=this._portSelectors.concat(_.keys(e)),_.extend(c,e)},this),this.attr(c,{silent:!0}),this.processPorts(),this.trigger("process:ports")},getPortSelector:function(a){var b=".inPorts",c=this.get("inPorts").indexOf(a);if(0>c&&(b=".outPorts",c=this.get("outPorts").indexOf(a),0>c))throw new Error("getPortSelector(): Port doesn't exist.");return b+">g:nth-child("+(c+1)+")>.port-body"}},joint.shapes.basic.PortsViewInterface={initialize:function(){this.listenTo(this.model,"process:ports",this.update),joint.dia.ElementView.prototype.initialize.apply(this,arguments)},update:function(){this.renderPorts(),joint.dia.ElementView.prototype.update.apply(this,arguments)},renderPorts:function(){var a=this.$(".inPorts").empty(),b=this.$(".outPorts").empty(),c=joint.util.template(this.model.portMarkup);_.each(_.filter(this.model.ports,function(a){return"in"===a.type}),function(b,d){a.append(V(c({id:d,port:b})).node)}),_.each(_.filter(this.model.ports,function(a){return"out"===a.type}),function(a,d){b.append(V(c({id:d,port:a})).node)})}},joint.shapes.basic.TextBlock=joint.shapes.basic.Generic.extend({markup:['<g class="rotatable">','<g class="scalable"><rect/></g>',joint.env.test("svgforeignobject")?'<foreignObject class="fobj"><body xmlns="http://www.w3.org/1999/xhtml"><div class="content"/></body></foreignObject>':'<text class="content"/>',"</g>"].join(""),defaults:joint.util.deepSupplement({type:"basic.TextBlock",attrs:{rect:{fill:"#ffffff",stroke:"#000000",width:80,height:100},text:{fill:"#000000","font-size":14,"font-family":"Arial, helvetica, sans-serif"},".content":{text:"",ref:"rect","ref-x":.5,"ref-y":.5,"y-alignment":"middle","x-alignment":"middle"}},content:""},joint.shapes.basic.Generic.prototype.defaults),initialize:function(){this.listenTo(this,"change:size",this.updateSize),this.listenTo(this,"change:content",this.updateContent),this.updateSize(this,this.get("size")),this.updateContent(this,this.get("content")),joint.shapes.basic.Generic.prototype.initialize.apply(this,arguments)},updateSize:function(a,b){this.attr({".fobj":_.clone(b),div:{style:_.clone(b)}})},updateContent:function(a,b){joint.env.test("svgforeignobject")?this.attr({".content":{html:b}}):this.attr({".content":{text:b}})},setForeignObjectSize:function(){this.updateSize.apply(this,arguments)},setDivContent:function(){this.updateContent.apply(this,arguments)}}),joint.shapes.basic.TextBlockView=joint.dia.ElementView.extend({initialize:function(){joint.dia.ElementView.prototype.initialize.apply(this,arguments),this.noSVGForeignObjectElement=!joint.env.test("svgforeignobject"),
|
joint.env.test("svgforeignobject")||this.listenTo(this.model,"change:content",function(a){this.updateContent(a)})},update:function(a,b){if(joint.env.test("svgforeignobject")){var c=this.model,d=_.omit(b||c.get("attrs"),".content");joint.dia.ElementView.prototype.update.call(this,c,d),b&&!_.has(b,".content")||this.updateContent(c,b)}else joint.dia.ElementView.prototype.update.call(this,c,b)},updateContent:function(a,b){var c=_.merge({},(b||a.get("attrs"))[".content"]);c=_.omit(c,"text");var d=joint.util.breakText(a.get("content"),a.get("size"),c,{svgDocument:this.paper.svg}),e=joint.util.setByPath({},".content",c,"/");e[".content"].text=d,joint.dia.ElementView.prototype.update.call(this,a,e)}}),joint.routers.manhattan=function(a,b){"use strict";function c(a){this.map={},this.options=a,this.mapGridSize=100}function d(){this.items=[],this.hash={},this.values={},this.OPEN=1,this.CLOSE=2}function e(a,b){for(var c,d=[],e={x:0,y:0},f=b;c=a[f];){var g=c.difference(f);g.equals(e)||(d.unshift(f),e=g),f=c}return d.unshift(f),d}function f(a,c,d){var e=d.step,f=a.center(),g=b.chain(d.directionMap).pick(c).map(function(b){var c=b.x*a.width/2,d=b.y*a.height/2,g=f.clone().offset(c,d);return a.containsPoint(g)&&g.offset(b.x*e,b.y*e),g.snapToGrid(e)}).value();return g}function g(b,c,d){var e=360/d;return Math.floor(a.normalizeAngle(b.theta(c)+e/2)/e)*e}function h(a,b){var c=Math.abs(a-b);return c>180?360-c:c}function i(a,b){for(var c=1/0,d=0,e=b.length;e>d;d++){var f=a.manhattanDistance(b[d]);c>f&&(c=f)}return c}function j(c,j,k,l){var m,n,o,p,q=l.step;if(c instanceof a.rect?(m=f(c,l.startDirections,l),o=c.center()):(o=c.clone().snapToGrid(q),m=[o]),j instanceof a.rect?(n=f(j,l.endDirections,l),p=j.center()):(p=j.clone().snapToGrid(q),n=[p]),m=b.filter(m,k.isPointAccessible,k),n=b.filter(n,k.isPointAccessible,k),m.length>0&&n.length>0){var r=new d,s={},t={};b.each(m,function(a){var b=a.toString();r.add(b,i(a,n)),t[b]=0});for(var u,v,w=l.directions,x=w.length,y=l.maximumLoops,z=b.invoke(n,"toString");!r.isEmpty()&&y>0;){var A=r.pop(),B=a.point(A),C=t[A],D=s[A]?g(s[A],B,x):null!=l.previousDirAngle?l.previousDirAngle:g(o,B,x);if(z.indexOf(A)>=0&&(v=h(D,g(B,p,x)),B.equals(p)||180>v))return l.previousDirAngle=D,e(s,B);for(var E=0;x>E;E++)if(u=w[E],v=h(D,u.angle),!(v>l.maxAllowedDirectionChange)){var F=B.clone().offset(u.offsetX,u.offsetY),G=F.toString();if(!r.isClose(G)&&k.isPointAccessible(F)){var H=C+u.cost+l.penalties[v];(!r.isOpen(G)||H<t[G])&&(s[G]=B,t[G]=H,r.add(G,H+i(F,n)))}}y--}}return l.fallbackRoute(o,p,l)}function k(c){c.directions=b.result(c,"directions"),c.penalties=b.result(c,"penalties"),c.paddingBox=b.result(c,"paddingBox"),b.each(c.directions,function(b){var c=new a.point(0,0),d=new a.point(b.offsetX,b.offsetY),e=a.normalizeAngle(c.theta(d));b.angle=e})}function l(d,e){k(e),this.options.perpendicular=!!e.perpendicular;for(var f=a.rect(this.sourceBBox).moveAndExpand(e.paddingBox),g=a.rect(this.targetBBox).moveAndExpand(e.paddingBox),h=new c(e).build(this.paper.model,this.model),i=b.map(d,a.point),l=[],m=f.center().snapToGrid(e.step),n=0,o=i.length;o>=n;n++){var p=null,q=r||f,r=i[n];if(!r){r=g;var s=!this.model.get("source").id||!this.model.get("target").id;if(s&&b.isFunction(e.draggingRoute)){var t=q instanceof a.rect?q.center():q;p=e.draggingRoute(t,r.origin(),e)}}p=p||j(q,r,h,e);var u=b.first(p);u&&u.equals(m)&&p.shift(),m=b.last(p)||m,Array.prototype.push.apply(l,p)}return l}var m={step:10,perpendicular:!0,excludeEnds:[],excludeTypes:["basic.Text"],maximumLoops:2e3,startDirections:["left","right","top","bottom"],endDirections:["left","right","top","bottom"],directionMap:{right:{x:1,y:0},bottom:{x:0,y:1},left:{x:-1,y:0},top:{x:0,y:-1}},maxAllowedDirectionChange:90,paddingBox:function(){var a=this.step;return{x:-a,y:-a,width:2*a,height:2*a}},directions:function(){var a=this.step;return[{offsetX:a,offsetY:0,cost:a},{offsetX:0,offsetY:a,cost:a},{offsetX:-a,offsetY:0,cost:a},{offsetX:0,offsetY:-a,cost:a}]},penalties:function(){return{0:0,45:this.step/2,90:this.step/2}},fallbackRoute:function(b,c,d){var e=(d.previousDirAngle||0)%180===0?a.point(b.x,c.y):a.point(c.x,b.y);return[e,c]},draggingRoute:null};return c.prototype.build=function(a,c){var d=this.options,e=b.chain(d.excludeEnds).map(c.get,c).pluck("id").map(a.getCell,a).value(),f=[],g=a.getCell(c.get("source").id);g&&(f=b.union(f,b.map(g.getAncestors(),"id")));var h=a.getCell(c.get("target").id);h&&(f=b.union(f,b.map(h.getAncestors(),"id")));var i=this.mapGridSize;return b.chain(a.getElements()).difference(e).reject(function(a){return b.contains(d.excludeTypes,a.get("type"))||b.contains(f,a.id)}).invoke("getBBox").invoke("moveAndExpand",d.paddingBox).foldl(function(a,b){for(var c=b.origin().snapToGrid(i),d=b.corner().snapToGrid(i),e=c.x;e<=d.x;e+=i)for(var f=c.y;f<=d.y;f+=i){var g=e+"@"+f;a[g]=a[g]||[],a[g].push(b)}return a},this.map).value(),this},c.prototype.isPointAccessible=function(a){var c=a.clone().snapToGrid(this.mapGridSize).toString();return b.every(this.map[c],function(b){return!b.containsPoint(a)})},d.prototype.add=function(a,c){this.hash[a]?this.items.splice(this.items.indexOf(a),1):this.hash[a]=this.OPEN,this.values[a]=c;var d=b.sortedIndex(this.items,a,function(a){return this.values[a]},this);this.items.splice(d,0,a)},d.prototype.remove=function(a){this.hash[a]=this.CLOSE},d.prototype.isOpen=function(a){return this.hash[a]===this.OPEN},d.prototype.isClose=function(a){return this.hash[a]===this.CLOSE},d.prototype.isEmpty=function(){return 0===this.items.length},d.prototype.pop=function(){var a=this.items.shift();return this.remove(a),a},function(a,c,d){return l.call(d,a,b.extend({},m,c))}}(g,_),joint.routers.metro=function(){if(!_.isFunction(joint.routers.manhattan))throw"Metro requires the manhattan router.";var a={diagonalCost:null,directions:function(){var a=this.step,b=this.diagonalCost||Math.ceil(Math.sqrt(a*a<<1));return[{offsetX:a,offsetY:0,cost:a},{offsetX:a,offsetY:a,cost:b},{offsetX:0,offsetY:a,cost:a},{offsetX:-a,offsetY:a,cost:b},{offsetX:-a,offsetY:0,cost:a},{offsetX:-a,offsetY:-a,cost:b},{offsetX:0,offsetY:-a,cost:a},{offsetX:a,offsetY:-a,cost:b}]},maxAllowedDirectionChange:45,fallbackRoute:function(a,b,c){var d=a.theta(b),e={x:b.x,y:a.y},f={x:a.x,y:b.y};if(d%180>90){var h=e;e=f,f=h}var i=45>d%90?e:f,j=g.line(a,i),k=90*Math.ceil(d/90),l=g.point.fromPolar(j.squaredLength(),g.toRad(k+135),i),m=g.line(b,l),n=j.intersection(m);return n?[n.round(),b]:[b]}};return function(b,c,d){return joint.routers.manhattan(b,_.extend({},a,c),d)}}(),joint.routers.normal=function(a,b,c){return a},joint.routers.oneSide=function(a,b,c){var d,e,f,g=b.side||"bottom",h=b.padding||40,i=c.sourceBBox,j=c.targetBBox,k=i.center(),l=j.center();switch(g){case"bottom":f=1,d="y",e="height";break;case"top":f=-1,d="y",e="height";break;case"left":f=-1,d="x",e="width";break;case"right":f=1,d="x",e="width";break;default:throw new Error("Router: invalid side")}return k[d]+=f*(i[e]/2+h),l[d]+=f*(j[e]/2+h),f*(k[d]-l[d])>0?l[d]=k[d]:k[d]=l[d],[k].concat(a,l)},joint.routers.orthogonal=function(){function a(a,b){return a.x==b.x?a.y>b.y?"N":"S":a.y==b.y?a.x>b.x?"W":"E":null}function b(a,b){return a["W"==b||"E"==b?"width":"height"]}function c(a,b){return g.rect(a).moveAndExpand({x:-b,y:-b,width:2*b,height:2*b})}function d(a){return g.rect(a.x,a.y,0,0)}function e(a,b){var c=Math.min(a.x,b.x),d=Math.min(a.y,b.y),e=Math.max(a.x+a.width,b.x+b.width),f=Math.max(a.y+a.height,b.y+b.height);return g.rect(c,d,e-c,f-d)}function f(a,b,c){var d=g.point(a.x,b.y);return c.containsPoint(d)&&(d=g.point(b.x,a.y)),d}function h(b,c,d){var e=g.point(b.x,c.y),f=g.point(c.x,b.y),h=a(b,e),i=a(b,f),j=n[d],k=h==d||h!=j&&(i==j||i!=d)?e:f;return{points:[k],direction:a(k,c)}}function i(b,c,d){var e=f(b,c,d);return{points:[e],direction:a(e,c)}}function j(c,d,e,h){var i,j={},k=[g.point(c.x,d.y),g.point(d.x,c.y)],l=_.filter(k,function(a){return!e.containsPoint(a)}),m=_.filter(l,function(b){return a(b,c)!=h});if(m.length>0)i=_.filter(m,function(b){return a(c,b)==h}).pop(),i=i||m[0],j.points=[i],j.direction=a(i,d);else{i=_.difference(k,l)[0];var n=g.point(d).move(i,-b(e,h)/2),o=f(n,c,e);j.points=[o,n],j.direction=a(n,d)}return j}function k(c,d,e,f){var j=i(d,c,f),k=j.points[0];if(e.containsPoint(k)){j=i(c,d,e);var l=j.points[0];if(f.containsPoint(l)){var m=g.point(c).move(l,-b(e,a(c,l))/2),n=g.point(d).move(k,-b(f,a(d,k))/2),o=g.line(m,n).midpoint(),p=i(c,o,e),q=h(o,d,p.direction);j.points=[p.points[0],q.points[0]],j.direction=q.direction}}return j}function l(b,d,h,i,j){var k,l,m,n={},p=c(e(h,i),1),q=p.center().distance(d)>p.center().distance(b),r=q?d:b,s=q?b:d;return j?(k=g.point.fromPolar(p.width+p.height,o[j],r),k=p.pointNearestToPoint(k).move(k,-1)):k=p.pointNearestToPoint(r).move(r,1),l=f(k,s,p),k.round().equals(l.round())?(l=g.point.fromPolar(p.width+p.height,g.toRad(k.theta(r))+Math.PI/2,s),l=p.pointNearestToPoint(l).move(s,1).round(),m=f(k,l,p),n.points=q?[l,m,k]:[k,m,l]):n.points=q?[l,k]:[k,l],n.direction=q?a(k,d):a(l,d),n}function m(b,e,f){var m=e.elementPadding||20,n=[],o=c(f.sourceBBox,m),p=c(f.targetBBox,m);b=_.map(b,g.point),b.unshift(o.center()),b.push(p.center());for(var q,r=0,s=b.length-1;s>r;r++){var t=null,u=b[r],v=b[r+1],w=!!a(u,v);if(0==r)r+1==s?o.intersect(c(p,1))?t=l(u,v,o,p):w||(t=k(u,v,o,p)):o.containsPoint(v)?t=l(u,v,o,c(d(v),m)):w||(t=i(u,v,o));else if(r+1==s){var x=w&&a(v,u)==q;p.containsPoint(u)||x?t=l(u,v,c(d(u),m),p,q):w||(t=j(u,v,p,q))}else w||(t=h(u,v,q));t?(Array.prototype.push.apply(n,t.points),q=t.direction):q=a(u,v),s>r+1&&n.push(v)}return n}var n={N:"S",S:"N",E:"W",W:"E"},o={N:-Math.PI/2*3,S:-Math.PI/2,E:0,W:Math.PI};return m}(),joint.connectors.normal=function(a,b,c){var d=["M",a.x,a.y];return _.each(c,function(a){d.push(a.x,a.y)}),d.push(b.x,b.y),d.join(" ")},joint.connectors.rounded=function(a,b,c,d){d=d||{};var e,f,h,i,j,k,l=d.radius||10,m=["M",a.x,a.y];return _.each(c,function(d,n){j=c[n-1]||a,k=c[n+1]||b,h=i||g.point(d).distance(j)/2,i=g.point(d).distance(k)/2,e=g.point(d).move(j,-Math.min(l,h)).round(),f=g.point(d).move(k,-Math.min(l,i)).round(),m.push(e.x,e.y,"S",d.x,d.y,f.x,f.y,"L")}),m.push(b.x,b.y),m.join(" ")},joint.connectors.smooth=function(a,b,c){var d;if(c.length)d=g.bezier.curveThroughPoints([a].concat(c).concat([b]));else{var e=a.x<b.x?b.x-(b.x-a.x)/2:a.x-(a.x-b.x)/2;d=["M",a.x,a.y,"C",e,a.y,e,b.y,b.x,b.y]}return d.join(" ")},joint.connectors.jumpover=function(a,b){function c(a,c,d){var e=[].concat(a,d,c);return e.reduce(function(a,c,d){var f=e[d+1];return null!=f&&(a[d]=b.line(c,f)),a},[])}function d(a){var b=a.paper._jumpOverUpdateList;null==b&&(b=a.paper._jumpOverUpdateList=[],a.paper.on("cell:pointerup",e),a.paper.model.on("reset",function(){b=[]})),b.indexOf(a)<0&&(b.push(a),a.listenToOnce(a.model,"change:connector remove",function(){b.splice(b.indexOf(a),1)}))}function e(){for(var a=this._jumpOverUpdateList,b=0;b<a.length;b++)a[b].update()}function f(b,c){return a(c).map(function(a){return b.intersection(a)}).compact().value()}function g(a,c){return b.line(a,c).squaredLength()}function h(a,c,d){return c.reduce(function(e,f,g){if(f.skip===!0)return e;var h=e.pop()||a,i=b.point(f).move(h.start,-d),j=b.point(f).move(h.start,+d),k=c[g+1];if(null!=k){var m=j.distance(k);d>=m&&(j=k.move(h.start,m),k.skip=!0)}else{var n=i.distance(h.end);if(2*d+l>n)return e.push(h),e}var o=j.distance(h.start);if(2*d+l>o)return e.push(h),e;var p=b.line(i,j);return p.isJump=!0,e.push(b.line(h.start,i),p,b.line(j,h.end)),e},[])}function i(c,d,e){var f=["M",c[0].start.x,c[0].start.y],g=a(c).map(function(a){if(a.isJump){var c;if("arc"===e){c=a.start.difference(a.end);var f=Number(c.x<0&&c.y<0);return["A",d,d,0,0,f,a.end.x,a.end.y]}if("gap"===e)return["M",a.end.x,a.end.y];if("cubic"===e){c=a.start.difference(a.end);var g=a.start.theta(a.end),h=.6*d,i=1.35*d;c.x<0&&c.y<0&&(i*=-1);var j=b.point(a.start.x+h,a.start.y+i).rotate(a.start,g),k=b.point(a.end.x-h,a.end.y+i).rotate(a.end,g);return["C",j.x,j.y,k.x,k.y,a.end.x,a.end.y]}}return["L",a.end.x,a.end.y]}).flatten().value();return[].concat(f,g).join(" ")}var j=5,k=["arc","gap","cubic"],l=1,m=["smooth"];return function(b,e,l,n){d(this);var o=n.size||j,p=n.jump&&(""+n.jump).toLowerCase(),q=n.ignoreConnectors||m;-1===k.indexOf(p)&&(p=k[0]);var r=this.paper,s=r.model,t=s.getLinks();if(1===t.length)return i(c(b,e,l),o,p);var u=this.model,v=t.indexOf(u),w=r.options.defaultConnector||{},x=t.filter(function(b,c){var d=b.get("connector")||w;return a.contains(q,d.name)?!1:c>v?"jumpover"!==d.name:!0}),y=x.map(function(a){return r.findViewByModel(a)}),z=c(b,e,l),A=y.map(function(a){return null==a?[]:a===this?z:c(a.sourcePoint,a.targetPoint,a.route)},this),B=z.reduce(function(b,c){var d=a(x).map(function(a,b){return a===u?null:f(c,A[b])}).flatten().compact().sortBy(a.partial(g,c.start)).value();return d.length>0?b.push.apply(b,h(c,d,o)):b.push(c),b},[]);return i(B,o,p)}}(_,g),joint.highlighters.addClass={className:"highlighted",highlight:function(a,b,c){var d=c.className||this.className;V(b).addClass(d)},unhighlight:function(a,b,c){var d=c.className||this.className;V(b).removeClass(d)}},joint.highlighters.opacity={highlight:function(a,b,c){V(b).addClass("joint-highlight-opacity")},unhighlight:function(a,b,c){V(b).removeClass("joint-highlight-opacity")}},joint.highlighters.stroke={defaultOptions:{padding:3,rx:0,ry:0},_views:{},highlight:function(a,b,c){if(!this._views[b.id]){c=_.defaults(c||{},this.defaultOptions);var d=V(b),e=d.bbox(!0);try{var f=d.convertToPathData()}catch(g){f=V.rectToPath(_.extend({},c,e))}var h=V("path").attr({d:f,"class":"joint-highlight-stroke","pointer-events":"none"});h.transform(a.el.getCTM().inverse()),h.transform(b.getCTM());var i=c.padding;if(i){var j=e.x+e.width/2,k=e.y+e.height/2,l=(e.width+i)/e.width,m=(e.height+i)/e.height;h.transform({a:l,b:0,c:0,d:m,e:j-l*j,f:k-m*k})}var n=this._views[b.id]=new joint.mvc.View({el:h.node,$el:h});n.listenTo(a.model,"remove",n.remove),a.vel.append(h)}},unhighlight:function(a,b,c){c=_.defaults(c||{},this.defaultOptions),this._views[b.id]&&(this._views[b.id].remove(),this._views[b.id]=null)}};
|
joint.shapes.erd={},joint.shapes.erd.Entity=joint.dia.Element.extend({markup:'<g class="rotatable"><g class="scalable"><polygon class="outer"/><polygon class="inner"/></g><text/></g>',defaults:joint.util.deepSupplement({type:"erd.Entity",size:{width:150,height:60},attrs:{".outer":{fill:"#2ECC71",stroke:"#27AE60","stroke-width":2,points:"100,0 100,60 0,60 0,0"},".inner":{fill:"#2ECC71",stroke:"#27AE60","stroke-width":2,points:"95,5 95,55 5,55 5,5",display:"none"},text:{text:"Entity","font-family":"Arial","font-size":14,ref:".outer","ref-x":.5,"ref-y":.5,"x-alignment":"middle","y-alignment":"middle"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.erd.WeakEntity=joint.shapes.erd.Entity.extend({defaults:joint.util.deepSupplement({type:"erd.WeakEntity",attrs:{".inner":{display:"auto"},text:{text:"Weak Entity"}}},joint.shapes.erd.Entity.prototype.defaults)}),joint.shapes.erd.Relationship=joint.dia.Element.extend({markup:'<g class="rotatable"><g class="scalable"><polygon class="outer"/><polygon class="inner"/></g><text/></g>',defaults:joint.util.deepSupplement({type:"erd.Relationship",size:{width:80,height:80},attrs:{".outer":{fill:"#3498DB",stroke:"#2980B9","stroke-width":2,points:"40,0 80,40 40,80 0,40"},".inner":{fill:"#3498DB",stroke:"#2980B9","stroke-width":2,points:"40,5 75,40 40,75 5,40",display:"none"},text:{text:"Relationship","font-family":"Arial","font-size":12,ref:".","ref-x":.5,"ref-y":.5,"x-alignment":"middle","y-alignment":"middle"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.erd.IdentifyingRelationship=joint.shapes.erd.Relationship.extend({defaults:joint.util.deepSupplement({type:"erd.IdentifyingRelationship",attrs:{".inner":{display:"auto"},text:{text:"Identifying"}}},joint.shapes.erd.Relationship.prototype.defaults)}),joint.shapes.erd.Attribute=joint.dia.Element.extend({markup:'<g class="rotatable"><g class="scalable"><ellipse class="outer"/><ellipse class="inner"/></g><text/></g>',defaults:joint.util.deepSupplement({type:"erd.Attribute",size:{width:100,height:50},attrs:{ellipse:{transform:"translate(50, 25)"},".outer":{stroke:"#D35400","stroke-width":2,cx:0,cy:0,rx:50,ry:25,fill:"#E67E22"},".inner":{stroke:"#D35400","stroke-width":2,cx:0,cy:0,rx:45,ry:20,fill:"#E67E22",display:"none"},text:{"font-family":"Arial","font-size":14,ref:".","ref-x":.5,"ref-y":.5,"x-alignment":"middle","y-alignment":"middle"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.erd.Multivalued=joint.shapes.erd.Attribute.extend({defaults:joint.util.deepSupplement({type:"erd.Multivalued",attrs:{".inner":{display:"block"},text:{text:"multivalued"}}},joint.shapes.erd.Attribute.prototype.defaults)}),joint.shapes.erd.Derived=joint.shapes.erd.Attribute.extend({defaults:joint.util.deepSupplement({type:"erd.Derived",attrs:{".outer":{"stroke-dasharray":"3,5"},text:{text:"derived"}}},joint.shapes.erd.Attribute.prototype.defaults)}),joint.shapes.erd.Key=joint.shapes.erd.Attribute.extend({defaults:joint.util.deepSupplement({type:"erd.Key",attrs:{ellipse:{"stroke-width":4},text:{text:"key","font-weight":"800","text-decoration":"underline"}}},joint.shapes.erd.Attribute.prototype.defaults)}),joint.shapes.erd.Normal=joint.shapes.erd.Attribute.extend({defaults:joint.util.deepSupplement({type:"erd.Normal",attrs:{text:{text:"Normal"}}},joint.shapes.erd.Attribute.prototype.defaults)}),joint.shapes.erd.ISA=joint.dia.Element.extend({markup:'<g class="rotatable"><g class="scalable"><polygon/></g><text/></g>',defaults:joint.util.deepSupplement({type:"erd.ISA",size:{width:100,height:50},attrs:{polygon:{points:"0,0 50,50 100,0",fill:"#F1C40F",stroke:"#F39C12","stroke-width":2},text:{text:"ISA","font-size":18,ref:"polygon","ref-x":.5,"ref-y":.3,"x-alignment":"middle","y-alignment":"middle"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.erd.Line=joint.dia.Link.extend({defaults:{type:"erd.Line"},cardinality:function(a){this.set("labels",[{position:-20,attrs:{text:{dy:-8,text:a}}}])}});
|
joint.shapes.fsa={},joint.shapes.fsa.State=joint.shapes.basic.Circle.extend({defaults:joint.util.deepSupplement({type:"fsa.State",attrs:{circle:{"stroke-width":3},text:{"font-weight":"800"}}},joint.shapes.basic.Circle.prototype.defaults)}),joint.shapes.fsa.StartState=joint.dia.Element.extend({markup:'<g class="rotatable"><g class="scalable"><circle/></g></g>',defaults:joint.util.deepSupplement({type:"fsa.StartState",size:{width:20,height:20},attrs:{circle:{transform:"translate(10, 10)",r:10,fill:"#000000"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.fsa.EndState=joint.dia.Element.extend({markup:'<g class="rotatable"><g class="scalable"><circle class="outer"/><circle class="inner"/></g></g>',defaults:joint.util.deepSupplement({type:"fsa.EndState",size:{width:20,height:20},attrs:{".outer":{transform:"translate(10, 10)",r:10,fill:"#ffffff",stroke:"#000000"},".inner":{transform:"translate(10, 10)",r:6,fill:"#000000"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.fsa.Arrow=joint.dia.Link.extend({defaults:joint.util.deepSupplement({type:"fsa.Arrow",attrs:{".marker-target":{d:"M 10 0 L 0 5 L 10 10 z"}},smooth:!0},joint.dia.Link.prototype.defaults)});
|
joint.shapes.org={},joint.shapes.org.Member=joint.dia.Element.extend({markup:'<g class="rotatable"><g class="scalable"><rect class="card"/><image/></g><text class="rank"/><text class="name"/></g>',defaults:joint.util.deepSupplement({type:"org.Member",size:{width:180,height:70},attrs:{rect:{width:170,height:60},".card":{fill:"#FFFFFF",stroke:"#000000","stroke-width":2,"pointer-events":"visiblePainted",rx:10,ry:10},image:{width:48,height:48,ref:".card","ref-x":10,"ref-y":5},".rank":{"text-decoration":"underline",ref:".card","ref-x":.9,"ref-y":.2,"font-family":"Courier New","font-size":14,"text-anchor":"end"},".name":{"font-weight":"800",ref:".card","ref-x":.9,"ref-y":.6,"font-family":"Courier New","font-size":14,"text-anchor":"end"}}},joint.dia.Element.prototype.defaults)}),joint.shapes.org.Arrow=joint.dia.Link.extend({defaults:{type:"org.Arrow",source:{selector:".card"},target:{selector:".card"},attrs:{".connection":{stroke:"#585858","stroke-width":3}},z:-1}});
|
joint.shapes.chess={},joint.shapes.chess.KingWhite=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"><path d="M 22.5,11.63 L 22.5,6" style="fill:none; stroke:#000000; stroke-linejoin:miter;" /> <path d="M 20,8 L 25,8" style="fill:none; stroke:#000000; stroke-linejoin:miter;" /> <path d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25" style="fill:#ffffff; stroke:#000000; stroke-linecap:butt; stroke-linejoin:miter;" /> <path d="M 11.5,37 C 17,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 19,16 9.5,13 6.5,19.5 C 3.5,25.5 11.5,29.5 11.5,29.5 L 11.5,37 z " style="fill:#ffffff; stroke:#000000;" /> <path d="M 11.5,30 C 17,27 27,27 32.5,30" style="fill:none; stroke:#000000;" /> <path d="M 11.5,33.5 C 17,30.5 27,30.5 32.5,33.5" style="fill:none; stroke:#000000;" /> <path d="M 11.5,37 C 17,34 27,34 32.5,37" style="fill:none; stroke:#000000;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.KingWhite",size:{width:42,height:38}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.KingBlack=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <path d="M 22.5,11.63 L 22.5,6" style="fill:none; stroke:#000000; stroke-linejoin:miter;" id="path6570" /> <path d="M 22.5,25 C 22.5,25 27,17.5 25.5,14.5 C 25.5,14.5 24.5,12 22.5,12 C 20.5,12 19.5,14.5 19.5,14.5 C 18,17.5 22.5,25 22.5,25" style="fill:#000000;fill-opacity:1; stroke-linecap:butt; stroke-linejoin:miter;" /> <path d="M 11.5,37 C 17,40.5 27,40.5 32.5,37 L 32.5,30 C 32.5,30 41.5,25.5 38.5,19.5 C 34.5,13 25,16 22.5,23.5 L 22.5,27 L 22.5,23.5 C 19,16 9.5,13 6.5,19.5 C 3.5,25.5 11.5,29.5 11.5,29.5 L 11.5,37 z " style="fill:#000000; stroke:#000000;" /> <path d="M 20,8 L 25,8" style="fill:none; stroke:#000000; stroke-linejoin:miter;" /> <path d="M 32,29.5 C 32,29.5 40.5,25.5 38.03,19.85 C 34.15,14 25,18 22.5,24.5 L 22.51,26.6 L 22.5,24.5 C 20,18 9.906,14 6.997,19.85 C 4.5,25.5 11.85,28.85 11.85,28.85" style="fill:none; stroke:#ffffff;" /> <path d="M 11.5,30 C 17,27 27,27 32.5,30 M 11.5,33.5 C 17,30.5 27,30.5 32.5,33.5 M 11.5,37 C 17,34 27,34 32.5,37" style="fill:none; stroke:#ffffff;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.KingBlack",size:{width:42,height:38}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.QueenWhite=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <path d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" transform="translate(-1,-1)" /> <path d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" transform="translate(15.5,-5.5)" /> <path d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" transform="translate(32,-1)" /> <path d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" transform="translate(7,-4.5)" /> <path d="M 9 13 A 2 2 0 1 1 5,13 A 2 2 0 1 1 9 13 z" transform="translate(24,-4)" /> <path d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38,14 L 31,25 L 31,11 L 25.5,24.5 L 22.5,9.5 L 19.5,24.5 L 14,10.5 L 14,25 L 7,14 L 9,26 z " style="stroke-linecap:butt;" /> <path d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 10.5,36 10.5,36 C 9,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z " style="stroke-linecap:butt;" /> <path d="M 11.5,30 C 15,29 30,29 33.5,30" style="fill:none;" /> <path d="M 12,33.5 C 18,32.5 27,32.5 33,33.5" style="fill:none;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.QueenWhite",size:{width:42,height:38}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.QueenBlack=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <g style="fill:#000000; stroke:none;"> <circle cx="6" cy="12" r="2.75" /> <circle cx="14" cy="9" r="2.75" /> <circle cx="22.5" cy="8" r="2.75" /> <circle cx="31" cy="9" r="2.75" /> <circle cx="39" cy="12" r="2.75" /> </g> <path d="M 9,26 C 17.5,24.5 30,24.5 36,26 L 38.5,13.5 L 31,25 L 30.7,10.9 L 25.5,24.5 L 22.5,10 L 19.5,24.5 L 14.3,10.9 L 14,25 L 6.5,13.5 L 9,26 z" style="stroke-linecap:butt; stroke:#000000;" /> <path d="M 9,26 C 9,28 10.5,28 11.5,30 C 12.5,31.5 12.5,31 12,33.5 C 10.5,34.5 10.5,36 10.5,36 C 9,37.5 11,38.5 11,38.5 C 17.5,39.5 27.5,39.5 34,38.5 C 34,38.5 35.5,37.5 34,36 C 34,36 34.5,34.5 33,33.5 C 32.5,31 32.5,31.5 33.5,30 C 34.5,28 36,28 36,26 C 27.5,24.5 17.5,24.5 9,26 z" style="stroke-linecap:butt;" /> <path d="M 11,38.5 A 35,35 1 0 0 34,38.5" style="fill:none; stroke:#000000; stroke-linecap:butt;" /> <path d="M 11,29 A 35,35 1 0 1 34,29" style="fill:none; stroke:#ffffff;" /> <path d="M 12.5,31.5 L 32.5,31.5" style="fill:none; stroke:#ffffff;" /> <path d="M 11.5,34.5 A 35,35 1 0 0 33.5,34.5" style="fill:none; stroke:#ffffff;" /> <path d="M 10.5,37.5 A 35,35 1 0 0 34.5,37.5" style="fill:none; stroke:#ffffff;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.QueenBlack",size:{width:42,height:38}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.RookWhite=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <path d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z " style="stroke-linecap:butt;" /> <path d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z " style="stroke-linecap:butt;" /> <path d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14" style="stroke-linecap:butt;" /> <path d="M 34,14 L 31,17 L 14,17 L 11,14" /> <path d="M 31,17 L 31,29.5 L 14,29.5 L 14,17" style="stroke-linecap:butt; stroke-linejoin:miter;" /> <path d="M 31,29.5 L 32.5,32 L 12.5,32 L 14,29.5" /> <path d="M 11,14 L 34,14" style="fill:none; stroke:#000000; stroke-linejoin:miter;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.RookWhite",size:{width:32,height:34}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.RookBlack=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <path d="M 9,39 L 36,39 L 36,36 L 9,36 L 9,39 z " style="stroke-linecap:butt;" /> <path d="M 12.5,32 L 14,29.5 L 31,29.5 L 32.5,32 L 12.5,32 z " style="stroke-linecap:butt;" /> <path d="M 12,36 L 12,32 L 33,32 L 33,36 L 12,36 z " style="stroke-linecap:butt;" /> <path d="M 14,29.5 L 14,16.5 L 31,16.5 L 31,29.5 L 14,29.5 z " style="stroke-linecap:butt;stroke-linejoin:miter;" /> <path d="M 14,16.5 L 11,14 L 34,14 L 31,16.5 L 14,16.5 z " style="stroke-linecap:butt;" /> <path d="M 11,14 L 11,9 L 15,9 L 15,11 L 20,11 L 20,9 L 25,9 L 25,11 L 30,11 L 30,9 L 34,9 L 34,14 L 11,14 z " style="stroke-linecap:butt;" /> <path d="M 12,35.5 L 33,35.5 L 33,35.5" style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" /> <path d="M 13,31.5 L 32,31.5" style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" /> <path d="M 14,29.5 L 31,29.5" style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" /> <path d="M 14,16.5 L 31,16.5" style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" /> <path d="M 11,14 L 34,14" style="fill:none; stroke:#ffffff; stroke-width:1; stroke-linejoin:miter;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.RookBlack",size:{width:32,height:34}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.BishopWhite=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <g style="fill:#ffffff; stroke:#000000; stroke-linecap:butt;"> <path d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.646,38.99 6.677,38.97 6,38 C 7.354,36.06 9,36 9,36 z" /> <path d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z" /> <path d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z" /> </g> <path d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18" style="fill:none; stroke:#000000; stroke-linejoin:miter;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.BishopWhite",size:{width:38,height:38}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.BishopBlack=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="opacity:1; fill:none; fill-rule:evenodd; fill-opacity:1; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:round; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <g style="fill:#000000; stroke:#000000; stroke-linecap:butt;"> <path d="M 9,36 C 12.39,35.03 19.11,36.43 22.5,34 C 25.89,36.43 32.61,35.03 36,36 C 36,36 37.65,36.54 39,38 C 38.32,38.97 37.35,38.99 36,38.5 C 32.61,37.53 25.89,38.96 22.5,37.5 C 19.11,38.96 12.39,37.53 9,38.5 C 7.646,38.99 6.677,38.97 6,38 C 7.354,36.06 9,36 9,36 z" /> <path d="M 15,32 C 17.5,34.5 27.5,34.5 30,32 C 30.5,30.5 30,30 30,30 C 30,27.5 27.5,26 27.5,26 C 33,24.5 33.5,14.5 22.5,10.5 C 11.5,14.5 12,24.5 17.5,26 C 17.5,26 15,27.5 15,30 C 15,30 14.5,30.5 15,32 z" /> <path d="M 25 8 A 2.5 2.5 0 1 1 20,8 A 2.5 2.5 0 1 1 25 8 z" /> </g> <path d="M 17.5,26 L 27.5,26 M 15,30 L 30,30 M 22.5,15.5 L 22.5,20.5 M 20,18 L 25,18" style="fill:none; stroke:#ffffff; stroke-linejoin:miter;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.BishopBlack",size:{width:38,height:38}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.KnightWhite=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <path d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18" style="fill:#ffffff; stroke:#000000;" /> <path d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10" style="fill:#ffffff; stroke:#000000;" /> <path d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z" style="fill:#000000; stroke:#000000;" /> <path d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z" transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)" style="fill:#000000; stroke:#000000;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.KnightWhite",size:{width:38,height:37}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.KnightBlack=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><g style="opacity:1; fill:none; fill-opacity:1; fill-rule:evenodd; stroke:#000000; stroke-width:1.5; stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;"> <path d="M 22,10 C 32.5,11 38.5,18 38,39 L 15,39 C 15,30 25,32.5 23,18" style="fill:#000000; stroke:#000000;" /> <path d="M 24,18 C 24.38,20.91 18.45,25.37 16,27 C 13,29 13.18,31.34 11,31 C 9.958,30.06 12.41,27.96 11,28 C 10,28 11.19,29.23 10,30 C 9,30 5.997,31 6,26 C 6,24 12,14 12,14 C 12,14 13.89,12.1 14,10.5 C 13.27,9.506 13.5,8.5 13.5,7.5 C 14.5,6.5 16.5,10 16.5,10 L 18.5,10 C 18.5,10 19.28,8.008 21,7 C 22,7 22,10 22,10" style="fill:#000000; stroke:#000000;" /> <path d="M 9.5 25.5 A 0.5 0.5 0 1 1 8.5,25.5 A 0.5 0.5 0 1 1 9.5 25.5 z" style="fill:#ffffff; stroke:#ffffff;" /> <path d="M 15 15.5 A 0.5 1.5 0 1 1 14,15.5 A 0.5 1.5 0 1 1 15 15.5 z" transform="matrix(0.866,0.5,-0.5,0.866,9.693,-5.173)" style="fill:#ffffff; stroke:#ffffff;" /> <path d="M 24.55,10.4 L 24.1,11.85 L 24.6,12 C 27.75,13 30.25,14.49 32.5,18.75 C 34.75,23.01 35.75,29.06 35.25,39 L 35.2,39.5 L 37.45,39.5 L 37.5,39 C 38,28.94 36.62,22.15 34.25,17.66 C 31.88,13.17 28.46,11.02 25.06,10.5 L 24.55,10.4 z " style="fill:#ffffff; stroke:none;" /> </g></g></g>',defaults:joint.util.deepSupplement({type:"chess.KnightBlack",size:{width:38,height:37}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.PawnWhite=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><path d="M 22,9 C 19.79,9 18,10.79 18,13 C 18,13.89 18.29,14.71 18.78,15.38 C 16.83,16.5 15.5,18.59 15.5,21 C 15.5,23.03 16.44,24.84 17.91,26.03 C 14.91,27.09 10.5,31.58 10.5,39.5 L 33.5,39.5 C 33.5,31.58 29.09,27.09 26.09,26.03 C 27.56,24.84 28.5,23.03 28.5,21 C 28.5,18.59 27.17,16.5 25.22,15.38 C 25.71,14.71 26,13.89 26,13 C 26,10.79 24.21,9 22,9 z " style="opacity:1; fill:#ffffff; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" /></g></g>',defaults:joint.util.deepSupplement({type:"chess.PawnWhite",size:{width:28,height:33}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.chess.PawnBlack=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><path d="M 22,9 C 19.79,9 18,10.79 18,13 C 18,13.89 18.29,14.71 18.78,15.38 C 16.83,16.5 15.5,18.59 15.5,21 C 15.5,23.03 16.44,24.84 17.91,26.03 C 14.91,27.09 10.5,31.58 10.5,39.5 L 33.5,39.5 C 33.5,31.58 29.09,27.09 26.09,26.03 C 27.56,24.84 28.5,23.03 28.5,21 C 28.5,18.59 27.17,16.5 25.22,15.38 C 25.71,14.71 26,13.89 26,13 C 26,10.79 24.21,9 22,9 z " style="opacity:1; fill:#000000; fill-opacity:1; fill-rule:nonzero; stroke:#000000; stroke-width:1.5; stroke-linecap:round; stroke-linejoin:miter; stroke-miterlimit:4; stroke-dasharray:none; stroke-opacity:1;" /></g></g>',defaults:joint.util.deepSupplement({type:"chess.PawnBlack",size:{width:28,height:33}},joint.shapes.basic.Generic.prototype.defaults)});
|
joint.shapes.pn={},joint.shapes.pn.Place=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><circle class="root"/><g class="tokens" /></g><text class="label"/></g>',defaults:joint.util.deepSupplement({type:"pn.Place",size:{width:50,height:50},attrs:{".root":{r:25,fill:"#ffffff",stroke:"#000000",transform:"translate(25, 25)"},".label":{"text-anchor":"middle","ref-x":.5,"ref-y":-20,ref:".root",fill:"#000000","font-size":12},".tokens > circle":{fill:"#000000",r:5},".tokens.one > circle":{transform:"translate(25, 25)"},".tokens.two > circle:nth-child(1)":{transform:"translate(19, 25)"},".tokens.two > circle:nth-child(2)":{transform:"translate(31, 25)"},".tokens.three > circle:nth-child(1)":{transform:"translate(18, 29)"},".tokens.three > circle:nth-child(2)":{transform:"translate(25, 19)"},".tokens.three > circle:nth-child(3)":{transform:"translate(32, 29)"},".tokens.alot > text":{transform:"translate(25, 18)","text-anchor":"middle",fill:"#000000"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.pn.PlaceView=joint.dia.ElementView.extend({initialize:function(){joint.dia.ElementView.prototype.initialize.apply(this,arguments),this.model.on("change:tokens",function(){this.renderTokens(),this.update()},this)},render:function(){joint.dia.ElementView.prototype.render.apply(this,arguments),this.renderTokens(),this.update()},renderTokens:function(){var a=this.$(".tokens").empty();a[0].className.baseVal="tokens";var b=this.model.get("tokens");if(b)switch(b){case 1:a[0].className.baseVal+=" one",a.append(V("<circle/>").node);break;case 2:a[0].className.baseVal+=" two",a.append(V("<circle/>").node,V("<circle/>").node);break;case 3:a[0].className.baseVal+=" three",a.append(V("<circle/>").node,V("<circle/>").node,V("<circle/>").node);break;default:a[0].className.baseVal+=" alot",a.append(V("<text/>").text(b+"").node)}}}),joint.shapes.pn.Transition=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><rect class="root"/></g></g><text class="label"/>',defaults:joint.util.deepSupplement({type:"pn.Transition",size:{width:12,height:50},attrs:{rect:{width:12,height:50,fill:"#000000",stroke:"#000000"},".label":{"text-anchor":"middle","ref-x":.5,"ref-y":-20,ref:"rect",fill:"#000000","font-size":12}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.pn.Link=joint.dia.Link.extend({defaults:joint.util.deepSupplement({type:"pn.Link",attrs:{".marker-target":{d:"M 10 0 L 0 5 L 10 10 z"}}},joint.dia.Link.prototype.defaults)});
|
joint.shapes.devs={},joint.shapes.devs.Model=joint.shapes.basic.Generic.extend(_.extend({},joint.shapes.basic.PortsModelInterface,{markup:'<g class="rotatable"><g class="scalable"><rect class="body"/></g><text class="label"/><g class="inPorts"/><g class="outPorts"/></g>',portMarkup:'<g class="port port<%= id %>"><circle class="port-body"/><text class="port-label"/></g>',defaults:joint.util.deepSupplement({type:"devs.Model",size:{width:1,height:1},inPorts:[],outPorts:[],attrs:{".":{magnet:!1},".body":{width:150,height:250,stroke:"#000000"},".port-body":{r:10,magnet:!0,stroke:"#000000"},text:{"pointer-events":"none"},".label":{text:"Model","ref-x":.5,"ref-y":10,ref:".body","text-anchor":"middle",fill:"#000000"},".inPorts .port-label":{x:-15,dy:4,"text-anchor":"end",fill:"#000000"},".outPorts .port-label":{x:15,dy:4,fill:"#000000"}}},joint.shapes.basic.Generic.prototype.defaults),getPortAttrs:function(a,b,c,d,e){var f={},g="port"+b,h=d+">."+g,i=h+">.port-label",j=h+">.port-body";return f[i]={text:a},f[j]={port:{id:a||_.uniqueId(e),type:e}},f[h]={ref:".body","ref-y":(b+.5)*(1/c)},".outPorts"===d&&(f[h]["ref-dx"]=0),f}})),joint.shapes.devs.Atomic=joint.shapes.devs.Model.extend({defaults:joint.util.deepSupplement({type:"devs.Atomic",size:{width:80,height:80},attrs:{".body":{fill:"salmon"},".label":{text:"Atomic"},".inPorts .port-body":{fill:"PaleGreen"},".outPorts .port-body":{fill:"Tomato"}}},joint.shapes.devs.Model.prototype.defaults)}),joint.shapes.devs.Coupled=joint.shapes.devs.Model.extend({defaults:joint.util.deepSupplement({type:"devs.Coupled",size:{width:200,height:300},attrs:{".body":{fill:"seaGreen"},".label":{text:"Coupled"},".inPorts .port-body":{fill:"PaleGreen"},".outPorts .port-body":{fill:"Tomato"}}},joint.shapes.devs.Model.prototype.defaults)}),joint.shapes.devs.Link=joint.dia.Link.extend({defaults:{type:"devs.Link",attrs:{".connection":{"stroke-width":2}}}}),joint.shapes.devs.ModelView=joint.dia.ElementView.extend(joint.shapes.basic.PortsViewInterface),joint.shapes.devs.AtomicView=joint.shapes.devs.ModelView,joint.shapes.devs.CoupledView=joint.shapes.devs.ModelView;
|
joint.shapes.uml={},joint.shapes.uml.Class=joint.shapes.basic.Generic.extend({markup:['<g class="rotatable">','<g class="scalable">','<rect class="uml-class-name-rect"/><rect class="uml-class-attrs-rect"/><rect class="uml-class-methods-rect"/>',"</g>",'<text class="uml-class-name-text"/><text class="uml-class-attrs-text"/><text class="uml-class-methods-text"/>',"</g>"].join(""),defaults:joint.util.deepSupplement({type:"uml.Class",attrs:{rect:{width:200},".uml-class-name-rect":{stroke:"black","stroke-width":2,fill:"#3498db"},".uml-class-attrs-rect":{stroke:"black","stroke-width":2,fill:"#2980b9"},".uml-class-methods-rect":{stroke:"black","stroke-width":2,fill:"#2980b9"},".uml-class-name-text":{ref:".uml-class-name-rect","ref-y":.5,"ref-x":.5,"text-anchor":"middle","y-alignment":"middle","font-weight":"bold",fill:"black","font-size":12,"font-family":"Times New Roman"},".uml-class-attrs-text":{ref:".uml-class-attrs-rect","ref-y":5,"ref-x":5,fill:"black","font-size":12,"font-family":"Times New Roman"},".uml-class-methods-text":{ref:".uml-class-methods-rect","ref-y":5,"ref-x":5,fill:"black","font-size":12,"font-family":"Times New Roman"}},name:[],attributes:[],methods:[]},joint.shapes.basic.Generic.prototype.defaults),initialize:function(){this.on("change:name change:attributes change:methods",function(){this.updateRectangles(),this.trigger("uml-update")},this),this.updateRectangles(),joint.shapes.basic.Generic.prototype.initialize.apply(this,arguments)},getClassName:function(){return this.get("name")},updateRectangles:function(){var a=this.get("attrs"),b=[{type:"name",text:this.getClassName()},{type:"attrs",text:this.get("attributes")},{type:"methods",text:this.get("methods")}],c=0;_.each(b,function(b){var d=_.isArray(b.text)?b.text:[b.text],e=20*d.length+20;a[".uml-class-"+b.type+"-text"].text=d.join("\n"),a[".uml-class-"+b.type+"-rect"].height=e,a[".uml-class-"+b.type+"-rect"].transform="translate(0,"+c+")",c+=e})}}),joint.shapes.uml.ClassView=joint.dia.ElementView.extend({initialize:function(){joint.dia.ElementView.prototype.initialize.apply(this,arguments),this.listenTo(this.model,"uml-update",function(){this.update(),this.resize()})}}),joint.shapes.uml.Abstract=joint.shapes.uml.Class.extend({defaults:joint.util.deepSupplement({type:"uml.Abstract",attrs:{".uml-class-name-rect":{fill:"#e74c3c"},".uml-class-attrs-rect":{fill:"#c0392b"},".uml-class-methods-rect":{fill:"#c0392b"}}},joint.shapes.uml.Class.prototype.defaults),getClassName:function(){return["<<Abstract>>",this.get("name")]}}),joint.shapes.uml.AbstractView=joint.shapes.uml.ClassView,joint.shapes.uml.Interface=joint.shapes.uml.Class.extend({defaults:joint.util.deepSupplement({type:"uml.Interface",attrs:{".uml-class-name-rect":{fill:"#f1c40f"},".uml-class-attrs-rect":{fill:"#f39c12"},".uml-class-methods-rect":{fill:"#f39c12"}}},joint.shapes.uml.Class.prototype.defaults),getClassName:function(){return["<<Interface>>",this.get("name")]}}),joint.shapes.uml.InterfaceView=joint.shapes.uml.ClassView,joint.shapes.uml.Generalization=joint.dia.Link.extend({defaults:{type:"uml.Generalization",attrs:{".marker-target":{d:"M 20 0 L 0 10 L 20 20 z",fill:"white"}}}}),joint.shapes.uml.Implementation=joint.dia.Link.extend({defaults:{type:"uml.Implementation",attrs:{".marker-target":{d:"M 20 0 L 0 10 L 20 20 z",fill:"white"},".connection":{"stroke-dasharray":"3,3"}}}}),joint.shapes.uml.Aggregation=joint.dia.Link.extend({defaults:{type:"uml.Aggregation",attrs:{".marker-target":{d:"M 40 10 L 20 20 L 0 10 L 20 0 z",fill:"white"}}}}),joint.shapes.uml.Composition=joint.dia.Link.extend({defaults:{type:"uml.Composition",attrs:{".marker-target":{d:"M 40 10 L 20 20 L 0 10 L 20 0 z",fill:"black"}}}}),joint.shapes.uml.Association=joint.dia.Link.extend({defaults:{type:"uml.Association"}}),joint.shapes.uml.State=joint.shapes.basic.Generic.extend({markup:['<g class="rotatable">','<g class="scalable">','<rect class="uml-state-body"/>',"</g>",'<path class="uml-state-separator"/>','<text class="uml-state-name"/>','<text class="uml-state-events"/>',"</g>"].join(""),defaults:joint.util.deepSupplement({type:"uml.State",attrs:{".uml-state-body":{width:200,height:200,rx:10,ry:10,fill:"#ecf0f1",stroke:"#bdc3c7","stroke-width":3},".uml-state-separator":{stroke:"#bdc3c7","stroke-width":2},".uml-state-name":{ref:".uml-state-body","ref-x":.5,"ref-y":5,"text-anchor":"middle",fill:"#000000","font-family":"Courier New","font-size":14},".uml-state-events":{ref:".uml-state-separator","ref-x":5,"ref-y":5,fill:"#000000","font-family":"Courier New","font-size":14}},name:"State",events:[]},joint.shapes.basic.Generic.prototype.defaults),initialize:function(){this.on({"change:name":this.updateName,"change:events":this.updateEvents,"change:size":this.updatePath},this),this.updateName(),this.updateEvents(),this.updatePath(),joint.shapes.basic.Generic.prototype.initialize.apply(this,arguments)},updateName:function(){this.attr(".uml-state-name/text",this.get("name"))},updateEvents:function(){this.attr(".uml-state-events/text",this.get("events").join("\n"))},updatePath:function(){var a="M 0 20 L "+this.get("size").width+" 20";this.attr(".uml-state-separator/d",a,{silent:!0})}}),joint.shapes.uml.StartState=joint.shapes.basic.Circle.extend({defaults:joint.util.deepSupplement({type:"uml.StartState",attrs:{circle:{fill:"#34495e",stroke:"#2c3e50","stroke-width":2,rx:1}}},joint.shapes.basic.Circle.prototype.defaults)}),joint.shapes.uml.EndState=joint.shapes.basic.Generic.extend({markup:'<g class="rotatable"><g class="scalable"><circle class="outer"/><circle class="inner"/></g></g>',defaults:joint.util.deepSupplement({type:"uml.EndState",size:{width:20,height:20},attrs:{"circle.outer":{transform:"translate(10, 10)",r:10,fill:"#ffffff",stroke:"#2c3e50"},"circle.inner":{transform:"translate(10, 10)",r:6,fill:"#34495e"}}},joint.shapes.basic.Generic.prototype.defaults)}),joint.shapes.uml.Transition=joint.dia.Link.extend({defaults:{type:"uml.Transition",attrs:{".marker-target":{d:"M 10 0 L 0 5 L 10 10 z",fill:"#34495e",stroke:"#2c3e50"},".connection":{stroke:"#2c3e50"}}}});
|
joint.shapes.logic={},joint.shapes.logic.Gate=joint.shapes.basic.Generic.extend({defaults:joint.util.deepSupplement({type:"logic.Gate",size:{width:80,height:40},attrs:{".":{magnet:!1},".body":{width:100,height:50},circle:{r:7,stroke:"black",fill:"transparent","stroke-width":2}}},joint.shapes.basic.Generic.prototype.defaults),operation:function(){return!0}}),joint.shapes.logic.IO=joint.shapes.logic.Gate.extend({markup:'<g class="rotatable"><g class="scalable"><rect class="body"/></g><path class="wire"/><circle/><text/></g>',defaults:joint.util.deepSupplement({type:"logic.IO",size:{width:60,height:30},attrs:{".body":{fill:"white",stroke:"black","stroke-width":2},".wire":{ref:".body","ref-y":.5,stroke:"black"},text:{fill:"black",ref:".body","ref-x":.5,"ref-y":.5,"y-alignment":"middle","text-anchor":"middle","font-weight":"bold","font-variant":"small-caps","text-transform":"capitalize","font-size":"14px"}}},joint.shapes.logic.Gate.prototype.defaults)}),joint.shapes.logic.Input=joint.shapes.logic.IO.extend({defaults:joint.util.deepSupplement({type:"logic.Input",attrs:{".wire":{"ref-dx":0,d:"M 0 0 L 23 0"},circle:{ref:".body","ref-dx":30,"ref-y":.5,magnet:!0,"class":"output",port:"out"},text:{text:"input"}}},joint.shapes.logic.IO.prototype.defaults)}),joint.shapes.logic.Output=joint.shapes.logic.IO.extend({defaults:joint.util.deepSupplement({type:"logic.Output",attrs:{".wire":{"ref-x":0,d:"M 0 0 L -23 0"},circle:{ref:".body","ref-x":-30,"ref-y":.5,magnet:"passive","class":"input",port:"in"},text:{text:"output"}}},joint.shapes.logic.IO.prototype.defaults)}),joint.shapes.logic.Gate11=joint.shapes.logic.Gate.extend({markup:'<g class="rotatable"><g class="scalable"><image class="body"/></g><circle class="input"/><circle class="output"/></g>',defaults:joint.util.deepSupplement({type:"logic.Gate11",attrs:{".input":{ref:".body","ref-x":-2,"ref-y":.5,magnet:"passive",port:"in"},".output":{ref:".body","ref-dx":2,"ref-y":.5,magnet:!0,port:"out"}}},joint.shapes.logic.Gate.prototype.defaults)}),joint.shapes.logic.Gate21=joint.shapes.logic.Gate.extend({markup:'<g class="rotatable"><g class="scalable"><image class="body"/></g><circle class="input input1"/><circle class="input input2"/><circle class="output"/></g>',defaults:joint.util.deepSupplement({type:"logic.Gate21",attrs:{".input1":{ref:".body","ref-x":-2,"ref-y":.3,magnet:"passive",port:"in1"},".input2":{ref:".body","ref-x":-2,"ref-y":.7,magnet:"passive",port:"in2"},".output":{ref:".body","ref-dx":2,"ref-y":.5,magnet:!0,port:"out"}}},joint.shapes.logic.Gate.prototype.defaults)}),joint.shapes.logic.Repeater=joint.shapes.logic.Gate11.extend({defaults:joint.util.deepSupplement({type:"logic.Repeater",attrs:{image:{"xlink:href":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnCiAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIKICAgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIKICAgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgogICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIKICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiCiAgIHdpZHRoPSIxMDAiCiAgIGhlaWdodD0iNTAiCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ2IgogICB2ZXJzaW9uPSIxLjAiCiAgIHNvZGlwb2RpOmRvY25hbWU9Ik5PVCBBTlNJLnN2ZyIKICAgaW5rc2NhcGU6b3V0cHV0X2V4dGVuc2lvbj0ib3JnLmlua3NjYXBlLm91dHB1dC5zdmcuaW5rc2NhcGUiPgogIDxkZWZzCiAgICAgaWQ9ImRlZnM0Ij4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAxNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF96PSI1MCA6IDE1IDogMSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIyNSA6IDEwIDogMSIKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI3MTQiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMC41IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEgOiAwLjUgOiAxIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjAuNSA6IDAuMzMzMzMzMzMgOiAxIgogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgwNiIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgxOSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIzNzIuMDQ3MjQgOiAzNTAuNzg3MzkgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNzQ0LjA5NDQ4IDogNTI2LjE4MTA5IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MjYuMTgxMDkgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjc3NyIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSI3NSA6IDQwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjE1MCA6IDYwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA2MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmUzMjc1IgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjUwIDogMzMuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEwMCA6IDUwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmU1NTMzIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjMyIDogMjEuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjY0IDogMzIgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDMyIDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI1NTciCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMjUgOiAxNi42NjY2NjcgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNTAgOiAyNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMjUgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICA8L2RlZnM+CiAgPHNvZGlwb2RpOm5hbWVkdmlldwogICAgIGlkPSJiYXNlIgogICAgIHBhZ2Vjb2xvcj0iI2ZmZmZmZiIKICAgICBib3JkZXJjb2xvcj0iIzY2NjY2NiIKICAgICBib3JkZXJvcGFjaXR5PSIxLjAiCiAgICAgaW5rc2NhcGU6cGFnZW9wYWNpdHk9IjAuMCIKICAgICBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIgogICAgIGlua3NjYXBlOnpvb209IjgiCiAgICAgaW5rc2NhcGU6Y3g9Ijg0LjY4NTM1MiIKICAgICBpbmtzY2FwZTpjeT0iMTUuMjg4NjI4IgogICAgIGlua3NjYXBlOmRvY3VtZW50LXVuaXRzPSJweCIKICAgICBpbmtzY2FwZTpjdXJyZW50LWxheWVyPSJsYXllcjEiCiAgICAgc2hvd2dyaWQ9InRydWUiCiAgICAgaW5rc2NhcGU6Z3JpZC1iYm94PSJ0cnVlIgogICAgIGlua3NjYXBlOmdyaWQtcG9pbnRzPSJ0cnVlIgogICAgIGdyaWR0b2xlcmFuY2U9IjEwMDAwIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTM5OSIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI4NzQiCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjMzIgogICAgIGlua3NjYXBlOndpbmRvdy15PSIwIgogICAgIGlua3NjYXBlOnNuYXAtYmJveD0idHJ1ZSI+CiAgICA8aW5rc2NhcGU6Z3JpZAogICAgICAgaWQ9IkdyaWRGcm9tUHJlMDQ2U2V0dGluZ3MiCiAgICAgICB0eXBlPSJ4eWdyaWQiCiAgICAgICBvcmlnaW54PSIwcHgiCiAgICAgICBvcmlnaW55PSIwcHgiCiAgICAgICBzcGFjaW5neD0iMXB4IgogICAgICAgc3BhY2luZ3k9IjFweCIKICAgICAgIGNvbG9yPSIjMDAwMGZmIgogICAgICAgZW1wY29sb3I9IiMwMDAwZmYiCiAgICAgICBvcGFjaXR5PSIwLjIiCiAgICAgICBlbXBvcGFjaXR5PSIwLjQiCiAgICAgICBlbXBzcGFjaW5nPSI1IgogICAgICAgdmlzaWJsZT0idHJ1ZSIKICAgICAgIGVuYWJsZWQ9InRydWUiIC8+CiAgPC9zb2RpcG9kaTpuYW1lZHZpZXc+CiAgPG1ldGFkYXRhCiAgICAgaWQ9Im1ldGFkYXRhNyI+CiAgICA8cmRmOlJERj4KICAgICAgPGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPgogICAgICAgIDxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PgogICAgICAgIDxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz4KICAgICAgPC9jYzpXb3JrPgogICAgPC9yZGY6UkRGPgogIDwvbWV0YWRhdGE+CiAgPGcKICAgICBpbmtzY2FwZTpsYWJlbD0iTGF5ZXIgMSIKICAgICBpbmtzY2FwZTpncm91cG1vZGU9ImxheWVyIgogICAgIGlkPSJsYXllcjEiPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjEuOTk5OTk5ODg7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Ik0gNzIuMTU2OTEsMjUgTCA5NSwyNSIKICAgICAgIGlkPSJwYXRoMzA1OSIKICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2MiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MjtzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgZD0iTSAyOS4wNDM0NzgsMjUgTCA1LjA0MzQ3ODEsMjUiCiAgICAgICBpZD0icGF0aDMwNjEiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MztzdHJva2UtbGluZWpvaW46bWl0ZXI7bWFya2VyOm5vbmU7c3Ryb2tlLW9wYWNpdHk6MTt2aXNpYmlsaXR5OnZpc2libGU7ZGlzcGxheTppbmxpbmU7b3ZlcmZsb3c6dmlzaWJsZTtlbmFibGUtYmFja2dyb3VuZDphY2N1bXVsYXRlIgogICAgICAgZD0iTSAyOC45Njg3NSwyLjU5Mzc1IEwgMjguOTY4NzUsNSBMIDI4Ljk2ODc1LDQ1IEwgMjguOTY4NzUsNDcuNDA2MjUgTCAzMS4xMjUsNDYuMzQzNzUgTCA3Mi4xNTYyNSwyNi4zNDM3NSBMIDcyLjE1NjI1LDIzLjY1NjI1IEwgMzEuMTI1LDMuNjU2MjUgTCAyOC45Njg3NSwyLjU5Mzc1IHogTSAzMS45Njg3NSw3LjQwNjI1IEwgNjguMDkzNzUsMjUgTCAzMS45Njg3NSw0Mi41OTM3NSBMIDMxLjk2ODc1LDcuNDA2MjUgeiIKICAgICAgIGlkPSJwYXRoMjYzOCIKICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2NjY2NjY2NjY2NjYyIgLz4KICA8L2c+Cjwvc3ZnPgo="}}},joint.shapes.logic.Gate11.prototype.defaults),operation:function(a){return a}}),joint.shapes.logic.Not=joint.shapes.logic.Gate11.extend({defaults:joint.util.deepSupplement({type:"logic.Not",attrs:{image:{"xlink:href":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnCiAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIKICAgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIKICAgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgogICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIKICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiCiAgIHdpZHRoPSIxMDAiCiAgIGhlaWdodD0iNTAiCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ2IgogICB2ZXJzaW9uPSIxLjAiCiAgIHNvZGlwb2RpOmRvY25hbWU9Ik5PVCBBTlNJLnN2ZyIKICAgaW5rc2NhcGU6b3V0cHV0X2V4dGVuc2lvbj0ib3JnLmlua3NjYXBlLm91dHB1dC5zdmcuaW5rc2NhcGUiPgogIDxkZWZzCiAgICAgaWQ9ImRlZnM0Ij4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAxNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF96PSI1MCA6IDE1IDogMSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIyNSA6IDEwIDogMSIKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI3MTQiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMC41IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEgOiAwLjUgOiAxIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjAuNSA6IDAuMzMzMzMzMzMgOiAxIgogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgwNiIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgxOSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIzNzIuMDQ3MjQgOiAzNTAuNzg3MzkgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNzQ0LjA5NDQ4IDogNTI2LjE4MTA5IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MjYuMTgxMDkgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjc3NyIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSI3NSA6IDQwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjE1MCA6IDYwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA2MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmUzMjc1IgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjUwIDogMzMuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEwMCA6IDUwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmU1NTMzIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjMyIDogMjEuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjY0IDogMzIgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDMyIDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI1NTciCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMjUgOiAxNi42NjY2NjcgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNTAgOiAyNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMjUgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICA8L2RlZnM+CiAgPHNvZGlwb2RpOm5hbWVkdmlldwogICAgIGlkPSJiYXNlIgogICAgIHBhZ2Vjb2xvcj0iI2ZmZmZmZiIKICAgICBib3JkZXJjb2xvcj0iIzY2NjY2NiIKICAgICBib3JkZXJvcGFjaXR5PSIxLjAiCiAgICAgaW5rc2NhcGU6cGFnZW9wYWNpdHk9IjAuMCIKICAgICBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIgogICAgIGlua3NjYXBlOnpvb209IjgiCiAgICAgaW5rc2NhcGU6Y3g9Ijg0LjY4NTM1MiIKICAgICBpbmtzY2FwZTpjeT0iMTUuMjg4NjI4IgogICAgIGlua3NjYXBlOmRvY3VtZW50LXVuaXRzPSJweCIKICAgICBpbmtzY2FwZTpjdXJyZW50LWxheWVyPSJsYXllcjEiCiAgICAgc2hvd2dyaWQ9InRydWUiCiAgICAgaW5rc2NhcGU6Z3JpZC1iYm94PSJ0cnVlIgogICAgIGlua3NjYXBlOmdyaWQtcG9pbnRzPSJ0cnVlIgogICAgIGdyaWR0b2xlcmFuY2U9IjEwMDAwIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTM5OSIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI4NzQiCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjMzIgogICAgIGlua3NjYXBlOndpbmRvdy15PSIwIgogICAgIGlua3NjYXBlOnNuYXAtYmJveD0idHJ1ZSI+CiAgICA8aW5rc2NhcGU6Z3JpZAogICAgICAgaWQ9IkdyaWRGcm9tUHJlMDQ2U2V0dGluZ3MiCiAgICAgICB0eXBlPSJ4eWdyaWQiCiAgICAgICBvcmlnaW54PSIwcHgiCiAgICAgICBvcmlnaW55PSIwcHgiCiAgICAgICBzcGFjaW5neD0iMXB4IgogICAgICAgc3BhY2luZ3k9IjFweCIKICAgICAgIGNvbG9yPSIjMDAwMGZmIgogICAgICAgZW1wY29sb3I9IiMwMDAwZmYiCiAgICAgICBvcGFjaXR5PSIwLjIiCiAgICAgICBlbXBvcGFjaXR5PSIwLjQiCiAgICAgICBlbXBzcGFjaW5nPSI1IgogICAgICAgdmlzaWJsZT0idHJ1ZSIKICAgICAgIGVuYWJsZWQ9InRydWUiIC8+CiAgPC9zb2RpcG9kaTpuYW1lZHZpZXc+CiAgPG1ldGFkYXRhCiAgICAgaWQ9Im1ldGFkYXRhNyI+CiAgICA8cmRmOlJERj4KICAgICAgPGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPgogICAgICAgIDxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PgogICAgICAgIDxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz4KICAgICAgPC9jYzpXb3JrPgogICAgPC9yZGY6UkRGPgogIDwvbWV0YWRhdGE+CiAgPGcKICAgICBpbmtzY2FwZTpsYWJlbD0iTGF5ZXIgMSIKICAgICBpbmtzY2FwZTpncm91cG1vZGU9ImxheWVyIgogICAgIGlkPSJsYXllcjEiPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjEuOTk5OTk5ODg7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Ik0gNzkuMTU2OTEsMjUgTCA5NSwyNSIKICAgICAgIGlkPSJwYXRoMzA1OSIKICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2MiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MjtzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgZD0iTSAyOS4wNDM0NzgsMjUgTCA1LjA0MzQ3ODEsMjUiCiAgICAgICBpZD0icGF0aDMwNjEiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MztzdHJva2UtbGluZWpvaW46bWl0ZXI7bWFya2VyOm5vbmU7c3Ryb2tlLW9wYWNpdHk6MTt2aXNpYmlsaXR5OnZpc2libGU7ZGlzcGxheTppbmxpbmU7b3ZlcmZsb3c6dmlzaWJsZTtlbmFibGUtYmFja2dyb3VuZDphY2N1bXVsYXRlIgogICAgICAgZD0iTSAyOC45Njg3NSwyLjU5Mzc1IEwgMjguOTY4NzUsNSBMIDI4Ljk2ODc1LDQ1IEwgMjguOTY4NzUsNDcuNDA2MjUgTCAzMS4xMjUsNDYuMzQzNzUgTCA3Mi4xNTYyNSwyNi4zNDM3NSBMIDcyLjE1NjI1LDIzLjY1NjI1IEwgMzEuMTI1LDMuNjU2MjUgTCAyOC45Njg3NSwyLjU5Mzc1IHogTSAzMS45Njg3NSw3LjQwNjI1IEwgNjguMDkzNzUsMjUgTCAzMS45Njg3NSw0Mi41OTM3NSBMIDMxLjk2ODc1LDcuNDA2MjUgeiIKICAgICAgIGlkPSJwYXRoMjYzOCIKICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2NjY2NjY2NjY2NjYyIgLz4KICAgIDxwYXRoCiAgICAgICBzb2RpcG9kaTp0eXBlPSJhcmMiCiAgICAgICBzdHlsZT0iZmlsbDpub25lO2ZpbGwtb3BhY2l0eToxO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDozO3N0cm9rZS1saW5lam9pbjptaXRlcjttYXJrZXI6bm9uZTtzdHJva2Utb3BhY2l0eToxO3Zpc2liaWxpdHk6dmlzaWJsZTtkaXNwbGF5OmlubGluZTtvdmVyZmxvdzp2aXNpYmxlO2VuYWJsZS1iYWNrZ3JvdW5kOmFjY3VtdWxhdGUiCiAgICAgICBpZD0icGF0aDI2NzEiCiAgICAgICBzb2RpcG9kaTpjeD0iNzYiCiAgICAgICBzb2RpcG9kaTpjeT0iMjUiCiAgICAgICBzb2RpcG9kaTpyeD0iNCIKICAgICAgIHNvZGlwb2RpOnJ5PSI0IgogICAgICAgZD0iTSA4MCwyNSBBIDQsNCAwIDEgMSA3MiwyNSBBIDQsNCAwIDEgMSA4MCwyNSB6IgogICAgICAgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTEsMCkiIC8+CiAgPC9nPgo8L3N2Zz4K"}}},joint.shapes.logic.Gate11.prototype.defaults),operation:function(a){return!a}}),joint.shapes.logic.Or=joint.shapes.logic.Gate21.extend({defaults:joint.util.deepSupplement({type:"logic.Or",attrs:{image:{"xlink:href":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnCiAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIKICAgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIKICAgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgogICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIKICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiCiAgIHdpZHRoPSIxMDAiCiAgIGhlaWdodD0iNTAiCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ2IgogICB2ZXJzaW9uPSIxLjAiCiAgIHNvZGlwb2RpOmRvY25hbWU9Ik9SIEFOU0kuc3ZnIgogICBpbmtzY2FwZTpvdXRwdXRfZXh0ZW5zaW9uPSJvcmcuaW5rc2NhcGUub3V0cHV0LnN2Zy5pbmtzY2FwZSI+CiAgPGRlZnMKICAgICBpZD0iZGVmczQiPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDE1IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3o9IjUwIDogMTUgOiAxIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjI1IDogMTAgOiAxIgogICAgICAgaWQ9InBlcnNwZWN0aXZlMjcxNCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAwLjUgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfej0iMSA6IDAuNSA6IDEiCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMC41IDogMC4zMzMzMzMzMyA6IDEiCiAgICAgICBpZD0icGVyc3BlY3RpdmUyODA2IiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmUyODE5IgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjM3Mi4wNDcyNCA6IDM1MC43ODczOSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF96PSI3NDQuMDk0NDggOiA1MjYuMTgxMDkgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDUyNi4xODEwOSA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmUyNzc3IgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49Ijc1IDogNDAgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iMTUwIDogNjAgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDYwIDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTMyNzUiCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iNTAgOiAzMy4zMzMzMzMgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iMTAwIDogNTAgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDUwIDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTU1MzMiCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMzIgOiAyMS4zMzMzMzMgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNjQgOiAzMiA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMzIgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjU1NyIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIyNSA6IDE2LjY2NjY2NyA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF96PSI1MCA6IDI1IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAyNSA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogIDwvZGVmcz4KICA8c29kaXBvZGk6bmFtZWR2aWV3CiAgICAgaWQ9ImJhc2UiCiAgICAgcGFnZWNvbG9yPSIjZmZmZmZmIgogICAgIGJvcmRlcmNvbG9yPSIjNjY2NjY2IgogICAgIGJvcmRlcm9wYWNpdHk9IjEuMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMC4wIgogICAgIGlua3NjYXBlOnBhZ2VzaGFkb3c9IjIiCiAgICAgaW5rc2NhcGU6em9vbT0iNCIKICAgICBpbmtzY2FwZTpjeD0iMTEzLjAwMDM5IgogICAgIGlua3NjYXBlOmN5PSIxMi44OTM3MzEiCiAgICAgaW5rc2NhcGU6ZG9jdW1lbnQtdW5pdHM9InB4IgogICAgIGlua3NjYXBlOmN1cnJlbnQtbGF5ZXI9ImcyNTYwIgogICAgIHNob3dncmlkPSJmYWxzZSIKICAgICBpbmtzY2FwZTpncmlkLWJib3g9InRydWUiCiAgICAgaW5rc2NhcGU6Z3JpZC1wb2ludHM9InRydWUiCiAgICAgZ3JpZHRvbGVyYW5jZT0iMTAwMDAiCiAgICAgaW5rc2NhcGU6d2luZG93LXdpZHRoPSIxMzk5IgogICAgIGlua3NjYXBlOndpbmRvdy1oZWlnaHQ9Ijg3NCIKICAgICBpbmtzY2FwZTp3aW5kb3cteD0iMzciCiAgICAgaW5rc2NhcGU6d2luZG93LXk9Ii00IgogICAgIGlua3NjYXBlOnNuYXAtYmJveD0idHJ1ZSI+CiAgICA8aW5rc2NhcGU6Z3JpZAogICAgICAgaWQ9IkdyaWRGcm9tUHJlMDQ2U2V0dGluZ3MiCiAgICAgICB0eXBlPSJ4eWdyaWQiCiAgICAgICBvcmlnaW54PSIwcHgiCiAgICAgICBvcmlnaW55PSIwcHgiCiAgICAgICBzcGFjaW5neD0iMXB4IgogICAgICAgc3BhY2luZ3k9IjFweCIKICAgICAgIGNvbG9yPSIjMDAwMGZmIgogICAgICAgZW1wY29sb3I9IiMwMDAwZmYiCiAgICAgICBvcGFjaXR5PSIwLjIiCiAgICAgICBlbXBvcGFjaXR5PSIwLjQiCiAgICAgICBlbXBzcGFjaW5nPSI1IgogICAgICAgdmlzaWJsZT0idHJ1ZSIKICAgICAgIGVuYWJsZWQ9InRydWUiIC8+CiAgPC9zb2RpcG9kaTpuYW1lZHZpZXc+CiAgPG1ldGFkYXRhCiAgICAgaWQ9Im1ldGFkYXRhNyI+CiAgICA8cmRmOlJERj4KICAgICAgPGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPgogICAgICAgIDxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PgogICAgICAgIDxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz4KICAgICAgPC9jYzpXb3JrPgogICAgPC9yZGY6UkRGPgogIDwvbWV0YWRhdGE+CiAgPGcKICAgICBpbmtzY2FwZTpsYWJlbD0iTGF5ZXIgMSIKICAgICBpbmtzY2FwZTpncm91cG1vZGU9ImxheWVyIgogICAgIGlkPSJsYXllcjEiPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjI7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Im0gNzAsMjUgYyAyMCwwIDI1LDAgMjUsMCIKICAgICAgIGlkPSJwYXRoMzA1OSIKICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2MiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MjtzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgZD0iTSAzMSwxNSA1LDE1IgogICAgICAgaWQ9InBhdGgzMDYxIiAvPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjEuOTk5OTk5ODg7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Ik0gMzIsMzUgNSwzNSIKICAgICAgIGlkPSJwYXRoMzk0NCIgLz4KICAgIDxnCiAgICAgICBpZD0iZzI1NjAiCiAgICAgICBpbmtzY2FwZTpsYWJlbD0iTGF5ZXIgMSIKICAgICAgIHRyYW5zZm9ybT0idHJhbnNsYXRlKDI2LjUsLTM5LjUpIj4KICAgICAgPHBhdGgKICAgICAgICAgc3R5bGU9ImZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6ZXZlbm9kZDtzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MztzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgICBkPSJNIC0yLjQwNjI1LDQ0LjUgTCAtMC40MDYyNSw0Ni45Mzc1IEMgLTAuNDA2MjUsNDYuOTM3NSA1LjI1LDUzLjkzNzU0OSA1LjI1LDY0LjUgQyA1LjI1LDc1LjA2MjQ1MSAtMC40MDYyNSw4Mi4wNjI1IC0wLjQwNjI1LDgyLjA2MjUgTCAtMi40MDYyNSw4NC41IEwgMC43NSw4NC41IEwgMTQuNzUsODQuNSBDIDE3LjE1ODA3Niw4NC41MDAwMDEgMjIuNDM5Njk5LDg0LjUyNDUxNCAyOC4zNzUsODIuMDkzNzUgQyAzNC4zMTAzMDEsNzkuNjYyOTg2IDQwLjkxMTUzNiw3NC43NTA0ODQgNDYuMDYyNSw2NS4yMTg3NSBMIDQ0Ljc1LDY0LjUgTCA0Ni4wNjI1LDYzLjc4MTI1IEMgMzUuNzU5Mzg3LDQ0LjcxNTU5IDE5LjUwNjU3NCw0NC41IDE0Ljc1LDQ0LjUgTCAwLjc1LDQ0LjUgTCAtMi40MDYyNSw0NC41IHogTSAzLjQ2ODc1LDQ3LjUgTCAxNC43NSw0Ny41IEMgMTkuNDM0MTczLDQ3LjUgMzMuMDM2ODUsNDcuMzY5NzkzIDQyLjcxODc1LDY0LjUgQyAzNy45NTE5NjQsNzIuOTI5MDc1IDMyLjE5NzQ2OSw3Ny4xODM5MSAyNyw3OS4zMTI1IEMgMjEuNjM5MzM5LDgxLjUwNzkyNCAxNy4xNTgwNzUsODEuNTAwMDAxIDE0Ljc1LDgxLjUgTCAzLjUsODEuNSBDIDUuMzczNTg4NCw3OC4zOTE1NjYgOC4yNSw3Mi40NTA2NSA4LjI1LDY0LjUgQyA4LjI1LDU2LjUyNjY0NiA1LjM0MTQ2ODYsNTAuNTk5ODE1IDMuNDY4NzUsNDcuNSB6IgogICAgICAgICBpZD0icGF0aDQ5NzMiCiAgICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2NzY2NjY3NjY2NjY2NjY2NzY2NzYyIgLz4KICAgIDwvZz4KICA8L2c+Cjwvc3ZnPgo="}}},joint.shapes.logic.Gate21.prototype.defaults),operation:function(a,b){return a||b}}),joint.shapes.logic.And=joint.shapes.logic.Gate21.extend({defaults:joint.util.deepSupplement({type:"logic.And",attrs:{image:{"xlink:href":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnCiAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIKICAgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIKICAgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgogICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIKICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiCiAgIHdpZHRoPSIxMDAiCiAgIGhlaWdodD0iNTAiCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ2IgogICB2ZXJzaW9uPSIxLjAiCiAgIHNvZGlwb2RpOmRvY25hbWU9IkFORCBBTlNJLnN2ZyIKICAgaW5rc2NhcGU6b3V0cHV0X2V4dGVuc2lvbj0ib3JnLmlua3NjYXBlLm91dHB1dC5zdmcuaW5rc2NhcGUiPgogIDxkZWZzCiAgICAgaWQ9ImRlZnM0Ij4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAxNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF96PSI1MCA6IDE1IDogMSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIyNSA6IDEwIDogMSIKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI3MTQiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMC41IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEgOiAwLjUgOiAxIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjAuNSA6IDAuMzMzMzMzMzMgOiAxIgogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgwNiIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgxOSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIzNzIuMDQ3MjQgOiAzNTAuNzg3MzkgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNzQ0LjA5NDQ4IDogNTI2LjE4MTA5IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MjYuMTgxMDkgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjc3NyIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSI3NSA6IDQwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjE1MCA6IDYwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA2MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmUzMjc1IgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjUwIDogMzMuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEwMCA6IDUwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmU1NTMzIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjMyIDogMjEuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjY0IDogMzIgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDMyIDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgPC9kZWZzPgogIDxzb2RpcG9kaTpuYW1lZHZpZXcKICAgICBpZD0iYmFzZSIKICAgICBwYWdlY29sb3I9IiNmZmZmZmYiCiAgICAgYm9yZGVyY29sb3I9IiM2NjY2NjYiCiAgICAgYm9yZGVyb3BhY2l0eT0iMS4wIgogICAgIGlua3NjYXBlOnBhZ2VvcGFjaXR5PSIwLjAiCiAgICAgaW5rc2NhcGU6cGFnZXNoYWRvdz0iMiIKICAgICBpbmtzY2FwZTp6b29tPSI4IgogICAgIGlua3NjYXBlOmN4PSI1Ni42OTgzNDgiCiAgICAgaW5rc2NhcGU6Y3k9IjI1LjMyNjg5OSIKICAgICBpbmtzY2FwZTpkb2N1bWVudC11bml0cz0icHgiCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0ibGF5ZXIxIgogICAgIHNob3dncmlkPSJ0cnVlIgogICAgIGlua3NjYXBlOmdyaWQtYmJveD0idHJ1ZSIKICAgICBpbmtzY2FwZTpncmlkLXBvaW50cz0idHJ1ZSIKICAgICBncmlkdG9sZXJhbmNlPSIxMDAwMCIKICAgICBpbmtzY2FwZTp3aW5kb3ctd2lkdGg9IjEzOTkiCiAgICAgaW5rc2NhcGU6d2luZG93LWhlaWdodD0iODc0IgogICAgIGlua3NjYXBlOndpbmRvdy14PSIzMyIKICAgICBpbmtzY2FwZTp3aW5kb3cteT0iMCIKICAgICBpbmtzY2FwZTpzbmFwLWJib3g9InRydWUiPgogICAgPGlua3NjYXBlOmdyaWQKICAgICAgIGlkPSJHcmlkRnJvbVByZTA0NlNldHRpbmdzIgogICAgICAgdHlwZT0ieHlncmlkIgogICAgICAgb3JpZ2lueD0iMHB4IgogICAgICAgb3JpZ2lueT0iMHB4IgogICAgICAgc3BhY2luZ3g9IjFweCIKICAgICAgIHNwYWNpbmd5PSIxcHgiCiAgICAgICBjb2xvcj0iIzAwMDBmZiIKICAgICAgIGVtcGNvbG9yPSIjMDAwMGZmIgogICAgICAgb3BhY2l0eT0iMC4yIgogICAgICAgZW1wb3BhY2l0eT0iMC40IgogICAgICAgZW1wc3BhY2luZz0iNSIKICAgICAgIHZpc2libGU9InRydWUiCiAgICAgICBlbmFibGVkPSJ0cnVlIiAvPgogIDwvc29kaXBvZGk6bmFtZWR2aWV3PgogIDxtZXRhZGF0YQogICAgIGlkPSJtZXRhZGF0YTciPgogICAgPHJkZjpSREY+CiAgICAgIDxjYzpXb3JrCiAgICAgICAgIHJkZjphYm91dD0iIj4KICAgICAgICA8ZGM6Zm9ybWF0PmltYWdlL3N2Zyt4bWw8L2RjOmZvcm1hdD4KICAgICAgICA8ZGM6dHlwZQogICAgICAgICAgIHJkZjpyZXNvdXJjZT0iaHR0cDovL3B1cmwub3JnL2RjL2RjbWl0eXBlL1N0aWxsSW1hZ2UiIC8+CiAgICAgIDwvY2M6V29yaz4KICAgIDwvcmRmOlJERj4KICA8L21ldGFkYXRhPgogIDxnCiAgICAgaW5rc2NhcGU6bGFiZWw9IkxheWVyIDEiCiAgICAgaW5rc2NhcGU6Z3JvdXBtb2RlPSJsYXllciIKICAgICBpZD0ibGF5ZXIxIj4KICAgIDxwYXRoCiAgICAgICBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoyO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1vcGFjaXR5OjEiCiAgICAgICBkPSJtIDcwLDI1IGMgMjAsMCAyNSwwIDI1LDAiCiAgICAgICBpZD0icGF0aDMwNTkiCiAgICAgICBzb2RpcG9kaTpub2RldHlwZXM9ImNjIiAvPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjI7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Ik0gMzEsMTUgNSwxNSIKICAgICAgIGlkPSJwYXRoMzA2MSIgLz4KICAgIDxwYXRoCiAgICAgICBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoxLjk5OTk5OTg4O3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1vcGFjaXR5OjEiCiAgICAgICBkPSJNIDMyLDM1IDUsMzUiCiAgICAgICBpZD0icGF0aDM5NDQiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZvbnQtc2l6ZTptZWRpdW07Zm9udC1zdHlsZTpub3JtYWw7Zm9udC12YXJpYW50Om5vcm1hbDtmb250LXdlaWdodDpub3JtYWw7Zm9udC1zdHJldGNoOm5vcm1hbDt0ZXh0LWluZGVudDowO3RleHQtYWxpZ246c3RhcnQ7dGV4dC1kZWNvcmF0aW9uOm5vbmU7bGluZS1oZWlnaHQ6bm9ybWFsO2xldHRlci1zcGFjaW5nOm5vcm1hbDt3b3JkLXNwYWNpbmc6bm9ybWFsO3RleHQtdHJhbnNmb3JtOm5vbmU7ZGlyZWN0aW9uOmx0cjtibG9jay1wcm9ncmVzc2lvbjp0Yjt3cml0aW5nLW1vZGU6bHItdGI7dGV4dC1hbmNob3I6c3RhcnQ7ZmlsbDojMDAwMDAwO2ZpbGwtb3BhY2l0eToxO3N0cm9rZTpub25lO3N0cm9rZS13aWR0aDozO21hcmtlcjpub25lO3Zpc2liaWxpdHk6dmlzaWJsZTtkaXNwbGF5OmlubGluZTtvdmVyZmxvdzp2aXNpYmxlO2VuYWJsZS1iYWNrZ3JvdW5kOmFjY3VtdWxhdGU7Zm9udC1mYW1pbHk6Qml0c3RyZWFtIFZlcmEgU2FuczstaW5rc2NhcGUtZm9udC1zcGVjaWZpY2F0aW9uOkJpdHN0cmVhbSBWZXJhIFNhbnMiCiAgICAgICBkPSJNIDMwLDUgTCAzMCw2LjQyODU3MTQgTCAzMCw0My41NzE0MjkgTCAzMCw0NSBMIDMxLjQyODU3MSw0NSBMIDUwLjQ3NjE5LDQ1IEMgNjEuNzQ0MDk4LDQ1IDcwLjQ3NjE5LDM1Ljk5OTk1NSA3MC40NzYxOSwyNSBDIDcwLjQ3NjE5LDE0LjAwMDA0NSA2MS43NDQwOTksNS4wMDAwMDAyIDUwLjQ3NjE5LDUgQyA1MC40NzYxOSw1IDUwLjQ3NjE5LDUgMzEuNDI4NTcxLDUgTCAzMCw1IHogTSAzMi44NTcxNDMsNy44NTcxNDI5IEMgNDAuODM0MjY0LDcuODU3MTQyOSA0NS45MTgzNjgsNy44NTcxNDI5IDQ4LjA5NTIzOCw3Ljg1NzE0MjkgQyA0OS4yODU3MTQsNy44NTcxNDI5IDQ5Ljg4MDk1Miw3Ljg1NzE0MjkgNTAuMTc4NTcxLDcuODU3MTQyOSBDIDUwLjMyNzM4MSw3Ljg1NzE0MjkgNTAuNDA5MjI3LDcuODU3MTQyOSA1MC40NDY0MjksNy44NTcxNDI5IEMgNTAuNDY1MDI5LDcuODU3MTQyOSA1MC40NzE1NDMsNy44NTcxNDI5IDUwLjQ3NjE5LDcuODU3MTQyOSBDIDYwLjIzNjg1Myw3Ljg1NzE0MyA2Ny4xNDI4NTcsMTUuNDk3MDk4IDY3LjE0Mjg1NywyNSBDIDY3LjE0Mjg1NywzNC41MDI5MDIgNTkuNzYwNjYyLDQyLjE0Mjg1NyA1MCw0Mi4xNDI4NTcgTCAzMi44NTcxNDMsNDIuMTQyODU3IEwgMzIuODU3MTQzLDcuODU3MTQyOSB6IgogICAgICAgaWQ9InBhdGgyODg0IgogICAgICAgc29kaXBvZGk6bm9kZXR5cGVzPSJjY2NjY2NzY2NjY3Nzc3NzY2NjIiAvPgogIDwvZz4KPC9zdmc+Cg=="}}},joint.shapes.logic.Gate21.prototype.defaults),operation:function(a,b){return a&&b}}),joint.shapes.logic.Nor=joint.shapes.logic.Gate21.extend({defaults:joint.util.deepSupplement({type:"logic.Nor",attrs:{image:{"xlink:href":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnCiAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIKICAgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIKICAgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgogICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIKICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiCiAgIHdpZHRoPSIxMDAiCiAgIGhlaWdodD0iNTAiCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ2IgogICB2ZXJzaW9uPSIxLjAiCiAgIHNvZGlwb2RpOmRvY25hbWU9Ik5PUiBBTlNJLnN2ZyIKICAgaW5rc2NhcGU6b3V0cHV0X2V4dGVuc2lvbj0ib3JnLmlua3NjYXBlLm91dHB1dC5zdmcuaW5rc2NhcGUiPgogIDxkZWZzCiAgICAgaWQ9ImRlZnM0Ij4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAxNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF96PSI1MCA6IDE1IDogMSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIyNSA6IDEwIDogMSIKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI3MTQiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMC41IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEgOiAwLjUgOiAxIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjAuNSA6IDAuMzMzMzMzMzMgOiAxIgogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgwNiIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgxOSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIzNzIuMDQ3MjQgOiAzNTAuNzg3MzkgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNzQ0LjA5NDQ4IDogNTI2LjE4MTA5IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MjYuMTgxMDkgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjc3NyIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSI3NSA6IDQwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjE1MCA6IDYwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA2MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmUzMjc1IgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjUwIDogMzMuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEwMCA6IDUwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmU1NTMzIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjMyIDogMjEuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjY0IDogMzIgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDMyIDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI1NTciCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMjUgOiAxNi42NjY2NjcgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNTAgOiAyNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMjUgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICA8L2RlZnM+CiAgPHNvZGlwb2RpOm5hbWVkdmlldwogICAgIGlkPSJiYXNlIgogICAgIHBhZ2Vjb2xvcj0iI2ZmZmZmZiIKICAgICBib3JkZXJjb2xvcj0iIzY2NjY2NiIKICAgICBib3JkZXJvcGFjaXR5PSIxLjAiCiAgICAgaW5rc2NhcGU6cGFnZW9wYWNpdHk9IjAuMCIKICAgICBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIgogICAgIGlua3NjYXBlOnpvb209IjEiCiAgICAgaW5rc2NhcGU6Y3g9Ijc4LjY3NzY0NCIKICAgICBpbmtzY2FwZTpjeT0iMjIuMTAyMzQ0IgogICAgIGlua3NjYXBlOmRvY3VtZW50LXVuaXRzPSJweCIKICAgICBpbmtzY2FwZTpjdXJyZW50LWxheWVyPSJsYXllcjEiCiAgICAgc2hvd2dyaWQ9InRydWUiCiAgICAgaW5rc2NhcGU6Z3JpZC1iYm94PSJ0cnVlIgogICAgIGlua3NjYXBlOmdyaWQtcG9pbnRzPSJ0cnVlIgogICAgIGdyaWR0b2xlcmFuY2U9IjEwMDAwIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTM5OSIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI4NzQiCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjM3IgogICAgIGlua3NjYXBlOndpbmRvdy15PSItNCIKICAgICBpbmtzY2FwZTpzbmFwLWJib3g9InRydWUiPgogICAgPGlua3NjYXBlOmdyaWQKICAgICAgIGlkPSJHcmlkRnJvbVByZTA0NlNldHRpbmdzIgogICAgICAgdHlwZT0ieHlncmlkIgogICAgICAgb3JpZ2lueD0iMHB4IgogICAgICAgb3JpZ2lueT0iMHB4IgogICAgICAgc3BhY2luZ3g9IjFweCIKICAgICAgIHNwYWNpbmd5PSIxcHgiCiAgICAgICBjb2xvcj0iIzAwMDBmZiIKICAgICAgIGVtcGNvbG9yPSIjMDAwMGZmIgogICAgICAgb3BhY2l0eT0iMC4yIgogICAgICAgZW1wb3BhY2l0eT0iMC40IgogICAgICAgZW1wc3BhY2luZz0iNSIKICAgICAgIHZpc2libGU9InRydWUiCiAgICAgICBlbmFibGVkPSJ0cnVlIiAvPgogIDwvc29kaXBvZGk6bmFtZWR2aWV3PgogIDxtZXRhZGF0YQogICAgIGlkPSJtZXRhZGF0YTciPgogICAgPHJkZjpSREY+CiAgICAgIDxjYzpXb3JrCiAgICAgICAgIHJkZjphYm91dD0iIj4KICAgICAgICA8ZGM6Zm9ybWF0PmltYWdlL3N2Zyt4bWw8L2RjOmZvcm1hdD4KICAgICAgICA8ZGM6dHlwZQogICAgICAgICAgIHJkZjpyZXNvdXJjZT0iaHR0cDovL3B1cmwub3JnL2RjL2RjbWl0eXBlL1N0aWxsSW1hZ2UiIC8+CiAgICAgIDwvY2M6V29yaz4KICAgIDwvcmRmOlJERj4KICA8L21ldGFkYXRhPgogIDxnCiAgICAgaW5rc2NhcGU6bGFiZWw9IkxheWVyIDEiCiAgICAgaW5rc2NhcGU6Z3JvdXBtb2RlPSJsYXllciIKICAgICBpZD0ibGF5ZXIxIj4KICAgIDxwYXRoCiAgICAgICBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoyO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1vcGFjaXR5OjEiCiAgICAgICBkPSJNIDc5LDI1IEMgOTksMjUgOTUsMjUgOTUsMjUiCiAgICAgICBpZD0icGF0aDMwNTkiCiAgICAgICBzb2RpcG9kaTpub2RldHlwZXM9ImNjIiAvPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjI7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Ik0gMzEsMTUgNSwxNSIKICAgICAgIGlkPSJwYXRoMzA2MSIgLz4KICAgIDxwYXRoCiAgICAgICBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoxLjk5OTk5OTg4O3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1vcGFjaXR5OjEiCiAgICAgICBkPSJNIDMyLDM1IDUsMzUiCiAgICAgICBpZD0icGF0aDM5NDQiIC8+CiAgICA8ZwogICAgICAgaWQ9ImcyNTYwIgogICAgICAgaW5rc2NhcGU6bGFiZWw9IkxheWVyIDEiCiAgICAgICB0cmFuc2Zvcm09InRyYW5zbGF0ZSgyNi41LC0zOS41KSI+CiAgICAgIDxwYXRoCiAgICAgICAgIHN0eWxlPSJmaWxsOiMwMDAwMDA7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOmV2ZW5vZGQ7c3Ryb2tlOm5vbmU7c3Ryb2tlLXdpZHRoOjM7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgICAgZD0iTSAtMi40MDYyNSw0NC41IEwgLTAuNDA2MjUsNDYuOTM3NSBDIC0wLjQwNjI1LDQ2LjkzNzUgNS4yNSw1My45Mzc1NDkgNS4yNSw2NC41IEMgNS4yNSw3NS4wNjI0NTEgLTAuNDA2MjUsODIuMDYyNSAtMC40MDYyNSw4Mi4wNjI1IEwgLTIuNDA2MjUsODQuNSBMIDAuNzUsODQuNSBMIDE0Ljc1LDg0LjUgQyAxNy4xNTgwNzYsODQuNTAwMDAxIDIyLjQzOTY5OSw4NC41MjQ1MTQgMjguMzc1LDgyLjA5Mzc1IEMgMzQuMzEwMzAxLDc5LjY2Mjk4NiA0MC45MTE1MzYsNzQuNzUwNDg0IDQ2LjA2MjUsNjUuMjE4NzUgTCA0NC43NSw2NC41IEwgNDYuMDYyNSw2My43ODEyNSBDIDM1Ljc1OTM4Nyw0NC43MTU1OSAxOS41MDY1NzQsNDQuNSAxNC43NSw0NC41IEwgMC43NSw0NC41IEwgLTIuNDA2MjUsNDQuNSB6IE0gMy40Njg3NSw0Ny41IEwgMTQuNzUsNDcuNSBDIDE5LjQzNDE3Myw0Ny41IDMzLjAzNjg1LDQ3LjM2OTc5MyA0Mi43MTg3NSw2NC41IEMgMzcuOTUxOTY0LDcyLjkyOTA3NSAzMi4xOTc0NjksNzcuMTgzOTEgMjcsNzkuMzEyNSBDIDIxLjYzOTMzOSw4MS41MDc5MjQgMTcuMTU4MDc1LDgxLjUwMDAwMSAxNC43NSw4MS41IEwgMy41LDgxLjUgQyA1LjM3MzU4ODQsNzguMzkxNTY2IDguMjUsNzIuNDUwNjUgOC4yNSw2NC41IEMgOC4yNSw1Ni41MjY2NDYgNS4zNDE0Njg2LDUwLjU5OTgxNSAzLjQ2ODc1LDQ3LjUgeiIKICAgICAgICAgaWQ9InBhdGg0OTczIgogICAgICAgICBzb2RpcG9kaTpub2RldHlwZXM9ImNjc2NjY2NzY2NjY2NjY2Njc2Njc2MiIC8+CiAgICAgIDxwYXRoCiAgICAgICAgIHNvZGlwb2RpOnR5cGU9ImFyYyIKICAgICAgICAgc3R5bGU9ImZpbGw6bm9uZTtmaWxsLW9wYWNpdHk6MTtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MztzdHJva2UtbGluZWpvaW46bWl0ZXI7bWFya2VyOm5vbmU7c3Ryb2tlLW9wYWNpdHk6MTt2aXNpYmlsaXR5OnZpc2libGU7ZGlzcGxheTppbmxpbmU7b3ZlcmZsb3c6dmlzaWJsZTtlbmFibGUtYmFja2dyb3VuZDphY2N1bXVsYXRlIgogICAgICAgICBpZD0icGF0aDI2MDQiCiAgICAgICAgIHNvZGlwb2RpOmN4PSI3NSIKICAgICAgICAgc29kaXBvZGk6Y3k9IjI1IgogICAgICAgICBzb2RpcG9kaTpyeD0iNCIKICAgICAgICAgc29kaXBvZGk6cnk9IjQiCiAgICAgICAgIGQ9Ik0gNzksMjUgQSA0LDQgMCAxIDEgNzEsMjUgQSA0LDQgMCAxIDEgNzksMjUgeiIKICAgICAgICAgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoLTI2LjUsMzkuNSkiIC8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K"
|
}}},joint.shapes.logic.Gate21.prototype.defaults),operation:function(a,b){return!(a||b)}}),joint.shapes.logic.Nand=joint.shapes.logic.Gate21.extend({defaults:joint.util.deepSupplement({type:"logic.Nand",attrs:{image:{"xlink:href":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnCiAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIKICAgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIKICAgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgogICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIKICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiCiAgIHdpZHRoPSIxMDAiCiAgIGhlaWdodD0iNTAiCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ2IgogICB2ZXJzaW9uPSIxLjAiCiAgIHNvZGlwb2RpOmRvY25hbWU9Ik5BTkQgQU5TSS5zdmciCiAgIGlua3NjYXBlOm91dHB1dF9leHRlbnNpb249Im9yZy5pbmtzY2FwZS5vdXRwdXQuc3ZnLmlua3NjYXBlIj4KICA8ZGVmcwogICAgIGlkPSJkZWZzNCI+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMTUgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfej0iNTAgOiAxNSA6IDEiCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMjUgOiAxMCA6IDEiCiAgICAgICBpZD0icGVyc3BlY3RpdmUyNzE0IiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDAuNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF96PSIxIDogMC41IDogMSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIwLjUgOiAwLjMzMzMzMzMzIDogMSIKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI4MDYiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI4MTkiCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMzcyLjA0NzI0IDogMzUwLjc4NzM5IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9Ijc0NC4wOTQ0OCA6IDUyNi4xODEwOSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogNTI2LjE4MTA5IDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI3NzciCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iNzUgOiA0MCA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF96PSIxNTAgOiA2MCA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogNjAgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMzI3NSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSI1MCA6IDMzLjMzMzMzMyA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF96PSIxMDAgOiA1MCA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogNTAgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlNTUzMyIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIzMiA6IDIxLjMzMzMzMyA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF96PSI2NCA6IDMyIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAzMiA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogIDwvZGVmcz4KICA8c29kaXBvZGk6bmFtZWR2aWV3CiAgICAgaWQ9ImJhc2UiCiAgICAgcGFnZWNvbG9yPSIjZmZmZmZmIgogICAgIGJvcmRlcmNvbG9yPSIjNjY2NjY2IgogICAgIGJvcmRlcm9wYWNpdHk9IjEuMCIKICAgICBpbmtzY2FwZTpwYWdlb3BhY2l0eT0iMC4wIgogICAgIGlua3NjYXBlOnBhZ2VzaGFkb3c9IjIiCiAgICAgaW5rc2NhcGU6em9vbT0iMTYiCiAgICAgaW5rc2NhcGU6Y3g9Ijc4LjI4MzMwNyIKICAgICBpbmtzY2FwZTpjeT0iMTYuNDQyODQzIgogICAgIGlua3NjYXBlOmRvY3VtZW50LXVuaXRzPSJweCIKICAgICBpbmtzY2FwZTpjdXJyZW50LWxheWVyPSJsYXllcjEiCiAgICAgc2hvd2dyaWQ9InRydWUiCiAgICAgaW5rc2NhcGU6Z3JpZC1iYm94PSJ0cnVlIgogICAgIGlua3NjYXBlOmdyaWQtcG9pbnRzPSJ0cnVlIgogICAgIGdyaWR0b2xlcmFuY2U9IjEwMDAwIgogICAgIGlua3NjYXBlOndpbmRvdy13aWR0aD0iMTM5OSIKICAgICBpbmtzY2FwZTp3aW5kb3ctaGVpZ2h0PSI4NzQiCiAgICAgaW5rc2NhcGU6d2luZG93LXg9IjMzIgogICAgIGlua3NjYXBlOndpbmRvdy15PSIwIgogICAgIGlua3NjYXBlOnNuYXAtYmJveD0idHJ1ZSI+CiAgICA8aW5rc2NhcGU6Z3JpZAogICAgICAgaWQ9IkdyaWRGcm9tUHJlMDQ2U2V0dGluZ3MiCiAgICAgICB0eXBlPSJ4eWdyaWQiCiAgICAgICBvcmlnaW54PSIwcHgiCiAgICAgICBvcmlnaW55PSIwcHgiCiAgICAgICBzcGFjaW5neD0iMXB4IgogICAgICAgc3BhY2luZ3k9IjFweCIKICAgICAgIGNvbG9yPSIjMDAwMGZmIgogICAgICAgZW1wY29sb3I9IiMwMDAwZmYiCiAgICAgICBvcGFjaXR5PSIwLjIiCiAgICAgICBlbXBvcGFjaXR5PSIwLjQiCiAgICAgICBlbXBzcGFjaW5nPSI1IgogICAgICAgdmlzaWJsZT0idHJ1ZSIKICAgICAgIGVuYWJsZWQ9InRydWUiIC8+CiAgPC9zb2RpcG9kaTpuYW1lZHZpZXc+CiAgPG1ldGFkYXRhCiAgICAgaWQ9Im1ldGFkYXRhNyI+CiAgICA8cmRmOlJERj4KICAgICAgPGNjOldvcmsKICAgICAgICAgcmRmOmFib3V0PSIiPgogICAgICAgIDxkYzpmb3JtYXQ+aW1hZ2Uvc3ZnK3htbDwvZGM6Zm9ybWF0PgogICAgICAgIDxkYzp0eXBlCiAgICAgICAgICAgcmRmOnJlc291cmNlPSJodHRwOi8vcHVybC5vcmcvZGMvZGNtaXR5cGUvU3RpbGxJbWFnZSIgLz4KICAgICAgPC9jYzpXb3JrPgogICAgPC9yZGY6UkRGPgogIDwvbWV0YWRhdGE+CiAgPGcKICAgICBpbmtzY2FwZTpsYWJlbD0iTGF5ZXIgMSIKICAgICBpbmtzY2FwZTpncm91cG1vZGU9ImxheWVyIgogICAgIGlkPSJsYXllcjEiPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjI7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Ik0gNzksMjUgQyA5MS44LDI1IDk1LDI1IDk1LDI1IgogICAgICAgaWQ9InBhdGgzMDU5IgogICAgICAgc29kaXBvZGk6bm9kZXR5cGVzPSJjYyIgLz4KICAgIDxwYXRoCiAgICAgICBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoyO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1vcGFjaXR5OjEiCiAgICAgICBkPSJNIDMxLDE1IDUsMTUiCiAgICAgICBpZD0icGF0aDMwNjEiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MS45OTk5OTk4ODtzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgZD0iTSAzMiwzNSA1LDM1IgogICAgICAgaWQ9InBhdGgzOTQ0IiAvPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmb250LXNpemU6bWVkaXVtO2ZvbnQtc3R5bGU6bm9ybWFsO2ZvbnQtdmFyaWFudDpub3JtYWw7Zm9udC13ZWlnaHQ6bm9ybWFsO2ZvbnQtc3RyZXRjaDpub3JtYWw7dGV4dC1pbmRlbnQ6MDt0ZXh0LWFsaWduOnN0YXJ0O3RleHQtZGVjb3JhdGlvbjpub25lO2xpbmUtaGVpZ2h0Om5vcm1hbDtsZXR0ZXItc3BhY2luZzpub3JtYWw7d29yZC1zcGFjaW5nOm5vcm1hbDt0ZXh0LXRyYW5zZm9ybTpub25lO2RpcmVjdGlvbjpsdHI7YmxvY2stcHJvZ3Jlc3Npb246dGI7d3JpdGluZy1tb2RlOmxyLXRiO3RleHQtYW5jaG9yOnN0YXJ0O2ZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MzttYXJrZXI6bm9uZTt2aXNpYmlsaXR5OnZpc2libGU7ZGlzcGxheTppbmxpbmU7b3ZlcmZsb3c6dmlzaWJsZTtlbmFibGUtYmFja2dyb3VuZDphY2N1bXVsYXRlO2ZvbnQtZmFtaWx5OkJpdHN0cmVhbSBWZXJhIFNhbnM7LWlua3NjYXBlLWZvbnQtc3BlY2lmaWNhdGlvbjpCaXRzdHJlYW0gVmVyYSBTYW5zIgogICAgICAgZD0iTSAzMCw1IEwgMzAsNi40Mjg1NzE0IEwgMzAsNDMuNTcxNDI5IEwgMzAsNDUgTCAzMS40Mjg1NzEsNDUgTCA1MC40NzYxOSw0NSBDIDYxLjc0NDA5OCw0NSA3MC40NzYxOSwzNS45OTk5NTUgNzAuNDc2MTksMjUgQyA3MC40NzYxOSwxNC4wMDAwNDUgNjEuNzQ0MDk5LDUuMDAwMDAwMiA1MC40NzYxOSw1IEMgNTAuNDc2MTksNSA1MC40NzYxOSw1IDMxLjQyODU3MSw1IEwgMzAsNSB6IE0gMzIuODU3MTQzLDcuODU3MTQyOSBDIDQwLjgzNDI2NCw3Ljg1NzE0MjkgNDUuOTE4MzY4LDcuODU3MTQyOSA0OC4wOTUyMzgsNy44NTcxNDI5IEMgNDkuMjg1NzE0LDcuODU3MTQyOSA0OS44ODA5NTIsNy44NTcxNDI5IDUwLjE3ODU3MSw3Ljg1NzE0MjkgQyA1MC4zMjczODEsNy44NTcxNDI5IDUwLjQwOTIyNyw3Ljg1NzE0MjkgNTAuNDQ2NDI5LDcuODU3MTQyOSBDIDUwLjQ2NTAyOSw3Ljg1NzE0MjkgNTAuNDcxNTQzLDcuODU3MTQyOSA1MC40NzYxOSw3Ljg1NzE0MjkgQyA2MC4yMzY4NTMsNy44NTcxNDMgNjcuMTQyODU3LDE1LjQ5NzA5OCA2Ny4xNDI4NTcsMjUgQyA2Ny4xNDI4NTcsMzQuNTAyOTAyIDU5Ljc2MDY2Miw0Mi4xNDI4NTcgNTAsNDIuMTQyODU3IEwgMzIuODU3MTQzLDQyLjE0Mjg1NyBMIDMyLjg1NzE0Myw3Ljg1NzE0MjkgeiIKICAgICAgIGlkPSJwYXRoMjg4NCIKICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2NjY2Njc2NjY2Nzc3Nzc2NjYyIgLz4KICAgIDxwYXRoCiAgICAgICBzb2RpcG9kaTp0eXBlPSJhcmMiCiAgICAgICBzdHlsZT0iZmlsbDpub25lO2ZpbGwtb3BhY2l0eToxO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDozO3N0cm9rZS1saW5lam9pbjptaXRlcjttYXJrZXI6bm9uZTtzdHJva2Utb3BhY2l0eToxO3Zpc2liaWxpdHk6dmlzaWJsZTtkaXNwbGF5OmlubGluZTtvdmVyZmxvdzp2aXNpYmxlO2VuYWJsZS1iYWNrZ3JvdW5kOmFjY3VtdWxhdGUiCiAgICAgICBpZD0icGF0aDQwMDgiCiAgICAgICBzb2RpcG9kaTpjeD0iNzUiCiAgICAgICBzb2RpcG9kaTpjeT0iMjUiCiAgICAgICBzb2RpcG9kaTpyeD0iNCIKICAgICAgIHNvZGlwb2RpOnJ5PSI0IgogICAgICAgZD0iTSA3OSwyNSBBIDQsNCAwIDEgMSA3MSwyNSBBIDQsNCAwIDEgMSA3OSwyNSB6IiAvPgogIDwvZz4KPC9zdmc+Cg=="}}},joint.shapes.logic.Gate21.prototype.defaults),operation:function(a,b){return!(a&&b)}}),joint.shapes.logic.Xor=joint.shapes.logic.Gate21.extend({defaults:joint.util.deepSupplement({type:"logic.Xor",attrs:{image:{"xlink:href":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnCiAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIKICAgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIKICAgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgogICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIKICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiCiAgIHdpZHRoPSIxMDAiCiAgIGhlaWdodD0iNTAiCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ2IgogICB2ZXJzaW9uPSIxLjAiCiAgIHNvZGlwb2RpOmRvY25hbWU9IlhPUiBBTlNJLnN2ZyIKICAgaW5rc2NhcGU6b3V0cHV0X2V4dGVuc2lvbj0ib3JnLmlua3NjYXBlLm91dHB1dC5zdmcuaW5rc2NhcGUiPgogIDxkZWZzCiAgICAgaWQ9ImRlZnM0Ij4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAxNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF96PSI1MCA6IDE1IDogMSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIyNSA6IDEwIDogMSIKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI3MTQiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMC41IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEgOiAwLjUgOiAxIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjAuNSA6IDAuMzMzMzMzMzMgOiAxIgogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgwNiIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjgxOSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIzNzIuMDQ3MjQgOiAzNTAuNzg3MzkgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNzQ0LjA5NDQ4IDogNTI2LjE4MTA5IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MjYuMTgxMDkgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMjc3NyIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSI3NSA6IDQwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjE1MCA6IDYwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA2MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmUzMjc1IgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjUwIDogMzMuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjEwMCA6IDUwIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiA1MCA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmU1NTMzIgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjMyIDogMjEuMzMzMzMzIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjY0IDogMzIgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDMyIDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI1NTciCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMjUgOiAxNi42NjY2NjcgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfej0iNTAgOiAyNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMjUgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICA8L2RlZnM+CiAgPHNvZGlwb2RpOm5hbWVkdmlldwogICAgIGlkPSJiYXNlIgogICAgIHBhZ2Vjb2xvcj0iI2ZmZmZmZiIKICAgICBib3JkZXJjb2xvcj0iIzY2NjY2NiIKICAgICBib3JkZXJvcGFjaXR5PSIxLjAiCiAgICAgaW5rc2NhcGU6cGFnZW9wYWNpdHk9IjAuMCIKICAgICBpbmtzY2FwZTpwYWdlc2hhZG93PSIyIgogICAgIGlua3NjYXBlOnpvb209IjUuNjU2ODU0MiIKICAgICBpbmtzY2FwZTpjeD0iMjUuOTM4MTE2IgogICAgIGlua3NjYXBlOmN5PSIxNy4yMzAwNSIKICAgICBpbmtzY2FwZTpkb2N1bWVudC11bml0cz0icHgiCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0ibGF5ZXIxIgogICAgIHNob3dncmlkPSJ0cnVlIgogICAgIGlua3NjYXBlOmdyaWQtYmJveD0idHJ1ZSIKICAgICBpbmtzY2FwZTpncmlkLXBvaW50cz0idHJ1ZSIKICAgICBncmlkdG9sZXJhbmNlPSIxMDAwMCIKICAgICBpbmtzY2FwZTp3aW5kb3ctd2lkdGg9IjEzOTkiCiAgICAgaW5rc2NhcGU6d2luZG93LWhlaWdodD0iODc0IgogICAgIGlua3NjYXBlOndpbmRvdy14PSIzMyIKICAgICBpbmtzY2FwZTp3aW5kb3cteT0iMCIKICAgICBpbmtzY2FwZTpzbmFwLWJib3g9InRydWUiPgogICAgPGlua3NjYXBlOmdyaWQKICAgICAgIGlkPSJHcmlkRnJvbVByZTA0NlNldHRpbmdzIgogICAgICAgdHlwZT0ieHlncmlkIgogICAgICAgb3JpZ2lueD0iMHB4IgogICAgICAgb3JpZ2lueT0iMHB4IgogICAgICAgc3BhY2luZ3g9IjFweCIKICAgICAgIHNwYWNpbmd5PSIxcHgiCiAgICAgICBjb2xvcj0iIzAwMDBmZiIKICAgICAgIGVtcGNvbG9yPSIjMDAwMGZmIgogICAgICAgb3BhY2l0eT0iMC4yIgogICAgICAgZW1wb3BhY2l0eT0iMC40IgogICAgICAgZW1wc3BhY2luZz0iNSIKICAgICAgIHZpc2libGU9InRydWUiCiAgICAgICBlbmFibGVkPSJ0cnVlIiAvPgogIDwvc29kaXBvZGk6bmFtZWR2aWV3PgogIDxtZXRhZGF0YQogICAgIGlkPSJtZXRhZGF0YTciPgogICAgPHJkZjpSREY+CiAgICAgIDxjYzpXb3JrCiAgICAgICAgIHJkZjphYm91dD0iIj4KICAgICAgICA8ZGM6Zm9ybWF0PmltYWdlL3N2Zyt4bWw8L2RjOmZvcm1hdD4KICAgICAgICA8ZGM6dHlwZQogICAgICAgICAgIHJkZjpyZXNvdXJjZT0iaHR0cDovL3B1cmwub3JnL2RjL2RjbWl0eXBlL1N0aWxsSW1hZ2UiIC8+CiAgICAgIDwvY2M6V29yaz4KICAgIDwvcmRmOlJERj4KICA8L21ldGFkYXRhPgogIDxnCiAgICAgaW5rc2NhcGU6bGFiZWw9IkxheWVyIDEiCiAgICAgaW5rc2NhcGU6Z3JvdXBtb2RlPSJsYXllciIKICAgICBpZD0ibGF5ZXIxIj4KICAgIDxwYXRoCiAgICAgICBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoyO3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1vcGFjaXR5OjEiCiAgICAgICBkPSJtIDcwLDI1IGMgMjAsMCAyNSwwIDI1LDAiCiAgICAgICBpZD0icGF0aDMwNTkiCiAgICAgICBzb2RpcG9kaTpub2RldHlwZXM9ImNjIiAvPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjEuOTk5OTk5ODg7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Ik0gMzAuMzg1NzE3LDE1IEwgNC45OTk5OTk4LDE1IgogICAgICAgaWQ9InBhdGgzMDYxIiAvPgogICAgPHBhdGgKICAgICAgIHN0eWxlPSJmaWxsOm5vbmU7c3Ryb2tlOiMwMDAwMDA7c3Ryb2tlLXdpZHRoOjEuOTk5OTk5NzY7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgIGQ9Ik0gMzEuMzYyMDkxLDM1IEwgNC45OTk5OTk4LDM1IgogICAgICAgaWQ9InBhdGgzOTQ0IiAvPgogICAgPGcKICAgICAgIGlkPSJnMjU2MCIKICAgICAgIGlua3NjYXBlOmxhYmVsPSJMYXllciAxIgogICAgICAgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMjYuNSwtMzkuNSkiPgogICAgICA8cGF0aAogICAgICAgICBpZD0icGF0aDM1MTYiCiAgICAgICAgIHN0eWxlPSJmaWxsOiMwMDAwMDA7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOmV2ZW5vZGQ7c3Ryb2tlOm5vbmU7c3Ryb2tlLXdpZHRoOjM7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgICAgZD0iTSAtMi4yNSw4MS41MDAwMDUgQyAtMy44NDczNzQsODQuMTQ0NDA1IC00LjUsODQuNTAwMDA1IC00LjUsODQuNTAwMDA1IEwgLTguMTU2MjUsODQuNTAwMDA1IEwgLTYuMTU2MjUsODIuMDYyNTA1IEMgLTYuMTU2MjUsODIuMDYyNTA1IC0wLjUsNzUuMDYyNDUxIC0wLjUsNjQuNSBDIC0wLjUsNTMuOTM3NTQ5IC02LjE1NjI1LDQ2LjkzNzUgLTYuMTU2MjUsNDYuOTM3NSBMIC04LjE1NjI1LDQ0LjUgTCAtNC41LDQ0LjUgQyAtMy43MTg3NSw0NS40Mzc1IC0zLjA3ODEyNSw0Ni4xNTYyNSAtMi4yODEyNSw0Ny41IEMgLTAuNDA4NTMxLDUwLjU5OTgxNSAyLjUsNTYuNTI2NjQ2IDIuNSw2NC41IEMgMi41LDcyLjQ1MDY1IC0wLjM5NjY5Nyw3OC4zNzk0MjUgLTIuMjUsODEuNTAwMDA1IHoiCiAgICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2NjY3NjY2Njc2MiIC8+CiAgICAgIDxwYXRoCiAgICAgICAgIHN0eWxlPSJmaWxsOiMwMDAwMDA7ZmlsbC1vcGFjaXR5OjE7ZmlsbC1ydWxlOmV2ZW5vZGQ7c3Ryb2tlOm5vbmU7c3Ryb2tlLXdpZHRoOjM7c3Ryb2tlLWxpbmVjYXA6YnV0dDtzdHJva2UtbGluZWpvaW46bWl0ZXI7c3Ryb2tlLW9wYWNpdHk6MSIKICAgICAgICAgZD0iTSAtMi40MDYyNSw0NC41IEwgLTAuNDA2MjUsNDYuOTM3NSBDIC0wLjQwNjI1LDQ2LjkzNzUgNS4yNSw1My45Mzc1NDkgNS4yNSw2NC41IEMgNS4yNSw3NS4wNjI0NTEgLTAuNDA2MjUsODIuMDYyNSAtMC40MDYyNSw4Mi4wNjI1IEwgLTIuNDA2MjUsODQuNSBMIDAuNzUsODQuNSBMIDE0Ljc1LDg0LjUgQyAxNy4xNTgwNzYsODQuNTAwMDAxIDIyLjQzOTY5OSw4NC41MjQ1MTQgMjguMzc1LDgyLjA5Mzc1IEMgMzQuMzEwMzAxLDc5LjY2Mjk4NiA0MC45MTE1MzYsNzQuNzUwNDg0IDQ2LjA2MjUsNjUuMjE4NzUgTCA0NC43NSw2NC41IEwgNDYuMDYyNSw2My43ODEyNSBDIDM1Ljc1OTM4Nyw0NC43MTU1OSAxOS41MDY1NzQsNDQuNSAxNC43NSw0NC41IEwgMC43NSw0NC41IEwgLTIuNDA2MjUsNDQuNSB6IE0gMy40Njg3NSw0Ny41IEwgMTQuNzUsNDcuNSBDIDE5LjQzNDE3Myw0Ny41IDMzLjAzNjg1LDQ3LjM2OTc5MyA0Mi43MTg3NSw2NC41IEMgMzcuOTUxOTY0LDcyLjkyOTA3NSAzMi4xOTc0NjksNzcuMTgzOTEgMjcsNzkuMzEyNSBDIDIxLjYzOTMzOSw4MS41MDc5MjQgMTcuMTU4MDc1LDgxLjUwMDAwMSAxNC43NSw4MS41IEwgMy41LDgxLjUgQyA1LjM3MzU4ODQsNzguMzkxNTY2IDguMjUsNzIuNDUwNjUgOC4yNSw2NC41IEMgOC4yNSw1Ni41MjY2NDYgNS4zNDE0Njg2LDUwLjU5OTgxNSAzLjQ2ODc1LDQ3LjUgeiIKICAgICAgICAgaWQ9InBhdGg0OTczIgogICAgICAgICBzb2RpcG9kaTpub2RldHlwZXM9ImNjc2NjY2NzY2NjY2NjY2Njc2Njc2MiIC8+CiAgICA8L2c+CiAgPC9nPgo8L3N2Zz4K"}}},joint.shapes.logic.Gate21.prototype.defaults),operation:function(a,b){return(!a||b)&&(a||!b)}}),joint.shapes.logic.Xnor=joint.shapes.logic.Gate21.extend({defaults:joint.util.deepSupplement({type:"logic.Xnor",attrs:{image:{"xlink:href":"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnCiAgIHhtbG5zOmRjPSJodHRwOi8vcHVybC5vcmcvZGMvZWxlbWVudHMvMS4xLyIKICAgeG1sbnM6Y2M9Imh0dHA6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL25zIyIKICAgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIgogICB4bWxuczpzdmc9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIgogICB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zOnNvZGlwb2RpPSJodHRwOi8vc29kaXBvZGkuc291cmNlZm9yZ2UubmV0L0RURC9zb2RpcG9kaS0wLmR0ZCIKICAgeG1sbnM6aW5rc2NhcGU9Imh0dHA6Ly93d3cuaW5rc2NhcGUub3JnL25hbWVzcGFjZXMvaW5rc2NhcGUiCiAgIHdpZHRoPSIxMDAiCiAgIGhlaWdodD0iNTAiCiAgIGlkPSJzdmcyIgogICBzb2RpcG9kaTp2ZXJzaW9uPSIwLjMyIgogICBpbmtzY2FwZTp2ZXJzaW9uPSIwLjQ2IgogICB2ZXJzaW9uPSIxLjAiCiAgIHNvZGlwb2RpOmRvY25hbWU9IlhOT1IgQU5TSS5zdmciCiAgIGlua3NjYXBlOm91dHB1dF9leHRlbnNpb249Im9yZy5pbmtzY2FwZS5vdXRwdXQuc3ZnLmlua3NjYXBlIj4KICA8ZGVmcwogICAgIGlkPSJkZWZzNCI+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogMTUgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfej0iNTAgOiAxNSA6IDEiCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMjUgOiAxMCA6IDEiCiAgICAgICBpZD0icGVyc3BlY3RpdmUyNzE0IiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDAuNSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF96PSIxIDogMC41IDogMSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIwLjUgOiAwLjMzMzMzMzMzIDogMSIKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI4MDYiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI4MTkiCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iMzcyLjA0NzI0IDogMzUwLjc4NzM5IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9Ijc0NC4wOTQ0OCA6IDUyNi4xODEwOSA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogNTI2LjE4MTA5IDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgICA8aW5rc2NhcGU6cGVyc3BlY3RpdmUKICAgICAgIGlkPSJwZXJzcGVjdGl2ZTI3NzciCiAgICAgICBpbmtzY2FwZTpwZXJzcDNkLW9yaWdpbj0iNzUgOiA0MCA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF96PSIxNTAgOiA2MCA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogNjAgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlMzI3NSIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSI1MCA6IDMzLjMzMzMzMyA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF96PSIxMDAgOiA1MCA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF95PSIwIDogMTAwMCA6IDAiCiAgICAgICBpbmtzY2FwZTp2cF94PSIwIDogNTAgOiAxIgogICAgICAgc29kaXBvZGk6dHlwZT0iaW5rc2NhcGU6cGVyc3AzZCIgLz4KICAgIDxpbmtzY2FwZTpwZXJzcGVjdGl2ZQogICAgICAgaWQ9InBlcnNwZWN0aXZlNTUzMyIKICAgICAgIGlua3NjYXBlOnBlcnNwM2Qtb3JpZ2luPSIzMiA6IDIxLjMzMzMzMyA6IDEiCiAgICAgICBpbmtzY2FwZTp2cF96PSI2NCA6IDMyIDogMSIKICAgICAgIGlua3NjYXBlOnZwX3k9IjAgOiAxMDAwIDogMCIKICAgICAgIGlua3NjYXBlOnZwX3g9IjAgOiAzMiA6IDEiCiAgICAgICBzb2RpcG9kaTp0eXBlPSJpbmtzY2FwZTpwZXJzcDNkIiAvPgogICAgPGlua3NjYXBlOnBlcnNwZWN0aXZlCiAgICAgICBpZD0icGVyc3BlY3RpdmUyNTU3IgogICAgICAgaW5rc2NhcGU6cGVyc3AzZC1vcmlnaW49IjI1IDogMTYuNjY2NjY3IDogMSIKICAgICAgIGlua3NjYXBlOnZwX3o9IjUwIDogMjUgOiAxIgogICAgICAgaW5rc2NhcGU6dnBfeT0iMCA6IDEwMDAgOiAwIgogICAgICAgaW5rc2NhcGU6dnBfeD0iMCA6IDI1IDogMSIKICAgICAgIHNvZGlwb2RpOnR5cGU9Imlua3NjYXBlOnBlcnNwM2QiIC8+CiAgPC9kZWZzPgogIDxzb2RpcG9kaTpuYW1lZHZpZXcKICAgICBpZD0iYmFzZSIKICAgICBwYWdlY29sb3I9IiNmZmZmZmYiCiAgICAgYm9yZGVyY29sb3I9IiM2NjY2NjYiCiAgICAgYm9yZGVyb3BhY2l0eT0iMS4wIgogICAgIGlua3NjYXBlOnBhZ2VvcGFjaXR5PSIwLjAiCiAgICAgaW5rc2NhcGU6cGFnZXNoYWRvdz0iMiIKICAgICBpbmtzY2FwZTp6b29tPSI0IgogICAgIGlua3NjYXBlOmN4PSI5NS43MjM2NiIKICAgICBpbmtzY2FwZTpjeT0iLTI2Ljc3NTAyMyIKICAgICBpbmtzY2FwZTpkb2N1bWVudC11bml0cz0icHgiCiAgICAgaW5rc2NhcGU6Y3VycmVudC1sYXllcj0ibGF5ZXIxIgogICAgIHNob3dncmlkPSJ0cnVlIgogICAgIGlua3NjYXBlOmdyaWQtYmJveD0idHJ1ZSIKICAgICBpbmtzY2FwZTpncmlkLXBvaW50cz0idHJ1ZSIKICAgICBncmlkdG9sZXJhbmNlPSIxMDAwMCIKICAgICBpbmtzY2FwZTp3aW5kb3ctd2lkdGg9IjEzOTkiCiAgICAgaW5rc2NhcGU6d2luZG93LWhlaWdodD0iODc0IgogICAgIGlua3NjYXBlOndpbmRvdy14PSIzMyIKICAgICBpbmtzY2FwZTp3aW5kb3cteT0iMCIKICAgICBpbmtzY2FwZTpzbmFwLWJib3g9InRydWUiPgogICAgPGlua3NjYXBlOmdyaWQKICAgICAgIGlkPSJHcmlkRnJvbVByZTA0NlNldHRpbmdzIgogICAgICAgdHlwZT0ieHlncmlkIgogICAgICAgb3JpZ2lueD0iMHB4IgogICAgICAgb3JpZ2lueT0iMHB4IgogICAgICAgc3BhY2luZ3g9IjFweCIKICAgICAgIHNwYWNpbmd5PSIxcHgiCiAgICAgICBjb2xvcj0iIzAwMDBmZiIKICAgICAgIGVtcGNvbG9yPSIjMDAwMGZmIgogICAgICAgb3BhY2l0eT0iMC4yIgogICAgICAgZW1wb3BhY2l0eT0iMC40IgogICAgICAgZW1wc3BhY2luZz0iNSIKICAgICAgIHZpc2libGU9InRydWUiCiAgICAgICBlbmFibGVkPSJ0cnVlIiAvPgogIDwvc29kaXBvZGk6bmFtZWR2aWV3PgogIDxtZXRhZGF0YQogICAgIGlkPSJtZXRhZGF0YTciPgogICAgPHJkZjpSREY+CiAgICAgIDxjYzpXb3JrCiAgICAgICAgIHJkZjphYm91dD0iIj4KICAgICAgICA8ZGM6Zm9ybWF0PmltYWdlL3N2Zyt4bWw8L2RjOmZvcm1hdD4KICAgICAgICA8ZGM6dHlwZQogICAgICAgICAgIHJkZjpyZXNvdXJjZT0iaHR0cDovL3B1cmwub3JnL2RjL2RjbWl0eXBlL1N0aWxsSW1hZ2UiIC8+CiAgICAgIDwvY2M6V29yaz4KICAgIDwvcmRmOlJERj4KICA8L21ldGFkYXRhPgogIDxnCiAgICAgaW5rc2NhcGU6bGFiZWw9IkxheWVyIDEiCiAgICAgaW5rc2NhcGU6Z3JvdXBtb2RlPSJsYXllciIKICAgICBpZD0ibGF5ZXIxIj4KICAgIDxwYXRoCiAgICAgICBzdHlsZT0iZmlsbDpub25lO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDoyLjAwMDAwMDI0O3N0cm9rZS1saW5lY2FwOmJ1dHQ7c3Ryb2tlLWxpbmVqb2luOm1pdGVyO3N0cm9rZS1vcGFjaXR5OjEiCiAgICAgICBkPSJNIDc4LjMzMzMzMiwyNSBDIDkxLjY2NjY2NiwyNSA5NSwyNSA5NSwyNSIKICAgICAgIGlkPSJwYXRoMzA1OSIKICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2MiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MS45OTk5OTk4ODtzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgZD0iTSAzMC4zODU3MTcsMTUgTCA0Ljk5OTk5OTgsMTUiCiAgICAgICBpZD0icGF0aDMwNjEiIC8+CiAgICA8cGF0aAogICAgICAgc3R5bGU9ImZpbGw6bm9uZTtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6MS45OTk5OTk3NjtzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgZD0iTSAzMS4zNjIwOTEsMzUgTCA0Ljk5OTk5OTgsMzUiCiAgICAgICBpZD0icGF0aDM5NDQiIC8+CiAgICA8ZwogICAgICAgaWQ9ImcyNTYwIgogICAgICAgaW5rc2NhcGU6bGFiZWw9IkxheWVyIDEiCiAgICAgICB0cmFuc2Zvcm09InRyYW5zbGF0ZSgyNi41LC0zOS41KSI+CiAgICAgIDxwYXRoCiAgICAgICAgIGlkPSJwYXRoMzUxNiIKICAgICAgICAgc3R5bGU9ImZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6ZXZlbm9kZDtzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MztzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgICBkPSJNIC0yLjI1LDgxLjUwMDAwNSBDIC0zLjg0NzM3NCw4NC4xNDQ0MDUgLTQuNSw4NC41MDAwMDUgLTQuNSw4NC41MDAwMDUgTCAtOC4xNTYyNSw4NC41MDAwMDUgTCAtNi4xNTYyNSw4Mi4wNjI1MDUgQyAtNi4xNTYyNSw4Mi4wNjI1MDUgLTAuNSw3NS4wNjI0NTEgLTAuNSw2NC41IEMgLTAuNSw1My45Mzc1NDkgLTYuMTU2MjUsNDYuOTM3NSAtNi4xNTYyNSw0Ni45Mzc1IEwgLTguMTU2MjUsNDQuNSBMIC00LjUsNDQuNSBDIC0zLjcxODc1LDQ1LjQzNzUgLTMuMDc4MTI1LDQ2LjE1NjI1IC0yLjI4MTI1LDQ3LjUgQyAtMC40MDg1MzEsNTAuNTk5ODE1IDIuNSw1Ni41MjY2NDYgMi41LDY0LjUgQyAyLjUsNzIuNDUwNjUgLTAuMzk2Njk3LDc4LjM3OTQyNSAtMi4yNSw4MS41MDAwMDUgeiIKICAgICAgICAgc29kaXBvZGk6bm9kZXR5cGVzPSJjY2Njc2NjY2NzYyIgLz4KICAgICAgPHBhdGgKICAgICAgICAgc3R5bGU9ImZpbGw6IzAwMDAwMDtmaWxsLW9wYWNpdHk6MTtmaWxsLXJ1bGU6ZXZlbm9kZDtzdHJva2U6bm9uZTtzdHJva2Utd2lkdGg6MztzdHJva2UtbGluZWNhcDpidXR0O3N0cm9rZS1saW5lam9pbjptaXRlcjtzdHJva2Utb3BhY2l0eToxIgogICAgICAgICBkPSJNIC0yLjQwNjI1LDQ0LjUgTCAtMC40MDYyNSw0Ni45Mzc1IEMgLTAuNDA2MjUsNDYuOTM3NSA1LjI1LDUzLjkzNzU0OSA1LjI1LDY0LjUgQyA1LjI1LDc1LjA2MjQ1MSAtMC40MDYyNSw4Mi4wNjI1IC0wLjQwNjI1LDgyLjA2MjUgTCAtMi40MDYyNSw4NC41IEwgMC43NSw4NC41IEwgMTQuNzUsODQuNSBDIDE3LjE1ODA3Niw4NC41MDAwMDEgMjIuNDM5Njk5LDg0LjUyNDUxNCAyOC4zNzUsODIuMDkzNzUgQyAzNC4zMTAzMDEsNzkuNjYyOTg2IDQwLjkxMTUzNiw3NC43NTA0ODQgNDYuMDYyNSw2NS4yMTg3NSBMIDQ0Ljc1LDY0LjUgTCA0Ni4wNjI1LDYzLjc4MTI1IEMgMzUuNzU5Mzg3LDQ0LjcxNTU5IDE5LjUwNjU3NCw0NC41IDE0Ljc1LDQ0LjUgTCAwLjc1LDQ0LjUgTCAtMi40MDYyNSw0NC41IHogTSAzLjQ2ODc1LDQ3LjUgTCAxNC43NSw0Ny41IEMgMTkuNDM0MTczLDQ3LjUgMzMuMDM2ODUsNDcuMzY5NzkzIDQyLjcxODc1LDY0LjUgQyAzNy45NTE5NjQsNzIuOTI5MDc1IDMyLjE5NzQ2OSw3Ny4xODM5MSAyNyw3OS4zMTI1IEMgMjEuNjM5MzM5LDgxLjUwNzkyNCAxNy4xNTgwNzUsODEuNTAwMDAxIDE0Ljc1LDgxLjUgTCAzLjUsODEuNSBDIDUuMzczNTg4NCw3OC4zOTE1NjYgOC4yNSw3Mi40NTA2NSA4LjI1LDY0LjUgQyA4LjI1LDU2LjUyNjY0NiA1LjM0MTQ2ODYsNTAuNTk5ODE1IDMuNDY4NzUsNDcuNSB6IgogICAgICAgICBpZD0icGF0aDQ5NzMiCiAgICAgICAgIHNvZGlwb2RpOm5vZGV0eXBlcz0iY2NzY2NjY3NjY2NjY2NjY2NzY2NzYyIgLz4KICAgIDwvZz4KICAgIDxwYXRoCiAgICAgICBzb2RpcG9kaTp0eXBlPSJhcmMiCiAgICAgICBzdHlsZT0iZmlsbDpub25lO2ZpbGwtb3BhY2l0eToxO3N0cm9rZTojMDAwMDAwO3N0cm9rZS13aWR0aDozO3N0cm9rZS1saW5lam9pbjptaXRlcjttYXJrZXI6bm9uZTtzdHJva2Utb3BhY2l0eToxO3Zpc2liaWxpdHk6dmlzaWJsZTtkaXNwbGF5OmlubGluZTtvdmVyZmxvdzp2aXNpYmxlO2VuYWJsZS1iYWNrZ3JvdW5kOmFjY3VtdWxhdGUiCiAgICAgICBpZD0icGF0aDM1NTEiCiAgICAgICBzb2RpcG9kaTpjeD0iNzUiCiAgICAgICBzb2RpcG9kaTpjeT0iMjUiCiAgICAgICBzb2RpcG9kaTpyeD0iNCIKICAgICAgIHNvZGlwb2RpOnJ5PSI0IgogICAgICAgZD0iTSA3OSwyNSBBIDQsNCAwIDEgMSA3MSwyNSBBIDQsNCAwIDEgMSA3OSwyNSB6IiAvPgogIDwvZz4KPC9zdmc+Cg=="}}},joint.shapes.logic.Gate21.prototype.defaults),operation:function(a,b){return(!a||!b)&&(a||b)}}),joint.shapes.logic.Wire=joint.dia.Link.extend({arrowheadMarkup:['<g class="marker-arrowhead-group marker-arrowhead-group-<%= end %>">','<circle class="marker-arrowhead" end="<%= end %>" r="7"/>',"</g>"].join(""),vertexMarkup:['<g class="marker-vertex-group" transform="translate(<%= x %>, <%= y %>)">','<circle class="marker-vertex" idx="<%= idx %>" r="10" />','<g class="marker-vertex-remove-group">','<path class="marker-vertex-remove-area" idx="<%= idx %>" d="M16,5.333c-7.732,0-14,4.701-14,10.5c0,1.982,0.741,3.833,2.016,5.414L2,25.667l5.613-1.441c2.339,1.317,5.237,2.107,8.387,2.107c7.732,0,14-4.701,14-10.5C30,10.034,23.732,5.333,16,5.333z" transform="translate(5, -33)"/>','<path class="marker-vertex-remove" idx="<%= idx %>" transform="scale(.8) translate(9.5, -37)" d="M24.778,21.419 19.276,15.917 24.777,10.415 21.949,7.585 16.447,13.087 10.945,7.585 8.117,10.415 13.618,15.917 8.116,21.419 10.946,24.248 16.447,18.746 21.948,24.248z">',"<title>Remove vertex.</title>","</path>","</g>","</g>"].join(""),defaults:joint.util.deepSupplement({type:"logic.Wire",attrs:{".connection":{"stroke-width":2},".marker-vertex":{r:7}},router:{name:"orthogonal"},connector:{name:"rounded",args:{radius:10}}},joint.dia.Link.prototype.defaults)});
|
if(true)var graphlib=__webpack_require__(6),dagre=__webpack_require__(26);graphlib=graphlib||"undefined"!=typeof window&&window.graphlib,dagre=dagre||"undefined"!=typeof window&&window.dagre,joint.layout.DirectedGraph={layout:function(a,b){var c;c=a instanceof joint.dia.Graph?a:(new joint.dia.Graph).resetCells(a),a=null,b=_.defaults(b||{},{resizeClusters:!0,clusterPadding:10});var d=c.toGraphLib({directed:!0,multigraph:!0,compound:!0,setNodeLabel:function(a){return{width:a.get("size").width,height:a.get("size").height,rank:a.get("rank")}},setEdgeLabel:function(a){return{minLen:a.get("minLen")||1}},setEdgeName:function(a){return a.id}}),e={};return b.rankDir&&(e.rankdir=b.rankDir),b.align&&(e.align=b.align),b.nodeSep&&(e.nodesep=b.nodeSep),b.edgeSep&&(e.edgesep=b.edgeSep),b.rankSep&&(e.ranksep=b.rankSep),b.marginX&&(e.marginx=b.marginX),b.marginY&&(e.marginy=b.marginY),d.setGraph(e),dagre.layout(d,{debugTiming:!!b.debugTiming}),c.startBatch("layout"),c.fromGraphLib(d,{importNode:function(a,c){var d=this.getCell(a),e=c.node(a);b.setPosition?b.setPosition(d,e):d.set("position",{x:e.x-e.width/2,y:e.y-e.height/2})},importEdge:function(a,c){var d=this.getCell(a.name),e=c.edge(a),f=e.points||[];b.setLinkVertices&&(b.setVertices?b.setVertices(d,f):d.set("vertices",f.slice(1,f.length-1)))}}),b.resizeClusters&&_.chain(d.nodes()).filter(function(a){return d.children(a).length>0}).map(c.getCell,c).sortBy(function(a){return-a.getAncestors().length}).invoke("fitEmbeds",{padding:b.clusterPadding}).value(),c.stopBatch("layout"),d.graph()},fromGraphLib:function(a,b){b=b||{};var c=b.importNode||_.noop,d=b.importEdge||_.noop,e=this instanceof joint.dia.Graph?this:new joint.dia.Graph;return a.nodes().forEach(function(d){c.call(e,d,a,e,b)}),a.edges().forEach(function(c){d.call(e,c,a,e,b)}),e},toGraphLib:function(a,b){b=b||{};var c=_.pick(b,"directed","compound","multigraph"),d=new graphlib.Graph(c),e=b.setNodeLabel||_.noop,f=b.setEdgeLabel||_.noop,g=b.setEdgeName||_.noop;return a.get("cells").each(function(a){if(a.isLink()){var b=a.get("source"),c=a.get("target");if(!b.id||!c.id)return;d.setEdge(b.id,c.id,f(a),g(a))}else d.setNode(a.id,e(a)),d.isCompound()&&a.has("parent")&&d.setParent(a.id,a.get("parent"))}),d}},joint.dia.Graph.prototype.toGraphLib=function(a){return joint.layout.DirectedGraph.toGraphLib(this,a)},joint.dia.Graph.prototype.fromGraphLib=function(a,b){return joint.layout.DirectedGraph.fromGraphLib.call(this,a,b)};
|
|
joint.g = g;
|
joint.V = joint.Vectorizer = V;
|
|
return joint;
|
|
}));
|
|
|
/***/ },
|
/* 1 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(global) {// Backbone.js 1.3.3
|
|
// (c) 2010-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
// Backbone may be freely distributed under the MIT license.
|
// For all details and documentation:
|
// http://backbonejs.org
|
|
(function(factory) {
|
|
// Establish the root object, `window` (`self`) in the browser, or `global` on the server.
|
// We use `self` instead of `window` for `WebWorker` support.
|
var root = (typeof self == 'object' && self.self === self && self) ||
|
(typeof global == 'object' && global.global === global && global);
|
|
// Set up Backbone appropriately for the environment. Start with AMD.
|
if (true) {
|
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(2), __webpack_require__(3), exports], __WEBPACK_AMD_DEFINE_RESULT__ = function(_, $, exports) {
|
// Export global even in AMD case in case this script is loaded with
|
// others that may still expect a global Backbone.
|
root.Backbone = factory(root, exports, _, $);
|
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
|
// Next for Node.js or CommonJS. jQuery may not be needed as a module.
|
} else if (typeof exports !== 'undefined') {
|
var _ = require('underscore'), $;
|
try { $ = require('jquery'); } catch (e) {}
|
factory(root, exports, _, $);
|
|
// Finally, as a browser global.
|
} else {
|
root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
|
}
|
|
})(function(root, Backbone, _, $) {
|
|
// Initial Setup
|
// -------------
|
|
// Save the previous value of the `Backbone` variable, so that it can be
|
// restored later on, if `noConflict` is used.
|
var previousBackbone = root.Backbone;
|
|
// Create a local reference to a common array method we'll want to use later.
|
var slice = Array.prototype.slice;
|
|
// Current version of the library. Keep in sync with `package.json`.
|
Backbone.VERSION = '1.3.3';
|
|
// For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
|
// the `$` variable.
|
Backbone.$ = $;
|
|
// Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
|
// to its previous owner. Returns a reference to this Backbone object.
|
Backbone.noConflict = function() {
|
root.Backbone = previousBackbone;
|
return this;
|
};
|
|
// Turn on `emulateHTTP` to support legacy HTTP servers. Setting this option
|
// will fake `"PATCH"`, `"PUT"` and `"DELETE"` requests via the `_method` parameter and
|
// set a `X-Http-Method-Override` header.
|
Backbone.emulateHTTP = false;
|
|
// Turn on `emulateJSON` to support legacy servers that can't deal with direct
|
// `application/json` requests ... this will encode the body as
|
// `application/x-www-form-urlencoded` instead and will send the model in a
|
// form param named `model`.
|
Backbone.emulateJSON = false;
|
|
// Proxy Backbone class methods to Underscore functions, wrapping the model's
|
// `attributes` object or collection's `models` array behind the scenes.
|
//
|
// collection.filter(function(model) { return model.get('age') > 10 });
|
// collection.each(this.addView);
|
//
|
// `Function#apply` can be slow so we use the method's arg count, if we know it.
|
var addMethod = function(length, method, attribute) {
|
switch (length) {
|
case 1: return function() {
|
return _[method](this[attribute]);
|
};
|
case 2: return function(value) {
|
return _[method](this[attribute], value);
|
};
|
case 3: return function(iteratee, context) {
|
return _[method](this[attribute], cb(iteratee, this), context);
|
};
|
case 4: return function(iteratee, defaultVal, context) {
|
return _[method](this[attribute], cb(iteratee, this), defaultVal, context);
|
};
|
default: return function() {
|
var args = slice.call(arguments);
|
args.unshift(this[attribute]);
|
return _[method].apply(_, args);
|
};
|
}
|
};
|
var addUnderscoreMethods = function(Class, methods, attribute) {
|
_.each(methods, function(length, method) {
|
if (_[method]) Class.prototype[method] = addMethod(length, method, attribute);
|
});
|
};
|
|
// Support `collection.sortBy('attr')` and `collection.findWhere({id: 1})`.
|
var cb = function(iteratee, instance) {
|
if (_.isFunction(iteratee)) return iteratee;
|
if (_.isObject(iteratee) && !instance._isModel(iteratee)) return modelMatcher(iteratee);
|
if (_.isString(iteratee)) return function(model) { return model.get(iteratee); };
|
return iteratee;
|
};
|
var modelMatcher = function(attrs) {
|
var matcher = _.matches(attrs);
|
return function(model) {
|
return matcher(model.attributes);
|
};
|
};
|
|
// Backbone.Events
|
// ---------------
|
|
// A module that can be mixed in to *any object* in order to provide it with
|
// a custom event channel. You may bind a callback to an event with `on` or
|
// remove with `off`; `trigger`-ing an event fires all callbacks in
|
// succession.
|
//
|
// var object = {};
|
// _.extend(object, Backbone.Events);
|
// object.on('expand', function(){ alert('expanded'); });
|
// object.trigger('expand');
|
//
|
var Events = Backbone.Events = {};
|
|
// Regular expression used to split event strings.
|
var eventSplitter = /\s+/;
|
|
// Iterates over the standard `event, callback` (as well as the fancy multiple
|
// space-separated events `"change blur", callback` and jQuery-style event
|
// maps `{event: callback}`).
|
var eventsApi = function(iteratee, events, name, callback, opts) {
|
var i = 0, names;
|
if (name && typeof name === 'object') {
|
// Handle event maps.
|
if (callback !== void 0 && 'context' in opts && opts.context === void 0) opts.context = callback;
|
for (names = _.keys(name); i < names.length ; i++) {
|
events = eventsApi(iteratee, events, names[i], name[names[i]], opts);
|
}
|
} else if (name && eventSplitter.test(name)) {
|
// Handle space-separated event names by delegating them individually.
|
for (names = name.split(eventSplitter); i < names.length; i++) {
|
events = iteratee(events, names[i], callback, opts);
|
}
|
} else {
|
// Finally, standard events.
|
events = iteratee(events, name, callback, opts);
|
}
|
return events;
|
};
|
|
// Bind an event to a `callback` function. Passing `"all"` will bind
|
// the callback to all events fired.
|
Events.on = function(name, callback, context) {
|
return internalOn(this, name, callback, context);
|
};
|
|
// Guard the `listening` argument from the public API.
|
var internalOn = function(obj, name, callback, context, listening) {
|
obj._events = eventsApi(onApi, obj._events || {}, name, callback, {
|
context: context,
|
ctx: obj,
|
listening: listening
|
});
|
|
if (listening) {
|
var listeners = obj._listeners || (obj._listeners = {});
|
listeners[listening.id] = listening;
|
}
|
|
return obj;
|
};
|
|
// Inversion-of-control versions of `on`. Tell *this* object to listen to
|
// an event in another object... keeping track of what it's listening to
|
// for easier unbinding later.
|
Events.listenTo = function(obj, name, callback) {
|
if (!obj) return this;
|
var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
|
var listeningTo = this._listeningTo || (this._listeningTo = {});
|
var listening = listeningTo[id];
|
|
// This object is not listening to any other events on `obj` yet.
|
// Setup the necessary references to track the listening callbacks.
|
if (!listening) {
|
var thisId = this._listenId || (this._listenId = _.uniqueId('l'));
|
listening = listeningTo[id] = {obj: obj, objId: id, id: thisId, listeningTo: listeningTo, count: 0};
|
}
|
|
// Bind callbacks on obj, and keep track of them on listening.
|
internalOn(obj, name, callback, this, listening);
|
return this;
|
};
|
|
// The reducing API that adds a callback to the `events` object.
|
var onApi = function(events, name, callback, options) {
|
if (callback) {
|
var handlers = events[name] || (events[name] = []);
|
var context = options.context, ctx = options.ctx, listening = options.listening;
|
if (listening) listening.count++;
|
|
handlers.push({callback: callback, context: context, ctx: context || ctx, listening: listening});
|
}
|
return events;
|
};
|
|
// Remove one or many callbacks. If `context` is null, removes all
|
// callbacks with that function. If `callback` is null, removes all
|
// callbacks for the event. If `name` is null, removes all bound
|
// callbacks for all events.
|
Events.off = function(name, callback, context) {
|
if (!this._events) return this;
|
this._events = eventsApi(offApi, this._events, name, callback, {
|
context: context,
|
listeners: this._listeners
|
});
|
return this;
|
};
|
|
// Tell this object to stop listening to either specific events ... or
|
// to every object it's currently listening to.
|
Events.stopListening = function(obj, name, callback) {
|
var listeningTo = this._listeningTo;
|
if (!listeningTo) return this;
|
|
var ids = obj ? [obj._listenId] : _.keys(listeningTo);
|
|
for (var i = 0; i < ids.length; i++) {
|
var listening = listeningTo[ids[i]];
|
|
// If listening doesn't exist, this object is not currently
|
// listening to obj. Break out early.
|
if (!listening) break;
|
|
listening.obj.off(name, callback, this);
|
}
|
|
return this;
|
};
|
|
// The reducing API that removes a callback from the `events` object.
|
var offApi = function(events, name, callback, options) {
|
if (!events) return;
|
|
var i = 0, listening;
|
var context = options.context, listeners = options.listeners;
|
|
// Delete all events listeners and "drop" events.
|
if (!name && !callback && !context) {
|
var ids = _.keys(listeners);
|
for (; i < ids.length; i++) {
|
listening = listeners[ids[i]];
|
delete listeners[listening.id];
|
delete listening.listeningTo[listening.objId];
|
}
|
return;
|
}
|
|
var names = name ? [name] : _.keys(events);
|
for (; i < names.length; i++) {
|
name = names[i];
|
var handlers = events[name];
|
|
// Bail out if there are no events stored.
|
if (!handlers) break;
|
|
// Replace events if there are any remaining. Otherwise, clean up.
|
var remaining = [];
|
for (var j = 0; j < handlers.length; j++) {
|
var handler = handlers[j];
|
if (
|
callback && callback !== handler.callback &&
|
callback !== handler.callback._callback ||
|
context && context !== handler.context
|
) {
|
remaining.push(handler);
|
} else {
|
listening = handler.listening;
|
if (listening && --listening.count === 0) {
|
delete listeners[listening.id];
|
delete listening.listeningTo[listening.objId];
|
}
|
}
|
}
|
|
// Update tail event if the list has any events. Otherwise, clean up.
|
if (remaining.length) {
|
events[name] = remaining;
|
} else {
|
delete events[name];
|
}
|
}
|
return events;
|
};
|
|
// Bind an event to only be triggered a single time. After the first time
|
// the callback is invoked, its listener will be removed. If multiple events
|
// are passed in using the space-separated syntax, the handler will fire
|
// once for each event, not once for a combination of all events.
|
Events.once = function(name, callback, context) {
|
// Map the event into a `{event: once}` object.
|
var events = eventsApi(onceMap, {}, name, callback, _.bind(this.off, this));
|
if (typeof name === 'string' && context == null) callback = void 0;
|
return this.on(events, callback, context);
|
};
|
|
// Inversion-of-control versions of `once`.
|
Events.listenToOnce = function(obj, name, callback) {
|
// Map the event into a `{event: once}` object.
|
var events = eventsApi(onceMap, {}, name, callback, _.bind(this.stopListening, this, obj));
|
return this.listenTo(obj, events);
|
};
|
|
// Reduces the event callbacks into a map of `{event: onceWrapper}`.
|
// `offer` unbinds the `onceWrapper` after it has been called.
|
var onceMap = function(map, name, callback, offer) {
|
if (callback) {
|
var once = map[name] = _.once(function() {
|
offer(name, once);
|
callback.apply(this, arguments);
|
});
|
once._callback = callback;
|
}
|
return map;
|
};
|
|
// Trigger one or many events, firing all bound callbacks. Callbacks are
|
// passed the same arguments as `trigger` is, apart from the event name
|
// (unless you're listening on `"all"`, which will cause your callback to
|
// receive the true name of the event as the first argument).
|
Events.trigger = function(name) {
|
if (!this._events) return this;
|
|
var length = Math.max(0, arguments.length - 1);
|
var args = Array(length);
|
for (var i = 0; i < length; i++) args[i] = arguments[i + 1];
|
|
eventsApi(triggerApi, this._events, name, void 0, args);
|
return this;
|
};
|
|
// Handles triggering the appropriate event callbacks.
|
var triggerApi = function(objEvents, name, callback, args) {
|
if (objEvents) {
|
var events = objEvents[name];
|
var allEvents = objEvents.all;
|
if (events && allEvents) allEvents = allEvents.slice();
|
if (events) triggerEvents(events, args);
|
if (allEvents) triggerEvents(allEvents, [name].concat(args));
|
}
|
return objEvents;
|
};
|
|
// A difficult-to-believe, but optimized internal dispatch function for
|
// triggering events. Tries to keep the usual cases speedy (most internal
|
// Backbone events have 3 arguments).
|
var triggerEvents = function(events, args) {
|
var ev, i = -1, l = events.length, a1 = args[0], a2 = args[1], a3 = args[2];
|
switch (args.length) {
|
case 0: while (++i < l) (ev = events[i]).callback.call(ev.ctx); return;
|
case 1: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1); return;
|
case 2: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2); return;
|
case 3: while (++i < l) (ev = events[i]).callback.call(ev.ctx, a1, a2, a3); return;
|
default: while (++i < l) (ev = events[i]).callback.apply(ev.ctx, args); return;
|
}
|
};
|
|
// Aliases for backwards compatibility.
|
Events.bind = Events.on;
|
Events.unbind = Events.off;
|
|
// Allow the `Backbone` object to serve as a global event bus, for folks who
|
// want global "pubsub" in a convenient place.
|
_.extend(Backbone, Events);
|
|
// Backbone.Model
|
// --------------
|
|
// Backbone **Models** are the basic data object in the framework --
|
// frequently representing a row in a table in a database on your server.
|
// A discrete chunk of data and a bunch of useful, related methods for
|
// performing computations and transformations on that data.
|
|
// Create a new model with the specified attributes. A client id (`cid`)
|
// is automatically generated and assigned for you.
|
var Model = Backbone.Model = function(attributes, options) {
|
var attrs = attributes || {};
|
options || (options = {});
|
this.cid = _.uniqueId(this.cidPrefix);
|
this.attributes = {};
|
if (options.collection) this.collection = options.collection;
|
if (options.parse) attrs = this.parse(attrs, options) || {};
|
var defaults = _.result(this, 'defaults');
|
attrs = _.defaults(_.extend({}, defaults, attrs), defaults);
|
this.set(attrs, options);
|
this.changed = {};
|
this.initialize.apply(this, arguments);
|
};
|
|
// Attach all inheritable methods to the Model prototype.
|
_.extend(Model.prototype, Events, {
|
|
// A hash of attributes whose current and previous value differ.
|
changed: null,
|
|
// The value returned during the last failed validation.
|
validationError: null,
|
|
// The default name for the JSON `id` attribute is `"id"`. MongoDB and
|
// CouchDB users may want to set this to `"_id"`.
|
idAttribute: 'id',
|
|
// The prefix is used to create the client id which is used to identify models locally.
|
// You may want to override this if you're experiencing name clashes with model ids.
|
cidPrefix: 'c',
|
|
// Initialize is an empty function by default. Override it with your own
|
// initialization logic.
|
initialize: function(){},
|
|
// Return a copy of the model's `attributes` object.
|
toJSON: function(options) {
|
return _.clone(this.attributes);
|
},
|
|
// Proxy `Backbone.sync` by default -- but override this if you need
|
// custom syncing semantics for *this* particular model.
|
sync: function() {
|
return Backbone.sync.apply(this, arguments);
|
},
|
|
// Get the value of an attribute.
|
get: function(attr) {
|
return this.attributes[attr];
|
},
|
|
// Get the HTML-escaped value of an attribute.
|
escape: function(attr) {
|
return _.escape(this.get(attr));
|
},
|
|
// Returns `true` if the attribute contains a value that is not null
|
// or undefined.
|
has: function(attr) {
|
return this.get(attr) != null;
|
},
|
|
// Special-cased proxy to underscore's `_.matches` method.
|
matches: function(attrs) {
|
return !!_.iteratee(attrs, this)(this.attributes);
|
},
|
|
// Set a hash of model attributes on the object, firing `"change"`. This is
|
// the core primitive operation of a model, updating the data and notifying
|
// anyone who needs to know about the change in state. The heart of the beast.
|
set: function(key, val, options) {
|
if (key == null) return this;
|
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
var attrs;
|
if (typeof key === 'object') {
|
attrs = key;
|
options = val;
|
} else {
|
(attrs = {})[key] = val;
|
}
|
|
options || (options = {});
|
|
// Run validation.
|
if (!this._validate(attrs, options)) return false;
|
|
// Extract attributes and options.
|
var unset = options.unset;
|
var silent = options.silent;
|
var changes = [];
|
var changing = this._changing;
|
this._changing = true;
|
|
if (!changing) {
|
this._previousAttributes = _.clone(this.attributes);
|
this.changed = {};
|
}
|
|
var current = this.attributes;
|
var changed = this.changed;
|
var prev = this._previousAttributes;
|
|
// For each `set` attribute, update or delete the current value.
|
for (var attr in attrs) {
|
val = attrs[attr];
|
if (!_.isEqual(current[attr], val)) changes.push(attr);
|
if (!_.isEqual(prev[attr], val)) {
|
changed[attr] = val;
|
} else {
|
delete changed[attr];
|
}
|
unset ? delete current[attr] : current[attr] = val;
|
}
|
|
// Update the `id`.
|
if (this.idAttribute in attrs) this.id = this.get(this.idAttribute);
|
|
// Trigger all relevant attribute changes.
|
if (!silent) {
|
if (changes.length) this._pending = options;
|
for (var i = 0; i < changes.length; i++) {
|
this.trigger('change:' + changes[i], this, current[changes[i]], options);
|
}
|
}
|
|
// You might be wondering why there's a `while` loop here. Changes can
|
// be recursively nested within `"change"` events.
|
if (changing) return this;
|
if (!silent) {
|
while (this._pending) {
|
options = this._pending;
|
this._pending = false;
|
this.trigger('change', this, options);
|
}
|
}
|
this._pending = false;
|
this._changing = false;
|
return this;
|
},
|
|
// Remove an attribute from the model, firing `"change"`. `unset` is a noop
|
// if the attribute doesn't exist.
|
unset: function(attr, options) {
|
return this.set(attr, void 0, _.extend({}, options, {unset: true}));
|
},
|
|
// Clear all attributes on the model, firing `"change"`.
|
clear: function(options) {
|
var attrs = {};
|
for (var key in this.attributes) attrs[key] = void 0;
|
return this.set(attrs, _.extend({}, options, {unset: true}));
|
},
|
|
// Determine if the model has changed since the last `"change"` event.
|
// If you specify an attribute name, determine if that attribute has changed.
|
hasChanged: function(attr) {
|
if (attr == null) return !_.isEmpty(this.changed);
|
return _.has(this.changed, attr);
|
},
|
|
// Return an object containing all the attributes that have changed, or
|
// false if there are no changed attributes. Useful for determining what
|
// parts of a view need to be updated and/or what attributes need to be
|
// persisted to the server. Unset attributes will be set to undefined.
|
// You can also pass an attributes object to diff against the model,
|
// determining if there *would be* a change.
|
changedAttributes: function(diff) {
|
if (!diff) return this.hasChanged() ? _.clone(this.changed) : false;
|
var old = this._changing ? this._previousAttributes : this.attributes;
|
var changed = {};
|
for (var attr in diff) {
|
var val = diff[attr];
|
if (_.isEqual(old[attr], val)) continue;
|
changed[attr] = val;
|
}
|
return _.size(changed) ? changed : false;
|
},
|
|
// Get the previous value of an attribute, recorded at the time the last
|
// `"change"` event was fired.
|
previous: function(attr) {
|
if (attr == null || !this._previousAttributes) return null;
|
return this._previousAttributes[attr];
|
},
|
|
// Get all of the attributes of the model at the time of the previous
|
// `"change"` event.
|
previousAttributes: function() {
|
return _.clone(this._previousAttributes);
|
},
|
|
// Fetch the model from the server, merging the response with the model's
|
// local attributes. Any changed attributes will trigger a "change" event.
|
fetch: function(options) {
|
options = _.extend({parse: true}, options);
|
var model = this;
|
var success = options.success;
|
options.success = function(resp) {
|
var serverAttrs = options.parse ? model.parse(resp, options) : resp;
|
if (!model.set(serverAttrs, options)) return false;
|
if (success) success.call(options.context, model, resp, options);
|
model.trigger('sync', model, resp, options);
|
};
|
wrapError(this, options);
|
return this.sync('read', this, options);
|
},
|
|
// Set a hash of model attributes, and sync the model to the server.
|
// If the server returns an attributes hash that differs, the model's
|
// state will be `set` again.
|
save: function(key, val, options) {
|
// Handle both `"key", value` and `{key: value}` -style arguments.
|
var attrs;
|
if (key == null || typeof key === 'object') {
|
attrs = key;
|
options = val;
|
} else {
|
(attrs = {})[key] = val;
|
}
|
|
options = _.extend({validate: true, parse: true}, options);
|
var wait = options.wait;
|
|
// If we're not waiting and attributes exist, save acts as
|
// `set(attr).save(null, opts)` with validation. Otherwise, check if
|
// the model will be valid when the attributes, if any, are set.
|
if (attrs && !wait) {
|
if (!this.set(attrs, options)) return false;
|
} else if (!this._validate(attrs, options)) {
|
return false;
|
}
|
|
// After a successful server-side save, the client is (optionally)
|
// updated with the server-side state.
|
var model = this;
|
var success = options.success;
|
var attributes = this.attributes;
|
options.success = function(resp) {
|
// Ensure attributes are restored during synchronous saves.
|
model.attributes = attributes;
|
var serverAttrs = options.parse ? model.parse(resp, options) : resp;
|
if (wait) serverAttrs = _.extend({}, attrs, serverAttrs);
|
if (serverAttrs && !model.set(serverAttrs, options)) return false;
|
if (success) success.call(options.context, model, resp, options);
|
model.trigger('sync', model, resp, options);
|
};
|
wrapError(this, options);
|
|
// Set temporary attributes if `{wait: true}` to properly find new ids.
|
if (attrs && wait) this.attributes = _.extend({}, attributes, attrs);
|
|
var method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
|
if (method === 'patch' && !options.attrs) options.attrs = attrs;
|
var xhr = this.sync(method, this, options);
|
|
// Restore attributes.
|
this.attributes = attributes;
|
|
return xhr;
|
},
|
|
// Destroy this model on the server if it was already persisted.
|
// Optimistically removes the model from its collection, if it has one.
|
// If `wait: true` is passed, waits for the server to respond before removal.
|
destroy: function(options) {
|
options = options ? _.clone(options) : {};
|
var model = this;
|
var success = options.success;
|
var wait = options.wait;
|
|
var destroy = function() {
|
model.stopListening();
|
model.trigger('destroy', model, model.collection, options);
|
};
|
|
options.success = function(resp) {
|
if (wait) destroy();
|
if (success) success.call(options.context, model, resp, options);
|
if (!model.isNew()) model.trigger('sync', model, resp, options);
|
};
|
|
var xhr = false;
|
if (this.isNew()) {
|
_.defer(options.success);
|
} else {
|
wrapError(this, options);
|
xhr = this.sync('delete', this, options);
|
}
|
if (!wait) destroy();
|
return xhr;
|
},
|
|
// Default URL for the model's representation on the server -- if you're
|
// using Backbone's restful methods, override this to change the endpoint
|
// that will be called.
|
url: function() {
|
var base =
|
_.result(this, 'urlRoot') ||
|
_.result(this.collection, 'url') ||
|
urlError();
|
if (this.isNew()) return base;
|
var id = this.get(this.idAttribute);
|
return base.replace(/[^\/]$/, '$&/') + encodeURIComponent(id);
|
},
|
|
// **parse** converts a response into the hash of attributes to be `set` on
|
// the model. The default implementation is just to pass the response along.
|
parse: function(resp, options) {
|
return resp;
|
},
|
|
// Create a new model with identical attributes to this one.
|
clone: function() {
|
return new this.constructor(this.attributes);
|
},
|
|
// A model is new if it has never been saved to the server, and lacks an id.
|
isNew: function() {
|
return !this.has(this.idAttribute);
|
},
|
|
// Check if the model is currently in a valid state.
|
isValid: function(options) {
|
return this._validate({}, _.extend({}, options, {validate: true}));
|
},
|
|
// Run validation against the next complete set of model attributes,
|
// returning `true` if all is well. Otherwise, fire an `"invalid"` event.
|
_validate: function(attrs, options) {
|
if (!options.validate || !this.validate) return true;
|
attrs = _.extend({}, this.attributes, attrs);
|
var error = this.validationError = this.validate(attrs, options) || null;
|
if (!error) return true;
|
this.trigger('invalid', this, error, _.extend(options, {validationError: error}));
|
return false;
|
}
|
|
});
|
|
// Underscore methods that we want to implement on the Model, mapped to the
|
// number of arguments they take.
|
var modelMethods = {keys: 1, values: 1, pairs: 1, invert: 1, pick: 0,
|
omit: 0, chain: 1, isEmpty: 1};
|
|
// Mix in each Underscore method as a proxy to `Model#attributes`.
|
addUnderscoreMethods(Model, modelMethods, 'attributes');
|
|
// Backbone.Collection
|
// -------------------
|
|
// If models tend to represent a single row of data, a Backbone Collection is
|
// more analogous to a table full of data ... or a small slice or page of that
|
// table, or a collection of rows that belong together for a particular reason
|
// -- all of the messages in this particular folder, all of the documents
|
// belonging to this particular author, and so on. Collections maintain
|
// indexes of their models, both in order, and for lookup by `id`.
|
|
// Create a new **Collection**, perhaps to contain a specific type of `model`.
|
// If a `comparator` is specified, the Collection will maintain
|
// its models in sort order, as they're added and removed.
|
var Collection = Backbone.Collection = function(models, options) {
|
options || (options = {});
|
if (options.model) this.model = options.model;
|
if (options.comparator !== void 0) this.comparator = options.comparator;
|
this._reset();
|
this.initialize.apply(this, arguments);
|
if (models) this.reset(models, _.extend({silent: true}, options));
|
};
|
|
// Default options for `Collection#set`.
|
var setOptions = {add: true, remove: true, merge: true};
|
var addOptions = {add: true, remove: false};
|
|
// Splices `insert` into `array` at index `at`.
|
var splice = function(array, insert, at) {
|
at = Math.min(Math.max(at, 0), array.length);
|
var tail = Array(array.length - at);
|
var length = insert.length;
|
var i;
|
for (i = 0; i < tail.length; i++) tail[i] = array[i + at];
|
for (i = 0; i < length; i++) array[i + at] = insert[i];
|
for (i = 0; i < tail.length; i++) array[i + length + at] = tail[i];
|
};
|
|
// Define the Collection's inheritable methods.
|
_.extend(Collection.prototype, Events, {
|
|
// The default model for a collection is just a **Backbone.Model**.
|
// This should be overridden in most cases.
|
model: Model,
|
|
// Initialize is an empty function by default. Override it with your own
|
// initialization logic.
|
initialize: function(){},
|
|
// The JSON representation of a Collection is an array of the
|
// models' attributes.
|
toJSON: function(options) {
|
return this.map(function(model) { return model.toJSON(options); });
|
},
|
|
// Proxy `Backbone.sync` by default.
|
sync: function() {
|
return Backbone.sync.apply(this, arguments);
|
},
|
|
// Add a model, or list of models to the set. `models` may be Backbone
|
// Models or raw JavaScript objects to be converted to Models, or any
|
// combination of the two.
|
add: function(models, options) {
|
return this.set(models, _.extend({merge: false}, options, addOptions));
|
},
|
|
// Remove a model, or a list of models from the set.
|
remove: function(models, options) {
|
options = _.extend({}, options);
|
var singular = !_.isArray(models);
|
models = singular ? [models] : models.slice();
|
var removed = this._removeModels(models, options);
|
if (!options.silent && removed.length) {
|
options.changes = {added: [], merged: [], removed: removed};
|
this.trigger('update', this, options);
|
}
|
return singular ? removed[0] : removed;
|
},
|
|
// Update a collection by `set`-ing a new list of models, adding new ones,
|
// removing models that are no longer present, and merging models that
|
// already exist in the collection, as necessary. Similar to **Model#set**,
|
// the core operation for updating the data contained by the collection.
|
set: function(models, options) {
|
if (models == null) return;
|
|
options = _.extend({}, setOptions, options);
|
if (options.parse && !this._isModel(models)) {
|
models = this.parse(models, options) || [];
|
}
|
|
var singular = !_.isArray(models);
|
models = singular ? [models] : models.slice();
|
|
var at = options.at;
|
if (at != null) at = +at;
|
if (at > this.length) at = this.length;
|
if (at < 0) at += this.length + 1;
|
|
var set = [];
|
var toAdd = [];
|
var toMerge = [];
|
var toRemove = [];
|
var modelMap = {};
|
|
var add = options.add;
|
var merge = options.merge;
|
var remove = options.remove;
|
|
var sort = false;
|
var sortable = this.comparator && at == null && options.sort !== false;
|
var sortAttr = _.isString(this.comparator) ? this.comparator : null;
|
|
// Turn bare objects into model references, and prevent invalid models
|
// from being added.
|
var model, i;
|
for (i = 0; i < models.length; i++) {
|
model = models[i];
|
|
// If a duplicate is found, prevent it from being added and
|
// optionally merge it into the existing model.
|
var existing = this.get(model);
|
if (existing) {
|
if (merge && model !== existing) {
|
var attrs = this._isModel(model) ? model.attributes : model;
|
if (options.parse) attrs = existing.parse(attrs, options);
|
existing.set(attrs, options);
|
toMerge.push(existing);
|
if (sortable && !sort) sort = existing.hasChanged(sortAttr);
|
}
|
if (!modelMap[existing.cid]) {
|
modelMap[existing.cid] = true;
|
set.push(existing);
|
}
|
models[i] = existing;
|
|
// If this is a new, valid model, push it to the `toAdd` list.
|
} else if (add) {
|
model = models[i] = this._prepareModel(model, options);
|
if (model) {
|
toAdd.push(model);
|
this._addReference(model, options);
|
modelMap[model.cid] = true;
|
set.push(model);
|
}
|
}
|
}
|
|
// Remove stale models.
|
if (remove) {
|
for (i = 0; i < this.length; i++) {
|
model = this.models[i];
|
if (!modelMap[model.cid]) toRemove.push(model);
|
}
|
if (toRemove.length) this._removeModels(toRemove, options);
|
}
|
|
// See if sorting is needed, update `length` and splice in new models.
|
var orderChanged = false;
|
var replace = !sortable && add && remove;
|
if (set.length && replace) {
|
orderChanged = this.length !== set.length || _.some(this.models, function(m, index) {
|
return m !== set[index];
|
});
|
this.models.length = 0;
|
splice(this.models, set, 0);
|
this.length = this.models.length;
|
} else if (toAdd.length) {
|
if (sortable) sort = true;
|
splice(this.models, toAdd, at == null ? this.length : at);
|
this.length = this.models.length;
|
}
|
|
// Silently sort the collection if appropriate.
|
if (sort) this.sort({silent: true});
|
|
// Unless silenced, it's time to fire all appropriate add/sort/update events.
|
if (!options.silent) {
|
for (i = 0; i < toAdd.length; i++) {
|
if (at != null) options.index = at + i;
|
model = toAdd[i];
|
model.trigger('add', model, this, options);
|
}
|
if (sort || orderChanged) this.trigger('sort', this, options);
|
if (toAdd.length || toRemove.length || toMerge.length) {
|
options.changes = {
|
added: toAdd,
|
removed: toRemove,
|
merged: toMerge
|
};
|
this.trigger('update', this, options);
|
}
|
}
|
|
// Return the added (or merged) model (or models).
|
return singular ? models[0] : models;
|
},
|
|
// When you have more items than you want to add or remove individually,
|
// you can reset the entire set with a new list of models, without firing
|
// any granular `add` or `remove` events. Fires `reset` when finished.
|
// Useful for bulk operations and optimizations.
|
reset: function(models, options) {
|
options = options ? _.clone(options) : {};
|
for (var i = 0; i < this.models.length; i++) {
|
this._removeReference(this.models[i], options);
|
}
|
options.previousModels = this.models;
|
this._reset();
|
models = this.add(models, _.extend({silent: true}, options));
|
if (!options.silent) this.trigger('reset', this, options);
|
return models;
|
},
|
|
// Add a model to the end of the collection.
|
push: function(model, options) {
|
return this.add(model, _.extend({at: this.length}, options));
|
},
|
|
// Remove a model from the end of the collection.
|
pop: function(options) {
|
var model = this.at(this.length - 1);
|
return this.remove(model, options);
|
},
|
|
// Add a model to the beginning of the collection.
|
unshift: function(model, options) {
|
return this.add(model, _.extend({at: 0}, options));
|
},
|
|
// Remove a model from the beginning of the collection.
|
shift: function(options) {
|
var model = this.at(0);
|
return this.remove(model, options);
|
},
|
|
// Slice out a sub-array of models from the collection.
|
slice: function() {
|
return slice.apply(this.models, arguments);
|
},
|
|
// Get a model from the set by id, cid, model object with id or cid
|
// properties, or an attributes object that is transformed through modelId.
|
get: function(obj) {
|
if (obj == null) return void 0;
|
return this._byId[obj] ||
|
this._byId[this.modelId(obj.attributes || obj)] ||
|
obj.cid && this._byId[obj.cid];
|
},
|
|
// Returns `true` if the model is in the collection.
|
has: function(obj) {
|
return this.get(obj) != null;
|
},
|
|
// Get the model at the given index.
|
at: function(index) {
|
if (index < 0) index += this.length;
|
return this.models[index];
|
},
|
|
// Return models with matching attributes. Useful for simple cases of
|
// `filter`.
|
where: function(attrs, first) {
|
return this[first ? 'find' : 'filter'](attrs);
|
},
|
|
// Return the first model with matching attributes. Useful for simple cases
|
// of `find`.
|
findWhere: function(attrs) {
|
return this.where(attrs, true);
|
},
|
|
// Force the collection to re-sort itself. You don't need to call this under
|
// normal circumstances, as the set will maintain sort order as each item
|
// is added.
|
sort: function(options) {
|
var comparator = this.comparator;
|
if (!comparator) throw new Error('Cannot sort a set without a comparator');
|
options || (options = {});
|
|
var length = comparator.length;
|
if (_.isFunction(comparator)) comparator = _.bind(comparator, this);
|
|
// Run sort based on type of `comparator`.
|
if (length === 1 || _.isString(comparator)) {
|
this.models = this.sortBy(comparator);
|
} else {
|
this.models.sort(comparator);
|
}
|
if (!options.silent) this.trigger('sort', this, options);
|
return this;
|
},
|
|
// Pluck an attribute from each model in the collection.
|
pluck: function(attr) {
|
return this.map(attr + '');
|
},
|
|
// Fetch the default set of models for this collection, resetting the
|
// collection when they arrive. If `reset: true` is passed, the response
|
// data will be passed through the `reset` method instead of `set`.
|
fetch: function(options) {
|
options = _.extend({parse: true}, options);
|
var success = options.success;
|
var collection = this;
|
options.success = function(resp) {
|
var method = options.reset ? 'reset' : 'set';
|
collection[method](resp, options);
|
if (success) success.call(options.context, collection, resp, options);
|
collection.trigger('sync', collection, resp, options);
|
};
|
wrapError(this, options);
|
return this.sync('read', this, options);
|
},
|
|
// Create a new instance of a model in this collection. Add the model to the
|
// collection immediately, unless `wait: true` is passed, in which case we
|
// wait for the server to agree.
|
create: function(model, options) {
|
options = options ? _.clone(options) : {};
|
var wait = options.wait;
|
model = this._prepareModel(model, options);
|
if (!model) return false;
|
if (!wait) this.add(model, options);
|
var collection = this;
|
var success = options.success;
|
options.success = function(m, resp, callbackOpts) {
|
if (wait) collection.add(m, callbackOpts);
|
if (success) success.call(callbackOpts.context, m, resp, callbackOpts);
|
};
|
model.save(null, options);
|
return model;
|
},
|
|
// **parse** converts a response into a list of models to be added to the
|
// collection. The default implementation is just to pass it through.
|
parse: function(resp, options) {
|
return resp;
|
},
|
|
// Create a new collection with an identical list of models as this one.
|
clone: function() {
|
return new this.constructor(this.models, {
|
model: this.model,
|
comparator: this.comparator
|
});
|
},
|
|
// Define how to uniquely identify models in the collection.
|
modelId: function(attrs) {
|
return attrs[this.model.prototype.idAttribute || 'id'];
|
},
|
|
// Private method to reset all internal state. Called when the collection
|
// is first initialized or reset.
|
_reset: function() {
|
this.length = 0;
|
this.models = [];
|
this._byId = {};
|
},
|
|
// Prepare a hash of attributes (or other model) to be added to this
|
// collection.
|
_prepareModel: function(attrs, options) {
|
if (this._isModel(attrs)) {
|
if (!attrs.collection) attrs.collection = this;
|
return attrs;
|
}
|
options = options ? _.clone(options) : {};
|
options.collection = this;
|
var model = new this.model(attrs, options);
|
if (!model.validationError) return model;
|
this.trigger('invalid', this, model.validationError, options);
|
return false;
|
},
|
|
// Internal method called by both remove and set.
|
_removeModels: function(models, options) {
|
var removed = [];
|
for (var i = 0; i < models.length; i++) {
|
var model = this.get(models[i]);
|
if (!model) continue;
|
|
var index = this.indexOf(model);
|
this.models.splice(index, 1);
|
this.length--;
|
|
// Remove references before triggering 'remove' event to prevent an
|
// infinite loop. #3693
|
delete this._byId[model.cid];
|
var id = this.modelId(model.attributes);
|
if (id != null) delete this._byId[id];
|
|
if (!options.silent) {
|
options.index = index;
|
model.trigger('remove', model, this, options);
|
}
|
|
removed.push(model);
|
this._removeReference(model, options);
|
}
|
return removed;
|
},
|
|
// Method for checking whether an object should be considered a model for
|
// the purposes of adding to the collection.
|
_isModel: function(model) {
|
return model instanceof Model;
|
},
|
|
// Internal method to create a model's ties to a collection.
|
_addReference: function(model, options) {
|
this._byId[model.cid] = model;
|
var id = this.modelId(model.attributes);
|
if (id != null) this._byId[id] = model;
|
model.on('all', this._onModelEvent, this);
|
},
|
|
// Internal method to sever a model's ties to a collection.
|
_removeReference: function(model, options) {
|
delete this._byId[model.cid];
|
var id = this.modelId(model.attributes);
|
if (id != null) delete this._byId[id];
|
if (this === model.collection) delete model.collection;
|
model.off('all', this._onModelEvent, this);
|
},
|
|
// Internal method called every time a model in the set fires an event.
|
// Sets need to update their indexes when models change ids. All other
|
// events simply proxy through. "add" and "remove" events that originate
|
// in other collections are ignored.
|
_onModelEvent: function(event, model, collection, options) {
|
if (model) {
|
if ((event === 'add' || event === 'remove') && collection !== this) return;
|
if (event === 'destroy') this.remove(model, options);
|
if (event === 'change') {
|
var prevId = this.modelId(model.previousAttributes());
|
var id = this.modelId(model.attributes);
|
if (prevId !== id) {
|
if (prevId != null) delete this._byId[prevId];
|
if (id != null) this._byId[id] = model;
|
}
|
}
|
}
|
this.trigger.apply(this, arguments);
|
}
|
|
});
|
|
// Underscore methods that we want to implement on the Collection.
|
// 90% of the core usefulness of Backbone Collections is actually implemented
|
// right here:
|
var collectionMethods = {forEach: 3, each: 3, map: 3, collect: 3, reduce: 0,
|
foldl: 0, inject: 0, reduceRight: 0, foldr: 0, find: 3, detect: 3, filter: 3,
|
select: 3, reject: 3, every: 3, all: 3, some: 3, any: 3, include: 3, includes: 3,
|
contains: 3, invoke: 0, max: 3, min: 3, toArray: 1, size: 1, first: 3,
|
head: 3, take: 3, initial: 3, rest: 3, tail: 3, drop: 3, last: 3,
|
without: 0, difference: 0, indexOf: 3, shuffle: 1, lastIndexOf: 3,
|
isEmpty: 1, chain: 1, sample: 3, partition: 3, groupBy: 3, countBy: 3,
|
sortBy: 3, indexBy: 3, findIndex: 3, findLastIndex: 3};
|
|
// Mix in each Underscore method as a proxy to `Collection#models`.
|
addUnderscoreMethods(Collection, collectionMethods, 'models');
|
|
// Backbone.View
|
// -------------
|
|
// Backbone Views are almost more convention than they are actual code. A View
|
// is simply a JavaScript object that represents a logical chunk of UI in the
|
// DOM. This might be a single item, an entire list, a sidebar or panel, or
|
// even the surrounding frame which wraps your whole app. Defining a chunk of
|
// UI as a **View** allows you to define your DOM events declaratively, without
|
// having to worry about render order ... and makes it easy for the view to
|
// react to specific changes in the state of your models.
|
|
// Creating a Backbone.View creates its initial element outside of the DOM,
|
// if an existing element is not provided...
|
var View = Backbone.View = function(options) {
|
this.cid = _.uniqueId('view');
|
_.extend(this, _.pick(options, viewOptions));
|
this._ensureElement();
|
this.initialize.apply(this, arguments);
|
};
|
|
// Cached regex to split keys for `delegate`.
|
var delegateEventSplitter = /^(\S+)\s*(.*)$/;
|
|
// List of view options to be set as properties.
|
var viewOptions = ['model', 'collection', 'el', 'id', 'attributes', 'className', 'tagName', 'events'];
|
|
// Set up all inheritable **Backbone.View** properties and methods.
|
_.extend(View.prototype, Events, {
|
|
// The default `tagName` of a View's element is `"div"`.
|
tagName: 'div',
|
|
// jQuery delegate for element lookup, scoped to DOM elements within the
|
// current view. This should be preferred to global lookups where possible.
|
$: function(selector) {
|
return this.$el.find(selector);
|
},
|
|
// Initialize is an empty function by default. Override it with your own
|
// initialization logic.
|
initialize: function(){},
|
|
// **render** is the core function that your view should override, in order
|
// to populate its element (`this.el`), with the appropriate HTML. The
|
// convention is for **render** to always return `this`.
|
render: function() {
|
return this;
|
},
|
|
// Remove this view by taking the element out of the DOM, and removing any
|
// applicable Backbone.Events listeners.
|
remove: function() {
|
this._removeElement();
|
this.stopListening();
|
return this;
|
},
|
|
// Remove this view's element from the document and all event listeners
|
// attached to it. Exposed for subclasses using an alternative DOM
|
// manipulation API.
|
_removeElement: function() {
|
this.$el.remove();
|
},
|
|
// Change the view's element (`this.el` property) and re-delegate the
|
// view's events on the new element.
|
setElement: function(element) {
|
this.undelegateEvents();
|
this._setElement(element);
|
this.delegateEvents();
|
return this;
|
},
|
|
// Creates the `this.el` and `this.$el` references for this view using the
|
// given `el`. `el` can be a CSS selector or an HTML string, a jQuery
|
// context or an element. Subclasses can override this to utilize an
|
// alternative DOM manipulation API and are only required to set the
|
// `this.el` property.
|
_setElement: function(el) {
|
this.$el = el instanceof Backbone.$ ? el : Backbone.$(el);
|
this.el = this.$el[0];
|
},
|
|
// Set callbacks, where `this.events` is a hash of
|
//
|
// *{"event selector": "callback"}*
|
//
|
// {
|
// 'mousedown .title': 'edit',
|
// 'click .button': 'save',
|
// 'click .open': function(e) { ... }
|
// }
|
//
|
// pairs. Callbacks will be bound to the view, with `this` set properly.
|
// Uses event delegation for efficiency.
|
// Omitting the selector binds the event to `this.el`.
|
delegateEvents: function(events) {
|
events || (events = _.result(this, 'events'));
|
if (!events) return this;
|
this.undelegateEvents();
|
for (var key in events) {
|
var method = events[key];
|
if (!_.isFunction(method)) method = this[method];
|
if (!method) continue;
|
var match = key.match(delegateEventSplitter);
|
this.delegate(match[1], match[2], _.bind(method, this));
|
}
|
return this;
|
},
|
|
// Add a single event listener to the view's element (or a child element
|
// using `selector`). This only works for delegate-able events: not `focus`,
|
// `blur`, and not `change`, `submit`, and `reset` in Internet Explorer.
|
delegate: function(eventName, selector, listener) {
|
this.$el.on(eventName + '.delegateEvents' + this.cid, selector, listener);
|
return this;
|
},
|
|
// Clears all callbacks previously bound to the view by `delegateEvents`.
|
// You usually don't need to use this, but may wish to if you have multiple
|
// Backbone views attached to the same DOM element.
|
undelegateEvents: function() {
|
if (this.$el) this.$el.off('.delegateEvents' + this.cid);
|
return this;
|
},
|
|
// A finer-grained `undelegateEvents` for removing a single delegated event.
|
// `selector` and `listener` are both optional.
|
undelegate: function(eventName, selector, listener) {
|
this.$el.off(eventName + '.delegateEvents' + this.cid, selector, listener);
|
return this;
|
},
|
|
// Produces a DOM element to be assigned to your view. Exposed for
|
// subclasses using an alternative DOM manipulation API.
|
_createElement: function(tagName) {
|
return document.createElement(tagName);
|
},
|
|
// Ensure that the View has a DOM element to render into.
|
// If `this.el` is a string, pass it through `$()`, take the first
|
// matching element, and re-assign it to `el`. Otherwise, create
|
// an element from the `id`, `className` and `tagName` properties.
|
_ensureElement: function() {
|
if (!this.el) {
|
var attrs = _.extend({}, _.result(this, 'attributes'));
|
if (this.id) attrs.id = _.result(this, 'id');
|
if (this.className) attrs['class'] = _.result(this, 'className');
|
this.setElement(this._createElement(_.result(this, 'tagName')));
|
this._setAttributes(attrs);
|
} else {
|
this.setElement(_.result(this, 'el'));
|
}
|
},
|
|
// Set attributes from a hash on this view's element. Exposed for
|
// subclasses using an alternative DOM manipulation API.
|
_setAttributes: function(attributes) {
|
this.$el.attr(attributes);
|
}
|
|
});
|
|
// Backbone.sync
|
// -------------
|
|
// Override this function to change the manner in which Backbone persists
|
// models to the server. You will be passed the type of request, and the
|
// model in question. By default, makes a RESTful Ajax request
|
// to the model's `url()`. Some possible customizations could be:
|
//
|
// * Use `setTimeout` to batch rapid-fire updates into a single request.
|
// * Send up the models as XML instead of JSON.
|
// * Persist models via WebSockets instead of Ajax.
|
//
|
// Turn on `Backbone.emulateHTTP` in order to send `PUT` and `DELETE` requests
|
// as `POST`, with a `_method` parameter containing the true HTTP method,
|
// as well as all requests with the body as `application/x-www-form-urlencoded`
|
// instead of `application/json` with the model in a param named `model`.
|
// Useful when interfacing with server-side languages like **PHP** that make
|
// it difficult to read the body of `PUT` requests.
|
Backbone.sync = function(method, model, options) {
|
var type = methodMap[method];
|
|
// Default options, unless specified.
|
_.defaults(options || (options = {}), {
|
emulateHTTP: Backbone.emulateHTTP,
|
emulateJSON: Backbone.emulateJSON
|
});
|
|
// Default JSON-request options.
|
var params = {type: type, dataType: 'json'};
|
|
// Ensure that we have a URL.
|
if (!options.url) {
|
params.url = _.result(model, 'url') || urlError();
|
}
|
|
// Ensure that we have the appropriate request data.
|
if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
|
params.contentType = 'application/json';
|
params.data = JSON.stringify(options.attrs || model.toJSON(options));
|
}
|
|
// For older servers, emulate JSON by encoding the request into an HTML-form.
|
if (options.emulateJSON) {
|
params.contentType = 'application/x-www-form-urlencoded';
|
params.data = params.data ? {model: params.data} : {};
|
}
|
|
// For older servers, emulate HTTP by mimicking the HTTP method with `_method`
|
// And an `X-HTTP-Method-Override` header.
|
if (options.emulateHTTP && (type === 'PUT' || type === 'DELETE' || type === 'PATCH')) {
|
params.type = 'POST';
|
if (options.emulateJSON) params.data._method = type;
|
var beforeSend = options.beforeSend;
|
options.beforeSend = function(xhr) {
|
xhr.setRequestHeader('X-HTTP-Method-Override', type);
|
if (beforeSend) return beforeSend.apply(this, arguments);
|
};
|
}
|
|
// Don't process data on a non-GET request.
|
if (params.type !== 'GET' && !options.emulateJSON) {
|
params.processData = false;
|
}
|
|
// Pass along `textStatus` and `errorThrown` from jQuery.
|
var error = options.error;
|
options.error = function(xhr, textStatus, errorThrown) {
|
options.textStatus = textStatus;
|
options.errorThrown = errorThrown;
|
if (error) error.call(options.context, xhr, textStatus, errorThrown);
|
};
|
|
// Make the request, allowing the user to override any Ajax options.
|
var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
|
model.trigger('request', model, xhr, options);
|
return xhr;
|
};
|
|
// Map from CRUD to HTTP for our default `Backbone.sync` implementation.
|
var methodMap = {
|
'create': 'POST',
|
'update': 'PUT',
|
'patch': 'PATCH',
|
'delete': 'DELETE',
|
'read': 'GET'
|
};
|
|
// Set the default implementation of `Backbone.ajax` to proxy through to `$`.
|
// Override this if you'd like to use a different library.
|
Backbone.ajax = function() {
|
return Backbone.$.ajax.apply(Backbone.$, arguments);
|
};
|
|
// Backbone.Router
|
// ---------------
|
|
// Routers map faux-URLs to actions, and fire events when routes are
|
// matched. Creating a new one sets its `routes` hash, if not set statically.
|
var Router = Backbone.Router = function(options) {
|
options || (options = {});
|
if (options.routes) this.routes = options.routes;
|
this._bindRoutes();
|
this.initialize.apply(this, arguments);
|
};
|
|
// Cached regular expressions for matching named param parts and splatted
|
// parts of route strings.
|
var optionalParam = /\((.*?)\)/g;
|
var namedParam = /(\(\?)?:\w+/g;
|
var splatParam = /\*\w+/g;
|
var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g;
|
|
// Set up all inheritable **Backbone.Router** properties and methods.
|
_.extend(Router.prototype, Events, {
|
|
// Initialize is an empty function by default. Override it with your own
|
// initialization logic.
|
initialize: function(){},
|
|
// Manually bind a single named route to a callback. For example:
|
//
|
// this.route('search/:query/p:num', 'search', function(query, num) {
|
// ...
|
// });
|
//
|
route: function(route, name, callback) {
|
if (!_.isRegExp(route)) route = this._routeToRegExp(route);
|
if (_.isFunction(name)) {
|
callback = name;
|
name = '';
|
}
|
if (!callback) callback = this[name];
|
var router = this;
|
Backbone.history.route(route, function(fragment) {
|
var args = router._extractParameters(route, fragment);
|
if (router.execute(callback, args, name) !== false) {
|
router.trigger.apply(router, ['route:' + name].concat(args));
|
router.trigger('route', name, args);
|
Backbone.history.trigger('route', router, name, args);
|
}
|
});
|
return this;
|
},
|
|
// Execute a route handler with the provided parameters. This is an
|
// excellent place to do pre-route setup or post-route cleanup.
|
execute: function(callback, args, name) {
|
if (callback) callback.apply(this, args);
|
},
|
|
// Simple proxy to `Backbone.history` to save a fragment into the history.
|
navigate: function(fragment, options) {
|
Backbone.history.navigate(fragment, options);
|
return this;
|
},
|
|
// Bind all defined routes to `Backbone.history`. We have to reverse the
|
// order of the routes here to support behavior where the most general
|
// routes can be defined at the bottom of the route map.
|
_bindRoutes: function() {
|
if (!this.routes) return;
|
this.routes = _.result(this, 'routes');
|
var route, routes = _.keys(this.routes);
|
while ((route = routes.pop()) != null) {
|
this.route(route, this.routes[route]);
|
}
|
},
|
|
// Convert a route string into a regular expression, suitable for matching
|
// against the current location hash.
|
_routeToRegExp: function(route) {
|
route = route.replace(escapeRegExp, '\\$&')
|
.replace(optionalParam, '(?:$1)?')
|
.replace(namedParam, function(match, optional) {
|
return optional ? match : '([^/?]+)';
|
})
|
.replace(splatParam, '([^?]*?)');
|
return new RegExp('^' + route + '(?:\\?([\\s\\S]*))?$');
|
},
|
|
// Given a route, and a URL fragment that it matches, return the array of
|
// extracted decoded parameters. Empty or unmatched parameters will be
|
// treated as `null` to normalize cross-browser behavior.
|
_extractParameters: function(route, fragment) {
|
var params = route.exec(fragment).slice(1);
|
return _.map(params, function(param, i) {
|
// Don't decode the search params.
|
if (i === params.length - 1) return param || null;
|
return param ? decodeURIComponent(param) : null;
|
});
|
}
|
|
});
|
|
// Backbone.History
|
// ----------------
|
|
// Handles cross-browser history management, based on either
|
// [pushState](http://diveintohtml5.info/history.html) and real URLs, or
|
// [onhashchange](https://developer.mozilla.org/en-US/docs/DOM/window.onhashchange)
|
// and URL fragments. If the browser supports neither (old IE, natch),
|
// falls back to polling.
|
var History = Backbone.History = function() {
|
this.handlers = [];
|
this.checkUrl = _.bind(this.checkUrl, this);
|
|
// Ensure that `History` can be used outside of the browser.
|
if (typeof window !== 'undefined') {
|
this.location = window.location;
|
this.history = window.history;
|
}
|
};
|
|
// Cached regex for stripping a leading hash/slash and trailing space.
|
var routeStripper = /^[#\/]|\s+$/g;
|
|
// Cached regex for stripping leading and trailing slashes.
|
var rootStripper = /^\/+|\/+$/g;
|
|
// Cached regex for stripping urls of hash.
|
var pathStripper = /#.*$/;
|
|
// Has the history handling already been started?
|
History.started = false;
|
|
// Set up all inheritable **Backbone.History** properties and methods.
|
_.extend(History.prototype, Events, {
|
|
// The default interval to poll for hash changes, if necessary, is
|
// twenty times a second.
|
interval: 50,
|
|
// Are we at the app root?
|
atRoot: function() {
|
var path = this.location.pathname.replace(/[^\/]$/, '$&/');
|
return path === this.root && !this.getSearch();
|
},
|
|
// Does the pathname match the root?
|
matchRoot: function() {
|
var path = this.decodeFragment(this.location.pathname);
|
var rootPath = path.slice(0, this.root.length - 1) + '/';
|
return rootPath === this.root;
|
},
|
|
// Unicode characters in `location.pathname` are percent encoded so they're
|
// decoded for comparison. `%25` should not be decoded since it may be part
|
// of an encoded parameter.
|
decodeFragment: function(fragment) {
|
return decodeURI(fragment.replace(/%25/g, '%2525'));
|
},
|
|
// In IE6, the hash fragment and search params are incorrect if the
|
// fragment contains `?`.
|
getSearch: function() {
|
var match = this.location.href.replace(/#.*/, '').match(/\?.+/);
|
return match ? match[0] : '';
|
},
|
|
// Gets the true hash value. Cannot use location.hash directly due to bug
|
// in Firefox where location.hash will always be decoded.
|
getHash: function(window) {
|
var match = (window || this).location.href.match(/#(.*)$/);
|
return match ? match[1] : '';
|
},
|
|
// Get the pathname and search params, without the root.
|
getPath: function() {
|
var path = this.decodeFragment(
|
this.location.pathname + this.getSearch()
|
).slice(this.root.length - 1);
|
return path.charAt(0) === '/' ? path.slice(1) : path;
|
},
|
|
// Get the cross-browser normalized URL fragment from the path or hash.
|
getFragment: function(fragment) {
|
if (fragment == null) {
|
if (this._usePushState || !this._wantsHashChange) {
|
fragment = this.getPath();
|
} else {
|
fragment = this.getHash();
|
}
|
}
|
return fragment.replace(routeStripper, '');
|
},
|
|
// Start the hash change handling, returning `true` if the current URL matches
|
// an existing route, and `false` otherwise.
|
start: function(options) {
|
if (History.started) throw new Error('Backbone.history has already been started');
|
History.started = true;
|
|
// Figure out the initial configuration. Do we need an iframe?
|
// Is pushState desired ... is it available?
|
this.options = _.extend({root: '/'}, this.options, options);
|
this.root = this.options.root;
|
this._wantsHashChange = this.options.hashChange !== false;
|
this._hasHashChange = 'onhashchange' in window && (document.documentMode === void 0 || document.documentMode > 7);
|
this._useHashChange = this._wantsHashChange && this._hasHashChange;
|
this._wantsPushState = !!this.options.pushState;
|
this._hasPushState = !!(this.history && this.history.pushState);
|
this._usePushState = this._wantsPushState && this._hasPushState;
|
this.fragment = this.getFragment();
|
|
// Normalize root to always include a leading and trailing slash.
|
this.root = ('/' + this.root + '/').replace(rootStripper, '/');
|
|
// Transition from hashChange to pushState or vice versa if both are
|
// requested.
|
if (this._wantsHashChange && this._wantsPushState) {
|
|
// If we've started off with a route from a `pushState`-enabled
|
// browser, but we're currently in a browser that doesn't support it...
|
if (!this._hasPushState && !this.atRoot()) {
|
var rootPath = this.root.slice(0, -1) || '/';
|
this.location.replace(rootPath + '#' + this.getPath());
|
// Return immediately as browser will do redirect to new url
|
return true;
|
|
// Or if we've started out with a hash-based route, but we're currently
|
// in a browser where it could be `pushState`-based instead...
|
} else if (this._hasPushState && this.atRoot()) {
|
this.navigate(this.getHash(), {replace: true});
|
}
|
|
}
|
|
// Proxy an iframe to handle location events if the browser doesn't
|
// support the `hashchange` event, HTML5 history, or the user wants
|
// `hashChange` but not `pushState`.
|
if (!this._hasHashChange && this._wantsHashChange && !this._usePushState) {
|
this.iframe = document.createElement('iframe');
|
this.iframe.src = 'javascript:0';
|
this.iframe.style.display = 'none';
|
this.iframe.tabIndex = -1;
|
var body = document.body;
|
// Using `appendChild` will throw on IE < 9 if the document is not ready.
|
var iWindow = body.insertBefore(this.iframe, body.firstChild).contentWindow;
|
iWindow.document.open();
|
iWindow.document.close();
|
iWindow.location.hash = '#' + this.fragment;
|
}
|
|
// Add a cross-platform `addEventListener` shim for older browsers.
|
var addEventListener = window.addEventListener || function(eventName, listener) {
|
return attachEvent('on' + eventName, listener);
|
};
|
|
// Depending on whether we're using pushState or hashes, and whether
|
// 'onhashchange' is supported, determine how we check the URL state.
|
if (this._usePushState) {
|
addEventListener('popstate', this.checkUrl, false);
|
} else if (this._useHashChange && !this.iframe) {
|
addEventListener('hashchange', this.checkUrl, false);
|
} else if (this._wantsHashChange) {
|
this._checkUrlInterval = setInterval(this.checkUrl, this.interval);
|
}
|
|
if (!this.options.silent) return this.loadUrl();
|
},
|
|
// Disable Backbone.history, perhaps temporarily. Not useful in a real app,
|
// but possibly useful for unit testing Routers.
|
stop: function() {
|
// Add a cross-platform `removeEventListener` shim for older browsers.
|
var removeEventListener = window.removeEventListener || function(eventName, listener) {
|
return detachEvent('on' + eventName, listener);
|
};
|
|
// Remove window listeners.
|
if (this._usePushState) {
|
removeEventListener('popstate', this.checkUrl, false);
|
} else if (this._useHashChange && !this.iframe) {
|
removeEventListener('hashchange', this.checkUrl, false);
|
}
|
|
// Clean up the iframe if necessary.
|
if (this.iframe) {
|
document.body.removeChild(this.iframe);
|
this.iframe = null;
|
}
|
|
// Some environments will throw when clearing an undefined interval.
|
if (this._checkUrlInterval) clearInterval(this._checkUrlInterval);
|
History.started = false;
|
},
|
|
// Add a route to be tested when the fragment changes. Routes added later
|
// may override previous routes.
|
route: function(route, callback) {
|
this.handlers.unshift({route: route, callback: callback});
|
},
|
|
// Checks the current URL to see if it has changed, and if it has,
|
// calls `loadUrl`, normalizing across the hidden iframe.
|
checkUrl: function(e) {
|
var current = this.getFragment();
|
|
// If the user pressed the back button, the iframe's hash will have
|
// changed and we should use that for comparison.
|
if (current === this.fragment && this.iframe) {
|
current = this.getHash(this.iframe.contentWindow);
|
}
|
|
if (current === this.fragment) return false;
|
if (this.iframe) this.navigate(current);
|
this.loadUrl();
|
},
|
|
// Attempt to load the current URL fragment. If a route succeeds with a
|
// match, returns `true`. If no defined routes matches the fragment,
|
// returns `false`.
|
loadUrl: function(fragment) {
|
// If the root doesn't match, no routes can match either.
|
if (!this.matchRoot()) return false;
|
fragment = this.fragment = this.getFragment(fragment);
|
return _.some(this.handlers, function(handler) {
|
if (handler.route.test(fragment)) {
|
handler.callback(fragment);
|
return true;
|
}
|
});
|
},
|
|
// Save a fragment into the hash history, or replace the URL state if the
|
// 'replace' option is passed. You are responsible for properly URL-encoding
|
// the fragment in advance.
|
//
|
// The options object can contain `trigger: true` if you wish to have the
|
// route callback be fired (not usually desirable), or `replace: true`, if
|
// you wish to modify the current URL without adding an entry to the history.
|
navigate: function(fragment, options) {
|
if (!History.started) return false;
|
if (!options || options === true) options = {trigger: !!options};
|
|
// Normalize the fragment.
|
fragment = this.getFragment(fragment || '');
|
|
// Don't include a trailing slash on the root.
|
var rootPath = this.root;
|
if (fragment === '' || fragment.charAt(0) === '?') {
|
rootPath = rootPath.slice(0, -1) || '/';
|
}
|
var url = rootPath + fragment;
|
|
// Strip the hash and decode for matching.
|
fragment = this.decodeFragment(fragment.replace(pathStripper, ''));
|
|
if (this.fragment === fragment) return;
|
this.fragment = fragment;
|
|
// If pushState is available, we use it to set the fragment as a real URL.
|
if (this._usePushState) {
|
this.history[options.replace ? 'replaceState' : 'pushState']({}, document.title, url);
|
|
// If hash changes haven't been explicitly disabled, update the hash
|
// fragment to store history.
|
} else if (this._wantsHashChange) {
|
this._updateHash(this.location, fragment, options.replace);
|
if (this.iframe && fragment !== this.getHash(this.iframe.contentWindow)) {
|
var iWindow = this.iframe.contentWindow;
|
|
// Opening and closing the iframe tricks IE7 and earlier to push a
|
// history entry on hash-tag change. When replace is true, we don't
|
// want this.
|
if (!options.replace) {
|
iWindow.document.open();
|
iWindow.document.close();
|
}
|
|
this._updateHash(iWindow.location, fragment, options.replace);
|
}
|
|
// If you've told us that you explicitly don't want fallback hashchange-
|
// based history, then `navigate` becomes a page refresh.
|
} else {
|
return this.location.assign(url);
|
}
|
if (options.trigger) return this.loadUrl(fragment);
|
},
|
|
// Update the hash location, either replacing the current entry, or adding
|
// a new one to the browser history.
|
_updateHash: function(location, fragment, replace) {
|
if (replace) {
|
var href = location.href.replace(/(javascript:|#).*$/, '');
|
location.replace(href + '#' + fragment);
|
} else {
|
// Some browsers require that `hash` contains a leading #.
|
location.hash = '#' + fragment;
|
}
|
}
|
|
});
|
|
// Create the default Backbone.history.
|
Backbone.history = new History;
|
|
// Helpers
|
// -------
|
|
// Helper function to correctly set up the prototype chain for subclasses.
|
// Similar to `goog.inherits`, but uses a hash of prototype properties and
|
// class properties to be extended.
|
var extend = function(protoProps, staticProps) {
|
var parent = this;
|
var child;
|
|
// The constructor function for the new subclass is either defined by you
|
// (the "constructor" property in your `extend` definition), or defaulted
|
// by us to simply call the parent constructor.
|
if (protoProps && _.has(protoProps, 'constructor')) {
|
child = protoProps.constructor;
|
} else {
|
child = function(){ return parent.apply(this, arguments); };
|
}
|
|
// Add static properties to the constructor function, if supplied.
|
_.extend(child, parent, staticProps);
|
|
// Set the prototype chain to inherit from `parent`, without calling
|
// `parent`'s constructor function and add the prototype properties.
|
child.prototype = _.create(parent.prototype, protoProps);
|
child.prototype.constructor = child;
|
|
// Set a convenience property in case the parent's prototype is needed
|
// later.
|
child.__super__ = parent.prototype;
|
|
return child;
|
};
|
|
// Set up inheritance for the model, collection, router, view and history.
|
Model.extend = Collection.extend = Router.extend = View.extend = History.extend = extend;
|
|
// Throw an error when a URL is needed, and none is supplied.
|
var urlError = function() {
|
throw new Error('A "url" property or function must be specified');
|
};
|
|
// Wrap an optional error callback with a fallback error event.
|
var wrapError = function(model, options) {
|
var error = options.error;
|
options.error = function(resp) {
|
if (error) error.call(options.context, model, resp, options);
|
model.trigger('error', model, resp, options);
|
};
|
};
|
|
return Backbone;
|
});
|
|
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))
|
|
/***/ },
|
/* 2 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;// Underscore.js 1.8.3
|
// http://underscorejs.org
|
// (c) 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
// Underscore may be freely distributed under the MIT license.
|
|
(function() {
|
|
// Baseline setup
|
// --------------
|
|
// Establish the root object, `window` in the browser, or `exports` on the server.
|
var root = this;
|
|
// Save the previous value of the `_` variable.
|
var previousUnderscore = root._;
|
|
// Save bytes in the minified (but not gzipped) version:
|
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
|
|
// Create quick reference variables for speed access to core prototypes.
|
var
|
push = ArrayProto.push,
|
slice = ArrayProto.slice,
|
toString = ObjProto.toString,
|
hasOwnProperty = ObjProto.hasOwnProperty;
|
|
// All **ECMAScript 5** native function implementations that we hope to use
|
// are declared here.
|
var
|
nativeIsArray = Array.isArray,
|
nativeKeys = Object.keys,
|
nativeBind = FuncProto.bind,
|
nativeCreate = Object.create;
|
|
// Naked function reference for surrogate-prototype-swapping.
|
var Ctor = function(){};
|
|
// Create a safe reference to the Underscore object for use below.
|
var _ = function(obj) {
|
if (obj instanceof _) return obj;
|
if (!(this instanceof _)) return new _(obj);
|
this._wrapped = obj;
|
};
|
|
// Export the Underscore object for **Node.js**, with
|
// backwards-compatibility for the old `require()` API. If we're in
|
// the browser, add `_` as a global object.
|
if (true) {
|
if (typeof module !== 'undefined' && module.exports) {
|
exports = module.exports = _;
|
}
|
exports._ = _;
|
} else {
|
root._ = _;
|
}
|
|
// Current version.
|
_.VERSION = '1.8.3';
|
|
// Internal function that returns an efficient (for current engines) version
|
// of the passed-in callback, to be repeatedly applied in other Underscore
|
// functions.
|
var optimizeCb = function(func, context, argCount) {
|
if (context === void 0) return func;
|
switch (argCount == null ? 3 : argCount) {
|
case 1: return function(value) {
|
return func.call(context, value);
|
};
|
case 2: return function(value, other) {
|
return func.call(context, value, other);
|
};
|
case 3: return function(value, index, collection) {
|
return func.call(context, value, index, collection);
|
};
|
case 4: return function(accumulator, value, index, collection) {
|
return func.call(context, accumulator, value, index, collection);
|
};
|
}
|
return function() {
|
return func.apply(context, arguments);
|
};
|
};
|
|
// A mostly-internal function to generate callbacks that can be applied
|
// to each element in a collection, returning the desired result — either
|
// identity, an arbitrary callback, a property matcher, or a property accessor.
|
var cb = function(value, context, argCount) {
|
if (value == null) return _.identity;
|
if (_.isFunction(value)) return optimizeCb(value, context, argCount);
|
if (_.isObject(value)) return _.matcher(value);
|
return _.property(value);
|
};
|
_.iteratee = function(value, context) {
|
return cb(value, context, Infinity);
|
};
|
|
// An internal function for creating assigner functions.
|
var createAssigner = function(keysFunc, undefinedOnly) {
|
return function(obj) {
|
var length = arguments.length;
|
if (length < 2 || obj == null) return obj;
|
for (var index = 1; index < length; index++) {
|
var source = arguments[index],
|
keys = keysFunc(source),
|
l = keys.length;
|
for (var i = 0; i < l; i++) {
|
var key = keys[i];
|
if (!undefinedOnly || obj[key] === void 0) obj[key] = source[key];
|
}
|
}
|
return obj;
|
};
|
};
|
|
// An internal function for creating a new object that inherits from another.
|
var baseCreate = function(prototype) {
|
if (!_.isObject(prototype)) return {};
|
if (nativeCreate) return nativeCreate(prototype);
|
Ctor.prototype = prototype;
|
var result = new Ctor;
|
Ctor.prototype = null;
|
return result;
|
};
|
|
var property = function(key) {
|
return function(obj) {
|
return obj == null ? void 0 : obj[key];
|
};
|
};
|
|
// Helper for collection methods to determine whether a collection
|
// should be iterated as an array or as an object
|
// Related: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
|
// Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
|
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
|
var getLength = property('length');
|
var isArrayLike = function(collection) {
|
var length = getLength(collection);
|
return typeof length == 'number' && length >= 0 && length <= MAX_ARRAY_INDEX;
|
};
|
|
// Collection Functions
|
// --------------------
|
|
// The cornerstone, an `each` implementation, aka `forEach`.
|
// Handles raw objects in addition to array-likes. Treats all
|
// sparse array-likes as if they were dense.
|
_.each = _.forEach = function(obj, iteratee, context) {
|
iteratee = optimizeCb(iteratee, context);
|
var i, length;
|
if (isArrayLike(obj)) {
|
for (i = 0, length = obj.length; i < length; i++) {
|
iteratee(obj[i], i, obj);
|
}
|
} else {
|
var keys = _.keys(obj);
|
for (i = 0, length = keys.length; i < length; i++) {
|
iteratee(obj[keys[i]], keys[i], obj);
|
}
|
}
|
return obj;
|
};
|
|
// Return the results of applying the iteratee to each element.
|
_.map = _.collect = function(obj, iteratee, context) {
|
iteratee = cb(iteratee, context);
|
var keys = !isArrayLike(obj) && _.keys(obj),
|
length = (keys || obj).length,
|
results = Array(length);
|
for (var index = 0; index < length; index++) {
|
var currentKey = keys ? keys[index] : index;
|
results[index] = iteratee(obj[currentKey], currentKey, obj);
|
}
|
return results;
|
};
|
|
// Create a reducing function iterating left or right.
|
function createReduce(dir) {
|
// Optimized iterator function as using arguments.length
|
// in the main function will deoptimize the, see #1991.
|
function iterator(obj, iteratee, memo, keys, index, length) {
|
for (; index >= 0 && index < length; index += dir) {
|
var currentKey = keys ? keys[index] : index;
|
memo = iteratee(memo, obj[currentKey], currentKey, obj);
|
}
|
return memo;
|
}
|
|
return function(obj, iteratee, memo, context) {
|
iteratee = optimizeCb(iteratee, context, 4);
|
var keys = !isArrayLike(obj) && _.keys(obj),
|
length = (keys || obj).length,
|
index = dir > 0 ? 0 : length - 1;
|
// Determine the initial value if none is provided.
|
if (arguments.length < 3) {
|
memo = obj[keys ? keys[index] : index];
|
index += dir;
|
}
|
return iterator(obj, iteratee, memo, keys, index, length);
|
};
|
}
|
|
// **Reduce** builds up a single result from a list of values, aka `inject`,
|
// or `foldl`.
|
_.reduce = _.foldl = _.inject = createReduce(1);
|
|
// The right-associative version of reduce, also known as `foldr`.
|
_.reduceRight = _.foldr = createReduce(-1);
|
|
// Return the first value which passes a truth test. Aliased as `detect`.
|
_.find = _.detect = function(obj, predicate, context) {
|
var key;
|
if (isArrayLike(obj)) {
|
key = _.findIndex(obj, predicate, context);
|
} else {
|
key = _.findKey(obj, predicate, context);
|
}
|
if (key !== void 0 && key !== -1) return obj[key];
|
};
|
|
// Return all the elements that pass a truth test.
|
// Aliased as `select`.
|
_.filter = _.select = function(obj, predicate, context) {
|
var results = [];
|
predicate = cb(predicate, context);
|
_.each(obj, function(value, index, list) {
|
if (predicate(value, index, list)) results.push(value);
|
});
|
return results;
|
};
|
|
// Return all the elements for which a truth test fails.
|
_.reject = function(obj, predicate, context) {
|
return _.filter(obj, _.negate(cb(predicate)), context);
|
};
|
|
// Determine whether all of the elements match a truth test.
|
// Aliased as `all`.
|
_.every = _.all = function(obj, predicate, context) {
|
predicate = cb(predicate, context);
|
var keys = !isArrayLike(obj) && _.keys(obj),
|
length = (keys || obj).length;
|
for (var index = 0; index < length; index++) {
|
var currentKey = keys ? keys[index] : index;
|
if (!predicate(obj[currentKey], currentKey, obj)) return false;
|
}
|
return true;
|
};
|
|
// Determine if at least one element in the object matches a truth test.
|
// Aliased as `any`.
|
_.some = _.any = function(obj, predicate, context) {
|
predicate = cb(predicate, context);
|
var keys = !isArrayLike(obj) && _.keys(obj),
|
length = (keys || obj).length;
|
for (var index = 0; index < length; index++) {
|
var currentKey = keys ? keys[index] : index;
|
if (predicate(obj[currentKey], currentKey, obj)) return true;
|
}
|
return false;
|
};
|
|
// Determine if the array or object contains a given item (using `===`).
|
// Aliased as `includes` and `include`.
|
_.contains = _.includes = _.include = function(obj, item, fromIndex, guard) {
|
if (!isArrayLike(obj)) obj = _.values(obj);
|
if (typeof fromIndex != 'number' || guard) fromIndex = 0;
|
return _.indexOf(obj, item, fromIndex) >= 0;
|
};
|
|
// Invoke a method (with arguments) on every item in a collection.
|
_.invoke = function(obj, method) {
|
var args = slice.call(arguments, 2);
|
var isFunc = _.isFunction(method);
|
return _.map(obj, function(value) {
|
var func = isFunc ? method : value[method];
|
return func == null ? func : func.apply(value, args);
|
});
|
};
|
|
// Convenience version of a common use case of `map`: fetching a property.
|
_.pluck = function(obj, key) {
|
return _.map(obj, _.property(key));
|
};
|
|
// Convenience version of a common use case of `filter`: selecting only objects
|
// containing specific `key:value` pairs.
|
_.where = function(obj, attrs) {
|
return _.filter(obj, _.matcher(attrs));
|
};
|
|
// Convenience version of a common use case of `find`: getting the first object
|
// containing specific `key:value` pairs.
|
_.findWhere = function(obj, attrs) {
|
return _.find(obj, _.matcher(attrs));
|
};
|
|
// Return the maximum element (or element-based computation).
|
_.max = function(obj, iteratee, context) {
|
var result = -Infinity, lastComputed = -Infinity,
|
value, computed;
|
if (iteratee == null && obj != null) {
|
obj = isArrayLike(obj) ? obj : _.values(obj);
|
for (var i = 0, length = obj.length; i < length; i++) {
|
value = obj[i];
|
if (value > result) {
|
result = value;
|
}
|
}
|
} else {
|
iteratee = cb(iteratee, context);
|
_.each(obj, function(value, index, list) {
|
computed = iteratee(value, index, list);
|
if (computed > lastComputed || computed === -Infinity && result === -Infinity) {
|
result = value;
|
lastComputed = computed;
|
}
|
});
|
}
|
return result;
|
};
|
|
// Return the minimum element (or element-based computation).
|
_.min = function(obj, iteratee, context) {
|
var result = Infinity, lastComputed = Infinity,
|
value, computed;
|
if (iteratee == null && obj != null) {
|
obj = isArrayLike(obj) ? obj : _.values(obj);
|
for (var i = 0, length = obj.length; i < length; i++) {
|
value = obj[i];
|
if (value < result) {
|
result = value;
|
}
|
}
|
} else {
|
iteratee = cb(iteratee, context);
|
_.each(obj, function(value, index, list) {
|
computed = iteratee(value, index, list);
|
if (computed < lastComputed || computed === Infinity && result === Infinity) {
|
result = value;
|
lastComputed = computed;
|
}
|
});
|
}
|
return result;
|
};
|
|
// Shuffle a collection, using the modern version of the
|
// [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
|
_.shuffle = function(obj) {
|
var set = isArrayLike(obj) ? obj : _.values(obj);
|
var length = set.length;
|
var shuffled = Array(length);
|
for (var index = 0, rand; index < length; index++) {
|
rand = _.random(0, index);
|
if (rand !== index) shuffled[index] = shuffled[rand];
|
shuffled[rand] = set[index];
|
}
|
return shuffled;
|
};
|
|
// Sample **n** random values from a collection.
|
// If **n** is not specified, returns a single random element.
|
// The internal `guard` argument allows it to work with `map`.
|
_.sample = function(obj, n, guard) {
|
if (n == null || guard) {
|
if (!isArrayLike(obj)) obj = _.values(obj);
|
return obj[_.random(obj.length - 1)];
|
}
|
return _.shuffle(obj).slice(0, Math.max(0, n));
|
};
|
|
// Sort the object's values by a criterion produced by an iteratee.
|
_.sortBy = function(obj, iteratee, context) {
|
iteratee = cb(iteratee, context);
|
return _.pluck(_.map(obj, function(value, index, list) {
|
return {
|
value: value,
|
index: index,
|
criteria: iteratee(value, index, list)
|
};
|
}).sort(function(left, right) {
|
var a = left.criteria;
|
var b = right.criteria;
|
if (a !== b) {
|
if (a > b || a === void 0) return 1;
|
if (a < b || b === void 0) return -1;
|
}
|
return left.index - right.index;
|
}), 'value');
|
};
|
|
// An internal function used for aggregate "group by" operations.
|
var group = function(behavior) {
|
return function(obj, iteratee, context) {
|
var result = {};
|
iteratee = cb(iteratee, context);
|
_.each(obj, function(value, index) {
|
var key = iteratee(value, index, obj);
|
behavior(result, value, key);
|
});
|
return result;
|
};
|
};
|
|
// Groups the object's values by a criterion. Pass either a string attribute
|
// to group by, or a function that returns the criterion.
|
_.groupBy = group(function(result, value, key) {
|
if (_.has(result, key)) result[key].push(value); else result[key] = [value];
|
});
|
|
// Indexes the object's values by a criterion, similar to `groupBy`, but for
|
// when you know that your index values will be unique.
|
_.indexBy = group(function(result, value, key) {
|
result[key] = value;
|
});
|
|
// Counts instances of an object that group by a certain criterion. Pass
|
// either a string attribute to count by, or a function that returns the
|
// criterion.
|
_.countBy = group(function(result, value, key) {
|
if (_.has(result, key)) result[key]++; else result[key] = 1;
|
});
|
|
// Safely create a real, live array from anything iterable.
|
_.toArray = function(obj) {
|
if (!obj) return [];
|
if (_.isArray(obj)) return slice.call(obj);
|
if (isArrayLike(obj)) return _.map(obj, _.identity);
|
return _.values(obj);
|
};
|
|
// Return the number of elements in an object.
|
_.size = function(obj) {
|
if (obj == null) return 0;
|
return isArrayLike(obj) ? obj.length : _.keys(obj).length;
|
};
|
|
// Split a collection into two arrays: one whose elements all satisfy the given
|
// predicate, and one whose elements all do not satisfy the predicate.
|
_.partition = function(obj, predicate, context) {
|
predicate = cb(predicate, context);
|
var pass = [], fail = [];
|
_.each(obj, function(value, key, obj) {
|
(predicate(value, key, obj) ? pass : fail).push(value);
|
});
|
return [pass, fail];
|
};
|
|
// Array Functions
|
// ---------------
|
|
// Get the first element of an array. Passing **n** will return the first N
|
// values in the array. Aliased as `head` and `take`. The **guard** check
|
// allows it to work with `_.map`.
|
_.first = _.head = _.take = function(array, n, guard) {
|
if (array == null) return void 0;
|
if (n == null || guard) return array[0];
|
return _.initial(array, array.length - n);
|
};
|
|
// Returns everything but the last entry of the array. Especially useful on
|
// the arguments object. Passing **n** will return all the values in
|
// the array, excluding the last N.
|
_.initial = function(array, n, guard) {
|
return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
|
};
|
|
// Get the last element of an array. Passing **n** will return the last N
|
// values in the array.
|
_.last = function(array, n, guard) {
|
if (array == null) return void 0;
|
if (n == null || guard) return array[array.length - 1];
|
return _.rest(array, Math.max(0, array.length - n));
|
};
|
|
// Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
|
// Especially useful on the arguments object. Passing an **n** will return
|
// the rest N values in the array.
|
_.rest = _.tail = _.drop = function(array, n, guard) {
|
return slice.call(array, n == null || guard ? 1 : n);
|
};
|
|
// Trim out all falsy values from an array.
|
_.compact = function(array) {
|
return _.filter(array, _.identity);
|
};
|
|
// Internal implementation of a recursive `flatten` function.
|
var flatten = function(input, shallow, strict, startIndex) {
|
var output = [], idx = 0;
|
for (var i = startIndex || 0, length = getLength(input); i < length; i++) {
|
var value = input[i];
|
if (isArrayLike(value) && (_.isArray(value) || _.isArguments(value))) {
|
//flatten current level of array or arguments object
|
if (!shallow) value = flatten(value, shallow, strict);
|
var j = 0, len = value.length;
|
output.length += len;
|
while (j < len) {
|
output[idx++] = value[j++];
|
}
|
} else if (!strict) {
|
output[idx++] = value;
|
}
|
}
|
return output;
|
};
|
|
// Flatten out an array, either recursively (by default), or just one level.
|
_.flatten = function(array, shallow) {
|
return flatten(array, shallow, false);
|
};
|
|
// Return a version of the array that does not contain the specified value(s).
|
_.without = function(array) {
|
return _.difference(array, slice.call(arguments, 1));
|
};
|
|
// Produce a duplicate-free version of the array. If the array has already
|
// been sorted, you have the option of using a faster algorithm.
|
// Aliased as `unique`.
|
_.uniq = _.unique = function(array, isSorted, iteratee, context) {
|
if (!_.isBoolean(isSorted)) {
|
context = iteratee;
|
iteratee = isSorted;
|
isSorted = false;
|
}
|
if (iteratee != null) iteratee = cb(iteratee, context);
|
var result = [];
|
var seen = [];
|
for (var i = 0, length = getLength(array); i < length; i++) {
|
var value = array[i],
|
computed = iteratee ? iteratee(value, i, array) : value;
|
if (isSorted) {
|
if (!i || seen !== computed) result.push(value);
|
seen = computed;
|
} else if (iteratee) {
|
if (!_.contains(seen, computed)) {
|
seen.push(computed);
|
result.push(value);
|
}
|
} else if (!_.contains(result, value)) {
|
result.push(value);
|
}
|
}
|
return result;
|
};
|
|
// Produce an array that contains the union: each distinct element from all of
|
// the passed-in arrays.
|
_.union = function() {
|
return _.uniq(flatten(arguments, true, true));
|
};
|
|
// Produce an array that contains every item shared between all the
|
// passed-in arrays.
|
_.intersection = function(array) {
|
var result = [];
|
var argsLength = arguments.length;
|
for (var i = 0, length = getLength(array); i < length; i++) {
|
var item = array[i];
|
if (_.contains(result, item)) continue;
|
for (var j = 1; j < argsLength; j++) {
|
if (!_.contains(arguments[j], item)) break;
|
}
|
if (j === argsLength) result.push(item);
|
}
|
return result;
|
};
|
|
// Take the difference between one array and a number of other arrays.
|
// Only the elements present in just the first array will remain.
|
_.difference = function(array) {
|
var rest = flatten(arguments, true, true, 1);
|
return _.filter(array, function(value){
|
return !_.contains(rest, value);
|
});
|
};
|
|
// Zip together multiple lists into a single array -- elements that share
|
// an index go together.
|
_.zip = function() {
|
return _.unzip(arguments);
|
};
|
|
// Complement of _.zip. Unzip accepts an array of arrays and groups
|
// each array's elements on shared indices
|
_.unzip = function(array) {
|
var length = array && _.max(array, getLength).length || 0;
|
var result = Array(length);
|
|
for (var index = 0; index < length; index++) {
|
result[index] = _.pluck(array, index);
|
}
|
return result;
|
};
|
|
// Converts lists into objects. Pass either a single array of `[key, value]`
|
// pairs, or two parallel arrays of the same length -- one of keys, and one of
|
// the corresponding values.
|
_.object = function(list, values) {
|
var result = {};
|
for (var i = 0, length = getLength(list); i < length; i++) {
|
if (values) {
|
result[list[i]] = values[i];
|
} else {
|
result[list[i][0]] = list[i][1];
|
}
|
}
|
return result;
|
};
|
|
// Generator function to create the findIndex and findLastIndex functions
|
function createPredicateIndexFinder(dir) {
|
return function(array, predicate, context) {
|
predicate = cb(predicate, context);
|
var length = getLength(array);
|
var index = dir > 0 ? 0 : length - 1;
|
for (; index >= 0 && index < length; index += dir) {
|
if (predicate(array[index], index, array)) return index;
|
}
|
return -1;
|
};
|
}
|
|
// Returns the first index on an array-like that passes a predicate test
|
_.findIndex = createPredicateIndexFinder(1);
|
_.findLastIndex = createPredicateIndexFinder(-1);
|
|
// Use a comparator function to figure out the smallest index at which
|
// an object should be inserted so as to maintain order. Uses binary search.
|
_.sortedIndex = function(array, obj, iteratee, context) {
|
iteratee = cb(iteratee, context, 1);
|
var value = iteratee(obj);
|
var low = 0, high = getLength(array);
|
while (low < high) {
|
var mid = Math.floor((low + high) / 2);
|
if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
|
}
|
return low;
|
};
|
|
// Generator function to create the indexOf and lastIndexOf functions
|
function createIndexFinder(dir, predicateFind, sortedIndex) {
|
return function(array, item, idx) {
|
var i = 0, length = getLength(array);
|
if (typeof idx == 'number') {
|
if (dir > 0) {
|
i = idx >= 0 ? idx : Math.max(idx + length, i);
|
} else {
|
length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
|
}
|
} else if (sortedIndex && idx && length) {
|
idx = sortedIndex(array, item);
|
return array[idx] === item ? idx : -1;
|
}
|
if (item !== item) {
|
idx = predicateFind(slice.call(array, i, length), _.isNaN);
|
return idx >= 0 ? idx + i : -1;
|
}
|
for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
|
if (array[idx] === item) return idx;
|
}
|
return -1;
|
};
|
}
|
|
// Return the position of the first occurrence of an item in an array,
|
// or -1 if the item is not included in the array.
|
// If the array is large and already in sort order, pass `true`
|
// for **isSorted** to use binary search.
|
_.indexOf = createIndexFinder(1, _.findIndex, _.sortedIndex);
|
_.lastIndexOf = createIndexFinder(-1, _.findLastIndex);
|
|
// Generate an integer Array containing an arithmetic progression. A port of
|
// the native Python `range()` function. See
|
// [the Python documentation](http://docs.python.org/library/functions.html#range).
|
_.range = function(start, stop, step) {
|
if (stop == null) {
|
stop = start || 0;
|
start = 0;
|
}
|
step = step || 1;
|
|
var length = Math.max(Math.ceil((stop - start) / step), 0);
|
var range = Array(length);
|
|
for (var idx = 0; idx < length; idx++, start += step) {
|
range[idx] = start;
|
}
|
|
return range;
|
};
|
|
// Function (ahem) Functions
|
// ------------------
|
|
// Determines whether to execute a function as a constructor
|
// or a normal function with the provided arguments
|
var executeBound = function(sourceFunc, boundFunc, context, callingContext, args) {
|
if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
|
var self = baseCreate(sourceFunc.prototype);
|
var result = sourceFunc.apply(self, args);
|
if (_.isObject(result)) return result;
|
return self;
|
};
|
|
// Create a function bound to a given object (assigning `this`, and arguments,
|
// optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
|
// available.
|
_.bind = function(func, context) {
|
if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
|
if (!_.isFunction(func)) throw new TypeError('Bind must be called on a function');
|
var args = slice.call(arguments, 2);
|
var bound = function() {
|
return executeBound(func, bound, context, this, args.concat(slice.call(arguments)));
|
};
|
return bound;
|
};
|
|
// Partially apply a function by creating a version that has had some of its
|
// arguments pre-filled, without changing its dynamic `this` context. _ acts
|
// as a placeholder, allowing any combination of arguments to be pre-filled.
|
_.partial = function(func) {
|
var boundArgs = slice.call(arguments, 1);
|
var bound = function() {
|
var position = 0, length = boundArgs.length;
|
var args = Array(length);
|
for (var i = 0; i < length; i++) {
|
args[i] = boundArgs[i] === _ ? arguments[position++] : boundArgs[i];
|
}
|
while (position < arguments.length) args.push(arguments[position++]);
|
return executeBound(func, bound, this, this, args);
|
};
|
return bound;
|
};
|
|
// Bind a number of an object's methods to that object. Remaining arguments
|
// are the method names to be bound. Useful for ensuring that all callbacks
|
// defined on an object belong to it.
|
_.bindAll = function(obj) {
|
var i, length = arguments.length, key;
|
if (length <= 1) throw new Error('bindAll must be passed function names');
|
for (i = 1; i < length; i++) {
|
key = arguments[i];
|
obj[key] = _.bind(obj[key], obj);
|
}
|
return obj;
|
};
|
|
// Memoize an expensive function by storing its results.
|
_.memoize = function(func, hasher) {
|
var memoize = function(key) {
|
var cache = memoize.cache;
|
var address = '' + (hasher ? hasher.apply(this, arguments) : key);
|
if (!_.has(cache, address)) cache[address] = func.apply(this, arguments);
|
return cache[address];
|
};
|
memoize.cache = {};
|
return memoize;
|
};
|
|
// Delays a function for the given number of milliseconds, and then calls
|
// it with the arguments supplied.
|
_.delay = function(func, wait) {
|
var args = slice.call(arguments, 2);
|
return setTimeout(function(){
|
return func.apply(null, args);
|
}, wait);
|
};
|
|
// Defers a function, scheduling it to run after the current call stack has
|
// cleared.
|
_.defer = _.partial(_.delay, _, 1);
|
|
// Returns a function, that, when invoked, will only be triggered at most once
|
// during a given window of time. Normally, the throttled function will run
|
// as much as it can, without ever going more than once per `wait` duration;
|
// but if you'd like to disable the execution on the leading edge, pass
|
// `{leading: false}`. To disable execution on the trailing edge, ditto.
|
_.throttle = function(func, wait, options) {
|
var context, args, result;
|
var timeout = null;
|
var previous = 0;
|
if (!options) options = {};
|
var later = function() {
|
previous = options.leading === false ? 0 : _.now();
|
timeout = null;
|
result = func.apply(context, args);
|
if (!timeout) context = args = null;
|
};
|
return function() {
|
var now = _.now();
|
if (!previous && options.leading === false) previous = now;
|
var remaining = wait - (now - previous);
|
context = this;
|
args = arguments;
|
if (remaining <= 0 || remaining > wait) {
|
if (timeout) {
|
clearTimeout(timeout);
|
timeout = null;
|
}
|
previous = now;
|
result = func.apply(context, args);
|
if (!timeout) context = args = null;
|
} else if (!timeout && options.trailing !== false) {
|
timeout = setTimeout(later, remaining);
|
}
|
return result;
|
};
|
};
|
|
// Returns a function, that, as long as it continues to be invoked, will not
|
// be triggered. The function will be called after it stops being called for
|
// N milliseconds. If `immediate` is passed, trigger the function on the
|
// leading edge, instead of the trailing.
|
_.debounce = function(func, wait, immediate) {
|
var timeout, args, context, timestamp, result;
|
|
var later = function() {
|
var last = _.now() - timestamp;
|
|
if (last < wait && last >= 0) {
|
timeout = setTimeout(later, wait - last);
|
} else {
|
timeout = null;
|
if (!immediate) {
|
result = func.apply(context, args);
|
if (!timeout) context = args = null;
|
}
|
}
|
};
|
|
return function() {
|
context = this;
|
args = arguments;
|
timestamp = _.now();
|
var callNow = immediate && !timeout;
|
if (!timeout) timeout = setTimeout(later, wait);
|
if (callNow) {
|
result = func.apply(context, args);
|
context = args = null;
|
}
|
|
return result;
|
};
|
};
|
|
// Returns the first function passed as an argument to the second,
|
// allowing you to adjust arguments, run code before and after, and
|
// conditionally execute the original function.
|
_.wrap = function(func, wrapper) {
|
return _.partial(wrapper, func);
|
};
|
|
// Returns a negated version of the passed-in predicate.
|
_.negate = function(predicate) {
|
return function() {
|
return !predicate.apply(this, arguments);
|
};
|
};
|
|
// Returns a function that is the composition of a list of functions, each
|
// consuming the return value of the function that follows.
|
_.compose = function() {
|
var args = arguments;
|
var start = args.length - 1;
|
return function() {
|
var i = start;
|
var result = args[start].apply(this, arguments);
|
while (i--) result = args[i].call(this, result);
|
return result;
|
};
|
};
|
|
// Returns a function that will only be executed on and after the Nth call.
|
_.after = function(times, func) {
|
return function() {
|
if (--times < 1) {
|
return func.apply(this, arguments);
|
}
|
};
|
};
|
|
// Returns a function that will only be executed up to (but not including) the Nth call.
|
_.before = function(times, func) {
|
var memo;
|
return function() {
|
if (--times > 0) {
|
memo = func.apply(this, arguments);
|
}
|
if (times <= 1) func = null;
|
return memo;
|
};
|
};
|
|
// Returns a function that will be executed at most one time, no matter how
|
// often you call it. Useful for lazy initialization.
|
_.once = _.partial(_.before, 2);
|
|
// Object Functions
|
// ----------------
|
|
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
|
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
|
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
|
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
|
|
function collectNonEnumProps(obj, keys) {
|
var nonEnumIdx = nonEnumerableProps.length;
|
var constructor = obj.constructor;
|
var proto = (_.isFunction(constructor) && constructor.prototype) || ObjProto;
|
|
// Constructor is a special case.
|
var prop = 'constructor';
|
if (_.has(obj, prop) && !_.contains(keys, prop)) keys.push(prop);
|
|
while (nonEnumIdx--) {
|
prop = nonEnumerableProps[nonEnumIdx];
|
if (prop in obj && obj[prop] !== proto[prop] && !_.contains(keys, prop)) {
|
keys.push(prop);
|
}
|
}
|
}
|
|
// Retrieve the names of an object's own properties.
|
// Delegates to **ECMAScript 5**'s native `Object.keys`
|
_.keys = function(obj) {
|
if (!_.isObject(obj)) return [];
|
if (nativeKeys) return nativeKeys(obj);
|
var keys = [];
|
for (var key in obj) if (_.has(obj, key)) keys.push(key);
|
// Ahem, IE < 9.
|
if (hasEnumBug) collectNonEnumProps(obj, keys);
|
return keys;
|
};
|
|
// Retrieve all the property names of an object.
|
_.allKeys = function(obj) {
|
if (!_.isObject(obj)) return [];
|
var keys = [];
|
for (var key in obj) keys.push(key);
|
// Ahem, IE < 9.
|
if (hasEnumBug) collectNonEnumProps(obj, keys);
|
return keys;
|
};
|
|
// Retrieve the values of an object's properties.
|
_.values = function(obj) {
|
var keys = _.keys(obj);
|
var length = keys.length;
|
var values = Array(length);
|
for (var i = 0; i < length; i++) {
|
values[i] = obj[keys[i]];
|
}
|
return values;
|
};
|
|
// Returns the results of applying the iteratee to each element of the object
|
// In contrast to _.map it returns an object
|
_.mapObject = function(obj, iteratee, context) {
|
iteratee = cb(iteratee, context);
|
var keys = _.keys(obj),
|
length = keys.length,
|
results = {},
|
currentKey;
|
for (var index = 0; index < length; index++) {
|
currentKey = keys[index];
|
results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
|
}
|
return results;
|
};
|
|
// Convert an object into a list of `[key, value]` pairs.
|
_.pairs = function(obj) {
|
var keys = _.keys(obj);
|
var length = keys.length;
|
var pairs = Array(length);
|
for (var i = 0; i < length; i++) {
|
pairs[i] = [keys[i], obj[keys[i]]];
|
}
|
return pairs;
|
};
|
|
// Invert the keys and values of an object. The values must be serializable.
|
_.invert = function(obj) {
|
var result = {};
|
var keys = _.keys(obj);
|
for (var i = 0, length = keys.length; i < length; i++) {
|
result[obj[keys[i]]] = keys[i];
|
}
|
return result;
|
};
|
|
// Return a sorted list of the function names available on the object.
|
// Aliased as `methods`
|
_.functions = _.methods = function(obj) {
|
var names = [];
|
for (var key in obj) {
|
if (_.isFunction(obj[key])) names.push(key);
|
}
|
return names.sort();
|
};
|
|
// Extend a given object with all the properties in passed-in object(s).
|
_.extend = createAssigner(_.allKeys);
|
|
// Assigns a given object with all the own properties in the passed-in object(s)
|
// (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
|
_.extendOwn = _.assign = createAssigner(_.keys);
|
|
// Returns the first key on an object that passes a predicate test
|
_.findKey = function(obj, predicate, context) {
|
predicate = cb(predicate, context);
|
var keys = _.keys(obj), key;
|
for (var i = 0, length = keys.length; i < length; i++) {
|
key = keys[i];
|
if (predicate(obj[key], key, obj)) return key;
|
}
|
};
|
|
// Return a copy of the object only containing the whitelisted properties.
|
_.pick = function(object, oiteratee, context) {
|
var result = {}, obj = object, iteratee, keys;
|
if (obj == null) return result;
|
if (_.isFunction(oiteratee)) {
|
keys = _.allKeys(obj);
|
iteratee = optimizeCb(oiteratee, context);
|
} else {
|
keys = flatten(arguments, false, false, 1);
|
iteratee = function(value, key, obj) { return key in obj; };
|
obj = Object(obj);
|
}
|
for (var i = 0, length = keys.length; i < length; i++) {
|
var key = keys[i];
|
var value = obj[key];
|
if (iteratee(value, key, obj)) result[key] = value;
|
}
|
return result;
|
};
|
|
// Return a copy of the object without the blacklisted properties.
|
_.omit = function(obj, iteratee, context) {
|
if (_.isFunction(iteratee)) {
|
iteratee = _.negate(iteratee);
|
} else {
|
var keys = _.map(flatten(arguments, false, false, 1), String);
|
iteratee = function(value, key) {
|
return !_.contains(keys, key);
|
};
|
}
|
return _.pick(obj, iteratee, context);
|
};
|
|
// Fill in a given object with default properties.
|
_.defaults = createAssigner(_.allKeys, true);
|
|
// Creates an object that inherits from the given prototype object.
|
// If additional properties are provided then they will be added to the
|
// created object.
|
_.create = function(prototype, props) {
|
var result = baseCreate(prototype);
|
if (props) _.extendOwn(result, props);
|
return result;
|
};
|
|
// Create a (shallow-cloned) duplicate of an object.
|
_.clone = function(obj) {
|
if (!_.isObject(obj)) return obj;
|
return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
|
};
|
|
// Invokes interceptor with the obj, and then returns obj.
|
// The primary purpose of this method is to "tap into" a method chain, in
|
// order to perform operations on intermediate results within the chain.
|
_.tap = function(obj, interceptor) {
|
interceptor(obj);
|
return obj;
|
};
|
|
// Returns whether an object has a given set of `key:value` pairs.
|
_.isMatch = function(object, attrs) {
|
var keys = _.keys(attrs), length = keys.length;
|
if (object == null) return !length;
|
var obj = Object(object);
|
for (var i = 0; i < length; i++) {
|
var key = keys[i];
|
if (attrs[key] !== obj[key] || !(key in obj)) return false;
|
}
|
return true;
|
};
|
|
|
// Internal recursive comparison function for `isEqual`.
|
var eq = function(a, b, aStack, bStack) {
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
if (a === b) return a !== 0 || 1 / a === 1 / b;
|
// A strict comparison is necessary because `null == undefined`.
|
if (a == null || b == null) return a === b;
|
// Unwrap any wrapped objects.
|
if (a instanceof _) a = a._wrapped;
|
if (b instanceof _) b = b._wrapped;
|
// Compare `[[Class]]` names.
|
var className = toString.call(a);
|
if (className !== toString.call(b)) return false;
|
switch (className) {
|
// Strings, numbers, regular expressions, dates, and booleans are compared by value.
|
case '[object RegExp]':
|
// RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
|
case '[object String]':
|
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
// equivalent to `new String("5")`.
|
return '' + a === '' + b;
|
case '[object Number]':
|
// `NaN`s are equivalent, but non-reflexive.
|
// Object(NaN) is equivalent to NaN
|
if (+a !== +a) return +b !== +b;
|
// An `egal` comparison is performed for other numeric values.
|
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
case '[object Date]':
|
case '[object Boolean]':
|
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
// millisecond representations. Note that invalid dates with millisecond representations
|
// of `NaN` are not equivalent.
|
return +a === +b;
|
}
|
|
var areArrays = className === '[object Array]';
|
if (!areArrays) {
|
if (typeof a != 'object' || typeof b != 'object') return false;
|
|
// Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
// from different frames are.
|
var aCtor = a.constructor, bCtor = b.constructor;
|
if (aCtor !== bCtor && !(_.isFunction(aCtor) && aCtor instanceof aCtor &&
|
_.isFunction(bCtor) && bCtor instanceof bCtor)
|
&& ('constructor' in a && 'constructor' in b)) {
|
return false;
|
}
|
}
|
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
|
// Initializing stack of traversed objects.
|
// It's done here since we only need them for objects and arrays comparison.
|
aStack = aStack || [];
|
bStack = bStack || [];
|
var length = aStack.length;
|
while (length--) {
|
// Linear search. Performance is inversely proportional to the number of
|
// unique nested structures.
|
if (aStack[length] === a) return bStack[length] === b;
|
}
|
|
// Add the first object to the stack of traversed objects.
|
aStack.push(a);
|
bStack.push(b);
|
|
// Recursively compare objects and arrays.
|
if (areArrays) {
|
// Compare array lengths to determine if a deep comparison is necessary.
|
length = a.length;
|
if (length !== b.length) return false;
|
// Deep compare the contents, ignoring non-numeric properties.
|
while (length--) {
|
if (!eq(a[length], b[length], aStack, bStack)) return false;
|
}
|
} else {
|
// Deep compare objects.
|
var keys = _.keys(a), key;
|
length = keys.length;
|
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
if (_.keys(b).length !== length) return false;
|
while (length--) {
|
// Deep compare each member
|
key = keys[length];
|
if (!(_.has(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
|
}
|
}
|
// Remove the first object from the stack of traversed objects.
|
aStack.pop();
|
bStack.pop();
|
return true;
|
};
|
|
// Perform a deep comparison to check if two objects are equal.
|
_.isEqual = function(a, b) {
|
return eq(a, b);
|
};
|
|
// Is a given array, string, or object empty?
|
// An "empty" object has no enumerable own-properties.
|
_.isEmpty = function(obj) {
|
if (obj == null) return true;
|
if (isArrayLike(obj) && (_.isArray(obj) || _.isString(obj) || _.isArguments(obj))) return obj.length === 0;
|
return _.keys(obj).length === 0;
|
};
|
|
// Is a given value a DOM element?
|
_.isElement = function(obj) {
|
return !!(obj && obj.nodeType === 1);
|
};
|
|
// Is a given value an array?
|
// Delegates to ECMA5's native Array.isArray
|
_.isArray = nativeIsArray || function(obj) {
|
return toString.call(obj) === '[object Array]';
|
};
|
|
// Is a given variable an object?
|
_.isObject = function(obj) {
|
var type = typeof obj;
|
return type === 'function' || type === 'object' && !!obj;
|
};
|
|
// Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp, isError.
|
_.each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'], function(name) {
|
_['is' + name] = function(obj) {
|
return toString.call(obj) === '[object ' + name + ']';
|
};
|
});
|
|
// Define a fallback version of the method in browsers (ahem, IE < 9), where
|
// there isn't any inspectable "Arguments" type.
|
if (!_.isArguments(arguments)) {
|
_.isArguments = function(obj) {
|
return _.has(obj, 'callee');
|
};
|
}
|
|
// Optimize `isFunction` if appropriate. Work around some typeof bugs in old v8,
|
// IE 11 (#1621), and in Safari 8 (#1929).
|
if (typeof /./ != 'function' && typeof Int8Array != 'object') {
|
_.isFunction = function(obj) {
|
return typeof obj == 'function' || false;
|
};
|
}
|
|
// Is a given object a finite number?
|
_.isFinite = function(obj) {
|
return isFinite(obj) && !isNaN(parseFloat(obj));
|
};
|
|
// Is the given value `NaN`? (NaN is the only number which does not equal itself).
|
_.isNaN = function(obj) {
|
return _.isNumber(obj) && obj !== +obj;
|
};
|
|
// Is a given value a boolean?
|
_.isBoolean = function(obj) {
|
return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
|
};
|
|
// Is a given value equal to null?
|
_.isNull = function(obj) {
|
return obj === null;
|
};
|
|
// Is a given variable undefined?
|
_.isUndefined = function(obj) {
|
return obj === void 0;
|
};
|
|
// Shortcut function for checking if an object has a given property directly
|
// on itself (in other words, not on a prototype).
|
_.has = function(obj, key) {
|
return obj != null && hasOwnProperty.call(obj, key);
|
};
|
|
// Utility Functions
|
// -----------------
|
|
// Run Underscore.js in *noConflict* mode, returning the `_` variable to its
|
// previous owner. Returns a reference to the Underscore object.
|
_.noConflict = function() {
|
root._ = previousUnderscore;
|
return this;
|
};
|
|
// Keep the identity function around for default iteratees.
|
_.identity = function(value) {
|
return value;
|
};
|
|
// Predicate-generating functions. Often useful outside of Underscore.
|
_.constant = function(value) {
|
return function() {
|
return value;
|
};
|
};
|
|
_.noop = function(){};
|
|
_.property = property;
|
|
// Generates a function for a given object that returns a given property.
|
_.propertyOf = function(obj) {
|
return obj == null ? function(){} : function(key) {
|
return obj[key];
|
};
|
};
|
|
// Returns a predicate for checking whether an object has a given set of
|
// `key:value` pairs.
|
_.matcher = _.matches = function(attrs) {
|
attrs = _.extendOwn({}, attrs);
|
return function(obj) {
|
return _.isMatch(obj, attrs);
|
};
|
};
|
|
// Run a function **n** times.
|
_.times = function(n, iteratee, context) {
|
var accum = Array(Math.max(0, n));
|
iteratee = optimizeCb(iteratee, context, 1);
|
for (var i = 0; i < n; i++) accum[i] = iteratee(i);
|
return accum;
|
};
|
|
// Return a random integer between min and max (inclusive).
|
_.random = function(min, max) {
|
if (max == null) {
|
max = min;
|
min = 0;
|
}
|
return min + Math.floor(Math.random() * (max - min + 1));
|
};
|
|
// A (possibly faster) way to get the current timestamp as an integer.
|
_.now = Date.now || function() {
|
return new Date().getTime();
|
};
|
|
// List of HTML entities for escaping.
|
var escapeMap = {
|
'&': '&',
|
'<': '<',
|
'>': '>',
|
'"': '"',
|
"'": ''',
|
'`': '`'
|
};
|
var unescapeMap = _.invert(escapeMap);
|
|
// Functions for escaping and unescaping strings to/from HTML interpolation.
|
var createEscaper = function(map) {
|
var escaper = function(match) {
|
return map[match];
|
};
|
// Regexes for identifying a key that needs to be escaped
|
var source = '(?:' + _.keys(map).join('|') + ')';
|
var testRegexp = RegExp(source);
|
var replaceRegexp = RegExp(source, 'g');
|
return function(string) {
|
string = string == null ? '' : '' + string;
|
return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
|
};
|
};
|
_.escape = createEscaper(escapeMap);
|
_.unescape = createEscaper(unescapeMap);
|
|
// If the value of the named `property` is a function then invoke it with the
|
// `object` as context; otherwise, return it.
|
_.result = function(object, property, fallback) {
|
var value = object == null ? void 0 : object[property];
|
if (value === void 0) {
|
value = fallback;
|
}
|
return _.isFunction(value) ? value.call(object) : value;
|
};
|
|
// Generate a unique integer id (unique within the entire client session).
|
// Useful for temporary DOM ids.
|
var idCounter = 0;
|
_.uniqueId = function(prefix) {
|
var id = ++idCounter + '';
|
return prefix ? prefix + id : id;
|
};
|
|
// By default, Underscore uses ERB-style template delimiters, change the
|
// following template settings to use alternative delimiters.
|
_.templateSettings = {
|
evaluate : /<%([\s\S]+?)%>/g,
|
interpolate : /<%=([\s\S]+?)%>/g,
|
escape : /<%-([\s\S]+?)%>/g
|
};
|
|
// When customizing `templateSettings`, if you don't want to define an
|
// interpolation, evaluation or escaping regex, we need one that is
|
// guaranteed not to match.
|
var noMatch = /(.)^/;
|
|
// Certain characters need to be escaped so that they can be put into a
|
// string literal.
|
var escapes = {
|
"'": "'",
|
'\\': '\\',
|
'\r': 'r',
|
'\n': 'n',
|
'\u2028': 'u2028',
|
'\u2029': 'u2029'
|
};
|
|
var escaper = /\\|'|\r|\n|\u2028|\u2029/g;
|
|
var escapeChar = function(match) {
|
return '\\' + escapes[match];
|
};
|
|
// JavaScript micro-templating, similar to John Resig's implementation.
|
// Underscore templating handles arbitrary delimiters, preserves whitespace,
|
// and correctly escapes quotes within interpolated code.
|
// NB: `oldSettings` only exists for backwards compatibility.
|
_.template = function(text, settings, oldSettings) {
|
if (!settings && oldSettings) settings = oldSettings;
|
settings = _.defaults({}, settings, _.templateSettings);
|
|
// Combine delimiters into one regular expression via alternation.
|
var matcher = RegExp([
|
(settings.escape || noMatch).source,
|
(settings.interpolate || noMatch).source,
|
(settings.evaluate || noMatch).source
|
].join('|') + '|$', 'g');
|
|
// Compile the template source, escaping string literals appropriately.
|
var index = 0;
|
var source = "__p+='";
|
text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
|
source += text.slice(index, offset).replace(escaper, escapeChar);
|
index = offset + match.length;
|
|
if (escape) {
|
source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
|
} else if (interpolate) {
|
source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
|
} else if (evaluate) {
|
source += "';\n" + evaluate + "\n__p+='";
|
}
|
|
// Adobe VMs need the match returned to produce the correct offest.
|
return match;
|
});
|
source += "';\n";
|
|
// If a variable is not specified, place data values in local scope.
|
if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
|
|
source = "var __t,__p='',__j=Array.prototype.join," +
|
"print=function(){__p+=__j.call(arguments,'');};\n" +
|
source + 'return __p;\n';
|
|
try {
|
var render = new Function(settings.variable || 'obj', '_', source);
|
} catch (e) {
|
e.source = source;
|
throw e;
|
}
|
|
var template = function(data) {
|
return render.call(this, data, _);
|
};
|
|
// Provide the compiled source as a convenience for precompilation.
|
var argument = settings.variable || 'obj';
|
template.source = 'function(' + argument + '){\n' + source + '}';
|
|
return template;
|
};
|
|
// Add a "chain" function. Start chaining a wrapped Underscore object.
|
_.chain = function(obj) {
|
var instance = _(obj);
|
instance._chain = true;
|
return instance;
|
};
|
|
// OOP
|
// ---------------
|
// If Underscore is called as a function, it returns a wrapped object that
|
// can be used OO-style. This wrapper holds altered versions of all the
|
// underscore functions. Wrapped objects may be chained.
|
|
// Helper function to continue chaining intermediate results.
|
var result = function(instance, obj) {
|
return instance._chain ? _(obj).chain() : obj;
|
};
|
|
// Add your own custom functions to the Underscore object.
|
_.mixin = function(obj) {
|
_.each(_.functions(obj), function(name) {
|
var func = _[name] = obj[name];
|
_.prototype[name] = function() {
|
var args = [this._wrapped];
|
push.apply(args, arguments);
|
return result(this, func.apply(_, args));
|
};
|
});
|
};
|
|
// Add all of the Underscore functions to the wrapper object.
|
_.mixin(_);
|
|
// Add all mutator Array functions to the wrapper.
|
_.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
|
var method = ArrayProto[name];
|
_.prototype[name] = function() {
|
var obj = this._wrapped;
|
method.apply(obj, arguments);
|
if ((name === 'shift' || name === 'splice') && obj.length === 0) delete obj[0];
|
return result(this, obj);
|
};
|
});
|
|
// Add all accessor Array functions to the wrapper.
|
_.each(['concat', 'join', 'slice'], function(name) {
|
var method = ArrayProto[name];
|
_.prototype[name] = function() {
|
return result(this, method.apply(this._wrapped, arguments));
|
};
|
});
|
|
// Extracts the result from a wrapped and chained object.
|
_.prototype.value = function() {
|
return this._wrapped;
|
};
|
|
// Provide unwrapping proxy for some methods used in engine operations
|
// such as arithmetic and JSON stringification.
|
_.prototype.valueOf = _.prototype.toJSON = _.prototype.value;
|
|
_.prototype.toString = function() {
|
return '' + this._wrapped;
|
};
|
|
// AMD registration happens at the end for compatibility with AMD loaders
|
// that may not enforce next-turn semantics on modules. Even though general
|
// practice for AMD registration is to be anonymous, underscore registers
|
// as a named module because, like jQuery, it is a base library that is
|
// popular enough to be bundled in a third party lib, but not be part of
|
// an AMD load request. Those cases could generate an error when an
|
// anonymous define() is called outside of a loader request.
|
if (true) {
|
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() {
|
return _;
|
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
}
|
}.call(this));
|
|
|
/***/ },
|
/* 3 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*!
|
* jQuery JavaScript Library v2.2.3
|
* http://jquery.com/
|
*
|
* Includes Sizzle.js
|
* http://sizzlejs.com/
|
*
|
* Copyright jQuery Foundation and other contributors
|
* Released under the MIT license
|
* http://jquery.org/license
|
*
|
* Date: 2016-04-05T19:26Z
|
*/
|
|
(function( global, factory ) {
|
|
if ( typeof module === "object" && typeof module.exports === "object" ) {
|
// For CommonJS and CommonJS-like environments where a proper `window`
|
// is present, execute the factory and get jQuery.
|
// For environments that do not have a `window` with a `document`
|
// (such as Node.js), expose a factory as module.exports.
|
// This accentuates the need for the creation of a real `window`.
|
// e.g. var jQuery = require("jquery")(window);
|
// See ticket #14549 for more info.
|
module.exports = global.document ?
|
factory( global, true ) :
|
function( w ) {
|
if ( !w.document ) {
|
throw new Error( "jQuery requires a window with a document" );
|
}
|
return factory( w );
|
};
|
} else {
|
factory( global );
|
}
|
|
// Pass this if window is not defined yet
|
}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
|
|
// Support: Firefox 18+
|
// Can't be in strict mode, several libs including ASP.NET trace
|
// the stack via arguments.caller.callee and Firefox dies if
|
// you try to trace through "use strict" call chains. (#13335)
|
//"use strict";
|
var arr = [];
|
|
var document = window.document;
|
|
var slice = arr.slice;
|
|
var concat = arr.concat;
|
|
var push = arr.push;
|
|
var indexOf = arr.indexOf;
|
|
var class2type = {};
|
|
var toString = class2type.toString;
|
|
var hasOwn = class2type.hasOwnProperty;
|
|
var support = {};
|
|
|
|
var
|
version = "2.2.3",
|
|
// Define a local copy of jQuery
|
jQuery = function( selector, context ) {
|
|
// The jQuery object is actually just the init constructor 'enhanced'
|
// Need init if jQuery is called (just allow error to be thrown if not included)
|
return new jQuery.fn.init( selector, context );
|
},
|
|
// Support: Android<4.1
|
// Make sure we trim BOM and NBSP
|
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
|
|
// Matches dashed string for camelizing
|
rmsPrefix = /^-ms-/,
|
rdashAlpha = /-([\da-z])/gi,
|
|
// Used by jQuery.camelCase as callback to replace()
|
fcamelCase = function( all, letter ) {
|
return letter.toUpperCase();
|
};
|
|
jQuery.fn = jQuery.prototype = {
|
|
// The current version of jQuery being used
|
jquery: version,
|
|
constructor: jQuery,
|
|
// Start with an empty selector
|
selector: "",
|
|
// The default length of a jQuery object is 0
|
length: 0,
|
|
toArray: function() {
|
return slice.call( this );
|
},
|
|
// Get the Nth element in the matched element set OR
|
// Get the whole matched element set as a clean array
|
get: function( num ) {
|
return num != null ?
|
|
// Return just the one element from the set
|
( num < 0 ? this[ num + this.length ] : this[ num ] ) :
|
|
// Return all the elements in a clean array
|
slice.call( this );
|
},
|
|
// Take an array of elements and push it onto the stack
|
// (returning the new matched element set)
|
pushStack: function( elems ) {
|
|
// Build a new jQuery matched element set
|
var ret = jQuery.merge( this.constructor(), elems );
|
|
// Add the old object onto the stack (as a reference)
|
ret.prevObject = this;
|
ret.context = this.context;
|
|
// Return the newly-formed element set
|
return ret;
|
},
|
|
// Execute a callback for every element in the matched set.
|
each: function( callback ) {
|
return jQuery.each( this, callback );
|
},
|
|
map: function( callback ) {
|
return this.pushStack( jQuery.map( this, function( elem, i ) {
|
return callback.call( elem, i, elem );
|
} ) );
|
},
|
|
slice: function() {
|
return this.pushStack( slice.apply( this, arguments ) );
|
},
|
|
first: function() {
|
return this.eq( 0 );
|
},
|
|
last: function() {
|
return this.eq( -1 );
|
},
|
|
eq: function( i ) {
|
var len = this.length,
|
j = +i + ( i < 0 ? len : 0 );
|
return this.pushStack( j >= 0 && j < len ? [ this[ j ] ] : [] );
|
},
|
|
end: function() {
|
return this.prevObject || this.constructor();
|
},
|
|
// For internal use only.
|
// Behaves like an Array's method, not like a jQuery method.
|
push: push,
|
sort: arr.sort,
|
splice: arr.splice
|
};
|
|
jQuery.extend = jQuery.fn.extend = function() {
|
var options, name, src, copy, copyIsArray, clone,
|
target = arguments[ 0 ] || {},
|
i = 1,
|
length = arguments.length,
|
deep = false;
|
|
// Handle a deep copy situation
|
if ( typeof target === "boolean" ) {
|
deep = target;
|
|
// Skip the boolean and the target
|
target = arguments[ i ] || {};
|
i++;
|
}
|
|
// Handle case when target is a string or something (possible in deep copy)
|
if ( typeof target !== "object" && !jQuery.isFunction( target ) ) {
|
target = {};
|
}
|
|
// Extend jQuery itself if only one argument is passed
|
if ( i === length ) {
|
target = this;
|
i--;
|
}
|
|
for ( ; i < length; i++ ) {
|
|
// Only deal with non-null/undefined values
|
if ( ( options = arguments[ i ] ) != null ) {
|
|
// Extend the base object
|
for ( name in options ) {
|
src = target[ name ];
|
copy = options[ name ];
|
|
// Prevent never-ending loop
|
if ( target === copy ) {
|
continue;
|
}
|
|
// Recurse if we're merging plain objects or arrays
|
if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
|
( copyIsArray = jQuery.isArray( copy ) ) ) ) {
|
|
if ( copyIsArray ) {
|
copyIsArray = false;
|
clone = src && jQuery.isArray( src ) ? src : [];
|
|
} else {
|
clone = src && jQuery.isPlainObject( src ) ? src : {};
|
}
|
|
// Never move original objects, clone them
|
target[ name ] = jQuery.extend( deep, clone, copy );
|
|
// Don't bring in undefined values
|
} else if ( copy !== undefined ) {
|
target[ name ] = copy;
|
}
|
}
|
}
|
}
|
|
// Return the modified object
|
return target;
|
};
|
|
jQuery.extend( {
|
|
// Unique for each copy of jQuery on the page
|
expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ),
|
|
// Assume jQuery is ready without the ready module
|
isReady: true,
|
|
error: function( msg ) {
|
throw new Error( msg );
|
},
|
|
noop: function() {},
|
|
isFunction: function( obj ) {
|
return jQuery.type( obj ) === "function";
|
},
|
|
isArray: Array.isArray,
|
|
isWindow: function( obj ) {
|
return obj != null && obj === obj.window;
|
},
|
|
isNumeric: function( obj ) {
|
|
// parseFloat NaNs numeric-cast false positives (null|true|false|"")
|
// ...but misinterprets leading-number strings, particularly hex literals ("0x...")
|
// subtraction forces infinities to NaN
|
// adding 1 corrects loss of precision from parseFloat (#15100)
|
var realStringObj = obj && obj.toString();
|
return !jQuery.isArray( obj ) && ( realStringObj - parseFloat( realStringObj ) + 1 ) >= 0;
|
},
|
|
isPlainObject: function( obj ) {
|
var key;
|
|
// Not plain objects:
|
// - Any object or value whose internal [[Class]] property is not "[object Object]"
|
// - DOM nodes
|
// - window
|
if ( jQuery.type( obj ) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
|
return false;
|
}
|
|
// Not own constructor property must be Object
|
if ( obj.constructor &&
|
!hasOwn.call( obj, "constructor" ) &&
|
!hasOwn.call( obj.constructor.prototype || {}, "isPrototypeOf" ) ) {
|
return false;
|
}
|
|
// Own properties are enumerated firstly, so to speed up,
|
// if last one is own, then all properties are own
|
for ( key in obj ) {}
|
|
return key === undefined || hasOwn.call( obj, key );
|
},
|
|
isEmptyObject: function( obj ) {
|
var name;
|
for ( name in obj ) {
|
return false;
|
}
|
return true;
|
},
|
|
type: function( obj ) {
|
if ( obj == null ) {
|
return obj + "";
|
}
|
|
// Support: Android<4.0, iOS<6 (functionish RegExp)
|
return typeof obj === "object" || typeof obj === "function" ?
|
class2type[ toString.call( obj ) ] || "object" :
|
typeof obj;
|
},
|
|
// Evaluates a script in a global context
|
globalEval: function( code ) {
|
var script,
|
indirect = eval;
|
|
code = jQuery.trim( code );
|
|
if ( code ) {
|
|
// If the code includes a valid, prologue position
|
// strict mode pragma, execute code by injecting a
|
// script tag into the document.
|
if ( code.indexOf( "use strict" ) === 1 ) {
|
script = document.createElement( "script" );
|
script.text = code;
|
document.head.appendChild( script ).parentNode.removeChild( script );
|
} else {
|
|
// Otherwise, avoid the DOM node creation, insertion
|
// and removal by using an indirect global eval
|
|
indirect( code );
|
}
|
}
|
},
|
|
// Convert dashed to camelCase; used by the css and data modules
|
// Support: IE9-11+
|
// Microsoft forgot to hump their vendor prefix (#9572)
|
camelCase: function( string ) {
|
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
|
},
|
|
nodeName: function( elem, name ) {
|
return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase();
|
},
|
|
each: function( obj, callback ) {
|
var length, i = 0;
|
|
if ( isArrayLike( obj ) ) {
|
length = obj.length;
|
for ( ; i < length; i++ ) {
|
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
|
break;
|
}
|
}
|
} else {
|
for ( i in obj ) {
|
if ( callback.call( obj[ i ], i, obj[ i ] ) === false ) {
|
break;
|
}
|
}
|
}
|
|
return obj;
|
},
|
|
// Support: Android<4.1
|
trim: function( text ) {
|
return text == null ?
|
"" :
|
( text + "" ).replace( rtrim, "" );
|
},
|
|
// results is for internal usage only
|
makeArray: function( arr, results ) {
|
var ret = results || [];
|
|
if ( arr != null ) {
|
if ( isArrayLike( Object( arr ) ) ) {
|
jQuery.merge( ret,
|
typeof arr === "string" ?
|
[ arr ] : arr
|
);
|
} else {
|
push.call( ret, arr );
|
}
|
}
|
|
return ret;
|
},
|
|
inArray: function( elem, arr, i ) {
|
return arr == null ? -1 : indexOf.call( arr, elem, i );
|
},
|
|
merge: function( first, second ) {
|
var len = +second.length,
|
j = 0,
|
i = first.length;
|
|
for ( ; j < len; j++ ) {
|
first[ i++ ] = second[ j ];
|
}
|
|
first.length = i;
|
|
return first;
|
},
|
|
grep: function( elems, callback, invert ) {
|
var callbackInverse,
|
matches = [],
|
i = 0,
|
length = elems.length,
|
callbackExpect = !invert;
|
|
// Go through the array, only saving the items
|
// that pass the validator function
|
for ( ; i < length; i++ ) {
|
callbackInverse = !callback( elems[ i ], i );
|
if ( callbackInverse !== callbackExpect ) {
|
matches.push( elems[ i ] );
|
}
|
}
|
|
return matches;
|
},
|
|
// arg is for internal usage only
|
map: function( elems, callback, arg ) {
|
var length, value,
|
i = 0,
|
ret = [];
|
|
// Go through the array, translating each of the items to their new values
|
if ( isArrayLike( elems ) ) {
|
length = elems.length;
|
for ( ; i < length; i++ ) {
|
value = callback( elems[ i ], i, arg );
|
|
if ( value != null ) {
|
ret.push( value );
|
}
|
}
|
|
// Go through every key on the object,
|
} else {
|
for ( i in elems ) {
|
value = callback( elems[ i ], i, arg );
|
|
if ( value != null ) {
|
ret.push( value );
|
}
|
}
|
}
|
|
// Flatten any nested arrays
|
return concat.apply( [], ret );
|
},
|
|
// A global GUID counter for objects
|
guid: 1,
|
|
// Bind a function to a context, optionally partially applying any
|
// arguments.
|
proxy: function( fn, context ) {
|
var tmp, args, proxy;
|
|
if ( typeof context === "string" ) {
|
tmp = fn[ context ];
|
context = fn;
|
fn = tmp;
|
}
|
|
// Quick check to determine if target is callable, in the spec
|
// this throws a TypeError, but we will just return undefined.
|
if ( !jQuery.isFunction( fn ) ) {
|
return undefined;
|
}
|
|
// Simulated bind
|
args = slice.call( arguments, 2 );
|
proxy = function() {
|
return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
|
};
|
|
// Set the guid of unique handler to the same of original handler, so it can be removed
|
proxy.guid = fn.guid = fn.guid || jQuery.guid++;
|
|
return proxy;
|
},
|
|
now: Date.now,
|
|
// jQuery.support is not used in Core but other projects attach their
|
// properties to it so it needs to exist.
|
support: support
|
} );
|
|
// JSHint would error on this code due to the Symbol not being defined in ES5.
|
// Defining this global in .jshintrc would create a danger of using the global
|
// unguarded in another place, it seems safer to just disable JSHint for these
|
// three lines.
|
/* jshint ignore: start */
|
if ( typeof Symbol === "function" ) {
|
jQuery.fn[ Symbol.iterator ] = arr[ Symbol.iterator ];
|
}
|
/* jshint ignore: end */
|
|
// Populate the class2type map
|
jQuery.each( "Boolean Number String Function Array Date RegExp Object Error Symbol".split( " " ),
|
function( i, name ) {
|
class2type[ "[object " + name + "]" ] = name.toLowerCase();
|
} );
|
|
function isArrayLike( obj ) {
|
|
// Support: iOS 8.2 (not reproducible in simulator)
|
// `in` check used to prevent JIT error (gh-2145)
|
// hasOwn isn't used here due to false negatives
|
// regarding Nodelist length in IE
|
var length = !!obj && "length" in obj && obj.length,
|
type = jQuery.type( obj );
|
|
if ( type === "function" || jQuery.isWindow( obj ) ) {
|
return false;
|
}
|
|
return type === "array" || length === 0 ||
|
typeof length === "number" && length > 0 && ( length - 1 ) in obj;
|
}
|
var Sizzle =
|
/*!
|
* Sizzle CSS Selector Engine v2.2.1
|
* http://sizzlejs.com/
|
*
|
* Copyright jQuery Foundation and other contributors
|
* Released under the MIT license
|
* http://jquery.org/license
|
*
|
* Date: 2015-10-17
|
*/
|
(function( window ) {
|
|
var i,
|
support,
|
Expr,
|
getText,
|
isXML,
|
tokenize,
|
compile,
|
select,
|
outermostContext,
|
sortInput,
|
hasDuplicate,
|
|
// Local document vars
|
setDocument,
|
document,
|
docElem,
|
documentIsHTML,
|
rbuggyQSA,
|
rbuggyMatches,
|
matches,
|
contains,
|
|
// Instance-specific data
|
expando = "sizzle" + 1 * new Date(),
|
preferredDoc = window.document,
|
dirruns = 0,
|
done = 0,
|
classCache = createCache(),
|
tokenCache = createCache(),
|
compilerCache = createCache(),
|
sortOrder = function( a, b ) {
|
if ( a === b ) {
|
hasDuplicate = true;
|
}
|
return 0;
|
},
|
|
// General-purpose constants
|
MAX_NEGATIVE = 1 << 31,
|
|
// Instance methods
|
hasOwn = ({}).hasOwnProperty,
|
arr = [],
|
pop = arr.pop,
|
push_native = arr.push,
|
push = arr.push,
|
slice = arr.slice,
|
// Use a stripped-down indexOf as it's faster than native
|
// http://jsperf.com/thor-indexof-vs-for/5
|
indexOf = function( list, elem ) {
|
var i = 0,
|
len = list.length;
|
for ( ; i < len; i++ ) {
|
if ( list[i] === elem ) {
|
return i;
|
}
|
}
|
return -1;
|
},
|
|
booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",
|
|
// Regular expressions
|
|
// http://www.w3.org/TR/css3-selectors/#whitespace
|
whitespace = "[\\x20\\t\\r\\n\\f]",
|
|
// http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
|
identifier = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",
|
|
// Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors
|
attributes = "\\[" + whitespace + "*(" + identifier + ")(?:" + whitespace +
|
// Operator (capture 2)
|
"*([*^$|!~]?=)" + whitespace +
|
// "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]"
|
"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace +
|
"*\\]",
|
|
pseudos = ":(" + identifier + ")(?:\\((" +
|
// To reduce the number of selectors needing tokenize in the preFilter, prefer arguments:
|
// 1. quoted (capture 3; capture 4 or capture 5)
|
"('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" +
|
// 2. simple (capture 6)
|
"((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" +
|
// 3. anything else (capture 2)
|
".*" +
|
")\\)|)",
|
|
// Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter
|
rwhitespace = new RegExp( whitespace + "+", "g" ),
|
rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ),
|
|
rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ),
|
rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ),
|
|
rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ),
|
|
rpseudo = new RegExp( pseudos ),
|
ridentifier = new RegExp( "^" + identifier + "$" ),
|
|
matchExpr = {
|
"ID": new RegExp( "^#(" + identifier + ")" ),
|
"CLASS": new RegExp( "^\\.(" + identifier + ")" ),
|
"TAG": new RegExp( "^(" + identifier + "|[*])" ),
|
"ATTR": new RegExp( "^" + attributes ),
|
"PSEUDO": new RegExp( "^" + pseudos ),
|
"CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace +
|
"*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace +
|
"*(\\d+)|))" + whitespace + "*\\)|)", "i" ),
|
"bool": new RegExp( "^(?:" + booleans + ")$", "i" ),
|
// For use in libraries implementing .is()
|
// We use this for POS matching in `select`
|
"needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" +
|
whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" )
|
},
|
|
rinputs = /^(?:input|select|textarea|button)$/i,
|
rheader = /^h\d$/i,
|
|
rnative = /^[^{]+\{\s*\[native \w/,
|
|
// Easily-parseable/retrievable ID or TAG or CLASS selectors
|
rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,
|
|
rsibling = /[+~]/,
|
rescape = /'|\\/g,
|
|
// CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters
|
runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ),
|
funescape = function( _, escaped, escapedWhitespace ) {
|
var high = "0x" + escaped - 0x10000;
|
// NaN means non-codepoint
|
// Support: Firefox<24
|
// Workaround erroneous numeric interpretation of +"0x"
|
return high !== high || escapedWhitespace ?
|
escaped :
|
high < 0 ?
|
// BMP codepoint
|
String.fromCharCode( high + 0x10000 ) :
|
// Supplemental Plane codepoint (surrogate pair)
|
String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 );
|
},
|
|
// Used for iframes
|
// See setDocument()
|
// Removing the function wrapper causes a "Permission Denied"
|
// error in IE
|
unloadHandler = function() {
|
setDocument();
|
};
|
|
// Optimize for push.apply( _, NodeList )
|
try {
|
push.apply(
|
(arr = slice.call( preferredDoc.childNodes )),
|
preferredDoc.childNodes
|
);
|
// Support: Android<4.0
|
// Detect silently failing push.apply
|
arr[ preferredDoc.childNodes.length ].nodeType;
|
} catch ( e ) {
|
push = { apply: arr.length ?
|
|
// Leverage slice if possible
|
function( target, els ) {
|
push_native.apply( target, slice.call(els) );
|
} :
|
|
// Support: IE<9
|
// Otherwise append directly
|
function( target, els ) {
|
var j = target.length,
|
i = 0;
|
// Can't trust NodeList.length
|
while ( (target[j++] = els[i++]) ) {}
|
target.length = j - 1;
|
}
|
};
|
}
|
|
function Sizzle( selector, context, results, seed ) {
|
var m, i, elem, nid, nidselect, match, groups, newSelector,
|
newContext = context && context.ownerDocument,
|
|
// nodeType defaults to 9, since context defaults to document
|
nodeType = context ? context.nodeType : 9;
|
|
results = results || [];
|
|
// Return early from calls with invalid selector or context
|
if ( typeof selector !== "string" || !selector ||
|
nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) {
|
|
return results;
|
}
|
|
// Try to shortcut find operations (as opposed to filters) in HTML documents
|
if ( !seed ) {
|
|
if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) {
|
setDocument( context );
|
}
|
context = context || document;
|
|
if ( documentIsHTML ) {
|
|
// If the selector is sufficiently simple, try using a "get*By*" DOM method
|
// (excepting DocumentFragment context, where the methods don't exist)
|
if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) {
|
|
// ID selector
|
if ( (m = match[1]) ) {
|
|
// Document context
|
if ( nodeType === 9 ) {
|
if ( (elem = context.getElementById( m )) ) {
|
|
// Support: IE, Opera, Webkit
|
// TODO: identify versions
|
// getElementById can match elements by name instead of ID
|
if ( elem.id === m ) {
|
results.push( elem );
|
return results;
|
}
|
} else {
|
return results;
|
}
|
|
// Element context
|
} else {
|
|
// Support: IE, Opera, Webkit
|
// TODO: identify versions
|
// getElementById can match elements by name instead of ID
|
if ( newContext && (elem = newContext.getElementById( m )) &&
|
contains( context, elem ) &&
|
elem.id === m ) {
|
|
results.push( elem );
|
return results;
|
}
|
}
|
|
// Type selector
|
} else if ( match[2] ) {
|
push.apply( results, context.getElementsByTagName( selector ) );
|
return results;
|
|
// Class selector
|
} else if ( (m = match[3]) && support.getElementsByClassName &&
|
context.getElementsByClassName ) {
|
|
push.apply( results, context.getElementsByClassName( m ) );
|
return results;
|
}
|
}
|
|
// Take advantage of querySelectorAll
|
if ( support.qsa &&
|
!compilerCache[ selector + " " ] &&
|
(!rbuggyQSA || !rbuggyQSA.test( selector )) ) {
|
|
if ( nodeType !== 1 ) {
|
newContext = context;
|
newSelector = selector;
|
|
// qSA looks outside Element context, which is not what we want
|
// Thanks to Andrew Dupont for this workaround technique
|
// Support: IE <=8
|
// Exclude object elements
|
} else if ( context.nodeName.toLowerCase() !== "object" ) {
|
|
// Capture the context ID, setting it first if necessary
|
if ( (nid = context.getAttribute( "id" )) ) {
|
nid = nid.replace( rescape, "\\$&" );
|
} else {
|
context.setAttribute( "id", (nid = expando) );
|
}
|
|
// Prefix every selector in the list
|
groups = tokenize( selector );
|
i = groups.length;
|
nidselect = ridentifier.test( nid ) ? "#" + nid : "[id='" + nid + "']";
|
while ( i-- ) {
|
groups[i] = nidselect + " " + toSelector( groups[i] );
|
}
|
newSelector = groups.join( "," );
|
|
// Expand context for sibling selectors
|
newContext = rsibling.test( selector ) && testContext( context.parentNode ) ||
|
context;
|
}
|
|
if ( newSelector ) {
|
try {
|
push.apply( results,
|
newContext.querySelectorAll( newSelector )
|
);
|
return results;
|
} catch ( qsaError ) {
|
} finally {
|
if ( nid === expando ) {
|
context.removeAttribute( "id" );
|
}
|
}
|
}
|
}
|
}
|
}
|
|
// All others
|
return select( selector.replace( rtrim, "$1" ), context, results, seed );
|
}
|
|
/**
|
* Create key-value caches of limited size
|
* @returns {function(string, object)} Returns the Object data after storing it on itself with
|
* property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength)
|
* deleting the oldest entry
|
*/
|
function createCache() {
|
var keys = [];
|
|
function cache( key, value ) {
|
// Use (key + " ") to avoid collision with native prototype properties (see Issue #157)
|
if ( keys.push( key + " " ) > Expr.cacheLength ) {
|
// Only keep the most recent entries
|
delete cache[ keys.shift() ];
|
}
|
return (cache[ key + " " ] = value);
|
}
|
return cache;
|
}
|
|
/**
|
* Mark a function for special use by Sizzle
|
* @param {Function} fn The function to mark
|
*/
|
function markFunction( fn ) {
|
fn[ expando ] = true;
|
return fn;
|
}
|
|
/**
|
* Support testing using an element
|
* @param {Function} fn Passed the created div and expects a boolean result
|
*/
|
function assert( fn ) {
|
var div = document.createElement("div");
|
|
try {
|
return !!fn( div );
|
} catch (e) {
|
return false;
|
} finally {
|
// Remove from its parent by default
|
if ( div.parentNode ) {
|
div.parentNode.removeChild( div );
|
}
|
// release memory in IE
|
div = null;
|
}
|
}
|
|
/**
|
* Adds the same handler for all of the specified attrs
|
* @param {String} attrs Pipe-separated list of attributes
|
* @param {Function} handler The method that will be applied
|
*/
|
function addHandle( attrs, handler ) {
|
var arr = attrs.split("|"),
|
i = arr.length;
|
|
while ( i-- ) {
|
Expr.attrHandle[ arr[i] ] = handler;
|
}
|
}
|
|
/**
|
* Checks document order of two siblings
|
* @param {Element} a
|
* @param {Element} b
|
* @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b
|
*/
|
function siblingCheck( a, b ) {
|
var cur = b && a,
|
diff = cur && a.nodeType === 1 && b.nodeType === 1 &&
|
( ~b.sourceIndex || MAX_NEGATIVE ) -
|
( ~a.sourceIndex || MAX_NEGATIVE );
|
|
// Use IE sourceIndex if available on both nodes
|
if ( diff ) {
|
return diff;
|
}
|
|
// Check if b follows a
|
if ( cur ) {
|
while ( (cur = cur.nextSibling) ) {
|
if ( cur === b ) {
|
return -1;
|
}
|
}
|
}
|
|
return a ? 1 : -1;
|
}
|
|
/**
|
* Returns a function to use in pseudos for input types
|
* @param {String} type
|
*/
|
function createInputPseudo( type ) {
|
return function( elem ) {
|
var name = elem.nodeName.toLowerCase();
|
return name === "input" && elem.type === type;
|
};
|
}
|
|
/**
|
* Returns a function to use in pseudos for buttons
|
* @param {String} type
|
*/
|
function createButtonPseudo( type ) {
|
return function( elem ) {
|
var name = elem.nodeName.toLowerCase();
|
return (name === "input" || name === "button") && elem.type === type;
|
};
|
}
|
|
/**
|
* Returns a function to use in pseudos for positionals
|
* @param {Function} fn
|
*/
|
function createPositionalPseudo( fn ) {
|
return markFunction(function( argument ) {
|
argument = +argument;
|
return markFunction(function( seed, matches ) {
|
var j,
|
matchIndexes = fn( [], seed.length, argument ),
|
i = matchIndexes.length;
|
|
// Match elements found at the specified indexes
|
while ( i-- ) {
|
if ( seed[ (j = matchIndexes[i]) ] ) {
|
seed[j] = !(matches[j] = seed[j]);
|
}
|
}
|
});
|
});
|
}
|
|
/**
|
* Checks a node for validity as a Sizzle context
|
* @param {Element|Object=} context
|
* @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value
|
*/
|
function testContext( context ) {
|
return context && typeof context.getElementsByTagName !== "undefined" && context;
|
}
|
|
// Expose support vars for convenience
|
support = Sizzle.support = {};
|
|
/**
|
* Detects XML nodes
|
* @param {Element|Object} elem An element or a document
|
* @returns {Boolean} True iff elem is a non-HTML XML node
|
*/
|
isXML = Sizzle.isXML = function( elem ) {
|
// documentElement is verified for cases where it doesn't yet exist
|
// (such as loading iframes in IE - #4833)
|
var documentElement = elem && (elem.ownerDocument || elem).documentElement;
|
return documentElement ? documentElement.nodeName !== "HTML" : false;
|
};
|
|
/**
|
* Sets document-related variables once based on the current document
|
* @param {Element|Object} [doc] An element or document object to use to set the document
|
* @returns {Object} Returns the current document
|
*/
|
setDocument = Sizzle.setDocument = function( node ) {
|
var hasCompare, parent,
|
doc = node ? node.ownerDocument || node : preferredDoc;
|
|
// Return early if doc is invalid or already selected
|
if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) {
|
return document;
|
}
|
|
// Update global variables
|
document = doc;
|
docElem = document.documentElement;
|
documentIsHTML = !isXML( document );
|
|
// Support: IE 9-11, Edge
|
// Accessing iframe documents after unload throws "permission denied" errors (jQuery #13936)
|
if ( (parent = document.defaultView) && parent.top !== parent ) {
|
// Support: IE 11
|
if ( parent.addEventListener ) {
|
parent.addEventListener( "unload", unloadHandler, false );
|
|
// Support: IE 9 - 10 only
|
} else if ( parent.attachEvent ) {
|
parent.attachEvent( "onunload", unloadHandler );
|
}
|
}
|
|
/* Attributes
|
---------------------------------------------------------------------- */
|
|
// Support: IE<8
|
// Verify that getAttribute really returns attributes and not properties
|
// (excepting IE8 booleans)
|
support.attributes = assert(function( div ) {
|
div.className = "i";
|
return !div.getAttribute("className");
|
});
|
|
/* getElement(s)By*
|
---------------------------------------------------------------------- */
|
|
// Check if getElementsByTagName("*") returns only elements
|
support.getElementsByTagName = assert(function( div ) {
|
div.appendChild( document.createComment("") );
|
return !div.getElementsByTagName("*").length;
|
});
|
|
// Support: IE<9
|
support.getElementsByClassName = rnative.test( document.getElementsByClassName );
|
|
// Support: IE<10
|
// Check if getElementById returns elements by name
|
// The broken getElementById methods don't pick up programatically-set names,
|
// so use a roundabout getElementsByName test
|
support.getById = assert(function( div ) {
|
docElem.appendChild( div ).id = expando;
|
return !document.getElementsByName || !document.getElementsByName( expando ).length;
|
});
|
|
// ID find and filter
|
if ( support.getById ) {
|
Expr.find["ID"] = function( id, context ) {
|
if ( typeof context.getElementById !== "undefined" && documentIsHTML ) {
|
var m = context.getElementById( id );
|
return m ? [ m ] : [];
|
}
|
};
|
Expr.filter["ID"] = function( id ) {
|
var attrId = id.replace( runescape, funescape );
|
return function( elem ) {
|
return elem.getAttribute("id") === attrId;
|
};
|
};
|
} else {
|
// Support: IE6/7
|
// getElementById is not reliable as a find shortcut
|
delete Expr.find["ID"];
|
|
Expr.filter["ID"] = function( id ) {
|
var attrId = id.replace( runescape, funescape );
|
return function( elem ) {
|
var node = typeof elem.getAttributeNode !== "undefined" &&
|
elem.getAttributeNode("id");
|
return node && node.value === attrId;
|
};
|
};
|
}
|
|
// Tag
|
Expr.find["TAG"] = support.getElementsByTagName ?
|
function( tag, context ) {
|
if ( typeof context.getElementsByTagName !== "undefined" ) {
|
return context.getElementsByTagName( tag );
|
|
// DocumentFragment nodes don't have gEBTN
|
} else if ( support.qsa ) {
|
return context.querySelectorAll( tag );
|
}
|
} :
|
|
function( tag, context ) {
|
var elem,
|
tmp = [],
|
i = 0,
|
// By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too
|
results = context.getElementsByTagName( tag );
|
|
// Filter out possible comments
|
if ( tag === "*" ) {
|
while ( (elem = results[i++]) ) {
|
if ( elem.nodeType === 1 ) {
|
tmp.push( elem );
|
}
|
}
|
|
return tmp;
|
}
|
return results;
|
};
|
|
// Class
|
Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) {
|
if ( typeof context.getElementsByClassName !== "undefined" && documentIsHTML ) {
|
return context.getElementsByClassName( className );
|
}
|
};
|
|
/* QSA/matchesSelector
|
---------------------------------------------------------------------- */
|
|
// QSA and matchesSelector support
|
|
// matchesSelector(:active) reports false when true (IE9/Opera 11.5)
|
rbuggyMatches = [];
|
|
// qSa(:focus) reports false when true (Chrome 21)
|
// We allow this because of a bug in IE8/9 that throws an error
|
// whenever `document.activeElement` is accessed on an iframe
|
// So, we allow :focus to pass through QSA all the time to avoid the IE error
|
// See http://bugs.jquery.com/ticket/13378
|
rbuggyQSA = [];
|
|
if ( (support.qsa = rnative.test( document.querySelectorAll )) ) {
|
// Build QSA regex
|
// Regex strategy adopted from Diego Perini
|
assert(function( div ) {
|
// Select is set to empty string on purpose
|
// This is to test IE's treatment of not explicitly
|
// setting a boolean content attribute,
|
// since its presence should be enough
|
// http://bugs.jquery.com/ticket/12359
|
docElem.appendChild( div ).innerHTML = "<a id='" + expando + "'></a>" +
|
"<select id='" + expando + "-\r\\' msallowcapture=''>" +
|
"<option selected=''></option></select>";
|
|
// Support: IE8, Opera 11-12.16
|
// Nothing should be selected when empty strings follow ^= or $= or *=
|
// The test attribute must be unknown in Opera but "safe" for WinRT
|
// http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section
|
if ( div.querySelectorAll("[msallowcapture^='']").length ) {
|
rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" );
|
}
|
|
// Support: IE8
|
// Boolean attributes and "value" are not treated correctly
|
if ( !div.querySelectorAll("[selected]").length ) {
|
rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" );
|
}
|
|
// Support: Chrome<29, Android<4.4, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.8+
|
if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) {
|
rbuggyQSA.push("~=");
|
}
|
|
// Webkit/Opera - :checked should return selected option elements
|
// http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
|
// IE8 throws error here and will not see later tests
|
if ( !div.querySelectorAll(":checked").length ) {
|
rbuggyQSA.push(":checked");
|
}
|
|
// Support: Safari 8+, iOS 8+
|
// https://bugs.webkit.org/show_bug.cgi?id=136851
|
// In-page `selector#id sibing-combinator selector` fails
|
if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) {
|
rbuggyQSA.push(".#.+[+~]");
|
}
|
});
|
|
assert(function( div ) {
|
// Support: Windows 8 Native Apps
|
// The type and name attributes are restricted during .innerHTML assignment
|
var input = document.createElement("input");
|
input.setAttribute( "type", "hidden" );
|
div.appendChild( input ).setAttribute( "name", "D" );
|
|
// Support: IE8
|
// Enforce case-sensitivity of name attribute
|
if ( div.querySelectorAll("[name=d]").length ) {
|
rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" );
|
}
|
|
// FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled)
|
// IE8 throws error here and will not see later tests
|
if ( !div.querySelectorAll(":enabled").length ) {
|
rbuggyQSA.push( ":enabled", ":disabled" );
|
}
|
|
// Opera 10-11 does not throw on post-comma invalid pseudos
|
div.querySelectorAll("*,:x");
|
rbuggyQSA.push(",.*:");
|
});
|
}
|
|
if ( (support.matchesSelector = rnative.test( (matches = docElem.matches ||
|
docElem.webkitMatchesSelector ||
|
docElem.mozMatchesSelector ||
|
docElem.oMatchesSelector ||
|
docElem.msMatchesSelector) )) ) {
|
|
assert(function( div ) {
|
// Check to see if it's possible to do matchesSelector
|
// on a disconnected node (IE 9)
|
support.disconnectedMatch = matches.call( div, "div" );
|
|
// This should fail with an exception
|
// Gecko does not error, returns false instead
|
matches.call( div, "[s!='']:x" );
|
rbuggyMatches.push( "!=", pseudos );
|
});
|
}
|
|
rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") );
|
rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") );
|
|
/* Contains
|
---------------------------------------------------------------------- */
|
hasCompare = rnative.test( docElem.compareDocumentPosition );
|
|
// Element contains another
|
// Purposefully self-exclusive
|
// As in, an element does not contain itself
|
contains = hasCompare || rnative.test( docElem.contains ) ?
|
function( a, b ) {
|
var adown = a.nodeType === 9 ? a.documentElement : a,
|
bup = b && b.parentNode;
|
return a === bup || !!( bup && bup.nodeType === 1 && (
|
adown.contains ?
|
adown.contains( bup ) :
|
a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16
|
));
|
} :
|
function( a, b ) {
|
if ( b ) {
|
while ( (b = b.parentNode) ) {
|
if ( b === a ) {
|
return true;
|
}
|
}
|
}
|
return false;
|
};
|
|
/* Sorting
|
---------------------------------------------------------------------- */
|
|
// Document order sorting
|
sortOrder = hasCompare ?
|
function( a, b ) {
|
|
// Flag for duplicate removal
|
if ( a === b ) {
|
hasDuplicate = true;
|
return 0;
|
}
|
|
// Sort on method existence if only one input has compareDocumentPosition
|
var compare = !a.compareDocumentPosition - !b.compareDocumentPosition;
|
if ( compare ) {
|
return compare;
|
}
|
|
// Calculate position if both inputs belong to the same document
|
compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ?
|
a.compareDocumentPosition( b ) :
|
|
// Otherwise we know they are disconnected
|
1;
|
|
// Disconnected nodes
|
if ( compare & 1 ||
|
(!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) {
|
|
// Choose the first element that is related to our preferred document
|
if ( a === document || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) {
|
return -1;
|
}
|
if ( b === document || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) {
|
return 1;
|
}
|
|
// Maintain original order
|
return sortInput ?
|
( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
|
0;
|
}
|
|
return compare & 4 ? -1 : 1;
|
} :
|
function( a, b ) {
|
// Exit early if the nodes are identical
|
if ( a === b ) {
|
hasDuplicate = true;
|
return 0;
|
}
|
|
var cur,
|
i = 0,
|
aup = a.parentNode,
|
bup = b.parentNode,
|
ap = [ a ],
|
bp = [ b ];
|
|
// Parentless nodes are either documents or disconnected
|
if ( !aup || !bup ) {
|
return a === document ? -1 :
|
b === document ? 1 :
|
aup ? -1 :
|
bup ? 1 :
|
sortInput ?
|
( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) :
|
0;
|
|
// If the nodes are siblings, we can do a quick check
|
} else if ( aup === bup ) {
|
return siblingCheck( a, b );
|
}
|
|
// Otherwise we need full lists of their ancestors for comparison
|
cur = a;
|
while ( (cur = cur.parentNode) ) {
|
ap.unshift( cur );
|
}
|
cur = b;
|
while ( (cur = cur.parentNode) ) {
|
bp.unshift( cur );
|
}
|
|
// Walk down the tree looking for a discrepancy
|
while ( ap[i] === bp[i] ) {
|
i++;
|
}
|
|
return i ?
|
// Do a sibling check if the nodes have a common ancestor
|
siblingCheck( ap[i], bp[i] ) :
|
|
// Otherwise nodes in our document sort first
|
ap[i] === preferredDoc ? -1 :
|
bp[i] === preferredDoc ? 1 :
|
0;
|
};
|
|
return document;
|
};
|
|
Sizzle.matches = function( expr, elements ) {
|
return Sizzle( expr, null, null, elements );
|
};
|
|
Sizzle.matchesSelector = function( elem, expr ) {
|
// Set document vars if needed
|
if ( ( elem.ownerDocument || elem ) !== document ) {
|
setDocument( elem );
|
}
|
|
// Make sure that attribute selectors are quoted
|
expr = expr.replace( rattributeQuotes, "='$1']" );
|
|
if ( support.matchesSelector && documentIsHTML &&
|
!compilerCache[ expr + " " ] &&
|
( !rbuggyMatches || !rbuggyMatches.test( expr ) ) &&
|
( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) {
|
|
try {
|
var ret = matches.call( elem, expr );
|
|
// IE 9's matchesSelector returns false on disconnected nodes
|
if ( ret || support.disconnectedMatch ||
|
// As well, disconnected nodes are said to be in a document
|
// fragment in IE 9
|
elem.document && elem.document.nodeType !== 11 ) {
|
return ret;
|
}
|
} catch (e) {}
|
}
|
|
return Sizzle( expr, document, null, [ elem ] ).length > 0;
|
};
|
|
Sizzle.contains = function( context, elem ) {
|
// Set document vars if needed
|
if ( ( context.ownerDocument || context ) !== document ) {
|
setDocument( context );
|
}
|
return contains( context, elem );
|
};
|
|
Sizzle.attr = function( elem, name ) {
|
// Set document vars if needed
|
if ( ( elem.ownerDocument || elem ) !== document ) {
|
setDocument( elem );
|
}
|
|
var fn = Expr.attrHandle[ name.toLowerCase() ],
|
// Don't get fooled by Object.prototype properties (jQuery #13807)
|
val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ?
|
fn( elem, name, !documentIsHTML ) :
|
undefined;
|
|
return val !== undefined ?
|
val :
|
support.attributes || !documentIsHTML ?
|
elem.getAttribute( name ) :
|
(val = elem.getAttributeNode(name)) && val.specified ?
|
val.value :
|
null;
|
};
|
|
Sizzle.error = function( msg ) {
|
throw new Error( "Syntax error, unrecognized expression: " + msg );
|
};
|
|
/**
|
* Document sorting and removing duplicates
|
* @param {ArrayLike} results
|
*/
|
Sizzle.uniqueSort = function( results ) {
|
var elem,
|
duplicates = [],
|
j = 0,
|
i = 0;
|
|
// Unless we *know* we can detect duplicates, assume their presence
|
hasDuplicate = !support.detectDuplicates;
|
sortInput = !support.sortStable && results.slice( 0 );
|
results.sort( sortOrder );
|
|
if ( hasDuplicate ) {
|
while ( (elem = results[i++]) ) {
|
if ( elem === results[ i ] ) {
|
j = duplicates.push( i );
|
}
|
}
|
while ( j-- ) {
|
results.splice( duplicates[ j ], 1 );
|
}
|
}
|
|
// Clear input after sorting to release objects
|
// See https://github.com/jquery/sizzle/pull/225
|
sortInput = null;
|
|
return results;
|
};
|
|
/**
|
* Utility function for retrieving the text value of an array of DOM nodes
|
* @param {Array|Element} elem
|
*/
|
getText = Sizzle.getText = function( elem ) {
|
var node,
|
ret = "",
|
i = 0,
|
nodeType = elem.nodeType;
|
|
if ( !nodeType ) {
|
// If no nodeType, this is expected to be an array
|
while ( (node = elem[i++]) ) {
|
// Do not traverse comment nodes
|
ret += getText( node );
|
}
|
} else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) {
|
// Use textContent for elements
|
// innerText usage removed for consistency of new lines (jQuery #11153)
|
if ( typeof elem.textContent === "string" ) {
|
return elem.textContent;
|
} else {
|
// Traverse its children
|
for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
|
ret += getText( elem );
|
}
|
}
|
} else if ( nodeType === 3 || nodeType === 4 ) {
|
return elem.nodeValue;
|
}
|
// Do not include comment or processing instruction nodes
|
|
return ret;
|
};
|
|
Expr = Sizzle.selectors = {
|
|
// Can be adjusted by the user
|
cacheLength: 50,
|
|
createPseudo: markFunction,
|
|
match: matchExpr,
|
|
attrHandle: {},
|
|
find: {},
|
|
relative: {
|
">": { dir: "parentNode", first: true },
|
" ": { dir: "parentNode" },
|
"+": { dir: "previousSibling", first: true },
|
"~": { dir: "previousSibling" }
|
},
|
|
preFilter: {
|
"ATTR": function( match ) {
|
match[1] = match[1].replace( runescape, funescape );
|
|
// Move the given value to match[3] whether quoted or unquoted
|
match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape );
|
|
if ( match[2] === "~=" ) {
|
match[3] = " " + match[3] + " ";
|
}
|
|
return match.slice( 0, 4 );
|
},
|
|
"CHILD": function( match ) {
|
/* matches from matchExpr["CHILD"]
|
1 type (only|nth|...)
|
2 what (child|of-type)
|
3 argument (even|odd|\d*|\d*n([+-]\d+)?|...)
|
4 xn-component of xn+y argument ([+-]?\d*n|)
|
5 sign of xn-component
|
6 x of xn-component
|
7 sign of y-component
|
8 y of y-component
|
*/
|
match[1] = match[1].toLowerCase();
|
|
if ( match[1].slice( 0, 3 ) === "nth" ) {
|
// nth-* requires argument
|
if ( !match[3] ) {
|
Sizzle.error( match[0] );
|
}
|
|
// numeric x and y parameters for Expr.filter.CHILD
|
// remember that false/true cast respectively to 0/1
|
match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) );
|
match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" );
|
|
// other types prohibit arguments
|
} else if ( match[3] ) {
|
Sizzle.error( match[0] );
|
}
|
|
return match;
|
},
|
|
"PSEUDO": function( match ) {
|
var excess,
|
unquoted = !match[6] && match[2];
|
|
if ( matchExpr["CHILD"].test( match[0] ) ) {
|
return null;
|
}
|
|
// Accept quoted arguments as-is
|
if ( match[3] ) {
|
match[2] = match[4] || match[5] || "";
|
|
// Strip excess characters from unquoted arguments
|
} else if ( unquoted && rpseudo.test( unquoted ) &&
|
// Get excess from tokenize (recursively)
|
(excess = tokenize( unquoted, true )) &&
|
// advance to the next closing parenthesis
|
(excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) {
|
|
// excess is a negative index
|
match[0] = match[0].slice( 0, excess );
|
match[2] = unquoted.slice( 0, excess );
|
}
|
|
// Return only captures needed by the pseudo filter method (type and argument)
|
return match.slice( 0, 3 );
|
}
|
},
|
|
filter: {
|
|
"TAG": function( nodeNameSelector ) {
|
var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase();
|
return nodeNameSelector === "*" ?
|
function() { return true; } :
|
function( elem ) {
|
return elem.nodeName && elem.nodeName.toLowerCase() === nodeName;
|
};
|
},
|
|
"CLASS": function( className ) {
|
var pattern = classCache[ className + " " ];
|
|
return pattern ||
|
(pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) &&
|
classCache( className, function( elem ) {
|
return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" );
|
});
|
},
|
|
"ATTR": function( name, operator, check ) {
|
return function( elem ) {
|
var result = Sizzle.attr( elem, name );
|
|
if ( result == null ) {
|
return operator === "!=";
|
}
|
if ( !operator ) {
|
return true;
|
}
|
|
result += "";
|
|
return operator === "=" ? result === check :
|
operator === "!=" ? result !== check :
|
operator === "^=" ? check && result.indexOf( check ) === 0 :
|
operator === "*=" ? check && result.indexOf( check ) > -1 :
|
operator === "$=" ? check && result.slice( -check.length ) === check :
|
operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 :
|
operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" :
|
false;
|
};
|
},
|
|
"CHILD": function( type, what, argument, first, last ) {
|
var simple = type.slice( 0, 3 ) !== "nth",
|
forward = type.slice( -4 ) !== "last",
|
ofType = what === "of-type";
|
|
return first === 1 && last === 0 ?
|
|
// Shortcut for :nth-*(n)
|
function( elem ) {
|
return !!elem.parentNode;
|
} :
|
|
function( elem, context, xml ) {
|
var cache, uniqueCache, outerCache, node, nodeIndex, start,
|
dir = simple !== forward ? "nextSibling" : "previousSibling",
|
parent = elem.parentNode,
|
name = ofType && elem.nodeName.toLowerCase(),
|
useCache = !xml && !ofType,
|
diff = false;
|
|
if ( parent ) {
|
|
// :(first|last|only)-(child|of-type)
|
if ( simple ) {
|
while ( dir ) {
|
node = elem;
|
while ( (node = node[ dir ]) ) {
|
if ( ofType ?
|
node.nodeName.toLowerCase() === name :
|
node.nodeType === 1 ) {
|
|
return false;
|
}
|
}
|
// Reverse direction for :only-* (if we haven't yet done so)
|
start = dir = type === "only" && !start && "nextSibling";
|
}
|
return true;
|
}
|
|
start = [ forward ? parent.firstChild : parent.lastChild ];
|
|
// non-xml :nth-child(...) stores cache data on `parent`
|
if ( forward && useCache ) {
|
|
// Seek `elem` from a previously-cached index
|
|
// ...in a gzip-friendly way
|
node = parent;
|
outerCache = node[ expando ] || (node[ expando ] = {});
|
|
// Support: IE <9 only
|
// Defend against cloned attroperties (jQuery gh-1709)
|
uniqueCache = outerCache[ node.uniqueID ] ||
|
(outerCache[ node.uniqueID ] = {});
|
|
cache = uniqueCache[ type ] || [];
|
nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
|
diff = nodeIndex && cache[ 2 ];
|
node = nodeIndex && parent.childNodes[ nodeIndex ];
|
|
while ( (node = ++nodeIndex && node && node[ dir ] ||
|
|
// Fallback to seeking `elem` from the start
|
(diff = nodeIndex = 0) || start.pop()) ) {
|
|
// When found, cache indexes on `parent` and break
|
if ( node.nodeType === 1 && ++diff && node === elem ) {
|
uniqueCache[ type ] = [ dirruns, nodeIndex, diff ];
|
break;
|
}
|
}
|
|
} else {
|
// Use previously-cached element index if available
|
if ( useCache ) {
|
// ...in a gzip-friendly way
|
node = elem;
|
outerCache = node[ expando ] || (node[ expando ] = {});
|
|
// Support: IE <9 only
|
// Defend against cloned attroperties (jQuery gh-1709)
|
uniqueCache = outerCache[ node.uniqueID ] ||
|
(outerCache[ node.uniqueID ] = {});
|
|
cache = uniqueCache[ type ] || [];
|
nodeIndex = cache[ 0 ] === dirruns && cache[ 1 ];
|
diff = nodeIndex;
|
}
|
|
// xml :nth-child(...)
|
// or :nth-last-child(...) or :nth(-last)?-of-type(...)
|
if ( diff === false ) {
|
// Use the same loop as above to seek `elem` from the start
|
while ( (node = ++nodeIndex && node && node[ dir ] ||
|
(diff = nodeIndex = 0) || start.pop()) ) {
|
|
if ( ( ofType ?
|
node.nodeName.toLowerCase() === name :
|
node.nodeType === 1 ) &&
|
++diff ) {
|
|
// Cache the index of each encountered element
|
if ( useCache ) {
|
outerCache = node[ expando ] || (node[ expando ] = {});
|
|
// Support: IE <9 only
|
// Defend against cloned attroperties (jQuery gh-1709)
|
uniqueCache = outerCache[ node.uniqueID ] ||
|
(outerCache[ node.uniqueID ] = {});
|
|
uniqueCache[ type ] = [ dirruns, diff ];
|
}
|
|
if ( node === elem ) {
|
break;
|
}
|
}
|
}
|
}
|
}
|
|
// Incorporate the offset, then check against cycle size
|
diff -= last;
|
return diff === first || ( diff % first === 0 && diff / first >= 0 );
|
}
|
};
|
},
|
|
"PSEUDO": function( pseudo, argument ) {
|
// pseudo-class names are case-insensitive
|
// http://www.w3.org/TR/selectors/#pseudo-classes
|
// Prioritize by case sensitivity in case custom pseudos are added with uppercase letters
|
// Remember that setFilters inherits from pseudos
|
var args,
|
fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] ||
|
Sizzle.error( "unsupported pseudo: " + pseudo );
|
|
// The user may use createPseudo to indicate that
|
// arguments are needed to create the filter function
|
// just as Sizzle does
|
if ( fn[ expando ] ) {
|
return fn( argument );
|
}
|
|
// But maintain support for old signatures
|
if ( fn.length > 1 ) {
|
args = [ pseudo, pseudo, "", argument ];
|
return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ?
|
markFunction(function( seed, matches ) {
|
var idx,
|
matched = fn( seed, argument ),
|
i = matched.length;
|
while ( i-- ) {
|
idx = indexOf( seed, matched[i] );
|
seed[ idx ] = !( matches[ idx ] = matched[i] );
|
}
|
}) :
|
function( elem ) {
|
return fn( elem, 0, args );
|
};
|
}
|
|
return fn;
|
}
|
},
|
|
pseudos: {
|
// Potentially complex pseudos
|
"not": markFunction(function( selector ) {
|
// Trim the selector passed to compile
|
// to avoid treating leading and trailing
|
// spaces as combinators
|
var input = [],
|
results = [],
|
matcher = compile( selector.replace( rtrim, "$1" ) );
|
|
return matcher[ expando ] ?
|
markFunction(function( seed, matches, context, xml ) {
|
var elem,
|
unmatched = matcher( seed, null, xml, [] ),
|
i = seed.length;
|
|
// Match elements unmatched by `matcher`
|
while ( i-- ) {
|
if ( (elem = unmatched[i]) ) {
|
seed[i] = !(matches[i] = elem);
|
}
|
}
|
}) :
|
function( elem, context, xml ) {
|
input[0] = elem;
|
matcher( input, null, xml, results );
|
// Don't keep the element (issue #299)
|
input[0] = null;
|
return !results.pop();
|
};
|
}),
|
|
"has": markFunction(function( selector ) {
|
return function( elem ) {
|
return Sizzle( selector, elem ).length > 0;
|
};
|
}),
|
|
"contains": markFunction(function( text ) {
|
text = text.replace( runescape, funescape );
|
return function( elem ) {
|
return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1;
|
};
|
}),
|
|
// "Whether an element is represented by a :lang() selector
|
// is based solely on the element's language value
|
// being equal to the identifier C,
|
// or beginning with the identifier C immediately followed by "-".
|
// The matching of C against the element's language value is performed case-insensitively.
|
// The identifier C does not have to be a valid language name."
|
// http://www.w3.org/TR/selectors/#lang-pseudo
|
"lang": markFunction( function( lang ) {
|
// lang value must be a valid identifier
|
if ( !ridentifier.test(lang || "") ) {
|
Sizzle.error( "unsupported lang: " + lang );
|
}
|
lang = lang.replace( runescape, funescape ).toLowerCase();
|
return function( elem ) {
|
var elemLang;
|
do {
|
if ( (elemLang = documentIsHTML ?
|
elem.lang :
|
elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) {
|
|
elemLang = elemLang.toLowerCase();
|
return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0;
|
}
|
} while ( (elem = elem.parentNode) && elem.nodeType === 1 );
|
return false;
|
};
|
}),
|
|
// Miscellaneous
|
"target": function( elem ) {
|
var hash = window.location && window.location.hash;
|
return hash && hash.slice( 1 ) === elem.id;
|
},
|
|
"root": function( elem ) {
|
return elem === docElem;
|
},
|
|
"focus": function( elem ) {
|
return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex);
|
},
|
|
// Boolean properties
|
"enabled": function( elem ) {
|
return elem.disabled === false;
|
},
|
|
"disabled": function( elem ) {
|
return elem.disabled === true;
|
},
|
|
"checked": function( elem ) {
|
// In CSS3, :checked should return both checked and selected elements
|
// http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked
|
var nodeName = elem.nodeName.toLowerCase();
|
return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected);
|
},
|
|
"selected": function( elem ) {
|
// Accessing this property makes selected-by-default
|
// options in Safari work properly
|
if ( elem.parentNode ) {
|
elem.parentNode.selectedIndex;
|
}
|
|
return elem.selected === true;
|
},
|
|
// Contents
|
"empty": function( elem ) {
|
// http://www.w3.org/TR/selectors/#empty-pseudo
|
// :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5),
|
// but not by others (comment: 8; processing instruction: 7; etc.)
|
// nodeType < 6 works because attributes (2) do not appear as children
|
for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) {
|
if ( elem.nodeType < 6 ) {
|
return false;
|
}
|
}
|
return true;
|
},
|
|
"parent": function( elem ) {
|
return !Expr.pseudos["empty"]( elem );
|
},
|
|
// Element/input types
|
"header": function( elem ) {
|
return rheader.test( elem.nodeName );
|
},
|
|
"input": function( elem ) {
|
return rinputs.test( elem.nodeName );
|
},
|
|
"button": function( elem ) {
|
var name = elem.nodeName.toLowerCase();
|
return name === "input" && elem.type === "button" || name === "button";
|
},
|
|
"text": function( elem ) {
|
var attr;
|
return elem.nodeName.toLowerCase() === "input" &&
|
elem.type === "text" &&
|
|
// Support: IE<8
|
// New HTML5 attribute values (e.g., "search") appear with elem.type === "text"
|
( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" );
|
},
|
|
// Position-in-collection
|
"first": createPositionalPseudo(function() {
|
return [ 0 ];
|
}),
|
|
"last": createPositionalPseudo(function( matchIndexes, length ) {
|
return [ length - 1 ];
|
}),
|
|
"eq": createPositionalPseudo(function( matchIndexes, length, argument ) {
|
return [ argument < 0 ? argument + length : argument ];
|
}),
|
|
"even": createPositionalPseudo(function( matchIndexes, length ) {
|
var i = 0;
|
for ( ; i < length; i += 2 ) {
|
matchIndexes.push( i );
|
}
|
return matchIndexes;
|
}),
|
|
"odd": createPositionalPseudo(function( matchIndexes, length ) {
|
var i = 1;
|
for ( ; i < length; i += 2 ) {
|
matchIndexes.push( i );
|
}
|
return matchIndexes;
|
}),
|
|
"lt": createPositionalPseudo(function( matchIndexes, length, argument ) {
|
var i = argument < 0 ? argument + length : argument;
|
for ( ; --i >= 0; ) {
|
matchIndexes.push( i );
|
}
|
return matchIndexes;
|
}),
|
|
"gt": createPositionalPseudo(function( matchIndexes, length, argument ) {
|
var i = argument < 0 ? argument + length : argument;
|
for ( ; ++i < length; ) {
|
matchIndexes.push( i );
|
}
|
return matchIndexes;
|
})
|
}
|
};
|
|
Expr.pseudos["nth"] = Expr.pseudos["eq"];
|
|
// Add button/input type pseudos
|
for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) {
|
Expr.pseudos[ i ] = createInputPseudo( i );
|
}
|
for ( i in { submit: true, reset: true } ) {
|
Expr.pseudos[ i ] = createButtonPseudo( i );
|
}
|
|
// Easy API for creating new setFilters
|
function setFilters() {}
|
setFilters.prototype = Expr.filters = Expr.pseudos;
|
Expr.setFilters = new setFilters();
|
|
tokenize = Sizzle.tokenize = function( selector, parseOnly ) {
|
var matched, match, tokens, type,
|
soFar, groups, preFilters,
|
cached = tokenCache[ selector + " " ];
|
|
if ( cached ) {
|
return parseOnly ? 0 : cached.slice( 0 );
|
}
|
|
soFar = selector;
|
groups = [];
|
preFilters = Expr.preFilter;
|
|
while ( soFar ) {
|
|
// Comma and first run
|
if ( !matched || (match = rcomma.exec( soFar )) ) {
|
if ( match ) {
|
// Don't consume trailing commas as valid
|
soFar = soFar.slice( match[0].length ) || soFar;
|
}
|
groups.push( (tokens = []) );
|
}
|
|
matched = false;
|
|
// Combinators
|
if ( (match = rcombinators.exec( soFar )) ) {
|
matched = match.shift();
|
tokens.push({
|
value: matched,
|
// Cast descendant combinators to space
|
type: match[0].replace( rtrim, " " )
|
});
|
soFar = soFar.slice( matched.length );
|
}
|
|
// Filters
|
for ( type in Expr.filter ) {
|
if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] ||
|
(match = preFilters[ type ]( match ))) ) {
|
matched = match.shift();
|
tokens.push({
|
value: matched,
|
type: type,
|
matches: match
|
});
|
soFar = soFar.slice( matched.length );
|
}
|
}
|
|
if ( !matched ) {
|
break;
|
}
|
}
|
|
// Return the length of the invalid excess
|
// if we're just parsing
|
// Otherwise, throw an error or return tokens
|
return parseOnly ?
|
soFar.length :
|
soFar ?
|
Sizzle.error( selector ) :
|
// Cache the tokens
|
tokenCache( selector, groups ).slice( 0 );
|
};
|
|
function toSelector( tokens ) {
|
var i = 0,
|
len = tokens.length,
|
selector = "";
|
for ( ; i < len; i++ ) {
|
selector += tokens[i].value;
|
}
|
return selector;
|
}
|
|
function addCombinator( matcher, combinator, base ) {
|
var dir = combinator.dir,
|
checkNonElements = base && dir === "parentNode",
|
doneName = done++;
|
|
return combinator.first ?
|
// Check against closest ancestor/preceding element
|
function( elem, context, xml ) {
|
while ( (elem = elem[ dir ]) ) {
|
if ( elem.nodeType === 1 || checkNonElements ) {
|
return matcher( elem, context, xml );
|
}
|
}
|
} :
|
|
// Check against all ancestor/preceding elements
|
function( elem, context, xml ) {
|
var oldCache, uniqueCache, outerCache,
|
newCache = [ dirruns, doneName ];
|
|
// We can't set arbitrary data on XML nodes, so they don't benefit from combinator caching
|
if ( xml ) {
|
while ( (elem = elem[ dir ]) ) {
|
if ( elem.nodeType === 1 || checkNonElements ) {
|
if ( matcher( elem, context, xml ) ) {
|
return true;
|
}
|
}
|
}
|
} else {
|
while ( (elem = elem[ dir ]) ) {
|
if ( elem.nodeType === 1 || checkNonElements ) {
|
outerCache = elem[ expando ] || (elem[ expando ] = {});
|
|
// Support: IE <9 only
|
// Defend against cloned attroperties (jQuery gh-1709)
|
uniqueCache = outerCache[ elem.uniqueID ] || (outerCache[ elem.uniqueID ] = {});
|
|
if ( (oldCache = uniqueCache[ dir ]) &&
|
oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) {
|
|
// Assign to newCache so results back-propagate to previous elements
|
return (newCache[ 2 ] = oldCache[ 2 ]);
|
} else {
|
// Reuse newcache so results back-propagate to previous elements
|
uniqueCache[ dir ] = newCache;
|
|
// A match means we're done; a fail means we have to keep checking
|
if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) {
|
return true;
|
}
|
}
|
}
|
}
|
}
|
};
|
}
|
|
function elementMatcher( matchers ) {
|
return matchers.length > 1 ?
|
function( elem, context, xml ) {
|
var i = matchers.length;
|
while ( i-- ) {
|
if ( !matchers[i]( elem, context, xml ) ) {
|
return false;
|
}
|
}
|
return true;
|
} :
|
matchers[0];
|
}
|
|
function multipleContexts( selector, contexts, results ) {
|
var i = 0,
|
len = contexts.length;
|
for ( ; i < len; i++ ) {
|
Sizzle( selector, contexts[i], results );
|
}
|
return results;
|
}
|
|
function condense( unmatched, map, filter, context, xml ) {
|
var elem,
|
newUnmatched = [],
|
i = 0,
|
len = unmatched.length,
|
mapped = map != null;
|
|
for ( ; i < len; i++ ) {
|
if ( (elem = unmatched[i]) ) {
|
if ( !filter || filter( elem, context, xml ) ) {
|
newUnmatched.push( elem );
|
if ( mapped ) {
|
map.push( i );
|
}
|
}
|
}
|
}
|
|
return newUnmatched;
|
}
|
|
function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) {
|
if ( postFilter && !postFilter[ expando ] ) {
|
postFilter = setMatcher( postFilter );
|
}
|
if ( postFinder && !postFinder[ expando ] ) {
|
postFinder = setMatcher( postFinder, postSelector );
|
}
|
return markFunction(function( seed, results, context, xml ) {
|
var temp, i, elem,
|
preMap = [],
|
postMap = [],
|
preexisting = results.length,
|
|
// Get initial elements from seed or context
|
elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ),
|
|
// Prefilter to get matcher input, preserving a map for seed-results synchronization
|
matcherIn = preFilter && ( seed || !selector ) ?
|
condense( elems, preMap, preFilter, context, xml ) :
|
elems,
|
|
matcherOut = matcher ?
|
// If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results,
|
postFinder || ( seed ? preFilter : preexisting || postFilter ) ?
|
|
// ...intermediate processing is necessary
|
[] :
|
|
// ...otherwise use results directly
|
results :
|
matcherIn;
|
|
// Find primary matches
|
if ( matcher ) {
|
matcher( matcherIn, matcherOut, context, xml );
|
}
|
|
// Apply postFilter
|
if ( postFilter ) {
|
temp = condense( matcherOut, postMap );
|
postFilter( temp, [], context, xml );
|
|
// Un-match failing elements by moving them back to matcherIn
|
i = temp.length;
|
while ( i-- ) {
|
if ( (elem = temp[i]) ) {
|
matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem);
|
}
|
}
|
}
|
|
if ( seed ) {
|
if ( postFinder || preFilter ) {
|
if ( postFinder ) {
|
// Get the final matcherOut by condensing this intermediate into postFinder contexts
|
temp = [];
|
i = matcherOut.length;
|
while ( i-- ) {
|
if ( (elem = matcherOut[i]) ) {
|
// Restore matcherIn since elem is not yet a final match
|
temp.push( (matcherIn[i] = elem) );
|
}
|
}
|
postFinder( null, (matcherOut = []), temp, xml );
|
}
|
|
// Move matched elements from seed to results to keep them synchronized
|
i = matcherOut.length;
|
while ( i-- ) {
|
if ( (elem = matcherOut[i]) &&
|
(temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) {
|
|
seed[temp] = !(results[temp] = elem);
|
}
|
}
|
}
|
|
// Add elements to results, through postFinder if defined
|
} else {
|
matcherOut = condense(
|
matcherOut === results ?
|
matcherOut.splice( preexisting, matcherOut.length ) :
|
matcherOut
|
);
|
if ( postFinder ) {
|
postFinder( null, results, matcherOut, xml );
|
} else {
|
push.apply( results, matcherOut );
|
}
|
}
|
});
|
}
|
|
function matcherFromTokens( tokens ) {
|
var checkContext, matcher, j,
|
len = tokens.length,
|
leadingRelative = Expr.relative[ tokens[0].type ],
|
implicitRelative = leadingRelative || Expr.relative[" "],
|
i = leadingRelative ? 1 : 0,
|
|
// The foundational matcher ensures that elements are reachable from top-level context(s)
|
matchContext = addCombinator( function( elem ) {
|
return elem === checkContext;
|
}, implicitRelative, true ),
|
matchAnyContext = addCombinator( function( elem ) {
|
return indexOf( checkContext, elem ) > -1;
|
}, implicitRelative, true ),
|
matchers = [ function( elem, context, xml ) {
|
var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || (
|
(checkContext = context).nodeType ?
|
matchContext( elem, context, xml ) :
|
matchAnyContext( elem, context, xml ) );
|
// Avoid hanging onto element (issue #299)
|
checkContext = null;
|
return ret;
|
} ];
|
|
for ( ; i < len; i++ ) {
|
if ( (matcher = Expr.relative[ tokens[i].type ]) ) {
|
matchers = [ addCombinator(elementMatcher( matchers ), matcher) ];
|
} else {
|
matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches );
|
|
// Return special upon seeing a positional matcher
|
if ( matcher[ expando ] ) {
|
// Find the next relative operator (if any) for proper handling
|
j = ++i;
|
for ( ; j < len; j++ ) {
|
if ( Expr.relative[ tokens[j].type ] ) {
|
break;
|
}
|
}
|
return setMatcher(
|
i > 1 && elementMatcher( matchers ),
|
i > 1 && toSelector(
|
// If the preceding token was a descendant combinator, insert an implicit any-element `*`
|
tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" })
|
).replace( rtrim, "$1" ),
|
matcher,
|
i < j && matcherFromTokens( tokens.slice( i, j ) ),
|
j < len && matcherFromTokens( (tokens = tokens.slice( j )) ),
|
j < len && toSelector( tokens )
|
);
|
}
|
matchers.push( matcher );
|
}
|
}
|
|
return elementMatcher( matchers );
|
}
|
|
function matcherFromGroupMatchers( elementMatchers, setMatchers ) {
|
var bySet = setMatchers.length > 0,
|
byElement = elementMatchers.length > 0,
|
superMatcher = function( seed, context, xml, results, outermost ) {
|
var elem, j, matcher,
|
matchedCount = 0,
|
i = "0",
|
unmatched = seed && [],
|
setMatched = [],
|
contextBackup = outermostContext,
|
// We must always have either seed elements or outermost context
|
elems = seed || byElement && Expr.find["TAG"]( "*", outermost ),
|
// Use integer dirruns iff this is the outermost matcher
|
dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1),
|
len = elems.length;
|
|
if ( outermost ) {
|
outermostContext = context === document || context || outermost;
|
}
|
|
// Add elements passing elementMatchers directly to results
|
// Support: IE<9, Safari
|
// Tolerate NodeList properties (IE: "length"; Safari: <number>) matching elements by id
|
for ( ; i !== len && (elem = elems[i]) != null; i++ ) {
|
if ( byElement && elem ) {
|
j = 0;
|
if ( !context && elem.ownerDocument !== document ) {
|
setDocument( elem );
|
xml = !documentIsHTML;
|
}
|
while ( (matcher = elementMatchers[j++]) ) {
|
if ( matcher( elem, context || document, xml) ) {
|
results.push( elem );
|
break;
|
}
|
}
|
if ( outermost ) {
|
dirruns = dirrunsUnique;
|
}
|
}
|
|
// Track unmatched elements for set filters
|
if ( bySet ) {
|
// They will have gone through all possible matchers
|
if ( (elem = !matcher && elem) ) {
|
matchedCount--;
|
}
|
|
// Lengthen the array for every element, matched or not
|
if ( seed ) {
|
unmatched.push( elem );
|
}
|
}
|
}
|
|
// `i` is now the count of elements visited above, and adding it to `matchedCount`
|
// makes the latter nonnegative.
|
matchedCount += i;
|
|
// Apply set filters to unmatched elements
|
// NOTE: This can be skipped if there are no unmatched elements (i.e., `matchedCount`
|
// equals `i`), unless we didn't visit _any_ elements in the above loop because we have
|
// no element matchers and no seed.
|
// Incrementing an initially-string "0" `i` allows `i` to remain a string only in that
|
// case, which will result in a "00" `matchedCount` that differs from `i` but is also
|
// numerically zero.
|
if ( bySet && i !== matchedCount ) {
|
j = 0;
|
while ( (matcher = setMatchers[j++]) ) {
|
matcher( unmatched, setMatched, context, xml );
|
}
|
|
if ( seed ) {
|
// Reintegrate element matches to eliminate the need for sorting
|
if ( matchedCount > 0 ) {
|
while ( i-- ) {
|
if ( !(unmatched[i] || setMatched[i]) ) {
|
setMatched[i] = pop.call( results );
|
}
|
}
|
}
|
|
// Discard index placeholder values to get only actual matches
|
setMatched = condense( setMatched );
|
}
|
|
// Add matches to results
|
push.apply( results, setMatched );
|
|
// Seedless set matches succeeding multiple successful matchers stipulate sorting
|
if ( outermost && !seed && setMatched.length > 0 &&
|
( matchedCount + setMatchers.length ) > 1 ) {
|
|
Sizzle.uniqueSort( results );
|
}
|
}
|
|
// Override manipulation of globals by nested matchers
|
if ( outermost ) {
|
dirruns = dirrunsUnique;
|
outermostContext = contextBackup;
|
}
|
|
return unmatched;
|
};
|
|
return bySet ?
|
markFunction( superMatcher ) :
|
superMatcher;
|
}
|
|
compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) {
|
var i,
|
setMatchers = [],
|
elementMatchers = [],
|
cached = compilerCache[ selector + " " ];
|
|
if ( !cached ) {
|
// Generate a function of recursive functions that can be used to check each element
|
if ( !match ) {
|
match = tokenize( selector );
|
}
|
i = match.length;
|
while ( i-- ) {
|
cached = matcherFromTokens( match[i] );
|
if ( cached[ expando ] ) {
|
setMatchers.push( cached );
|
} else {
|
elementMatchers.push( cached );
|
}
|
}
|
|
// Cache the compiled function
|
cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) );
|
|
// Save selector and tokenization
|
cached.selector = selector;
|
}
|
return cached;
|
};
|
|
/**
|
* A low-level selection function that works with Sizzle's compiled
|
* selector functions
|
* @param {String|Function} selector A selector or a pre-compiled
|
* selector function built with Sizzle.compile
|
* @param {Element} context
|
* @param {Array} [results]
|
* @param {Array} [seed] A set of elements to match against
|
*/
|
select = Sizzle.select = function( selector, context, results, seed ) {
|
var i, tokens, token, type, find,
|
compiled = typeof selector === "function" && selector,
|
match = !seed && tokenize( (selector = compiled.selector || selector) );
|
|
results = results || [];
|
|
// Try to minimize operations if there is only one selector in the list and no seed
|
// (the latter of which guarantees us context)
|
if ( match.length === 1 ) {
|
|
// Reduce context if the leading compound selector is an ID
|
tokens = match[0] = match[0].slice( 0 );
|
if ( tokens.length > 2 && (token = tokens[0]).type === "ID" &&
|
support.getById && context.nodeType === 9 && documentIsHTML &&
|
Expr.relative[ tokens[1].type ] ) {
|
|
context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0];
|
if ( !context ) {
|
return results;
|
|
// Precompiled matchers will still verify ancestry, so step up a level
|
} else if ( compiled ) {
|
context = context.parentNode;
|
}
|
|
selector = selector.slice( tokens.shift().value.length );
|
}
|
|
// Fetch a seed set for right-to-left matching
|
i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length;
|
while ( i-- ) {
|
token = tokens[i];
|
|
// Abort if we hit a combinator
|
if ( Expr.relative[ (type = token.type) ] ) {
|
break;
|
}
|
if ( (find = Expr.find[ type ]) ) {
|
// Search, expanding context for leading sibling combinators
|
if ( (seed = find(
|
token.matches[0].replace( runescape, funescape ),
|
rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context
|
)) ) {
|
|
// If seed is empty or no tokens remain, we can return early
|
tokens.splice( i, 1 );
|
selector = seed.length && toSelector( tokens );
|
if ( !selector ) {
|
push.apply( results, seed );
|
return results;
|
}
|
|
break;
|
}
|
}
|
}
|
}
|
|
// Compile and execute a filtering function if one is not provided
|
// Provide `match` to avoid retokenization if we modified the selector above
|
( compiled || compile( selector, match ) )(
|
seed,
|
context,
|
!documentIsHTML,
|
results,
|
!context || rsibling.test( selector ) && testContext( context.parentNode ) || context
|
);
|
return results;
|
};
|
|
// One-time assignments
|
|
// Sort stability
|
support.sortStable = expando.split("").sort( sortOrder ).join("") === expando;
|
|
// Support: Chrome 14-35+
|
// Always assume duplicates if they aren't passed to the comparison function
|
support.detectDuplicates = !!hasDuplicate;
|
|
// Initialize against the default document
|
setDocument();
|
|
// Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27)
|
// Detached nodes confoundingly follow *each other*
|
support.sortDetached = assert(function( div1 ) {
|
// Should return 1, but returns 4 (following)
|
return div1.compareDocumentPosition( document.createElement("div") ) & 1;
|
});
|
|
// Support: IE<8
|
// Prevent attribute/property "interpolation"
|
// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx
|
if ( !assert(function( div ) {
|
div.innerHTML = "<a href='#'></a>";
|
return div.firstChild.getAttribute("href") === "#" ;
|
}) ) {
|
addHandle( "type|href|height|width", function( elem, name, isXML ) {
|
if ( !isXML ) {
|
return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 );
|
}
|
});
|
}
|
|
// Support: IE<9
|
// Use defaultValue in place of getAttribute("value")
|
if ( !support.attributes || !assert(function( div ) {
|
div.innerHTML = "<input/>";
|
div.firstChild.setAttribute( "value", "" );
|
return div.firstChild.getAttribute( "value" ) === "";
|
}) ) {
|
addHandle( "value", function( elem, name, isXML ) {
|
if ( !isXML && elem.nodeName.toLowerCase() === "input" ) {
|
return elem.defaultValue;
|
}
|
});
|
}
|
|
// Support: IE<9
|
// Use getAttributeNode to fetch booleans when getAttribute lies
|
if ( !assert(function( div ) {
|
return div.getAttribute("disabled") == null;
|
}) ) {
|
addHandle( booleans, function( elem, name, isXML ) {
|
var val;
|
if ( !isXML ) {
|
return elem[ name ] === true ? name.toLowerCase() :
|
(val = elem.getAttributeNode( name )) && val.specified ?
|
val.value :
|
null;
|
}
|
});
|
}
|
|
return Sizzle;
|
|
})( window );
|
|
|
|
jQuery.find = Sizzle;
|
jQuery.expr = Sizzle.selectors;
|
jQuery.expr[ ":" ] = jQuery.expr.pseudos;
|
jQuery.uniqueSort = jQuery.unique = Sizzle.uniqueSort;
|
jQuery.text = Sizzle.getText;
|
jQuery.isXMLDoc = Sizzle.isXML;
|
jQuery.contains = Sizzle.contains;
|
|
|
|
var dir = function( elem, dir, until ) {
|
var matched = [],
|
truncate = until !== undefined;
|
|
while ( ( elem = elem[ dir ] ) && elem.nodeType !== 9 ) {
|
if ( elem.nodeType === 1 ) {
|
if ( truncate && jQuery( elem ).is( until ) ) {
|
break;
|
}
|
matched.push( elem );
|
}
|
}
|
return matched;
|
};
|
|
|
var siblings = function( n, elem ) {
|
var matched = [];
|
|
for ( ; n; n = n.nextSibling ) {
|
if ( n.nodeType === 1 && n !== elem ) {
|
matched.push( n );
|
}
|
}
|
|
return matched;
|
};
|
|
|
var rneedsContext = jQuery.expr.match.needsContext;
|
|
var rsingleTag = ( /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/ );
|
|
|
|
var risSimple = /^.[^:#\[\.,]*$/;
|
|
// Implement the identical functionality for filter and not
|
function winnow( elements, qualifier, not ) {
|
if ( jQuery.isFunction( qualifier ) ) {
|
return jQuery.grep( elements, function( elem, i ) {
|
/* jshint -W018 */
|
return !!qualifier.call( elem, i, elem ) !== not;
|
} );
|
|
}
|
|
if ( qualifier.nodeType ) {
|
return jQuery.grep( elements, function( elem ) {
|
return ( elem === qualifier ) !== not;
|
} );
|
|
}
|
|
if ( typeof qualifier === "string" ) {
|
if ( risSimple.test( qualifier ) ) {
|
return jQuery.filter( qualifier, elements, not );
|
}
|
|
qualifier = jQuery.filter( qualifier, elements );
|
}
|
|
return jQuery.grep( elements, function( elem ) {
|
return ( indexOf.call( qualifier, elem ) > -1 ) !== not;
|
} );
|
}
|
|
jQuery.filter = function( expr, elems, not ) {
|
var elem = elems[ 0 ];
|
|
if ( not ) {
|
expr = ":not(" + expr + ")";
|
}
|
|
return elems.length === 1 && elem.nodeType === 1 ?
|
jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
|
jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
|
return elem.nodeType === 1;
|
} ) );
|
};
|
|
jQuery.fn.extend( {
|
find: function( selector ) {
|
var i,
|
len = this.length,
|
ret = [],
|
self = this;
|
|
if ( typeof selector !== "string" ) {
|
return this.pushStack( jQuery( selector ).filter( function() {
|
for ( i = 0; i < len; i++ ) {
|
if ( jQuery.contains( self[ i ], this ) ) {
|
return true;
|
}
|
}
|
} ) );
|
}
|
|
for ( i = 0; i < len; i++ ) {
|
jQuery.find( selector, self[ i ], ret );
|
}
|
|
// Needed because $( selector, context ) becomes $( context ).find( selector )
|
ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret );
|
ret.selector = this.selector ? this.selector + " " + selector : selector;
|
return ret;
|
},
|
filter: function( selector ) {
|
return this.pushStack( winnow( this, selector || [], false ) );
|
},
|
not: function( selector ) {
|
return this.pushStack( winnow( this, selector || [], true ) );
|
},
|
is: function( selector ) {
|
return !!winnow(
|
this,
|
|
// If this is a positional/relative selector, check membership in the returned set
|
// so $("p:first").is("p:last") won't return true for a doc with two "p".
|
typeof selector === "string" && rneedsContext.test( selector ) ?
|
jQuery( selector ) :
|
selector || [],
|
false
|
).length;
|
}
|
} );
|
|
|
// Initialize a jQuery object
|
|
|
// A central reference to the root jQuery(document)
|
var rootjQuery,
|
|
// A simple way to check for HTML strings
|
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
|
// Strict HTML recognition (#11290: must start with <)
|
rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,
|
|
init = jQuery.fn.init = function( selector, context, root ) {
|
var match, elem;
|
|
// HANDLE: $(""), $(null), $(undefined), $(false)
|
if ( !selector ) {
|
return this;
|
}
|
|
// Method init() accepts an alternate rootjQuery
|
// so migrate can support jQuery.sub (gh-2101)
|
root = root || rootjQuery;
|
|
// Handle HTML strings
|
if ( typeof selector === "string" ) {
|
if ( selector[ 0 ] === "<" &&
|
selector[ selector.length - 1 ] === ">" &&
|
selector.length >= 3 ) {
|
|
// Assume that strings that start and end with <> are HTML and skip the regex check
|
match = [ null, selector, null ];
|
|
} else {
|
match = rquickExpr.exec( selector );
|
}
|
|
// Match html or make sure no context is specified for #id
|
if ( match && ( match[ 1 ] || !context ) ) {
|
|
// HANDLE: $(html) -> $(array)
|
if ( match[ 1 ] ) {
|
context = context instanceof jQuery ? context[ 0 ] : context;
|
|
// Option to run scripts is true for back-compat
|
// Intentionally let the error be thrown if parseHTML is not present
|
jQuery.merge( this, jQuery.parseHTML(
|
match[ 1 ],
|
context && context.nodeType ? context.ownerDocument || context : document,
|
true
|
) );
|
|
// HANDLE: $(html, props)
|
if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
|
for ( match in context ) {
|
|
// Properties of context are called as methods if possible
|
if ( jQuery.isFunction( this[ match ] ) ) {
|
this[ match ]( context[ match ] );
|
|
// ...and otherwise set as attributes
|
} else {
|
this.attr( match, context[ match ] );
|
}
|
}
|
}
|
|
return this;
|
|
// HANDLE: $(#id)
|
} else {
|
elem = document.getElementById( match[ 2 ] );
|
|
// Support: Blackberry 4.6
|
// gEBID returns nodes no longer in the document (#6963)
|
if ( elem && elem.parentNode ) {
|
|
// Inject the element directly into the jQuery object
|
this.length = 1;
|
this[ 0 ] = elem;
|
}
|
|
this.context = document;
|
this.selector = selector;
|
return this;
|
}
|
|
// HANDLE: $(expr, $(...))
|
} else if ( !context || context.jquery ) {
|
return ( context || root ).find( selector );
|
|
// HANDLE: $(expr, context)
|
// (which is just equivalent to: $(context).find(expr)
|
} else {
|
return this.constructor( context ).find( selector );
|
}
|
|
// HANDLE: $(DOMElement)
|
} else if ( selector.nodeType ) {
|
this.context = this[ 0 ] = selector;
|
this.length = 1;
|
return this;
|
|
// HANDLE: $(function)
|
// Shortcut for document ready
|
} else if ( jQuery.isFunction( selector ) ) {
|
return root.ready !== undefined ?
|
root.ready( selector ) :
|
|
// Execute immediately if ready is not present
|
selector( jQuery );
|
}
|
|
if ( selector.selector !== undefined ) {
|
this.selector = selector.selector;
|
this.context = selector.context;
|
}
|
|
return jQuery.makeArray( selector, this );
|
};
|
|
// Give the init function the jQuery prototype for later instantiation
|
init.prototype = jQuery.fn;
|
|
// Initialize central reference
|
rootjQuery = jQuery( document );
|
|
|
var rparentsprev = /^(?:parents|prev(?:Until|All))/,
|
|
// Methods guaranteed to produce a unique set when starting from a unique set
|
guaranteedUnique = {
|
children: true,
|
contents: true,
|
next: true,
|
prev: true
|
};
|
|
jQuery.fn.extend( {
|
has: function( target ) {
|
var targets = jQuery( target, this ),
|
l = targets.length;
|
|
return this.filter( function() {
|
var i = 0;
|
for ( ; i < l; i++ ) {
|
if ( jQuery.contains( this, targets[ i ] ) ) {
|
return true;
|
}
|
}
|
} );
|
},
|
|
closest: function( selectors, context ) {
|
var cur,
|
i = 0,
|
l = this.length,
|
matched = [],
|
pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ?
|
jQuery( selectors, context || this.context ) :
|
0;
|
|
for ( ; i < l; i++ ) {
|
for ( cur = this[ i ]; cur && cur !== context; cur = cur.parentNode ) {
|
|
// Always skip document fragments
|
if ( cur.nodeType < 11 && ( pos ?
|
pos.index( cur ) > -1 :
|
|
// Don't pass non-elements to Sizzle
|
cur.nodeType === 1 &&
|
jQuery.find.matchesSelector( cur, selectors ) ) ) {
|
|
matched.push( cur );
|
break;
|
}
|
}
|
}
|
|
return this.pushStack( matched.length > 1 ? jQuery.uniqueSort( matched ) : matched );
|
},
|
|
// Determine the position of an element within the set
|
index: function( elem ) {
|
|
// No argument, return index in parent
|
if ( !elem ) {
|
return ( this[ 0 ] && this[ 0 ].parentNode ) ? this.first().prevAll().length : -1;
|
}
|
|
// Index in selector
|
if ( typeof elem === "string" ) {
|
return indexOf.call( jQuery( elem ), this[ 0 ] );
|
}
|
|
// Locate the position of the desired element
|
return indexOf.call( this,
|
|
// If it receives a jQuery object, the first element is used
|
elem.jquery ? elem[ 0 ] : elem
|
);
|
},
|
|
add: function( selector, context ) {
|
return this.pushStack(
|
jQuery.uniqueSort(
|
jQuery.merge( this.get(), jQuery( selector, context ) )
|
)
|
);
|
},
|
|
addBack: function( selector ) {
|
return this.add( selector == null ?
|
this.prevObject : this.prevObject.filter( selector )
|
);
|
}
|
} );
|
|
function sibling( cur, dir ) {
|
while ( ( cur = cur[ dir ] ) && cur.nodeType !== 1 ) {}
|
return cur;
|
}
|
|
jQuery.each( {
|
parent: function( elem ) {
|
var parent = elem.parentNode;
|
return parent && parent.nodeType !== 11 ? parent : null;
|
},
|
parents: function( elem ) {
|
return dir( elem, "parentNode" );
|
},
|
parentsUntil: function( elem, i, until ) {
|
return dir( elem, "parentNode", until );
|
},
|
next: function( elem ) {
|
return sibling( elem, "nextSibling" );
|
},
|
prev: function( elem ) {
|
return sibling( elem, "previousSibling" );
|
},
|
nextAll: function( elem ) {
|
return dir( elem, "nextSibling" );
|
},
|
prevAll: function( elem ) {
|
return dir( elem, "previousSibling" );
|
},
|
nextUntil: function( elem, i, until ) {
|
return dir( elem, "nextSibling", until );
|
},
|
prevUntil: function( elem, i, until ) {
|
return dir( elem, "previousSibling", until );
|
},
|
siblings: function( elem ) {
|
return siblings( ( elem.parentNode || {} ).firstChild, elem );
|
},
|
children: function( elem ) {
|
return siblings( elem.firstChild );
|
},
|
contents: function( elem ) {
|
return elem.contentDocument || jQuery.merge( [], elem.childNodes );
|
}
|
}, function( name, fn ) {
|
jQuery.fn[ name ] = function( until, selector ) {
|
var matched = jQuery.map( this, fn, until );
|
|
if ( name.slice( -5 ) !== "Until" ) {
|
selector = until;
|
}
|
|
if ( selector && typeof selector === "string" ) {
|
matched = jQuery.filter( selector, matched );
|
}
|
|
if ( this.length > 1 ) {
|
|
// Remove duplicates
|
if ( !guaranteedUnique[ name ] ) {
|
jQuery.uniqueSort( matched );
|
}
|
|
// Reverse order for parents* and prev-derivatives
|
if ( rparentsprev.test( name ) ) {
|
matched.reverse();
|
}
|
}
|
|
return this.pushStack( matched );
|
};
|
} );
|
var rnotwhite = ( /\S+/g );
|
|
|
|
// Convert String-formatted options into Object-formatted ones
|
function createOptions( options ) {
|
var object = {};
|
jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) {
|
object[ flag ] = true;
|
} );
|
return object;
|
}
|
|
/*
|
* Create a callback list using the following parameters:
|
*
|
* options: an optional list of space-separated options that will change how
|
* the callback list behaves or a more traditional option object
|
*
|
* By default a callback list will act like an event callback list and can be
|
* "fired" multiple times.
|
*
|
* Possible options:
|
*
|
* once: will ensure the callback list can only be fired once (like a Deferred)
|
*
|
* memory: will keep track of previous values and will call any callback added
|
* after the list has been fired right away with the latest "memorized"
|
* values (like a Deferred)
|
*
|
* unique: will ensure a callback can only be added once (no duplicate in the list)
|
*
|
* stopOnFalse: interrupt callings when a callback returns false
|
*
|
*/
|
jQuery.Callbacks = function( options ) {
|
|
// Convert options from String-formatted to Object-formatted if needed
|
// (we check in cache first)
|
options = typeof options === "string" ?
|
createOptions( options ) :
|
jQuery.extend( {}, options );
|
|
var // Flag to know if list is currently firing
|
firing,
|
|
// Last fire value for non-forgettable lists
|
memory,
|
|
// Flag to know if list was already fired
|
fired,
|
|
// Flag to prevent firing
|
locked,
|
|
// Actual callback list
|
list = [],
|
|
// Queue of execution data for repeatable lists
|
queue = [],
|
|
// Index of currently firing callback (modified by add/remove as needed)
|
firingIndex = -1,
|
|
// Fire callbacks
|
fire = function() {
|
|
// Enforce single-firing
|
locked = options.once;
|
|
// Execute callbacks for all pending executions,
|
// respecting firingIndex overrides and runtime changes
|
fired = firing = true;
|
for ( ; queue.length; firingIndex = -1 ) {
|
memory = queue.shift();
|
while ( ++firingIndex < list.length ) {
|
|
// Run callback and check for early termination
|
if ( list[ firingIndex ].apply( memory[ 0 ], memory[ 1 ] ) === false &&
|
options.stopOnFalse ) {
|
|
// Jump to end and forget the data so .add doesn't re-fire
|
firingIndex = list.length;
|
memory = false;
|
}
|
}
|
}
|
|
// Forget the data if we're done with it
|
if ( !options.memory ) {
|
memory = false;
|
}
|
|
firing = false;
|
|
// Clean up if we're done firing for good
|
if ( locked ) {
|
|
// Keep an empty list if we have data for future add calls
|
if ( memory ) {
|
list = [];
|
|
// Otherwise, this object is spent
|
} else {
|
list = "";
|
}
|
}
|
},
|
|
// Actual Callbacks object
|
self = {
|
|
// Add a callback or a collection of callbacks to the list
|
add: function() {
|
if ( list ) {
|
|
// If we have memory from a past run, we should fire after adding
|
if ( memory && !firing ) {
|
firingIndex = list.length - 1;
|
queue.push( memory );
|
}
|
|
( function add( args ) {
|
jQuery.each( args, function( _, arg ) {
|
if ( jQuery.isFunction( arg ) ) {
|
if ( !options.unique || !self.has( arg ) ) {
|
list.push( arg );
|
}
|
} else if ( arg && arg.length && jQuery.type( arg ) !== "string" ) {
|
|
// Inspect recursively
|
add( arg );
|
}
|
} );
|
} )( arguments );
|
|
if ( memory && !firing ) {
|
fire();
|
}
|
}
|
return this;
|
},
|
|
// Remove a callback from the list
|
remove: function() {
|
jQuery.each( arguments, function( _, arg ) {
|
var index;
|
while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) {
|
list.splice( index, 1 );
|
|
// Handle firing indexes
|
if ( index <= firingIndex ) {
|
firingIndex--;
|
}
|
}
|
} );
|
return this;
|
},
|
|
// Check if a given callback is in the list.
|
// If no argument is given, return whether or not list has callbacks attached.
|
has: function( fn ) {
|
return fn ?
|
jQuery.inArray( fn, list ) > -1 :
|
list.length > 0;
|
},
|
|
// Remove all callbacks from the list
|
empty: function() {
|
if ( list ) {
|
list = [];
|
}
|
return this;
|
},
|
|
// Disable .fire and .add
|
// Abort any current/pending executions
|
// Clear all callbacks and values
|
disable: function() {
|
locked = queue = [];
|
list = memory = "";
|
return this;
|
},
|
disabled: function() {
|
return !list;
|
},
|
|
// Disable .fire
|
// Also disable .add unless we have memory (since it would have no effect)
|
// Abort any pending executions
|
lock: function() {
|
locked = queue = [];
|
if ( !memory ) {
|
list = memory = "";
|
}
|
return this;
|
},
|
locked: function() {
|
return !!locked;
|
},
|
|
// Call all callbacks with the given context and arguments
|
fireWith: function( context, args ) {
|
if ( !locked ) {
|
args = args || [];
|
args = [ context, args.slice ? args.slice() : args ];
|
queue.push( args );
|
if ( !firing ) {
|
fire();
|
}
|
}
|
return this;
|
},
|
|
// Call all the callbacks with the given arguments
|
fire: function() {
|
self.fireWith( this, arguments );
|
return this;
|
},
|
|
// To know if the callbacks have already been called at least once
|
fired: function() {
|
return !!fired;
|
}
|
};
|
|
return self;
|
};
|
|
|
jQuery.extend( {
|
|
Deferred: function( func ) {
|
var tuples = [
|
|
// action, add listener, listener list, final state
|
[ "resolve", "done", jQuery.Callbacks( "once memory" ), "resolved" ],
|
[ "reject", "fail", jQuery.Callbacks( "once memory" ), "rejected" ],
|
[ "notify", "progress", jQuery.Callbacks( "memory" ) ]
|
],
|
state = "pending",
|
promise = {
|
state: function() {
|
return state;
|
},
|
always: function() {
|
deferred.done( arguments ).fail( arguments );
|
return this;
|
},
|
then: function( /* fnDone, fnFail, fnProgress */ ) {
|
var fns = arguments;
|
return jQuery.Deferred( function( newDefer ) {
|
jQuery.each( tuples, function( i, tuple ) {
|
var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
|
|
// deferred[ done | fail | progress ] for forwarding actions to newDefer
|
deferred[ tuple[ 1 ] ]( function() {
|
var returned = fn && fn.apply( this, arguments );
|
if ( returned && jQuery.isFunction( returned.promise ) ) {
|
returned.promise()
|
.progress( newDefer.notify )
|
.done( newDefer.resolve )
|
.fail( newDefer.reject );
|
} else {
|
newDefer[ tuple[ 0 ] + "With" ](
|
this === promise ? newDefer.promise() : this,
|
fn ? [ returned ] : arguments
|
);
|
}
|
} );
|
} );
|
fns = null;
|
} ).promise();
|
},
|
|
// Get a promise for this deferred
|
// If obj is provided, the promise aspect is added to the object
|
promise: function( obj ) {
|
return obj != null ? jQuery.extend( obj, promise ) : promise;
|
}
|
},
|
deferred = {};
|
|
// Keep pipe for back-compat
|
promise.pipe = promise.then;
|
|
// Add list-specific methods
|
jQuery.each( tuples, function( i, tuple ) {
|
var list = tuple[ 2 ],
|
stateString = tuple[ 3 ];
|
|
// promise[ done | fail | progress ] = list.add
|
promise[ tuple[ 1 ] ] = list.add;
|
|
// Handle state
|
if ( stateString ) {
|
list.add( function() {
|
|
// state = [ resolved | rejected ]
|
state = stateString;
|
|
// [ reject_list | resolve_list ].disable; progress_list.lock
|
}, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
|
}
|
|
// deferred[ resolve | reject | notify ]
|
deferred[ tuple[ 0 ] ] = function() {
|
deferred[ tuple[ 0 ] + "With" ]( this === deferred ? promise : this, arguments );
|
return this;
|
};
|
deferred[ tuple[ 0 ] + "With" ] = list.fireWith;
|
} );
|
|
// Make the deferred a promise
|
promise.promise( deferred );
|
|
// Call given func if any
|
if ( func ) {
|
func.call( deferred, deferred );
|
}
|
|
// All done!
|
return deferred;
|
},
|
|
// Deferred helper
|
when: function( subordinate /* , ..., subordinateN */ ) {
|
var i = 0,
|
resolveValues = slice.call( arguments ),
|
length = resolveValues.length,
|
|
// the count of uncompleted subordinates
|
remaining = length !== 1 ||
|
( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0,
|
|
// the master Deferred.
|
// If resolveValues consist of only a single Deferred, just use that.
|
deferred = remaining === 1 ? subordinate : jQuery.Deferred(),
|
|
// Update function for both resolve and progress values
|
updateFunc = function( i, contexts, values ) {
|
return function( value ) {
|
contexts[ i ] = this;
|
values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value;
|
if ( values === progressValues ) {
|
deferred.notifyWith( contexts, values );
|
} else if ( !( --remaining ) ) {
|
deferred.resolveWith( contexts, values );
|
}
|
};
|
},
|
|
progressValues, progressContexts, resolveContexts;
|
|
// Add listeners to Deferred subordinates; treat others as resolved
|
if ( length > 1 ) {
|
progressValues = new Array( length );
|
progressContexts = new Array( length );
|
resolveContexts = new Array( length );
|
for ( ; i < length; i++ ) {
|
if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) {
|
resolveValues[ i ].promise()
|
.progress( updateFunc( i, progressContexts, progressValues ) )
|
.done( updateFunc( i, resolveContexts, resolveValues ) )
|
.fail( deferred.reject );
|
} else {
|
--remaining;
|
}
|
}
|
}
|
|
// If we're not waiting on anything, resolve the master
|
if ( !remaining ) {
|
deferred.resolveWith( resolveContexts, resolveValues );
|
}
|
|
return deferred.promise();
|
}
|
} );
|
|
|
// The deferred used on DOM ready
|
var readyList;
|
|
jQuery.fn.ready = function( fn ) {
|
|
// Add the callback
|
jQuery.ready.promise().done( fn );
|
|
return this;
|
};
|
|
jQuery.extend( {
|
|
// Is the DOM ready to be used? Set to true once it occurs.
|
isReady: false,
|
|
// A counter to track how many items to wait for before
|
// the ready event fires. See #6781
|
readyWait: 1,
|
|
// Hold (or release) the ready event
|
holdReady: function( hold ) {
|
if ( hold ) {
|
jQuery.readyWait++;
|
} else {
|
jQuery.ready( true );
|
}
|
},
|
|
// Handle when the DOM is ready
|
ready: function( wait ) {
|
|
// Abort if there are pending holds or we're already ready
|
if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
|
return;
|
}
|
|
// Remember that the DOM is ready
|
jQuery.isReady = true;
|
|
// If a normal DOM Ready event fired, decrement, and wait if need be
|
if ( wait !== true && --jQuery.readyWait > 0 ) {
|
return;
|
}
|
|
// If there are functions bound, to execute
|
readyList.resolveWith( document, [ jQuery ] );
|
|
// Trigger any bound ready events
|
if ( jQuery.fn.triggerHandler ) {
|
jQuery( document ).triggerHandler( "ready" );
|
jQuery( document ).off( "ready" );
|
}
|
}
|
} );
|
|
/**
|
* The ready event handler and self cleanup method
|
*/
|
function completed() {
|
document.removeEventListener( "DOMContentLoaded", completed );
|
window.removeEventListener( "load", completed );
|
jQuery.ready();
|
}
|
|
jQuery.ready.promise = function( obj ) {
|
if ( !readyList ) {
|
|
readyList = jQuery.Deferred();
|
|
// Catch cases where $(document).ready() is called
|
// after the browser event has already occurred.
|
// Support: IE9-10 only
|
// Older IE sometimes signals "interactive" too soon
|
if ( document.readyState === "complete" ||
|
( document.readyState !== "loading" && !document.documentElement.doScroll ) ) {
|
|
// Handle it asynchronously to allow scripts the opportunity to delay ready
|
window.setTimeout( jQuery.ready );
|
|
} else {
|
|
// Use the handy event callback
|
document.addEventListener( "DOMContentLoaded", completed );
|
|
// A fallback to window.onload, that will always work
|
window.addEventListener( "load", completed );
|
}
|
}
|
return readyList.promise( obj );
|
};
|
|
// Kick off the DOM ready check even if the user does not
|
jQuery.ready.promise();
|
|
|
|
|
// Multifunctional method to get and set values of a collection
|
// The value/s can optionally be executed if it's a function
|
var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
|
var i = 0,
|
len = elems.length,
|
bulk = key == null;
|
|
// Sets many values
|
if ( jQuery.type( key ) === "object" ) {
|
chainable = true;
|
for ( i in key ) {
|
access( elems, fn, i, key[ i ], true, emptyGet, raw );
|
}
|
|
// Sets one value
|
} else if ( value !== undefined ) {
|
chainable = true;
|
|
if ( !jQuery.isFunction( value ) ) {
|
raw = true;
|
}
|
|
if ( bulk ) {
|
|
// Bulk operations run against the entire set
|
if ( raw ) {
|
fn.call( elems, value );
|
fn = null;
|
|
// ...except when executing function values
|
} else {
|
bulk = fn;
|
fn = function( elem, key, value ) {
|
return bulk.call( jQuery( elem ), value );
|
};
|
}
|
}
|
|
if ( fn ) {
|
for ( ; i < len; i++ ) {
|
fn(
|
elems[ i ], key, raw ?
|
value :
|
value.call( elems[ i ], i, fn( elems[ i ], key ) )
|
);
|
}
|
}
|
}
|
|
return chainable ?
|
elems :
|
|
// Gets
|
bulk ?
|
fn.call( elems ) :
|
len ? fn( elems[ 0 ], key ) : emptyGet;
|
};
|
var acceptData = function( owner ) {
|
|
// Accepts only:
|
// - Node
|
// - Node.ELEMENT_NODE
|
// - Node.DOCUMENT_NODE
|
// - Object
|
// - Any
|
/* jshint -W018 */
|
return owner.nodeType === 1 || owner.nodeType === 9 || !( +owner.nodeType );
|
};
|
|
|
|
|
function Data() {
|
this.expando = jQuery.expando + Data.uid++;
|
}
|
|
Data.uid = 1;
|
|
Data.prototype = {
|
|
register: function( owner, initial ) {
|
var value = initial || {};
|
|
// If it is a node unlikely to be stringify-ed or looped over
|
// use plain assignment
|
if ( owner.nodeType ) {
|
owner[ this.expando ] = value;
|
|
// Otherwise secure it in a non-enumerable, non-writable property
|
// configurability must be true to allow the property to be
|
// deleted with the delete operator
|
} else {
|
Object.defineProperty( owner, this.expando, {
|
value: value,
|
writable: true,
|
configurable: true
|
} );
|
}
|
return owner[ this.expando ];
|
},
|
cache: function( owner ) {
|
|
// We can accept data for non-element nodes in modern browsers,
|
// but we should not, see #8335.
|
// Always return an empty object.
|
if ( !acceptData( owner ) ) {
|
return {};
|
}
|
|
// Check if the owner object already has a cache
|
var value = owner[ this.expando ];
|
|
// If not, create one
|
if ( !value ) {
|
value = {};
|
|
// We can accept data for non-element nodes in modern browsers,
|
// but we should not, see #8335.
|
// Always return an empty object.
|
if ( acceptData( owner ) ) {
|
|
// If it is a node unlikely to be stringify-ed or looped over
|
// use plain assignment
|
if ( owner.nodeType ) {
|
owner[ this.expando ] = value;
|
|
// Otherwise secure it in a non-enumerable property
|
// configurable must be true to allow the property to be
|
// deleted when data is removed
|
} else {
|
Object.defineProperty( owner, this.expando, {
|
value: value,
|
configurable: true
|
} );
|
}
|
}
|
}
|
|
return value;
|
},
|
set: function( owner, data, value ) {
|
var prop,
|
cache = this.cache( owner );
|
|
// Handle: [ owner, key, value ] args
|
if ( typeof data === "string" ) {
|
cache[ data ] = value;
|
|
// Handle: [ owner, { properties } ] args
|
} else {
|
|
// Copy the properties one-by-one to the cache object
|
for ( prop in data ) {
|
cache[ prop ] = data[ prop ];
|
}
|
}
|
return cache;
|
},
|
get: function( owner, key ) {
|
return key === undefined ?
|
this.cache( owner ) :
|
owner[ this.expando ] && owner[ this.expando ][ key ];
|
},
|
access: function( owner, key, value ) {
|
var stored;
|
|
// In cases where either:
|
//
|
// 1. No key was specified
|
// 2. A string key was specified, but no value provided
|
//
|
// Take the "read" path and allow the get method to determine
|
// which value to return, respectively either:
|
//
|
// 1. The entire cache object
|
// 2. The data stored at the key
|
//
|
if ( key === undefined ||
|
( ( key && typeof key === "string" ) && value === undefined ) ) {
|
|
stored = this.get( owner, key );
|
|
return stored !== undefined ?
|
stored : this.get( owner, jQuery.camelCase( key ) );
|
}
|
|
// When the key is not a string, or both a key and value
|
// are specified, set or extend (existing objects) with either:
|
//
|
// 1. An object of properties
|
// 2. A key and value
|
//
|
this.set( owner, key, value );
|
|
// Since the "set" path can have two possible entry points
|
// return the expected data based on which path was taken[*]
|
return value !== undefined ? value : key;
|
},
|
remove: function( owner, key ) {
|
var i, name, camel,
|
cache = owner[ this.expando ];
|
|
if ( cache === undefined ) {
|
return;
|
}
|
|
if ( key === undefined ) {
|
this.register( owner );
|
|
} else {
|
|
// Support array or space separated string of keys
|
if ( jQuery.isArray( key ) ) {
|
|
// If "name" is an array of keys...
|
// When data is initially created, via ("key", "val") signature,
|
// keys will be converted to camelCase.
|
// Since there is no way to tell _how_ a key was added, remove
|
// both plain key and camelCase key. #12786
|
// This will only penalize the array argument path.
|
name = key.concat( key.map( jQuery.camelCase ) );
|
} else {
|
camel = jQuery.camelCase( key );
|
|
// Try the string as a key before any manipulation
|
if ( key in cache ) {
|
name = [ key, camel ];
|
} else {
|
|
// If a key with the spaces exists, use it.
|
// Otherwise, create an array by matching non-whitespace
|
name = camel;
|
name = name in cache ?
|
[ name ] : ( name.match( rnotwhite ) || [] );
|
}
|
}
|
|
i = name.length;
|
|
while ( i-- ) {
|
delete cache[ name[ i ] ];
|
}
|
}
|
|
// Remove the expando if there's no more data
|
if ( key === undefined || jQuery.isEmptyObject( cache ) ) {
|
|
// Support: Chrome <= 35-45+
|
// Webkit & Blink performance suffers when deleting properties
|
// from DOM nodes, so set to undefined instead
|
// https://code.google.com/p/chromium/issues/detail?id=378607
|
if ( owner.nodeType ) {
|
owner[ this.expando ] = undefined;
|
} else {
|
delete owner[ this.expando ];
|
}
|
}
|
},
|
hasData: function( owner ) {
|
var cache = owner[ this.expando ];
|
return cache !== undefined && !jQuery.isEmptyObject( cache );
|
}
|
};
|
var dataPriv = new Data();
|
|
var dataUser = new Data();
|
|
|
|
// Implementation Summary
|
//
|
// 1. Enforce API surface and semantic compatibility with 1.9.x branch
|
// 2. Improve the module's maintainability by reducing the storage
|
// paths to a single mechanism.
|
// 3. Use the same single mechanism to support "private" and "user" data.
|
// 4. _Never_ expose "private" data to user code (TODO: Drop _data, _removeData)
|
// 5. Avoid exposing implementation details on user objects (eg. expando properties)
|
// 6. Provide a clear path for implementation upgrade to WeakMap in 2014
|
|
var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,
|
rmultiDash = /[A-Z]/g;
|
|
function dataAttr( elem, key, data ) {
|
var name;
|
|
// If nothing was found internally, try to fetch any
|
// data from the HTML5 data-* attribute
|
if ( data === undefined && elem.nodeType === 1 ) {
|
name = "data-" + key.replace( rmultiDash, "-$&" ).toLowerCase();
|
data = elem.getAttribute( name );
|
|
if ( typeof data === "string" ) {
|
try {
|
data = data === "true" ? true :
|
data === "false" ? false :
|
data === "null" ? null :
|
|
// Only convert to a number if it doesn't change the string
|
+data + "" === data ? +data :
|
rbrace.test( data ) ? jQuery.parseJSON( data ) :
|
data;
|
} catch ( e ) {}
|
|
// Make sure we set the data so it isn't changed later
|
dataUser.set( elem, key, data );
|
} else {
|
data = undefined;
|
}
|
}
|
return data;
|
}
|
|
jQuery.extend( {
|
hasData: function( elem ) {
|
return dataUser.hasData( elem ) || dataPriv.hasData( elem );
|
},
|
|
data: function( elem, name, data ) {
|
return dataUser.access( elem, name, data );
|
},
|
|
removeData: function( elem, name ) {
|
dataUser.remove( elem, name );
|
},
|
|
// TODO: Now that all calls to _data and _removeData have been replaced
|
// with direct calls to dataPriv methods, these can be deprecated.
|
_data: function( elem, name, data ) {
|
return dataPriv.access( elem, name, data );
|
},
|
|
_removeData: function( elem, name ) {
|
dataPriv.remove( elem, name );
|
}
|
} );
|
|
jQuery.fn.extend( {
|
data: function( key, value ) {
|
var i, name, data,
|
elem = this[ 0 ],
|
attrs = elem && elem.attributes;
|
|
// Gets all values
|
if ( key === undefined ) {
|
if ( this.length ) {
|
data = dataUser.get( elem );
|
|
if ( elem.nodeType === 1 && !dataPriv.get( elem, "hasDataAttrs" ) ) {
|
i = attrs.length;
|
while ( i-- ) {
|
|
// Support: IE11+
|
// The attrs elements can be null (#14894)
|
if ( attrs[ i ] ) {
|
name = attrs[ i ].name;
|
if ( name.indexOf( "data-" ) === 0 ) {
|
name = jQuery.camelCase( name.slice( 5 ) );
|
dataAttr( elem, name, data[ name ] );
|
}
|
}
|
}
|
dataPriv.set( elem, "hasDataAttrs", true );
|
}
|
}
|
|
return data;
|
}
|
|
// Sets multiple values
|
if ( typeof key === "object" ) {
|
return this.each( function() {
|
dataUser.set( this, key );
|
} );
|
}
|
|
return access( this, function( value ) {
|
var data, camelKey;
|
|
// The calling jQuery object (element matches) is not empty
|
// (and therefore has an element appears at this[ 0 ]) and the
|
// `value` parameter was not undefined. An empty jQuery object
|
// will result in `undefined` for elem = this[ 0 ] which will
|
// throw an exception if an attempt to read a data cache is made.
|
if ( elem && value === undefined ) {
|
|
// Attempt to get data from the cache
|
// with the key as-is
|
data = dataUser.get( elem, key ) ||
|
|
// Try to find dashed key if it exists (gh-2779)
|
// This is for 2.2.x only
|
dataUser.get( elem, key.replace( rmultiDash, "-$&" ).toLowerCase() );
|
|
if ( data !== undefined ) {
|
return data;
|
}
|
|
camelKey = jQuery.camelCase( key );
|
|
// Attempt to get data from the cache
|
// with the key camelized
|
data = dataUser.get( elem, camelKey );
|
if ( data !== undefined ) {
|
return data;
|
}
|
|
// Attempt to "discover" the data in
|
// HTML5 custom data-* attrs
|
data = dataAttr( elem, camelKey, undefined );
|
if ( data !== undefined ) {
|
return data;
|
}
|
|
// We tried really hard, but the data doesn't exist.
|
return;
|
}
|
|
// Set the data...
|
camelKey = jQuery.camelCase( key );
|
this.each( function() {
|
|
// First, attempt to store a copy or reference of any
|
// data that might've been store with a camelCased key.
|
var data = dataUser.get( this, camelKey );
|
|
// For HTML5 data-* attribute interop, we have to
|
// store property names with dashes in a camelCase form.
|
// This might not apply to all properties...*
|
dataUser.set( this, camelKey, value );
|
|
// *... In the case of properties that might _actually_
|
// have dashes, we need to also store a copy of that
|
// unchanged property.
|
if ( key.indexOf( "-" ) > -1 && data !== undefined ) {
|
dataUser.set( this, key, value );
|
}
|
} );
|
}, null, value, arguments.length > 1, null, true );
|
},
|
|
removeData: function( key ) {
|
return this.each( function() {
|
dataUser.remove( this, key );
|
} );
|
}
|
} );
|
|
|
jQuery.extend( {
|
queue: function( elem, type, data ) {
|
var queue;
|
|
if ( elem ) {
|
type = ( type || "fx" ) + "queue";
|
queue = dataPriv.get( elem, type );
|
|
// Speed up dequeue by getting out quickly if this is just a lookup
|
if ( data ) {
|
if ( !queue || jQuery.isArray( data ) ) {
|
queue = dataPriv.access( elem, type, jQuery.makeArray( data ) );
|
} else {
|
queue.push( data );
|
}
|
}
|
return queue || [];
|
}
|
},
|
|
dequeue: function( elem, type ) {
|
type = type || "fx";
|
|
var queue = jQuery.queue( elem, type ),
|
startLength = queue.length,
|
fn = queue.shift(),
|
hooks = jQuery._queueHooks( elem, type ),
|
next = function() {
|
jQuery.dequeue( elem, type );
|
};
|
|
// If the fx queue is dequeued, always remove the progress sentinel
|
if ( fn === "inprogress" ) {
|
fn = queue.shift();
|
startLength--;
|
}
|
|
if ( fn ) {
|
|
// Add a progress sentinel to prevent the fx queue from being
|
// automatically dequeued
|
if ( type === "fx" ) {
|
queue.unshift( "inprogress" );
|
}
|
|
// Clear up the last queue stop function
|
delete hooks.stop;
|
fn.call( elem, next, hooks );
|
}
|
|
if ( !startLength && hooks ) {
|
hooks.empty.fire();
|
}
|
},
|
|
// Not public - generate a queueHooks object, or return the current one
|
_queueHooks: function( elem, type ) {
|
var key = type + "queueHooks";
|
return dataPriv.get( elem, key ) || dataPriv.access( elem, key, {
|
empty: jQuery.Callbacks( "once memory" ).add( function() {
|
dataPriv.remove( elem, [ type + "queue", key ] );
|
} )
|
} );
|
}
|
} );
|
|
jQuery.fn.extend( {
|
queue: function( type, data ) {
|
var setter = 2;
|
|
if ( typeof type !== "string" ) {
|
data = type;
|
type = "fx";
|
setter--;
|
}
|
|
if ( arguments.length < setter ) {
|
return jQuery.queue( this[ 0 ], type );
|
}
|
|
return data === undefined ?
|
this :
|
this.each( function() {
|
var queue = jQuery.queue( this, type, data );
|
|
// Ensure a hooks for this queue
|
jQuery._queueHooks( this, type );
|
|
if ( type === "fx" && queue[ 0 ] !== "inprogress" ) {
|
jQuery.dequeue( this, type );
|
}
|
} );
|
},
|
dequeue: function( type ) {
|
return this.each( function() {
|
jQuery.dequeue( this, type );
|
} );
|
},
|
clearQueue: function( type ) {
|
return this.queue( type || "fx", [] );
|
},
|
|
// Get a promise resolved when queues of a certain type
|
// are emptied (fx is the type by default)
|
promise: function( type, obj ) {
|
var tmp,
|
count = 1,
|
defer = jQuery.Deferred(),
|
elements = this,
|
i = this.length,
|
resolve = function() {
|
if ( !( --count ) ) {
|
defer.resolveWith( elements, [ elements ] );
|
}
|
};
|
|
if ( typeof type !== "string" ) {
|
obj = type;
|
type = undefined;
|
}
|
type = type || "fx";
|
|
while ( i-- ) {
|
tmp = dataPriv.get( elements[ i ], type + "queueHooks" );
|
if ( tmp && tmp.empty ) {
|
count++;
|
tmp.empty.add( resolve );
|
}
|
}
|
resolve();
|
return defer.promise( obj );
|
}
|
} );
|
var pnum = ( /[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/ ).source;
|
|
var rcssNum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" );
|
|
|
var cssExpand = [ "Top", "Right", "Bottom", "Left" ];
|
|
var isHidden = function( elem, el ) {
|
|
// isHidden might be called from jQuery#filter function;
|
// in that case, element will be second argument
|
elem = el || elem;
|
return jQuery.css( elem, "display" ) === "none" ||
|
!jQuery.contains( elem.ownerDocument, elem );
|
};
|
|
|
|
function adjustCSS( elem, prop, valueParts, tween ) {
|
var adjusted,
|
scale = 1,
|
maxIterations = 20,
|
currentValue = tween ?
|
function() { return tween.cur(); } :
|
function() { return jQuery.css( elem, prop, "" ); },
|
initial = currentValue(),
|
unit = valueParts && valueParts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ),
|
|
// Starting value computation is required for potential unit mismatches
|
initialInUnit = ( jQuery.cssNumber[ prop ] || unit !== "px" && +initial ) &&
|
rcssNum.exec( jQuery.css( elem, prop ) );
|
|
if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
|
|
// Trust units reported by jQuery.css
|
unit = unit || initialInUnit[ 3 ];
|
|
// Make sure we update the tween properties later on
|
valueParts = valueParts || [];
|
|
// Iteratively approximate from a nonzero starting point
|
initialInUnit = +initial || 1;
|
|
do {
|
|
// If previous iteration zeroed out, double until we get *something*.
|
// Use string for doubling so we don't accidentally see scale as unchanged below
|
scale = scale || ".5";
|
|
// Adjust and apply
|
initialInUnit = initialInUnit / scale;
|
jQuery.style( elem, prop, initialInUnit + unit );
|
|
// Update scale, tolerating zero or NaN from tween.cur()
|
// Break the loop if scale is unchanged or perfect, or if we've just had enough.
|
} while (
|
scale !== ( scale = currentValue() / initial ) && scale !== 1 && --maxIterations
|
);
|
}
|
|
if ( valueParts ) {
|
initialInUnit = +initialInUnit || +initial || 0;
|
|
// Apply relative offset (+=/-=) if specified
|
adjusted = valueParts[ 1 ] ?
|
initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
|
+valueParts[ 2 ];
|
if ( tween ) {
|
tween.unit = unit;
|
tween.start = initialInUnit;
|
tween.end = adjusted;
|
}
|
}
|
return adjusted;
|
}
|
var rcheckableType = ( /^(?:checkbox|radio)$/i );
|
|
var rtagName = ( /<([\w:-]+)/ );
|
|
var rscriptType = ( /^$|\/(?:java|ecma)script/i );
|
|
|
|
// We have to close these tags to support XHTML (#13200)
|
var wrapMap = {
|
|
// Support: IE9
|
option: [ 1, "<select multiple='multiple'>", "</select>" ],
|
|
// XHTML parsers do not magically insert elements in the
|
// same way that tag soup parsers do. So we cannot shorten
|
// this by omitting <tbody> or other required elements.
|
thead: [ 1, "<table>", "</table>" ],
|
col: [ 2, "<table><colgroup>", "</colgroup></table>" ],
|
tr: [ 2, "<table><tbody>", "</tbody></table>" ],
|
td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
|
|
_default: [ 0, "", "" ]
|
};
|
|
// Support: IE9
|
wrapMap.optgroup = wrapMap.option;
|
|
wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
|
wrapMap.th = wrapMap.td;
|
|
|
function getAll( context, tag ) {
|
|
// Support: IE9-11+
|
// Use typeof to avoid zero-argument method invocation on host objects (#15151)
|
var ret = typeof context.getElementsByTagName !== "undefined" ?
|
context.getElementsByTagName( tag || "*" ) :
|
typeof context.querySelectorAll !== "undefined" ?
|
context.querySelectorAll( tag || "*" ) :
|
[];
|
|
return tag === undefined || tag && jQuery.nodeName( context, tag ) ?
|
jQuery.merge( [ context ], ret ) :
|
ret;
|
}
|
|
|
// Mark scripts as having already been evaluated
|
function setGlobalEval( elems, refElements ) {
|
var i = 0,
|
l = elems.length;
|
|
for ( ; i < l; i++ ) {
|
dataPriv.set(
|
elems[ i ],
|
"globalEval",
|
!refElements || dataPriv.get( refElements[ i ], "globalEval" )
|
);
|
}
|
}
|
|
|
var rhtml = /<|&#?\w+;/;
|
|
function buildFragment( elems, context, scripts, selection, ignored ) {
|
var elem, tmp, tag, wrap, contains, j,
|
fragment = context.createDocumentFragment(),
|
nodes = [],
|
i = 0,
|
l = elems.length;
|
|
for ( ; i < l; i++ ) {
|
elem = elems[ i ];
|
|
if ( elem || elem === 0 ) {
|
|
// Add nodes directly
|
if ( jQuery.type( elem ) === "object" ) {
|
|
// Support: Android<4.1, PhantomJS<2
|
// push.apply(_, arraylike) throws on ancient WebKit
|
jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );
|
|
// Convert non-html into a text node
|
} else if ( !rhtml.test( elem ) ) {
|
nodes.push( context.createTextNode( elem ) );
|
|
// Convert html into DOM nodes
|
} else {
|
tmp = tmp || fragment.appendChild( context.createElement( "div" ) );
|
|
// Deserialize a standard representation
|
tag = ( rtagName.exec( elem ) || [ "", "" ] )[ 1 ].toLowerCase();
|
wrap = wrapMap[ tag ] || wrapMap._default;
|
tmp.innerHTML = wrap[ 1 ] + jQuery.htmlPrefilter( elem ) + wrap[ 2 ];
|
|
// Descend through wrappers to the right content
|
j = wrap[ 0 ];
|
while ( j-- ) {
|
tmp = tmp.lastChild;
|
}
|
|
// Support: Android<4.1, PhantomJS<2
|
// push.apply(_, arraylike) throws on ancient WebKit
|
jQuery.merge( nodes, tmp.childNodes );
|
|
// Remember the top-level container
|
tmp = fragment.firstChild;
|
|
// Ensure the created nodes are orphaned (#12392)
|
tmp.textContent = "";
|
}
|
}
|
}
|
|
// Remove wrapper from fragment
|
fragment.textContent = "";
|
|
i = 0;
|
while ( ( elem = nodes[ i++ ] ) ) {
|
|
// Skip elements already in the context collection (trac-4087)
|
if ( selection && jQuery.inArray( elem, selection ) > -1 ) {
|
if ( ignored ) {
|
ignored.push( elem );
|
}
|
continue;
|
}
|
|
contains = jQuery.contains( elem.ownerDocument, elem );
|
|
// Append to fragment
|
tmp = getAll( fragment.appendChild( elem ), "script" );
|
|
// Preserve script evaluation history
|
if ( contains ) {
|
setGlobalEval( tmp );
|
}
|
|
// Capture executables
|
if ( scripts ) {
|
j = 0;
|
while ( ( elem = tmp[ j++ ] ) ) {
|
if ( rscriptType.test( elem.type || "" ) ) {
|
scripts.push( elem );
|
}
|
}
|
}
|
}
|
|
return fragment;
|
}
|
|
|
( function() {
|
var fragment = document.createDocumentFragment(),
|
div = fragment.appendChild( document.createElement( "div" ) ),
|
input = document.createElement( "input" );
|
|
// Support: Android 4.0-4.3, Safari<=5.1
|
// Check state lost if the name is set (#11217)
|
// Support: Windows Web Apps (WWA)
|
// `name` and `type` must use .setAttribute for WWA (#14901)
|
input.setAttribute( "type", "radio" );
|
input.setAttribute( "checked", "checked" );
|
input.setAttribute( "name", "t" );
|
|
div.appendChild( input );
|
|
// Support: Safari<=5.1, Android<4.2
|
// Older WebKit doesn't clone checked state correctly in fragments
|
support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked;
|
|
// Support: IE<=11+
|
// Make sure textarea (and checkbox) defaultValue is properly cloned
|
div.innerHTML = "<textarea>x</textarea>";
|
support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue;
|
} )();
|
|
|
var
|
rkeyEvent = /^key/,
|
rmouseEvent = /^(?:mouse|pointer|contextmenu|drag|drop)|click/,
|
rtypenamespace = /^([^.]*)(?:\.(.+)|)/;
|
|
function returnTrue() {
|
return true;
|
}
|
|
function returnFalse() {
|
return false;
|
}
|
|
// Support: IE9
|
// See #13393 for more info
|
function safeActiveElement() {
|
try {
|
return document.activeElement;
|
} catch ( err ) { }
|
}
|
|
function on( elem, types, selector, data, fn, one ) {
|
var origFn, type;
|
|
// Types can be a map of types/handlers
|
if ( typeof types === "object" ) {
|
|
// ( types-Object, selector, data )
|
if ( typeof selector !== "string" ) {
|
|
// ( types-Object, data )
|
data = data || selector;
|
selector = undefined;
|
}
|
for ( type in types ) {
|
on( elem, type, selector, data, types[ type ], one );
|
}
|
return elem;
|
}
|
|
if ( data == null && fn == null ) {
|
|
// ( types, fn )
|
fn = selector;
|
data = selector = undefined;
|
} else if ( fn == null ) {
|
if ( typeof selector === "string" ) {
|
|
// ( types, selector, fn )
|
fn = data;
|
data = undefined;
|
} else {
|
|
// ( types, data, fn )
|
fn = data;
|
data = selector;
|
selector = undefined;
|
}
|
}
|
if ( fn === false ) {
|
fn = returnFalse;
|
} else if ( !fn ) {
|
return elem;
|
}
|
|
if ( one === 1 ) {
|
origFn = fn;
|
fn = function( event ) {
|
|
// Can use an empty set, since event contains the info
|
jQuery().off( event );
|
return origFn.apply( this, arguments );
|
};
|
|
// Use same guid so caller can remove using origFn
|
fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ );
|
}
|
return elem.each( function() {
|
jQuery.event.add( this, types, fn, data, selector );
|
} );
|
}
|
|
/*
|
* Helper functions for managing events -- not part of the public interface.
|
* Props to Dean Edwards' addEvent library for many of the ideas.
|
*/
|
jQuery.event = {
|
|
global: {},
|
|
add: function( elem, types, handler, data, selector ) {
|
|
var handleObjIn, eventHandle, tmp,
|
events, t, handleObj,
|
special, handlers, type, namespaces, origType,
|
elemData = dataPriv.get( elem );
|
|
// Don't attach events to noData or text/comment nodes (but allow plain objects)
|
if ( !elemData ) {
|
return;
|
}
|
|
// Caller can pass in an object of custom data in lieu of the handler
|
if ( handler.handler ) {
|
handleObjIn = handler;
|
handler = handleObjIn.handler;
|
selector = handleObjIn.selector;
|
}
|
|
// Make sure that the handler has a unique ID, used to find/remove it later
|
if ( !handler.guid ) {
|
handler.guid = jQuery.guid++;
|
}
|
|
// Init the element's event structure and main handler, if this is the first
|
if ( !( events = elemData.events ) ) {
|
events = elemData.events = {};
|
}
|
if ( !( eventHandle = elemData.handle ) ) {
|
eventHandle = elemData.handle = function( e ) {
|
|
// Discard the second event of a jQuery.event.trigger() and
|
// when an event is called after a page has unloaded
|
return typeof jQuery !== "undefined" && jQuery.event.triggered !== e.type ?
|
jQuery.event.dispatch.apply( elem, arguments ) : undefined;
|
};
|
}
|
|
// Handle multiple events separated by a space
|
types = ( types || "" ).match( rnotwhite ) || [ "" ];
|
t = types.length;
|
while ( t-- ) {
|
tmp = rtypenamespace.exec( types[ t ] ) || [];
|
type = origType = tmp[ 1 ];
|
namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort();
|
|
// There *must* be a type, no attaching namespace-only handlers
|
if ( !type ) {
|
continue;
|
}
|
|
// If event changes its type, use the special event handlers for the changed type
|
special = jQuery.event.special[ type ] || {};
|
|
// If selector defined, determine special event api type, otherwise given type
|
type = ( selector ? special.delegateType : special.bindType ) || type;
|
|
// Update special based on newly reset type
|
special = jQuery.event.special[ type ] || {};
|
|
// handleObj is passed to all event handlers
|
handleObj = jQuery.extend( {
|
type: type,
|
origType: origType,
|
data: data,
|
handler: handler,
|
guid: handler.guid,
|
selector: selector,
|
needsContext: selector && jQuery.expr.match.needsContext.test( selector ),
|
namespace: namespaces.join( "." )
|
}, handleObjIn );
|
|
// Init the event handler queue if we're the first
|
if ( !( handlers = events[ type ] ) ) {
|
handlers = events[ type ] = [];
|
handlers.delegateCount = 0;
|
|
// Only use addEventListener if the special events handler returns false
|
if ( !special.setup ||
|
special.setup.call( elem, data, namespaces, eventHandle ) === false ) {
|
|
if ( elem.addEventListener ) {
|
elem.addEventListener( type, eventHandle );
|
}
|
}
|
}
|
|
if ( special.add ) {
|
special.add.call( elem, handleObj );
|
|
if ( !handleObj.handler.guid ) {
|
handleObj.handler.guid = handler.guid;
|
}
|
}
|
|
// Add to the element's handler list, delegates in front
|
if ( selector ) {
|
handlers.splice( handlers.delegateCount++, 0, handleObj );
|
} else {
|
handlers.push( handleObj );
|
}
|
|
// Keep track of which events have ever been used, for event optimization
|
jQuery.event.global[ type ] = true;
|
}
|
|
},
|
|
// Detach an event or set of events from an element
|
remove: function( elem, types, handler, selector, mappedTypes ) {
|
|
var j, origCount, tmp,
|
events, t, handleObj,
|
special, handlers, type, namespaces, origType,
|
elemData = dataPriv.hasData( elem ) && dataPriv.get( elem );
|
|
if ( !elemData || !( events = elemData.events ) ) {
|
return;
|
}
|
|
// Once for each type.namespace in types; type may be omitted
|
types = ( types || "" ).match( rnotwhite ) || [ "" ];
|
t = types.length;
|
while ( t-- ) {
|
tmp = rtypenamespace.exec( types[ t ] ) || [];
|
type = origType = tmp[ 1 ];
|
namespaces = ( tmp[ 2 ] || "" ).split( "." ).sort();
|
|
// Unbind all events (on this namespace, if provided) for the element
|
if ( !type ) {
|
for ( type in events ) {
|
jQuery.event.remove( elem, type + types[ t ], handler, selector, true );
|
}
|
continue;
|
}
|
|
special = jQuery.event.special[ type ] || {};
|
type = ( selector ? special.delegateType : special.bindType ) || type;
|
handlers = events[ type ] || [];
|
tmp = tmp[ 2 ] &&
|
new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" );
|
|
// Remove matching events
|
origCount = j = handlers.length;
|
while ( j-- ) {
|
handleObj = handlers[ j ];
|
|
if ( ( mappedTypes || origType === handleObj.origType ) &&
|
( !handler || handler.guid === handleObj.guid ) &&
|
( !tmp || tmp.test( handleObj.namespace ) ) &&
|
( !selector || selector === handleObj.selector ||
|
selector === "**" && handleObj.selector ) ) {
|
handlers.splice( j, 1 );
|
|
if ( handleObj.selector ) {
|
handlers.delegateCount--;
|
}
|
if ( special.remove ) {
|
special.remove.call( elem, handleObj );
|
}
|
}
|
}
|
|
// Remove generic event handler if we removed something and no more handlers exist
|
// (avoids potential for endless recursion during removal of special event handlers)
|
if ( origCount && !handlers.length ) {
|
if ( !special.teardown ||
|
special.teardown.call( elem, namespaces, elemData.handle ) === false ) {
|
|
jQuery.removeEvent( elem, type, elemData.handle );
|
}
|
|
delete events[ type ];
|
}
|
}
|
|
// Remove data and the expando if it's no longer used
|
if ( jQuery.isEmptyObject( events ) ) {
|
dataPriv.remove( elem, "handle events" );
|
}
|
},
|
|
dispatch: function( event ) {
|
|
// Make a writable jQuery.Event from the native event object
|
event = jQuery.event.fix( event );
|
|
var i, j, ret, matched, handleObj,
|
handlerQueue = [],
|
args = slice.call( arguments ),
|
handlers = ( dataPriv.get( this, "events" ) || {} )[ event.type ] || [],
|
special = jQuery.event.special[ event.type ] || {};
|
|
// Use the fix-ed jQuery.Event rather than the (read-only) native event
|
args[ 0 ] = event;
|
event.delegateTarget = this;
|
|
// Call the preDispatch hook for the mapped type, and let it bail if desired
|
if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) {
|
return;
|
}
|
|
// Determine handlers
|
handlerQueue = jQuery.event.handlers.call( this, event, handlers );
|
|
// Run delegates first; they may want to stop propagation beneath us
|
i = 0;
|
while ( ( matched = handlerQueue[ i++ ] ) && !event.isPropagationStopped() ) {
|
event.currentTarget = matched.elem;
|
|
j = 0;
|
while ( ( handleObj = matched.handlers[ j++ ] ) &&
|
!event.isImmediatePropagationStopped() ) {
|
|
// Triggered event must either 1) have no namespace, or 2) have namespace(s)
|
// a subset or equal to those in the bound event (both can have no namespace).
|
if ( !event.rnamespace || event.rnamespace.test( handleObj.namespace ) ) {
|
|
event.handleObj = handleObj;
|
event.data = handleObj.data;
|
|
ret = ( ( jQuery.event.special[ handleObj.origType ] || {} ).handle ||
|
handleObj.handler ).apply( matched.elem, args );
|
|
if ( ret !== undefined ) {
|
if ( ( event.result = ret ) === false ) {
|
event.preventDefault();
|
event.stopPropagation();
|
}
|
}
|
}
|
}
|
}
|
|
// Call the postDispatch hook for the mapped type
|
if ( special.postDispatch ) {
|
special.postDispatch.call( this, event );
|
}
|
|
return event.result;
|
},
|
|
handlers: function( event, handlers ) {
|
var i, matches, sel, handleObj,
|
handlerQueue = [],
|
delegateCount = handlers.delegateCount,
|
cur = event.target;
|
|
// Support (at least): Chrome, IE9
|
// Find delegate handlers
|
// Black-hole SVG <use> instance trees (#13180)
|
//
|
// Support: Firefox<=42+
|
// Avoid non-left-click in FF but don't block IE radio events (#3861, gh-2343)
|
if ( delegateCount && cur.nodeType &&
|
( event.type !== "click" || isNaN( event.button ) || event.button < 1 ) ) {
|
|
for ( ; cur !== this; cur = cur.parentNode || this ) {
|
|
// Don't check non-elements (#13208)
|
// Don't process clicks on disabled elements (#6911, #8165, #11382, #11764)
|
if ( cur.nodeType === 1 && ( cur.disabled !== true || event.type !== "click" ) ) {
|
matches = [];
|
for ( i = 0; i < delegateCount; i++ ) {
|
handleObj = handlers[ i ];
|
|
// Don't conflict with Object.prototype properties (#13203)
|
sel = handleObj.selector + " ";
|
|
if ( matches[ sel ] === undefined ) {
|
matches[ sel ] = handleObj.needsContext ?
|
jQuery( sel, this ).index( cur ) > -1 :
|
jQuery.find( sel, this, null, [ cur ] ).length;
|
}
|
if ( matches[ sel ] ) {
|
matches.push( handleObj );
|
}
|
}
|
if ( matches.length ) {
|
handlerQueue.push( { elem: cur, handlers: matches } );
|
}
|
}
|
}
|
}
|
|
// Add the remaining (directly-bound) handlers
|
if ( delegateCount < handlers.length ) {
|
handlerQueue.push( { elem: this, handlers: handlers.slice( delegateCount ) } );
|
}
|
|
return handlerQueue;
|
},
|
|
// Includes some event props shared by KeyEvent and MouseEvent
|
props: ( "altKey bubbles cancelable ctrlKey currentTarget detail eventPhase " +
|
"metaKey relatedTarget shiftKey target timeStamp view which" ).split( " " ),
|
|
fixHooks: {},
|
|
keyHooks: {
|
props: "char charCode key keyCode".split( " " ),
|
filter: function( event, original ) {
|
|
// Add which for key events
|
if ( event.which == null ) {
|
event.which = original.charCode != null ? original.charCode : original.keyCode;
|
}
|
|
return event;
|
}
|
},
|
|
mouseHooks: {
|
props: ( "button buttons clientX clientY offsetX offsetY pageX pageY " +
|
"screenX screenY toElement" ).split( " " ),
|
filter: function( event, original ) {
|
var eventDoc, doc, body,
|
button = original.button;
|
|
// Calculate pageX/Y if missing and clientX/Y available
|
if ( event.pageX == null && original.clientX != null ) {
|
eventDoc = event.target.ownerDocument || document;
|
doc = eventDoc.documentElement;
|
body = eventDoc.body;
|
|
event.pageX = original.clientX +
|
( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
|
( doc && doc.clientLeft || body && body.clientLeft || 0 );
|
event.pageY = original.clientY +
|
( doc && doc.scrollTop || body && body.scrollTop || 0 ) -
|
( doc && doc.clientTop || body && body.clientTop || 0 );
|
}
|
|
// Add which for click: 1 === left; 2 === middle; 3 === right
|
// Note: button is not normalized, so don't use it
|
if ( !event.which && button !== undefined ) {
|
event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) );
|
}
|
|
return event;
|
}
|
},
|
|
fix: function( event ) {
|
if ( event[ jQuery.expando ] ) {
|
return event;
|
}
|
|
// Create a writable copy of the event object and normalize some properties
|
var i, prop, copy,
|
type = event.type,
|
originalEvent = event,
|
fixHook = this.fixHooks[ type ];
|
|
if ( !fixHook ) {
|
this.fixHooks[ type ] = fixHook =
|
rmouseEvent.test( type ) ? this.mouseHooks :
|
rkeyEvent.test( type ) ? this.keyHooks :
|
{};
|
}
|
copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props;
|
|
event = new jQuery.Event( originalEvent );
|
|
i = copy.length;
|
while ( i-- ) {
|
prop = copy[ i ];
|
event[ prop ] = originalEvent[ prop ];
|
}
|
|
// Support: Cordova 2.5 (WebKit) (#13255)
|
// All events should have a target; Cordova deviceready doesn't
|
if ( !event.target ) {
|
event.target = document;
|
}
|
|
// Support: Safari 6.0+, Chrome<28
|
// Target should not be a text node (#504, #13143)
|
if ( event.target.nodeType === 3 ) {
|
event.target = event.target.parentNode;
|
}
|
|
return fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
|
},
|
|
special: {
|
load: {
|
|
// Prevent triggered image.load events from bubbling to window.load
|
noBubble: true
|
},
|
focus: {
|
|
// Fire native event if possible so blur/focus sequence is correct
|
trigger: function() {
|
if ( this !== safeActiveElement() && this.focus ) {
|
this.focus();
|
return false;
|
}
|
},
|
delegateType: "focusin"
|
},
|
blur: {
|
trigger: function() {
|
if ( this === safeActiveElement() && this.blur ) {
|
this.blur();
|
return false;
|
}
|
},
|
delegateType: "focusout"
|
},
|
click: {
|
|
// For checkbox, fire native event so checked state will be right
|
trigger: function() {
|
if ( this.type === "checkbox" && this.click && jQuery.nodeName( this, "input" ) ) {
|
this.click();
|
return false;
|
}
|
},
|
|
// For cross-browser consistency, don't fire native .click() on links
|
_default: function( event ) {
|
return jQuery.nodeName( event.target, "a" );
|
}
|
},
|
|
beforeunload: {
|
postDispatch: function( event ) {
|
|
// Support: Firefox 20+
|
// Firefox doesn't alert if the returnValue field is not set.
|
if ( event.result !== undefined && event.originalEvent ) {
|
event.originalEvent.returnValue = event.result;
|
}
|
}
|
}
|
}
|
};
|
|
jQuery.removeEvent = function( elem, type, handle ) {
|
|
// This "if" is needed for plain objects
|
if ( elem.removeEventListener ) {
|
elem.removeEventListener( type, handle );
|
}
|
};
|
|
jQuery.Event = function( src, props ) {
|
|
// Allow instantiation without the 'new' keyword
|
if ( !( this instanceof jQuery.Event ) ) {
|
return new jQuery.Event( src, props );
|
}
|
|
// Event object
|
if ( src && src.type ) {
|
this.originalEvent = src;
|
this.type = src.type;
|
|
// Events bubbling up the document may have been marked as prevented
|
// by a handler lower down the tree; reflect the correct value.
|
this.isDefaultPrevented = src.defaultPrevented ||
|
src.defaultPrevented === undefined &&
|
|
// Support: Android<4.0
|
src.returnValue === false ?
|
returnTrue :
|
returnFalse;
|
|
// Event type
|
} else {
|
this.type = src;
|
}
|
|
// Put explicitly provided properties onto the event object
|
if ( props ) {
|
jQuery.extend( this, props );
|
}
|
|
// Create a timestamp if incoming event doesn't have one
|
this.timeStamp = src && src.timeStamp || jQuery.now();
|
|
// Mark it as fixed
|
this[ jQuery.expando ] = true;
|
};
|
|
// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding
|
// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
|
jQuery.Event.prototype = {
|
constructor: jQuery.Event,
|
isDefaultPrevented: returnFalse,
|
isPropagationStopped: returnFalse,
|
isImmediatePropagationStopped: returnFalse,
|
|
preventDefault: function() {
|
var e = this.originalEvent;
|
|
this.isDefaultPrevented = returnTrue;
|
|
if ( e ) {
|
e.preventDefault();
|
}
|
},
|
stopPropagation: function() {
|
var e = this.originalEvent;
|
|
this.isPropagationStopped = returnTrue;
|
|
if ( e ) {
|
e.stopPropagation();
|
}
|
},
|
stopImmediatePropagation: function() {
|
var e = this.originalEvent;
|
|
this.isImmediatePropagationStopped = returnTrue;
|
|
if ( e ) {
|
e.stopImmediatePropagation();
|
}
|
|
this.stopPropagation();
|
}
|
};
|
|
// Create mouseenter/leave events using mouseover/out and event-time checks
|
// so that event delegation works in jQuery.
|
// Do the same for pointerenter/pointerleave and pointerover/pointerout
|
//
|
// Support: Safari 7 only
|
// Safari sends mouseenter too often; see:
|
// https://code.google.com/p/chromium/issues/detail?id=470258
|
// for the description of the bug (it existed in older Chrome versions as well).
|
jQuery.each( {
|
mouseenter: "mouseover",
|
mouseleave: "mouseout",
|
pointerenter: "pointerover",
|
pointerleave: "pointerout"
|
}, function( orig, fix ) {
|
jQuery.event.special[ orig ] = {
|
delegateType: fix,
|
bindType: fix,
|
|
handle: function( event ) {
|
var ret,
|
target = this,
|
related = event.relatedTarget,
|
handleObj = event.handleObj;
|
|
// For mouseenter/leave call the handler if related is outside the target.
|
// NB: No relatedTarget if the mouse left/entered the browser window
|
if ( !related || ( related !== target && !jQuery.contains( target, related ) ) ) {
|
event.type = handleObj.origType;
|
ret = handleObj.handler.apply( this, arguments );
|
event.type = fix;
|
}
|
return ret;
|
}
|
};
|
} );
|
|
jQuery.fn.extend( {
|
on: function( types, selector, data, fn ) {
|
return on( this, types, selector, data, fn );
|
},
|
one: function( types, selector, data, fn ) {
|
return on( this, types, selector, data, fn, 1 );
|
},
|
off: function( types, selector, fn ) {
|
var handleObj, type;
|
if ( types && types.preventDefault && types.handleObj ) {
|
|
// ( event ) dispatched jQuery.Event
|
handleObj = types.handleObj;
|
jQuery( types.delegateTarget ).off(
|
handleObj.namespace ?
|
handleObj.origType + "." + handleObj.namespace :
|
handleObj.origType,
|
handleObj.selector,
|
handleObj.handler
|
);
|
return this;
|
}
|
if ( typeof types === "object" ) {
|
|
// ( types-object [, selector] )
|
for ( type in types ) {
|
this.off( type, selector, types[ type ] );
|
}
|
return this;
|
}
|
if ( selector === false || typeof selector === "function" ) {
|
|
// ( types [, fn] )
|
fn = selector;
|
selector = undefined;
|
}
|
if ( fn === false ) {
|
fn = returnFalse;
|
}
|
return this.each( function() {
|
jQuery.event.remove( this, types, fn, selector );
|
} );
|
}
|
} );
|
|
|
var
|
rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi,
|
|
// Support: IE 10-11, Edge 10240+
|
// In IE/Edge using regex groups here causes severe slowdowns.
|
// See https://connect.microsoft.com/IE/feedback/details/1736512/
|
rnoInnerhtml = /<script|<style|<link/i,
|
|
// checked="checked" or checked
|
rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
|
rscriptTypeMasked = /^true\/(.*)/,
|
rcleanScript = /^\s*<!(?:\[CDATA\[|--)|(?:\]\]|--)>\s*$/g;
|
|
// Manipulating tables requires a tbody
|
function manipulationTarget( elem, content ) {
|
return jQuery.nodeName( elem, "table" ) &&
|
jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ?
|
|
elem.getElementsByTagName( "tbody" )[ 0 ] ||
|
elem.appendChild( elem.ownerDocument.createElement( "tbody" ) ) :
|
elem;
|
}
|
|
// Replace/restore the type attribute of script elements for safe DOM manipulation
|
function disableScript( elem ) {
|
elem.type = ( elem.getAttribute( "type" ) !== null ) + "/" + elem.type;
|
return elem;
|
}
|
function restoreScript( elem ) {
|
var match = rscriptTypeMasked.exec( elem.type );
|
|
if ( match ) {
|
elem.type = match[ 1 ];
|
} else {
|
elem.removeAttribute( "type" );
|
}
|
|
return elem;
|
}
|
|
function cloneCopyEvent( src, dest ) {
|
var i, l, type, pdataOld, pdataCur, udataOld, udataCur, events;
|
|
if ( dest.nodeType !== 1 ) {
|
return;
|
}
|
|
// 1. Copy private data: events, handlers, etc.
|
if ( dataPriv.hasData( src ) ) {
|
pdataOld = dataPriv.access( src );
|
pdataCur = dataPriv.set( dest, pdataOld );
|
events = pdataOld.events;
|
|
if ( events ) {
|
delete pdataCur.handle;
|
pdataCur.events = {};
|
|
for ( type in events ) {
|
for ( i = 0, l = events[ type ].length; i < l; i++ ) {
|
jQuery.event.add( dest, type, events[ type ][ i ] );
|
}
|
}
|
}
|
}
|
|
// 2. Copy user data
|
if ( dataUser.hasData( src ) ) {
|
udataOld = dataUser.access( src );
|
udataCur = jQuery.extend( {}, udataOld );
|
|
dataUser.set( dest, udataCur );
|
}
|
}
|
|
// Fix IE bugs, see support tests
|
function fixInput( src, dest ) {
|
var nodeName = dest.nodeName.toLowerCase();
|
|
// Fails to persist the checked state of a cloned checkbox or radio button.
|
if ( nodeName === "input" && rcheckableType.test( src.type ) ) {
|
dest.checked = src.checked;
|
|
// Fails to return the selected option to the default selected state when cloning options
|
} else if ( nodeName === "input" || nodeName === "textarea" ) {
|
dest.defaultValue = src.defaultValue;
|
}
|
}
|
|
function domManip( collection, args, callback, ignored ) {
|
|
// Flatten any nested arrays
|
args = concat.apply( [], args );
|
|
var fragment, first, scripts, hasScripts, node, doc,
|
i = 0,
|
l = collection.length,
|
iNoClone = l - 1,
|
value = args[ 0 ],
|
isFunction = jQuery.isFunction( value );
|
|
// We can't cloneNode fragments that contain checked, in WebKit
|
if ( isFunction ||
|
( l > 1 && typeof value === "string" &&
|
!support.checkClone && rchecked.test( value ) ) ) {
|
return collection.each( function( index ) {
|
var self = collection.eq( index );
|
if ( isFunction ) {
|
args[ 0 ] = value.call( this, index, self.html() );
|
}
|
domManip( self, args, callback, ignored );
|
} );
|
}
|
|
if ( l ) {
|
fragment = buildFragment( args, collection[ 0 ].ownerDocument, false, collection, ignored );
|
first = fragment.firstChild;
|
|
if ( fragment.childNodes.length === 1 ) {
|
fragment = first;
|
}
|
|
// Require either new content or an interest in ignored elements to invoke the callback
|
if ( first || ignored ) {
|
scripts = jQuery.map( getAll( fragment, "script" ), disableScript );
|
hasScripts = scripts.length;
|
|
// Use the original fragment for the last item
|
// instead of the first because it can end up
|
// being emptied incorrectly in certain situations (#8070).
|
for ( ; i < l; i++ ) {
|
node = fragment;
|
|
if ( i !== iNoClone ) {
|
node = jQuery.clone( node, true, true );
|
|
// Keep references to cloned scripts for later restoration
|
if ( hasScripts ) {
|
|
// Support: Android<4.1, PhantomJS<2
|
// push.apply(_, arraylike) throws on ancient WebKit
|
jQuery.merge( scripts, getAll( node, "script" ) );
|
}
|
}
|
|
callback.call( collection[ i ], node, i );
|
}
|
|
if ( hasScripts ) {
|
doc = scripts[ scripts.length - 1 ].ownerDocument;
|
|
// Reenable scripts
|
jQuery.map( scripts, restoreScript );
|
|
// Evaluate executable scripts on first document insertion
|
for ( i = 0; i < hasScripts; i++ ) {
|
node = scripts[ i ];
|
if ( rscriptType.test( node.type || "" ) &&
|
!dataPriv.access( node, "globalEval" ) &&
|
jQuery.contains( doc, node ) ) {
|
|
if ( node.src ) {
|
|
// Optional AJAX dependency, but won't run scripts if not present
|
if ( jQuery._evalUrl ) {
|
jQuery._evalUrl( node.src );
|
}
|
} else {
|
jQuery.globalEval( node.textContent.replace( rcleanScript, "" ) );
|
}
|
}
|
}
|
}
|
}
|
}
|
|
return collection;
|
}
|
|
function remove( elem, selector, keepData ) {
|
var node,
|
nodes = selector ? jQuery.filter( selector, elem ) : elem,
|
i = 0;
|
|
for ( ; ( node = nodes[ i ] ) != null; i++ ) {
|
if ( !keepData && node.nodeType === 1 ) {
|
jQuery.cleanData( getAll( node ) );
|
}
|
|
if ( node.parentNode ) {
|
if ( keepData && jQuery.contains( node.ownerDocument, node ) ) {
|
setGlobalEval( getAll( node, "script" ) );
|
}
|
node.parentNode.removeChild( node );
|
}
|
}
|
|
return elem;
|
}
|
|
jQuery.extend( {
|
htmlPrefilter: function( html ) {
|
return html.replace( rxhtmlTag, "<$1></$2>" );
|
},
|
|
clone: function( elem, dataAndEvents, deepDataAndEvents ) {
|
var i, l, srcElements, destElements,
|
clone = elem.cloneNode( true ),
|
inPage = jQuery.contains( elem.ownerDocument, elem );
|
|
// Fix IE cloning issues
|
if ( !support.noCloneChecked && ( elem.nodeType === 1 || elem.nodeType === 11 ) &&
|
!jQuery.isXMLDoc( elem ) ) {
|
|
// We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2
|
destElements = getAll( clone );
|
srcElements = getAll( elem );
|
|
for ( i = 0, l = srcElements.length; i < l; i++ ) {
|
fixInput( srcElements[ i ], destElements[ i ] );
|
}
|
}
|
|
// Copy the events from the original to the clone
|
if ( dataAndEvents ) {
|
if ( deepDataAndEvents ) {
|
srcElements = srcElements || getAll( elem );
|
destElements = destElements || getAll( clone );
|
|
for ( i = 0, l = srcElements.length; i < l; i++ ) {
|
cloneCopyEvent( srcElements[ i ], destElements[ i ] );
|
}
|
} else {
|
cloneCopyEvent( elem, clone );
|
}
|
}
|
|
// Preserve script evaluation history
|
destElements = getAll( clone, "script" );
|
if ( destElements.length > 0 ) {
|
setGlobalEval( destElements, !inPage && getAll( elem, "script" ) );
|
}
|
|
// Return the cloned set
|
return clone;
|
},
|
|
cleanData: function( elems ) {
|
var data, elem, type,
|
special = jQuery.event.special,
|
i = 0;
|
|
for ( ; ( elem = elems[ i ] ) !== undefined; i++ ) {
|
if ( acceptData( elem ) ) {
|
if ( ( data = elem[ dataPriv.expando ] ) ) {
|
if ( data.events ) {
|
for ( type in data.events ) {
|
if ( special[ type ] ) {
|
jQuery.event.remove( elem, type );
|
|
// This is a shortcut to avoid jQuery.event.remove's overhead
|
} else {
|
jQuery.removeEvent( elem, type, data.handle );
|
}
|
}
|
}
|
|
// Support: Chrome <= 35-45+
|
// Assign undefined instead of using delete, see Data#remove
|
elem[ dataPriv.expando ] = undefined;
|
}
|
if ( elem[ dataUser.expando ] ) {
|
|
// Support: Chrome <= 35-45+
|
// Assign undefined instead of using delete, see Data#remove
|
elem[ dataUser.expando ] = undefined;
|
}
|
}
|
}
|
}
|
} );
|
|
jQuery.fn.extend( {
|
|
// Keep domManip exposed until 3.0 (gh-2225)
|
domManip: domManip,
|
|
detach: function( selector ) {
|
return remove( this, selector, true );
|
},
|
|
remove: function( selector ) {
|
return remove( this, selector );
|
},
|
|
text: function( value ) {
|
return access( this, function( value ) {
|
return value === undefined ?
|
jQuery.text( this ) :
|
this.empty().each( function() {
|
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
|
this.textContent = value;
|
}
|
} );
|
}, null, value, arguments.length );
|
},
|
|
append: function() {
|
return domManip( this, arguments, function( elem ) {
|
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
|
var target = manipulationTarget( this, elem );
|
target.appendChild( elem );
|
}
|
} );
|
},
|
|
prepend: function() {
|
return domManip( this, arguments, function( elem ) {
|
if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) {
|
var target = manipulationTarget( this, elem );
|
target.insertBefore( elem, target.firstChild );
|
}
|
} );
|
},
|
|
before: function() {
|
return domManip( this, arguments, function( elem ) {
|
if ( this.parentNode ) {
|
this.parentNode.insertBefore( elem, this );
|
}
|
} );
|
},
|
|
after: function() {
|
return domManip( this, arguments, function( elem ) {
|
if ( this.parentNode ) {
|
this.parentNode.insertBefore( elem, this.nextSibling );
|
}
|
} );
|
},
|
|
empty: function() {
|
var elem,
|
i = 0;
|
|
for ( ; ( elem = this[ i ] ) != null; i++ ) {
|
if ( elem.nodeType === 1 ) {
|
|
// Prevent memory leaks
|
jQuery.cleanData( getAll( elem, false ) );
|
|
// Remove any remaining nodes
|
elem.textContent = "";
|
}
|
}
|
|
return this;
|
},
|
|
clone: function( dataAndEvents, deepDataAndEvents ) {
|
dataAndEvents = dataAndEvents == null ? false : dataAndEvents;
|
deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
|
|
return this.map( function() {
|
return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
|
} );
|
},
|
|
html: function( value ) {
|
return access( this, function( value ) {
|
var elem = this[ 0 ] || {},
|
i = 0,
|
l = this.length;
|
|
if ( value === undefined && elem.nodeType === 1 ) {
|
return elem.innerHTML;
|
}
|
|
// See if we can take a shortcut and just use innerHTML
|
if ( typeof value === "string" && !rnoInnerhtml.test( value ) &&
|
!wrapMap[ ( rtagName.exec( value ) || [ "", "" ] )[ 1 ].toLowerCase() ] ) {
|
|
value = jQuery.htmlPrefilter( value );
|
|
try {
|
for ( ; i < l; i++ ) {
|
elem = this[ i ] || {};
|
|
// Remove element nodes and prevent memory leaks
|
if ( elem.nodeType === 1 ) {
|
jQuery.cleanData( getAll( elem, false ) );
|
elem.innerHTML = value;
|
}
|
}
|
|
elem = 0;
|
|
// If using innerHTML throws an exception, use the fallback method
|
} catch ( e ) {}
|
}
|
|
if ( elem ) {
|
this.empty().append( value );
|
}
|
}, null, value, arguments.length );
|
},
|
|
replaceWith: function() {
|
var ignored = [];
|
|
// Make the changes, replacing each non-ignored context element with the new content
|
return domManip( this, arguments, function( elem ) {
|
var parent = this.parentNode;
|
|
if ( jQuery.inArray( this, ignored ) < 0 ) {
|
jQuery.cleanData( getAll( this ) );
|
if ( parent ) {
|
parent.replaceChild( elem, this );
|
}
|
}
|
|
// Force callback invocation
|
}, ignored );
|
}
|
} );
|
|
jQuery.each( {
|
appendTo: "append",
|
prependTo: "prepend",
|
insertBefore: "before",
|
insertAfter: "after",
|
replaceAll: "replaceWith"
|
}, function( name, original ) {
|
jQuery.fn[ name ] = function( selector ) {
|
var elems,
|
ret = [],
|
insert = jQuery( selector ),
|
last = insert.length - 1,
|
i = 0;
|
|
for ( ; i <= last; i++ ) {
|
elems = i === last ? this : this.clone( true );
|
jQuery( insert[ i ] )[ original ]( elems );
|
|
// Support: QtWebKit
|
// .get() because push.apply(_, arraylike) throws
|
push.apply( ret, elems.get() );
|
}
|
|
return this.pushStack( ret );
|
};
|
} );
|
|
|
var iframe,
|
elemdisplay = {
|
|
// Support: Firefox
|
// We have to pre-define these values for FF (#10227)
|
HTML: "block",
|
BODY: "block"
|
};
|
|
/**
|
* Retrieve the actual display of a element
|
* @param {String} name nodeName of the element
|
* @param {Object} doc Document object
|
*/
|
|
// Called only from within defaultDisplay
|
function actualDisplay( name, doc ) {
|
var elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ),
|
|
display = jQuery.css( elem[ 0 ], "display" );
|
|
// We don't have any data stored on the element,
|
// so use "detach" method as fast way to get rid of the element
|
elem.detach();
|
|
return display;
|
}
|
|
/**
|
* Try to determine the default display value of an element
|
* @param {String} nodeName
|
*/
|
function defaultDisplay( nodeName ) {
|
var doc = document,
|
display = elemdisplay[ nodeName ];
|
|
if ( !display ) {
|
display = actualDisplay( nodeName, doc );
|
|
// If the simple way fails, read from inside an iframe
|
if ( display === "none" || !display ) {
|
|
// Use the already-created iframe if possible
|
iframe = ( iframe || jQuery( "<iframe frameborder='0' width='0' height='0'/>" ) )
|
.appendTo( doc.documentElement );
|
|
// Always write a new HTML skeleton so Webkit and Firefox don't choke on reuse
|
doc = iframe[ 0 ].contentDocument;
|
|
// Support: IE
|
doc.write();
|
doc.close();
|
|
display = actualDisplay( nodeName, doc );
|
iframe.detach();
|
}
|
|
// Store the correct default display
|
elemdisplay[ nodeName ] = display;
|
}
|
|
return display;
|
}
|
var rmargin = ( /^margin/ );
|
|
var rnumnonpx = new RegExp( "^(" + pnum + ")(?!px)[a-z%]+$", "i" );
|
|
var getStyles = function( elem ) {
|
|
// Support: IE<=11+, Firefox<=30+ (#15098, #14150)
|
// IE throws on elements created in popups
|
// FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
|
var view = elem.ownerDocument.defaultView;
|
|
if ( !view || !view.opener ) {
|
view = window;
|
}
|
|
return view.getComputedStyle( elem );
|
};
|
|
var swap = function( elem, options, callback, args ) {
|
var ret, name,
|
old = {};
|
|
// Remember the old values, and insert the new ones
|
for ( name in options ) {
|
old[ name ] = elem.style[ name ];
|
elem.style[ name ] = options[ name ];
|
}
|
|
ret = callback.apply( elem, args || [] );
|
|
// Revert the old values
|
for ( name in options ) {
|
elem.style[ name ] = old[ name ];
|
}
|
|
return ret;
|
};
|
|
|
var documentElement = document.documentElement;
|
|
|
|
( function() {
|
var pixelPositionVal, boxSizingReliableVal, pixelMarginRightVal, reliableMarginLeftVal,
|
container = document.createElement( "div" ),
|
div = document.createElement( "div" );
|
|
// Finish early in limited (non-browser) environments
|
if ( !div.style ) {
|
return;
|
}
|
|
// Support: IE9-11+
|
// Style of cloned element affects source element cloned (#8908)
|
div.style.backgroundClip = "content-box";
|
div.cloneNode( true ).style.backgroundClip = "";
|
support.clearCloneStyle = div.style.backgroundClip === "content-box";
|
|
container.style.cssText = "border:0;width:8px;height:0;top:0;left:-9999px;" +
|
"padding:0;margin-top:1px;position:absolute";
|
container.appendChild( div );
|
|
// Executing both pixelPosition & boxSizingReliable tests require only one layout
|
// so they're executed at the same time to save the second computation.
|
function computeStyleTests() {
|
div.style.cssText =
|
|
// Support: Firefox<29, Android 2.3
|
// Vendor-prefix box-sizing
|
"-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;" +
|
"position:relative;display:block;" +
|
"margin:auto;border:1px;padding:1px;" +
|
"top:1%;width:50%";
|
div.innerHTML = "";
|
documentElement.appendChild( container );
|
|
var divStyle = window.getComputedStyle( div );
|
pixelPositionVal = divStyle.top !== "1%";
|
reliableMarginLeftVal = divStyle.marginLeft === "2px";
|
boxSizingReliableVal = divStyle.width === "4px";
|
|
// Support: Android 4.0 - 4.3 only
|
// Some styles come back with percentage values, even though they shouldn't
|
div.style.marginRight = "50%";
|
pixelMarginRightVal = divStyle.marginRight === "4px";
|
|
documentElement.removeChild( container );
|
}
|
|
jQuery.extend( support, {
|
pixelPosition: function() {
|
|
// This test is executed only once but we still do memoizing
|
// since we can use the boxSizingReliable pre-computing.
|
// No need to check if the test was already performed, though.
|
computeStyleTests();
|
return pixelPositionVal;
|
},
|
boxSizingReliable: function() {
|
if ( boxSizingReliableVal == null ) {
|
computeStyleTests();
|
}
|
return boxSizingReliableVal;
|
},
|
pixelMarginRight: function() {
|
|
// Support: Android 4.0-4.3
|
// We're checking for boxSizingReliableVal here instead of pixelMarginRightVal
|
// since that compresses better and they're computed together anyway.
|
if ( boxSizingReliableVal == null ) {
|
computeStyleTests();
|
}
|
return pixelMarginRightVal;
|
},
|
reliableMarginLeft: function() {
|
|
// Support: IE <=8 only, Android 4.0 - 4.3 only, Firefox <=3 - 37
|
if ( boxSizingReliableVal == null ) {
|
computeStyleTests();
|
}
|
return reliableMarginLeftVal;
|
},
|
reliableMarginRight: function() {
|
|
// Support: Android 2.3
|
// Check if div with explicit width and no margin-right incorrectly
|
// gets computed margin-right based on width of container. (#3333)
|
// WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
|
// This support function is only executed once so no memoizing is needed.
|
var ret,
|
marginDiv = div.appendChild( document.createElement( "div" ) );
|
|
// Reset CSS: box-sizing; display; margin; border; padding
|
marginDiv.style.cssText = div.style.cssText =
|
|
// Support: Android 2.3
|
// Vendor-prefix box-sizing
|
"-webkit-box-sizing:content-box;box-sizing:content-box;" +
|
"display:block;margin:0;border:0;padding:0";
|
marginDiv.style.marginRight = marginDiv.style.width = "0";
|
div.style.width = "1px";
|
documentElement.appendChild( container );
|
|
ret = !parseFloat( window.getComputedStyle( marginDiv ).marginRight );
|
|
documentElement.removeChild( container );
|
div.removeChild( marginDiv );
|
|
return ret;
|
}
|
} );
|
} )();
|
|
|
function curCSS( elem, name, computed ) {
|
var width, minWidth, maxWidth, ret,
|
style = elem.style;
|
|
computed = computed || getStyles( elem );
|
ret = computed ? computed.getPropertyValue( name ) || computed[ name ] : undefined;
|
|
// Support: Opera 12.1x only
|
// Fall back to style even without computed
|
// computed is undefined for elems on document fragments
|
if ( ( ret === "" || ret === undefined ) && !jQuery.contains( elem.ownerDocument, elem ) ) {
|
ret = jQuery.style( elem, name );
|
}
|
|
// Support: IE9
|
// getPropertyValue is only needed for .css('filter') (#12537)
|
if ( computed ) {
|
|
// A tribute to the "awesome hack by Dean Edwards"
|
// Android Browser returns percentage for some values,
|
// but width seems to be reliably pixels.
|
// This is against the CSSOM draft spec:
|
// http://dev.w3.org/csswg/cssom/#resolved-values
|
if ( !support.pixelMarginRight() && rnumnonpx.test( ret ) && rmargin.test( name ) ) {
|
|
// Remember the original values
|
width = style.width;
|
minWidth = style.minWidth;
|
maxWidth = style.maxWidth;
|
|
// Put in the new values to get a computed value out
|
style.minWidth = style.maxWidth = style.width = ret;
|
ret = computed.width;
|
|
// Revert the changed values
|
style.width = width;
|
style.minWidth = minWidth;
|
style.maxWidth = maxWidth;
|
}
|
}
|
|
return ret !== undefined ?
|
|
// Support: IE9-11+
|
// IE returns zIndex value as an integer.
|
ret + "" :
|
ret;
|
}
|
|
|
function addGetHookIf( conditionFn, hookFn ) {
|
|
// Define the hook, we'll check on the first run if it's really needed.
|
return {
|
get: function() {
|
if ( conditionFn() ) {
|
|
// Hook not needed (or it's not possible to use it due
|
// to missing dependency), remove it.
|
delete this.get;
|
return;
|
}
|
|
// Hook needed; redefine it so that the support test is not executed again.
|
return ( this.get = hookFn ).apply( this, arguments );
|
}
|
};
|
}
|
|
|
var
|
|
// Swappable if display is none or starts with table
|
// except "table", "table-cell", or "table-caption"
|
// See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
|
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
|
|
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
|
cssNormalTransform = {
|
letterSpacing: "0",
|
fontWeight: "400"
|
},
|
|
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ],
|
emptyStyle = document.createElement( "div" ).style;
|
|
// Return a css property mapped to a potentially vendor prefixed property
|
function vendorPropName( name ) {
|
|
// Shortcut for names that are not vendor prefixed
|
if ( name in emptyStyle ) {
|
return name;
|
}
|
|
// Check for vendor prefixed names
|
var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
|
i = cssPrefixes.length;
|
|
while ( i-- ) {
|
name = cssPrefixes[ i ] + capName;
|
if ( name in emptyStyle ) {
|
return name;
|
}
|
}
|
}
|
|
function setPositiveNumber( elem, value, subtract ) {
|
|
// Any relative (+/-) values have already been
|
// normalized at this point
|
var matches = rcssNum.exec( value );
|
return matches ?
|
|
// Guard against undefined "subtract", e.g., when used as in cssHooks
|
Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) :
|
value;
|
}
|
|
function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
|
var i = extra === ( isBorderBox ? "border" : "content" ) ?
|
|
// If we already have the right measurement, avoid augmentation
|
4 :
|
|
// Otherwise initialize for horizontal or vertical properties
|
name === "width" ? 1 : 0,
|
|
val = 0;
|
|
for ( ; i < 4; i += 2 ) {
|
|
// Both box models exclude margin, so add it if we want it
|
if ( extra === "margin" ) {
|
val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
|
}
|
|
if ( isBorderBox ) {
|
|
// border-box includes padding, so remove it if we want content
|
if ( extra === "content" ) {
|
val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
|
}
|
|
// At this point, extra isn't border nor margin, so remove border
|
if ( extra !== "margin" ) {
|
val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
}
|
} else {
|
|
// At this point, extra isn't content, so add padding
|
val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
|
|
// At this point, extra isn't content nor padding, so add border
|
if ( extra !== "padding" ) {
|
val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
|
}
|
}
|
}
|
|
return val;
|
}
|
|
function getWidthOrHeight( elem, name, extra ) {
|
|
// Start with offset property, which is equivalent to the border-box value
|
var valueIsBorderBox = true,
|
val = name === "width" ? elem.offsetWidth : elem.offsetHeight,
|
styles = getStyles( elem ),
|
isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
|
|
// Support: IE11 only
|
// In IE 11 fullscreen elements inside of an iframe have
|
// 100x too small dimensions (gh-1764).
|
if ( document.msFullscreenElement && window.top !== window ) {
|
|
// Support: IE11 only
|
// Running getBoundingClientRect on a disconnected node
|
// in IE throws an error.
|
if ( elem.getClientRects().length ) {
|
val = Math.round( elem.getBoundingClientRect()[ name ] * 100 );
|
}
|
}
|
|
// Some non-html elements return undefined for offsetWidth, so check for null/undefined
|
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285
|
// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668
|
if ( val <= 0 || val == null ) {
|
|
// Fall back to computed then uncomputed css if necessary
|
val = curCSS( elem, name, styles );
|
if ( val < 0 || val == null ) {
|
val = elem.style[ name ];
|
}
|
|
// Computed unit is not pixels. Stop here and return.
|
if ( rnumnonpx.test( val ) ) {
|
return val;
|
}
|
|
// Check for style in case a browser which returns unreliable values
|
// for getComputedStyle silently falls back to the reliable elem.style
|
valueIsBorderBox = isBorderBox &&
|
( support.boxSizingReliable() || val === elem.style[ name ] );
|
|
// Normalize "", auto, and prepare for extra
|
val = parseFloat( val ) || 0;
|
}
|
|
// Use the active box-sizing model to add/subtract irrelevant styles
|
return ( val +
|
augmentWidthOrHeight(
|
elem,
|
name,
|
extra || ( isBorderBox ? "border" : "content" ),
|
valueIsBorderBox,
|
styles
|
)
|
) + "px";
|
}
|
|
function showHide( elements, show ) {
|
var display, elem, hidden,
|
values = [],
|
index = 0,
|
length = elements.length;
|
|
for ( ; index < length; index++ ) {
|
elem = elements[ index ];
|
if ( !elem.style ) {
|
continue;
|
}
|
|
values[ index ] = dataPriv.get( elem, "olddisplay" );
|
display = elem.style.display;
|
if ( show ) {
|
|
// Reset the inline display of this element to learn if it is
|
// being hidden by cascaded rules or not
|
if ( !values[ index ] && display === "none" ) {
|
elem.style.display = "";
|
}
|
|
// Set elements which have been overridden with display: none
|
// in a stylesheet to whatever the default browser style is
|
// for such an element
|
if ( elem.style.display === "" && isHidden( elem ) ) {
|
values[ index ] = dataPriv.access(
|
elem,
|
"olddisplay",
|
defaultDisplay( elem.nodeName )
|
);
|
}
|
} else {
|
hidden = isHidden( elem );
|
|
if ( display !== "none" || !hidden ) {
|
dataPriv.set(
|
elem,
|
"olddisplay",
|
hidden ? display : jQuery.css( elem, "display" )
|
);
|
}
|
}
|
}
|
|
// Set the display of most of the elements in a second loop
|
// to avoid the constant reflow
|
for ( index = 0; index < length; index++ ) {
|
elem = elements[ index ];
|
if ( !elem.style ) {
|
continue;
|
}
|
if ( !show || elem.style.display === "none" || elem.style.display === "" ) {
|
elem.style.display = show ? values[ index ] || "" : "none";
|
}
|
}
|
|
return elements;
|
}
|
|
jQuery.extend( {
|
|
// Add in style property hooks for overriding the default
|
// behavior of getting and setting a style property
|
cssHooks: {
|
opacity: {
|
get: function( elem, computed ) {
|
if ( computed ) {
|
|
// We should always get a number back from opacity
|
var ret = curCSS( elem, "opacity" );
|
return ret === "" ? "1" : ret;
|
}
|
}
|
}
|
},
|
|
// Don't automatically add "px" to these possibly-unitless properties
|
cssNumber: {
|
"animationIterationCount": true,
|
"columnCount": true,
|
"fillOpacity": true,
|
"flexGrow": true,
|
"flexShrink": true,
|
"fontWeight": true,
|
"lineHeight": true,
|
"opacity": true,
|
"order": true,
|
"orphans": true,
|
"widows": true,
|
"zIndex": true,
|
"zoom": true
|
},
|
|
// Add in properties whose names you wish to fix before
|
// setting or getting the value
|
cssProps: {
|
"float": "cssFloat"
|
},
|
|
// Get and set the style property on a DOM Node
|
style: function( elem, name, value, extra ) {
|
|
// Don't set styles on text and comment nodes
|
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
|
return;
|
}
|
|
// Make sure that we're working with the right name
|
var ret, type, hooks,
|
origName = jQuery.camelCase( name ),
|
style = elem.style;
|
|
name = jQuery.cssProps[ origName ] ||
|
( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName );
|
|
// Gets hook for the prefixed version, then unprefixed version
|
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
|
|
// Check if we're setting a value
|
if ( value !== undefined ) {
|
type = typeof value;
|
|
// Convert "+=" or "-=" to relative numbers (#7345)
|
if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
|
value = adjustCSS( elem, name, ret );
|
|
// Fixes bug #9237
|
type = "number";
|
}
|
|
// Make sure that null and NaN values aren't set (#7116)
|
if ( value == null || value !== value ) {
|
return;
|
}
|
|
// If a number was passed in, add the unit (except for certain CSS properties)
|
if ( type === "number" ) {
|
value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
|
}
|
|
// Support: IE9-11+
|
// background-* props affect original clone's values
|
if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
|
style[ name ] = "inherit";
|
}
|
|
// If a hook was provided, use that value, otherwise just set the specified value
|
if ( !hooks || !( "set" in hooks ) ||
|
( value = hooks.set( elem, value, extra ) ) !== undefined ) {
|
|
style[ name ] = value;
|
}
|
|
} else {
|
|
// If a hook was provided get the non-computed value from there
|
if ( hooks && "get" in hooks &&
|
( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
|
|
return ret;
|
}
|
|
// Otherwise just get the value from the style object
|
return style[ name ];
|
}
|
},
|
|
css: function( elem, name, extra, styles ) {
|
var val, num, hooks,
|
origName = jQuery.camelCase( name );
|
|
// Make sure that we're working with the right name
|
name = jQuery.cssProps[ origName ] ||
|
( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName );
|
|
// Try prefixed name followed by the unprefixed name
|
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
|
|
// If a hook was provided get the computed value from there
|
if ( hooks && "get" in hooks ) {
|
val = hooks.get( elem, true, extra );
|
}
|
|
// Otherwise, if a way to get the computed value exists, use that
|
if ( val === undefined ) {
|
val = curCSS( elem, name, styles );
|
}
|
|
// Convert "normal" to computed value
|
if ( val === "normal" && name in cssNormalTransform ) {
|
val = cssNormalTransform[ name ];
|
}
|
|
// Make numeric if forced or a qualifier was provided and val looks numeric
|
if ( extra === "" || extra ) {
|
num = parseFloat( val );
|
return extra === true || isFinite( num ) ? num || 0 : val;
|
}
|
return val;
|
}
|
} );
|
|
jQuery.each( [ "height", "width" ], function( i, name ) {
|
jQuery.cssHooks[ name ] = {
|
get: function( elem, computed, extra ) {
|
if ( computed ) {
|
|
// Certain elements can have dimension info if we invisibly show them
|
// but it must have a current display style that would benefit
|
return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
|
elem.offsetWidth === 0 ?
|
swap( elem, cssShow, function() {
|
return getWidthOrHeight( elem, name, extra );
|
} ) :
|
getWidthOrHeight( elem, name, extra );
|
}
|
},
|
|
set: function( elem, value, extra ) {
|
var matches,
|
styles = extra && getStyles( elem ),
|
subtract = extra && augmentWidthOrHeight(
|
elem,
|
name,
|
extra,
|
jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
|
styles
|
);
|
|
// Convert to pixels if value adjustment is needed
|
if ( subtract && ( matches = rcssNum.exec( value ) ) &&
|
( matches[ 3 ] || "px" ) !== "px" ) {
|
|
elem.style[ name ] = value;
|
value = jQuery.css( elem, name );
|
}
|
|
return setPositiveNumber( elem, value, subtract );
|
}
|
};
|
} );
|
|
jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
|
function( elem, computed ) {
|
if ( computed ) {
|
return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
|
elem.getBoundingClientRect().left -
|
swap( elem, { marginLeft: 0 }, function() {
|
return elem.getBoundingClientRect().left;
|
} )
|
) + "px";
|
}
|
}
|
);
|
|
// Support: Android 2.3
|
jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
|
function( elem, computed ) {
|
if ( computed ) {
|
return swap( elem, { "display": "inline-block" },
|
curCSS, [ elem, "marginRight" ] );
|
}
|
}
|
);
|
|
// These hooks are used by animate to expand properties
|
jQuery.each( {
|
margin: "",
|
padding: "",
|
border: "Width"
|
}, function( prefix, suffix ) {
|
jQuery.cssHooks[ prefix + suffix ] = {
|
expand: function( value ) {
|
var i = 0,
|
expanded = {},
|
|
// Assumes a single number if not a string
|
parts = typeof value === "string" ? value.split( " " ) : [ value ];
|
|
for ( ; i < 4; i++ ) {
|
expanded[ prefix + cssExpand[ i ] + suffix ] =
|
parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
|
}
|
|
return expanded;
|
}
|
};
|
|
if ( !rmargin.test( prefix ) ) {
|
jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
|
}
|
} );
|
|
jQuery.fn.extend( {
|
css: function( name, value ) {
|
return access( this, function( elem, name, value ) {
|
var styles, len,
|
map = {},
|
i = 0;
|
|
if ( jQuery.isArray( name ) ) {
|
styles = getStyles( elem );
|
len = name.length;
|
|
for ( ; i < len; i++ ) {
|
map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
|
}
|
|
return map;
|
}
|
|
return value !== undefined ?
|
jQuery.style( elem, name, value ) :
|
jQuery.css( elem, name );
|
}, name, value, arguments.length > 1 );
|
},
|
show: function() {
|
return showHide( this, true );
|
},
|
hide: function() {
|
return showHide( this );
|
},
|
toggle: function( state ) {
|
if ( typeof state === "boolean" ) {
|
return state ? this.show() : this.hide();
|
}
|
|
return this.each( function() {
|
if ( isHidden( this ) ) {
|
jQuery( this ).show();
|
} else {
|
jQuery( this ).hide();
|
}
|
} );
|
}
|
} );
|
|
|
function Tween( elem, options, prop, end, easing ) {
|
return new Tween.prototype.init( elem, options, prop, end, easing );
|
}
|
jQuery.Tween = Tween;
|
|
Tween.prototype = {
|
constructor: Tween,
|
init: function( elem, options, prop, end, easing, unit ) {
|
this.elem = elem;
|
this.prop = prop;
|
this.easing = easing || jQuery.easing._default;
|
this.options = options;
|
this.start = this.now = this.cur();
|
this.end = end;
|
this.unit = unit || ( jQuery.cssNumber[ prop ] ? "" : "px" );
|
},
|
cur: function() {
|
var hooks = Tween.propHooks[ this.prop ];
|
|
return hooks && hooks.get ?
|
hooks.get( this ) :
|
Tween.propHooks._default.get( this );
|
},
|
run: function( percent ) {
|
var eased,
|
hooks = Tween.propHooks[ this.prop ];
|
|
if ( this.options.duration ) {
|
this.pos = eased = jQuery.easing[ this.easing ](
|
percent, this.options.duration * percent, 0, 1, this.options.duration
|
);
|
} else {
|
this.pos = eased = percent;
|
}
|
this.now = ( this.end - this.start ) * eased + this.start;
|
|
if ( this.options.step ) {
|
this.options.step.call( this.elem, this.now, this );
|
}
|
|
if ( hooks && hooks.set ) {
|
hooks.set( this );
|
} else {
|
Tween.propHooks._default.set( this );
|
}
|
return this;
|
}
|
};
|
|
Tween.prototype.init.prototype = Tween.prototype;
|
|
Tween.propHooks = {
|
_default: {
|
get: function( tween ) {
|
var result;
|
|
// Use a property on the element directly when it is not a DOM element,
|
// or when there is no matching style property that exists.
|
if ( tween.elem.nodeType !== 1 ||
|
tween.elem[ tween.prop ] != null && tween.elem.style[ tween.prop ] == null ) {
|
return tween.elem[ tween.prop ];
|
}
|
|
// Passing an empty string as a 3rd parameter to .css will automatically
|
// attempt a parseFloat and fallback to a string if the parse fails.
|
// Simple values such as "10px" are parsed to Float;
|
// complex values such as "rotate(1rad)" are returned as-is.
|
result = jQuery.css( tween.elem, tween.prop, "" );
|
|
// Empty strings, null, undefined and "auto" are converted to 0.
|
return !result || result === "auto" ? 0 : result;
|
},
|
set: function( tween ) {
|
|
// Use step hook for back compat.
|
// Use cssHook if its there.
|
// Use .style if available and use plain properties where available.
|
if ( jQuery.fx.step[ tween.prop ] ) {
|
jQuery.fx.step[ tween.prop ]( tween );
|
} else if ( tween.elem.nodeType === 1 &&
|
( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null ||
|
jQuery.cssHooks[ tween.prop ] ) ) {
|
jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
|
} else {
|
tween.elem[ tween.prop ] = tween.now;
|
}
|
}
|
}
|
};
|
|
// Support: IE9
|
// Panic based approach to setting things on disconnected nodes
|
Tween.propHooks.scrollTop = Tween.propHooks.scrollLeft = {
|
set: function( tween ) {
|
if ( tween.elem.nodeType && tween.elem.parentNode ) {
|
tween.elem[ tween.prop ] = tween.now;
|
}
|
}
|
};
|
|
jQuery.easing = {
|
linear: function( p ) {
|
return p;
|
},
|
swing: function( p ) {
|
return 0.5 - Math.cos( p * Math.PI ) / 2;
|
},
|
_default: "swing"
|
};
|
|
jQuery.fx = Tween.prototype.init;
|
|
// Back Compat <1.8 extension point
|
jQuery.fx.step = {};
|
|
|
|
|
var
|
fxNow, timerId,
|
rfxtypes = /^(?:toggle|show|hide)$/,
|
rrun = /queueHooks$/;
|
|
// Animations created synchronously will run synchronously
|
function createFxNow() {
|
window.setTimeout( function() {
|
fxNow = undefined;
|
} );
|
return ( fxNow = jQuery.now() );
|
}
|
|
// Generate parameters to create a standard animation
|
function genFx( type, includeWidth ) {
|
var which,
|
i = 0,
|
attrs = { height: type };
|
|
// If we include width, step value is 1 to do all cssExpand values,
|
// otherwise step value is 2 to skip over Left and Right
|
includeWidth = includeWidth ? 1 : 0;
|
for ( ; i < 4 ; i += 2 - includeWidth ) {
|
which = cssExpand[ i ];
|
attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
|
}
|
|
if ( includeWidth ) {
|
attrs.opacity = attrs.width = type;
|
}
|
|
return attrs;
|
}
|
|
function createTween( value, prop, animation ) {
|
var tween,
|
collection = ( Animation.tweeners[ prop ] || [] ).concat( Animation.tweeners[ "*" ] ),
|
index = 0,
|
length = collection.length;
|
for ( ; index < length; index++ ) {
|
if ( ( tween = collection[ index ].call( animation, prop, value ) ) ) {
|
|
// We're done with this property
|
return tween;
|
}
|
}
|
}
|
|
function defaultPrefilter( elem, props, opts ) {
|
/* jshint validthis: true */
|
var prop, value, toggle, tween, hooks, oldfire, display, checkDisplay,
|
anim = this,
|
orig = {},
|
style = elem.style,
|
hidden = elem.nodeType && isHidden( elem ),
|
dataShow = dataPriv.get( elem, "fxshow" );
|
|
// Handle queue: false promises
|
if ( !opts.queue ) {
|
hooks = jQuery._queueHooks( elem, "fx" );
|
if ( hooks.unqueued == null ) {
|
hooks.unqueued = 0;
|
oldfire = hooks.empty.fire;
|
hooks.empty.fire = function() {
|
if ( !hooks.unqueued ) {
|
oldfire();
|
}
|
};
|
}
|
hooks.unqueued++;
|
|
anim.always( function() {
|
|
// Ensure the complete handler is called before this completes
|
anim.always( function() {
|
hooks.unqueued--;
|
if ( !jQuery.queue( elem, "fx" ).length ) {
|
hooks.empty.fire();
|
}
|
} );
|
} );
|
}
|
|
// Height/width overflow pass
|
if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
|
|
// Make sure that nothing sneaks out
|
// Record all 3 overflow attributes because IE9-10 do not
|
// change the overflow attribute when overflowX and
|
// overflowY are set to the same value
|
opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
|
|
// Set display property to inline-block for height/width
|
// animations on inline elements that are having width/height animated
|
display = jQuery.css( elem, "display" );
|
|
// Test default display if display is currently "none"
|
checkDisplay = display === "none" ?
|
dataPriv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display;
|
|
if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) {
|
style.display = "inline-block";
|
}
|
}
|
|
if ( opts.overflow ) {
|
style.overflow = "hidden";
|
anim.always( function() {
|
style.overflow = opts.overflow[ 0 ];
|
style.overflowX = opts.overflow[ 1 ];
|
style.overflowY = opts.overflow[ 2 ];
|
} );
|
}
|
|
// show/hide pass
|
for ( prop in props ) {
|
value = props[ prop ];
|
if ( rfxtypes.exec( value ) ) {
|
delete props[ prop ];
|
toggle = toggle || value === "toggle";
|
if ( value === ( hidden ? "hide" : "show" ) ) {
|
|
// If there is dataShow left over from a stopped hide or show
|
// and we are going to proceed with show, we should pretend to be hidden
|
if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
|
hidden = true;
|
} else {
|
continue;
|
}
|
}
|
orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
|
|
// Any non-fx value stops us from restoring the original display value
|
} else {
|
display = undefined;
|
}
|
}
|
|
if ( !jQuery.isEmptyObject( orig ) ) {
|
if ( dataShow ) {
|
if ( "hidden" in dataShow ) {
|
hidden = dataShow.hidden;
|
}
|
} else {
|
dataShow = dataPriv.access( elem, "fxshow", {} );
|
}
|
|
// Store state if its toggle - enables .stop().toggle() to "reverse"
|
if ( toggle ) {
|
dataShow.hidden = !hidden;
|
}
|
if ( hidden ) {
|
jQuery( elem ).show();
|
} else {
|
anim.done( function() {
|
jQuery( elem ).hide();
|
} );
|
}
|
anim.done( function() {
|
var prop;
|
|
dataPriv.remove( elem, "fxshow" );
|
for ( prop in orig ) {
|
jQuery.style( elem, prop, orig[ prop ] );
|
}
|
} );
|
for ( prop in orig ) {
|
tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
|
|
if ( !( prop in dataShow ) ) {
|
dataShow[ prop ] = tween.start;
|
if ( hidden ) {
|
tween.end = tween.start;
|
tween.start = prop === "width" || prop === "height" ? 1 : 0;
|
}
|
}
|
}
|
|
// If this is a noop like .hide().hide(), restore an overwritten display value
|
} else if ( ( display === "none" ? defaultDisplay( elem.nodeName ) : display ) === "inline" ) {
|
style.display = display;
|
}
|
}
|
|
function propFilter( props, specialEasing ) {
|
var index, name, easing, value, hooks;
|
|
// camelCase, specialEasing and expand cssHook pass
|
for ( index in props ) {
|
name = jQuery.camelCase( index );
|
easing = specialEasing[ name ];
|
value = props[ index ];
|
if ( jQuery.isArray( value ) ) {
|
easing = value[ 1 ];
|
value = props[ index ] = value[ 0 ];
|
}
|
|
if ( index !== name ) {
|
props[ name ] = value;
|
delete props[ index ];
|
}
|
|
hooks = jQuery.cssHooks[ name ];
|
if ( hooks && "expand" in hooks ) {
|
value = hooks.expand( value );
|
delete props[ name ];
|
|
// Not quite $.extend, this won't overwrite existing keys.
|
// Reusing 'index' because we have the correct "name"
|
for ( index in value ) {
|
if ( !( index in props ) ) {
|
props[ index ] = value[ index ];
|
specialEasing[ index ] = easing;
|
}
|
}
|
} else {
|
specialEasing[ name ] = easing;
|
}
|
}
|
}
|
|
function Animation( elem, properties, options ) {
|
var result,
|
stopped,
|
index = 0,
|
length = Animation.prefilters.length,
|
deferred = jQuery.Deferred().always( function() {
|
|
// Don't match elem in the :animated selector
|
delete tick.elem;
|
} ),
|
tick = function() {
|
if ( stopped ) {
|
return false;
|
}
|
var currentTime = fxNow || createFxNow(),
|
remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
|
|
// Support: Android 2.3
|
// Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
|
temp = remaining / animation.duration || 0,
|
percent = 1 - temp,
|
index = 0,
|
length = animation.tweens.length;
|
|
for ( ; index < length ; index++ ) {
|
animation.tweens[ index ].run( percent );
|
}
|
|
deferred.notifyWith( elem, [ animation, percent, remaining ] );
|
|
if ( percent < 1 && length ) {
|
return remaining;
|
} else {
|
deferred.resolveWith( elem, [ animation ] );
|
return false;
|
}
|
},
|
animation = deferred.promise( {
|
elem: elem,
|
props: jQuery.extend( {}, properties ),
|
opts: jQuery.extend( true, {
|
specialEasing: {},
|
easing: jQuery.easing._default
|
}, options ),
|
originalProperties: properties,
|
originalOptions: options,
|
startTime: fxNow || createFxNow(),
|
duration: options.duration,
|
tweens: [],
|
createTween: function( prop, end ) {
|
var tween = jQuery.Tween( elem, animation.opts, prop, end,
|
animation.opts.specialEasing[ prop ] || animation.opts.easing );
|
animation.tweens.push( tween );
|
return tween;
|
},
|
stop: function( gotoEnd ) {
|
var index = 0,
|
|
// If we are going to the end, we want to run all the tweens
|
// otherwise we skip this part
|
length = gotoEnd ? animation.tweens.length : 0;
|
if ( stopped ) {
|
return this;
|
}
|
stopped = true;
|
for ( ; index < length ; index++ ) {
|
animation.tweens[ index ].run( 1 );
|
}
|
|
// Resolve when we played the last frame; otherwise, reject
|
if ( gotoEnd ) {
|
deferred.notifyWith( elem, [ animation, 1, 0 ] );
|
deferred.resolveWith( elem, [ animation, gotoEnd ] );
|
} else {
|
deferred.rejectWith( elem, [ animation, gotoEnd ] );
|
}
|
return this;
|
}
|
} ),
|
props = animation.props;
|
|
propFilter( props, animation.opts.specialEasing );
|
|
for ( ; index < length ; index++ ) {
|
result = Animation.prefilters[ index ].call( animation, elem, props, animation.opts );
|
if ( result ) {
|
if ( jQuery.isFunction( result.stop ) ) {
|
jQuery._queueHooks( animation.elem, animation.opts.queue ).stop =
|
jQuery.proxy( result.stop, result );
|
}
|
return result;
|
}
|
}
|
|
jQuery.map( props, createTween, animation );
|
|
if ( jQuery.isFunction( animation.opts.start ) ) {
|
animation.opts.start.call( elem, animation );
|
}
|
|
jQuery.fx.timer(
|
jQuery.extend( tick, {
|
elem: elem,
|
anim: animation,
|
queue: animation.opts.queue
|
} )
|
);
|
|
// attach callbacks from options
|
return animation.progress( animation.opts.progress )
|
.done( animation.opts.done, animation.opts.complete )
|
.fail( animation.opts.fail )
|
.always( animation.opts.always );
|
}
|
|
jQuery.Animation = jQuery.extend( Animation, {
|
tweeners: {
|
"*": [ function( prop, value ) {
|
var tween = this.createTween( prop, value );
|
adjustCSS( tween.elem, prop, rcssNum.exec( value ), tween );
|
return tween;
|
} ]
|
},
|
|
tweener: function( props, callback ) {
|
if ( jQuery.isFunction( props ) ) {
|
callback = props;
|
props = [ "*" ];
|
} else {
|
props = props.match( rnotwhite );
|
}
|
|
var prop,
|
index = 0,
|
length = props.length;
|
|
for ( ; index < length ; index++ ) {
|
prop = props[ index ];
|
Animation.tweeners[ prop ] = Animation.tweeners[ prop ] || [];
|
Animation.tweeners[ prop ].unshift( callback );
|
}
|
},
|
|
prefilters: [ defaultPrefilter ],
|
|
prefilter: function( callback, prepend ) {
|
if ( prepend ) {
|
Animation.prefilters.unshift( callback );
|
} else {
|
Animation.prefilters.push( callback );
|
}
|
}
|
} );
|
|
jQuery.speed = function( speed, easing, fn ) {
|
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
|
complete: fn || !fn && easing ||
|
jQuery.isFunction( speed ) && speed,
|
duration: speed,
|
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
|
};
|
|
opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ?
|
opt.duration : opt.duration in jQuery.fx.speeds ?
|
jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default;
|
|
// Normalize opt.queue - true/undefined/null -> "fx"
|
if ( opt.queue == null || opt.queue === true ) {
|
opt.queue = "fx";
|
}
|
|
// Queueing
|
opt.old = opt.complete;
|
|
opt.complete = function() {
|
if ( jQuery.isFunction( opt.old ) ) {
|
opt.old.call( this );
|
}
|
|
if ( opt.queue ) {
|
jQuery.dequeue( this, opt.queue );
|
}
|
};
|
|
return opt;
|
};
|
|
jQuery.fn.extend( {
|
fadeTo: function( speed, to, easing, callback ) {
|
|
// Show any hidden elements after setting opacity to 0
|
return this.filter( isHidden ).css( "opacity", 0 ).show()
|
|
// Animate to the value specified
|
.end().animate( { opacity: to }, speed, easing, callback );
|
},
|
animate: function( prop, speed, easing, callback ) {
|
var empty = jQuery.isEmptyObject( prop ),
|
optall = jQuery.speed( speed, easing, callback ),
|
doAnimation = function() {
|
|
// Operate on a copy of prop so per-property easing won't be lost
|
var anim = Animation( this, jQuery.extend( {}, prop ), optall );
|
|
// Empty animations, or finishing resolves immediately
|
if ( empty || dataPriv.get( this, "finish" ) ) {
|
anim.stop( true );
|
}
|
};
|
doAnimation.finish = doAnimation;
|
|
return empty || optall.queue === false ?
|
this.each( doAnimation ) :
|
this.queue( optall.queue, doAnimation );
|
},
|
stop: function( type, clearQueue, gotoEnd ) {
|
var stopQueue = function( hooks ) {
|
var stop = hooks.stop;
|
delete hooks.stop;
|
stop( gotoEnd );
|
};
|
|
if ( typeof type !== "string" ) {
|
gotoEnd = clearQueue;
|
clearQueue = type;
|
type = undefined;
|
}
|
if ( clearQueue && type !== false ) {
|
this.queue( type || "fx", [] );
|
}
|
|
return this.each( function() {
|
var dequeue = true,
|
index = type != null && type + "queueHooks",
|
timers = jQuery.timers,
|
data = dataPriv.get( this );
|
|
if ( index ) {
|
if ( data[ index ] && data[ index ].stop ) {
|
stopQueue( data[ index ] );
|
}
|
} else {
|
for ( index in data ) {
|
if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
|
stopQueue( data[ index ] );
|
}
|
}
|
}
|
|
for ( index = timers.length; index--; ) {
|
if ( timers[ index ].elem === this &&
|
( type == null || timers[ index ].queue === type ) ) {
|
|
timers[ index ].anim.stop( gotoEnd );
|
dequeue = false;
|
timers.splice( index, 1 );
|
}
|
}
|
|
// Start the next in the queue if the last step wasn't forced.
|
// Timers currently will call their complete callbacks, which
|
// will dequeue but only if they were gotoEnd.
|
if ( dequeue || !gotoEnd ) {
|
jQuery.dequeue( this, type );
|
}
|
} );
|
},
|
finish: function( type ) {
|
if ( type !== false ) {
|
type = type || "fx";
|
}
|
return this.each( function() {
|
var index,
|
data = dataPriv.get( this ),
|
queue = data[ type + "queue" ],
|
hooks = data[ type + "queueHooks" ],
|
timers = jQuery.timers,
|
length = queue ? queue.length : 0;
|
|
// Enable finishing flag on private data
|
data.finish = true;
|
|
// Empty the queue first
|
jQuery.queue( this, type, [] );
|
|
if ( hooks && hooks.stop ) {
|
hooks.stop.call( this, true );
|
}
|
|
// Look for any active animations, and finish them
|
for ( index = timers.length; index--; ) {
|
if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
|
timers[ index ].anim.stop( true );
|
timers.splice( index, 1 );
|
}
|
}
|
|
// Look for any animations in the old queue and finish them
|
for ( index = 0; index < length; index++ ) {
|
if ( queue[ index ] && queue[ index ].finish ) {
|
queue[ index ].finish.call( this );
|
}
|
}
|
|
// Turn off finishing flag
|
delete data.finish;
|
} );
|
}
|
} );
|
|
jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) {
|
var cssFn = jQuery.fn[ name ];
|
jQuery.fn[ name ] = function( speed, easing, callback ) {
|
return speed == null || typeof speed === "boolean" ?
|
cssFn.apply( this, arguments ) :
|
this.animate( genFx( name, true ), speed, easing, callback );
|
};
|
} );
|
|
// Generate shortcuts for custom animations
|
jQuery.each( {
|
slideDown: genFx( "show" ),
|
slideUp: genFx( "hide" ),
|
slideToggle: genFx( "toggle" ),
|
fadeIn: { opacity: "show" },
|
fadeOut: { opacity: "hide" },
|
fadeToggle: { opacity: "toggle" }
|
}, function( name, props ) {
|
jQuery.fn[ name ] = function( speed, easing, callback ) {
|
return this.animate( props, speed, easing, callback );
|
};
|
} );
|
|
jQuery.timers = [];
|
jQuery.fx.tick = function() {
|
var timer,
|
i = 0,
|
timers = jQuery.timers;
|
|
fxNow = jQuery.now();
|
|
for ( ; i < timers.length; i++ ) {
|
timer = timers[ i ];
|
|
// Checks the timer has not already been removed
|
if ( !timer() && timers[ i ] === timer ) {
|
timers.splice( i--, 1 );
|
}
|
}
|
|
if ( !timers.length ) {
|
jQuery.fx.stop();
|
}
|
fxNow = undefined;
|
};
|
|
jQuery.fx.timer = function( timer ) {
|
jQuery.timers.push( timer );
|
if ( timer() ) {
|
jQuery.fx.start();
|
} else {
|
jQuery.timers.pop();
|
}
|
};
|
|
jQuery.fx.interval = 13;
|
jQuery.fx.start = function() {
|
if ( !timerId ) {
|
timerId = window.setInterval( jQuery.fx.tick, jQuery.fx.interval );
|
}
|
};
|
|
jQuery.fx.stop = function() {
|
window.clearInterval( timerId );
|
|
timerId = null;
|
};
|
|
jQuery.fx.speeds = {
|
slow: 600,
|
fast: 200,
|
|
// Default speed
|
_default: 400
|
};
|
|
|
// Based off of the plugin by Clint Helfers, with permission.
|
// http://web.archive.org/web/20100324014747/http://blindsignals.com/index.php/2009/07/jquery-delay/
|
jQuery.fn.delay = function( time, type ) {
|
time = jQuery.fx ? jQuery.fx.speeds[ time ] || time : time;
|
type = type || "fx";
|
|
return this.queue( type, function( next, hooks ) {
|
var timeout = window.setTimeout( next, time );
|
hooks.stop = function() {
|
window.clearTimeout( timeout );
|
};
|
} );
|
};
|
|
|
( function() {
|
var input = document.createElement( "input" ),
|
select = document.createElement( "select" ),
|
opt = select.appendChild( document.createElement( "option" ) );
|
|
input.type = "checkbox";
|
|
// Support: iOS<=5.1, Android<=4.2+
|
// Default value for a checkbox should be "on"
|
support.checkOn = input.value !== "";
|
|
// Support: IE<=11+
|
// Must access selectedIndex to make default options select
|
support.optSelected = opt.selected;
|
|
// Support: Android<=2.3
|
// Options inside disabled selects are incorrectly marked as disabled
|
select.disabled = true;
|
support.optDisabled = !opt.disabled;
|
|
// Support: IE<=11+
|
// An input loses its value after becoming a radio
|
input = document.createElement( "input" );
|
input.value = "t";
|
input.type = "radio";
|
support.radioValue = input.value === "t";
|
} )();
|
|
|
var boolHook,
|
attrHandle = jQuery.expr.attrHandle;
|
|
jQuery.fn.extend( {
|
attr: function( name, value ) {
|
return access( this, jQuery.attr, name, value, arguments.length > 1 );
|
},
|
|
removeAttr: function( name ) {
|
return this.each( function() {
|
jQuery.removeAttr( this, name );
|
} );
|
}
|
} );
|
|
jQuery.extend( {
|
attr: function( elem, name, value ) {
|
var ret, hooks,
|
nType = elem.nodeType;
|
|
// Don't get/set attributes on text, comment and attribute nodes
|
if ( nType === 3 || nType === 8 || nType === 2 ) {
|
return;
|
}
|
|
// Fallback to prop when attributes are not supported
|
if ( typeof elem.getAttribute === "undefined" ) {
|
return jQuery.prop( elem, name, value );
|
}
|
|
// All attributes are lowercase
|
// Grab necessary hook if one is defined
|
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
|
name = name.toLowerCase();
|
hooks = jQuery.attrHooks[ name ] ||
|
( jQuery.expr.match.bool.test( name ) ? boolHook : undefined );
|
}
|
|
if ( value !== undefined ) {
|
if ( value === null ) {
|
jQuery.removeAttr( elem, name );
|
return;
|
}
|
|
if ( hooks && "set" in hooks &&
|
( ret = hooks.set( elem, value, name ) ) !== undefined ) {
|
return ret;
|
}
|
|
elem.setAttribute( name, value + "" );
|
return value;
|
}
|
|
if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
|
return ret;
|
}
|
|
ret = jQuery.find.attr( elem, name );
|
|
// Non-existent attributes return null, we normalize to undefined
|
return ret == null ? undefined : ret;
|
},
|
|
attrHooks: {
|
type: {
|
set: function( elem, value ) {
|
if ( !support.radioValue && value === "radio" &&
|
jQuery.nodeName( elem, "input" ) ) {
|
var val = elem.value;
|
elem.setAttribute( "type", value );
|
if ( val ) {
|
elem.value = val;
|
}
|
return value;
|
}
|
}
|
}
|
},
|
|
removeAttr: function( elem, value ) {
|
var name, propName,
|
i = 0,
|
attrNames = value && value.match( rnotwhite );
|
|
if ( attrNames && elem.nodeType === 1 ) {
|
while ( ( name = attrNames[ i++ ] ) ) {
|
propName = jQuery.propFix[ name ] || name;
|
|
// Boolean attributes get special treatment (#10870)
|
if ( jQuery.expr.match.bool.test( name ) ) {
|
|
// Set corresponding property to false
|
elem[ propName ] = false;
|
}
|
|
elem.removeAttribute( name );
|
}
|
}
|
}
|
} );
|
|
// Hooks for boolean attributes
|
boolHook = {
|
set: function( elem, value, name ) {
|
if ( value === false ) {
|
|
// Remove boolean attributes when set to false
|
jQuery.removeAttr( elem, name );
|
} else {
|
elem.setAttribute( name, name );
|
}
|
return name;
|
}
|
};
|
jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
|
var getter = attrHandle[ name ] || jQuery.find.attr;
|
|
attrHandle[ name ] = function( elem, name, isXML ) {
|
var ret, handle;
|
if ( !isXML ) {
|
|
// Avoid an infinite loop by temporarily removing this function from the getter
|
handle = attrHandle[ name ];
|
attrHandle[ name ] = ret;
|
ret = getter( elem, name, isXML ) != null ?
|
name.toLowerCase() :
|
null;
|
attrHandle[ name ] = handle;
|
}
|
return ret;
|
};
|
} );
|
|
|
|
|
var rfocusable = /^(?:input|select|textarea|button)$/i,
|
rclickable = /^(?:a|area)$/i;
|
|
jQuery.fn.extend( {
|
prop: function( name, value ) {
|
return access( this, jQuery.prop, name, value, arguments.length > 1 );
|
},
|
|
removeProp: function( name ) {
|
return this.each( function() {
|
delete this[ jQuery.propFix[ name ] || name ];
|
} );
|
}
|
} );
|
|
jQuery.extend( {
|
prop: function( elem, name, value ) {
|
var ret, hooks,
|
nType = elem.nodeType;
|
|
// Don't get/set properties on text, comment and attribute nodes
|
if ( nType === 3 || nType === 8 || nType === 2 ) {
|
return;
|
}
|
|
if ( nType !== 1 || !jQuery.isXMLDoc( elem ) ) {
|
|
// Fix name and attach hooks
|
name = jQuery.propFix[ name ] || name;
|
hooks = jQuery.propHooks[ name ];
|
}
|
|
if ( value !== undefined ) {
|
if ( hooks && "set" in hooks &&
|
( ret = hooks.set( elem, value, name ) ) !== undefined ) {
|
return ret;
|
}
|
|
return ( elem[ name ] = value );
|
}
|
|
if ( hooks && "get" in hooks && ( ret = hooks.get( elem, name ) ) !== null ) {
|
return ret;
|
}
|
|
return elem[ name ];
|
},
|
|
propHooks: {
|
tabIndex: {
|
get: function( elem ) {
|
|
// elem.tabIndex doesn't always return the
|
// correct value when it hasn't been explicitly set
|
// http://fluidproject.org/blog/2008/01/09/getting-setting-and-removing-tabindex-values-with-javascript/
|
// Use proper attribute retrieval(#12072)
|
var tabindex = jQuery.find.attr( elem, "tabindex" );
|
|
return tabindex ?
|
parseInt( tabindex, 10 ) :
|
rfocusable.test( elem.nodeName ) ||
|
rclickable.test( elem.nodeName ) && elem.href ?
|
0 :
|
-1;
|
}
|
}
|
},
|
|
propFix: {
|
"for": "htmlFor",
|
"class": "className"
|
}
|
} );
|
|
// Support: IE <=11 only
|
// Accessing the selectedIndex property
|
// forces the browser to respect setting selected
|
// on the option
|
// The getter ensures a default option is selected
|
// when in an optgroup
|
if ( !support.optSelected ) {
|
jQuery.propHooks.selected = {
|
get: function( elem ) {
|
var parent = elem.parentNode;
|
if ( parent && parent.parentNode ) {
|
parent.parentNode.selectedIndex;
|
}
|
return null;
|
},
|
set: function( elem ) {
|
var parent = elem.parentNode;
|
if ( parent ) {
|
parent.selectedIndex;
|
|
if ( parent.parentNode ) {
|
parent.parentNode.selectedIndex;
|
}
|
}
|
}
|
};
|
}
|
|
jQuery.each( [
|
"tabIndex",
|
"readOnly",
|
"maxLength",
|
"cellSpacing",
|
"cellPadding",
|
"rowSpan",
|
"colSpan",
|
"useMap",
|
"frameBorder",
|
"contentEditable"
|
], function() {
|
jQuery.propFix[ this.toLowerCase() ] = this;
|
} );
|
|
|
|
|
var rclass = /[\t\r\n\f]/g;
|
|
function getClass( elem ) {
|
return elem.getAttribute && elem.getAttribute( "class" ) || "";
|
}
|
|
jQuery.fn.extend( {
|
addClass: function( value ) {
|
var classes, elem, cur, curValue, clazz, j, finalValue,
|
i = 0;
|
|
if ( jQuery.isFunction( value ) ) {
|
return this.each( function( j ) {
|
jQuery( this ).addClass( value.call( this, j, getClass( this ) ) );
|
} );
|
}
|
|
if ( typeof value === "string" && value ) {
|
classes = value.match( rnotwhite ) || [];
|
|
while ( ( elem = this[ i++ ] ) ) {
|
curValue = getClass( elem );
|
cur = elem.nodeType === 1 &&
|
( " " + curValue + " " ).replace( rclass, " " );
|
|
if ( cur ) {
|
j = 0;
|
while ( ( clazz = classes[ j++ ] ) ) {
|
if ( cur.indexOf( " " + clazz + " " ) < 0 ) {
|
cur += clazz + " ";
|
}
|
}
|
|
// Only assign if different to avoid unneeded rendering.
|
finalValue = jQuery.trim( cur );
|
if ( curValue !== finalValue ) {
|
elem.setAttribute( "class", finalValue );
|
}
|
}
|
}
|
}
|
|
return this;
|
},
|
|
removeClass: function( value ) {
|
var classes, elem, cur, curValue, clazz, j, finalValue,
|
i = 0;
|
|
if ( jQuery.isFunction( value ) ) {
|
return this.each( function( j ) {
|
jQuery( this ).removeClass( value.call( this, j, getClass( this ) ) );
|
} );
|
}
|
|
if ( !arguments.length ) {
|
return this.attr( "class", "" );
|
}
|
|
if ( typeof value === "string" && value ) {
|
classes = value.match( rnotwhite ) || [];
|
|
while ( ( elem = this[ i++ ] ) ) {
|
curValue = getClass( elem );
|
|
// This expression is here for better compressibility (see addClass)
|
cur = elem.nodeType === 1 &&
|
( " " + curValue + " " ).replace( rclass, " " );
|
|
if ( cur ) {
|
j = 0;
|
while ( ( clazz = classes[ j++ ] ) ) {
|
|
// Remove *all* instances
|
while ( cur.indexOf( " " + clazz + " " ) > -1 ) {
|
cur = cur.replace( " " + clazz + " ", " " );
|
}
|
}
|
|
// Only assign if different to avoid unneeded rendering.
|
finalValue = jQuery.trim( cur );
|
if ( curValue !== finalValue ) {
|
elem.setAttribute( "class", finalValue );
|
}
|
}
|
}
|
}
|
|
return this;
|
},
|
|
toggleClass: function( value, stateVal ) {
|
var type = typeof value;
|
|
if ( typeof stateVal === "boolean" && type === "string" ) {
|
return stateVal ? this.addClass( value ) : this.removeClass( value );
|
}
|
|
if ( jQuery.isFunction( value ) ) {
|
return this.each( function( i ) {
|
jQuery( this ).toggleClass(
|
value.call( this, i, getClass( this ), stateVal ),
|
stateVal
|
);
|
} );
|
}
|
|
return this.each( function() {
|
var className, i, self, classNames;
|
|
if ( type === "string" ) {
|
|
// Toggle individual class names
|
i = 0;
|
self = jQuery( this );
|
classNames = value.match( rnotwhite ) || [];
|
|
while ( ( className = classNames[ i++ ] ) ) {
|
|
// Check each className given, space separated list
|
if ( self.hasClass( className ) ) {
|
self.removeClass( className );
|
} else {
|
self.addClass( className );
|
}
|
}
|
|
// Toggle whole class name
|
} else if ( value === undefined || type === "boolean" ) {
|
className = getClass( this );
|
if ( className ) {
|
|
// Store className if set
|
dataPriv.set( this, "__className__", className );
|
}
|
|
// If the element has a class name or if we're passed `false`,
|
// then remove the whole classname (if there was one, the above saved it).
|
// Otherwise bring back whatever was previously saved (if anything),
|
// falling back to the empty string if nothing was stored.
|
if ( this.setAttribute ) {
|
this.setAttribute( "class",
|
className || value === false ?
|
"" :
|
dataPriv.get( this, "__className__" ) || ""
|
);
|
}
|
}
|
} );
|
},
|
|
hasClass: function( selector ) {
|
var className, elem,
|
i = 0;
|
|
className = " " + selector + " ";
|
while ( ( elem = this[ i++ ] ) ) {
|
if ( elem.nodeType === 1 &&
|
( " " + getClass( elem ) + " " ).replace( rclass, " " )
|
.indexOf( className ) > -1
|
) {
|
return true;
|
}
|
}
|
|
return false;
|
}
|
} );
|
|
|
|
|
var rreturn = /\r/g,
|
rspaces = /[\x20\t\r\n\f]+/g;
|
|
jQuery.fn.extend( {
|
val: function( value ) {
|
var hooks, ret, isFunction,
|
elem = this[ 0 ];
|
|
if ( !arguments.length ) {
|
if ( elem ) {
|
hooks = jQuery.valHooks[ elem.type ] ||
|
jQuery.valHooks[ elem.nodeName.toLowerCase() ];
|
|
if ( hooks &&
|
"get" in hooks &&
|
( ret = hooks.get( elem, "value" ) ) !== undefined
|
) {
|
return ret;
|
}
|
|
ret = elem.value;
|
|
return typeof ret === "string" ?
|
|
// Handle most common string cases
|
ret.replace( rreturn, "" ) :
|
|
// Handle cases where value is null/undef or number
|
ret == null ? "" : ret;
|
}
|
|
return;
|
}
|
|
isFunction = jQuery.isFunction( value );
|
|
return this.each( function( i ) {
|
var val;
|
|
if ( this.nodeType !== 1 ) {
|
return;
|
}
|
|
if ( isFunction ) {
|
val = value.call( this, i, jQuery( this ).val() );
|
} else {
|
val = value;
|
}
|
|
// Treat null/undefined as ""; convert numbers to string
|
if ( val == null ) {
|
val = "";
|
|
} else if ( typeof val === "number" ) {
|
val += "";
|
|
} else if ( jQuery.isArray( val ) ) {
|
val = jQuery.map( val, function( value ) {
|
return value == null ? "" : value + "";
|
} );
|
}
|
|
hooks = jQuery.valHooks[ this.type ] || jQuery.valHooks[ this.nodeName.toLowerCase() ];
|
|
// If set returns undefined, fall back to normal setting
|
if ( !hooks || !( "set" in hooks ) || hooks.set( this, val, "value" ) === undefined ) {
|
this.value = val;
|
}
|
} );
|
}
|
} );
|
|
jQuery.extend( {
|
valHooks: {
|
option: {
|
get: function( elem ) {
|
|
var val = jQuery.find.attr( elem, "value" );
|
return val != null ?
|
val :
|
|
// Support: IE10-11+
|
// option.text throws exceptions (#14686, #14858)
|
// Strip and collapse whitespace
|
// https://html.spec.whatwg.org/#strip-and-collapse-whitespace
|
jQuery.trim( jQuery.text( elem ) ).replace( rspaces, " " );
|
}
|
},
|
select: {
|
get: function( elem ) {
|
var value, option,
|
options = elem.options,
|
index = elem.selectedIndex,
|
one = elem.type === "select-one" || index < 0,
|
values = one ? null : [],
|
max = one ? index + 1 : options.length,
|
i = index < 0 ?
|
max :
|
one ? index : 0;
|
|
// Loop through all the selected options
|
for ( ; i < max; i++ ) {
|
option = options[ i ];
|
|
// IE8-9 doesn't update selected after form reset (#2551)
|
if ( ( option.selected || i === index ) &&
|
|
// Don't return options that are disabled or in a disabled optgroup
|
( support.optDisabled ?
|
!option.disabled : option.getAttribute( "disabled" ) === null ) &&
|
( !option.parentNode.disabled ||
|
!jQuery.nodeName( option.parentNode, "optgroup" ) ) ) {
|
|
// Get the specific value for the option
|
value = jQuery( option ).val();
|
|
// We don't need an array for one selects
|
if ( one ) {
|
return value;
|
}
|
|
// Multi-Selects return an array
|
values.push( value );
|
}
|
}
|
|
return values;
|
},
|
|
set: function( elem, value ) {
|
var optionSet, option,
|
options = elem.options,
|
values = jQuery.makeArray( value ),
|
i = options.length;
|
|
while ( i-- ) {
|
option = options[ i ];
|
if ( option.selected =
|
jQuery.inArray( jQuery.valHooks.option.get( option ), values ) > -1
|
) {
|
optionSet = true;
|
}
|
}
|
|
// Force browsers to behave consistently when non-matching value is set
|
if ( !optionSet ) {
|
elem.selectedIndex = -1;
|
}
|
return values;
|
}
|
}
|
}
|
} );
|
|
// Radios and checkboxes getter/setter
|
jQuery.each( [ "radio", "checkbox" ], function() {
|
jQuery.valHooks[ this ] = {
|
set: function( elem, value ) {
|
if ( jQuery.isArray( value ) ) {
|
return ( elem.checked = jQuery.inArray( jQuery( elem ).val(), value ) > -1 );
|
}
|
}
|
};
|
if ( !support.checkOn ) {
|
jQuery.valHooks[ this ].get = function( elem ) {
|
return elem.getAttribute( "value" ) === null ? "on" : elem.value;
|
};
|
}
|
} );
|
|
|
|
|
// Return jQuery for attributes-only inclusion
|
|
|
var rfocusMorph = /^(?:focusinfocus|focusoutblur)$/;
|
|
jQuery.extend( jQuery.event, {
|
|
trigger: function( event, data, elem, onlyHandlers ) {
|
|
var i, cur, tmp, bubbleType, ontype, handle, special,
|
eventPath = [ elem || document ],
|
type = hasOwn.call( event, "type" ) ? event.type : event,
|
namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split( "." ) : [];
|
|
cur = tmp = elem = elem || document;
|
|
// Don't do events on text and comment nodes
|
if ( elem.nodeType === 3 || elem.nodeType === 8 ) {
|
return;
|
}
|
|
// focus/blur morphs to focusin/out; ensure we're not firing them right now
|
if ( rfocusMorph.test( type + jQuery.event.triggered ) ) {
|
return;
|
}
|
|
if ( type.indexOf( "." ) > -1 ) {
|
|
// Namespaced trigger; create a regexp to match event type in handle()
|
namespaces = type.split( "." );
|
type = namespaces.shift();
|
namespaces.sort();
|
}
|
ontype = type.indexOf( ":" ) < 0 && "on" + type;
|
|
// Caller can pass in a jQuery.Event object, Object, or just an event type string
|
event = event[ jQuery.expando ] ?
|
event :
|
new jQuery.Event( type, typeof event === "object" && event );
|
|
// Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true)
|
event.isTrigger = onlyHandlers ? 2 : 3;
|
event.namespace = namespaces.join( "." );
|
event.rnamespace = event.namespace ?
|
new RegExp( "(^|\\.)" + namespaces.join( "\\.(?:.*\\.|)" ) + "(\\.|$)" ) :
|
null;
|
|
// Clean up the event in case it is being reused
|
event.result = undefined;
|
if ( !event.target ) {
|
event.target = elem;
|
}
|
|
// Clone any incoming data and prepend the event, creating the handler arg list
|
data = data == null ?
|
[ event ] :
|
jQuery.makeArray( data, [ event ] );
|
|
// Allow special events to draw outside the lines
|
special = jQuery.event.special[ type ] || {};
|
if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) {
|
return;
|
}
|
|
// Determine event propagation path in advance, per W3C events spec (#9951)
|
// Bubble up to document, then to window; watch for a global ownerDocument var (#9724)
|
if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) {
|
|
bubbleType = special.delegateType || type;
|
if ( !rfocusMorph.test( bubbleType + type ) ) {
|
cur = cur.parentNode;
|
}
|
for ( ; cur; cur = cur.parentNode ) {
|
eventPath.push( cur );
|
tmp = cur;
|
}
|
|
// Only add window if we got to document (e.g., not plain obj or detached DOM)
|
if ( tmp === ( elem.ownerDocument || document ) ) {
|
eventPath.push( tmp.defaultView || tmp.parentWindow || window );
|
}
|
}
|
|
// Fire handlers on the event path
|
i = 0;
|
while ( ( cur = eventPath[ i++ ] ) && !event.isPropagationStopped() ) {
|
|
event.type = i > 1 ?
|
bubbleType :
|
special.bindType || type;
|
|
// jQuery handler
|
handle = ( dataPriv.get( cur, "events" ) || {} )[ event.type ] &&
|
dataPriv.get( cur, "handle" );
|
if ( handle ) {
|
handle.apply( cur, data );
|
}
|
|
// Native handler
|
handle = ontype && cur[ ontype ];
|
if ( handle && handle.apply && acceptData( cur ) ) {
|
event.result = handle.apply( cur, data );
|
if ( event.result === false ) {
|
event.preventDefault();
|
}
|
}
|
}
|
event.type = type;
|
|
// If nobody prevented the default action, do it now
|
if ( !onlyHandlers && !event.isDefaultPrevented() ) {
|
|
if ( ( !special._default ||
|
special._default.apply( eventPath.pop(), data ) === false ) &&
|
acceptData( elem ) ) {
|
|
// Call a native DOM method on the target with the same name name as the event.
|
// Don't do default actions on window, that's where global variables be (#6170)
|
if ( ontype && jQuery.isFunction( elem[ type ] ) && !jQuery.isWindow( elem ) ) {
|
|
// Don't re-trigger an onFOO event when we call its FOO() method
|
tmp = elem[ ontype ];
|
|
if ( tmp ) {
|
elem[ ontype ] = null;
|
}
|
|
// Prevent re-triggering of the same event, since we already bubbled it above
|
jQuery.event.triggered = type;
|
elem[ type ]();
|
jQuery.event.triggered = undefined;
|
|
if ( tmp ) {
|
elem[ ontype ] = tmp;
|
}
|
}
|
}
|
}
|
|
return event.result;
|
},
|
|
// Piggyback on a donor event to simulate a different one
|
simulate: function( type, elem, event ) {
|
var e = jQuery.extend(
|
new jQuery.Event(),
|
event,
|
{
|
type: type,
|
isSimulated: true
|
|
// Previously, `originalEvent: {}` was set here, so stopPropagation call
|
// would not be triggered on donor event, since in our own
|
// jQuery.event.stopPropagation function we had a check for existence of
|
// originalEvent.stopPropagation method, so, consequently it would be a noop.
|
//
|
// But now, this "simulate" function is used only for events
|
// for which stopPropagation() is noop, so there is no need for that anymore.
|
//
|
// For the 1.x branch though, guard for "click" and "submit"
|
// events is still used, but was moved to jQuery.event.stopPropagation function
|
// because `originalEvent` should point to the original event for the constancy
|
// with other events and for more focused logic
|
}
|
);
|
|
jQuery.event.trigger( e, null, elem );
|
|
if ( e.isDefaultPrevented() ) {
|
event.preventDefault();
|
}
|
}
|
|
} );
|
|
jQuery.fn.extend( {
|
|
trigger: function( type, data ) {
|
return this.each( function() {
|
jQuery.event.trigger( type, data, this );
|
} );
|
},
|
triggerHandler: function( type, data ) {
|
var elem = this[ 0 ];
|
if ( elem ) {
|
return jQuery.event.trigger( type, data, elem, true );
|
}
|
}
|
} );
|
|
|
jQuery.each( ( "blur focus focusin focusout load resize scroll unload click dblclick " +
|
"mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave " +
|
"change select submit keydown keypress keyup error contextmenu" ).split( " " ),
|
function( i, name ) {
|
|
// Handle event binding
|
jQuery.fn[ name ] = function( data, fn ) {
|
return arguments.length > 0 ?
|
this.on( name, null, data, fn ) :
|
this.trigger( name );
|
};
|
} );
|
|
jQuery.fn.extend( {
|
hover: function( fnOver, fnOut ) {
|
return this.mouseenter( fnOver ).mouseleave( fnOut || fnOver );
|
}
|
} );
|
|
|
|
|
support.focusin = "onfocusin" in window;
|
|
|
// Support: Firefox
|
// Firefox doesn't have focus(in | out) events
|
// Related ticket - https://bugzilla.mozilla.org/show_bug.cgi?id=687787
|
//
|
// Support: Chrome, Safari
|
// focus(in | out) events fire after focus & blur events,
|
// which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order
|
// Related ticket - https://code.google.com/p/chromium/issues/detail?id=449857
|
if ( !support.focusin ) {
|
jQuery.each( { focus: "focusin", blur: "focusout" }, function( orig, fix ) {
|
|
// Attach a single capturing handler on the document while someone wants focusin/focusout
|
var handler = function( event ) {
|
jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ) );
|
};
|
|
jQuery.event.special[ fix ] = {
|
setup: function() {
|
var doc = this.ownerDocument || this,
|
attaches = dataPriv.access( doc, fix );
|
|
if ( !attaches ) {
|
doc.addEventListener( orig, handler, true );
|
}
|
dataPriv.access( doc, fix, ( attaches || 0 ) + 1 );
|
},
|
teardown: function() {
|
var doc = this.ownerDocument || this,
|
attaches = dataPriv.access( doc, fix ) - 1;
|
|
if ( !attaches ) {
|
doc.removeEventListener( orig, handler, true );
|
dataPriv.remove( doc, fix );
|
|
} else {
|
dataPriv.access( doc, fix, attaches );
|
}
|
}
|
};
|
} );
|
}
|
var location = window.location;
|
|
var nonce = jQuery.now();
|
|
var rquery = ( /\?/ );
|
|
|
|
// Support: Android 2.3
|
// Workaround failure to string-cast null input
|
jQuery.parseJSON = function( data ) {
|
return JSON.parse( data + "" );
|
};
|
|
|
// Cross-browser xml parsing
|
jQuery.parseXML = function( data ) {
|
var xml;
|
if ( !data || typeof data !== "string" ) {
|
return null;
|
}
|
|
// Support: IE9
|
try {
|
xml = ( new window.DOMParser() ).parseFromString( data, "text/xml" );
|
} catch ( e ) {
|
xml = undefined;
|
}
|
|
if ( !xml || xml.getElementsByTagName( "parsererror" ).length ) {
|
jQuery.error( "Invalid XML: " + data );
|
}
|
return xml;
|
};
|
|
|
var
|
rhash = /#.*$/,
|
rts = /([?&])_=[^&]*/,
|
rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg,
|
|
// #7653, #8125, #8152: local protocol detection
|
rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/,
|
rnoContent = /^(?:GET|HEAD)$/,
|
rprotocol = /^\/\//,
|
|
/* Prefilters
|
* 1) They are useful to introduce custom dataTypes (see ajax/jsonp.js for an example)
|
* 2) These are called:
|
* - BEFORE asking for a transport
|
* - AFTER param serialization (s.data is a string if s.processData is true)
|
* 3) key is the dataType
|
* 4) the catchall symbol "*" can be used
|
* 5) execution will start with transport dataType and THEN continue down to "*" if needed
|
*/
|
prefilters = {},
|
|
/* Transports bindings
|
* 1) key is the dataType
|
* 2) the catchall symbol "*" can be used
|
* 3) selection will start with transport dataType and THEN go to "*" if needed
|
*/
|
transports = {},
|
|
// Avoid comment-prolog char sequence (#10098); must appease lint and evade compression
|
allTypes = "*/".concat( "*" ),
|
|
// Anchor tag for parsing the document origin
|
originAnchor = document.createElement( "a" );
|
originAnchor.href = location.href;
|
|
// Base "constructor" for jQuery.ajaxPrefilter and jQuery.ajaxTransport
|
function addToPrefiltersOrTransports( structure ) {
|
|
// dataTypeExpression is optional and defaults to "*"
|
return function( dataTypeExpression, func ) {
|
|
if ( typeof dataTypeExpression !== "string" ) {
|
func = dataTypeExpression;
|
dataTypeExpression = "*";
|
}
|
|
var dataType,
|
i = 0,
|
dataTypes = dataTypeExpression.toLowerCase().match( rnotwhite ) || [];
|
|
if ( jQuery.isFunction( func ) ) {
|
|
// For each dataType in the dataTypeExpression
|
while ( ( dataType = dataTypes[ i++ ] ) ) {
|
|
// Prepend if requested
|
if ( dataType[ 0 ] === "+" ) {
|
dataType = dataType.slice( 1 ) || "*";
|
( structure[ dataType ] = structure[ dataType ] || [] ).unshift( func );
|
|
// Otherwise append
|
} else {
|
( structure[ dataType ] = structure[ dataType ] || [] ).push( func );
|
}
|
}
|
}
|
};
|
}
|
|
// Base inspection function for prefilters and transports
|
function inspectPrefiltersOrTransports( structure, options, originalOptions, jqXHR ) {
|
|
var inspected = {},
|
seekingTransport = ( structure === transports );
|
|
function inspect( dataType ) {
|
var selected;
|
inspected[ dataType ] = true;
|
jQuery.each( structure[ dataType ] || [], function( _, prefilterOrFactory ) {
|
var dataTypeOrTransport = prefilterOrFactory( options, originalOptions, jqXHR );
|
if ( typeof dataTypeOrTransport === "string" &&
|
!seekingTransport && !inspected[ dataTypeOrTransport ] ) {
|
|
options.dataTypes.unshift( dataTypeOrTransport );
|
inspect( dataTypeOrTransport );
|
return false;
|
} else if ( seekingTransport ) {
|
return !( selected = dataTypeOrTransport );
|
}
|
} );
|
return selected;
|
}
|
|
return inspect( options.dataTypes[ 0 ] ) || !inspected[ "*" ] && inspect( "*" );
|
}
|
|
// A special extend for ajax options
|
// that takes "flat" options (not to be deep extended)
|
// Fixes #9887
|
function ajaxExtend( target, src ) {
|
var key, deep,
|
flatOptions = jQuery.ajaxSettings.flatOptions || {};
|
|
for ( key in src ) {
|
if ( src[ key ] !== undefined ) {
|
( flatOptions[ key ] ? target : ( deep || ( deep = {} ) ) )[ key ] = src[ key ];
|
}
|
}
|
if ( deep ) {
|
jQuery.extend( true, target, deep );
|
}
|
|
return target;
|
}
|
|
/* Handles responses to an ajax request:
|
* - finds the right dataType (mediates between content-type and expected dataType)
|
* - returns the corresponding response
|
*/
|
function ajaxHandleResponses( s, jqXHR, responses ) {
|
|
var ct, type, finalDataType, firstDataType,
|
contents = s.contents,
|
dataTypes = s.dataTypes;
|
|
// Remove auto dataType and get content-type in the process
|
while ( dataTypes[ 0 ] === "*" ) {
|
dataTypes.shift();
|
if ( ct === undefined ) {
|
ct = s.mimeType || jqXHR.getResponseHeader( "Content-Type" );
|
}
|
}
|
|
// Check if we're dealing with a known content-type
|
if ( ct ) {
|
for ( type in contents ) {
|
if ( contents[ type ] && contents[ type ].test( ct ) ) {
|
dataTypes.unshift( type );
|
break;
|
}
|
}
|
}
|
|
// Check to see if we have a response for the expected dataType
|
if ( dataTypes[ 0 ] in responses ) {
|
finalDataType = dataTypes[ 0 ];
|
} else {
|
|
// Try convertible dataTypes
|
for ( type in responses ) {
|
if ( !dataTypes[ 0 ] || s.converters[ type + " " + dataTypes[ 0 ] ] ) {
|
finalDataType = type;
|
break;
|
}
|
if ( !firstDataType ) {
|
firstDataType = type;
|
}
|
}
|
|
// Or just use first one
|
finalDataType = finalDataType || firstDataType;
|
}
|
|
// If we found a dataType
|
// We add the dataType to the list if needed
|
// and return the corresponding response
|
if ( finalDataType ) {
|
if ( finalDataType !== dataTypes[ 0 ] ) {
|
dataTypes.unshift( finalDataType );
|
}
|
return responses[ finalDataType ];
|
}
|
}
|
|
/* Chain conversions given the request and the original response
|
* Also sets the responseXXX fields on the jqXHR instance
|
*/
|
function ajaxConvert( s, response, jqXHR, isSuccess ) {
|
var conv2, current, conv, tmp, prev,
|
converters = {},
|
|
// Work with a copy of dataTypes in case we need to modify it for conversion
|
dataTypes = s.dataTypes.slice();
|
|
// Create converters map with lowercased keys
|
if ( dataTypes[ 1 ] ) {
|
for ( conv in s.converters ) {
|
converters[ conv.toLowerCase() ] = s.converters[ conv ];
|
}
|
}
|
|
current = dataTypes.shift();
|
|
// Convert to each sequential dataType
|
while ( current ) {
|
|
if ( s.responseFields[ current ] ) {
|
jqXHR[ s.responseFields[ current ] ] = response;
|
}
|
|
// Apply the dataFilter if provided
|
if ( !prev && isSuccess && s.dataFilter ) {
|
response = s.dataFilter( response, s.dataType );
|
}
|
|
prev = current;
|
current = dataTypes.shift();
|
|
if ( current ) {
|
|
// There's only work to do if current dataType is non-auto
|
if ( current === "*" ) {
|
|
current = prev;
|
|
// Convert response if prev dataType is non-auto and differs from current
|
} else if ( prev !== "*" && prev !== current ) {
|
|
// Seek a direct converter
|
conv = converters[ prev + " " + current ] || converters[ "* " + current ];
|
|
// If none found, seek a pair
|
if ( !conv ) {
|
for ( conv2 in converters ) {
|
|
// If conv2 outputs current
|
tmp = conv2.split( " " );
|
if ( tmp[ 1 ] === current ) {
|
|
// If prev can be converted to accepted input
|
conv = converters[ prev + " " + tmp[ 0 ] ] ||
|
converters[ "* " + tmp[ 0 ] ];
|
if ( conv ) {
|
|
// Condense equivalence converters
|
if ( conv === true ) {
|
conv = converters[ conv2 ];
|
|
// Otherwise, insert the intermediate dataType
|
} else if ( converters[ conv2 ] !== true ) {
|
current = tmp[ 0 ];
|
dataTypes.unshift( tmp[ 1 ] );
|
}
|
break;
|
}
|
}
|
}
|
}
|
|
// Apply converter (if not an equivalence)
|
if ( conv !== true ) {
|
|
// Unless errors are allowed to bubble, catch and return them
|
if ( conv && s.throws ) {
|
response = conv( response );
|
} else {
|
try {
|
response = conv( response );
|
} catch ( e ) {
|
return {
|
state: "parsererror",
|
error: conv ? e : "No conversion from " + prev + " to " + current
|
};
|
}
|
}
|
}
|
}
|
}
|
}
|
|
return { state: "success", data: response };
|
}
|
|
jQuery.extend( {
|
|
// Counter for holding the number of active queries
|
active: 0,
|
|
// Last-Modified header cache for next request
|
lastModified: {},
|
etag: {},
|
|
ajaxSettings: {
|
url: location.href,
|
type: "GET",
|
isLocal: rlocalProtocol.test( location.protocol ),
|
global: true,
|
processData: true,
|
async: true,
|
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
|
/*
|
timeout: 0,
|
data: null,
|
dataType: null,
|
username: null,
|
password: null,
|
cache: null,
|
throws: false,
|
traditional: false,
|
headers: {},
|
*/
|
|
accepts: {
|
"*": allTypes,
|
text: "text/plain",
|
html: "text/html",
|
xml: "application/xml, text/xml",
|
json: "application/json, text/javascript"
|
},
|
|
contents: {
|
xml: /\bxml\b/,
|
html: /\bhtml/,
|
json: /\bjson\b/
|
},
|
|
responseFields: {
|
xml: "responseXML",
|
text: "responseText",
|
json: "responseJSON"
|
},
|
|
// Data converters
|
// Keys separate source (or catchall "*") and destination types with a single space
|
converters: {
|
|
// Convert anything to text
|
"* text": String,
|
|
// Text to html (true = no transformation)
|
"text html": true,
|
|
// Evaluate text as a json expression
|
"text json": jQuery.parseJSON,
|
|
// Parse text as xml
|
"text xml": jQuery.parseXML
|
},
|
|
// For options that shouldn't be deep extended:
|
// you can add your own custom options here if
|
// and when you create one that shouldn't be
|
// deep extended (see ajaxExtend)
|
flatOptions: {
|
url: true,
|
context: true
|
}
|
},
|
|
// Creates a full fledged settings object into target
|
// with both ajaxSettings and settings fields.
|
// If target is omitted, writes into ajaxSettings.
|
ajaxSetup: function( target, settings ) {
|
return settings ?
|
|
// Building a settings object
|
ajaxExtend( ajaxExtend( target, jQuery.ajaxSettings ), settings ) :
|
|
// Extending ajaxSettings
|
ajaxExtend( jQuery.ajaxSettings, target );
|
},
|
|
ajaxPrefilter: addToPrefiltersOrTransports( prefilters ),
|
ajaxTransport: addToPrefiltersOrTransports( transports ),
|
|
// Main method
|
ajax: function( url, options ) {
|
|
// If url is an object, simulate pre-1.5 signature
|
if ( typeof url === "object" ) {
|
options = url;
|
url = undefined;
|
}
|
|
// Force options to be an object
|
options = options || {};
|
|
var transport,
|
|
// URL without anti-cache param
|
cacheURL,
|
|
// Response headers
|
responseHeadersString,
|
responseHeaders,
|
|
// timeout handle
|
timeoutTimer,
|
|
// Url cleanup var
|
urlAnchor,
|
|
// To know if global events are to be dispatched
|
fireGlobals,
|
|
// Loop variable
|
i,
|
|
// Create the final options object
|
s = jQuery.ajaxSetup( {}, options ),
|
|
// Callbacks context
|
callbackContext = s.context || s,
|
|
// Context for global events is callbackContext if it is a DOM node or jQuery collection
|
globalEventContext = s.context &&
|
( callbackContext.nodeType || callbackContext.jquery ) ?
|
jQuery( callbackContext ) :
|
jQuery.event,
|
|
// Deferreds
|
deferred = jQuery.Deferred(),
|
completeDeferred = jQuery.Callbacks( "once memory" ),
|
|
// Status-dependent callbacks
|
statusCode = s.statusCode || {},
|
|
// Headers (they are sent all at once)
|
requestHeaders = {},
|
requestHeadersNames = {},
|
|
// The jqXHR state
|
state = 0,
|
|
// Default abort message
|
strAbort = "canceled",
|
|
// Fake xhr
|
jqXHR = {
|
readyState: 0,
|
|
// Builds headers hashtable if needed
|
getResponseHeader: function( key ) {
|
var match;
|
if ( state === 2 ) {
|
if ( !responseHeaders ) {
|
responseHeaders = {};
|
while ( ( match = rheaders.exec( responseHeadersString ) ) ) {
|
responseHeaders[ match[ 1 ].toLowerCase() ] = match[ 2 ];
|
}
|
}
|
match = responseHeaders[ key.toLowerCase() ];
|
}
|
return match == null ? null : match;
|
},
|
|
// Raw string
|
getAllResponseHeaders: function() {
|
return state === 2 ? responseHeadersString : null;
|
},
|
|
// Caches the header
|
setRequestHeader: function( name, value ) {
|
var lname = name.toLowerCase();
|
if ( !state ) {
|
name = requestHeadersNames[ lname ] = requestHeadersNames[ lname ] || name;
|
requestHeaders[ name ] = value;
|
}
|
return this;
|
},
|
|
// Overrides response content-type header
|
overrideMimeType: function( type ) {
|
if ( !state ) {
|
s.mimeType = type;
|
}
|
return this;
|
},
|
|
// Status-dependent callbacks
|
statusCode: function( map ) {
|
var code;
|
if ( map ) {
|
if ( state < 2 ) {
|
for ( code in map ) {
|
|
// Lazy-add the new callback in a way that preserves old ones
|
statusCode[ code ] = [ statusCode[ code ], map[ code ] ];
|
}
|
} else {
|
|
// Execute the appropriate callbacks
|
jqXHR.always( map[ jqXHR.status ] );
|
}
|
}
|
return this;
|
},
|
|
// Cancel the request
|
abort: function( statusText ) {
|
var finalText = statusText || strAbort;
|
if ( transport ) {
|
transport.abort( finalText );
|
}
|
done( 0, finalText );
|
return this;
|
}
|
};
|
|
// Attach deferreds
|
deferred.promise( jqXHR ).complete = completeDeferred.add;
|
jqXHR.success = jqXHR.done;
|
jqXHR.error = jqXHR.fail;
|
|
// Remove hash character (#7531: and string promotion)
|
// Add protocol if not provided (prefilters might expect it)
|
// Handle falsy url in the settings object (#10093: consistency with old signature)
|
// We also use the url parameter if available
|
s.url = ( ( url || s.url || location.href ) + "" ).replace( rhash, "" )
|
.replace( rprotocol, location.protocol + "//" );
|
|
// Alias method option to type as per ticket #12004
|
s.type = options.method || options.type || s.method || s.type;
|
|
// Extract dataTypes list
|
s.dataTypes = jQuery.trim( s.dataType || "*" ).toLowerCase().match( rnotwhite ) || [ "" ];
|
|
// A cross-domain request is in order when the origin doesn't match the current origin.
|
if ( s.crossDomain == null ) {
|
urlAnchor = document.createElement( "a" );
|
|
// Support: IE8-11+
|
// IE throws exception if url is malformed, e.g. http://example.com:80x/
|
try {
|
urlAnchor.href = s.url;
|
|
// Support: IE8-11+
|
// Anchor's host property isn't correctly set when s.url is relative
|
urlAnchor.href = urlAnchor.href;
|
s.crossDomain = originAnchor.protocol + "//" + originAnchor.host !==
|
urlAnchor.protocol + "//" + urlAnchor.host;
|
} catch ( e ) {
|
|
// If there is an error parsing the URL, assume it is crossDomain,
|
// it can be rejected by the transport if it is invalid
|
s.crossDomain = true;
|
}
|
}
|
|
// Convert data if not already a string
|
if ( s.data && s.processData && typeof s.data !== "string" ) {
|
s.data = jQuery.param( s.data, s.traditional );
|
}
|
|
// Apply prefilters
|
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
|
|
// If request was aborted inside a prefilter, stop there
|
if ( state === 2 ) {
|
return jqXHR;
|
}
|
|
// We can fire global events as of now if asked to
|
// Don't fire events if jQuery.event is undefined in an AMD-usage scenario (#15118)
|
fireGlobals = jQuery.event && s.global;
|
|
// Watch for a new set of requests
|
if ( fireGlobals && jQuery.active++ === 0 ) {
|
jQuery.event.trigger( "ajaxStart" );
|
}
|
|
// Uppercase the type
|
s.type = s.type.toUpperCase();
|
|
// Determine if request has content
|
s.hasContent = !rnoContent.test( s.type );
|
|
// Save the URL in case we're toying with the If-Modified-Since
|
// and/or If-None-Match header later on
|
cacheURL = s.url;
|
|
// More options handling for requests with no content
|
if ( !s.hasContent ) {
|
|
// If data is available, append data to url
|
if ( s.data ) {
|
cacheURL = ( s.url += ( rquery.test( cacheURL ) ? "&" : "?" ) + s.data );
|
|
// #9682: remove data so that it's not used in an eventual retry
|
delete s.data;
|
}
|
|
// Add anti-cache in url if needed
|
if ( s.cache === false ) {
|
s.url = rts.test( cacheURL ) ?
|
|
// If there is already a '_' parameter, set its value
|
cacheURL.replace( rts, "$1_=" + nonce++ ) :
|
|
// Otherwise add one to the end
|
cacheURL + ( rquery.test( cacheURL ) ? "&" : "?" ) + "_=" + nonce++;
|
}
|
}
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
if ( s.ifModified ) {
|
if ( jQuery.lastModified[ cacheURL ] ) {
|
jqXHR.setRequestHeader( "If-Modified-Since", jQuery.lastModified[ cacheURL ] );
|
}
|
if ( jQuery.etag[ cacheURL ] ) {
|
jqXHR.setRequestHeader( "If-None-Match", jQuery.etag[ cacheURL ] );
|
}
|
}
|
|
// Set the correct header, if data is being sent
|
if ( s.data && s.hasContent && s.contentType !== false || options.contentType ) {
|
jqXHR.setRequestHeader( "Content-Type", s.contentType );
|
}
|
|
// Set the Accepts header for the server, depending on the dataType
|
jqXHR.setRequestHeader(
|
"Accept",
|
s.dataTypes[ 0 ] && s.accepts[ s.dataTypes[ 0 ] ] ?
|
s.accepts[ s.dataTypes[ 0 ] ] +
|
( s.dataTypes[ 0 ] !== "*" ? ", " + allTypes + "; q=0.01" : "" ) :
|
s.accepts[ "*" ]
|
);
|
|
// Check for headers option
|
for ( i in s.headers ) {
|
jqXHR.setRequestHeader( i, s.headers[ i ] );
|
}
|
|
// Allow custom headers/mimetypes and early abort
|
if ( s.beforeSend &&
|
( s.beforeSend.call( callbackContext, jqXHR, s ) === false || state === 2 ) ) {
|
|
// Abort if not done already and return
|
return jqXHR.abort();
|
}
|
|
// Aborting is no longer a cancellation
|
strAbort = "abort";
|
|
// Install callbacks on deferreds
|
for ( i in { success: 1, error: 1, complete: 1 } ) {
|
jqXHR[ i ]( s[ i ] );
|
}
|
|
// Get transport
|
transport = inspectPrefiltersOrTransports( transports, s, options, jqXHR );
|
|
// If no transport, we auto-abort
|
if ( !transport ) {
|
done( -1, "No Transport" );
|
} else {
|
jqXHR.readyState = 1;
|
|
// Send global event
|
if ( fireGlobals ) {
|
globalEventContext.trigger( "ajaxSend", [ jqXHR, s ] );
|
}
|
|
// If request was aborted inside ajaxSend, stop there
|
if ( state === 2 ) {
|
return jqXHR;
|
}
|
|
// Timeout
|
if ( s.async && s.timeout > 0 ) {
|
timeoutTimer = window.setTimeout( function() {
|
jqXHR.abort( "timeout" );
|
}, s.timeout );
|
}
|
|
try {
|
state = 1;
|
transport.send( requestHeaders, done );
|
} catch ( e ) {
|
|
// Propagate exception as error if not done
|
if ( state < 2 ) {
|
done( -1, e );
|
|
// Simply rethrow otherwise
|
} else {
|
throw e;
|
}
|
}
|
}
|
|
// Callback for when everything is done
|
function done( status, nativeStatusText, responses, headers ) {
|
var isSuccess, success, error, response, modified,
|
statusText = nativeStatusText;
|
|
// Called once
|
if ( state === 2 ) {
|
return;
|
}
|
|
// State is "done" now
|
state = 2;
|
|
// Clear timeout if it exists
|
if ( timeoutTimer ) {
|
window.clearTimeout( timeoutTimer );
|
}
|
|
// Dereference transport for early garbage collection
|
// (no matter how long the jqXHR object will be used)
|
transport = undefined;
|
|
// Cache response headers
|
responseHeadersString = headers || "";
|
|
// Set readyState
|
jqXHR.readyState = status > 0 ? 4 : 0;
|
|
// Determine if successful
|
isSuccess = status >= 200 && status < 300 || status === 304;
|
|
// Get response data
|
if ( responses ) {
|
response = ajaxHandleResponses( s, jqXHR, responses );
|
}
|
|
// Convert no matter what (that way responseXXX fields are always set)
|
response = ajaxConvert( s, response, jqXHR, isSuccess );
|
|
// If successful, handle type chaining
|
if ( isSuccess ) {
|
|
// Set the If-Modified-Since and/or If-None-Match header, if in ifModified mode.
|
if ( s.ifModified ) {
|
modified = jqXHR.getResponseHeader( "Last-Modified" );
|
if ( modified ) {
|
jQuery.lastModified[ cacheURL ] = modified;
|
}
|
modified = jqXHR.getResponseHeader( "etag" );
|
if ( modified ) {
|
jQuery.etag[ cacheURL ] = modified;
|
}
|
}
|
|
// if no content
|
if ( status === 204 || s.type === "HEAD" ) {
|
statusText = "nocontent";
|
|
// if not modified
|
} else if ( status === 304 ) {
|
statusText = "notmodified";
|
|
// If we have data, let's convert it
|
} else {
|
statusText = response.state;
|
success = response.data;
|
error = response.error;
|
isSuccess = !error;
|
}
|
} else {
|
|
// Extract error from statusText and normalize for non-aborts
|
error = statusText;
|
if ( status || !statusText ) {
|
statusText = "error";
|
if ( status < 0 ) {
|
status = 0;
|
}
|
}
|
}
|
|
// Set data for the fake xhr object
|
jqXHR.status = status;
|
jqXHR.statusText = ( nativeStatusText || statusText ) + "";
|
|
// Success/Error
|
if ( isSuccess ) {
|
deferred.resolveWith( callbackContext, [ success, statusText, jqXHR ] );
|
} else {
|
deferred.rejectWith( callbackContext, [ jqXHR, statusText, error ] );
|
}
|
|
// Status-dependent callbacks
|
jqXHR.statusCode( statusCode );
|
statusCode = undefined;
|
|
if ( fireGlobals ) {
|
globalEventContext.trigger( isSuccess ? "ajaxSuccess" : "ajaxError",
|
[ jqXHR, s, isSuccess ? success : error ] );
|
}
|
|
// Complete
|
completeDeferred.fireWith( callbackContext, [ jqXHR, statusText ] );
|
|
if ( fireGlobals ) {
|
globalEventContext.trigger( "ajaxComplete", [ jqXHR, s ] );
|
|
// Handle the global AJAX counter
|
if ( !( --jQuery.active ) ) {
|
jQuery.event.trigger( "ajaxStop" );
|
}
|
}
|
}
|
|
return jqXHR;
|
},
|
|
getJSON: function( url, data, callback ) {
|
return jQuery.get( url, data, callback, "json" );
|
},
|
|
getScript: function( url, callback ) {
|
return jQuery.get( url, undefined, callback, "script" );
|
}
|
} );
|
|
jQuery.each( [ "get", "post" ], function( i, method ) {
|
jQuery[ method ] = function( url, data, callback, type ) {
|
|
// Shift arguments if data argument was omitted
|
if ( jQuery.isFunction( data ) ) {
|
type = type || callback;
|
callback = data;
|
data = undefined;
|
}
|
|
// The url can be an options object (which then must have .url)
|
return jQuery.ajax( jQuery.extend( {
|
url: url,
|
type: method,
|
dataType: type,
|
data: data,
|
success: callback
|
}, jQuery.isPlainObject( url ) && url ) );
|
};
|
} );
|
|
|
jQuery._evalUrl = function( url ) {
|
return jQuery.ajax( {
|
url: url,
|
|
// Make this explicit, since user can override this through ajaxSetup (#11264)
|
type: "GET",
|
dataType: "script",
|
async: false,
|
global: false,
|
"throws": true
|
} );
|
};
|
|
|
jQuery.fn.extend( {
|
wrapAll: function( html ) {
|
var wrap;
|
|
if ( jQuery.isFunction( html ) ) {
|
return this.each( function( i ) {
|
jQuery( this ).wrapAll( html.call( this, i ) );
|
} );
|
}
|
|
if ( this[ 0 ] ) {
|
|
// The elements to wrap the target around
|
wrap = jQuery( html, this[ 0 ].ownerDocument ).eq( 0 ).clone( true );
|
|
if ( this[ 0 ].parentNode ) {
|
wrap.insertBefore( this[ 0 ] );
|
}
|
|
wrap.map( function() {
|
var elem = this;
|
|
while ( elem.firstElementChild ) {
|
elem = elem.firstElementChild;
|
}
|
|
return elem;
|
} ).append( this );
|
}
|
|
return this;
|
},
|
|
wrapInner: function( html ) {
|
if ( jQuery.isFunction( html ) ) {
|
return this.each( function( i ) {
|
jQuery( this ).wrapInner( html.call( this, i ) );
|
} );
|
}
|
|
return this.each( function() {
|
var self = jQuery( this ),
|
contents = self.contents();
|
|
if ( contents.length ) {
|
contents.wrapAll( html );
|
|
} else {
|
self.append( html );
|
}
|
} );
|
},
|
|
wrap: function( html ) {
|
var isFunction = jQuery.isFunction( html );
|
|
return this.each( function( i ) {
|
jQuery( this ).wrapAll( isFunction ? html.call( this, i ) : html );
|
} );
|
},
|
|
unwrap: function() {
|
return this.parent().each( function() {
|
if ( !jQuery.nodeName( this, "body" ) ) {
|
jQuery( this ).replaceWith( this.childNodes );
|
}
|
} ).end();
|
}
|
} );
|
|
|
jQuery.expr.filters.hidden = function( elem ) {
|
return !jQuery.expr.filters.visible( elem );
|
};
|
jQuery.expr.filters.visible = function( elem ) {
|
|
// Support: Opera <= 12.12
|
// Opera reports offsetWidths and offsetHeights less than zero on some elements
|
// Use OR instead of AND as the element is not visible if either is true
|
// See tickets #10406 and #13132
|
return elem.offsetWidth > 0 || elem.offsetHeight > 0 || elem.getClientRects().length > 0;
|
};
|
|
|
|
|
var r20 = /%20/g,
|
rbracket = /\[\]$/,
|
rCRLF = /\r?\n/g,
|
rsubmitterTypes = /^(?:submit|button|image|reset|file)$/i,
|
rsubmittable = /^(?:input|select|textarea|keygen)/i;
|
|
function buildParams( prefix, obj, traditional, add ) {
|
var name;
|
|
if ( jQuery.isArray( obj ) ) {
|
|
// Serialize array item.
|
jQuery.each( obj, function( i, v ) {
|
if ( traditional || rbracket.test( prefix ) ) {
|
|
// Treat each array item as a scalar.
|
add( prefix, v );
|
|
} else {
|
|
// Item is non-scalar (array or object), encode its numeric index.
|
buildParams(
|
prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
|
v,
|
traditional,
|
add
|
);
|
}
|
} );
|
|
} else if ( !traditional && jQuery.type( obj ) === "object" ) {
|
|
// Serialize object item.
|
for ( name in obj ) {
|
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
|
}
|
|
} else {
|
|
// Serialize scalar item.
|
add( prefix, obj );
|
}
|
}
|
|
// Serialize an array of form elements or a set of
|
// key/values into a query string
|
jQuery.param = function( a, traditional ) {
|
var prefix,
|
s = [],
|
add = function( key, value ) {
|
|
// If value is a function, invoke it and return its value
|
value = jQuery.isFunction( value ) ? value() : ( value == null ? "" : value );
|
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
|
};
|
|
// Set traditional to true for jQuery <= 1.3.2 behavior.
|
if ( traditional === undefined ) {
|
traditional = jQuery.ajaxSettings && jQuery.ajaxSettings.traditional;
|
}
|
|
// If an array was passed in, assume that it is an array of form elements.
|
if ( jQuery.isArray( a ) || ( a.jquery && !jQuery.isPlainObject( a ) ) ) {
|
|
// Serialize the form elements
|
jQuery.each( a, function() {
|
add( this.name, this.value );
|
} );
|
|
} else {
|
|
// If traditional, encode the "old" way (the way 1.3.2 or older
|
// did it), otherwise encode params recursively.
|
for ( prefix in a ) {
|
buildParams( prefix, a[ prefix ], traditional, add );
|
}
|
}
|
|
// Return the resulting serialization
|
return s.join( "&" ).replace( r20, "+" );
|
};
|
|
jQuery.fn.extend( {
|
serialize: function() {
|
return jQuery.param( this.serializeArray() );
|
},
|
serializeArray: function() {
|
return this.map( function() {
|
|
// Can add propHook for "elements" to filter or add form elements
|
var elements = jQuery.prop( this, "elements" );
|
return elements ? jQuery.makeArray( elements ) : this;
|
} )
|
.filter( function() {
|
var type = this.type;
|
|
// Use .is( ":disabled" ) so that fieldset[disabled] works
|
return this.name && !jQuery( this ).is( ":disabled" ) &&
|
rsubmittable.test( this.nodeName ) && !rsubmitterTypes.test( type ) &&
|
( this.checked || !rcheckableType.test( type ) );
|
} )
|
.map( function( i, elem ) {
|
var val = jQuery( this ).val();
|
|
return val == null ?
|
null :
|
jQuery.isArray( val ) ?
|
jQuery.map( val, function( val ) {
|
return { name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
} ) :
|
{ name: elem.name, value: val.replace( rCRLF, "\r\n" ) };
|
} ).get();
|
}
|
} );
|
|
|
jQuery.ajaxSettings.xhr = function() {
|
try {
|
return new window.XMLHttpRequest();
|
} catch ( e ) {}
|
};
|
|
var xhrSuccessStatus = {
|
|
// File protocol always yields status code 0, assume 200
|
0: 200,
|
|
// Support: IE9
|
// #1450: sometimes IE returns 1223 when it should be 204
|
1223: 204
|
},
|
xhrSupported = jQuery.ajaxSettings.xhr();
|
|
support.cors = !!xhrSupported && ( "withCredentials" in xhrSupported );
|
support.ajax = xhrSupported = !!xhrSupported;
|
|
jQuery.ajaxTransport( function( options ) {
|
var callback, errorCallback;
|
|
// Cross domain only allowed if supported through XMLHttpRequest
|
if ( support.cors || xhrSupported && !options.crossDomain ) {
|
return {
|
send: function( headers, complete ) {
|
var i,
|
xhr = options.xhr();
|
|
xhr.open(
|
options.type,
|
options.url,
|
options.async,
|
options.username,
|
options.password
|
);
|
|
// Apply custom fields if provided
|
if ( options.xhrFields ) {
|
for ( i in options.xhrFields ) {
|
xhr[ i ] = options.xhrFields[ i ];
|
}
|
}
|
|
// Override mime type if needed
|
if ( options.mimeType && xhr.overrideMimeType ) {
|
xhr.overrideMimeType( options.mimeType );
|
}
|
|
// X-Requested-With header
|
// For cross-domain requests, seeing as conditions for a preflight are
|
// akin to a jigsaw puzzle, we simply never set it to be sure.
|
// (it can always be set on a per-request basis or even using ajaxSetup)
|
// For same-domain requests, won't change header if already provided.
|
if ( !options.crossDomain && !headers[ "X-Requested-With" ] ) {
|
headers[ "X-Requested-With" ] = "XMLHttpRequest";
|
}
|
|
// Set headers
|
for ( i in headers ) {
|
xhr.setRequestHeader( i, headers[ i ] );
|
}
|
|
// Callback
|
callback = function( type ) {
|
return function() {
|
if ( callback ) {
|
callback = errorCallback = xhr.onload =
|
xhr.onerror = xhr.onabort = xhr.onreadystatechange = null;
|
|
if ( type === "abort" ) {
|
xhr.abort();
|
} else if ( type === "error" ) {
|
|
// Support: IE9
|
// On a manual native abort, IE9 throws
|
// errors on any property access that is not readyState
|
if ( typeof xhr.status !== "number" ) {
|
complete( 0, "error" );
|
} else {
|
complete(
|
|
// File: protocol always yields status 0; see #8605, #14207
|
xhr.status,
|
xhr.statusText
|
);
|
}
|
} else {
|
complete(
|
xhrSuccessStatus[ xhr.status ] || xhr.status,
|
xhr.statusText,
|
|
// Support: IE9 only
|
// IE9 has no XHR2 but throws on binary (trac-11426)
|
// For XHR2 non-text, let the caller handle it (gh-2498)
|
( xhr.responseType || "text" ) !== "text" ||
|
typeof xhr.responseText !== "string" ?
|
{ binary: xhr.response } :
|
{ text: xhr.responseText },
|
xhr.getAllResponseHeaders()
|
);
|
}
|
}
|
};
|
};
|
|
// Listen to events
|
xhr.onload = callback();
|
errorCallback = xhr.onerror = callback( "error" );
|
|
// Support: IE9
|
// Use onreadystatechange to replace onabort
|
// to handle uncaught aborts
|
if ( xhr.onabort !== undefined ) {
|
xhr.onabort = errorCallback;
|
} else {
|
xhr.onreadystatechange = function() {
|
|
// Check readyState before timeout as it changes
|
if ( xhr.readyState === 4 ) {
|
|
// Allow onerror to be called first,
|
// but that will not handle a native abort
|
// Also, save errorCallback to a variable
|
// as xhr.onerror cannot be accessed
|
window.setTimeout( function() {
|
if ( callback ) {
|
errorCallback();
|
}
|
} );
|
}
|
};
|
}
|
|
// Create the abort callback
|
callback = callback( "abort" );
|
|
try {
|
|
// Do send the request (this may raise an exception)
|
xhr.send( options.hasContent && options.data || null );
|
} catch ( e ) {
|
|
// #14683: Only rethrow if this hasn't been notified as an error yet
|
if ( callback ) {
|
throw e;
|
}
|
}
|
},
|
|
abort: function() {
|
if ( callback ) {
|
callback();
|
}
|
}
|
};
|
}
|
} );
|
|
|
|
|
// Install script dataType
|
jQuery.ajaxSetup( {
|
accepts: {
|
script: "text/javascript, application/javascript, " +
|
"application/ecmascript, application/x-ecmascript"
|
},
|
contents: {
|
script: /\b(?:java|ecma)script\b/
|
},
|
converters: {
|
"text script": function( text ) {
|
jQuery.globalEval( text );
|
return text;
|
}
|
}
|
} );
|
|
// Handle cache's special case and crossDomain
|
jQuery.ajaxPrefilter( "script", function( s ) {
|
if ( s.cache === undefined ) {
|
s.cache = false;
|
}
|
if ( s.crossDomain ) {
|
s.type = "GET";
|
}
|
} );
|
|
// Bind script tag hack transport
|
jQuery.ajaxTransport( "script", function( s ) {
|
|
// This transport only deals with cross domain requests
|
if ( s.crossDomain ) {
|
var script, callback;
|
return {
|
send: function( _, complete ) {
|
script = jQuery( "<script>" ).prop( {
|
charset: s.scriptCharset,
|
src: s.url
|
} ).on(
|
"load error",
|
callback = function( evt ) {
|
script.remove();
|
callback = null;
|
if ( evt ) {
|
complete( evt.type === "error" ? 404 : 200, evt.type );
|
}
|
}
|
);
|
|
// Use native DOM manipulation to avoid our domManip AJAX trickery
|
document.head.appendChild( script[ 0 ] );
|
},
|
abort: function() {
|
if ( callback ) {
|
callback();
|
}
|
}
|
};
|
}
|
} );
|
|
|
|
|
var oldCallbacks = [],
|
rjsonp = /(=)\?(?=&|$)|\?\?/;
|
|
// Default jsonp settings
|
jQuery.ajaxSetup( {
|
jsonp: "callback",
|
jsonpCallback: function() {
|
var callback = oldCallbacks.pop() || ( jQuery.expando + "_" + ( nonce++ ) );
|
this[ callback ] = true;
|
return callback;
|
}
|
} );
|
|
// Detect, normalize options and install callbacks for jsonp requests
|
jQuery.ajaxPrefilter( "json jsonp", function( s, originalSettings, jqXHR ) {
|
|
var callbackName, overwritten, responseContainer,
|
jsonProp = s.jsonp !== false && ( rjsonp.test( s.url ) ?
|
"url" :
|
typeof s.data === "string" &&
|
( s.contentType || "" )
|
.indexOf( "application/x-www-form-urlencoded" ) === 0 &&
|
rjsonp.test( s.data ) && "data"
|
);
|
|
// Handle iff the expected data type is "jsonp" or we have a parameter to set
|
if ( jsonProp || s.dataTypes[ 0 ] === "jsonp" ) {
|
|
// Get callback name, remembering preexisting value associated with it
|
callbackName = s.jsonpCallback = jQuery.isFunction( s.jsonpCallback ) ?
|
s.jsonpCallback() :
|
s.jsonpCallback;
|
|
// Insert callback into url or form data
|
if ( jsonProp ) {
|
s[ jsonProp ] = s[ jsonProp ].replace( rjsonp, "$1" + callbackName );
|
} else if ( s.jsonp !== false ) {
|
s.url += ( rquery.test( s.url ) ? "&" : "?" ) + s.jsonp + "=" + callbackName;
|
}
|
|
// Use data converter to retrieve json after script execution
|
s.converters[ "script json" ] = function() {
|
if ( !responseContainer ) {
|
jQuery.error( callbackName + " was not called" );
|
}
|
return responseContainer[ 0 ];
|
};
|
|
// Force json dataType
|
s.dataTypes[ 0 ] = "json";
|
|
// Install callback
|
overwritten = window[ callbackName ];
|
window[ callbackName ] = function() {
|
responseContainer = arguments;
|
};
|
|
// Clean-up function (fires after converters)
|
jqXHR.always( function() {
|
|
// If previous value didn't exist - remove it
|
if ( overwritten === undefined ) {
|
jQuery( window ).removeProp( callbackName );
|
|
// Otherwise restore preexisting value
|
} else {
|
window[ callbackName ] = overwritten;
|
}
|
|
// Save back as free
|
if ( s[ callbackName ] ) {
|
|
// Make sure that re-using the options doesn't screw things around
|
s.jsonpCallback = originalSettings.jsonpCallback;
|
|
// Save the callback name for future use
|
oldCallbacks.push( callbackName );
|
}
|
|
// Call if it was a function and we have a response
|
if ( responseContainer && jQuery.isFunction( overwritten ) ) {
|
overwritten( responseContainer[ 0 ] );
|
}
|
|
responseContainer = overwritten = undefined;
|
} );
|
|
// Delegate to script
|
return "script";
|
}
|
} );
|
|
|
|
|
// Argument "data" should be string of html
|
// context (optional): If specified, the fragment will be created in this context,
|
// defaults to document
|
// keepScripts (optional): If true, will include scripts passed in the html string
|
jQuery.parseHTML = function( data, context, keepScripts ) {
|
if ( !data || typeof data !== "string" ) {
|
return null;
|
}
|
if ( typeof context === "boolean" ) {
|
keepScripts = context;
|
context = false;
|
}
|
context = context || document;
|
|
var parsed = rsingleTag.exec( data ),
|
scripts = !keepScripts && [];
|
|
// Single tag
|
if ( parsed ) {
|
return [ context.createElement( parsed[ 1 ] ) ];
|
}
|
|
parsed = buildFragment( [ data ], context, scripts );
|
|
if ( scripts && scripts.length ) {
|
jQuery( scripts ).remove();
|
}
|
|
return jQuery.merge( [], parsed.childNodes );
|
};
|
|
|
// Keep a copy of the old load method
|
var _load = jQuery.fn.load;
|
|
/**
|
* Load a url into a page
|
*/
|
jQuery.fn.load = function( url, params, callback ) {
|
if ( typeof url !== "string" && _load ) {
|
return _load.apply( this, arguments );
|
}
|
|
var selector, type, response,
|
self = this,
|
off = url.indexOf( " " );
|
|
if ( off > -1 ) {
|
selector = jQuery.trim( url.slice( off ) );
|
url = url.slice( 0, off );
|
}
|
|
// If it's a function
|
if ( jQuery.isFunction( params ) ) {
|
|
// We assume that it's the callback
|
callback = params;
|
params = undefined;
|
|
// Otherwise, build a param string
|
} else if ( params && typeof params === "object" ) {
|
type = "POST";
|
}
|
|
// If we have elements to modify, make the request
|
if ( self.length > 0 ) {
|
jQuery.ajax( {
|
url: url,
|
|
// If "type" variable is undefined, then "GET" method will be used.
|
// Make value of this field explicit since
|
// user can override it through ajaxSetup method
|
type: type || "GET",
|
dataType: "html",
|
data: params
|
} ).done( function( responseText ) {
|
|
// Save response for use in complete callback
|
response = arguments;
|
|
self.html( selector ?
|
|
// If a selector was specified, locate the right elements in a dummy div
|
// Exclude scripts to avoid IE 'Permission Denied' errors
|
jQuery( "<div>" ).append( jQuery.parseHTML( responseText ) ).find( selector ) :
|
|
// Otherwise use the full result
|
responseText );
|
|
// If the request succeeds, this function gets "data", "status", "jqXHR"
|
// but they are ignored because response was set above.
|
// If it fails, this function gets "jqXHR", "status", "error"
|
} ).always( callback && function( jqXHR, status ) {
|
self.each( function() {
|
callback.apply( this, response || [ jqXHR.responseText, status, jqXHR ] );
|
} );
|
} );
|
}
|
|
return this;
|
};
|
|
|
|
|
// Attach a bunch of functions for handling common AJAX events
|
jQuery.each( [
|
"ajaxStart",
|
"ajaxStop",
|
"ajaxComplete",
|
"ajaxError",
|
"ajaxSuccess",
|
"ajaxSend"
|
], function( i, type ) {
|
jQuery.fn[ type ] = function( fn ) {
|
return this.on( type, fn );
|
};
|
} );
|
|
|
|
|
jQuery.expr.filters.animated = function( elem ) {
|
return jQuery.grep( jQuery.timers, function( fn ) {
|
return elem === fn.elem;
|
} ).length;
|
};
|
|
|
|
|
/**
|
* Gets a window from an element
|
*/
|
function getWindow( elem ) {
|
return jQuery.isWindow( elem ) ? elem : elem.nodeType === 9 && elem.defaultView;
|
}
|
|
jQuery.offset = {
|
setOffset: function( elem, options, i ) {
|
var curPosition, curLeft, curCSSTop, curTop, curOffset, curCSSLeft, calculatePosition,
|
position = jQuery.css( elem, "position" ),
|
curElem = jQuery( elem ),
|
props = {};
|
|
// Set position first, in-case top/left are set even on static elem
|
if ( position === "static" ) {
|
elem.style.position = "relative";
|
}
|
|
curOffset = curElem.offset();
|
curCSSTop = jQuery.css( elem, "top" );
|
curCSSLeft = jQuery.css( elem, "left" );
|
calculatePosition = ( position === "absolute" || position === "fixed" ) &&
|
( curCSSTop + curCSSLeft ).indexOf( "auto" ) > -1;
|
|
// Need to be able to calculate position if either
|
// top or left is auto and position is either absolute or fixed
|
if ( calculatePosition ) {
|
curPosition = curElem.position();
|
curTop = curPosition.top;
|
curLeft = curPosition.left;
|
|
} else {
|
curTop = parseFloat( curCSSTop ) || 0;
|
curLeft = parseFloat( curCSSLeft ) || 0;
|
}
|
|
if ( jQuery.isFunction( options ) ) {
|
|
// Use jQuery.extend here to allow modification of coordinates argument (gh-1848)
|
options = options.call( elem, i, jQuery.extend( {}, curOffset ) );
|
}
|
|
if ( options.top != null ) {
|
props.top = ( options.top - curOffset.top ) + curTop;
|
}
|
if ( options.left != null ) {
|
props.left = ( options.left - curOffset.left ) + curLeft;
|
}
|
|
if ( "using" in options ) {
|
options.using.call( elem, props );
|
|
} else {
|
curElem.css( props );
|
}
|
}
|
};
|
|
jQuery.fn.extend( {
|
offset: function( options ) {
|
if ( arguments.length ) {
|
return options === undefined ?
|
this :
|
this.each( function( i ) {
|
jQuery.offset.setOffset( this, options, i );
|
} );
|
}
|
|
var docElem, win,
|
elem = this[ 0 ],
|
box = { top: 0, left: 0 },
|
doc = elem && elem.ownerDocument;
|
|
if ( !doc ) {
|
return;
|
}
|
|
docElem = doc.documentElement;
|
|
// Make sure it's not a disconnected DOM node
|
if ( !jQuery.contains( docElem, elem ) ) {
|
return box;
|
}
|
|
box = elem.getBoundingClientRect();
|
win = getWindow( doc );
|
return {
|
top: box.top + win.pageYOffset - docElem.clientTop,
|
left: box.left + win.pageXOffset - docElem.clientLeft
|
};
|
},
|
|
position: function() {
|
if ( !this[ 0 ] ) {
|
return;
|
}
|
|
var offsetParent, offset,
|
elem = this[ 0 ],
|
parentOffset = { top: 0, left: 0 };
|
|
// Fixed elements are offset from window (parentOffset = {top:0, left: 0},
|
// because it is its only offset parent
|
if ( jQuery.css( elem, "position" ) === "fixed" ) {
|
|
// Assume getBoundingClientRect is there when computed position is fixed
|
offset = elem.getBoundingClientRect();
|
|
} else {
|
|
// Get *real* offsetParent
|
offsetParent = this.offsetParent();
|
|
// Get correct offsets
|
offset = this.offset();
|
if ( !jQuery.nodeName( offsetParent[ 0 ], "html" ) ) {
|
parentOffset = offsetParent.offset();
|
}
|
|
// Add offsetParent borders
|
parentOffset.top += jQuery.css( offsetParent[ 0 ], "borderTopWidth", true );
|
parentOffset.left += jQuery.css( offsetParent[ 0 ], "borderLeftWidth", true );
|
}
|
|
// Subtract parent offsets and element margins
|
return {
|
top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ),
|
left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true )
|
};
|
},
|
|
// This method will return documentElement in the following cases:
|
// 1) For the element inside the iframe without offsetParent, this method will return
|
// documentElement of the parent window
|
// 2) For the hidden or detached element
|
// 3) For body or html element, i.e. in case of the html node - it will return itself
|
//
|
// but those exceptions were never presented as a real life use-cases
|
// and might be considered as more preferable results.
|
//
|
// This logic, however, is not guaranteed and can change at any point in the future
|
offsetParent: function() {
|
return this.map( function() {
|
var offsetParent = this.offsetParent;
|
|
while ( offsetParent && jQuery.css( offsetParent, "position" ) === "static" ) {
|
offsetParent = offsetParent.offsetParent;
|
}
|
|
return offsetParent || documentElement;
|
} );
|
}
|
} );
|
|
// Create scrollLeft and scrollTop methods
|
jQuery.each( { scrollLeft: "pageXOffset", scrollTop: "pageYOffset" }, function( method, prop ) {
|
var top = "pageYOffset" === prop;
|
|
jQuery.fn[ method ] = function( val ) {
|
return access( this, function( elem, method, val ) {
|
var win = getWindow( elem );
|
|
if ( val === undefined ) {
|
return win ? win[ prop ] : elem[ method ];
|
}
|
|
if ( win ) {
|
win.scrollTo(
|
!top ? val : win.pageXOffset,
|
top ? val : win.pageYOffset
|
);
|
|
} else {
|
elem[ method ] = val;
|
}
|
}, method, val, arguments.length );
|
};
|
} );
|
|
// Support: Safari<7-8+, Chrome<37-44+
|
// Add the top/left cssHooks using jQuery.fn.position
|
// Webkit bug: https://bugs.webkit.org/show_bug.cgi?id=29084
|
// Blink bug: https://code.google.com/p/chromium/issues/detail?id=229280
|
// getComputedStyle returns percent when specified for top/left/bottom/right;
|
// rather than make the css module depend on the offset module, just check for it here
|
jQuery.each( [ "top", "left" ], function( i, prop ) {
|
jQuery.cssHooks[ prop ] = addGetHookIf( support.pixelPosition,
|
function( elem, computed ) {
|
if ( computed ) {
|
computed = curCSS( elem, prop );
|
|
// If curCSS returns percentage, fallback to offset
|
return rnumnonpx.test( computed ) ?
|
jQuery( elem ).position()[ prop ] + "px" :
|
computed;
|
}
|
}
|
);
|
} );
|
|
|
// Create innerHeight, innerWidth, height, width, outerHeight and outerWidth methods
|
jQuery.each( { Height: "height", Width: "width" }, function( name, type ) {
|
jQuery.each( { padding: "inner" + name, content: type, "": "outer" + name },
|
function( defaultExtra, funcName ) {
|
|
// Margin is only for outerHeight, outerWidth
|
jQuery.fn[ funcName ] = function( margin, value ) {
|
var chainable = arguments.length && ( defaultExtra || typeof margin !== "boolean" ),
|
extra = defaultExtra || ( margin === true || value === true ? "margin" : "border" );
|
|
return access( this, function( elem, type, value ) {
|
var doc;
|
|
if ( jQuery.isWindow( elem ) ) {
|
|
// As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
|
// isn't a whole lot we can do. See pull request at this URL for discussion:
|
// https://github.com/jquery/jquery/pull/764
|
return elem.document.documentElement[ "client" + name ];
|
}
|
|
// Get document width or height
|
if ( elem.nodeType === 9 ) {
|
doc = elem.documentElement;
|
|
// Either scroll[Width/Height] or offset[Width/Height] or client[Width/Height],
|
// whichever is greatest
|
return Math.max(
|
elem.body[ "scroll" + name ], doc[ "scroll" + name ],
|
elem.body[ "offset" + name ], doc[ "offset" + name ],
|
doc[ "client" + name ]
|
);
|
}
|
|
return value === undefined ?
|
|
// Get width or height on the element, requesting but not forcing parseFloat
|
jQuery.css( elem, type, extra ) :
|
|
// Set width or height on the element
|
jQuery.style( elem, type, value, extra );
|
}, type, chainable ? margin : undefined, chainable, null );
|
};
|
} );
|
} );
|
|
|
jQuery.fn.extend( {
|
|
bind: function( types, data, fn ) {
|
return this.on( types, null, data, fn );
|
},
|
unbind: function( types, fn ) {
|
return this.off( types, null, fn );
|
},
|
|
delegate: function( selector, types, data, fn ) {
|
return this.on( types, selector, data, fn );
|
},
|
undelegate: function( selector, types, fn ) {
|
|
// ( namespace ) or ( selector, types [, fn] )
|
return arguments.length === 1 ?
|
this.off( selector, "**" ) :
|
this.off( types, selector || "**", fn );
|
},
|
size: function() {
|
return this.length;
|
}
|
} );
|
|
jQuery.fn.andSelf = jQuery.fn.addBack;
|
|
|
|
|
// Register as a named AMD module, since jQuery can be concatenated with other
|
// files that may use define, but not via a proper concatenation script that
|
// understands anonymous AMD modules. A named AMD is safest and most robust
|
// way to register. Lowercase jquery is used because AMD module names are
|
// derived from file names, and jQuery is normally delivered in a lowercase
|
// file name. Do this after creating the global so that if an AMD module wants
|
// to call noConflict to hide this version of jQuery, it will work.
|
|
// Note that for maximum portability, libraries that are not jQuery should
|
// declare themselves as anonymous modules, and avoid setting a global if an
|
// AMD loader is present. jQuery is a special case. For more information, see
|
// https://github.com/jrburke/requirejs/wiki/Updating-existing-libraries#wiki-anon
|
|
if ( true ) {
|
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = function() {
|
return jQuery;
|
}.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
}
|
|
|
|
var
|
|
// Map over jQuery in case of overwrite
|
_jQuery = window.jQuery,
|
|
// Map over the $ in case of overwrite
|
_$ = window.$;
|
|
jQuery.noConflict = function( deep ) {
|
if ( window.$ === jQuery ) {
|
window.$ = _$;
|
}
|
|
if ( deep && window.jQuery === jQuery ) {
|
window.jQuery = _jQuery;
|
}
|
|
return jQuery;
|
};
|
|
// Expose jQuery and $ identifiers, even in AMD
|
// (#7102#comment:10, https://github.com/jquery/jquery/pull/557)
|
// and CommonJS for browser emulators (#13566)
|
if ( !noGlobal ) {
|
window.jQuery = window.$ = jQuery;
|
}
|
|
return jQuery;
|
}));
|
|
|
/***/ },
|
/* 4 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var __WEBPACK_AMD_DEFINE_RESULT__;/* WEBPACK VAR INJECTION */(function(module, global) {/**
|
* @license
|
* lodash 3.10.1 (Custom Build) <https://lodash.com/>
|
* Build: `lodash modern -d -o ./index.js`
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
* Available under MIT license <https://lodash.com/license>
|
*/
|
;(function() {
|
|
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
|
var undefined;
|
|
/** Used as the semantic version number. */
|
var VERSION = '3.10.1';
|
|
/** Used to compose bitmasks for wrapper metadata. */
|
var BIND_FLAG = 1,
|
BIND_KEY_FLAG = 2,
|
CURRY_BOUND_FLAG = 4,
|
CURRY_FLAG = 8,
|
CURRY_RIGHT_FLAG = 16,
|
PARTIAL_FLAG = 32,
|
PARTIAL_RIGHT_FLAG = 64,
|
ARY_FLAG = 128,
|
REARG_FLAG = 256;
|
|
/** Used as default options for `_.trunc`. */
|
var DEFAULT_TRUNC_LENGTH = 30,
|
DEFAULT_TRUNC_OMISSION = '...';
|
|
/** Used to detect when a function becomes hot. */
|
var HOT_COUNT = 150,
|
HOT_SPAN = 16;
|
|
/** Used as the size to enable large array optimizations. */
|
var LARGE_ARRAY_SIZE = 200;
|
|
/** Used to indicate the type of lazy iteratees. */
|
var LAZY_FILTER_FLAG = 1,
|
LAZY_MAP_FLAG = 2;
|
|
/** Used as the `TypeError` message for "Functions" methods. */
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
/** Used as the internal argument placeholder. */
|
var PLACEHOLDER = '__lodash_placeholder__';
|
|
/** `Object#toString` result references. */
|
var argsTag = '[object Arguments]',
|
arrayTag = '[object Array]',
|
boolTag = '[object Boolean]',
|
dateTag = '[object Date]',
|
errorTag = '[object Error]',
|
funcTag = '[object Function]',
|
mapTag = '[object Map]',
|
numberTag = '[object Number]',
|
objectTag = '[object Object]',
|
regexpTag = '[object RegExp]',
|
setTag = '[object Set]',
|
stringTag = '[object String]',
|
weakMapTag = '[object WeakMap]';
|
|
var arrayBufferTag = '[object ArrayBuffer]',
|
float32Tag = '[object Float32Array]',
|
float64Tag = '[object Float64Array]',
|
int8Tag = '[object Int8Array]',
|
int16Tag = '[object Int16Array]',
|
int32Tag = '[object Int32Array]',
|
uint8Tag = '[object Uint8Array]',
|
uint8ClampedTag = '[object Uint8ClampedArray]',
|
uint16Tag = '[object Uint16Array]',
|
uint32Tag = '[object Uint32Array]';
|
|
/** Used to match empty string literals in compiled template source. */
|
var reEmptyStringLeading = /\b__p \+= '';/g,
|
reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
|
reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
|
|
/** Used to match HTML entities and HTML characters. */
|
var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
|
reUnescapedHtml = /[&<>"'`]/g,
|
reHasEscapedHtml = RegExp(reEscapedHtml.source),
|
reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|
/** Used to match template delimiters. */
|
var reEscape = /<%-([\s\S]+?)%>/g,
|
reEvaluate = /<%([\s\S]+?)%>/g,
|
reInterpolate = /<%=([\s\S]+?)%>/g;
|
|
/** Used to match property names within property paths. */
|
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
|
reIsPlainProp = /^\w*$/,
|
rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
|
|
/**
|
* Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
|
* and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
|
*/
|
var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
|
reHasRegExpChars = RegExp(reRegExpChars.source);
|
|
/** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
|
var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
|
|
/** Used to match backslashes in property paths. */
|
var reEscapeChar = /\\(\\)?/g;
|
|
/** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
|
var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
|
|
/** Used to match `RegExp` flags from their coerced string values. */
|
var reFlags = /\w*$/;
|
|
/** Used to detect hexadecimal string values. */
|
var reHasHexPrefix = /^0[xX]/;
|
|
/** Used to detect host constructors (Safari > 5). */
|
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
/** Used to detect unsigned integer values. */
|
var reIsUint = /^\d+$/;
|
|
/** Used to match latin-1 supplementary letters (excluding mathematical operators). */
|
var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
|
|
/** Used to ensure capturing order of template delimiters. */
|
var reNoMatch = /($^)/;
|
|
/** Used to match unescaped characters in compiled string literals. */
|
var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
|
|
/** Used to match words to create compound words. */
|
var reWords = (function() {
|
var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
|
lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
|
|
return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
|
}());
|
|
/** Used to assign default `context` object properties. */
|
var contextProps = [
|
'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
|
'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
|
'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
|
'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
|
'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
|
];
|
|
/** Used to make template sourceURLs easier to identify. */
|
var templateCounter = -1;
|
|
/** Used to identify `toStringTag` values of typed arrays. */
|
var typedArrayTags = {};
|
typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
typedArrayTags[uint32Tag] = true;
|
typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
|
typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
typedArrayTags[dateTag] = typedArrayTags[errorTag] =
|
typedArrayTags[funcTag] = typedArrayTags[mapTag] =
|
typedArrayTags[numberTag] = typedArrayTags[objectTag] =
|
typedArrayTags[regexpTag] = typedArrayTags[setTag] =
|
typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
|
|
/** Used to identify `toStringTag` values supported by `_.clone`. */
|
var cloneableTags = {};
|
cloneableTags[argsTag] = cloneableTags[arrayTag] =
|
cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
|
cloneableTags[dateTag] = cloneableTags[float32Tag] =
|
cloneableTags[float64Tag] = cloneableTags[int8Tag] =
|
cloneableTags[int16Tag] = cloneableTags[int32Tag] =
|
cloneableTags[numberTag] = cloneableTags[objectTag] =
|
cloneableTags[regexpTag] = cloneableTags[stringTag] =
|
cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
|
cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
|
cloneableTags[errorTag] = cloneableTags[funcTag] =
|
cloneableTags[mapTag] = cloneableTags[setTag] =
|
cloneableTags[weakMapTag] = false;
|
|
/** Used to map latin-1 supplementary letters to basic latin letters. */
|
var deburredLetters = {
|
'\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
|
'\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
|
'\xc7': 'C', '\xe7': 'c',
|
'\xd0': 'D', '\xf0': 'd',
|
'\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
|
'\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
|
'\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
|
'\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
|
'\xd1': 'N', '\xf1': 'n',
|
'\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
|
'\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
|
'\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
|
'\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
|
'\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
|
'\xc6': 'Ae', '\xe6': 'ae',
|
'\xde': 'Th', '\xfe': 'th',
|
'\xdf': 'ss'
|
};
|
|
/** Used to map characters to HTML entities. */
|
var htmlEscapes = {
|
'&': '&',
|
'<': '<',
|
'>': '>',
|
'"': '"',
|
"'": ''',
|
'`': '`'
|
};
|
|
/** Used to map HTML entities to characters. */
|
var htmlUnescapes = {
|
'&': '&',
|
'<': '<',
|
'>': '>',
|
'"': '"',
|
''': "'",
|
'`': '`'
|
};
|
|
/** Used to determine if values are of the language type `Object`. */
|
var objectTypes = {
|
'function': true,
|
'object': true
|
};
|
|
/** Used to escape characters for inclusion in compiled regexes. */
|
var regexpEscapes = {
|
'0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
|
'5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
|
'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
|
'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
|
'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
|
};
|
|
/** Used to escape characters for inclusion in compiled string literals. */
|
var stringEscapes = {
|
'\\': '\\',
|
"'": "'",
|
'\n': 'n',
|
'\r': 'r',
|
'\u2028': 'u2028',
|
'\u2029': 'u2029'
|
};
|
|
/** Detect free variable `exports`. */
|
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
|
/** Detect free variable `module`. */
|
var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
|
|
/** Detect free variable `global` from Node.js. */
|
var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
|
|
/** Detect free variable `self`. */
|
var freeSelf = objectTypes[typeof self] && self && self.Object && self;
|
|
/** Detect free variable `window`. */
|
var freeWindow = objectTypes[typeof window] && window && window.Object && window;
|
|
/** Detect the popular CommonJS extension `module.exports`. */
|
var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
|
|
/**
|
* Used as a reference to the global object.
|
*
|
* The `this` value is used if it's the global object to avoid Greasemonkey's
|
* restricted `window` object, otherwise the `window` object is used.
|
*/
|
var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
|
|
/*--------------------------------------------------------------------------*/
|
|
/**
|
* The base implementation of `compareAscending` which compares values and
|
* sorts them in ascending order without guaranteeing a stable sort.
|
*
|
* @private
|
* @param {*} value The value to compare.
|
* @param {*} other The other value to compare.
|
* @returns {number} Returns the sort order indicator for `value`.
|
*/
|
function baseCompareAscending(value, other) {
|
if (value !== other) {
|
var valIsNull = value === null,
|
valIsUndef = value === undefined,
|
valIsReflexive = value === value;
|
|
var othIsNull = other === null,
|
othIsUndef = other === undefined,
|
othIsReflexive = other === other;
|
|
if ((value > other && !othIsNull) || !valIsReflexive ||
|
(valIsNull && !othIsUndef && othIsReflexive) ||
|
(valIsUndef && othIsReflexive)) {
|
return 1;
|
}
|
if ((value < other && !valIsNull) || !othIsReflexive ||
|
(othIsNull && !valIsUndef && valIsReflexive) ||
|
(othIsUndef && valIsReflexive)) {
|
return -1;
|
}
|
}
|
return 0;
|
}
|
|
/**
|
* The base implementation of `_.findIndex` and `_.findLastIndex` without
|
* support for callback shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to search.
|
* @param {Function} predicate The function invoked per iteration.
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
*/
|
function baseFindIndex(array, predicate, fromRight) {
|
var length = array.length,
|
index = fromRight ? length : -1;
|
|
while ((fromRight ? index-- : ++index < length)) {
|
if (predicate(array[index], index, array)) {
|
return index;
|
}
|
}
|
return -1;
|
}
|
|
/**
|
* The base implementation of `_.indexOf` without support for binary searches.
|
*
|
* @private
|
* @param {Array} array The array to search.
|
* @param {*} value The value to search for.
|
* @param {number} fromIndex The index to search from.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
*/
|
function baseIndexOf(array, value, fromIndex) {
|
if (value !== value) {
|
return indexOfNaN(array, fromIndex);
|
}
|
var index = fromIndex - 1,
|
length = array.length;
|
|
while (++index < length) {
|
if (array[index] === value) {
|
return index;
|
}
|
}
|
return -1;
|
}
|
|
/**
|
* The base implementation of `_.isFunction` without support for environments
|
* with incorrect `typeof` results.
|
*
|
* @private
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
*/
|
function baseIsFunction(value) {
|
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
|
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
|
return typeof value == 'function' || false;
|
}
|
|
/**
|
* Converts `value` to a string if it's not one. An empty string is returned
|
* for `null` or `undefined` values.
|
*
|
* @private
|
* @param {*} value The value to process.
|
* @returns {string} Returns the string.
|
*/
|
function baseToString(value) {
|
return value == null ? '' : (value + '');
|
}
|
|
/**
|
* Used by `_.trim` and `_.trimLeft` to get the index of the first character
|
* of `string` that is not found in `chars`.
|
*
|
* @private
|
* @param {string} string The string to inspect.
|
* @param {string} chars The characters to find.
|
* @returns {number} Returns the index of the first character not found in `chars`.
|
*/
|
function charsLeftIndex(string, chars) {
|
var index = -1,
|
length = string.length;
|
|
while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
|
return index;
|
}
|
|
/**
|
* Used by `_.trim` and `_.trimRight` to get the index of the last character
|
* of `string` that is not found in `chars`.
|
*
|
* @private
|
* @param {string} string The string to inspect.
|
* @param {string} chars The characters to find.
|
* @returns {number} Returns the index of the last character not found in `chars`.
|
*/
|
function charsRightIndex(string, chars) {
|
var index = string.length;
|
|
while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
|
return index;
|
}
|
|
/**
|
* Used by `_.sortBy` to compare transformed elements of a collection and stable
|
* sort them in ascending order.
|
*
|
* @private
|
* @param {Object} object The object to compare.
|
* @param {Object} other The other object to compare.
|
* @returns {number} Returns the sort order indicator for `object`.
|
*/
|
function compareAscending(object, other) {
|
return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
|
}
|
|
/**
|
* Used by `_.sortByOrder` to compare multiple properties of a value to another
|
* and stable sort them.
|
*
|
* If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
|
* a value is sorted in ascending order if its corresponding order is "asc", and
|
* descending if "desc".
|
*
|
* @private
|
* @param {Object} object The object to compare.
|
* @param {Object} other The other object to compare.
|
* @param {boolean[]} orders The order to sort by for each property.
|
* @returns {number} Returns the sort order indicator for `object`.
|
*/
|
function compareMultiple(object, other, orders) {
|
var index = -1,
|
objCriteria = object.criteria,
|
othCriteria = other.criteria,
|
length = objCriteria.length,
|
ordersLength = orders.length;
|
|
while (++index < length) {
|
var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
|
if (result) {
|
if (index >= ordersLength) {
|
return result;
|
}
|
var order = orders[index];
|
return result * ((order === 'asc' || order === true) ? 1 : -1);
|
}
|
}
|
// Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
|
// that causes it, under certain circumstances, to provide the same value for
|
// `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
|
// for more details.
|
//
|
// This also ensures a stable sort in V8 and other engines.
|
// See https://code.google.com/p/v8/issues/detail?id=90 for more details.
|
return object.index - other.index;
|
}
|
|
/**
|
* Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
|
*
|
* @private
|
* @param {string} letter The matched letter to deburr.
|
* @returns {string} Returns the deburred letter.
|
*/
|
function deburrLetter(letter) {
|
return deburredLetters[letter];
|
}
|
|
/**
|
* Used by `_.escape` to convert characters to HTML entities.
|
*
|
* @private
|
* @param {string} chr The matched character to escape.
|
* @returns {string} Returns the escaped character.
|
*/
|
function escapeHtmlChar(chr) {
|
return htmlEscapes[chr];
|
}
|
|
/**
|
* Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
|
*
|
* @private
|
* @param {string} chr The matched character to escape.
|
* @param {string} leadingChar The capture group for a leading character.
|
* @param {string} whitespaceChar The capture group for a whitespace character.
|
* @returns {string} Returns the escaped character.
|
*/
|
function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
|
if (leadingChar) {
|
chr = regexpEscapes[chr];
|
} else if (whitespaceChar) {
|
chr = stringEscapes[chr];
|
}
|
return '\\' + chr;
|
}
|
|
/**
|
* Used by `_.template` to escape characters for inclusion in compiled string literals.
|
*
|
* @private
|
* @param {string} chr The matched character to escape.
|
* @returns {string} Returns the escaped character.
|
*/
|
function escapeStringChar(chr) {
|
return '\\' + stringEscapes[chr];
|
}
|
|
/**
|
* Gets the index at which the first occurrence of `NaN` is found in `array`.
|
*
|
* @private
|
* @param {Array} array The array to search.
|
* @param {number} fromIndex The index to search from.
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
* @returns {number} Returns the index of the matched `NaN`, else `-1`.
|
*/
|
function indexOfNaN(array, fromIndex, fromRight) {
|
var length = array.length,
|
index = fromIndex + (fromRight ? 0 : -1);
|
|
while ((fromRight ? index-- : ++index < length)) {
|
var other = array[index];
|
if (other !== other) {
|
return index;
|
}
|
}
|
return -1;
|
}
|
|
/**
|
* Checks if `value` is object-like.
|
*
|
* @private
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
*/
|
function isObjectLike(value) {
|
return !!value && typeof value == 'object';
|
}
|
|
/**
|
* Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
|
* character code is whitespace.
|
*
|
* @private
|
* @param {number} charCode The character code to inspect.
|
* @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
|
*/
|
function isSpace(charCode) {
|
return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
|
(charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
|
}
|
|
/**
|
* Replaces all `placeholder` elements in `array` with an internal placeholder
|
* and returns an array of their indexes.
|
*
|
* @private
|
* @param {Array} array The array to modify.
|
* @param {*} placeholder The placeholder to replace.
|
* @returns {Array} Returns the new array of placeholder indexes.
|
*/
|
function replaceHolders(array, placeholder) {
|
var index = -1,
|
length = array.length,
|
resIndex = -1,
|
result = [];
|
|
while (++index < length) {
|
if (array[index] === placeholder) {
|
array[index] = PLACEHOLDER;
|
result[++resIndex] = index;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* An implementation of `_.uniq` optimized for sorted arrays without support
|
* for callback shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to inspect.
|
* @param {Function} [iteratee] The function invoked per iteration.
|
* @returns {Array} Returns the new duplicate-value-free array.
|
*/
|
function sortedUniq(array, iteratee) {
|
var seen,
|
index = -1,
|
length = array.length,
|
resIndex = -1,
|
result = [];
|
|
while (++index < length) {
|
var value = array[index],
|
computed = iteratee ? iteratee(value, index, array) : value;
|
|
if (!index || seen !== computed) {
|
seen = computed;
|
result[++resIndex] = value;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
|
* character of `string`.
|
*
|
* @private
|
* @param {string} string The string to inspect.
|
* @returns {number} Returns the index of the first non-whitespace character.
|
*/
|
function trimmedLeftIndex(string) {
|
var index = -1,
|
length = string.length;
|
|
while (++index < length && isSpace(string.charCodeAt(index))) {}
|
return index;
|
}
|
|
/**
|
* Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
|
* character of `string`.
|
*
|
* @private
|
* @param {string} string The string to inspect.
|
* @returns {number} Returns the index of the last non-whitespace character.
|
*/
|
function trimmedRightIndex(string) {
|
var index = string.length;
|
|
while (index-- && isSpace(string.charCodeAt(index))) {}
|
return index;
|
}
|
|
/**
|
* Used by `_.unescape` to convert HTML entities to characters.
|
*
|
* @private
|
* @param {string} chr The matched character to unescape.
|
* @returns {string} Returns the unescaped character.
|
*/
|
function unescapeHtmlChar(chr) {
|
return htmlUnescapes[chr];
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
/**
|
* Create a new pristine `lodash` function using the given `context` object.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Object} [context=root] The context object.
|
* @returns {Function} Returns a new `lodash` function.
|
* @example
|
*
|
* _.mixin({ 'foo': _.constant('foo') });
|
*
|
* var lodash = _.runInContext();
|
* lodash.mixin({ 'bar': lodash.constant('bar') });
|
*
|
* _.isFunction(_.foo);
|
* // => true
|
* _.isFunction(_.bar);
|
* // => false
|
*
|
* lodash.isFunction(lodash.foo);
|
* // => false
|
* lodash.isFunction(lodash.bar);
|
* // => true
|
*
|
* // using `context` to mock `Date#getTime` use in `_.now`
|
* var mock = _.runInContext({
|
* 'Date': function() {
|
* return { 'getTime': getTimeMock };
|
* }
|
* });
|
*
|
* // or creating a suped-up `defer` in Node.js
|
* var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
|
*/
|
function runInContext(context) {
|
// Avoid issues with some ES3 environments that attempt to use values, named
|
// after built-in constructors like `Object`, for the creation of literals.
|
// ES5 clears this up by stating that literals must use built-in constructors.
|
// See https://es5.github.io/#x11.1.5 for more details.
|
context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
|
|
/** Native constructor references. */
|
var Array = context.Array,
|
Date = context.Date,
|
Error = context.Error,
|
Function = context.Function,
|
Math = context.Math,
|
Number = context.Number,
|
Object = context.Object,
|
RegExp = context.RegExp,
|
String = context.String,
|
TypeError = context.TypeError;
|
|
/** Used for native method references. */
|
var arrayProto = Array.prototype,
|
objectProto = Object.prototype,
|
stringProto = String.prototype;
|
|
/** Used to resolve the decompiled source of functions. */
|
var fnToString = Function.prototype.toString;
|
|
/** Used to check objects for own properties. */
|
var hasOwnProperty = objectProto.hasOwnProperty;
|
|
/** Used to generate unique IDs. */
|
var idCounter = 0;
|
|
/**
|
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
|
* of values.
|
*/
|
var objToString = objectProto.toString;
|
|
/** Used to restore the original `_` reference in `_.noConflict`. */
|
var oldDash = root._;
|
|
/** Used to detect if a method is native. */
|
var reIsNative = RegExp('^' +
|
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
);
|
|
/** Native method references. */
|
var ArrayBuffer = context.ArrayBuffer,
|
clearTimeout = context.clearTimeout,
|
parseFloat = context.parseFloat,
|
pow = Math.pow,
|
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
Set = getNative(context, 'Set'),
|
setTimeout = context.setTimeout,
|
splice = arrayProto.splice,
|
Uint8Array = context.Uint8Array,
|
WeakMap = getNative(context, 'WeakMap');
|
|
/* Native method references for those with the same name as other `lodash` methods. */
|
var nativeCeil = Math.ceil,
|
nativeCreate = getNative(Object, 'create'),
|
nativeFloor = Math.floor,
|
nativeIsArray = getNative(Array, 'isArray'),
|
nativeIsFinite = context.isFinite,
|
nativeKeys = getNative(Object, 'keys'),
|
nativeMax = Math.max,
|
nativeMin = Math.min,
|
nativeNow = getNative(Date, 'now'),
|
nativeParseInt = context.parseInt,
|
nativeRandom = Math.random;
|
|
/** Used as references for `-Infinity` and `Infinity`. */
|
var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
|
POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
|
|
/** Used as references for the maximum length and index of an array. */
|
var MAX_ARRAY_LENGTH = 4294967295,
|
MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
|
HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
|
|
/**
|
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
|
* of an array-like value.
|
*/
|
var MAX_SAFE_INTEGER = 9007199254740991;
|
|
/** Used to store function metadata. */
|
var metaMap = WeakMap && new WeakMap;
|
|
/** Used to lookup unminified function names. */
|
var realNames = {};
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Creates a `lodash` object which wraps `value` to enable implicit chaining.
|
* Methods that operate on and return arrays, collections, and functions can
|
* be chained together. Methods that retrieve a single value or may return a
|
* primitive value will automatically end the chain returning the unwrapped
|
* value. Explicit chaining may be enabled using `_.chain`. The execution of
|
* chained methods is lazy, that is, execution is deferred until `_#value`
|
* is implicitly or explicitly called.
|
*
|
* Lazy evaluation allows several methods to support shortcut fusion. Shortcut
|
* fusion is an optimization strategy which merge iteratee calls; this can help
|
* to avoid the creation of intermediate data structures and greatly reduce the
|
* number of iteratee executions.
|
*
|
* Chaining is supported in custom builds as long as the `_#value` method is
|
* directly or indirectly included in the build.
|
*
|
* In addition to lodash methods, wrappers have `Array` and `String` methods.
|
*
|
* The wrapper `Array` methods are:
|
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
|
* `splice`, and `unshift`
|
*
|
* The wrapper `String` methods are:
|
* `replace` and `split`
|
*
|
* The wrapper methods that support shortcut fusion are:
|
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
|
* `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
|
* `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
|
* and `where`
|
*
|
* The chainable wrapper methods are:
|
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
|
* `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
|
* `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
|
* `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
|
* `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
|
* `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
|
* `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
|
* `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
|
* `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
|
* `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
|
* `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
|
* `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
|
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
|
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
|
* `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
|
*
|
* The wrapper methods that are **not** chainable by default are:
|
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
|
* `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
|
* `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
|
* `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
|
* `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
|
* `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
|
* `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
|
* `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
|
* `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
|
* `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
|
* `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
|
* `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
|
* `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
|
* `unescape`, `uniqueId`, `value`, and `words`
|
*
|
* The wrapper method `sample` will return a wrapped value when `n` is provided,
|
* otherwise an unwrapped value is returned.
|
*
|
* @name _
|
* @constructor
|
* @category Chain
|
* @param {*} value The value to wrap in a `lodash` instance.
|
* @returns {Object} Returns the new `lodash` wrapper instance.
|
* @example
|
*
|
* var wrapped = _([1, 2, 3]);
|
*
|
* // returns an unwrapped value
|
* wrapped.reduce(function(total, n) {
|
* return total + n;
|
* });
|
* // => 6
|
*
|
* // returns a wrapped value
|
* var squares = wrapped.map(function(n) {
|
* return n * n;
|
* });
|
*
|
* _.isArray(squares);
|
* // => false
|
*
|
* _.isArray(squares.value());
|
* // => true
|
*/
|
function lodash(value) {
|
if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
|
if (value instanceof LodashWrapper) {
|
return value;
|
}
|
if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
|
return wrapperClone(value);
|
}
|
}
|
return new LodashWrapper(value);
|
}
|
|
/**
|
* The function whose prototype all chaining wrappers inherit from.
|
*
|
* @private
|
*/
|
function baseLodash() {
|
// No operation performed.
|
}
|
|
/**
|
* The base constructor for creating `lodash` wrapper objects.
|
*
|
* @private
|
* @param {*} value The value to wrap.
|
* @param {boolean} [chainAll] Enable chaining for all wrapper methods.
|
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
|
*/
|
function LodashWrapper(value, chainAll, actions) {
|
this.__wrapped__ = value;
|
this.__actions__ = actions || [];
|
this.__chain__ = !!chainAll;
|
}
|
|
/**
|
* An object environment feature flags.
|
*
|
* @static
|
* @memberOf _
|
* @type Object
|
*/
|
var support = lodash.support = {};
|
|
/**
|
* By default, the template delimiters used by lodash are like those in
|
* embedded Ruby (ERB). Change the following template settings to use
|
* alternative delimiters.
|
*
|
* @static
|
* @memberOf _
|
* @type Object
|
*/
|
lodash.templateSettings = {
|
|
/**
|
* Used to detect `data` property values to be HTML-escaped.
|
*
|
* @memberOf _.templateSettings
|
* @type RegExp
|
*/
|
'escape': reEscape,
|
|
/**
|
* Used to detect code to be evaluated.
|
*
|
* @memberOf _.templateSettings
|
* @type RegExp
|
*/
|
'evaluate': reEvaluate,
|
|
/**
|
* Used to detect `data` property values to inject.
|
*
|
* @memberOf _.templateSettings
|
* @type RegExp
|
*/
|
'interpolate': reInterpolate,
|
|
/**
|
* Used to reference the data object in the template text.
|
*
|
* @memberOf _.templateSettings
|
* @type string
|
*/
|
'variable': '',
|
|
/**
|
* Used to import variables into the compiled template.
|
*
|
* @memberOf _.templateSettings
|
* @type Object
|
*/
|
'imports': {
|
|
/**
|
* A reference to the `lodash` function.
|
*
|
* @memberOf _.templateSettings.imports
|
* @type Function
|
*/
|
'_': lodash
|
}
|
};
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
|
*
|
* @private
|
* @param {*} value The value to wrap.
|
*/
|
function LazyWrapper(value) {
|
this.__wrapped__ = value;
|
this.__actions__ = [];
|
this.__dir__ = 1;
|
this.__filtered__ = false;
|
this.__iteratees__ = [];
|
this.__takeCount__ = POSITIVE_INFINITY;
|
this.__views__ = [];
|
}
|
|
/**
|
* Creates a clone of the lazy wrapper object.
|
*
|
* @private
|
* @name clone
|
* @memberOf LazyWrapper
|
* @returns {Object} Returns the cloned `LazyWrapper` object.
|
*/
|
function lazyClone() {
|
var result = new LazyWrapper(this.__wrapped__);
|
result.__actions__ = arrayCopy(this.__actions__);
|
result.__dir__ = this.__dir__;
|
result.__filtered__ = this.__filtered__;
|
result.__iteratees__ = arrayCopy(this.__iteratees__);
|
result.__takeCount__ = this.__takeCount__;
|
result.__views__ = arrayCopy(this.__views__);
|
return result;
|
}
|
|
/**
|
* Reverses the direction of lazy iteration.
|
*
|
* @private
|
* @name reverse
|
* @memberOf LazyWrapper
|
* @returns {Object} Returns the new reversed `LazyWrapper` object.
|
*/
|
function lazyReverse() {
|
if (this.__filtered__) {
|
var result = new LazyWrapper(this);
|
result.__dir__ = -1;
|
result.__filtered__ = true;
|
} else {
|
result = this.clone();
|
result.__dir__ *= -1;
|
}
|
return result;
|
}
|
|
/**
|
* Extracts the unwrapped value from its lazy wrapper.
|
*
|
* @private
|
* @name value
|
* @memberOf LazyWrapper
|
* @returns {*} Returns the unwrapped value.
|
*/
|
function lazyValue() {
|
var array = this.__wrapped__.value(),
|
dir = this.__dir__,
|
isArr = isArray(array),
|
isRight = dir < 0,
|
arrLength = isArr ? array.length : 0,
|
view = getView(0, arrLength, this.__views__),
|
start = view.start,
|
end = view.end,
|
length = end - start,
|
index = isRight ? end : (start - 1),
|
iteratees = this.__iteratees__,
|
iterLength = iteratees.length,
|
resIndex = 0,
|
takeCount = nativeMin(length, this.__takeCount__);
|
|
if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
|
return baseWrapperValue((isRight && isArr) ? array.reverse() : array, this.__actions__);
|
}
|
var result = [];
|
|
outer:
|
while (length-- && resIndex < takeCount) {
|
index += dir;
|
|
var iterIndex = -1,
|
value = array[index];
|
|
while (++iterIndex < iterLength) {
|
var data = iteratees[iterIndex],
|
iteratee = data.iteratee,
|
type = data.type,
|
computed = iteratee(value);
|
|
if (type == LAZY_MAP_FLAG) {
|
value = computed;
|
} else if (!computed) {
|
if (type == LAZY_FILTER_FLAG) {
|
continue outer;
|
} else {
|
break outer;
|
}
|
}
|
}
|
result[resIndex++] = value;
|
}
|
return result;
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Creates a cache object to store key/value pairs.
|
*
|
* @private
|
* @static
|
* @name Cache
|
* @memberOf _.memoize
|
*/
|
function MapCache() {
|
this.__data__ = {};
|
}
|
|
/**
|
* Removes `key` and its value from the cache.
|
*
|
* @private
|
* @name delete
|
* @memberOf _.memoize.Cache
|
* @param {string} key The key of the value to remove.
|
* @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
|
*/
|
function mapDelete(key) {
|
return this.has(key) && delete this.__data__[key];
|
}
|
|
/**
|
* Gets the cached value for `key`.
|
*
|
* @private
|
* @name get
|
* @memberOf _.memoize.Cache
|
* @param {string} key The key of the value to get.
|
* @returns {*} Returns the cached value.
|
*/
|
function mapGet(key) {
|
return key == '__proto__' ? undefined : this.__data__[key];
|
}
|
|
/**
|
* Checks if a cached value for `key` exists.
|
*
|
* @private
|
* @name has
|
* @memberOf _.memoize.Cache
|
* @param {string} key The key of the entry to check.
|
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
|
*/
|
function mapHas(key) {
|
return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
|
}
|
|
/**
|
* Sets `value` to `key` of the cache.
|
*
|
* @private
|
* @name set
|
* @memberOf _.memoize.Cache
|
* @param {string} key The key of the value to cache.
|
* @param {*} value The value to cache.
|
* @returns {Object} Returns the cache object.
|
*/
|
function mapSet(key, value) {
|
if (key != '__proto__') {
|
this.__data__[key] = value;
|
}
|
return this;
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
*
|
* Creates a cache object to store unique values.
|
*
|
* @private
|
* @param {Array} [values] The values to cache.
|
*/
|
function SetCache(values) {
|
var length = values ? values.length : 0;
|
|
this.data = { 'hash': nativeCreate(null), 'set': new Set };
|
while (length--) {
|
this.push(values[length]);
|
}
|
}
|
|
/**
|
* Checks if `value` is in `cache` mimicking the return signature of
|
* `_.indexOf` by returning `0` if the value is found, else `-1`.
|
*
|
* @private
|
* @param {Object} cache The cache to search.
|
* @param {*} value The value to search for.
|
* @returns {number} Returns `0` if `value` is found, else `-1`.
|
*/
|
function cacheIndexOf(cache, value) {
|
var data = cache.data,
|
result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
|
|
return result ? 0 : -1;
|
}
|
|
/**
|
* Adds `value` to the cache.
|
*
|
* @private
|
* @name push
|
* @memberOf SetCache
|
* @param {*} value The value to cache.
|
*/
|
function cachePush(value) {
|
var data = this.data;
|
if (typeof value == 'string' || isObject(value)) {
|
data.set.add(value);
|
} else {
|
data.hash[value] = true;
|
}
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Creates a new array joining `array` with `other`.
|
*
|
* @private
|
* @param {Array} array The array to join.
|
* @param {Array} other The other array to join.
|
* @returns {Array} Returns the new concatenated array.
|
*/
|
function arrayConcat(array, other) {
|
var index = -1,
|
length = array.length,
|
othIndex = -1,
|
othLength = other.length,
|
result = Array(length + othLength);
|
|
while (++index < length) {
|
result[index] = array[index];
|
}
|
while (++othIndex < othLength) {
|
result[index++] = other[othIndex];
|
}
|
return result;
|
}
|
|
/**
|
* Copies the values of `source` to `array`.
|
*
|
* @private
|
* @param {Array} source The array to copy values from.
|
* @param {Array} [array=[]] The array to copy values to.
|
* @returns {Array} Returns `array`.
|
*/
|
function arrayCopy(source, array) {
|
var index = -1,
|
length = source.length;
|
|
array || (array = Array(length));
|
while (++index < length) {
|
array[index] = source[index];
|
}
|
return array;
|
}
|
|
/**
|
* A specialized version of `_.forEach` for arrays without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Array} Returns `array`.
|
*/
|
function arrayEach(array, iteratee) {
|
var index = -1,
|
length = array.length;
|
|
while (++index < length) {
|
if (iteratee(array[index], index, array) === false) {
|
break;
|
}
|
}
|
return array;
|
}
|
|
/**
|
* A specialized version of `_.forEachRight` for arrays without support for
|
* callback shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Array} Returns `array`.
|
*/
|
function arrayEachRight(array, iteratee) {
|
var length = array.length;
|
|
while (length--) {
|
if (iteratee(array[length], length, array) === false) {
|
break;
|
}
|
}
|
return array;
|
}
|
|
/**
|
* A specialized version of `_.every` for arrays without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} predicate The function invoked per iteration.
|
* @returns {boolean} Returns `true` if all elements pass the predicate check,
|
* else `false`.
|
*/
|
function arrayEvery(array, predicate) {
|
var index = -1,
|
length = array.length;
|
|
while (++index < length) {
|
if (!predicate(array[index], index, array)) {
|
return false;
|
}
|
}
|
return true;
|
}
|
|
/**
|
* A specialized version of `baseExtremum` for arrays which invokes `iteratee`
|
* with one argument: (value).
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} comparator The function used to compare values.
|
* @param {*} exValue The initial extremum value.
|
* @returns {*} Returns the extremum value.
|
*/
|
function arrayExtremum(array, iteratee, comparator, exValue) {
|
var index = -1,
|
length = array.length,
|
computed = exValue,
|
result = computed;
|
|
while (++index < length) {
|
var value = array[index],
|
current = +iteratee(value);
|
|
if (comparator(current, computed)) {
|
computed = current;
|
result = value;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* A specialized version of `_.filter` for arrays without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} predicate The function invoked per iteration.
|
* @returns {Array} Returns the new filtered array.
|
*/
|
function arrayFilter(array, predicate) {
|
var index = -1,
|
length = array.length,
|
resIndex = -1,
|
result = [];
|
|
while (++index < length) {
|
var value = array[index];
|
if (predicate(value, index, array)) {
|
result[++resIndex] = value;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* A specialized version of `_.map` for arrays without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Array} Returns the new mapped array.
|
*/
|
function arrayMap(array, iteratee) {
|
var index = -1,
|
length = array.length,
|
result = Array(length);
|
|
while (++index < length) {
|
result[index] = iteratee(array[index], index, array);
|
}
|
return result;
|
}
|
|
/**
|
* Appends the elements of `values` to `array`.
|
*
|
* @private
|
* @param {Array} array The array to modify.
|
* @param {Array} values The values to append.
|
* @returns {Array} Returns `array`.
|
*/
|
function arrayPush(array, values) {
|
var index = -1,
|
length = values.length,
|
offset = array.length;
|
|
while (++index < length) {
|
array[offset + index] = values[index];
|
}
|
return array;
|
}
|
|
/**
|
* A specialized version of `_.reduce` for arrays without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @param {*} [accumulator] The initial value.
|
* @param {boolean} [initFromArray] Specify using the first element of `array`
|
* as the initial value.
|
* @returns {*} Returns the accumulated value.
|
*/
|
function arrayReduce(array, iteratee, accumulator, initFromArray) {
|
var index = -1,
|
length = array.length;
|
|
if (initFromArray && length) {
|
accumulator = array[++index];
|
}
|
while (++index < length) {
|
accumulator = iteratee(accumulator, array[index], index, array);
|
}
|
return accumulator;
|
}
|
|
/**
|
* A specialized version of `_.reduceRight` for arrays without support for
|
* callback shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @param {*} [accumulator] The initial value.
|
* @param {boolean} [initFromArray] Specify using the last element of `array`
|
* as the initial value.
|
* @returns {*} Returns the accumulated value.
|
*/
|
function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
|
var length = array.length;
|
if (initFromArray && length) {
|
accumulator = array[--length];
|
}
|
while (length--) {
|
accumulator = iteratee(accumulator, array[length], length, array);
|
}
|
return accumulator;
|
}
|
|
/**
|
* A specialized version of `_.some` for arrays without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} predicate The function invoked per iteration.
|
* @returns {boolean} Returns `true` if any element passes the predicate check,
|
* else `false`.
|
*/
|
function arraySome(array, predicate) {
|
var index = -1,
|
length = array.length;
|
|
while (++index < length) {
|
if (predicate(array[index], index, array)) {
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/**
|
* A specialized version of `_.sum` for arrays without support for callback
|
* shorthands and `this` binding..
|
*
|
* @private
|
* @param {Array} array The array to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {number} Returns the sum.
|
*/
|
function arraySum(array, iteratee) {
|
var length = array.length,
|
result = 0;
|
|
while (length--) {
|
result += +iteratee(array[length]) || 0;
|
}
|
return result;
|
}
|
|
/**
|
* Used by `_.defaults` to customize its `_.assign` use.
|
*
|
* @private
|
* @param {*} objectValue The destination object property value.
|
* @param {*} sourceValue The source object property value.
|
* @returns {*} Returns the value to assign to the destination object.
|
*/
|
function assignDefaults(objectValue, sourceValue) {
|
return objectValue === undefined ? sourceValue : objectValue;
|
}
|
|
/**
|
* Used by `_.template` to customize its `_.assign` use.
|
*
|
* **Note:** This function is like `assignDefaults` except that it ignores
|
* inherited property values when checking if a property is `undefined`.
|
*
|
* @private
|
* @param {*} objectValue The destination object property value.
|
* @param {*} sourceValue The source object property value.
|
* @param {string} key The key associated with the object and source values.
|
* @param {Object} object The destination object.
|
* @returns {*} Returns the value to assign to the destination object.
|
*/
|
function assignOwnDefaults(objectValue, sourceValue, key, object) {
|
return (objectValue === undefined || !hasOwnProperty.call(object, key))
|
? sourceValue
|
: objectValue;
|
}
|
|
/**
|
* A specialized version of `_.assign` for customizing assigned values without
|
* support for argument juggling, multiple sources, and `this` binding `customizer`
|
* functions.
|
*
|
* @private
|
* @param {Object} object The destination object.
|
* @param {Object} source The source object.
|
* @param {Function} customizer The function to customize assigned values.
|
* @returns {Object} Returns `object`.
|
*/
|
function assignWith(object, source, customizer) {
|
var index = -1,
|
props = keys(source),
|
length = props.length;
|
|
while (++index < length) {
|
var key = props[index],
|
value = object[key],
|
result = customizer(value, source[key], key, object, source);
|
|
if ((result === result ? (result !== value) : (value === value)) ||
|
(value === undefined && !(key in object))) {
|
object[key] = result;
|
}
|
}
|
return object;
|
}
|
|
/**
|
* The base implementation of `_.assign` without support for argument juggling,
|
* multiple sources, and `customizer` functions.
|
*
|
* @private
|
* @param {Object} object The destination object.
|
* @param {Object} source The source object.
|
* @returns {Object} Returns `object`.
|
*/
|
function baseAssign(object, source) {
|
return source == null
|
? object
|
: baseCopy(source, keys(source), object);
|
}
|
|
/**
|
* The base implementation of `_.at` without support for string collections
|
* and individual key arguments.
|
*
|
* @private
|
* @param {Array|Object} collection The collection to iterate over.
|
* @param {number[]|string[]} props The property names or indexes of elements to pick.
|
* @returns {Array} Returns the new array of picked elements.
|
*/
|
function baseAt(collection, props) {
|
var index = -1,
|
isNil = collection == null,
|
isArr = !isNil && isArrayLike(collection),
|
length = isArr ? collection.length : 0,
|
propsLength = props.length,
|
result = Array(propsLength);
|
|
while(++index < propsLength) {
|
var key = props[index];
|
if (isArr) {
|
result[index] = isIndex(key, length) ? collection[key] : undefined;
|
} else {
|
result[index] = isNil ? undefined : collection[key];
|
}
|
}
|
return result;
|
}
|
|
/**
|
* Copies properties of `source` to `object`.
|
*
|
* @private
|
* @param {Object} source The object to copy properties from.
|
* @param {Array} props The property names to copy.
|
* @param {Object} [object={}] The object to copy properties to.
|
* @returns {Object} Returns `object`.
|
*/
|
function baseCopy(source, props, object) {
|
object || (object = {});
|
|
var index = -1,
|
length = props.length;
|
|
while (++index < length) {
|
var key = props[index];
|
object[key] = source[key];
|
}
|
return object;
|
}
|
|
/**
|
* The base implementation of `_.callback` which supports specifying the
|
* number of arguments to provide to `func`.
|
*
|
* @private
|
* @param {*} [func=_.identity] The value to convert to a callback.
|
* @param {*} [thisArg] The `this` binding of `func`.
|
* @param {number} [argCount] The number of arguments to provide to `func`.
|
* @returns {Function} Returns the callback.
|
*/
|
function baseCallback(func, thisArg, argCount) {
|
var type = typeof func;
|
if (type == 'function') {
|
return thisArg === undefined
|
? func
|
: bindCallback(func, thisArg, argCount);
|
}
|
if (func == null) {
|
return identity;
|
}
|
if (type == 'object') {
|
return baseMatches(func);
|
}
|
return thisArg === undefined
|
? property(func)
|
: baseMatchesProperty(func, thisArg);
|
}
|
|
/**
|
* The base implementation of `_.clone` without support for argument juggling
|
* and `this` binding `customizer` functions.
|
*
|
* @private
|
* @param {*} value The value to clone.
|
* @param {boolean} [isDeep] Specify a deep clone.
|
* @param {Function} [customizer] The function to customize cloning values.
|
* @param {string} [key] The key of `value`.
|
* @param {Object} [object] The object `value` belongs to.
|
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
* @param {Array} [stackB=[]] Associates clones with source counterparts.
|
* @returns {*} Returns the cloned value.
|
*/
|
function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
|
var result;
|
if (customizer) {
|
result = object ? customizer(value, key, object) : customizer(value);
|
}
|
if (result !== undefined) {
|
return result;
|
}
|
if (!isObject(value)) {
|
return value;
|
}
|
var isArr = isArray(value);
|
if (isArr) {
|
result = initCloneArray(value);
|
if (!isDeep) {
|
return arrayCopy(value, result);
|
}
|
} else {
|
var tag = objToString.call(value),
|
isFunc = tag == funcTag;
|
|
if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
|
result = initCloneObject(isFunc ? {} : value);
|
if (!isDeep) {
|
return baseAssign(result, value);
|
}
|
} else {
|
return cloneableTags[tag]
|
? initCloneByTag(value, tag, isDeep)
|
: (object ? value : {});
|
}
|
}
|
// Check for circular references and return its corresponding clone.
|
stackA || (stackA = []);
|
stackB || (stackB = []);
|
|
var length = stackA.length;
|
while (length--) {
|
if (stackA[length] == value) {
|
return stackB[length];
|
}
|
}
|
// Add the source value to the stack of traversed objects and associate it with its clone.
|
stackA.push(value);
|
stackB.push(result);
|
|
// Recursively populate clone (susceptible to call stack limits).
|
(isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
|
result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
|
});
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.create` without support for assigning
|
* properties to the created object.
|
*
|
* @private
|
* @param {Object} prototype The object to inherit from.
|
* @returns {Object} Returns the new object.
|
*/
|
var baseCreate = (function() {
|
function object() {}
|
return function(prototype) {
|
if (isObject(prototype)) {
|
object.prototype = prototype;
|
var result = new object;
|
object.prototype = undefined;
|
}
|
return result || {};
|
};
|
}());
|
|
/**
|
* The base implementation of `_.delay` and `_.defer` which accepts an index
|
* of where to slice the arguments to provide to `func`.
|
*
|
* @private
|
* @param {Function} func The function to delay.
|
* @param {number} wait The number of milliseconds to delay invocation.
|
* @param {Object} args The arguments provide to `func`.
|
* @returns {number} Returns the timer id.
|
*/
|
function baseDelay(func, wait, args) {
|
if (typeof func != 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
return setTimeout(function() { func.apply(undefined, args); }, wait);
|
}
|
|
/**
|
* The base implementation of `_.difference` which accepts a single array
|
* of values to exclude.
|
*
|
* @private
|
* @param {Array} array The array to inspect.
|
* @param {Array} values The values to exclude.
|
* @returns {Array} Returns the new array of filtered values.
|
*/
|
function baseDifference(array, values) {
|
var length = array ? array.length : 0,
|
result = [];
|
|
if (!length) {
|
return result;
|
}
|
var index = -1,
|
indexOf = getIndexOf(),
|
isCommon = indexOf == baseIndexOf,
|
cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
|
valuesLength = values.length;
|
|
if (cache) {
|
indexOf = cacheIndexOf;
|
isCommon = false;
|
values = cache;
|
}
|
outer:
|
while (++index < length) {
|
var value = array[index];
|
|
if (isCommon && value === value) {
|
var valuesIndex = valuesLength;
|
while (valuesIndex--) {
|
if (values[valuesIndex] === value) {
|
continue outer;
|
}
|
}
|
result.push(value);
|
}
|
else if (indexOf(values, value, 0) < 0) {
|
result.push(value);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.forEach` without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Array|Object|string} Returns `collection`.
|
*/
|
var baseEach = createBaseEach(baseForOwn);
|
|
/**
|
* The base implementation of `_.forEachRight` without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Array|Object|string} Returns `collection`.
|
*/
|
var baseEachRight = createBaseEach(baseForOwnRight, true);
|
|
/**
|
* The base implementation of `_.every` without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} predicate The function invoked per iteration.
|
* @returns {boolean} Returns `true` if all elements pass the predicate check,
|
* else `false`
|
*/
|
function baseEvery(collection, predicate) {
|
var result = true;
|
baseEach(collection, function(value, index, collection) {
|
result = !!predicate(value, index, collection);
|
return result;
|
});
|
return result;
|
}
|
|
/**
|
* Gets the extremum value of `collection` invoking `iteratee` for each value
|
* in `collection` to generate the criterion by which the value is ranked.
|
* The `iteratee` is invoked with three arguments: (value, index|key, collection).
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} comparator The function used to compare values.
|
* @param {*} exValue The initial extremum value.
|
* @returns {*} Returns the extremum value.
|
*/
|
function baseExtremum(collection, iteratee, comparator, exValue) {
|
var computed = exValue,
|
result = computed;
|
|
baseEach(collection, function(value, index, collection) {
|
var current = +iteratee(value, index, collection);
|
if (comparator(current, computed) || (current === exValue && current === result)) {
|
computed = current;
|
result = value;
|
}
|
});
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.fill` without an iteratee call guard.
|
*
|
* @private
|
* @param {Array} array The array to fill.
|
* @param {*} value The value to fill `array` with.
|
* @param {number} [start=0] The start position.
|
* @param {number} [end=array.length] The end position.
|
* @returns {Array} Returns `array`.
|
*/
|
function baseFill(array, value, start, end) {
|
var length = array.length;
|
|
start = start == null ? 0 : (+start || 0);
|
if (start < 0) {
|
start = -start > length ? 0 : (length + start);
|
}
|
end = (end === undefined || end > length) ? length : (+end || 0);
|
if (end < 0) {
|
end += length;
|
}
|
length = start > end ? 0 : (end >>> 0);
|
start >>>= 0;
|
|
while (start < length) {
|
array[start++] = value;
|
}
|
return array;
|
}
|
|
/**
|
* The base implementation of `_.filter` without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} predicate The function invoked per iteration.
|
* @returns {Array} Returns the new filtered array.
|
*/
|
function baseFilter(collection, predicate) {
|
var result = [];
|
baseEach(collection, function(value, index, collection) {
|
if (predicate(value, index, collection)) {
|
result.push(value);
|
}
|
});
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
|
* without support for callback shorthands and `this` binding, which iterates
|
* over `collection` using the provided `eachFunc`.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to search.
|
* @param {Function} predicate The function invoked per iteration.
|
* @param {Function} eachFunc The function to iterate over `collection`.
|
* @param {boolean} [retKey] Specify returning the key of the found element
|
* instead of the element itself.
|
* @returns {*} Returns the found element or its key, else `undefined`.
|
*/
|
function baseFind(collection, predicate, eachFunc, retKey) {
|
var result;
|
eachFunc(collection, function(value, key, collection) {
|
if (predicate(value, key, collection)) {
|
result = retKey ? key : value;
|
return false;
|
}
|
});
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.flatten` with added support for restricting
|
* flattening and specifying the start index.
|
*
|
* @private
|
* @param {Array} array The array to flatten.
|
* @param {boolean} [isDeep] Specify a deep flatten.
|
* @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
|
* @param {Array} [result=[]] The initial result value.
|
* @returns {Array} Returns the new flattened array.
|
*/
|
function baseFlatten(array, isDeep, isStrict, result) {
|
result || (result = []);
|
|
var index = -1,
|
length = array.length;
|
|
while (++index < length) {
|
var value = array[index];
|
if (isObjectLike(value) && isArrayLike(value) &&
|
(isStrict || isArray(value) || isArguments(value))) {
|
if (isDeep) {
|
// Recursively flatten arrays (susceptible to call stack limits).
|
baseFlatten(value, isDeep, isStrict, result);
|
} else {
|
arrayPush(result, value);
|
}
|
} else if (!isStrict) {
|
result[result.length] = value;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* The base implementation of `baseForIn` and `baseForOwn` which iterates
|
* over `object` properties returned by `keysFunc` invoking `iteratee` for
|
* each property. Iteratee functions may exit iteration early by explicitly
|
* returning `false`.
|
*
|
* @private
|
* @param {Object} object The object to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} keysFunc The function to get the keys of `object`.
|
* @returns {Object} Returns `object`.
|
*/
|
var baseFor = createBaseFor();
|
|
/**
|
* This function is like `baseFor` except that it iterates over properties
|
* in the opposite order.
|
*
|
* @private
|
* @param {Object} object The object to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @param {Function} keysFunc The function to get the keys of `object`.
|
* @returns {Object} Returns `object`.
|
*/
|
var baseForRight = createBaseFor(true);
|
|
/**
|
* The base implementation of `_.forIn` without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Object} object The object to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Object} Returns `object`.
|
*/
|
function baseForIn(object, iteratee) {
|
return baseFor(object, iteratee, keysIn);
|
}
|
|
/**
|
* The base implementation of `_.forOwn` without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Object} object The object to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Object} Returns `object`.
|
*/
|
function baseForOwn(object, iteratee) {
|
return baseFor(object, iteratee, keys);
|
}
|
|
/**
|
* The base implementation of `_.forOwnRight` without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Object} object The object to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Object} Returns `object`.
|
*/
|
function baseForOwnRight(object, iteratee) {
|
return baseForRight(object, iteratee, keys);
|
}
|
|
/**
|
* The base implementation of `_.functions` which creates an array of
|
* `object` function property names filtered from those provided.
|
*
|
* @private
|
* @param {Object} object The object to inspect.
|
* @param {Array} props The property names to filter.
|
* @returns {Array} Returns the new array of filtered property names.
|
*/
|
function baseFunctions(object, props) {
|
var index = -1,
|
length = props.length,
|
resIndex = -1,
|
result = [];
|
|
while (++index < length) {
|
var key = props[index];
|
if (isFunction(object[key])) {
|
result[++resIndex] = key;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* The base implementation of `get` without support for string paths
|
* and default values.
|
*
|
* @private
|
* @param {Object} object The object to query.
|
* @param {Array} path The path of the property to get.
|
* @param {string} [pathKey] The key representation of path.
|
* @returns {*} Returns the resolved value.
|
*/
|
function baseGet(object, path, pathKey) {
|
if (object == null) {
|
return;
|
}
|
if (pathKey !== undefined && pathKey in toObject(object)) {
|
path = [pathKey];
|
}
|
var index = 0,
|
length = path.length;
|
|
while (object != null && index < length) {
|
object = object[path[index++]];
|
}
|
return (index && index == length) ? object : undefined;
|
}
|
|
/**
|
* The base implementation of `_.isEqual` without support for `this` binding
|
* `customizer` functions.
|
*
|
* @private
|
* @param {*} value The value to compare.
|
* @param {*} other The other value to compare.
|
* @param {Function} [customizer] The function to customize comparing values.
|
* @param {boolean} [isLoose] Specify performing partial comparisons.
|
* @param {Array} [stackA] Tracks traversed `value` objects.
|
* @param {Array} [stackB] Tracks traversed `other` objects.
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
*/
|
function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
|
if (value === other) {
|
return true;
|
}
|
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
|
return value !== value && other !== other;
|
}
|
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
|
}
|
|
/**
|
* A specialized version of `baseIsEqual` for arrays and objects which performs
|
* deep comparisons and tracks traversed objects enabling objects with circular
|
* references to be compared.
|
*
|
* @private
|
* @param {Object} object The object to compare.
|
* @param {Object} other The other object to compare.
|
* @param {Function} equalFunc The function to determine equivalents of values.
|
* @param {Function} [customizer] The function to customize comparing objects.
|
* @param {boolean} [isLoose] Specify performing partial comparisons.
|
* @param {Array} [stackA=[]] Tracks traversed `value` objects.
|
* @param {Array} [stackB=[]] Tracks traversed `other` objects.
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
*/
|
function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
|
var objIsArr = isArray(object),
|
othIsArr = isArray(other),
|
objTag = arrayTag,
|
othTag = arrayTag;
|
|
if (!objIsArr) {
|
objTag = objToString.call(object);
|
if (objTag == argsTag) {
|
objTag = objectTag;
|
} else if (objTag != objectTag) {
|
objIsArr = isTypedArray(object);
|
}
|
}
|
if (!othIsArr) {
|
othTag = objToString.call(other);
|
if (othTag == argsTag) {
|
othTag = objectTag;
|
} else if (othTag != objectTag) {
|
othIsArr = isTypedArray(other);
|
}
|
}
|
var objIsObj = objTag == objectTag,
|
othIsObj = othTag == objectTag,
|
isSameTag = objTag == othTag;
|
|
if (isSameTag && !(objIsArr || objIsObj)) {
|
return equalByTag(object, other, objTag);
|
}
|
if (!isLoose) {
|
var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
|
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
|
|
if (objIsWrapped || othIsWrapped) {
|
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
|
}
|
}
|
if (!isSameTag) {
|
return false;
|
}
|
// Assume cyclic values are equal.
|
// For more information on detecting circular references see https://es5.github.io/#JO.
|
stackA || (stackA = []);
|
stackB || (stackB = []);
|
|
var length = stackA.length;
|
while (length--) {
|
if (stackA[length] == object) {
|
return stackB[length] == other;
|
}
|
}
|
// Add `object` and `other` to the stack of traversed objects.
|
stackA.push(object);
|
stackB.push(other);
|
|
var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
|
|
stackA.pop();
|
stackB.pop();
|
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.isMatch` without support for callback
|
* shorthands and `this` binding.
|
*
|
* @private
|
* @param {Object} object The object to inspect.
|
* @param {Array} matchData The propery names, values, and compare flags to match.
|
* @param {Function} [customizer] The function to customize comparing objects.
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
*/
|
function baseIsMatch(object, matchData, customizer) {
|
var index = matchData.length,
|
length = index,
|
noCustomizer = !customizer;
|
|
if (object == null) {
|
return !length;
|
}
|
object = toObject(object);
|
while (index--) {
|
var data = matchData[index];
|
if ((noCustomizer && data[2])
|
? data[1] !== object[data[0]]
|
: !(data[0] in object)
|
) {
|
return false;
|
}
|
}
|
while (++index < length) {
|
data = matchData[index];
|
var key = data[0],
|
objValue = object[key],
|
srcValue = data[1];
|
|
if (noCustomizer && data[2]) {
|
if (objValue === undefined && !(key in object)) {
|
return false;
|
}
|
} else {
|
var result = customizer ? customizer(objValue, srcValue, key) : undefined;
|
if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
|
return false;
|
}
|
}
|
}
|
return true;
|
}
|
|
/**
|
* The base implementation of `_.map` without support for callback shorthands
|
* and `this` binding.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {Array} Returns the new mapped array.
|
*/
|
function baseMap(collection, iteratee) {
|
var index = -1,
|
result = isArrayLike(collection) ? Array(collection.length) : [];
|
|
baseEach(collection, function(value, key, collection) {
|
result[++index] = iteratee(value, key, collection);
|
});
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.matches` which does not clone `source`.
|
*
|
* @private
|
* @param {Object} source The object of property values to match.
|
* @returns {Function} Returns the new function.
|
*/
|
function baseMatches(source) {
|
var matchData = getMatchData(source);
|
if (matchData.length == 1 && matchData[0][2]) {
|
var key = matchData[0][0],
|
value = matchData[0][1];
|
|
return function(object) {
|
if (object == null) {
|
return false;
|
}
|
return object[key] === value && (value !== undefined || (key in toObject(object)));
|
};
|
}
|
return function(object) {
|
return baseIsMatch(object, matchData);
|
};
|
}
|
|
/**
|
* The base implementation of `_.matchesProperty` which does not clone `srcValue`.
|
*
|
* @private
|
* @param {string} path The path of the property to get.
|
* @param {*} srcValue The value to compare.
|
* @returns {Function} Returns the new function.
|
*/
|
function baseMatchesProperty(path, srcValue) {
|
var isArr = isArray(path),
|
isCommon = isKey(path) && isStrictComparable(srcValue),
|
pathKey = (path + '');
|
|
path = toPath(path);
|
return function(object) {
|
if (object == null) {
|
return false;
|
}
|
var key = pathKey;
|
object = toObject(object);
|
if ((isArr || !isCommon) && !(key in object)) {
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
if (object == null) {
|
return false;
|
}
|
key = last(path);
|
object = toObject(object);
|
}
|
return object[key] === srcValue
|
? (srcValue !== undefined || (key in object))
|
: baseIsEqual(srcValue, object[key], undefined, true);
|
};
|
}
|
|
/**
|
* The base implementation of `_.merge` without support for argument juggling,
|
* multiple sources, and `this` binding `customizer` functions.
|
*
|
* @private
|
* @param {Object} object The destination object.
|
* @param {Object} source The source object.
|
* @param {Function} [customizer] The function to customize merged values.
|
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
* @returns {Object} Returns `object`.
|
*/
|
function baseMerge(object, source, customizer, stackA, stackB) {
|
if (!isObject(object)) {
|
return object;
|
}
|
var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
|
props = isSrcArr ? undefined : keys(source);
|
|
arrayEach(props || source, function(srcValue, key) {
|
if (props) {
|
key = srcValue;
|
srcValue = source[key];
|
}
|
if (isObjectLike(srcValue)) {
|
stackA || (stackA = []);
|
stackB || (stackB = []);
|
baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
|
}
|
else {
|
var value = object[key],
|
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
isCommon = result === undefined;
|
|
if (isCommon) {
|
result = srcValue;
|
}
|
if ((result !== undefined || (isSrcArr && !(key in object))) &&
|
(isCommon || (result === result ? (result !== value) : (value === value)))) {
|
object[key] = result;
|
}
|
}
|
});
|
return object;
|
}
|
|
/**
|
* A specialized version of `baseMerge` for arrays and objects which performs
|
* deep merges and tracks traversed objects enabling objects with circular
|
* references to be merged.
|
*
|
* @private
|
* @param {Object} object The destination object.
|
* @param {Object} source The source object.
|
* @param {string} key The key of the value to merge.
|
* @param {Function} mergeFunc The function to merge values.
|
* @param {Function} [customizer] The function to customize merged values.
|
* @param {Array} [stackA=[]] Tracks traversed source objects.
|
* @param {Array} [stackB=[]] Associates values with source counterparts.
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
*/
|
function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
|
var length = stackA.length,
|
srcValue = source[key];
|
|
while (length--) {
|
if (stackA[length] == srcValue) {
|
object[key] = stackB[length];
|
return;
|
}
|
}
|
var value = object[key],
|
result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
|
isCommon = result === undefined;
|
|
if (isCommon) {
|
result = srcValue;
|
if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
|
result = isArray(value)
|
? value
|
: (isArrayLike(value) ? arrayCopy(value) : []);
|
}
|
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
result = isArguments(value)
|
? toPlainObject(value)
|
: (isPlainObject(value) ? value : {});
|
}
|
else {
|
isCommon = false;
|
}
|
}
|
// Add the source value to the stack of traversed objects and associate
|
// it with its merged value.
|
stackA.push(srcValue);
|
stackB.push(result);
|
|
if (isCommon) {
|
// Recursively merge objects and arrays (susceptible to call stack limits).
|
object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
|
} else if (result === result ? (result !== value) : (value === value)) {
|
object[key] = result;
|
}
|
}
|
|
/**
|
* The base implementation of `_.property` without support for deep paths.
|
*
|
* @private
|
* @param {string} key The key of the property to get.
|
* @returns {Function} Returns the new function.
|
*/
|
function baseProperty(key) {
|
return function(object) {
|
return object == null ? undefined : object[key];
|
};
|
}
|
|
/**
|
* A specialized version of `baseProperty` which supports deep paths.
|
*
|
* @private
|
* @param {Array|string} path The path of the property to get.
|
* @returns {Function} Returns the new function.
|
*/
|
function basePropertyDeep(path) {
|
var pathKey = (path + '');
|
path = toPath(path);
|
return function(object) {
|
return baseGet(object, path, pathKey);
|
};
|
}
|
|
/**
|
* The base implementation of `_.pullAt` without support for individual
|
* index arguments and capturing the removed elements.
|
*
|
* @private
|
* @param {Array} array The array to modify.
|
* @param {number[]} indexes The indexes of elements to remove.
|
* @returns {Array} Returns `array`.
|
*/
|
function basePullAt(array, indexes) {
|
var length = array ? indexes.length : 0;
|
while (length--) {
|
var index = indexes[length];
|
if (index != previous && isIndex(index)) {
|
var previous = index;
|
splice.call(array, index, 1);
|
}
|
}
|
return array;
|
}
|
|
/**
|
* The base implementation of `_.random` without support for argument juggling
|
* and returning floating-point numbers.
|
*
|
* @private
|
* @param {number} min The minimum possible value.
|
* @param {number} max The maximum possible value.
|
* @returns {number} Returns the random number.
|
*/
|
function baseRandom(min, max) {
|
return min + nativeFloor(nativeRandom() * (max - min + 1));
|
}
|
|
/**
|
* The base implementation of `_.reduce` and `_.reduceRight` without support
|
* for callback shorthands and `this` binding, which iterates over `collection`
|
* using the provided `eachFunc`.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @param {*} accumulator The initial value.
|
* @param {boolean} initFromCollection Specify using the first or last element
|
* of `collection` as the initial value.
|
* @param {Function} eachFunc The function to iterate over `collection`.
|
* @returns {*} Returns the accumulated value.
|
*/
|
function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
|
eachFunc(collection, function(value, index, collection) {
|
accumulator = initFromCollection
|
? (initFromCollection = false, value)
|
: iteratee(accumulator, value, index, collection);
|
});
|
return accumulator;
|
}
|
|
/**
|
* The base implementation of `setData` without support for hot loop detection.
|
*
|
* @private
|
* @param {Function} func The function to associate metadata with.
|
* @param {*} data The metadata.
|
* @returns {Function} Returns `func`.
|
*/
|
var baseSetData = !metaMap ? identity : function(func, data) {
|
metaMap.set(func, data);
|
return func;
|
};
|
|
/**
|
* The base implementation of `_.slice` without an iteratee call guard.
|
*
|
* @private
|
* @param {Array} array The array to slice.
|
* @param {number} [start=0] The start position.
|
* @param {number} [end=array.length] The end position.
|
* @returns {Array} Returns the slice of `array`.
|
*/
|
function baseSlice(array, start, end) {
|
var index = -1,
|
length = array.length;
|
|
start = start == null ? 0 : (+start || 0);
|
if (start < 0) {
|
start = -start > length ? 0 : (length + start);
|
}
|
end = (end === undefined || end > length) ? length : (+end || 0);
|
if (end < 0) {
|
end += length;
|
}
|
length = start > end ? 0 : ((end - start) >>> 0);
|
start >>>= 0;
|
|
var result = Array(length);
|
while (++index < length) {
|
result[index] = array[index + start];
|
}
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.some` without support for callback shorthands
|
* and `this` binding.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} predicate The function invoked per iteration.
|
* @returns {boolean} Returns `true` if any element passes the predicate check,
|
* else `false`.
|
*/
|
function baseSome(collection, predicate) {
|
var result;
|
|
baseEach(collection, function(value, index, collection) {
|
result = predicate(value, index, collection);
|
return !result;
|
});
|
return !!result;
|
}
|
|
/**
|
* The base implementation of `_.sortBy` which uses `comparer` to define
|
* the sort order of `array` and replaces criteria objects with their
|
* corresponding values.
|
*
|
* @private
|
* @param {Array} array The array to sort.
|
* @param {Function} comparer The function to define sort order.
|
* @returns {Array} Returns `array`.
|
*/
|
function baseSortBy(array, comparer) {
|
var length = array.length;
|
|
array.sort(comparer);
|
while (length--) {
|
array[length] = array[length].value;
|
}
|
return array;
|
}
|
|
/**
|
* The base implementation of `_.sortByOrder` without param guards.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
* @param {boolean[]} orders The sort orders of `iteratees`.
|
* @returns {Array} Returns the new sorted array.
|
*/
|
function baseSortByOrder(collection, iteratees, orders) {
|
var callback = getCallback(),
|
index = -1;
|
|
iteratees = arrayMap(iteratees, function(iteratee) { return callback(iteratee); });
|
|
var result = baseMap(collection, function(value) {
|
var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
|
return { 'criteria': criteria, 'index': ++index, 'value': value };
|
});
|
|
return baseSortBy(result, function(object, other) {
|
return compareMultiple(object, other, orders);
|
});
|
}
|
|
/**
|
* The base implementation of `_.sum` without support for callback shorthands
|
* and `this` binding.
|
*
|
* @private
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @returns {number} Returns the sum.
|
*/
|
function baseSum(collection, iteratee) {
|
var result = 0;
|
baseEach(collection, function(value, index, collection) {
|
result += +iteratee(value, index, collection) || 0;
|
});
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.uniq` without support for callback shorthands
|
* and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to inspect.
|
* @param {Function} [iteratee] The function invoked per iteration.
|
* @returns {Array} Returns the new duplicate-value-free array.
|
*/
|
function baseUniq(array, iteratee) {
|
var index = -1,
|
indexOf = getIndexOf(),
|
length = array.length,
|
isCommon = indexOf == baseIndexOf,
|
isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
|
seen = isLarge ? createCache() : null,
|
result = [];
|
|
if (seen) {
|
indexOf = cacheIndexOf;
|
isCommon = false;
|
} else {
|
isLarge = false;
|
seen = iteratee ? [] : result;
|
}
|
outer:
|
while (++index < length) {
|
var value = array[index],
|
computed = iteratee ? iteratee(value, index, array) : value;
|
|
if (isCommon && value === value) {
|
var seenIndex = seen.length;
|
while (seenIndex--) {
|
if (seen[seenIndex] === computed) {
|
continue outer;
|
}
|
}
|
if (iteratee) {
|
seen.push(computed);
|
}
|
result.push(value);
|
}
|
else if (indexOf(seen, computed, 0) < 0) {
|
if (iteratee || isLarge) {
|
seen.push(computed);
|
}
|
result.push(value);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.values` and `_.valuesIn` which creates an
|
* array of `object` property values corresponding to the property names
|
* of `props`.
|
*
|
* @private
|
* @param {Object} object The object to query.
|
* @param {Array} props The property names to get values for.
|
* @returns {Object} Returns the array of property values.
|
*/
|
function baseValues(object, props) {
|
var index = -1,
|
length = props.length,
|
result = Array(length);
|
|
while (++index < length) {
|
result[index] = object[props[index]];
|
}
|
return result;
|
}
|
|
/**
|
* The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
|
* and `_.takeWhile` without support for callback shorthands and `this` binding.
|
*
|
* @private
|
* @param {Array} array The array to query.
|
* @param {Function} predicate The function invoked per iteration.
|
* @param {boolean} [isDrop] Specify dropping elements instead of taking them.
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
* @returns {Array} Returns the slice of `array`.
|
*/
|
function baseWhile(array, predicate, isDrop, fromRight) {
|
var length = array.length,
|
index = fromRight ? length : -1;
|
|
while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
|
return isDrop
|
? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
|
: baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
|
}
|
|
/**
|
* The base implementation of `wrapperValue` which returns the result of
|
* performing a sequence of actions on the unwrapped `value`, where each
|
* successive action is supplied the return value of the previous.
|
*
|
* @private
|
* @param {*} value The unwrapped value.
|
* @param {Array} actions Actions to peform to resolve the unwrapped value.
|
* @returns {*} Returns the resolved value.
|
*/
|
function baseWrapperValue(value, actions) {
|
var result = value;
|
if (result instanceof LazyWrapper) {
|
result = result.value();
|
}
|
var index = -1,
|
length = actions.length;
|
|
while (++index < length) {
|
var action = actions[index];
|
result = action.func.apply(action.thisArg, arrayPush([result], action.args));
|
}
|
return result;
|
}
|
|
/**
|
* Performs a binary search of `array` to determine the index at which `value`
|
* should be inserted into `array` in order to maintain its sort order.
|
*
|
* @private
|
* @param {Array} array The sorted array to inspect.
|
* @param {*} value The value to evaluate.
|
* @param {boolean} [retHighest] Specify returning the highest qualified index.
|
* @returns {number} Returns the index at which `value` should be inserted
|
* into `array`.
|
*/
|
function binaryIndex(array, value, retHighest) {
|
var low = 0,
|
high = array ? array.length : low;
|
|
if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
|
while (low < high) {
|
var mid = (low + high) >>> 1,
|
computed = array[mid];
|
|
if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
|
low = mid + 1;
|
} else {
|
high = mid;
|
}
|
}
|
return high;
|
}
|
return binaryIndexBy(array, value, identity, retHighest);
|
}
|
|
/**
|
* This function is like `binaryIndex` except that it invokes `iteratee` for
|
* `value` and each element of `array` to compute their sort ranking. The
|
* iteratee is invoked with one argument; (value).
|
*
|
* @private
|
* @param {Array} array The sorted array to inspect.
|
* @param {*} value The value to evaluate.
|
* @param {Function} iteratee The function invoked per iteration.
|
* @param {boolean} [retHighest] Specify returning the highest qualified index.
|
* @returns {number} Returns the index at which `value` should be inserted
|
* into `array`.
|
*/
|
function binaryIndexBy(array, value, iteratee, retHighest) {
|
value = iteratee(value);
|
|
var low = 0,
|
high = array ? array.length : 0,
|
valIsNaN = value !== value,
|
valIsNull = value === null,
|
valIsUndef = value === undefined;
|
|
while (low < high) {
|
var mid = nativeFloor((low + high) / 2),
|
computed = iteratee(array[mid]),
|
isDef = computed !== undefined,
|
isReflexive = computed === computed;
|
|
if (valIsNaN) {
|
var setLow = isReflexive || retHighest;
|
} else if (valIsNull) {
|
setLow = isReflexive && isDef && (retHighest || computed != null);
|
} else if (valIsUndef) {
|
setLow = isReflexive && (retHighest || isDef);
|
} else if (computed == null) {
|
setLow = false;
|
} else {
|
setLow = retHighest ? (computed <= value) : (computed < value);
|
}
|
if (setLow) {
|
low = mid + 1;
|
} else {
|
high = mid;
|
}
|
}
|
return nativeMin(high, MAX_ARRAY_INDEX);
|
}
|
|
/**
|
* A specialized version of `baseCallback` which only supports `this` binding
|
* and specifying the number of arguments to provide to `func`.
|
*
|
* @private
|
* @param {Function} func The function to bind.
|
* @param {*} thisArg The `this` binding of `func`.
|
* @param {number} [argCount] The number of arguments to provide to `func`.
|
* @returns {Function} Returns the callback.
|
*/
|
function bindCallback(func, thisArg, argCount) {
|
if (typeof func != 'function') {
|
return identity;
|
}
|
if (thisArg === undefined) {
|
return func;
|
}
|
switch (argCount) {
|
case 1: return function(value) {
|
return func.call(thisArg, value);
|
};
|
case 3: return function(value, index, collection) {
|
return func.call(thisArg, value, index, collection);
|
};
|
case 4: return function(accumulator, value, index, collection) {
|
return func.call(thisArg, accumulator, value, index, collection);
|
};
|
case 5: return function(value, other, key, object, source) {
|
return func.call(thisArg, value, other, key, object, source);
|
};
|
}
|
return function() {
|
return func.apply(thisArg, arguments);
|
};
|
}
|
|
/**
|
* Creates a clone of the given array buffer.
|
*
|
* @private
|
* @param {ArrayBuffer} buffer The array buffer to clone.
|
* @returns {ArrayBuffer} Returns the cloned array buffer.
|
*/
|
function bufferClone(buffer) {
|
var result = new ArrayBuffer(buffer.byteLength),
|
view = new Uint8Array(result);
|
|
view.set(new Uint8Array(buffer));
|
return result;
|
}
|
|
/**
|
* Creates an array that is the composition of partially applied arguments,
|
* placeholders, and provided arguments into a single array of arguments.
|
*
|
* @private
|
* @param {Array|Object} args The provided arguments.
|
* @param {Array} partials The arguments to prepend to those provided.
|
* @param {Array} holders The `partials` placeholder indexes.
|
* @returns {Array} Returns the new array of composed arguments.
|
*/
|
function composeArgs(args, partials, holders) {
|
var holdersLength = holders.length,
|
argsIndex = -1,
|
argsLength = nativeMax(args.length - holdersLength, 0),
|
leftIndex = -1,
|
leftLength = partials.length,
|
result = Array(leftLength + argsLength);
|
|
while (++leftIndex < leftLength) {
|
result[leftIndex] = partials[leftIndex];
|
}
|
while (++argsIndex < holdersLength) {
|
result[holders[argsIndex]] = args[argsIndex];
|
}
|
while (argsLength--) {
|
result[leftIndex++] = args[argsIndex++];
|
}
|
return result;
|
}
|
|
/**
|
* This function is like `composeArgs` except that the arguments composition
|
* is tailored for `_.partialRight`.
|
*
|
* @private
|
* @param {Array|Object} args The provided arguments.
|
* @param {Array} partials The arguments to append to those provided.
|
* @param {Array} holders The `partials` placeholder indexes.
|
* @returns {Array} Returns the new array of composed arguments.
|
*/
|
function composeArgsRight(args, partials, holders) {
|
var holdersIndex = -1,
|
holdersLength = holders.length,
|
argsIndex = -1,
|
argsLength = nativeMax(args.length - holdersLength, 0),
|
rightIndex = -1,
|
rightLength = partials.length,
|
result = Array(argsLength + rightLength);
|
|
while (++argsIndex < argsLength) {
|
result[argsIndex] = args[argsIndex];
|
}
|
var offset = argsIndex;
|
while (++rightIndex < rightLength) {
|
result[offset + rightIndex] = partials[rightIndex];
|
}
|
while (++holdersIndex < holdersLength) {
|
result[offset + holders[holdersIndex]] = args[argsIndex++];
|
}
|
return result;
|
}
|
|
/**
|
* Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
|
*
|
* @private
|
* @param {Function} setter The function to set keys and values of the accumulator object.
|
* @param {Function} [initializer] The function to initialize the accumulator object.
|
* @returns {Function} Returns the new aggregator function.
|
*/
|
function createAggregator(setter, initializer) {
|
return function(collection, iteratee, thisArg) {
|
var result = initializer ? initializer() : {};
|
iteratee = getCallback(iteratee, thisArg, 3);
|
|
if (isArray(collection)) {
|
var index = -1,
|
length = collection.length;
|
|
while (++index < length) {
|
var value = collection[index];
|
setter(result, value, iteratee(value, index, collection), collection);
|
}
|
} else {
|
baseEach(collection, function(value, key, collection) {
|
setter(result, value, iteratee(value, key, collection), collection);
|
});
|
}
|
return result;
|
};
|
}
|
|
/**
|
* Creates a `_.assign`, `_.defaults`, or `_.merge` function.
|
*
|
* @private
|
* @param {Function} assigner The function to assign values.
|
* @returns {Function} Returns the new assigner function.
|
*/
|
function createAssigner(assigner) {
|
return restParam(function(object, sources) {
|
var index = -1,
|
length = object == null ? 0 : sources.length,
|
customizer = length > 2 ? sources[length - 2] : undefined,
|
guard = length > 2 ? sources[2] : undefined,
|
thisArg = length > 1 ? sources[length - 1] : undefined;
|
|
if (typeof customizer == 'function') {
|
customizer = bindCallback(customizer, thisArg, 5);
|
length -= 2;
|
} else {
|
customizer = typeof thisArg == 'function' ? thisArg : undefined;
|
length -= (customizer ? 1 : 0);
|
}
|
if (guard && isIterateeCall(sources[0], sources[1], guard)) {
|
customizer = length < 3 ? undefined : customizer;
|
length = 1;
|
}
|
while (++index < length) {
|
var source = sources[index];
|
if (source) {
|
assigner(object, source, customizer);
|
}
|
}
|
return object;
|
});
|
}
|
|
/**
|
* Creates a `baseEach` or `baseEachRight` function.
|
*
|
* @private
|
* @param {Function} eachFunc The function to iterate over a collection.
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
* @returns {Function} Returns the new base function.
|
*/
|
function createBaseEach(eachFunc, fromRight) {
|
return function(collection, iteratee) {
|
var length = collection ? getLength(collection) : 0;
|
if (!isLength(length)) {
|
return eachFunc(collection, iteratee);
|
}
|
var index = fromRight ? length : -1,
|
iterable = toObject(collection);
|
|
while ((fromRight ? index-- : ++index < length)) {
|
if (iteratee(iterable[index], index, iterable) === false) {
|
break;
|
}
|
}
|
return collection;
|
};
|
}
|
|
/**
|
* Creates a base function for `_.forIn` or `_.forInRight`.
|
*
|
* @private
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
* @returns {Function} Returns the new base function.
|
*/
|
function createBaseFor(fromRight) {
|
return function(object, iteratee, keysFunc) {
|
var iterable = toObject(object),
|
props = keysFunc(object),
|
length = props.length,
|
index = fromRight ? length : -1;
|
|
while ((fromRight ? index-- : ++index < length)) {
|
var key = props[index];
|
if (iteratee(iterable[key], key, iterable) === false) {
|
break;
|
}
|
}
|
return object;
|
};
|
}
|
|
/**
|
* Creates a function that wraps `func` and invokes it with the `this`
|
* binding of `thisArg`.
|
*
|
* @private
|
* @param {Function} func The function to bind.
|
* @param {*} [thisArg] The `this` binding of `func`.
|
* @returns {Function} Returns the new bound function.
|
*/
|
function createBindWrapper(func, thisArg) {
|
var Ctor = createCtorWrapper(func);
|
|
function wrapper() {
|
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
return fn.apply(thisArg, arguments);
|
}
|
return wrapper;
|
}
|
|
/**
|
* Creates a `Set` cache object to optimize linear searches of large arrays.
|
*
|
* @private
|
* @param {Array} [values] The values to cache.
|
* @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
|
*/
|
function createCache(values) {
|
return (nativeCreate && Set) ? new SetCache(values) : null;
|
}
|
|
/**
|
* Creates a function that produces compound words out of the words in a
|
* given string.
|
*
|
* @private
|
* @param {Function} callback The function to combine each word.
|
* @returns {Function} Returns the new compounder function.
|
*/
|
function createCompounder(callback) {
|
return function(string) {
|
var index = -1,
|
array = words(deburr(string)),
|
length = array.length,
|
result = '';
|
|
while (++index < length) {
|
result = callback(result, array[index], index);
|
}
|
return result;
|
};
|
}
|
|
/**
|
* Creates a function that produces an instance of `Ctor` regardless of
|
* whether it was invoked as part of a `new` expression or by `call` or `apply`.
|
*
|
* @private
|
* @param {Function} Ctor The constructor to wrap.
|
* @returns {Function} Returns the new wrapped function.
|
*/
|
function createCtorWrapper(Ctor) {
|
return function() {
|
// Use a `switch` statement to work with class constructors.
|
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
// for more details.
|
var args = arguments;
|
switch (args.length) {
|
case 0: return new Ctor;
|
case 1: return new Ctor(args[0]);
|
case 2: return new Ctor(args[0], args[1]);
|
case 3: return new Ctor(args[0], args[1], args[2]);
|
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
|
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
|
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
|
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
|
}
|
var thisBinding = baseCreate(Ctor.prototype),
|
result = Ctor.apply(thisBinding, args);
|
|
// Mimic the constructor's `return` behavior.
|
// See https://es5.github.io/#x13.2.2 for more details.
|
return isObject(result) ? result : thisBinding;
|
};
|
}
|
|
/**
|
* Creates a `_.curry` or `_.curryRight` function.
|
*
|
* @private
|
* @param {boolean} flag The curry bit flag.
|
* @returns {Function} Returns the new curry function.
|
*/
|
function createCurry(flag) {
|
function curryFunc(func, arity, guard) {
|
if (guard && isIterateeCall(func, arity, guard)) {
|
arity = undefined;
|
}
|
var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
|
result.placeholder = curryFunc.placeholder;
|
return result;
|
}
|
return curryFunc;
|
}
|
|
/**
|
* Creates a `_.defaults` or `_.defaultsDeep` function.
|
*
|
* @private
|
* @param {Function} assigner The function to assign values.
|
* @param {Function} customizer The function to customize assigned values.
|
* @returns {Function} Returns the new defaults function.
|
*/
|
function createDefaults(assigner, customizer) {
|
return restParam(function(args) {
|
var object = args[0];
|
if (object == null) {
|
return object;
|
}
|
args.push(customizer);
|
return assigner.apply(undefined, args);
|
});
|
}
|
|
/**
|
* Creates a `_.max` or `_.min` function.
|
*
|
* @private
|
* @param {Function} comparator The function used to compare values.
|
* @param {*} exValue The initial extremum value.
|
* @returns {Function} Returns the new extremum function.
|
*/
|
function createExtremum(comparator, exValue) {
|
return function(collection, iteratee, thisArg) {
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
iteratee = undefined;
|
}
|
iteratee = getCallback(iteratee, thisArg, 3);
|
if (iteratee.length == 1) {
|
collection = isArray(collection) ? collection : toIterable(collection);
|
var result = arrayExtremum(collection, iteratee, comparator, exValue);
|
if (!(collection.length && result === exValue)) {
|
return result;
|
}
|
}
|
return baseExtremum(collection, iteratee, comparator, exValue);
|
};
|
}
|
|
/**
|
* Creates a `_.find` or `_.findLast` function.
|
*
|
* @private
|
* @param {Function} eachFunc The function to iterate over a collection.
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
* @returns {Function} Returns the new find function.
|
*/
|
function createFind(eachFunc, fromRight) {
|
return function(collection, predicate, thisArg) {
|
predicate = getCallback(predicate, thisArg, 3);
|
if (isArray(collection)) {
|
var index = baseFindIndex(collection, predicate, fromRight);
|
return index > -1 ? collection[index] : undefined;
|
}
|
return baseFind(collection, predicate, eachFunc);
|
};
|
}
|
|
/**
|
* Creates a `_.findIndex` or `_.findLastIndex` function.
|
*
|
* @private
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
* @returns {Function} Returns the new find function.
|
*/
|
function createFindIndex(fromRight) {
|
return function(array, predicate, thisArg) {
|
if (!(array && array.length)) {
|
return -1;
|
}
|
predicate = getCallback(predicate, thisArg, 3);
|
return baseFindIndex(array, predicate, fromRight);
|
};
|
}
|
|
/**
|
* Creates a `_.findKey` or `_.findLastKey` function.
|
*
|
* @private
|
* @param {Function} objectFunc The function to iterate over an object.
|
* @returns {Function} Returns the new find function.
|
*/
|
function createFindKey(objectFunc) {
|
return function(object, predicate, thisArg) {
|
predicate = getCallback(predicate, thisArg, 3);
|
return baseFind(object, predicate, objectFunc, true);
|
};
|
}
|
|
/**
|
* Creates a `_.flow` or `_.flowRight` function.
|
*
|
* @private
|
* @param {boolean} [fromRight] Specify iterating from right to left.
|
* @returns {Function} Returns the new flow function.
|
*/
|
function createFlow(fromRight) {
|
return function() {
|
var wrapper,
|
length = arguments.length,
|
index = fromRight ? length : -1,
|
leftIndex = 0,
|
funcs = Array(length);
|
|
while ((fromRight ? index-- : ++index < length)) {
|
var func = funcs[leftIndex++] = arguments[index];
|
if (typeof func != 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
|
wrapper = new LodashWrapper([], true);
|
}
|
}
|
index = wrapper ? -1 : length;
|
while (++index < length) {
|
func = funcs[index];
|
|
var funcName = getFuncName(func),
|
data = funcName == 'wrapper' ? getData(func) : undefined;
|
|
if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
|
wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
|
} else {
|
wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
|
}
|
}
|
return function() {
|
var args = arguments,
|
value = args[0];
|
|
if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
|
return wrapper.plant(value).value();
|
}
|
var index = 0,
|
result = length ? funcs[index].apply(this, args) : value;
|
|
while (++index < length) {
|
result = funcs[index].call(this, result);
|
}
|
return result;
|
};
|
};
|
}
|
|
/**
|
* Creates a function for `_.forEach` or `_.forEachRight`.
|
*
|
* @private
|
* @param {Function} arrayFunc The function to iterate over an array.
|
* @param {Function} eachFunc The function to iterate over a collection.
|
* @returns {Function} Returns the new each function.
|
*/
|
function createForEach(arrayFunc, eachFunc) {
|
return function(collection, iteratee, thisArg) {
|
return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
|
? arrayFunc(collection, iteratee)
|
: eachFunc(collection, bindCallback(iteratee, thisArg, 3));
|
};
|
}
|
|
/**
|
* Creates a function for `_.forIn` or `_.forInRight`.
|
*
|
* @private
|
* @param {Function} objectFunc The function to iterate over an object.
|
* @returns {Function} Returns the new each function.
|
*/
|
function createForIn(objectFunc) {
|
return function(object, iteratee, thisArg) {
|
if (typeof iteratee != 'function' || thisArg !== undefined) {
|
iteratee = bindCallback(iteratee, thisArg, 3);
|
}
|
return objectFunc(object, iteratee, keysIn);
|
};
|
}
|
|
/**
|
* Creates a function for `_.forOwn` or `_.forOwnRight`.
|
*
|
* @private
|
* @param {Function} objectFunc The function to iterate over an object.
|
* @returns {Function} Returns the new each function.
|
*/
|
function createForOwn(objectFunc) {
|
return function(object, iteratee, thisArg) {
|
if (typeof iteratee != 'function' || thisArg !== undefined) {
|
iteratee = bindCallback(iteratee, thisArg, 3);
|
}
|
return objectFunc(object, iteratee);
|
};
|
}
|
|
/**
|
* Creates a function for `_.mapKeys` or `_.mapValues`.
|
*
|
* @private
|
* @param {boolean} [isMapKeys] Specify mapping keys instead of values.
|
* @returns {Function} Returns the new map function.
|
*/
|
function createObjectMapper(isMapKeys) {
|
return function(object, iteratee, thisArg) {
|
var result = {};
|
iteratee = getCallback(iteratee, thisArg, 3);
|
|
baseForOwn(object, function(value, key, object) {
|
var mapped = iteratee(value, key, object);
|
key = isMapKeys ? mapped : key;
|
value = isMapKeys ? value : mapped;
|
result[key] = value;
|
});
|
return result;
|
};
|
}
|
|
/**
|
* Creates a function for `_.padLeft` or `_.padRight`.
|
*
|
* @private
|
* @param {boolean} [fromRight] Specify padding from the right.
|
* @returns {Function} Returns the new pad function.
|
*/
|
function createPadDir(fromRight) {
|
return function(string, length, chars) {
|
string = baseToString(string);
|
return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
|
};
|
}
|
|
/**
|
* Creates a `_.partial` or `_.partialRight` function.
|
*
|
* @private
|
* @param {boolean} flag The partial bit flag.
|
* @returns {Function} Returns the new partial function.
|
*/
|
function createPartial(flag) {
|
var partialFunc = restParam(function(func, partials) {
|
var holders = replaceHolders(partials, partialFunc.placeholder);
|
return createWrapper(func, flag, undefined, partials, holders);
|
});
|
return partialFunc;
|
}
|
|
/**
|
* Creates a function for `_.reduce` or `_.reduceRight`.
|
*
|
* @private
|
* @param {Function} arrayFunc The function to iterate over an array.
|
* @param {Function} eachFunc The function to iterate over a collection.
|
* @returns {Function} Returns the new each function.
|
*/
|
function createReduce(arrayFunc, eachFunc) {
|
return function(collection, iteratee, accumulator, thisArg) {
|
var initFromArray = arguments.length < 3;
|
return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
|
? arrayFunc(collection, iteratee, accumulator, initFromArray)
|
: baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
|
};
|
}
|
|
/**
|
* Creates a function that wraps `func` and invokes it with optional `this`
|
* binding of, partial application, and currying.
|
*
|
* @private
|
* @param {Function|string} func The function or method name to reference.
|
* @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
|
* @param {*} [thisArg] The `this` binding of `func`.
|
* @param {Array} [partials] The arguments to prepend to those provided to the new function.
|
* @param {Array} [holders] The `partials` placeholder indexes.
|
* @param {Array} [partialsRight] The arguments to append to those provided to the new function.
|
* @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
|
* @param {Array} [argPos] The argument positions of the new function.
|
* @param {number} [ary] The arity cap of `func`.
|
* @param {number} [arity] The arity of `func`.
|
* @returns {Function} Returns the new wrapped function.
|
*/
|
function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
|
var isAry = bitmask & ARY_FLAG,
|
isBind = bitmask & BIND_FLAG,
|
isBindKey = bitmask & BIND_KEY_FLAG,
|
isCurry = bitmask & CURRY_FLAG,
|
isCurryBound = bitmask & CURRY_BOUND_FLAG,
|
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
|
Ctor = isBindKey ? undefined : createCtorWrapper(func);
|
|
function wrapper() {
|
// Avoid `arguments` object use disqualifying optimizations by
|
// converting it to an array before providing it to other functions.
|
var length = arguments.length,
|
index = length,
|
args = Array(length);
|
|
while (index--) {
|
args[index] = arguments[index];
|
}
|
if (partials) {
|
args = composeArgs(args, partials, holders);
|
}
|
if (partialsRight) {
|
args = composeArgsRight(args, partialsRight, holdersRight);
|
}
|
if (isCurry || isCurryRight) {
|
var placeholder = wrapper.placeholder,
|
argsHolders = replaceHolders(args, placeholder);
|
|
length -= argsHolders.length;
|
if (length < arity) {
|
var newArgPos = argPos ? arrayCopy(argPos) : undefined,
|
newArity = nativeMax(arity - length, 0),
|
newsHolders = isCurry ? argsHolders : undefined,
|
newHoldersRight = isCurry ? undefined : argsHolders,
|
newPartials = isCurry ? args : undefined,
|
newPartialsRight = isCurry ? undefined : args;
|
|
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
|
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
|
|
if (!isCurryBound) {
|
bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
|
}
|
var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
|
result = createHybridWrapper.apply(undefined, newData);
|
|
if (isLaziable(func)) {
|
setData(result, newData);
|
}
|
result.placeholder = placeholder;
|
return result;
|
}
|
}
|
var thisBinding = isBind ? thisArg : this,
|
fn = isBindKey ? thisBinding[func] : func;
|
|
if (argPos) {
|
args = reorder(args, argPos);
|
}
|
if (isAry && ary < args.length) {
|
args.length = ary;
|
}
|
if (this && this !== root && this instanceof wrapper) {
|
fn = Ctor || createCtorWrapper(func);
|
}
|
return fn.apply(thisBinding, args);
|
}
|
return wrapper;
|
}
|
|
/**
|
* Creates the padding required for `string` based on the given `length`.
|
* The `chars` string is truncated if the number of characters exceeds `length`.
|
*
|
* @private
|
* @param {string} string The string to create padding for.
|
* @param {number} [length=0] The padding length.
|
* @param {string} [chars=' '] The string used as padding.
|
* @returns {string} Returns the pad for `string`.
|
*/
|
function createPadding(string, length, chars) {
|
var strLength = string.length;
|
length = +length;
|
|
if (strLength >= length || !nativeIsFinite(length)) {
|
return '';
|
}
|
var padLength = length - strLength;
|
chars = chars == null ? ' ' : (chars + '');
|
return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
|
}
|
|
/**
|
* Creates a function that wraps `func` and invokes it with the optional `this`
|
* binding of `thisArg` and the `partials` prepended to those provided to
|
* the wrapper.
|
*
|
* @private
|
* @param {Function} func The function to partially apply arguments to.
|
* @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
|
* @param {*} thisArg The `this` binding of `func`.
|
* @param {Array} partials The arguments to prepend to those provided to the new function.
|
* @returns {Function} Returns the new bound function.
|
*/
|
function createPartialWrapper(func, bitmask, thisArg, partials) {
|
var isBind = bitmask & BIND_FLAG,
|
Ctor = createCtorWrapper(func);
|
|
function wrapper() {
|
// Avoid `arguments` object use disqualifying optimizations by
|
// converting it to an array before providing it `func`.
|
var argsIndex = -1,
|
argsLength = arguments.length,
|
leftIndex = -1,
|
leftLength = partials.length,
|
args = Array(leftLength + argsLength);
|
|
while (++leftIndex < leftLength) {
|
args[leftIndex] = partials[leftIndex];
|
}
|
while (argsLength--) {
|
args[leftIndex++] = arguments[++argsIndex];
|
}
|
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
return fn.apply(isBind ? thisArg : this, args);
|
}
|
return wrapper;
|
}
|
|
/**
|
* Creates a `_.ceil`, `_.floor`, or `_.round` function.
|
*
|
* @private
|
* @param {string} methodName The name of the `Math` method to use when rounding.
|
* @returns {Function} Returns the new round function.
|
*/
|
function createRound(methodName) {
|
var func = Math[methodName];
|
return function(number, precision) {
|
precision = precision === undefined ? 0 : (+precision || 0);
|
if (precision) {
|
precision = pow(10, precision);
|
return func(number * precision) / precision;
|
}
|
return func(number);
|
};
|
}
|
|
/**
|
* Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
|
*
|
* @private
|
* @param {boolean} [retHighest] Specify returning the highest qualified index.
|
* @returns {Function} Returns the new index function.
|
*/
|
function createSortedIndex(retHighest) {
|
return function(array, value, iteratee, thisArg) {
|
var callback = getCallback(iteratee);
|
return (iteratee == null && callback === baseCallback)
|
? binaryIndex(array, value, retHighest)
|
: binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
|
};
|
}
|
|
/**
|
* Creates a function that either curries or invokes `func` with optional
|
* `this` binding and partially applied arguments.
|
*
|
* @private
|
* @param {Function|string} func The function or method name to reference.
|
* @param {number} bitmask The bitmask of flags.
|
* The bitmask may be composed of the following flags:
|
* 1 - `_.bind`
|
* 2 - `_.bindKey`
|
* 4 - `_.curry` or `_.curryRight` of a bound function
|
* 8 - `_.curry`
|
* 16 - `_.curryRight`
|
* 32 - `_.partial`
|
* 64 - `_.partialRight`
|
* 128 - `_.rearg`
|
* 256 - `_.ary`
|
* @param {*} [thisArg] The `this` binding of `func`.
|
* @param {Array} [partials] The arguments to be partially applied.
|
* @param {Array} [holders] The `partials` placeholder indexes.
|
* @param {Array} [argPos] The argument positions of the new function.
|
* @param {number} [ary] The arity cap of `func`.
|
* @param {number} [arity] The arity of `func`.
|
* @returns {Function} Returns the new wrapped function.
|
*/
|
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
|
var isBindKey = bitmask & BIND_KEY_FLAG;
|
if (!isBindKey && typeof func != 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
var length = partials ? partials.length : 0;
|
if (!length) {
|
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
|
partials = holders = undefined;
|
}
|
length -= (holders ? holders.length : 0);
|
if (bitmask & PARTIAL_RIGHT_FLAG) {
|
var partialsRight = partials,
|
holdersRight = holders;
|
|
partials = holders = undefined;
|
}
|
var data = isBindKey ? undefined : getData(func),
|
newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
|
|
if (data) {
|
mergeData(newData, data);
|
bitmask = newData[1];
|
arity = newData[9];
|
}
|
newData[9] = arity == null
|
? (isBindKey ? 0 : func.length)
|
: (nativeMax(arity - length, 0) || 0);
|
|
if (bitmask == BIND_FLAG) {
|
var result = createBindWrapper(newData[0], newData[2]);
|
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
|
result = createPartialWrapper.apply(undefined, newData);
|
} else {
|
result = createHybridWrapper.apply(undefined, newData);
|
}
|
var setter = data ? baseSetData : setData;
|
return setter(result, newData);
|
}
|
|
/**
|
* A specialized version of `baseIsEqualDeep` for arrays with support for
|
* partial deep comparisons.
|
*
|
* @private
|
* @param {Array} array The array to compare.
|
* @param {Array} other The other array to compare.
|
* @param {Function} equalFunc The function to determine equivalents of values.
|
* @param {Function} [customizer] The function to customize comparing arrays.
|
* @param {boolean} [isLoose] Specify performing partial comparisons.
|
* @param {Array} [stackA] Tracks traversed `value` objects.
|
* @param {Array} [stackB] Tracks traversed `other` objects.
|
* @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
|
*/
|
function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
|
var index = -1,
|
arrLength = array.length,
|
othLength = other.length;
|
|
if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
|
return false;
|
}
|
// Ignore non-index properties.
|
while (++index < arrLength) {
|
var arrValue = array[index],
|
othValue = other[index],
|
result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
|
|
if (result !== undefined) {
|
if (result) {
|
continue;
|
}
|
return false;
|
}
|
// Recursively compare arrays (susceptible to call stack limits).
|
if (isLoose) {
|
if (!arraySome(other, function(othValue) {
|
return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
|
})) {
|
return false;
|
}
|
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
|
return false;
|
}
|
}
|
return true;
|
}
|
|
/**
|
* A specialized version of `baseIsEqualDeep` for comparing objects of
|
* the same `toStringTag`.
|
*
|
* **Note:** This function only supports comparing values with tags of
|
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
*
|
* @private
|
* @param {Object} object The object to compare.
|
* @param {Object} other The other object to compare.
|
* @param {string} tag The `toStringTag` of the objects to compare.
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
*/
|
function equalByTag(object, other, tag) {
|
switch (tag) {
|
case boolTag:
|
case dateTag:
|
// Coerce dates and booleans to numbers, dates to milliseconds and booleans
|
// to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
|
return +object == +other;
|
|
case errorTag:
|
return object.name == other.name && object.message == other.message;
|
|
case numberTag:
|
// Treat `NaN` vs. `NaN` as equal.
|
return (object != +object)
|
? other != +other
|
: object == +other;
|
|
case regexpTag:
|
case stringTag:
|
// Coerce regexes to strings and treat strings primitives and string
|
// objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
|
return object == (other + '');
|
}
|
return false;
|
}
|
|
/**
|
* A specialized version of `baseIsEqualDeep` for objects with support for
|
* partial deep comparisons.
|
*
|
* @private
|
* @param {Object} object The object to compare.
|
* @param {Object} other The other object to compare.
|
* @param {Function} equalFunc The function to determine equivalents of values.
|
* @param {Function} [customizer] The function to customize comparing values.
|
* @param {boolean} [isLoose] Specify performing partial comparisons.
|
* @param {Array} [stackA] Tracks traversed `value` objects.
|
* @param {Array} [stackB] Tracks traversed `other` objects.
|
* @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
|
*/
|
function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
|
var objProps = keys(object),
|
objLength = objProps.length,
|
othProps = keys(other),
|
othLength = othProps.length;
|
|
if (objLength != othLength && !isLoose) {
|
return false;
|
}
|
var index = objLength;
|
while (index--) {
|
var key = objProps[index];
|
if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
|
return false;
|
}
|
}
|
var skipCtor = isLoose;
|
while (++index < objLength) {
|
key = objProps[index];
|
var objValue = object[key],
|
othValue = other[key],
|
result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
|
|
// Recursively compare objects (susceptible to call stack limits).
|
if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
|
return false;
|
}
|
skipCtor || (skipCtor = key == 'constructor');
|
}
|
if (!skipCtor) {
|
var objCtor = object.constructor,
|
othCtor = other.constructor;
|
|
// Non `Object` object instances with different constructors are not equal.
|
if (objCtor != othCtor &&
|
('constructor' in object && 'constructor' in other) &&
|
!(typeof objCtor == 'function' && objCtor instanceof objCtor &&
|
typeof othCtor == 'function' && othCtor instanceof othCtor)) {
|
return false;
|
}
|
}
|
return true;
|
}
|
|
/**
|
* Gets the appropriate "callback" function. If the `_.callback` method is
|
* customized this function returns the custom method, otherwise it returns
|
* the `baseCallback` function. If arguments are provided the chosen function
|
* is invoked with them and its result is returned.
|
*
|
* @private
|
* @returns {Function} Returns the chosen function or its result.
|
*/
|
function getCallback(func, thisArg, argCount) {
|
var result = lodash.callback || callback;
|
result = result === callback ? baseCallback : result;
|
return argCount ? result(func, thisArg, argCount) : result;
|
}
|
|
/**
|
* Gets metadata for `func`.
|
*
|
* @private
|
* @param {Function} func The function to query.
|
* @returns {*} Returns the metadata for `func`.
|
*/
|
var getData = !metaMap ? noop : function(func) {
|
return metaMap.get(func);
|
};
|
|
/**
|
* Gets the name of `func`.
|
*
|
* @private
|
* @param {Function} func The function to query.
|
* @returns {string} Returns the function name.
|
*/
|
function getFuncName(func) {
|
var result = func.name,
|
array = realNames[result],
|
length = array ? array.length : 0;
|
|
while (length--) {
|
var data = array[length],
|
otherFunc = data.func;
|
if (otherFunc == null || otherFunc == func) {
|
return data.name;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* Gets the appropriate "indexOf" function. If the `_.indexOf` method is
|
* customized this function returns the custom method, otherwise it returns
|
* the `baseIndexOf` function. If arguments are provided the chosen function
|
* is invoked with them and its result is returned.
|
*
|
* @private
|
* @returns {Function|number} Returns the chosen function or its result.
|
*/
|
function getIndexOf(collection, target, fromIndex) {
|
var result = lodash.indexOf || indexOf;
|
result = result === indexOf ? baseIndexOf : result;
|
return collection ? result(collection, target, fromIndex) : result;
|
}
|
|
/**
|
* Gets the "length" property value of `object`.
|
*
|
* **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
|
* that affects Safari on at least iOS 8.1-8.3 ARM64.
|
*
|
* @private
|
* @param {Object} object The object to query.
|
* @returns {*} Returns the "length" value.
|
*/
|
var getLength = baseProperty('length');
|
|
/**
|
* Gets the propery names, values, and compare flags of `object`.
|
*
|
* @private
|
* @param {Object} object The object to query.
|
* @returns {Array} Returns the match data of `object`.
|
*/
|
function getMatchData(object) {
|
var result = pairs(object),
|
length = result.length;
|
|
while (length--) {
|
result[length][2] = isStrictComparable(result[length][1]);
|
}
|
return result;
|
}
|
|
/**
|
* Gets the native function at `key` of `object`.
|
*
|
* @private
|
* @param {Object} object The object to query.
|
* @param {string} key The key of the method to get.
|
* @returns {*} Returns the function if it's native, else `undefined`.
|
*/
|
function getNative(object, key) {
|
var value = object == null ? undefined : object[key];
|
return isNative(value) ? value : undefined;
|
}
|
|
/**
|
* Gets the view, applying any `transforms` to the `start` and `end` positions.
|
*
|
* @private
|
* @param {number} start The start of the view.
|
* @param {number} end The end of the view.
|
* @param {Array} transforms The transformations to apply to the view.
|
* @returns {Object} Returns an object containing the `start` and `end`
|
* positions of the view.
|
*/
|
function getView(start, end, transforms) {
|
var index = -1,
|
length = transforms.length;
|
|
while (++index < length) {
|
var data = transforms[index],
|
size = data.size;
|
|
switch (data.type) {
|
case 'drop': start += size; break;
|
case 'dropRight': end -= size; break;
|
case 'take': end = nativeMin(end, start + size); break;
|
case 'takeRight': start = nativeMax(start, end - size); break;
|
}
|
}
|
return { 'start': start, 'end': end };
|
}
|
|
/**
|
* Initializes an array clone.
|
*
|
* @private
|
* @param {Array} array The array to clone.
|
* @returns {Array} Returns the initialized clone.
|
*/
|
function initCloneArray(array) {
|
var length = array.length,
|
result = new array.constructor(length);
|
|
// Add array properties assigned by `RegExp#exec`.
|
if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
|
result.index = array.index;
|
result.input = array.input;
|
}
|
return result;
|
}
|
|
/**
|
* Initializes an object clone.
|
*
|
* @private
|
* @param {Object} object The object to clone.
|
* @returns {Object} Returns the initialized clone.
|
*/
|
function initCloneObject(object) {
|
var Ctor = object.constructor;
|
if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
|
Ctor = Object;
|
}
|
return new Ctor;
|
}
|
|
/**
|
* Initializes an object clone based on its `toStringTag`.
|
*
|
* **Note:** This function only supports cloning values with tags of
|
* `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
|
*
|
* @private
|
* @param {Object} object The object to clone.
|
* @param {string} tag The `toStringTag` of the object to clone.
|
* @param {boolean} [isDeep] Specify a deep clone.
|
* @returns {Object} Returns the initialized clone.
|
*/
|
function initCloneByTag(object, tag, isDeep) {
|
var Ctor = object.constructor;
|
switch (tag) {
|
case arrayBufferTag:
|
return bufferClone(object);
|
|
case boolTag:
|
case dateTag:
|
return new Ctor(+object);
|
|
case float32Tag: case float64Tag:
|
case int8Tag: case int16Tag: case int32Tag:
|
case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
|
var buffer = object.buffer;
|
return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
|
|
case numberTag:
|
case stringTag:
|
return new Ctor(object);
|
|
case regexpTag:
|
var result = new Ctor(object.source, reFlags.exec(object));
|
result.lastIndex = object.lastIndex;
|
}
|
return result;
|
}
|
|
/**
|
* Invokes the method at `path` on `object`.
|
*
|
* @private
|
* @param {Object} object The object to query.
|
* @param {Array|string} path The path of the method to invoke.
|
* @param {Array} args The arguments to invoke the method with.
|
* @returns {*} Returns the result of the invoked method.
|
*/
|
function invokePath(object, path, args) {
|
if (object != null && !isKey(path, object)) {
|
path = toPath(path);
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
path = last(path);
|
}
|
var func = object == null ? object : object[path];
|
return func == null ? undefined : func.apply(object, args);
|
}
|
|
/**
|
* Checks if `value` is array-like.
|
*
|
* @private
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is array-like, else `false`.
|
*/
|
function isArrayLike(value) {
|
return value != null && isLength(getLength(value));
|
}
|
|
/**
|
* Checks if `value` is a valid array-like index.
|
*
|
* @private
|
* @param {*} value The value to check.
|
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
*/
|
function isIndex(value, length) {
|
value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
|
length = length == null ? MAX_SAFE_INTEGER : length;
|
return value > -1 && value % 1 == 0 && value < length;
|
}
|
|
/**
|
* Checks if the provided arguments are from an iteratee call.
|
*
|
* @private
|
* @param {*} value The potential iteratee value argument.
|
* @param {*} index The potential iteratee index or key argument.
|
* @param {*} object The potential iteratee object argument.
|
* @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
|
*/
|
function isIterateeCall(value, index, object) {
|
if (!isObject(object)) {
|
return false;
|
}
|
var type = typeof index;
|
if (type == 'number'
|
? (isArrayLike(object) && isIndex(index, object.length))
|
: (type == 'string' && index in object)) {
|
var other = object[index];
|
return value === value ? (value === other) : (other !== other);
|
}
|
return false;
|
}
|
|
/**
|
* Checks if `value` is a property name and not a property path.
|
*
|
* @private
|
* @param {*} value The value to check.
|
* @param {Object} [object] The object to query keys on.
|
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
*/
|
function isKey(value, object) {
|
var type = typeof value;
|
if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
|
return true;
|
}
|
if (isArray(value)) {
|
return false;
|
}
|
var result = !reIsDeepProp.test(value);
|
return result || (object != null && value in toObject(object));
|
}
|
|
/**
|
* Checks if `func` has a lazy counterpart.
|
*
|
* @private
|
* @param {Function} func The function to check.
|
* @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
|
*/
|
function isLaziable(func) {
|
var funcName = getFuncName(func);
|
if (!(funcName in LazyWrapper.prototype)) {
|
return false;
|
}
|
var other = lodash[funcName];
|
if (func === other) {
|
return true;
|
}
|
var data = getData(other);
|
return !!data && func === data[0];
|
}
|
|
/**
|
* Checks if `value` is a valid array-like length.
|
*
|
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
|
*
|
* @private
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
|
*/
|
function isLength(value) {
|
return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
}
|
|
/**
|
* Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
|
*
|
* @private
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` if suitable for strict
|
* equality comparisons, else `false`.
|
*/
|
function isStrictComparable(value) {
|
return value === value && !isObject(value);
|
}
|
|
/**
|
* Merges the function metadata of `source` into `data`.
|
*
|
* Merging metadata reduces the number of wrappers required to invoke a function.
|
* This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
|
* may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
|
* augment function arguments, making the order in which they are executed important,
|
* preventing the merging of metadata. However, we make an exception for a safe
|
* common case where curried functions have `_.ary` and or `_.rearg` applied.
|
*
|
* @private
|
* @param {Array} data The destination metadata.
|
* @param {Array} source The source metadata.
|
* @returns {Array} Returns `data`.
|
*/
|
function mergeData(data, source) {
|
var bitmask = data[1],
|
srcBitmask = source[1],
|
newBitmask = bitmask | srcBitmask,
|
isCommon = newBitmask < ARY_FLAG;
|
|
var isCombo =
|
(srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
|
(srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
|
(srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
|
|
// Exit early if metadata can't be merged.
|
if (!(isCommon || isCombo)) {
|
return data;
|
}
|
// Use source `thisArg` if available.
|
if (srcBitmask & BIND_FLAG) {
|
data[2] = source[2];
|
// Set when currying a bound function.
|
newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
|
}
|
// Compose partial arguments.
|
var value = source[3];
|
if (value) {
|
var partials = data[3];
|
data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
|
data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
|
}
|
// Compose partial right arguments.
|
value = source[5];
|
if (value) {
|
partials = data[5];
|
data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
|
data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
|
}
|
// Use source `argPos` if available.
|
value = source[7];
|
if (value) {
|
data[7] = arrayCopy(value);
|
}
|
// Use source `ary` if it's smaller.
|
if (srcBitmask & ARY_FLAG) {
|
data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
|
}
|
// Use source `arity` if one is not provided.
|
if (data[9] == null) {
|
data[9] = source[9];
|
}
|
// Use source `func` and merge bitmasks.
|
data[0] = source[0];
|
data[1] = newBitmask;
|
|
return data;
|
}
|
|
/**
|
* Used by `_.defaultsDeep` to customize its `_.merge` use.
|
*
|
* @private
|
* @param {*} objectValue The destination object property value.
|
* @param {*} sourceValue The source object property value.
|
* @returns {*} Returns the value to assign to the destination object.
|
*/
|
function mergeDefaults(objectValue, sourceValue) {
|
return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
|
}
|
|
/**
|
* A specialized version of `_.pick` which picks `object` properties specified
|
* by `props`.
|
*
|
* @private
|
* @param {Object} object The source object.
|
* @param {string[]} props The property names to pick.
|
* @returns {Object} Returns the new object.
|
*/
|
function pickByArray(object, props) {
|
object = toObject(object);
|
|
var index = -1,
|
length = props.length,
|
result = {};
|
|
while (++index < length) {
|
var key = props[index];
|
if (key in object) {
|
result[key] = object[key];
|
}
|
}
|
return result;
|
}
|
|
/**
|
* A specialized version of `_.pick` which picks `object` properties `predicate`
|
* returns truthy for.
|
*
|
* @private
|
* @param {Object} object The source object.
|
* @param {Function} predicate The function invoked per iteration.
|
* @returns {Object} Returns the new object.
|
*/
|
function pickByCallback(object, predicate) {
|
var result = {};
|
baseForIn(object, function(value, key, object) {
|
if (predicate(value, key, object)) {
|
result[key] = value;
|
}
|
});
|
return result;
|
}
|
|
/**
|
* Reorder `array` according to the specified indexes where the element at
|
* the first index is assigned as the first element, the element at
|
* the second index is assigned as the second element, and so on.
|
*
|
* @private
|
* @param {Array} array The array to reorder.
|
* @param {Array} indexes The arranged array indexes.
|
* @returns {Array} Returns `array`.
|
*/
|
function reorder(array, indexes) {
|
var arrLength = array.length,
|
length = nativeMin(indexes.length, arrLength),
|
oldArray = arrayCopy(array);
|
|
while (length--) {
|
var index = indexes[length];
|
array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
|
}
|
return array;
|
}
|
|
/**
|
* Sets metadata for `func`.
|
*
|
* **Note:** If this function becomes hot, i.e. is invoked a lot in a short
|
* period of time, it will trip its breaker and transition to an identity function
|
* to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
|
* for more details.
|
*
|
* @private
|
* @param {Function} func The function to associate metadata with.
|
* @param {*} data The metadata.
|
* @returns {Function} Returns `func`.
|
*/
|
var setData = (function() {
|
var count = 0,
|
lastCalled = 0;
|
|
return function(key, value) {
|
var stamp = now(),
|
remaining = HOT_SPAN - (stamp - lastCalled);
|
|
lastCalled = stamp;
|
if (remaining > 0) {
|
if (++count >= HOT_COUNT) {
|
return key;
|
}
|
} else {
|
count = 0;
|
}
|
return baseSetData(key, value);
|
};
|
}());
|
|
/**
|
* A fallback implementation of `Object.keys` which creates an array of the
|
* own enumerable property names of `object`.
|
*
|
* @private
|
* @param {Object} object The object to query.
|
* @returns {Array} Returns the array of property names.
|
*/
|
function shimKeys(object) {
|
var props = keysIn(object),
|
propsLength = props.length,
|
length = propsLength && object.length;
|
|
var allowIndexes = !!length && isLength(length) &&
|
(isArray(object) || isArguments(object));
|
|
var index = -1,
|
result = [];
|
|
while (++index < propsLength) {
|
var key = props[index];
|
if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
|
result.push(key);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* Converts `value` to an array-like object if it's not one.
|
*
|
* @private
|
* @param {*} value The value to process.
|
* @returns {Array|Object} Returns the array-like object.
|
*/
|
function toIterable(value) {
|
if (value == null) {
|
return [];
|
}
|
if (!isArrayLike(value)) {
|
return values(value);
|
}
|
return isObject(value) ? value : Object(value);
|
}
|
|
/**
|
* Converts `value` to an object if it's not one.
|
*
|
* @private
|
* @param {*} value The value to process.
|
* @returns {Object} Returns the object.
|
*/
|
function toObject(value) {
|
return isObject(value) ? value : Object(value);
|
}
|
|
/**
|
* Converts `value` to property path array if it's not one.
|
*
|
* @private
|
* @param {*} value The value to process.
|
* @returns {Array} Returns the property path array.
|
*/
|
function toPath(value) {
|
if (isArray(value)) {
|
return value;
|
}
|
var result = [];
|
baseToString(value).replace(rePropName, function(match, number, quote, string) {
|
result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
|
});
|
return result;
|
}
|
|
/**
|
* Creates a clone of `wrapper`.
|
*
|
* @private
|
* @param {Object} wrapper The wrapper to clone.
|
* @returns {Object} Returns the cloned wrapper.
|
*/
|
function wrapperClone(wrapper) {
|
return wrapper instanceof LazyWrapper
|
? wrapper.clone()
|
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Creates an array of elements split into groups the length of `size`.
|
* If `collection` can't be split evenly, the final chunk will be the remaining
|
* elements.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to process.
|
* @param {number} [size=1] The length of each chunk.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Array} Returns the new array containing chunks.
|
* @example
|
*
|
* _.chunk(['a', 'b', 'c', 'd'], 2);
|
* // => [['a', 'b'], ['c', 'd']]
|
*
|
* _.chunk(['a', 'b', 'c', 'd'], 3);
|
* // => [['a', 'b', 'c'], ['d']]
|
*/
|
function chunk(array, size, guard) {
|
if (guard ? isIterateeCall(array, size, guard) : size == null) {
|
size = 1;
|
} else {
|
size = nativeMax(nativeFloor(size) || 1, 1);
|
}
|
var index = 0,
|
length = array ? array.length : 0,
|
resIndex = -1,
|
result = Array(nativeCeil(length / size));
|
|
while (index < length) {
|
result[++resIndex] = baseSlice(array, index, (index += size));
|
}
|
return result;
|
}
|
|
/**
|
* Creates an array with all falsey values removed. The values `false`, `null`,
|
* `0`, `""`, `undefined`, and `NaN` are falsey.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to compact.
|
* @returns {Array} Returns the new array of filtered values.
|
* @example
|
*
|
* _.compact([0, 1, false, 2, '', 3]);
|
* // => [1, 2, 3]
|
*/
|
function compact(array) {
|
var index = -1,
|
length = array ? array.length : 0,
|
resIndex = -1,
|
result = [];
|
|
while (++index < length) {
|
var value = array[index];
|
if (value) {
|
result[++resIndex] = value;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* Creates an array of unique `array` values not included in the other
|
* provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* for equality comparisons.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to inspect.
|
* @param {...Array} [values] The arrays of values to exclude.
|
* @returns {Array} Returns the new array of filtered values.
|
* @example
|
*
|
* _.difference([1, 2, 3], [4, 2]);
|
* // => [1, 3]
|
*/
|
var difference = restParam(function(array, values) {
|
return (isObjectLike(array) && isArrayLike(array))
|
? baseDifference(array, baseFlatten(values, false, true))
|
: [];
|
});
|
|
/**
|
* Creates a slice of `array` with `n` elements dropped from the beginning.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @param {number} [n=1] The number of elements to drop.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.drop([1, 2, 3]);
|
* // => [2, 3]
|
*
|
* _.drop([1, 2, 3], 2);
|
* // => [3]
|
*
|
* _.drop([1, 2, 3], 5);
|
* // => []
|
*
|
* _.drop([1, 2, 3], 0);
|
* // => [1, 2, 3]
|
*/
|
function drop(array, n, guard) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return [];
|
}
|
if (guard ? isIterateeCall(array, n, guard) : n == null) {
|
n = 1;
|
}
|
return baseSlice(array, n < 0 ? 0 : n);
|
}
|
|
/**
|
* Creates a slice of `array` with `n` elements dropped from the end.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @param {number} [n=1] The number of elements to drop.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.dropRight([1, 2, 3]);
|
* // => [1, 2]
|
*
|
* _.dropRight([1, 2, 3], 2);
|
* // => [1]
|
*
|
* _.dropRight([1, 2, 3], 5);
|
* // => []
|
*
|
* _.dropRight([1, 2, 3], 0);
|
* // => [1, 2, 3]
|
*/
|
function dropRight(array, n, guard) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return [];
|
}
|
if (guard ? isIterateeCall(array, n, guard) : n == null) {
|
n = 1;
|
}
|
n = length - (+n || 0);
|
return baseSlice(array, 0, n < 0 ? 0 : n);
|
}
|
|
/**
|
* Creates a slice of `array` excluding elements dropped from the end.
|
* Elements are dropped until `predicate` returns falsey. The predicate is
|
* bound to `thisArg` and invoked with three arguments: (value, index, array).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that match the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.dropRightWhile([1, 2, 3], function(n) {
|
* return n > 1;
|
* });
|
* // => [1]
|
*
|
* var users = [
|
* { 'user': 'barney', 'active': true },
|
* { 'user': 'fred', 'active': false },
|
* { 'user': 'pebbles', 'active': false }
|
* ];
|
*
|
* // using the `_.matches` callback shorthand
|
* _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
|
* // => ['barney', 'fred']
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.pluck(_.dropRightWhile(users, 'active', false), 'user');
|
* // => ['barney']
|
*
|
* // using the `_.property` callback shorthand
|
* _.pluck(_.dropRightWhile(users, 'active'), 'user');
|
* // => ['barney', 'fred', 'pebbles']
|
*/
|
function dropRightWhile(array, predicate, thisArg) {
|
return (array && array.length)
|
? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
|
: [];
|
}
|
|
/**
|
* Creates a slice of `array` excluding elements dropped from the beginning.
|
* Elements are dropped until `predicate` returns falsey. The predicate is
|
* bound to `thisArg` and invoked with three arguments: (value, index, array).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.dropWhile([1, 2, 3], function(n) {
|
* return n < 3;
|
* });
|
* // => [3]
|
*
|
* var users = [
|
* { 'user': 'barney', 'active': false },
|
* { 'user': 'fred', 'active': false },
|
* { 'user': 'pebbles', 'active': true }
|
* ];
|
*
|
* // using the `_.matches` callback shorthand
|
* _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
|
* // => ['fred', 'pebbles']
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.pluck(_.dropWhile(users, 'active', false), 'user');
|
* // => ['pebbles']
|
*
|
* // using the `_.property` callback shorthand
|
* _.pluck(_.dropWhile(users, 'active'), 'user');
|
* // => ['barney', 'fred', 'pebbles']
|
*/
|
function dropWhile(array, predicate, thisArg) {
|
return (array && array.length)
|
? baseWhile(array, getCallback(predicate, thisArg, 3), true)
|
: [];
|
}
|
|
/**
|
* Fills elements of `array` with `value` from `start` up to, but not
|
* including, `end`.
|
*
|
* **Note:** This method mutates `array`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to fill.
|
* @param {*} value The value to fill `array` with.
|
* @param {number} [start=0] The start position.
|
* @param {number} [end=array.length] The end position.
|
* @returns {Array} Returns `array`.
|
* @example
|
*
|
* var array = [1, 2, 3];
|
*
|
* _.fill(array, 'a');
|
* console.log(array);
|
* // => ['a', 'a', 'a']
|
*
|
* _.fill(Array(3), 2);
|
* // => [2, 2, 2]
|
*
|
* _.fill([4, 6, 8], '*', 1, 2);
|
* // => [4, '*', 8]
|
*/
|
function fill(array, value, start, end) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return [];
|
}
|
if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
|
start = 0;
|
end = length;
|
}
|
return baseFill(array, value, start, end);
|
}
|
|
/**
|
* This method is like `_.find` except that it returns the index of the first
|
* element `predicate` returns truthy for instead of the element itself.
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to search.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {number} Returns the index of the found element, else `-1`.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'active': false },
|
* { 'user': 'fred', 'active': false },
|
* { 'user': 'pebbles', 'active': true }
|
* ];
|
*
|
* _.findIndex(users, function(chr) {
|
* return chr.user == 'barney';
|
* });
|
* // => 0
|
*
|
* // using the `_.matches` callback shorthand
|
* _.findIndex(users, { 'user': 'fred', 'active': false });
|
* // => 1
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.findIndex(users, 'active', false);
|
* // => 0
|
*
|
* // using the `_.property` callback shorthand
|
* _.findIndex(users, 'active');
|
* // => 2
|
*/
|
var findIndex = createFindIndex();
|
|
/**
|
* This method is like `_.findIndex` except that it iterates over elements
|
* of `collection` from right to left.
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to search.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {number} Returns the index of the found element, else `-1`.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'active': true },
|
* { 'user': 'fred', 'active': false },
|
* { 'user': 'pebbles', 'active': false }
|
* ];
|
*
|
* _.findLastIndex(users, function(chr) {
|
* return chr.user == 'pebbles';
|
* });
|
* // => 2
|
*
|
* // using the `_.matches` callback shorthand
|
* _.findLastIndex(users, { 'user': 'barney', 'active': true });
|
* // => 0
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.findLastIndex(users, 'active', false);
|
* // => 2
|
*
|
* // using the `_.property` callback shorthand
|
* _.findLastIndex(users, 'active');
|
* // => 0
|
*/
|
var findLastIndex = createFindIndex(true);
|
|
/**
|
* Gets the first element of `array`.
|
*
|
* @static
|
* @memberOf _
|
* @alias head
|
* @category Array
|
* @param {Array} array The array to query.
|
* @returns {*} Returns the first element of `array`.
|
* @example
|
*
|
* _.first([1, 2, 3]);
|
* // => 1
|
*
|
* _.first([]);
|
* // => undefined
|
*/
|
function first(array) {
|
return array ? array[0] : undefined;
|
}
|
|
/**
|
* Flattens a nested array. If `isDeep` is `true` the array is recursively
|
* flattened, otherwise it is only flattened a single level.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to flatten.
|
* @param {boolean} [isDeep] Specify a deep flatten.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Array} Returns the new flattened array.
|
* @example
|
*
|
* _.flatten([1, [2, 3, [4]]]);
|
* // => [1, 2, 3, [4]]
|
*
|
* // using `isDeep`
|
* _.flatten([1, [2, 3, [4]]], true);
|
* // => [1, 2, 3, 4]
|
*/
|
function flatten(array, isDeep, guard) {
|
var length = array ? array.length : 0;
|
if (guard && isIterateeCall(array, isDeep, guard)) {
|
isDeep = false;
|
}
|
return length ? baseFlatten(array, isDeep) : [];
|
}
|
|
/**
|
* Recursively flattens a nested array.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to recursively flatten.
|
* @returns {Array} Returns the new flattened array.
|
* @example
|
*
|
* _.flattenDeep([1, [2, 3, [4]]]);
|
* // => [1, 2, 3, 4]
|
*/
|
function flattenDeep(array) {
|
var length = array ? array.length : 0;
|
return length ? baseFlatten(array, true) : [];
|
}
|
|
/**
|
* Gets the index at which the first occurrence of `value` is found in `array`
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
|
* from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
|
* performs a faster binary search.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to search.
|
* @param {*} value The value to search for.
|
* @param {boolean|number} [fromIndex=0] The index to search from or `true`
|
* to perform a binary search on a sorted array.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
* @example
|
*
|
* _.indexOf([1, 2, 1, 2], 2);
|
* // => 1
|
*
|
* // using `fromIndex`
|
* _.indexOf([1, 2, 1, 2], 2, 2);
|
* // => 3
|
*
|
* // performing a binary search
|
* _.indexOf([1, 1, 2, 2], 2, true);
|
* // => 2
|
*/
|
function indexOf(array, value, fromIndex) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return -1;
|
}
|
if (typeof fromIndex == 'number') {
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
|
} else if (fromIndex) {
|
var index = binaryIndex(array, value);
|
if (index < length &&
|
(value === value ? (value === array[index]) : (array[index] !== array[index]))) {
|
return index;
|
}
|
return -1;
|
}
|
return baseIndexOf(array, value, fromIndex || 0);
|
}
|
|
/**
|
* Gets all but the last element of `array`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.initial([1, 2, 3]);
|
* // => [1, 2]
|
*/
|
function initial(array) {
|
return dropRight(array, 1);
|
}
|
|
/**
|
* Creates an array of unique values that are included in all of the provided
|
* arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* for equality comparisons.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {...Array} [arrays] The arrays to inspect.
|
* @returns {Array} Returns the new array of shared values.
|
* @example
|
* _.intersection([1, 2], [4, 2], [2, 1]);
|
* // => [2]
|
*/
|
var intersection = restParam(function(arrays) {
|
var othLength = arrays.length,
|
othIndex = othLength,
|
caches = Array(length),
|
indexOf = getIndexOf(),
|
isCommon = indexOf == baseIndexOf,
|
result = [];
|
|
while (othIndex--) {
|
var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
|
caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
|
}
|
var array = arrays[0],
|
index = -1,
|
length = array ? array.length : 0,
|
seen = caches[0];
|
|
outer:
|
while (++index < length) {
|
value = array[index];
|
if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
|
var othIndex = othLength;
|
while (--othIndex) {
|
var cache = caches[othIndex];
|
if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
|
continue outer;
|
}
|
}
|
if (seen) {
|
seen.push(value);
|
}
|
result.push(value);
|
}
|
}
|
return result;
|
});
|
|
/**
|
* Gets the last element of `array`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @returns {*} Returns the last element of `array`.
|
* @example
|
*
|
* _.last([1, 2, 3]);
|
* // => 3
|
*/
|
function last(array) {
|
var length = array ? array.length : 0;
|
return length ? array[length - 1] : undefined;
|
}
|
|
/**
|
* This method is like `_.indexOf` except that it iterates over elements of
|
* `array` from right to left.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to search.
|
* @param {*} value The value to search for.
|
* @param {boolean|number} [fromIndex=array.length-1] The index to search from
|
* or `true` to perform a binary search on a sorted array.
|
* @returns {number} Returns the index of the matched value, else `-1`.
|
* @example
|
*
|
* _.lastIndexOf([1, 2, 1, 2], 2);
|
* // => 3
|
*
|
* // using `fromIndex`
|
* _.lastIndexOf([1, 2, 1, 2], 2, 2);
|
* // => 1
|
*
|
* // performing a binary search
|
* _.lastIndexOf([1, 1, 2, 2], 2, true);
|
* // => 3
|
*/
|
function lastIndexOf(array, value, fromIndex) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return -1;
|
}
|
var index = length;
|
if (typeof fromIndex == 'number') {
|
index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
|
} else if (fromIndex) {
|
index = binaryIndex(array, value, true) - 1;
|
var other = array[index];
|
if (value === value ? (value === other) : (other !== other)) {
|
return index;
|
}
|
return -1;
|
}
|
if (value !== value) {
|
return indexOfNaN(array, index, true);
|
}
|
while (index--) {
|
if (array[index] === value) {
|
return index;
|
}
|
}
|
return -1;
|
}
|
|
/**
|
* Removes all provided values from `array` using
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* for equality comparisons.
|
*
|
* **Note:** Unlike `_.without`, this method mutates `array`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to modify.
|
* @param {...*} [values] The values to remove.
|
* @returns {Array} Returns `array`.
|
* @example
|
*
|
* var array = [1, 2, 3, 1, 2, 3];
|
*
|
* _.pull(array, 2, 3);
|
* console.log(array);
|
* // => [1, 1]
|
*/
|
function pull() {
|
var args = arguments,
|
array = args[0];
|
|
if (!(array && array.length)) {
|
return array;
|
}
|
var index = 0,
|
indexOf = getIndexOf(),
|
length = args.length;
|
|
while (++index < length) {
|
var fromIndex = 0,
|
value = args[index];
|
|
while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
|
splice.call(array, fromIndex, 1);
|
}
|
}
|
return array;
|
}
|
|
/**
|
* Removes elements from `array` corresponding to the given indexes and returns
|
* an array of the removed elements. Indexes may be specified as an array of
|
* indexes or as individual arguments.
|
*
|
* **Note:** Unlike `_.at`, this method mutates `array`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to modify.
|
* @param {...(number|number[])} [indexes] The indexes of elements to remove,
|
* specified as individual indexes or arrays of indexes.
|
* @returns {Array} Returns the new array of removed elements.
|
* @example
|
*
|
* var array = [5, 10, 15, 20];
|
* var evens = _.pullAt(array, 1, 3);
|
*
|
* console.log(array);
|
* // => [5, 15]
|
*
|
* console.log(evens);
|
* // => [10, 20]
|
*/
|
var pullAt = restParam(function(array, indexes) {
|
indexes = baseFlatten(indexes);
|
|
var result = baseAt(array, indexes);
|
basePullAt(array, indexes.sort(baseCompareAscending));
|
return result;
|
});
|
|
/**
|
* Removes all elements from `array` that `predicate` returns truthy for
|
* and returns an array of the removed elements. The predicate is bound to
|
* `thisArg` and invoked with three arguments: (value, index, array).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* **Note:** Unlike `_.filter`, this method mutates `array`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to modify.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Array} Returns the new array of removed elements.
|
* @example
|
*
|
* var array = [1, 2, 3, 4];
|
* var evens = _.remove(array, function(n) {
|
* return n % 2 == 0;
|
* });
|
*
|
* console.log(array);
|
* // => [1, 3]
|
*
|
* console.log(evens);
|
* // => [2, 4]
|
*/
|
function remove(array, predicate, thisArg) {
|
var result = [];
|
if (!(array && array.length)) {
|
return result;
|
}
|
var index = -1,
|
indexes = [],
|
length = array.length;
|
|
predicate = getCallback(predicate, thisArg, 3);
|
while (++index < length) {
|
var value = array[index];
|
if (predicate(value, index, array)) {
|
result.push(value);
|
indexes.push(index);
|
}
|
}
|
basePullAt(array, indexes);
|
return result;
|
}
|
|
/**
|
* Gets all but the first element of `array`.
|
*
|
* @static
|
* @memberOf _
|
* @alias tail
|
* @category Array
|
* @param {Array} array The array to query.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.rest([1, 2, 3]);
|
* // => [2, 3]
|
*/
|
function rest(array) {
|
return drop(array, 1);
|
}
|
|
/**
|
* Creates a slice of `array` from `start` up to, but not including, `end`.
|
*
|
* **Note:** This method is used instead of `Array#slice` to support node
|
* lists in IE < 9 and to ensure dense arrays are returned.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to slice.
|
* @param {number} [start=0] The start position.
|
* @param {number} [end=array.length] The end position.
|
* @returns {Array} Returns the slice of `array`.
|
*/
|
function slice(array, start, end) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return [];
|
}
|
if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
|
start = 0;
|
end = length;
|
}
|
return baseSlice(array, start, end);
|
}
|
|
/**
|
* Uses a binary search to determine the lowest index at which `value` should
|
* be inserted into `array` in order to maintain its sort order. If an iteratee
|
* function is provided it is invoked for `value` and each element of `array`
|
* to compute their sort ranking. The iteratee is bound to `thisArg` and
|
* invoked with one argument; (value).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The sorted array to inspect.
|
* @param {*} value The value to evaluate.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {number} Returns the index at which `value` should be inserted
|
* into `array`.
|
* @example
|
*
|
* _.sortedIndex([30, 50], 40);
|
* // => 1
|
*
|
* _.sortedIndex([4, 4, 5, 5], 5);
|
* // => 2
|
*
|
* var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
|
*
|
* // using an iteratee function
|
* _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
|
* return this.data[word];
|
* }, dict);
|
* // => 1
|
*
|
* // using the `_.property` callback shorthand
|
* _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
|
* // => 1
|
*/
|
var sortedIndex = createSortedIndex();
|
|
/**
|
* This method is like `_.sortedIndex` except that it returns the highest
|
* index at which `value` should be inserted into `array` in order to
|
* maintain its sort order.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The sorted array to inspect.
|
* @param {*} value The value to evaluate.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {number} Returns the index at which `value` should be inserted
|
* into `array`.
|
* @example
|
*
|
* _.sortedLastIndex([4, 4, 5, 5], 5);
|
* // => 4
|
*/
|
var sortedLastIndex = createSortedIndex(true);
|
|
/**
|
* Creates a slice of `array` with `n` elements taken from the beginning.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @param {number} [n=1] The number of elements to take.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.take([1, 2, 3]);
|
* // => [1]
|
*
|
* _.take([1, 2, 3], 2);
|
* // => [1, 2]
|
*
|
* _.take([1, 2, 3], 5);
|
* // => [1, 2, 3]
|
*
|
* _.take([1, 2, 3], 0);
|
* // => []
|
*/
|
function take(array, n, guard) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return [];
|
}
|
if (guard ? isIterateeCall(array, n, guard) : n == null) {
|
n = 1;
|
}
|
return baseSlice(array, 0, n < 0 ? 0 : n);
|
}
|
|
/**
|
* Creates a slice of `array` with `n` elements taken from the end.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @param {number} [n=1] The number of elements to take.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.takeRight([1, 2, 3]);
|
* // => [3]
|
*
|
* _.takeRight([1, 2, 3], 2);
|
* // => [2, 3]
|
*
|
* _.takeRight([1, 2, 3], 5);
|
* // => [1, 2, 3]
|
*
|
* _.takeRight([1, 2, 3], 0);
|
* // => []
|
*/
|
function takeRight(array, n, guard) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return [];
|
}
|
if (guard ? isIterateeCall(array, n, guard) : n == null) {
|
n = 1;
|
}
|
n = length - (+n || 0);
|
return baseSlice(array, n < 0 ? 0 : n);
|
}
|
|
/**
|
* Creates a slice of `array` with elements taken from the end. Elements are
|
* taken until `predicate` returns falsey. The predicate is bound to `thisArg`
|
* and invoked with three arguments: (value, index, array).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.takeRightWhile([1, 2, 3], function(n) {
|
* return n > 1;
|
* });
|
* // => [2, 3]
|
*
|
* var users = [
|
* { 'user': 'barney', 'active': true },
|
* { 'user': 'fred', 'active': false },
|
* { 'user': 'pebbles', 'active': false }
|
* ];
|
*
|
* // using the `_.matches` callback shorthand
|
* _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
|
* // => ['pebbles']
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.pluck(_.takeRightWhile(users, 'active', false), 'user');
|
* // => ['fred', 'pebbles']
|
*
|
* // using the `_.property` callback shorthand
|
* _.pluck(_.takeRightWhile(users, 'active'), 'user');
|
* // => []
|
*/
|
function takeRightWhile(array, predicate, thisArg) {
|
return (array && array.length)
|
? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
|
: [];
|
}
|
|
/**
|
* Creates a slice of `array` with elements taken from the beginning. Elements
|
* are taken until `predicate` returns falsey. The predicate is bound to
|
* `thisArg` and invoked with three arguments: (value, index, array).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to query.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Array} Returns the slice of `array`.
|
* @example
|
*
|
* _.takeWhile([1, 2, 3], function(n) {
|
* return n < 3;
|
* });
|
* // => [1, 2]
|
*
|
* var users = [
|
* { 'user': 'barney', 'active': false },
|
* { 'user': 'fred', 'active': false},
|
* { 'user': 'pebbles', 'active': true }
|
* ];
|
*
|
* // using the `_.matches` callback shorthand
|
* _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
|
* // => ['barney']
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.pluck(_.takeWhile(users, 'active', false), 'user');
|
* // => ['barney', 'fred']
|
*
|
* // using the `_.property` callback shorthand
|
* _.pluck(_.takeWhile(users, 'active'), 'user');
|
* // => []
|
*/
|
function takeWhile(array, predicate, thisArg) {
|
return (array && array.length)
|
? baseWhile(array, getCallback(predicate, thisArg, 3))
|
: [];
|
}
|
|
/**
|
* Creates an array of unique values, in order, from all of the provided arrays
|
* using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* for equality comparisons.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {...Array} [arrays] The arrays to inspect.
|
* @returns {Array} Returns the new array of combined values.
|
* @example
|
*
|
* _.union([1, 2], [4, 2], [2, 1]);
|
* // => [1, 2, 4]
|
*/
|
var union = restParam(function(arrays) {
|
return baseUniq(baseFlatten(arrays, false, true));
|
});
|
|
/**
|
* Creates a duplicate-free version of an array, using
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* for equality comparisons, in which only the first occurence of each element
|
* is kept. Providing `true` for `isSorted` performs a faster search algorithm
|
* for sorted arrays. If an iteratee function is provided it is invoked for
|
* each element in the array to generate the criterion by which uniqueness
|
* is computed. The `iteratee` is bound to `thisArg` and invoked with three
|
* arguments: (value, index, array).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @alias unique
|
* @category Array
|
* @param {Array} array The array to inspect.
|
* @param {boolean} [isSorted] Specify the array is sorted.
|
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Array} Returns the new duplicate-value-free array.
|
* @example
|
*
|
* _.uniq([2, 1, 2]);
|
* // => [2, 1]
|
*
|
* // using `isSorted`
|
* _.uniq([1, 1, 2], true);
|
* // => [1, 2]
|
*
|
* // using an iteratee function
|
* _.uniq([1, 2.5, 1.5, 2], function(n) {
|
* return this.floor(n);
|
* }, Math);
|
* // => [1, 2.5]
|
*
|
* // using the `_.property` callback shorthand
|
* _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
* // => [{ 'x': 1 }, { 'x': 2 }]
|
*/
|
function uniq(array, isSorted, iteratee, thisArg) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return [];
|
}
|
if (isSorted != null && typeof isSorted != 'boolean') {
|
thisArg = iteratee;
|
iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
|
isSorted = false;
|
}
|
var callback = getCallback();
|
if (!(iteratee == null && callback === baseCallback)) {
|
iteratee = callback(iteratee, thisArg, 3);
|
}
|
return (isSorted && getIndexOf() == baseIndexOf)
|
? sortedUniq(array, iteratee)
|
: baseUniq(array, iteratee);
|
}
|
|
/**
|
* This method is like `_.zip` except that it accepts an array of grouped
|
* elements and creates an array regrouping the elements to their pre-zip
|
* configuration.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array of grouped elements to process.
|
* @returns {Array} Returns the new array of regrouped elements.
|
* @example
|
*
|
* var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
|
* // => [['fred', 30, true], ['barney', 40, false]]
|
*
|
* _.unzip(zipped);
|
* // => [['fred', 'barney'], [30, 40], [true, false]]
|
*/
|
function unzip(array) {
|
if (!(array && array.length)) {
|
return [];
|
}
|
var index = -1,
|
length = 0;
|
|
array = arrayFilter(array, function(group) {
|
if (isArrayLike(group)) {
|
length = nativeMax(group.length, length);
|
return true;
|
}
|
});
|
var result = Array(length);
|
while (++index < length) {
|
result[index] = arrayMap(array, baseProperty(index));
|
}
|
return result;
|
}
|
|
/**
|
* This method is like `_.unzip` except that it accepts an iteratee to specify
|
* how regrouped values should be combined. The `iteratee` is bound to `thisArg`
|
* and invoked with four arguments: (accumulator, value, index, group).
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array of grouped elements to process.
|
* @param {Function} [iteratee] The function to combine regrouped values.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Array} Returns the new array of regrouped elements.
|
* @example
|
*
|
* var zipped = _.zip([1, 2], [10, 20], [100, 200]);
|
* // => [[1, 10, 100], [2, 20, 200]]
|
*
|
* _.unzipWith(zipped, _.add);
|
* // => [3, 30, 300]
|
*/
|
function unzipWith(array, iteratee, thisArg) {
|
var length = array ? array.length : 0;
|
if (!length) {
|
return [];
|
}
|
var result = unzip(array);
|
if (iteratee == null) {
|
return result;
|
}
|
iteratee = bindCallback(iteratee, thisArg, 4);
|
return arrayMap(result, function(group) {
|
return arrayReduce(group, iteratee, undefined, true);
|
});
|
}
|
|
/**
|
* Creates an array excluding all provided values using
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* for equality comparisons.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {Array} array The array to filter.
|
* @param {...*} [values] The values to exclude.
|
* @returns {Array} Returns the new array of filtered values.
|
* @example
|
*
|
* _.without([1, 2, 1, 3], 1, 2);
|
* // => [3]
|
*/
|
var without = restParam(function(array, values) {
|
return isArrayLike(array)
|
? baseDifference(array, values)
|
: [];
|
});
|
|
/**
|
* Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
|
* of the provided arrays.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {...Array} [arrays] The arrays to inspect.
|
* @returns {Array} Returns the new array of values.
|
* @example
|
*
|
* _.xor([1, 2], [4, 2]);
|
* // => [1, 4]
|
*/
|
function xor() {
|
var index = -1,
|
length = arguments.length;
|
|
while (++index < length) {
|
var array = arguments[index];
|
if (isArrayLike(array)) {
|
var result = result
|
? arrayPush(baseDifference(result, array), baseDifference(array, result))
|
: array;
|
}
|
}
|
return result ? baseUniq(result) : [];
|
}
|
|
/**
|
* Creates an array of grouped elements, the first of which contains the first
|
* elements of the given arrays, the second of which contains the second elements
|
* of the given arrays, and so on.
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {...Array} [arrays] The arrays to process.
|
* @returns {Array} Returns the new array of grouped elements.
|
* @example
|
*
|
* _.zip(['fred', 'barney'], [30, 40], [true, false]);
|
* // => [['fred', 30, true], ['barney', 40, false]]
|
*/
|
var zip = restParam(unzip);
|
|
/**
|
* The inverse of `_.pairs`; this method returns an object composed from arrays
|
* of property names and values. Provide either a single two dimensional array,
|
* e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
|
* and one of corresponding values.
|
*
|
* @static
|
* @memberOf _
|
* @alias object
|
* @category Array
|
* @param {Array} props The property names.
|
* @param {Array} [values=[]] The property values.
|
* @returns {Object} Returns the new object.
|
* @example
|
*
|
* _.zipObject([['fred', 30], ['barney', 40]]);
|
* // => { 'fred': 30, 'barney': 40 }
|
*
|
* _.zipObject(['fred', 'barney'], [30, 40]);
|
* // => { 'fred': 30, 'barney': 40 }
|
*/
|
function zipObject(props, values) {
|
var index = -1,
|
length = props ? props.length : 0,
|
result = {};
|
|
if (length && !values && !isArray(props[0])) {
|
values = [];
|
}
|
while (++index < length) {
|
var key = props[index];
|
if (values) {
|
result[key] = values[index];
|
} else if (key) {
|
result[key[0]] = key[1];
|
}
|
}
|
return result;
|
}
|
|
/**
|
* This method is like `_.zip` except that it accepts an iteratee to specify
|
* how grouped values should be combined. The `iteratee` is bound to `thisArg`
|
* and invoked with four arguments: (accumulator, value, index, group).
|
*
|
* @static
|
* @memberOf _
|
* @category Array
|
* @param {...Array} [arrays] The arrays to process.
|
* @param {Function} [iteratee] The function to combine grouped values.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Array} Returns the new array of grouped elements.
|
* @example
|
*
|
* _.zipWith([1, 2], [10, 20], [100, 200], _.add);
|
* // => [111, 222]
|
*/
|
var zipWith = restParam(function(arrays) {
|
var length = arrays.length,
|
iteratee = length > 2 ? arrays[length - 2] : undefined,
|
thisArg = length > 1 ? arrays[length - 1] : undefined;
|
|
if (length > 2 && typeof iteratee == 'function') {
|
length -= 2;
|
} else {
|
iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
|
thisArg = undefined;
|
}
|
arrays.length = length;
|
return unzipWith(arrays, iteratee, thisArg);
|
});
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Creates a `lodash` object that wraps `value` with explicit method
|
* chaining enabled.
|
*
|
* @static
|
* @memberOf _
|
* @category Chain
|
* @param {*} value The value to wrap.
|
* @returns {Object} Returns the new `lodash` wrapper instance.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'fred', 'age': 40 },
|
* { 'user': 'pebbles', 'age': 1 }
|
* ];
|
*
|
* var youngest = _.chain(users)
|
* .sortBy('age')
|
* .map(function(chr) {
|
* return chr.user + ' is ' + chr.age;
|
* })
|
* .first()
|
* .value();
|
* // => 'pebbles is 1'
|
*/
|
function chain(value) {
|
var result = lodash(value);
|
result.__chain__ = true;
|
return result;
|
}
|
|
/**
|
* This method invokes `interceptor` and returns `value`. The interceptor is
|
* bound to `thisArg` and invoked with one argument; (value). The purpose of
|
* this method is to "tap into" a method chain in order to perform operations
|
* on intermediate results within the chain.
|
*
|
* @static
|
* @memberOf _
|
* @category Chain
|
* @param {*} value The value to provide to `interceptor`.
|
* @param {Function} interceptor The function to invoke.
|
* @param {*} [thisArg] The `this` binding of `interceptor`.
|
* @returns {*} Returns `value`.
|
* @example
|
*
|
* _([1, 2, 3])
|
* .tap(function(array) {
|
* array.pop();
|
* })
|
* .reverse()
|
* .value();
|
* // => [2, 1]
|
*/
|
function tap(value, interceptor, thisArg) {
|
interceptor.call(thisArg, value);
|
return value;
|
}
|
|
/**
|
* This method is like `_.tap` except that it returns the result of `interceptor`.
|
*
|
* @static
|
* @memberOf _
|
* @category Chain
|
* @param {*} value The value to provide to `interceptor`.
|
* @param {Function} interceptor The function to invoke.
|
* @param {*} [thisArg] The `this` binding of `interceptor`.
|
* @returns {*} Returns the result of `interceptor`.
|
* @example
|
*
|
* _(' abc ')
|
* .chain()
|
* .trim()
|
* .thru(function(value) {
|
* return [value];
|
* })
|
* .value();
|
* // => ['abc']
|
*/
|
function thru(value, interceptor, thisArg) {
|
return interceptor.call(thisArg, value);
|
}
|
|
/**
|
* Enables explicit method chaining on the wrapper object.
|
*
|
* @name chain
|
* @memberOf _
|
* @category Chain
|
* @returns {Object} Returns the new `lodash` wrapper instance.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'fred', 'age': 40 }
|
* ];
|
*
|
* // without explicit chaining
|
* _(users).first();
|
* // => { 'user': 'barney', 'age': 36 }
|
*
|
* // with explicit chaining
|
* _(users).chain()
|
* .first()
|
* .pick('user')
|
* .value();
|
* // => { 'user': 'barney' }
|
*/
|
function wrapperChain() {
|
return chain(this);
|
}
|
|
/**
|
* Executes the chained sequence and returns the wrapped result.
|
*
|
* @name commit
|
* @memberOf _
|
* @category Chain
|
* @returns {Object} Returns the new `lodash` wrapper instance.
|
* @example
|
*
|
* var array = [1, 2];
|
* var wrapped = _(array).push(3);
|
*
|
* console.log(array);
|
* // => [1, 2]
|
*
|
* wrapped = wrapped.commit();
|
* console.log(array);
|
* // => [1, 2, 3]
|
*
|
* wrapped.last();
|
* // => 3
|
*
|
* console.log(array);
|
* // => [1, 2, 3]
|
*/
|
function wrapperCommit() {
|
return new LodashWrapper(this.value(), this.__chain__);
|
}
|
|
/**
|
* Creates a new array joining a wrapped array with any additional arrays
|
* and/or values.
|
*
|
* @name concat
|
* @memberOf _
|
* @category Chain
|
* @param {...*} [values] The values to concatenate.
|
* @returns {Array} Returns the new concatenated array.
|
* @example
|
*
|
* var array = [1];
|
* var wrapped = _(array).concat(2, [3], [[4]]);
|
*
|
* console.log(wrapped.value());
|
* // => [1, 2, 3, [4]]
|
*
|
* console.log(array);
|
* // => [1]
|
*/
|
var wrapperConcat = restParam(function(values) {
|
values = baseFlatten(values);
|
return this.thru(function(array) {
|
return arrayConcat(isArray(array) ? array : [toObject(array)], values);
|
});
|
});
|
|
/**
|
* Creates a clone of the chained sequence planting `value` as the wrapped value.
|
*
|
* @name plant
|
* @memberOf _
|
* @category Chain
|
* @returns {Object} Returns the new `lodash` wrapper instance.
|
* @example
|
*
|
* var array = [1, 2];
|
* var wrapped = _(array).map(function(value) {
|
* return Math.pow(value, 2);
|
* });
|
*
|
* var other = [3, 4];
|
* var otherWrapped = wrapped.plant(other);
|
*
|
* otherWrapped.value();
|
* // => [9, 16]
|
*
|
* wrapped.value();
|
* // => [1, 4]
|
*/
|
function wrapperPlant(value) {
|
var result,
|
parent = this;
|
|
while (parent instanceof baseLodash) {
|
var clone = wrapperClone(parent);
|
if (result) {
|
previous.__wrapped__ = clone;
|
} else {
|
result = clone;
|
}
|
var previous = clone;
|
parent = parent.__wrapped__;
|
}
|
previous.__wrapped__ = value;
|
return result;
|
}
|
|
/**
|
* Reverses the wrapped array so the first element becomes the last, the
|
* second element becomes the second to last, and so on.
|
*
|
* **Note:** This method mutates the wrapped array.
|
*
|
* @name reverse
|
* @memberOf _
|
* @category Chain
|
* @returns {Object} Returns the new reversed `lodash` wrapper instance.
|
* @example
|
*
|
* var array = [1, 2, 3];
|
*
|
* _(array).reverse().value()
|
* // => [3, 2, 1]
|
*
|
* console.log(array);
|
* // => [3, 2, 1]
|
*/
|
function wrapperReverse() {
|
var value = this.__wrapped__;
|
|
var interceptor = function(value) {
|
return (wrapped && wrapped.__dir__ < 0) ? value : value.reverse();
|
};
|
if (value instanceof LazyWrapper) {
|
var wrapped = value;
|
if (this.__actions__.length) {
|
wrapped = new LazyWrapper(this);
|
}
|
wrapped = wrapped.reverse();
|
wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
|
return new LodashWrapper(wrapped, this.__chain__);
|
}
|
return this.thru(interceptor);
|
}
|
|
/**
|
* Produces the result of coercing the unwrapped value to a string.
|
*
|
* @name toString
|
* @memberOf _
|
* @category Chain
|
* @returns {string} Returns the coerced string value.
|
* @example
|
*
|
* _([1, 2, 3]).toString();
|
* // => '1,2,3'
|
*/
|
function wrapperToString() {
|
return (this.value() + '');
|
}
|
|
/**
|
* Executes the chained sequence to extract the unwrapped value.
|
*
|
* @name value
|
* @memberOf _
|
* @alias run, toJSON, valueOf
|
* @category Chain
|
* @returns {*} Returns the resolved unwrapped value.
|
* @example
|
*
|
* _([1, 2, 3]).value();
|
* // => [1, 2, 3]
|
*/
|
function wrapperValue() {
|
return baseWrapperValue(this.__wrapped__, this.__actions__);
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Creates an array of elements corresponding to the given keys, or indexes,
|
* of `collection`. Keys may be specified as individual arguments or as arrays
|
* of keys.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {...(number|number[]|string|string[])} [props] The property names
|
* or indexes of elements to pick, specified individually or in arrays.
|
* @returns {Array} Returns the new array of picked elements.
|
* @example
|
*
|
* _.at(['a', 'b', 'c'], [0, 2]);
|
* // => ['a', 'c']
|
*
|
* _.at(['barney', 'fred', 'pebbles'], 0, 2);
|
* // => ['barney', 'pebbles']
|
*/
|
var at = restParam(function(collection, props) {
|
return baseAt(collection, baseFlatten(props));
|
});
|
|
/**
|
* Creates an object composed of keys generated from the results of running
|
* each element of `collection` through `iteratee`. The corresponding value
|
* of each key is the number of times the key was returned by `iteratee`.
|
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
* (value, index|key, collection).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns the composed aggregate object.
|
* @example
|
*
|
* _.countBy([4.3, 6.1, 6.4], function(n) {
|
* return Math.floor(n);
|
* });
|
* // => { '4': 1, '6': 2 }
|
*
|
* _.countBy([4.3, 6.1, 6.4], function(n) {
|
* return this.floor(n);
|
* }, Math);
|
* // => { '4': 1, '6': 2 }
|
*
|
* _.countBy(['one', 'two', 'three'], 'length');
|
* // => { '3': 2, '5': 1 }
|
*/
|
var countBy = createAggregator(function(result, value, key) {
|
hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
|
});
|
|
/**
|
* Checks if `predicate` returns truthy for **all** elements of `collection`.
|
* The predicate is bound to `thisArg` and invoked with three arguments:
|
* (value, index|key, collection).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @alias all
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {boolean} Returns `true` if all elements pass the predicate check,
|
* else `false`.
|
* @example
|
*
|
* _.every([true, 1, null, 'yes'], Boolean);
|
* // => false
|
*
|
* var users = [
|
* { 'user': 'barney', 'active': false },
|
* { 'user': 'fred', 'active': false }
|
* ];
|
*
|
* // using the `_.matches` callback shorthand
|
* _.every(users, { 'user': 'barney', 'active': false });
|
* // => false
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.every(users, 'active', false);
|
* // => true
|
*
|
* // using the `_.property` callback shorthand
|
* _.every(users, 'active');
|
* // => false
|
*/
|
function every(collection, predicate, thisArg) {
|
var func = isArray(collection) ? arrayEvery : baseEvery;
|
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
|
predicate = undefined;
|
}
|
if (typeof predicate != 'function' || thisArg !== undefined) {
|
predicate = getCallback(predicate, thisArg, 3);
|
}
|
return func(collection, predicate);
|
}
|
|
/**
|
* Iterates over elements of `collection`, returning an array of all elements
|
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
|
* invoked with three arguments: (value, index|key, collection).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @alias select
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Array} Returns the new filtered array.
|
* @example
|
*
|
* _.filter([4, 5, 6], function(n) {
|
* return n % 2 == 0;
|
* });
|
* // => [4, 6]
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36, 'active': true },
|
* { 'user': 'fred', 'age': 40, 'active': false }
|
* ];
|
*
|
* // using the `_.matches` callback shorthand
|
* _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
|
* // => ['barney']
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.pluck(_.filter(users, 'active', false), 'user');
|
* // => ['fred']
|
*
|
* // using the `_.property` callback shorthand
|
* _.pluck(_.filter(users, 'active'), 'user');
|
* // => ['barney']
|
*/
|
function filter(collection, predicate, thisArg) {
|
var func = isArray(collection) ? arrayFilter : baseFilter;
|
predicate = getCallback(predicate, thisArg, 3);
|
return func(collection, predicate);
|
}
|
|
/**
|
* Iterates over elements of `collection`, returning the first element
|
* `predicate` returns truthy for. The predicate is bound to `thisArg` and
|
* invoked with three arguments: (value, index|key, collection).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @alias detect
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to search.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {*} Returns the matched element, else `undefined`.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36, 'active': true },
|
* { 'user': 'fred', 'age': 40, 'active': false },
|
* { 'user': 'pebbles', 'age': 1, 'active': true }
|
* ];
|
*
|
* _.result(_.find(users, function(chr) {
|
* return chr.age < 40;
|
* }), 'user');
|
* // => 'barney'
|
*
|
* // using the `_.matches` callback shorthand
|
* _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
|
* // => 'pebbles'
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.result(_.find(users, 'active', false), 'user');
|
* // => 'fred'
|
*
|
* // using the `_.property` callback shorthand
|
* _.result(_.find(users, 'active'), 'user');
|
* // => 'barney'
|
*/
|
var find = createFind(baseEach);
|
|
/**
|
* This method is like `_.find` except that it iterates over elements of
|
* `collection` from right to left.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to search.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {*} Returns the matched element, else `undefined`.
|
* @example
|
*
|
* _.findLast([1, 2, 3, 4], function(n) {
|
* return n % 2 == 1;
|
* });
|
* // => 3
|
*/
|
var findLast = createFind(baseEachRight, true);
|
|
/**
|
* Performs a deep comparison between each element in `collection` and the
|
* source object, returning the first element that has equivalent property
|
* values.
|
*
|
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
* numbers, `Object` objects, regexes, and strings. Objects are compared by
|
* their own, not inherited, enumerable properties. For comparing a single
|
* own or inherited property value see `_.matchesProperty`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to search.
|
* @param {Object} source The object of property values to match.
|
* @returns {*} Returns the matched element, else `undefined`.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36, 'active': true },
|
* { 'user': 'fred', 'age': 40, 'active': false }
|
* ];
|
*
|
* _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
|
* // => 'barney'
|
*
|
* _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
|
* // => 'fred'
|
*/
|
function findWhere(collection, source) {
|
return find(collection, baseMatches(source));
|
}
|
|
/**
|
* Iterates over elements of `collection` invoking `iteratee` for each element.
|
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
* (value, index|key, collection). Iteratee functions may exit iteration early
|
* by explicitly returning `false`.
|
*
|
* **Note:** As with other "Collections" methods, objects with a "length" property
|
* are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
|
* may be used for object iteration.
|
*
|
* @static
|
* @memberOf _
|
* @alias each
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Array|Object|string} Returns `collection`.
|
* @example
|
*
|
* _([1, 2]).forEach(function(n) {
|
* console.log(n);
|
* }).value();
|
* // => logs each value from left to right and returns the array
|
*
|
* _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
|
* console.log(n, key);
|
* });
|
* // => logs each value-key pair and returns the object (iteration order is not guaranteed)
|
*/
|
var forEach = createForEach(arrayEach, baseEach);
|
|
/**
|
* This method is like `_.forEach` except that it iterates over elements of
|
* `collection` from right to left.
|
*
|
* @static
|
* @memberOf _
|
* @alias eachRight
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Array|Object|string} Returns `collection`.
|
* @example
|
*
|
* _([1, 2]).forEachRight(function(n) {
|
* console.log(n);
|
* }).value();
|
* // => logs each value from right to left and returns the array
|
*/
|
var forEachRight = createForEach(arrayEachRight, baseEachRight);
|
|
/**
|
* Creates an object composed of keys generated from the results of running
|
* each element of `collection` through `iteratee`. The corresponding value
|
* of each key is an array of the elements responsible for generating the key.
|
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
* (value, index|key, collection).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns the composed aggregate object.
|
* @example
|
*
|
* _.groupBy([4.2, 6.1, 6.4], function(n) {
|
* return Math.floor(n);
|
* });
|
* // => { '4': [4.2], '6': [6.1, 6.4] }
|
*
|
* _.groupBy([4.2, 6.1, 6.4], function(n) {
|
* return this.floor(n);
|
* }, Math);
|
* // => { '4': [4.2], '6': [6.1, 6.4] }
|
*
|
* // using the `_.property` callback shorthand
|
* _.groupBy(['one', 'two', 'three'], 'length');
|
* // => { '3': ['one', 'two'], '5': ['three'] }
|
*/
|
var groupBy = createAggregator(function(result, value, key) {
|
if (hasOwnProperty.call(result, key)) {
|
result[key].push(value);
|
} else {
|
result[key] = [value];
|
}
|
});
|
|
/**
|
* Checks if `value` is in `collection` using
|
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
* for equality comparisons. If `fromIndex` is negative, it is used as the offset
|
* from the end of `collection`.
|
*
|
* @static
|
* @memberOf _
|
* @alias contains, include
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to search.
|
* @param {*} target The value to search for.
|
* @param {number} [fromIndex=0] The index to search from.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
|
* @returns {boolean} Returns `true` if a matching element is found, else `false`.
|
* @example
|
*
|
* _.includes([1, 2, 3], 1);
|
* // => true
|
*
|
* _.includes([1, 2, 3], 1, 2);
|
* // => false
|
*
|
* _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
|
* // => true
|
*
|
* _.includes('pebbles', 'eb');
|
* // => true
|
*/
|
function includes(collection, target, fromIndex, guard) {
|
var length = collection ? getLength(collection) : 0;
|
if (!isLength(length)) {
|
collection = values(collection);
|
length = collection.length;
|
}
|
if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
|
fromIndex = 0;
|
} else {
|
fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
|
}
|
return (typeof collection == 'string' || !isArray(collection) && isString(collection))
|
? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
|
: (!!length && getIndexOf(collection, target, fromIndex) > -1);
|
}
|
|
/**
|
* Creates an object composed of keys generated from the results of running
|
* each element of `collection` through `iteratee`. The corresponding value
|
* of each key is the last element responsible for generating the key. The
|
* iteratee function is bound to `thisArg` and invoked with three arguments:
|
* (value, index|key, collection).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns the composed aggregate object.
|
* @example
|
*
|
* var keyData = [
|
* { 'dir': 'left', 'code': 97 },
|
* { 'dir': 'right', 'code': 100 }
|
* ];
|
*
|
* _.indexBy(keyData, 'dir');
|
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
|
*
|
* _.indexBy(keyData, function(object) {
|
* return String.fromCharCode(object.code);
|
* });
|
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
*
|
* _.indexBy(keyData, function(object) {
|
* return this.fromCharCode(object.code);
|
* }, String);
|
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
*/
|
var indexBy = createAggregator(function(result, value, key) {
|
result[key] = value;
|
});
|
|
/**
|
* Invokes the method at `path` of each element in `collection`, returning
|
* an array of the results of each invoked method. Any additional arguments
|
* are provided to each invoked method. If `methodName` is a function it is
|
* invoked for, and `this` bound to, each element in `collection`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|Function|string} path The path of the method to invoke or
|
* the function invoked per iteration.
|
* @param {...*} [args] The arguments to invoke the method with.
|
* @returns {Array} Returns the array of results.
|
* @example
|
*
|
* _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
|
* // => [[1, 5, 7], [1, 2, 3]]
|
*
|
* _.invoke([123, 456], String.prototype.split, '');
|
* // => [['1', '2', '3'], ['4', '5', '6']]
|
*/
|
var invoke = restParam(function(collection, path, args) {
|
var index = -1,
|
isFunc = typeof path == 'function',
|
isProp = isKey(path),
|
result = isArrayLike(collection) ? Array(collection.length) : [];
|
|
baseEach(collection, function(value) {
|
var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
|
result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
|
});
|
return result;
|
});
|
|
/**
|
* Creates an array of values by running each element in `collection` through
|
* `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
|
* arguments: (value, index|key, collection).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* Many lodash methods are guarded to work as iteratees for methods like
|
* `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
*
|
* The guarded methods are:
|
* `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
|
* `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
|
* `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
|
* `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
|
* `sum`, `uniq`, and `words`
|
*
|
* @static
|
* @memberOf _
|
* @alias collect
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Array} Returns the new mapped array.
|
* @example
|
*
|
* function timesThree(n) {
|
* return n * 3;
|
* }
|
*
|
* _.map([1, 2], timesThree);
|
* // => [3, 6]
|
*
|
* _.map({ 'a': 1, 'b': 2 }, timesThree);
|
* // => [3, 6] (iteration order is not guaranteed)
|
*
|
* var users = [
|
* { 'user': 'barney' },
|
* { 'user': 'fred' }
|
* ];
|
*
|
* // using the `_.property` callback shorthand
|
* _.map(users, 'user');
|
* // => ['barney', 'fred']
|
*/
|
function map(collection, iteratee, thisArg) {
|
var func = isArray(collection) ? arrayMap : baseMap;
|
iteratee = getCallback(iteratee, thisArg, 3);
|
return func(collection, iteratee);
|
}
|
|
/**
|
* Creates an array of elements split into two groups, the first of which
|
* contains elements `predicate` returns truthy for, while the second of which
|
* contains elements `predicate` returns falsey for. The predicate is bound
|
* to `thisArg` and invoked with three arguments: (value, index|key, collection).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Array} Returns the array of grouped elements.
|
* @example
|
*
|
* _.partition([1, 2, 3], function(n) {
|
* return n % 2;
|
* });
|
* // => [[1, 3], [2]]
|
*
|
* _.partition([1.2, 2.3, 3.4], function(n) {
|
* return this.floor(n) % 2;
|
* }, Math);
|
* // => [[1.2, 3.4], [2.3]]
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36, 'active': false },
|
* { 'user': 'fred', 'age': 40, 'active': true },
|
* { 'user': 'pebbles', 'age': 1, 'active': false }
|
* ];
|
*
|
* var mapper = function(array) {
|
* return _.pluck(array, 'user');
|
* };
|
*
|
* // using the `_.matches` callback shorthand
|
* _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
|
* // => [['pebbles'], ['barney', 'fred']]
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.map(_.partition(users, 'active', false), mapper);
|
* // => [['barney', 'pebbles'], ['fred']]
|
*
|
* // using the `_.property` callback shorthand
|
* _.map(_.partition(users, 'active'), mapper);
|
* // => [['fred'], ['barney', 'pebbles']]
|
*/
|
var partition = createAggregator(function(result, value, key) {
|
result[key ? 0 : 1].push(value);
|
}, function() { return [[], []]; });
|
|
/**
|
* Gets the property value of `path` from all elements in `collection`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Array|string} path The path of the property to pluck.
|
* @returns {Array} Returns the property values.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'fred', 'age': 40 }
|
* ];
|
*
|
* _.pluck(users, 'user');
|
* // => ['barney', 'fred']
|
*
|
* var userIndex = _.indexBy(users, 'user');
|
* _.pluck(userIndex, 'age');
|
* // => [36, 40] (iteration order is not guaranteed)
|
*/
|
function pluck(collection, path) {
|
return map(collection, property(path));
|
}
|
|
/**
|
* Reduces `collection` to a value which is the accumulated result of running
|
* each element in `collection` through `iteratee`, where each successive
|
* invocation is supplied the return value of the previous. If `accumulator`
|
* is not provided the first element of `collection` is used as the initial
|
* value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
|
* (accumulator, value, index|key, collection).
|
*
|
* Many lodash methods are guarded to work as iteratees for methods like
|
* `_.reduce`, `_.reduceRight`, and `_.transform`.
|
*
|
* The guarded methods are:
|
* `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
|
* and `sortByOrder`
|
*
|
* @static
|
* @memberOf _
|
* @alias foldl, inject
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [accumulator] The initial value.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {*} Returns the accumulated value.
|
* @example
|
*
|
* _.reduce([1, 2], function(total, n) {
|
* return total + n;
|
* });
|
* // => 3
|
*
|
* _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
|
* result[key] = n * 3;
|
* return result;
|
* }, {});
|
* // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
|
*/
|
var reduce = createReduce(arrayReduce, baseEach);
|
|
/**
|
* This method is like `_.reduce` except that it iterates over elements of
|
* `collection` from right to left.
|
*
|
* @static
|
* @memberOf _
|
* @alias foldr
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [accumulator] The initial value.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {*} Returns the accumulated value.
|
* @example
|
*
|
* var array = [[0, 1], [2, 3], [4, 5]];
|
*
|
* _.reduceRight(array, function(flattened, other) {
|
* return flattened.concat(other);
|
* }, []);
|
* // => [4, 5, 2, 3, 0, 1]
|
*/
|
var reduceRight = createReduce(arrayReduceRight, baseEachRight);
|
|
/**
|
* The opposite of `_.filter`; this method returns the elements of `collection`
|
* that `predicate` does **not** return truthy for.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Array} Returns the new filtered array.
|
* @example
|
*
|
* _.reject([1, 2, 3, 4], function(n) {
|
* return n % 2 == 0;
|
* });
|
* // => [1, 3]
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36, 'active': false },
|
* { 'user': 'fred', 'age': 40, 'active': true }
|
* ];
|
*
|
* // using the `_.matches` callback shorthand
|
* _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
|
* // => ['barney']
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.pluck(_.reject(users, 'active', false), 'user');
|
* // => ['fred']
|
*
|
* // using the `_.property` callback shorthand
|
* _.pluck(_.reject(users, 'active'), 'user');
|
* // => ['barney']
|
*/
|
function reject(collection, predicate, thisArg) {
|
var func = isArray(collection) ? arrayFilter : baseFilter;
|
predicate = getCallback(predicate, thisArg, 3);
|
return func(collection, function(value, index, collection) {
|
return !predicate(value, index, collection);
|
});
|
}
|
|
/**
|
* Gets a random element or `n` random elements from a collection.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to sample.
|
* @param {number} [n] The number of elements to sample.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {*} Returns the random sample(s).
|
* @example
|
*
|
* _.sample([1, 2, 3, 4]);
|
* // => 2
|
*
|
* _.sample([1, 2, 3, 4], 2);
|
* // => [3, 1]
|
*/
|
function sample(collection, n, guard) {
|
if (guard ? isIterateeCall(collection, n, guard) : n == null) {
|
collection = toIterable(collection);
|
var length = collection.length;
|
return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
|
}
|
var index = -1,
|
result = toArray(collection),
|
length = result.length,
|
lastIndex = length - 1;
|
|
n = nativeMin(n < 0 ? 0 : (+n || 0), length);
|
while (++index < n) {
|
var rand = baseRandom(index, lastIndex),
|
value = result[rand];
|
|
result[rand] = result[index];
|
result[index] = value;
|
}
|
result.length = n;
|
return result;
|
}
|
|
/**
|
* Creates an array of shuffled values, using a version of the
|
* [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to shuffle.
|
* @returns {Array} Returns the new shuffled array.
|
* @example
|
*
|
* _.shuffle([1, 2, 3, 4]);
|
* // => [4, 1, 3, 2]
|
*/
|
function shuffle(collection) {
|
return sample(collection, POSITIVE_INFINITY);
|
}
|
|
/**
|
* Gets the size of `collection` by returning its length for array-like
|
* values or the number of own enumerable properties for objects.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to inspect.
|
* @returns {number} Returns the size of `collection`.
|
* @example
|
*
|
* _.size([1, 2, 3]);
|
* // => 3
|
*
|
* _.size({ 'a': 1, 'b': 2 });
|
* // => 2
|
*
|
* _.size('pebbles');
|
* // => 7
|
*/
|
function size(collection) {
|
var length = collection ? getLength(collection) : 0;
|
return isLength(length) ? length : keys(collection).length;
|
}
|
|
/**
|
* Checks if `predicate` returns truthy for **any** element of `collection`.
|
* The function returns as soon as it finds a passing value and does not iterate
|
* over the entire collection. The predicate is bound to `thisArg` and invoked
|
* with three arguments: (value, index|key, collection).
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @alias any
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {boolean} Returns `true` if any element passes the predicate check,
|
* else `false`.
|
* @example
|
*
|
* _.some([null, 0, 'yes', false], Boolean);
|
* // => true
|
*
|
* var users = [
|
* { 'user': 'barney', 'active': true },
|
* { 'user': 'fred', 'active': false }
|
* ];
|
*
|
* // using the `_.matches` callback shorthand
|
* _.some(users, { 'user': 'barney', 'active': false });
|
* // => false
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.some(users, 'active', false);
|
* // => true
|
*
|
* // using the `_.property` callback shorthand
|
* _.some(users, 'active');
|
* // => true
|
*/
|
function some(collection, predicate, thisArg) {
|
var func = isArray(collection) ? arraySome : baseSome;
|
if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
|
predicate = undefined;
|
}
|
if (typeof predicate != 'function' || thisArg !== undefined) {
|
predicate = getCallback(predicate, thisArg, 3);
|
}
|
return func(collection, predicate);
|
}
|
|
/**
|
* Creates an array of elements, sorted in ascending order by the results of
|
* running each element in a collection through `iteratee`. This method performs
|
* a stable sort, that is, it preserves the original sort order of equal elements.
|
* The `iteratee` is bound to `thisArg` and invoked with three arguments:
|
* (value, index|key, collection).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Array} Returns the new sorted array.
|
* @example
|
*
|
* _.sortBy([1, 2, 3], function(n) {
|
* return Math.sin(n);
|
* });
|
* // => [3, 1, 2]
|
*
|
* _.sortBy([1, 2, 3], function(n) {
|
* return this.sin(n);
|
* }, Math);
|
* // => [3, 1, 2]
|
*
|
* var users = [
|
* { 'user': 'fred' },
|
* { 'user': 'pebbles' },
|
* { 'user': 'barney' }
|
* ];
|
*
|
* // using the `_.property` callback shorthand
|
* _.pluck(_.sortBy(users, 'user'), 'user');
|
* // => ['barney', 'fred', 'pebbles']
|
*/
|
function sortBy(collection, iteratee, thisArg) {
|
if (collection == null) {
|
return [];
|
}
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
iteratee = undefined;
|
}
|
var index = -1;
|
iteratee = getCallback(iteratee, thisArg, 3);
|
|
var result = baseMap(collection, function(value, key, collection) {
|
return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
|
});
|
return baseSortBy(result, compareAscending);
|
}
|
|
/**
|
* This method is like `_.sortBy` except that it can sort by multiple iteratees
|
* or property names.
|
*
|
* If a property name is provided for an iteratee the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If an object is provided for an iteratee the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
|
* The iteratees to sort by, specified as individual values or arrays of values.
|
* @returns {Array} Returns the new sorted array.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'fred', 'age': 48 },
|
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'fred', 'age': 42 },
|
* { 'user': 'barney', 'age': 34 }
|
* ];
|
*
|
* _.map(_.sortByAll(users, ['user', 'age']), _.values);
|
* // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
|
*
|
* _.map(_.sortByAll(users, 'user', function(chr) {
|
* return Math.floor(chr.age / 10);
|
* }), _.values);
|
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
*/
|
var sortByAll = restParam(function(collection, iteratees) {
|
if (collection == null) {
|
return [];
|
}
|
var guard = iteratees[2];
|
if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
|
iteratees.length = 1;
|
}
|
return baseSortByOrder(collection, baseFlatten(iteratees), []);
|
});
|
|
/**
|
* This method is like `_.sortByAll` except that it allows specifying the
|
* sort orders of the iteratees to sort by. If `orders` is unspecified, all
|
* values are sorted in ascending order. Otherwise, a value is sorted in
|
* ascending order if its corresponding order is "asc", and descending if "desc".
|
*
|
* If a property name is provided for an iteratee the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If an object is provided for an iteratee the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
|
* @param {boolean[]} [orders] The sort orders of `iteratees`.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
|
* @returns {Array} Returns the new sorted array.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'fred', 'age': 48 },
|
* { 'user': 'barney', 'age': 34 },
|
* { 'user': 'fred', 'age': 42 },
|
* { 'user': 'barney', 'age': 36 }
|
* ];
|
*
|
* // sort by `user` in ascending order and by `age` in descending order
|
* _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
|
* // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
*/
|
function sortByOrder(collection, iteratees, orders, guard) {
|
if (collection == null) {
|
return [];
|
}
|
if (guard && isIterateeCall(iteratees, orders, guard)) {
|
orders = undefined;
|
}
|
if (!isArray(iteratees)) {
|
iteratees = iteratees == null ? [] : [iteratees];
|
}
|
if (!isArray(orders)) {
|
orders = orders == null ? [] : [orders];
|
}
|
return baseSortByOrder(collection, iteratees, orders);
|
}
|
|
/**
|
* Performs a deep comparison between each element in `collection` and the
|
* source object, returning an array of all elements that have equivalent
|
* property values.
|
*
|
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
* numbers, `Object` objects, regexes, and strings. Objects are compared by
|
* their own, not inherited, enumerable properties. For comparing a single
|
* own or inherited property value see `_.matchesProperty`.
|
*
|
* @static
|
* @memberOf _
|
* @category Collection
|
* @param {Array|Object|string} collection The collection to search.
|
* @param {Object} source The object of property values to match.
|
* @returns {Array} Returns the new filtered array.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
|
* { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
|
* ];
|
*
|
* _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
|
* // => ['barney']
|
*
|
* _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
|
* // => ['fred']
|
*/
|
function where(collection, source) {
|
return filter(collection, baseMatches(source));
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Gets the number of milliseconds that have elapsed since the Unix epoch
|
* (1 January 1970 00:00:00 UTC).
|
*
|
* @static
|
* @memberOf _
|
* @category Date
|
* @example
|
*
|
* _.defer(function(stamp) {
|
* console.log(_.now() - stamp);
|
* }, _.now());
|
* // => logs the number of milliseconds it took for the deferred function to be invoked
|
*/
|
var now = nativeNow || function() {
|
return new Date().getTime();
|
};
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* The opposite of `_.before`; this method creates a function that invokes
|
* `func` once it is called `n` or more times.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {number} n The number of calls before `func` is invoked.
|
* @param {Function} func The function to restrict.
|
* @returns {Function} Returns the new restricted function.
|
* @example
|
*
|
* var saves = ['profile', 'settings'];
|
*
|
* var done = _.after(saves.length, function() {
|
* console.log('done saving!');
|
* });
|
*
|
* _.forEach(saves, function(type) {
|
* asyncSave({ 'type': type, 'complete': done });
|
* });
|
* // => logs 'done saving!' after the two async saves have completed
|
*/
|
function after(n, func) {
|
if (typeof func != 'function') {
|
if (typeof n == 'function') {
|
var temp = n;
|
n = func;
|
func = temp;
|
} else {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
}
|
n = nativeIsFinite(n = +n) ? n : 0;
|
return function() {
|
if (--n < 1) {
|
return func.apply(this, arguments);
|
}
|
};
|
}
|
|
/**
|
* Creates a function that accepts up to `n` arguments ignoring any
|
* additional arguments.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to cap arguments for.
|
* @param {number} [n=func.length] The arity cap.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* _.map(['6', '8', '10'], _.ary(parseInt, 1));
|
* // => [6, 8, 10]
|
*/
|
function ary(func, n, guard) {
|
if (guard && isIterateeCall(func, n, guard)) {
|
n = undefined;
|
}
|
n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
|
return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
|
}
|
|
/**
|
* Creates a function that invokes `func`, with the `this` binding and arguments
|
* of the created function, while it is called less than `n` times. Subsequent
|
* calls to the created function return the result of the last `func` invocation.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {number} n The number of calls at which `func` is no longer invoked.
|
* @param {Function} func The function to restrict.
|
* @returns {Function} Returns the new restricted function.
|
* @example
|
*
|
* jQuery('#add').on('click', _.before(5, addContactToList));
|
* // => allows adding up to 4 contacts to the list
|
*/
|
function before(n, func) {
|
var result;
|
if (typeof func != 'function') {
|
if (typeof n == 'function') {
|
var temp = n;
|
n = func;
|
func = temp;
|
} else {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
}
|
return function() {
|
if (--n > 0) {
|
result = func.apply(this, arguments);
|
}
|
if (n <= 1) {
|
func = undefined;
|
}
|
return result;
|
};
|
}
|
|
/**
|
* Creates a function that invokes `func` with the `this` binding of `thisArg`
|
* and prepends any additional `_.bind` arguments to those provided to the
|
* bound function.
|
*
|
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
* may be used as a placeholder for partially applied arguments.
|
*
|
* **Note:** Unlike native `Function#bind` this method does not set the "length"
|
* property of bound functions.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to bind.
|
* @param {*} thisArg The `this` binding of `func`.
|
* @param {...*} [partials] The arguments to be partially applied.
|
* @returns {Function} Returns the new bound function.
|
* @example
|
*
|
* var greet = function(greeting, punctuation) {
|
* return greeting + ' ' + this.user + punctuation;
|
* };
|
*
|
* var object = { 'user': 'fred' };
|
*
|
* var bound = _.bind(greet, object, 'hi');
|
* bound('!');
|
* // => 'hi fred!'
|
*
|
* // using placeholders
|
* var bound = _.bind(greet, object, _, '!');
|
* bound('hi');
|
* // => 'hi fred!'
|
*/
|
var bind = restParam(function(func, thisArg, partials) {
|
var bitmask = BIND_FLAG;
|
if (partials.length) {
|
var holders = replaceHolders(partials, bind.placeholder);
|
bitmask |= PARTIAL_FLAG;
|
}
|
return createWrapper(func, bitmask, thisArg, partials, holders);
|
});
|
|
/**
|
* Binds methods of an object to the object itself, overwriting the existing
|
* method. Method names may be specified as individual arguments or as arrays
|
* of method names. If no method names are provided all enumerable function
|
* properties, own and inherited, of `object` are bound.
|
*
|
* **Note:** This method does not set the "length" property of bound functions.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Object} object The object to bind and assign the bound methods to.
|
* @param {...(string|string[])} [methodNames] The object method names to bind,
|
* specified as individual method names or arrays of method names.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* var view = {
|
* 'label': 'docs',
|
* 'onClick': function() {
|
* console.log('clicked ' + this.label);
|
* }
|
* };
|
*
|
* _.bindAll(view);
|
* jQuery('#docs').on('click', view.onClick);
|
* // => logs 'clicked docs' when the element is clicked
|
*/
|
var bindAll = restParam(function(object, methodNames) {
|
methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
|
|
var index = -1,
|
length = methodNames.length;
|
|
while (++index < length) {
|
var key = methodNames[index];
|
object[key] = createWrapper(object[key], BIND_FLAG, object);
|
}
|
return object;
|
});
|
|
/**
|
* Creates a function that invokes the method at `object[key]` and prepends
|
* any additional `_.bindKey` arguments to those provided to the bound function.
|
*
|
* This method differs from `_.bind` by allowing bound functions to reference
|
* methods that may be redefined or don't yet exist.
|
* See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
|
* for more details.
|
*
|
* The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
|
* builds, may be used as a placeholder for partially applied arguments.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Object} object The object the method belongs to.
|
* @param {string} key The key of the method.
|
* @param {...*} [partials] The arguments to be partially applied.
|
* @returns {Function} Returns the new bound function.
|
* @example
|
*
|
* var object = {
|
* 'user': 'fred',
|
* 'greet': function(greeting, punctuation) {
|
* return greeting + ' ' + this.user + punctuation;
|
* }
|
* };
|
*
|
* var bound = _.bindKey(object, 'greet', 'hi');
|
* bound('!');
|
* // => 'hi fred!'
|
*
|
* object.greet = function(greeting, punctuation) {
|
* return greeting + 'ya ' + this.user + punctuation;
|
* };
|
*
|
* bound('!');
|
* // => 'hiya fred!'
|
*
|
* // using placeholders
|
* var bound = _.bindKey(object, 'greet', _, '!');
|
* bound('hi');
|
* // => 'hiya fred!'
|
*/
|
var bindKey = restParam(function(object, key, partials) {
|
var bitmask = BIND_FLAG | BIND_KEY_FLAG;
|
if (partials.length) {
|
var holders = replaceHolders(partials, bindKey.placeholder);
|
bitmask |= PARTIAL_FLAG;
|
}
|
return createWrapper(key, bitmask, object, partials, holders);
|
});
|
|
/**
|
* Creates a function that accepts one or more arguments of `func` that when
|
* called either invokes `func` returning its result, if all `func` arguments
|
* have been provided, or returns a function that accepts one or more of the
|
* remaining `func` arguments, and so on. The arity of `func` may be specified
|
* if `func.length` is not sufficient.
|
*
|
* The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
* may be used as a placeholder for provided arguments.
|
*
|
* **Note:** This method does not set the "length" property of curried functions.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to curry.
|
* @param {number} [arity=func.length] The arity of `func`.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Function} Returns the new curried function.
|
* @example
|
*
|
* var abc = function(a, b, c) {
|
* return [a, b, c];
|
* };
|
*
|
* var curried = _.curry(abc);
|
*
|
* curried(1)(2)(3);
|
* // => [1, 2, 3]
|
*
|
* curried(1, 2)(3);
|
* // => [1, 2, 3]
|
*
|
* curried(1, 2, 3);
|
* // => [1, 2, 3]
|
*
|
* // using placeholders
|
* curried(1)(_, 3)(2);
|
* // => [1, 2, 3]
|
*/
|
var curry = createCurry(CURRY_FLAG);
|
|
/**
|
* This method is like `_.curry` except that arguments are applied to `func`
|
* in the manner of `_.partialRight` instead of `_.partial`.
|
*
|
* The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
|
* builds, may be used as a placeholder for provided arguments.
|
*
|
* **Note:** This method does not set the "length" property of curried functions.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to curry.
|
* @param {number} [arity=func.length] The arity of `func`.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Function} Returns the new curried function.
|
* @example
|
*
|
* var abc = function(a, b, c) {
|
* return [a, b, c];
|
* };
|
*
|
* var curried = _.curryRight(abc);
|
*
|
* curried(3)(2)(1);
|
* // => [1, 2, 3]
|
*
|
* curried(2, 3)(1);
|
* // => [1, 2, 3]
|
*
|
* curried(1, 2, 3);
|
* // => [1, 2, 3]
|
*
|
* // using placeholders
|
* curried(3)(1, _)(2);
|
* // => [1, 2, 3]
|
*/
|
var curryRight = createCurry(CURRY_RIGHT_FLAG);
|
|
/**
|
* Creates a debounced function that delays invoking `func` until after `wait`
|
* milliseconds have elapsed since the last time the debounced function was
|
* invoked. The debounced function comes with a `cancel` method to cancel
|
* delayed invocations. Provide an options object to indicate that `func`
|
* should be invoked on the leading and/or trailing edge of the `wait` timeout.
|
* Subsequent calls to the debounced function return the result of the last
|
* `func` invocation.
|
*
|
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
|
* on the trailing edge of the timeout only if the the debounced function is
|
* invoked more than once during the `wait` timeout.
|
*
|
* See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
|
* for details over the differences between `_.debounce` and `_.throttle`.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to debounce.
|
* @param {number} [wait=0] The number of milliseconds to delay.
|
* @param {Object} [options] The options object.
|
* @param {boolean} [options.leading=false] Specify invoking on the leading
|
* edge of the timeout.
|
* @param {number} [options.maxWait] The maximum time `func` is allowed to be
|
* delayed before it is invoked.
|
* @param {boolean} [options.trailing=true] Specify invoking on the trailing
|
* edge of the timeout.
|
* @returns {Function} Returns the new debounced function.
|
* @example
|
*
|
* // avoid costly calculations while the window size is in flux
|
* jQuery(window).on('resize', _.debounce(calculateLayout, 150));
|
*
|
* // invoke `sendMail` when the click event is fired, debouncing subsequent calls
|
* jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
|
* 'leading': true,
|
* 'trailing': false
|
* }));
|
*
|
* // ensure `batchLog` is invoked once after 1 second of debounced calls
|
* var source = new EventSource('/stream');
|
* jQuery(source).on('message', _.debounce(batchLog, 250, {
|
* 'maxWait': 1000
|
* }));
|
*
|
* // cancel a debounced call
|
* var todoChanges = _.debounce(batchLog, 1000);
|
* Object.observe(models.todo, todoChanges);
|
*
|
* Object.observe(models, function(changes) {
|
* if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
|
* todoChanges.cancel();
|
* }
|
* }, ['delete']);
|
*
|
* // ...at some point `models.todo` is changed
|
* models.todo.completed = true;
|
*
|
* // ...before 1 second has passed `models.todo` is deleted
|
* // which cancels the debounced `todoChanges` call
|
* delete models.todo;
|
*/
|
function debounce(func, wait, options) {
|
var args,
|
maxTimeoutId,
|
result,
|
stamp,
|
thisArg,
|
timeoutId,
|
trailingCall,
|
lastCalled = 0,
|
maxWait = false,
|
trailing = true;
|
|
if (typeof func != 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
wait = wait < 0 ? 0 : (+wait || 0);
|
if (options === true) {
|
var leading = true;
|
trailing = false;
|
} else if (isObject(options)) {
|
leading = !!options.leading;
|
maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
|
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
}
|
|
function cancel() {
|
if (timeoutId) {
|
clearTimeout(timeoutId);
|
}
|
if (maxTimeoutId) {
|
clearTimeout(maxTimeoutId);
|
}
|
lastCalled = 0;
|
maxTimeoutId = timeoutId = trailingCall = undefined;
|
}
|
|
function complete(isCalled, id) {
|
if (id) {
|
clearTimeout(id);
|
}
|
maxTimeoutId = timeoutId = trailingCall = undefined;
|
if (isCalled) {
|
lastCalled = now();
|
result = func.apply(thisArg, args);
|
if (!timeoutId && !maxTimeoutId) {
|
args = thisArg = undefined;
|
}
|
}
|
}
|
|
function delayed() {
|
var remaining = wait - (now() - stamp);
|
if (remaining <= 0 || remaining > wait) {
|
complete(trailingCall, maxTimeoutId);
|
} else {
|
timeoutId = setTimeout(delayed, remaining);
|
}
|
}
|
|
function maxDelayed() {
|
complete(trailing, timeoutId);
|
}
|
|
function debounced() {
|
args = arguments;
|
stamp = now();
|
thisArg = this;
|
trailingCall = trailing && (timeoutId || !leading);
|
|
if (maxWait === false) {
|
var leadingCall = leading && !timeoutId;
|
} else {
|
if (!maxTimeoutId && !leading) {
|
lastCalled = stamp;
|
}
|
var remaining = maxWait - (stamp - lastCalled),
|
isCalled = remaining <= 0 || remaining > maxWait;
|
|
if (isCalled) {
|
if (maxTimeoutId) {
|
maxTimeoutId = clearTimeout(maxTimeoutId);
|
}
|
lastCalled = stamp;
|
result = func.apply(thisArg, args);
|
}
|
else if (!maxTimeoutId) {
|
maxTimeoutId = setTimeout(maxDelayed, remaining);
|
}
|
}
|
if (isCalled && timeoutId) {
|
timeoutId = clearTimeout(timeoutId);
|
}
|
else if (!timeoutId && wait !== maxWait) {
|
timeoutId = setTimeout(delayed, wait);
|
}
|
if (leadingCall) {
|
isCalled = true;
|
result = func.apply(thisArg, args);
|
}
|
if (isCalled && !timeoutId && !maxTimeoutId) {
|
args = thisArg = undefined;
|
}
|
return result;
|
}
|
debounced.cancel = cancel;
|
return debounced;
|
}
|
|
/**
|
* Defers invoking the `func` until the current call stack has cleared. Any
|
* additional arguments are provided to `func` when it is invoked.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to defer.
|
* @param {...*} [args] The arguments to invoke the function with.
|
* @returns {number} Returns the timer id.
|
* @example
|
*
|
* _.defer(function(text) {
|
* console.log(text);
|
* }, 'deferred');
|
* // logs 'deferred' after one or more milliseconds
|
*/
|
var defer = restParam(function(func, args) {
|
return baseDelay(func, 1, args);
|
});
|
|
/**
|
* Invokes `func` after `wait` milliseconds. Any additional arguments are
|
* provided to `func` when it is invoked.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to delay.
|
* @param {number} wait The number of milliseconds to delay invocation.
|
* @param {...*} [args] The arguments to invoke the function with.
|
* @returns {number} Returns the timer id.
|
* @example
|
*
|
* _.delay(function(text) {
|
* console.log(text);
|
* }, 1000, 'later');
|
* // => logs 'later' after one second
|
*/
|
var delay = restParam(function(func, wait, args) {
|
return baseDelay(func, wait, args);
|
});
|
|
/**
|
* Creates a function that returns the result of invoking the provided
|
* functions with the `this` binding of the created function, where each
|
* successive invocation is supplied the return value of the previous.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {...Function} [funcs] Functions to invoke.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* function square(n) {
|
* return n * n;
|
* }
|
*
|
* var addSquare = _.flow(_.add, square);
|
* addSquare(1, 2);
|
* // => 9
|
*/
|
var flow = createFlow();
|
|
/**
|
* This method is like `_.flow` except that it creates a function that
|
* invokes the provided functions from right to left.
|
*
|
* @static
|
* @memberOf _
|
* @alias backflow, compose
|
* @category Function
|
* @param {...Function} [funcs] Functions to invoke.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* function square(n) {
|
* return n * n;
|
* }
|
*
|
* var addSquare = _.flowRight(square, _.add);
|
* addSquare(1, 2);
|
* // => 9
|
*/
|
var flowRight = createFlow(true);
|
|
/**
|
* Creates a function that memoizes the result of `func`. If `resolver` is
|
* provided it determines the cache key for storing the result based on the
|
* arguments provided to the memoized function. By default, the first argument
|
* provided to the memoized function is coerced to a string and used as the
|
* cache key. The `func` is invoked with the `this` binding of the memoized
|
* function.
|
*
|
* **Note:** The cache is exposed as the `cache` property on the memoized
|
* function. Its creation may be customized by replacing the `_.memoize.Cache`
|
* constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
|
* method interface of `get`, `has`, and `set`.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to have its output memoized.
|
* @param {Function} [resolver] The function to resolve the cache key.
|
* @returns {Function} Returns the new memoizing function.
|
* @example
|
*
|
* var upperCase = _.memoize(function(string) {
|
* return string.toUpperCase();
|
* });
|
*
|
* upperCase('fred');
|
* // => 'FRED'
|
*
|
* // modifying the result cache
|
* upperCase.cache.set('fred', 'BARNEY');
|
* upperCase('fred');
|
* // => 'BARNEY'
|
*
|
* // replacing `_.memoize.Cache`
|
* var object = { 'user': 'fred' };
|
* var other = { 'user': 'barney' };
|
* var identity = _.memoize(_.identity);
|
*
|
* identity(object);
|
* // => { 'user': 'fred' }
|
* identity(other);
|
* // => { 'user': 'fred' }
|
*
|
* _.memoize.Cache = WeakMap;
|
* var identity = _.memoize(_.identity);
|
*
|
* identity(object);
|
* // => { 'user': 'fred' }
|
* identity(other);
|
* // => { 'user': 'barney' }
|
*/
|
function memoize(func, resolver) {
|
if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
var memoized = function() {
|
var args = arguments,
|
key = resolver ? resolver.apply(this, args) : args[0],
|
cache = memoized.cache;
|
|
if (cache.has(key)) {
|
return cache.get(key);
|
}
|
var result = func.apply(this, args);
|
memoized.cache = cache.set(key, result);
|
return result;
|
};
|
memoized.cache = new memoize.Cache;
|
return memoized;
|
}
|
|
/**
|
* Creates a function that runs each argument through a corresponding
|
* transform function.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to wrap.
|
* @param {...(Function|Function[])} [transforms] The functions to transform
|
* arguments, specified as individual functions or arrays of functions.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* function doubled(n) {
|
* return n * 2;
|
* }
|
*
|
* function square(n) {
|
* return n * n;
|
* }
|
*
|
* var modded = _.modArgs(function(x, y) {
|
* return [x, y];
|
* }, square, doubled);
|
*
|
* modded(1, 2);
|
* // => [1, 4]
|
*
|
* modded(5, 10);
|
* // => [25, 20]
|
*/
|
var modArgs = restParam(function(func, transforms) {
|
transforms = baseFlatten(transforms);
|
if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
var length = transforms.length;
|
return restParam(function(args) {
|
var index = nativeMin(args.length, length);
|
while (index--) {
|
args[index] = transforms[index](args[index]);
|
}
|
return func.apply(this, args);
|
});
|
});
|
|
/**
|
* Creates a function that negates the result of the predicate `func`. The
|
* `func` predicate is invoked with the `this` binding and arguments of the
|
* created function.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} predicate The predicate to negate.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* function isEven(n) {
|
* return n % 2 == 0;
|
* }
|
*
|
* _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
|
* // => [1, 3, 5]
|
*/
|
function negate(predicate) {
|
if (typeof predicate != 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
return function() {
|
return !predicate.apply(this, arguments);
|
};
|
}
|
|
/**
|
* Creates a function that is restricted to invoking `func` once. Repeat calls
|
* to the function return the value of the first call. The `func` is invoked
|
* with the `this` binding and arguments of the created function.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to restrict.
|
* @returns {Function} Returns the new restricted function.
|
* @example
|
*
|
* var initialize = _.once(createApplication);
|
* initialize();
|
* initialize();
|
* // `initialize` invokes `createApplication` once
|
*/
|
function once(func) {
|
return before(2, func);
|
}
|
|
/**
|
* Creates a function that invokes `func` with `partial` arguments prepended
|
* to those provided to the new function. This method is like `_.bind` except
|
* it does **not** alter the `this` binding.
|
*
|
* The `_.partial.placeholder` value, which defaults to `_` in monolithic
|
* builds, may be used as a placeholder for partially applied arguments.
|
*
|
* **Note:** This method does not set the "length" property of partially
|
* applied functions.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to partially apply arguments to.
|
* @param {...*} [partials] The arguments to be partially applied.
|
* @returns {Function} Returns the new partially applied function.
|
* @example
|
*
|
* var greet = function(greeting, name) {
|
* return greeting + ' ' + name;
|
* };
|
*
|
* var sayHelloTo = _.partial(greet, 'hello');
|
* sayHelloTo('fred');
|
* // => 'hello fred'
|
*
|
* // using placeholders
|
* var greetFred = _.partial(greet, _, 'fred');
|
* greetFred('hi');
|
* // => 'hi fred'
|
*/
|
var partial = createPartial(PARTIAL_FLAG);
|
|
/**
|
* This method is like `_.partial` except that partially applied arguments
|
* are appended to those provided to the new function.
|
*
|
* The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
|
* builds, may be used as a placeholder for partially applied arguments.
|
*
|
* **Note:** This method does not set the "length" property of partially
|
* applied functions.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to partially apply arguments to.
|
* @param {...*} [partials] The arguments to be partially applied.
|
* @returns {Function} Returns the new partially applied function.
|
* @example
|
*
|
* var greet = function(greeting, name) {
|
* return greeting + ' ' + name;
|
* };
|
*
|
* var greetFred = _.partialRight(greet, 'fred');
|
* greetFred('hi');
|
* // => 'hi fred'
|
*
|
* // using placeholders
|
* var sayHelloTo = _.partialRight(greet, 'hello', _);
|
* sayHelloTo('fred');
|
* // => 'hello fred'
|
*/
|
var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
|
|
/**
|
* Creates a function that invokes `func` with arguments arranged according
|
* to the specified indexes where the argument value at the first index is
|
* provided as the first argument, the argument value at the second index is
|
* provided as the second argument, and so on.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to rearrange arguments for.
|
* @param {...(number|number[])} indexes The arranged argument indexes,
|
* specified as individual indexes or arrays of indexes.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var rearged = _.rearg(function(a, b, c) {
|
* return [a, b, c];
|
* }, 2, 0, 1);
|
*
|
* rearged('b', 'c', 'a')
|
* // => ['a', 'b', 'c']
|
*
|
* var map = _.rearg(_.map, [1, 0]);
|
* map(function(n) {
|
* return n * 3;
|
* }, [1, 2, 3]);
|
* // => [3, 6, 9]
|
*/
|
var rearg = restParam(function(func, indexes) {
|
return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
|
});
|
|
/**
|
* Creates a function that invokes `func` with the `this` binding of the
|
* created function and arguments from `start` and beyond provided as an array.
|
*
|
* **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters).
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to apply a rest parameter to.
|
* @param {number} [start=func.length-1] The start position of the rest parameter.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var say = _.restParam(function(what, names) {
|
* return what + ' ' + _.initial(names).join(', ') +
|
* (_.size(names) > 1 ? ', & ' : '') + _.last(names);
|
* });
|
*
|
* say('hello', 'fred', 'barney', 'pebbles');
|
* // => 'hello fred, barney, & pebbles'
|
*/
|
function restParam(func, start) {
|
if (typeof func != 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
|
return function() {
|
var args = arguments,
|
index = -1,
|
length = nativeMax(args.length - start, 0),
|
rest = Array(length);
|
|
while (++index < length) {
|
rest[index] = args[start + index];
|
}
|
switch (start) {
|
case 0: return func.call(this, rest);
|
case 1: return func.call(this, args[0], rest);
|
case 2: return func.call(this, args[0], args[1], rest);
|
}
|
var otherArgs = Array(start + 1);
|
index = -1;
|
while (++index < start) {
|
otherArgs[index] = args[index];
|
}
|
otherArgs[start] = rest;
|
return func.apply(this, otherArgs);
|
};
|
}
|
|
/**
|
* Creates a function that invokes `func` with the `this` binding of the created
|
* function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
|
*
|
* **Note:** This method is based on the [spread operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator).
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to spread arguments over.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var say = _.spread(function(who, what) {
|
* return who + ' says ' + what;
|
* });
|
*
|
* say(['fred', 'hello']);
|
* // => 'fred says hello'
|
*
|
* // with a Promise
|
* var numbers = Promise.all([
|
* Promise.resolve(40),
|
* Promise.resolve(36)
|
* ]);
|
*
|
* numbers.then(_.spread(function(x, y) {
|
* return x + y;
|
* }));
|
* // => a Promise of 76
|
*/
|
function spread(func) {
|
if (typeof func != 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
return function(array) {
|
return func.apply(this, array);
|
};
|
}
|
|
/**
|
* Creates a throttled function that only invokes `func` at most once per
|
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
* method to cancel delayed invocations. Provide an options object to indicate
|
* that `func` should be invoked on the leading and/or trailing edge of the
|
* `wait` timeout. Subsequent calls to the throttled function return the
|
* result of the last `func` call.
|
*
|
* **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
|
* on the trailing edge of the timeout only if the the throttled function is
|
* invoked more than once during the `wait` timeout.
|
*
|
* See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
|
* for details over the differences between `_.throttle` and `_.debounce`.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {Function} func The function to throttle.
|
* @param {number} [wait=0] The number of milliseconds to throttle invocations to.
|
* @param {Object} [options] The options object.
|
* @param {boolean} [options.leading=true] Specify invoking on the leading
|
* edge of the timeout.
|
* @param {boolean} [options.trailing=true] Specify invoking on the trailing
|
* edge of the timeout.
|
* @returns {Function} Returns the new throttled function.
|
* @example
|
*
|
* // avoid excessively updating the position while scrolling
|
* jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
*
|
* // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
|
* jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
|
* 'trailing': false
|
* }));
|
*
|
* // cancel a trailing throttled call
|
* jQuery(window).on('popstate', throttled.cancel);
|
*/
|
function throttle(func, wait, options) {
|
var leading = true,
|
trailing = true;
|
|
if (typeof func != 'function') {
|
throw new TypeError(FUNC_ERROR_TEXT);
|
}
|
if (options === false) {
|
leading = false;
|
} else if (isObject(options)) {
|
leading = 'leading' in options ? !!options.leading : leading;
|
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
}
|
return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
|
}
|
|
/**
|
* Creates a function that provides `value` to the wrapper function as its
|
* first argument. Any additional arguments provided to the function are
|
* appended to those provided to the wrapper function. The wrapper is invoked
|
* with the `this` binding of the created function.
|
*
|
* @static
|
* @memberOf _
|
* @category Function
|
* @param {*} value The value to wrap.
|
* @param {Function} wrapper The wrapper function.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var p = _.wrap(_.escape, function(func, text) {
|
* return '<p>' + func(text) + '</p>';
|
* });
|
*
|
* p('fred, barney, & pebbles');
|
* // => '<p>fred, barney, & pebbles</p>'
|
*/
|
function wrap(value, wrapper) {
|
wrapper = wrapper == null ? identity : wrapper;
|
return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
|
* otherwise they are assigned by reference. If `customizer` is provided it is
|
* invoked to produce the cloned values. If `customizer` returns `undefined`
|
* cloning is handled by the method instead. The `customizer` is bound to
|
* `thisArg` and invoked with two argument; (value [, index|key, object]).
|
*
|
* **Note:** This method is loosely based on the
|
* [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
|
* The enumerable properties of `arguments` objects and objects created by
|
* constructors other than `Object` are cloned to plain `Object` objects. An
|
* empty object is returned for uncloneable values such as functions, DOM nodes,
|
* Maps, Sets, and WeakMaps.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to clone.
|
* @param {boolean} [isDeep] Specify a deep clone.
|
* @param {Function} [customizer] The function to customize cloning values.
|
* @param {*} [thisArg] The `this` binding of `customizer`.
|
* @returns {*} Returns the cloned value.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney' },
|
* { 'user': 'fred' }
|
* ];
|
*
|
* var shallow = _.clone(users);
|
* shallow[0] === users[0];
|
* // => true
|
*
|
* var deep = _.clone(users, true);
|
* deep[0] === users[0];
|
* // => false
|
*
|
* // using a customizer callback
|
* var el = _.clone(document.body, function(value) {
|
* if (_.isElement(value)) {
|
* return value.cloneNode(false);
|
* }
|
* });
|
*
|
* el === document.body
|
* // => false
|
* el.nodeName
|
* // => BODY
|
* el.childNodes.length;
|
* // => 0
|
*/
|
function clone(value, isDeep, customizer, thisArg) {
|
if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
|
isDeep = false;
|
}
|
else if (typeof isDeep == 'function') {
|
thisArg = customizer;
|
customizer = isDeep;
|
isDeep = false;
|
}
|
return typeof customizer == 'function'
|
? baseClone(value, isDeep, bindCallback(customizer, thisArg, 1))
|
: baseClone(value, isDeep);
|
}
|
|
/**
|
* Creates a deep clone of `value`. If `customizer` is provided it is invoked
|
* to produce the cloned values. If `customizer` returns `undefined` cloning
|
* is handled by the method instead. The `customizer` is bound to `thisArg`
|
* and invoked with two argument; (value [, index|key, object]).
|
*
|
* **Note:** This method is loosely based on the
|
* [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
|
* The enumerable properties of `arguments` objects and objects created by
|
* constructors other than `Object` are cloned to plain `Object` objects. An
|
* empty object is returned for uncloneable values such as functions, DOM nodes,
|
* Maps, Sets, and WeakMaps.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to deep clone.
|
* @param {Function} [customizer] The function to customize cloning values.
|
* @param {*} [thisArg] The `this` binding of `customizer`.
|
* @returns {*} Returns the deep cloned value.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney' },
|
* { 'user': 'fred' }
|
* ];
|
*
|
* var deep = _.cloneDeep(users);
|
* deep[0] === users[0];
|
* // => false
|
*
|
* // using a customizer callback
|
* var el = _.cloneDeep(document.body, function(value) {
|
* if (_.isElement(value)) {
|
* return value.cloneNode(true);
|
* }
|
* });
|
*
|
* el === document.body
|
* // => false
|
* el.nodeName
|
* // => BODY
|
* el.childNodes.length;
|
* // => 20
|
*/
|
function cloneDeep(value, customizer, thisArg) {
|
return typeof customizer == 'function'
|
? baseClone(value, true, bindCallback(customizer, thisArg, 1))
|
: baseClone(value, true);
|
}
|
|
/**
|
* Checks if `value` is greater than `other`.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to compare.
|
* @param {*} other The other value to compare.
|
* @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
|
* @example
|
*
|
* _.gt(3, 1);
|
* // => true
|
*
|
* _.gt(3, 3);
|
* // => false
|
*
|
* _.gt(1, 3);
|
* // => false
|
*/
|
function gt(value, other) {
|
return value > other;
|
}
|
|
/**
|
* Checks if `value` is greater than or equal to `other`.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to compare.
|
* @param {*} other The other value to compare.
|
* @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
|
* @example
|
*
|
* _.gte(3, 1);
|
* // => true
|
*
|
* _.gte(3, 3);
|
* // => true
|
*
|
* _.gte(1, 3);
|
* // => false
|
*/
|
function gte(value, other) {
|
return value >= other;
|
}
|
|
/**
|
* Checks if `value` is classified as an `arguments` object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isArguments(function() { return arguments; }());
|
* // => true
|
*
|
* _.isArguments([1, 2, 3]);
|
* // => false
|
*/
|
function isArguments(value) {
|
return isObjectLike(value) && isArrayLike(value) &&
|
hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
|
}
|
|
/**
|
* Checks if `value` is classified as an `Array` object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isArray([1, 2, 3]);
|
* // => true
|
*
|
* _.isArray(function() { return arguments; }());
|
* // => false
|
*/
|
var isArray = nativeIsArray || function(value) {
|
return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
|
};
|
|
/**
|
* Checks if `value` is classified as a boolean primitive or object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isBoolean(false);
|
* // => true
|
*
|
* _.isBoolean(null);
|
* // => false
|
*/
|
function isBoolean(value) {
|
return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
|
}
|
|
/**
|
* Checks if `value` is classified as a `Date` object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isDate(new Date);
|
* // => true
|
*
|
* _.isDate('Mon April 23 2012');
|
* // => false
|
*/
|
function isDate(value) {
|
return isObjectLike(value) && objToString.call(value) == dateTag;
|
}
|
|
/**
|
* Checks if `value` is a DOM element.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
|
* @example
|
*
|
* _.isElement(document.body);
|
* // => true
|
*
|
* _.isElement('<body>');
|
* // => false
|
*/
|
function isElement(value) {
|
return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
|
}
|
|
/**
|
* Checks if `value` is empty. A value is considered empty unless it is an
|
* `arguments` object, array, string, or jQuery-like collection with a length
|
* greater than `0` or an object with own enumerable properties.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {Array|Object|string} value The value to inspect.
|
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
|
* @example
|
*
|
* _.isEmpty(null);
|
* // => true
|
*
|
* _.isEmpty(true);
|
* // => true
|
*
|
* _.isEmpty(1);
|
* // => true
|
*
|
* _.isEmpty([1, 2, 3]);
|
* // => false
|
*
|
* _.isEmpty({ 'a': 1 });
|
* // => false
|
*/
|
function isEmpty(value) {
|
if (value == null) {
|
return true;
|
}
|
if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
|
(isObjectLike(value) && isFunction(value.splice)))) {
|
return !value.length;
|
}
|
return !keys(value).length;
|
}
|
|
/**
|
* Performs a deep comparison between two values to determine if they are
|
* equivalent. If `customizer` is provided it is invoked to compare values.
|
* If `customizer` returns `undefined` comparisons are handled by the method
|
* instead. The `customizer` is bound to `thisArg` and invoked with three
|
* arguments: (value, other [, index|key]).
|
*
|
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
* numbers, `Object` objects, regexes, and strings. Objects are compared by
|
* their own, not inherited, enumerable properties. Functions and DOM nodes
|
* are **not** supported. Provide a customizer function to extend support
|
* for comparing other values.
|
*
|
* @static
|
* @memberOf _
|
* @alias eq
|
* @category Lang
|
* @param {*} value The value to compare.
|
* @param {*} other The other value to compare.
|
* @param {Function} [customizer] The function to customize value comparisons.
|
* @param {*} [thisArg] The `this` binding of `customizer`.
|
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
* @example
|
*
|
* var object = { 'user': 'fred' };
|
* var other = { 'user': 'fred' };
|
*
|
* object == other;
|
* // => false
|
*
|
* _.isEqual(object, other);
|
* // => true
|
*
|
* // using a customizer callback
|
* var array = ['hello', 'goodbye'];
|
* var other = ['hi', 'goodbye'];
|
*
|
* _.isEqual(array, other, function(value, other) {
|
* if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
|
* return true;
|
* }
|
* });
|
* // => true
|
*/
|
function isEqual(value, other, customizer, thisArg) {
|
customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
|
var result = customizer ? customizer(value, other) : undefined;
|
return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
|
}
|
|
/**
|
* Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
|
* `SyntaxError`, `TypeError`, or `URIError` object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is an error object, else `false`.
|
* @example
|
*
|
* _.isError(new Error);
|
* // => true
|
*
|
* _.isError(Error);
|
* // => false
|
*/
|
function isError(value) {
|
return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
|
}
|
|
/**
|
* Checks if `value` is a finite primitive number.
|
*
|
* **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
|
* @example
|
*
|
* _.isFinite(10);
|
* // => true
|
*
|
* _.isFinite('10');
|
* // => false
|
*
|
* _.isFinite(true);
|
* // => false
|
*
|
* _.isFinite(Object(10));
|
* // => false
|
*
|
* _.isFinite(Infinity);
|
* // => false
|
*/
|
function isFinite(value) {
|
return typeof value == 'number' && nativeIsFinite(value);
|
}
|
|
/**
|
* Checks if `value` is classified as a `Function` object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isFunction(_);
|
* // => true
|
*
|
* _.isFunction(/abc/);
|
* // => false
|
*/
|
function isFunction(value) {
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
// in older versions of Chrome and Safari which return 'function' for regexes
|
// and Safari 8 equivalents which return 'object' for typed array constructors.
|
return isObject(value) && objToString.call(value) == funcTag;
|
}
|
|
/**
|
* Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
|
* (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
* @example
|
*
|
* _.isObject({});
|
* // => true
|
*
|
* _.isObject([1, 2, 3]);
|
* // => true
|
*
|
* _.isObject(1);
|
* // => false
|
*/
|
function isObject(value) {
|
// Avoid a V8 JIT bug in Chrome 19-20.
|
// See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
|
var type = typeof value;
|
return !!value && (type == 'object' || type == 'function');
|
}
|
|
/**
|
* Performs a deep comparison between `object` and `source` to determine if
|
* `object` contains equivalent property values. If `customizer` is provided
|
* it is invoked to compare values. If `customizer` returns `undefined`
|
* comparisons are handled by the method instead. The `customizer` is bound
|
* to `thisArg` and invoked with three arguments: (value, other, index|key).
|
*
|
* **Note:** This method supports comparing properties of arrays, booleans,
|
* `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
|
* and DOM nodes are **not** supported. Provide a customizer function to extend
|
* support for comparing other values.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {Object} object The object to inspect.
|
* @param {Object} source The object of property values to match.
|
* @param {Function} [customizer] The function to customize value comparisons.
|
* @param {*} [thisArg] The `this` binding of `customizer`.
|
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
|
* @example
|
*
|
* var object = { 'user': 'fred', 'age': 40 };
|
*
|
* _.isMatch(object, { 'age': 40 });
|
* // => true
|
*
|
* _.isMatch(object, { 'age': 36 });
|
* // => false
|
*
|
* // using a customizer callback
|
* var object = { 'greeting': 'hello' };
|
* var source = { 'greeting': 'hi' };
|
*
|
* _.isMatch(object, source, function(value, other) {
|
* return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
|
* });
|
* // => true
|
*/
|
function isMatch(object, source, customizer, thisArg) {
|
customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
|
return baseIsMatch(object, getMatchData(source), customizer);
|
}
|
|
/**
|
* Checks if `value` is `NaN`.
|
*
|
* **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
|
* which returns `true` for `undefined` and other non-numeric values.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
|
* @example
|
*
|
* _.isNaN(NaN);
|
* // => true
|
*
|
* _.isNaN(new Number(NaN));
|
* // => true
|
*
|
* isNaN(undefined);
|
* // => true
|
*
|
* _.isNaN(undefined);
|
* // => false
|
*/
|
function isNaN(value) {
|
// An `NaN` primitive is the only value that is not equal to itself.
|
// Perform the `toStringTag` check first to avoid errors with some host objects in IE.
|
return isNumber(value) && value != +value;
|
}
|
|
/**
|
* Checks if `value` is a native function.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
|
* @example
|
*
|
* _.isNative(Array.prototype.push);
|
* // => true
|
*
|
* _.isNative(_);
|
* // => false
|
*/
|
function isNative(value) {
|
if (value == null) {
|
return false;
|
}
|
if (isFunction(value)) {
|
return reIsNative.test(fnToString.call(value));
|
}
|
return isObjectLike(value) && reIsHostCtor.test(value);
|
}
|
|
/**
|
* Checks if `value` is `null`.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is `null`, else `false`.
|
* @example
|
*
|
* _.isNull(null);
|
* // => true
|
*
|
* _.isNull(void 0);
|
* // => false
|
*/
|
function isNull(value) {
|
return value === null;
|
}
|
|
/**
|
* Checks if `value` is classified as a `Number` primitive or object.
|
*
|
* **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
|
* as numbers, use the `_.isFinite` method.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isNumber(8.4);
|
* // => true
|
*
|
* _.isNumber(NaN);
|
* // => true
|
*
|
* _.isNumber('8.4');
|
* // => false
|
*/
|
function isNumber(value) {
|
return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
|
}
|
|
/**
|
* Checks if `value` is a plain object, that is, an object created by the
|
* `Object` constructor or one with a `[[Prototype]]` of `null`.
|
*
|
* **Note:** This method assumes objects created by the `Object` constructor
|
* have no inherited enumerable properties.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* }
|
*
|
* _.isPlainObject(new Foo);
|
* // => false
|
*
|
* _.isPlainObject([1, 2, 3]);
|
* // => false
|
*
|
* _.isPlainObject({ 'x': 0, 'y': 0 });
|
* // => true
|
*
|
* _.isPlainObject(Object.create(null));
|
* // => true
|
*/
|
function isPlainObject(value) {
|
var Ctor;
|
|
// Exit early for non `Object` objects.
|
if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
|
(!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
|
return false;
|
}
|
// IE < 9 iterates inherited properties before own properties. If the first
|
// iterated property is an object's own property then there are no inherited
|
// enumerable properties.
|
var result;
|
// In most environments an object's own properties are iterated before
|
// its inherited properties. If the last iterated property is an object's
|
// own property then there are no inherited enumerable properties.
|
baseForIn(value, function(subValue, key) {
|
result = key;
|
});
|
return result === undefined || hasOwnProperty.call(value, result);
|
}
|
|
/**
|
* Checks if `value` is classified as a `RegExp` object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isRegExp(/abc/);
|
* // => true
|
*
|
* _.isRegExp('/abc/');
|
* // => false
|
*/
|
function isRegExp(value) {
|
return isObject(value) && objToString.call(value) == regexpTag;
|
}
|
|
/**
|
* Checks if `value` is classified as a `String` primitive or object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isString('abc');
|
* // => true
|
*
|
* _.isString(1);
|
* // => false
|
*/
|
function isString(value) {
|
return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
|
}
|
|
/**
|
* Checks if `value` is classified as a typed array.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
* @example
|
*
|
* _.isTypedArray(new Uint8Array);
|
* // => true
|
*
|
* _.isTypedArray([]);
|
* // => false
|
*/
|
function isTypedArray(value) {
|
return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
|
}
|
|
/**
|
* Checks if `value` is `undefined`.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to check.
|
* @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
|
* @example
|
*
|
* _.isUndefined(void 0);
|
* // => true
|
*
|
* _.isUndefined(null);
|
* // => false
|
*/
|
function isUndefined(value) {
|
return value === undefined;
|
}
|
|
/**
|
* Checks if `value` is less than `other`.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to compare.
|
* @param {*} other The other value to compare.
|
* @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
|
* @example
|
*
|
* _.lt(1, 3);
|
* // => true
|
*
|
* _.lt(3, 3);
|
* // => false
|
*
|
* _.lt(3, 1);
|
* // => false
|
*/
|
function lt(value, other) {
|
return value < other;
|
}
|
|
/**
|
* Checks if `value` is less than or equal to `other`.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to compare.
|
* @param {*} other The other value to compare.
|
* @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
|
* @example
|
*
|
* _.lte(1, 3);
|
* // => true
|
*
|
* _.lte(3, 3);
|
* // => true
|
*
|
* _.lte(3, 1);
|
* // => false
|
*/
|
function lte(value, other) {
|
return value <= other;
|
}
|
|
/**
|
* Converts `value` to an array.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to convert.
|
* @returns {Array} Returns the converted array.
|
* @example
|
*
|
* (function() {
|
* return _.toArray(arguments).slice(1);
|
* }(1, 2, 3));
|
* // => [2, 3]
|
*/
|
function toArray(value) {
|
var length = value ? getLength(value) : 0;
|
if (!isLength(length)) {
|
return values(value);
|
}
|
if (!length) {
|
return [];
|
}
|
return arrayCopy(value);
|
}
|
|
/**
|
* Converts `value` to a plain object flattening inherited enumerable
|
* properties of `value` to own properties of the plain object.
|
*
|
* @static
|
* @memberOf _
|
* @category Lang
|
* @param {*} value The value to convert.
|
* @returns {Object} Returns the converted plain object.
|
* @example
|
*
|
* function Foo() {
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.assign({ 'a': 1 }, new Foo);
|
* // => { 'a': 1, 'b': 2 }
|
*
|
* _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
|
* // => { 'a': 1, 'b': 2, 'c': 3 }
|
*/
|
function toPlainObject(value) {
|
return baseCopy(value, keysIn(value));
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Recursively merges own enumerable properties of the source object(s), that
|
* don't resolve to `undefined` into the destination object. Subsequent sources
|
* overwrite property assignments of previous sources. If `customizer` is
|
* provided it is invoked to produce the merged values of the destination and
|
* source properties. If `customizer` returns `undefined` merging is handled
|
* by the method instead. The `customizer` is bound to `thisArg` and invoked
|
* with five arguments: (objectValue, sourceValue, key, object, source).
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The destination object.
|
* @param {...Object} [sources] The source objects.
|
* @param {Function} [customizer] The function to customize assigned values.
|
* @param {*} [thisArg] The `this` binding of `customizer`.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* var users = {
|
* 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
|
* };
|
*
|
* var ages = {
|
* 'data': [{ 'age': 36 }, { 'age': 40 }]
|
* };
|
*
|
* _.merge(users, ages);
|
* // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
|
*
|
* // using a customizer callback
|
* var object = {
|
* 'fruits': ['apple'],
|
* 'vegetables': ['beet']
|
* };
|
*
|
* var other = {
|
* 'fruits': ['banana'],
|
* 'vegetables': ['carrot']
|
* };
|
*
|
* _.merge(object, other, function(a, b) {
|
* if (_.isArray(a)) {
|
* return a.concat(b);
|
* }
|
* });
|
* // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
|
*/
|
var merge = createAssigner(baseMerge);
|
|
/**
|
* Assigns own enumerable properties of source object(s) to the destination
|
* object. Subsequent sources overwrite property assignments of previous sources.
|
* If `customizer` is provided it is invoked to produce the assigned values.
|
* The `customizer` is bound to `thisArg` and invoked with five arguments:
|
* (objectValue, sourceValue, key, object, source).
|
*
|
* **Note:** This method mutates `object` and is based on
|
* [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
|
*
|
* @static
|
* @memberOf _
|
* @alias extend
|
* @category Object
|
* @param {Object} object The destination object.
|
* @param {...Object} [sources] The source objects.
|
* @param {Function} [customizer] The function to customize assigned values.
|
* @param {*} [thisArg] The `this` binding of `customizer`.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
|
* // => { 'user': 'fred', 'age': 40 }
|
*
|
* // using a customizer callback
|
* var defaults = _.partialRight(_.assign, function(value, other) {
|
* return _.isUndefined(value) ? other : value;
|
* });
|
*
|
* defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
|
* // => { 'user': 'barney', 'age': 36 }
|
*/
|
var assign = createAssigner(function(object, source, customizer) {
|
return customizer
|
? assignWith(object, source, customizer)
|
: baseAssign(object, source);
|
});
|
|
/**
|
* Creates an object that inherits from the given `prototype` object. If a
|
* `properties` object is provided its own enumerable properties are assigned
|
* to the created object.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} prototype The object to inherit from.
|
* @param {Object} [properties] The properties to assign to the object.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Object} Returns the new object.
|
* @example
|
*
|
* function Shape() {
|
* this.x = 0;
|
* this.y = 0;
|
* }
|
*
|
* function Circle() {
|
* Shape.call(this);
|
* }
|
*
|
* Circle.prototype = _.create(Shape.prototype, {
|
* 'constructor': Circle
|
* });
|
*
|
* var circle = new Circle;
|
* circle instanceof Circle;
|
* // => true
|
*
|
* circle instanceof Shape;
|
* // => true
|
*/
|
function create(prototype, properties, guard) {
|
var result = baseCreate(prototype);
|
if (guard && isIterateeCall(prototype, properties, guard)) {
|
properties = undefined;
|
}
|
return properties ? baseAssign(result, properties) : result;
|
}
|
|
/**
|
* Assigns own enumerable properties of source object(s) to the destination
|
* object for all destination properties that resolve to `undefined`. Once a
|
* property is set, additional values of the same property are ignored.
|
*
|
* **Note:** This method mutates `object`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The destination object.
|
* @param {...Object} [sources] The source objects.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
|
* // => { 'user': 'barney', 'age': 36 }
|
*/
|
var defaults = createDefaults(assign, assignDefaults);
|
|
/**
|
* This method is like `_.defaults` except that it recursively assigns
|
* default properties.
|
*
|
* **Note:** This method mutates `object`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The destination object.
|
* @param {...Object} [sources] The source objects.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
|
* // => { 'user': { 'name': 'barney', 'age': 36 } }
|
*
|
*/
|
var defaultsDeep = createDefaults(merge, mergeDefaults);
|
|
/**
|
* This method is like `_.find` except that it returns the key of the first
|
* element `predicate` returns truthy for instead of the element itself.
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to search.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {string|undefined} Returns the key of the matched element, else `undefined`.
|
* @example
|
*
|
* var users = {
|
* 'barney': { 'age': 36, 'active': true },
|
* 'fred': { 'age': 40, 'active': false },
|
* 'pebbles': { 'age': 1, 'active': true }
|
* };
|
*
|
* _.findKey(users, function(chr) {
|
* return chr.age < 40;
|
* });
|
* // => 'barney' (iteration order is not guaranteed)
|
*
|
* // using the `_.matches` callback shorthand
|
* _.findKey(users, { 'age': 1, 'active': true });
|
* // => 'pebbles'
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.findKey(users, 'active', false);
|
* // => 'fred'
|
*
|
* // using the `_.property` callback shorthand
|
* _.findKey(users, 'active');
|
* // => 'barney'
|
*/
|
var findKey = createFindKey(baseForOwn);
|
|
/**
|
* This method is like `_.findKey` except that it iterates over elements of
|
* a collection in the opposite order.
|
*
|
* If a property name is provided for `predicate` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `predicate` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to search.
|
* @param {Function|Object|string} [predicate=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {string|undefined} Returns the key of the matched element, else `undefined`.
|
* @example
|
*
|
* var users = {
|
* 'barney': { 'age': 36, 'active': true },
|
* 'fred': { 'age': 40, 'active': false },
|
* 'pebbles': { 'age': 1, 'active': true }
|
* };
|
*
|
* _.findLastKey(users, function(chr) {
|
* return chr.age < 40;
|
* });
|
* // => returns `pebbles` assuming `_.findKey` returns `barney`
|
*
|
* // using the `_.matches` callback shorthand
|
* _.findLastKey(users, { 'age': 36, 'active': true });
|
* // => 'barney'
|
*
|
* // using the `_.matchesProperty` callback shorthand
|
* _.findLastKey(users, 'active', false);
|
* // => 'fred'
|
*
|
* // using the `_.property` callback shorthand
|
* _.findLastKey(users, 'active');
|
* // => 'pebbles'
|
*/
|
var findLastKey = createFindKey(baseForOwnRight);
|
|
/**
|
* Iterates over own and inherited enumerable properties of an object invoking
|
* `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
|
* with three arguments: (value, key, object). Iteratee functions may exit
|
* iteration early by explicitly returning `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.forIn(new Foo, function(value, key) {
|
* console.log(key);
|
* });
|
* // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
|
*/
|
var forIn = createForIn(baseFor);
|
|
/**
|
* This method is like `_.forIn` except that it iterates over properties of
|
* `object` in the opposite order.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.forInRight(new Foo, function(value, key) {
|
* console.log(key);
|
* });
|
* // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
|
*/
|
var forInRight = createForIn(baseForRight);
|
|
/**
|
* Iterates over own enumerable properties of an object invoking `iteratee`
|
* for each property. The `iteratee` is bound to `thisArg` and invoked with
|
* three arguments: (value, key, object). Iteratee functions may exit iteration
|
* early by explicitly returning `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.forOwn(new Foo, function(value, key) {
|
* console.log(key);
|
* });
|
* // => logs 'a' and 'b' (iteration order is not guaranteed)
|
*/
|
var forOwn = createForOwn(baseForOwn);
|
|
/**
|
* This method is like `_.forOwn` except that it iterates over properties of
|
* `object` in the opposite order.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.forOwnRight(new Foo, function(value, key) {
|
* console.log(key);
|
* });
|
* // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
|
*/
|
var forOwnRight = createForOwn(baseForOwnRight);
|
|
/**
|
* Creates an array of function property names from all enumerable properties,
|
* own and inherited, of `object`.
|
*
|
* @static
|
* @memberOf _
|
* @alias methods
|
* @category Object
|
* @param {Object} object The object to inspect.
|
* @returns {Array} Returns the new array of property names.
|
* @example
|
*
|
* _.functions(_);
|
* // => ['after', 'ary', 'assign', ...]
|
*/
|
function functions(object) {
|
return baseFunctions(object, keysIn(object));
|
}
|
|
/**
|
* Gets the property value at `path` of `object`. If the resolved value is
|
* `undefined` the `defaultValue` is used in its place.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to query.
|
* @param {Array|string} path The path of the property to get.
|
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
|
* @returns {*} Returns the resolved value.
|
* @example
|
*
|
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
*
|
* _.get(object, 'a[0].b.c');
|
* // => 3
|
*
|
* _.get(object, ['a', '0', 'b', 'c']);
|
* // => 3
|
*
|
* _.get(object, 'a.b.c', 'default');
|
* // => 'default'
|
*/
|
function get(object, path, defaultValue) {
|
var result = object == null ? undefined : baseGet(object, toPath(path), path + '');
|
return result === undefined ? defaultValue : result;
|
}
|
|
/**
|
* Checks if `path` is a direct property.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to query.
|
* @param {Array|string} path The path to check.
|
* @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
|
* @example
|
*
|
* var object = { 'a': { 'b': { 'c': 3 } } };
|
*
|
* _.has(object, 'a');
|
* // => true
|
*
|
* _.has(object, 'a.b.c');
|
* // => true
|
*
|
* _.has(object, ['a', 'b', 'c']);
|
* // => true
|
*/
|
function has(object, path) {
|
if (object == null) {
|
return false;
|
}
|
var result = hasOwnProperty.call(object, path);
|
if (!result && !isKey(path)) {
|
path = toPath(path);
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
if (object == null) {
|
return false;
|
}
|
path = last(path);
|
result = hasOwnProperty.call(object, path);
|
}
|
return result || (isLength(object.length) && isIndex(path, object.length) &&
|
(isArray(object) || isArguments(object)));
|
}
|
|
/**
|
* Creates an object composed of the inverted keys and values of `object`.
|
* If `object` contains duplicate values, subsequent values overwrite property
|
* assignments of previous values unless `multiValue` is `true`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to invert.
|
* @param {boolean} [multiValue] Allow multiple values per key.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Object} Returns the new inverted object.
|
* @example
|
*
|
* var object = { 'a': 1, 'b': 2, 'c': 1 };
|
*
|
* _.invert(object);
|
* // => { '1': 'c', '2': 'b' }
|
*
|
* // with `multiValue`
|
* _.invert(object, true);
|
* // => { '1': ['a', 'c'], '2': ['b'] }
|
*/
|
function invert(object, multiValue, guard) {
|
if (guard && isIterateeCall(object, multiValue, guard)) {
|
multiValue = undefined;
|
}
|
var index = -1,
|
props = keys(object),
|
length = props.length,
|
result = {};
|
|
while (++index < length) {
|
var key = props[index],
|
value = object[key];
|
|
if (multiValue) {
|
if (hasOwnProperty.call(result, value)) {
|
result[value].push(key);
|
} else {
|
result[value] = [key];
|
}
|
}
|
else {
|
result[value] = key;
|
}
|
}
|
return result;
|
}
|
|
/**
|
* Creates an array of the own enumerable property names of `object`.
|
*
|
* **Note:** Non-object values are coerced to objects. See the
|
* [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
|
* for more details.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to query.
|
* @returns {Array} Returns the array of property names.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.keys(new Foo);
|
* // => ['a', 'b'] (iteration order is not guaranteed)
|
*
|
* _.keys('hi');
|
* // => ['0', '1']
|
*/
|
var keys = !nativeKeys ? shimKeys : function(object) {
|
var Ctor = object == null ? undefined : object.constructor;
|
if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
|
(typeof object != 'function' && isArrayLike(object))) {
|
return shimKeys(object);
|
}
|
return isObject(object) ? nativeKeys(object) : [];
|
};
|
|
/**
|
* Creates an array of the own and inherited enumerable property names of `object`.
|
*
|
* **Note:** Non-object values are coerced to objects.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to query.
|
* @returns {Array} Returns the array of property names.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.keysIn(new Foo);
|
* // => ['a', 'b', 'c'] (iteration order is not guaranteed)
|
*/
|
function keysIn(object) {
|
if (object == null) {
|
return [];
|
}
|
if (!isObject(object)) {
|
object = Object(object);
|
}
|
var length = object.length;
|
length = (length && isLength(length) &&
|
(isArray(object) || isArguments(object)) && length) || 0;
|
|
var Ctor = object.constructor,
|
index = -1,
|
isProto = typeof Ctor == 'function' && Ctor.prototype === object,
|
result = Array(length),
|
skipIndexes = length > 0;
|
|
while (++index < length) {
|
result[index] = (index + '');
|
}
|
for (var key in object) {
|
if (!(skipIndexes && isIndex(key, length)) &&
|
!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
|
result.push(key);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* The opposite of `_.mapValues`; this method creates an object with the
|
* same values as `object` and keys generated by running each own enumerable
|
* property of `object` through `iteratee`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to iterate over.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns the new mapped object.
|
* @example
|
*
|
* _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
|
* return key + value;
|
* });
|
* // => { 'a1': 1, 'b2': 2 }
|
*/
|
var mapKeys = createObjectMapper(true);
|
|
/**
|
* Creates an object with the same keys as `object` and values generated by
|
* running each own enumerable property of `object` through `iteratee`. The
|
* iteratee function is bound to `thisArg` and invoked with three arguments:
|
* (value, key, object).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to iterate over.
|
* @param {Function|Object|string} [iteratee=_.identity] The function invoked
|
* per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Object} Returns the new mapped object.
|
* @example
|
*
|
* _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
|
* return n * 3;
|
* });
|
* // => { 'a': 3, 'b': 6 }
|
*
|
* var users = {
|
* 'fred': { 'user': 'fred', 'age': 40 },
|
* 'pebbles': { 'user': 'pebbles', 'age': 1 }
|
* };
|
*
|
* // using the `_.property` callback shorthand
|
* _.mapValues(users, 'age');
|
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
*/
|
var mapValues = createObjectMapper();
|
|
/**
|
* The opposite of `_.pick`; this method creates an object composed of the
|
* own and inherited enumerable properties of `object` that are not omitted.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The source object.
|
* @param {Function|...(string|string[])} [predicate] The function invoked per
|
* iteration or property names to omit, specified as individual property
|
* names or arrays of property names.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Object} Returns the new object.
|
* @example
|
*
|
* var object = { 'user': 'fred', 'age': 40 };
|
*
|
* _.omit(object, 'age');
|
* // => { 'user': 'fred' }
|
*
|
* _.omit(object, _.isNumber);
|
* // => { 'user': 'fred' }
|
*/
|
var omit = restParam(function(object, props) {
|
if (object == null) {
|
return {};
|
}
|
if (typeof props[0] != 'function') {
|
var props = arrayMap(baseFlatten(props), String);
|
return pickByArray(object, baseDifference(keysIn(object), props));
|
}
|
var predicate = bindCallback(props[0], props[1], 3);
|
return pickByCallback(object, function(value, key, object) {
|
return !predicate(value, key, object);
|
});
|
});
|
|
/**
|
* Creates a two dimensional array of the key-value pairs for `object`,
|
* e.g. `[[key1, value1], [key2, value2]]`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to query.
|
* @returns {Array} Returns the new array of key-value pairs.
|
* @example
|
*
|
* _.pairs({ 'barney': 36, 'fred': 40 });
|
* // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
|
*/
|
function pairs(object) {
|
object = toObject(object);
|
|
var index = -1,
|
props = keys(object),
|
length = props.length,
|
result = Array(length);
|
|
while (++index < length) {
|
var key = props[index];
|
result[index] = [key, object[key]];
|
}
|
return result;
|
}
|
|
/**
|
* Creates an object composed of the picked `object` properties. Property
|
* names may be specified as individual arguments or as arrays of property
|
* names. If `predicate` is provided it is invoked for each property of `object`
|
* picking the properties `predicate` returns truthy for. The predicate is
|
* bound to `thisArg` and invoked with three arguments: (value, key, object).
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The source object.
|
* @param {Function|...(string|string[])} [predicate] The function invoked per
|
* iteration or property names to pick, specified as individual property
|
* names or arrays of property names.
|
* @param {*} [thisArg] The `this` binding of `predicate`.
|
* @returns {Object} Returns the new object.
|
* @example
|
*
|
* var object = { 'user': 'fred', 'age': 40 };
|
*
|
* _.pick(object, 'user');
|
* // => { 'user': 'fred' }
|
*
|
* _.pick(object, _.isString);
|
* // => { 'user': 'fred' }
|
*/
|
var pick = restParam(function(object, props) {
|
if (object == null) {
|
return {};
|
}
|
return typeof props[0] == 'function'
|
? pickByCallback(object, bindCallback(props[0], props[1], 3))
|
: pickByArray(object, baseFlatten(props));
|
});
|
|
/**
|
* This method is like `_.get` except that if the resolved value is a function
|
* it is invoked with the `this` binding of its parent object and its result
|
* is returned.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to query.
|
* @param {Array|string} path The path of the property to resolve.
|
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
|
* @returns {*} Returns the resolved value.
|
* @example
|
*
|
* var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
|
*
|
* _.result(object, 'a[0].b.c1');
|
* // => 3
|
*
|
* _.result(object, 'a[0].b.c2');
|
* // => 4
|
*
|
* _.result(object, 'a.b.c', 'default');
|
* // => 'default'
|
*
|
* _.result(object, 'a.b.c', _.constant('default'));
|
* // => 'default'
|
*/
|
function result(object, path, defaultValue) {
|
var result = object == null ? undefined : object[path];
|
if (result === undefined) {
|
if (object != null && !isKey(path, object)) {
|
path = toPath(path);
|
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
result = object == null ? undefined : object[last(path)];
|
}
|
result = result === undefined ? defaultValue : result;
|
}
|
return isFunction(result) ? result.call(object) : result;
|
}
|
|
/**
|
* Sets the property value of `path` on `object`. If a portion of `path`
|
* does not exist it is created.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to augment.
|
* @param {Array|string} path The path of the property to set.
|
* @param {*} value The value to set.
|
* @returns {Object} Returns `object`.
|
* @example
|
*
|
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
*
|
* _.set(object, 'a[0].b.c', 4);
|
* console.log(object.a[0].b.c);
|
* // => 4
|
*
|
* _.set(object, 'x[0].y.z', 5);
|
* console.log(object.x[0].y.z);
|
* // => 5
|
*/
|
function set(object, path, value) {
|
if (object == null) {
|
return object;
|
}
|
var pathKey = (path + '');
|
path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
|
|
var index = -1,
|
length = path.length,
|
lastIndex = length - 1,
|
nested = object;
|
|
while (nested != null && ++index < length) {
|
var key = path[index];
|
if (isObject(nested)) {
|
if (index == lastIndex) {
|
nested[key] = value;
|
} else if (nested[key] == null) {
|
nested[key] = isIndex(path[index + 1]) ? [] : {};
|
}
|
}
|
nested = nested[key];
|
}
|
return object;
|
}
|
|
/**
|
* An alternative to `_.reduce`; this method transforms `object` to a new
|
* `accumulator` object which is the result of running each of its own enumerable
|
* properties through `iteratee`, with each invocation potentially mutating
|
* the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
|
* with four arguments: (accumulator, value, key, object). Iteratee functions
|
* may exit iteration early by explicitly returning `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Array|Object} object The object to iterate over.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [accumulator] The custom accumulator value.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {*} Returns the accumulated value.
|
* @example
|
*
|
* _.transform([2, 3, 4], function(result, n) {
|
* result.push(n *= n);
|
* return n % 2 == 0;
|
* });
|
* // => [4, 9]
|
*
|
* _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
|
* result[key] = n * 3;
|
* });
|
* // => { 'a': 3, 'b': 6 }
|
*/
|
function transform(object, iteratee, accumulator, thisArg) {
|
var isArr = isArray(object) || isTypedArray(object);
|
iteratee = getCallback(iteratee, thisArg, 4);
|
|
if (accumulator == null) {
|
if (isArr || isObject(object)) {
|
var Ctor = object.constructor;
|
if (isArr) {
|
accumulator = isArray(object) ? new Ctor : [];
|
} else {
|
accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
|
}
|
} else {
|
accumulator = {};
|
}
|
}
|
(isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
|
return iteratee(accumulator, value, index, object);
|
});
|
return accumulator;
|
}
|
|
/**
|
* Creates an array of the own enumerable property values of `object`.
|
*
|
* **Note:** Non-object values are coerced to objects.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to query.
|
* @returns {Array} Returns the array of property values.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.values(new Foo);
|
* // => [1, 2] (iteration order is not guaranteed)
|
*
|
* _.values('hi');
|
* // => ['h', 'i']
|
*/
|
function values(object) {
|
return baseValues(object, keys(object));
|
}
|
|
/**
|
* Creates an array of the own and inherited enumerable property values
|
* of `object`.
|
*
|
* **Note:** Non-object values are coerced to objects.
|
*
|
* @static
|
* @memberOf _
|
* @category Object
|
* @param {Object} object The object to query.
|
* @returns {Array} Returns the array of property values.
|
* @example
|
*
|
* function Foo() {
|
* this.a = 1;
|
* this.b = 2;
|
* }
|
*
|
* Foo.prototype.c = 3;
|
*
|
* _.valuesIn(new Foo);
|
* // => [1, 2, 3] (iteration order is not guaranteed)
|
*/
|
function valuesIn(object) {
|
return baseValues(object, keysIn(object));
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Checks if `n` is between `start` and up to but not including, `end`. If
|
* `end` is not specified it is set to `start` with `start` then set to `0`.
|
*
|
* @static
|
* @memberOf _
|
* @category Number
|
* @param {number} n The number to check.
|
* @param {number} [start=0] The start of the range.
|
* @param {number} end The end of the range.
|
* @returns {boolean} Returns `true` if `n` is in the range, else `false`.
|
* @example
|
*
|
* _.inRange(3, 2, 4);
|
* // => true
|
*
|
* _.inRange(4, 8);
|
* // => true
|
*
|
* _.inRange(4, 2);
|
* // => false
|
*
|
* _.inRange(2, 2);
|
* // => false
|
*
|
* _.inRange(1.2, 2);
|
* // => true
|
*
|
* _.inRange(5.2, 4);
|
* // => false
|
*/
|
function inRange(value, start, end) {
|
start = +start || 0;
|
if (end === undefined) {
|
end = start;
|
start = 0;
|
} else {
|
end = +end || 0;
|
}
|
return value >= nativeMin(start, end) && value < nativeMax(start, end);
|
}
|
|
/**
|
* Produces a random number between `min` and `max` (inclusive). If only one
|
* argument is provided a number between `0` and the given number is returned.
|
* If `floating` is `true`, or either `min` or `max` are floats, a floating-point
|
* number is returned instead of an integer.
|
*
|
* @static
|
* @memberOf _
|
* @category Number
|
* @param {number} [min=0] The minimum possible value.
|
* @param {number} [max=1] The maximum possible value.
|
* @param {boolean} [floating] Specify returning a floating-point number.
|
* @returns {number} Returns the random number.
|
* @example
|
*
|
* _.random(0, 5);
|
* // => an integer between 0 and 5
|
*
|
* _.random(5);
|
* // => also an integer between 0 and 5
|
*
|
* _.random(5, true);
|
* // => a floating-point number between 0 and 5
|
*
|
* _.random(1.2, 5.2);
|
* // => a floating-point number between 1.2 and 5.2
|
*/
|
function random(min, max, floating) {
|
if (floating && isIterateeCall(min, max, floating)) {
|
max = floating = undefined;
|
}
|
var noMin = min == null,
|
noMax = max == null;
|
|
if (floating == null) {
|
if (noMax && typeof min == 'boolean') {
|
floating = min;
|
min = 1;
|
}
|
else if (typeof max == 'boolean') {
|
floating = max;
|
noMax = true;
|
}
|
}
|
if (noMin && noMax) {
|
max = 1;
|
noMax = false;
|
}
|
min = +min || 0;
|
if (noMax) {
|
max = min;
|
min = 0;
|
} else {
|
max = +max || 0;
|
}
|
if (floating || min % 1 || max % 1) {
|
var rand = nativeRandom();
|
return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
|
}
|
return baseRandom(min, max);
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to convert.
|
* @returns {string} Returns the camel cased string.
|
* @example
|
*
|
* _.camelCase('Foo Bar');
|
* // => 'fooBar'
|
*
|
* _.camelCase('--foo-bar');
|
* // => 'fooBar'
|
*
|
* _.camelCase('__foo_bar__');
|
* // => 'fooBar'
|
*/
|
var camelCase = createCompounder(function(result, word, index) {
|
word = word.toLowerCase();
|
return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
|
});
|
|
/**
|
* Capitalizes the first character of `string`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to capitalize.
|
* @returns {string} Returns the capitalized string.
|
* @example
|
*
|
* _.capitalize('fred');
|
* // => 'Fred'
|
*/
|
function capitalize(string) {
|
string = baseToString(string);
|
return string && (string.charAt(0).toUpperCase() + string.slice(1));
|
}
|
|
/**
|
* Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
|
* to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to deburr.
|
* @returns {string} Returns the deburred string.
|
* @example
|
*
|
* _.deburr('déjà vu');
|
* // => 'deja vu'
|
*/
|
function deburr(string) {
|
string = baseToString(string);
|
return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
|
}
|
|
/**
|
* Checks if `string` ends with the given target string.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to search.
|
* @param {string} [target] The string to search for.
|
* @param {number} [position=string.length] The position to search from.
|
* @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
|
* @example
|
*
|
* _.endsWith('abc', 'c');
|
* // => true
|
*
|
* _.endsWith('abc', 'b');
|
* // => false
|
*
|
* _.endsWith('abc', 'b', 2);
|
* // => true
|
*/
|
function endsWith(string, target, position) {
|
string = baseToString(string);
|
target = (target + '');
|
|
var length = string.length;
|
position = position === undefined
|
? length
|
: nativeMin(position < 0 ? 0 : (+position || 0), length);
|
|
position -= target.length;
|
return position >= 0 && string.indexOf(target, position) == position;
|
}
|
|
/**
|
* Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
|
* their corresponding HTML entities.
|
*
|
* **Note:** No other characters are escaped. To escape additional characters
|
* use a third-party library like [_he_](https://mths.be/he).
|
*
|
* Though the ">" character is escaped for symmetry, characters like
|
* ">" and "/" don't need escaping in HTML and have no special meaning
|
* unless they're part of a tag or unquoted attribute value.
|
* See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
|
* (under "semi-related fun fact") for more details.
|
*
|
* Backticks are escaped because in Internet Explorer < 9, they can break out
|
* of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
|
* [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
|
* [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
|
* for more details.
|
*
|
* When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
|
* to reduce XSS vectors.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to escape.
|
* @returns {string} Returns the escaped string.
|
* @example
|
*
|
* _.escape('fred, barney, & pebbles');
|
* // => 'fred, barney, & pebbles'
|
*/
|
function escape(string) {
|
// Reset `lastIndex` because in IE < 9 `String#replace` does not.
|
string = baseToString(string);
|
return (string && reHasUnescapedHtml.test(string))
|
? string.replace(reUnescapedHtml, escapeHtmlChar)
|
: string;
|
}
|
|
/**
|
* Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
|
* "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to escape.
|
* @returns {string} Returns the escaped string.
|
* @example
|
*
|
* _.escapeRegExp('[lodash](https://lodash.com/)');
|
* // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
|
*/
|
function escapeRegExp(string) {
|
string = baseToString(string);
|
return (string && reHasRegExpChars.test(string))
|
? string.replace(reRegExpChars, escapeRegExpChar)
|
: (string || '(?:)');
|
}
|
|
/**
|
* Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to convert.
|
* @returns {string} Returns the kebab cased string.
|
* @example
|
*
|
* _.kebabCase('Foo Bar');
|
* // => 'foo-bar'
|
*
|
* _.kebabCase('fooBar');
|
* // => 'foo-bar'
|
*
|
* _.kebabCase('__foo_bar__');
|
* // => 'foo-bar'
|
*/
|
var kebabCase = createCompounder(function(result, word, index) {
|
return result + (index ? '-' : '') + word.toLowerCase();
|
});
|
|
/**
|
* Pads `string` on the left and right sides if it's shorter than `length`.
|
* Padding characters are truncated if they can't be evenly divided by `length`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to pad.
|
* @param {number} [length=0] The padding length.
|
* @param {string} [chars=' '] The string used as padding.
|
* @returns {string} Returns the padded string.
|
* @example
|
*
|
* _.pad('abc', 8);
|
* // => ' abc '
|
*
|
* _.pad('abc', 8, '_-');
|
* // => '_-abc_-_'
|
*
|
* _.pad('abc', 3);
|
* // => 'abc'
|
*/
|
function pad(string, length, chars) {
|
string = baseToString(string);
|
length = +length;
|
|
var strLength = string.length;
|
if (strLength >= length || !nativeIsFinite(length)) {
|
return string;
|
}
|
var mid = (length - strLength) / 2,
|
leftLength = nativeFloor(mid),
|
rightLength = nativeCeil(mid);
|
|
chars = createPadding('', rightLength, chars);
|
return chars.slice(0, leftLength) + string + chars;
|
}
|
|
/**
|
* Pads `string` on the left side if it's shorter than `length`. Padding
|
* characters are truncated if they exceed `length`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to pad.
|
* @param {number} [length=0] The padding length.
|
* @param {string} [chars=' '] The string used as padding.
|
* @returns {string} Returns the padded string.
|
* @example
|
*
|
* _.padLeft('abc', 6);
|
* // => ' abc'
|
*
|
* _.padLeft('abc', 6, '_-');
|
* // => '_-_abc'
|
*
|
* _.padLeft('abc', 3);
|
* // => 'abc'
|
*/
|
var padLeft = createPadDir();
|
|
/**
|
* Pads `string` on the right side if it's shorter than `length`. Padding
|
* characters are truncated if they exceed `length`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to pad.
|
* @param {number} [length=0] The padding length.
|
* @param {string} [chars=' '] The string used as padding.
|
* @returns {string} Returns the padded string.
|
* @example
|
*
|
* _.padRight('abc', 6);
|
* // => 'abc '
|
*
|
* _.padRight('abc', 6, '_-');
|
* // => 'abc_-_'
|
*
|
* _.padRight('abc', 3);
|
* // => 'abc'
|
*/
|
var padRight = createPadDir(true);
|
|
/**
|
* Converts `string` to an integer of the specified radix. If `radix` is
|
* `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
|
* in which case a `radix` of `16` is used.
|
*
|
* **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
|
* of `parseInt`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} string The string to convert.
|
* @param {number} [radix] The radix to interpret `value` by.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {number} Returns the converted integer.
|
* @example
|
*
|
* _.parseInt('08');
|
* // => 8
|
*
|
* _.map(['6', '08', '10'], _.parseInt);
|
* // => [6, 8, 10]
|
*/
|
function parseInt(string, radix, guard) {
|
// Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
|
// Chrome fails to trim leading <BOM> whitespace characters.
|
// See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
|
if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
|
radix = 0;
|
} else if (radix) {
|
radix = +radix;
|
}
|
string = trim(string);
|
return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
|
}
|
|
/**
|
* Repeats the given string `n` times.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to repeat.
|
* @param {number} [n=0] The number of times to repeat the string.
|
* @returns {string} Returns the repeated string.
|
* @example
|
*
|
* _.repeat('*', 3);
|
* // => '***'
|
*
|
* _.repeat('abc', 2);
|
* // => 'abcabc'
|
*
|
* _.repeat('abc', 0);
|
* // => ''
|
*/
|
function repeat(string, n) {
|
var result = '';
|
string = baseToString(string);
|
n = +n;
|
if (n < 1 || !string || !nativeIsFinite(n)) {
|
return result;
|
}
|
// Leverage the exponentiation by squaring algorithm for a faster repeat.
|
// See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
|
do {
|
if (n % 2) {
|
result += string;
|
}
|
n = nativeFloor(n / 2);
|
string += string;
|
} while (n);
|
|
return result;
|
}
|
|
/**
|
* Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to convert.
|
* @returns {string} Returns the snake cased string.
|
* @example
|
*
|
* _.snakeCase('Foo Bar');
|
* // => 'foo_bar'
|
*
|
* _.snakeCase('fooBar');
|
* // => 'foo_bar'
|
*
|
* _.snakeCase('--foo-bar');
|
* // => 'foo_bar'
|
*/
|
var snakeCase = createCompounder(function(result, word, index) {
|
return result + (index ? '_' : '') + word.toLowerCase();
|
});
|
|
/**
|
* Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to convert.
|
* @returns {string} Returns the start cased string.
|
* @example
|
*
|
* _.startCase('--foo-bar');
|
* // => 'Foo Bar'
|
*
|
* _.startCase('fooBar');
|
* // => 'Foo Bar'
|
*
|
* _.startCase('__foo_bar__');
|
* // => 'Foo Bar'
|
*/
|
var startCase = createCompounder(function(result, word, index) {
|
return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
|
});
|
|
/**
|
* Checks if `string` starts with the given target string.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to search.
|
* @param {string} [target] The string to search for.
|
* @param {number} [position=0] The position to search from.
|
* @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
|
* @example
|
*
|
* _.startsWith('abc', 'a');
|
* // => true
|
*
|
* _.startsWith('abc', 'b');
|
* // => false
|
*
|
* _.startsWith('abc', 'b', 1);
|
* // => true
|
*/
|
function startsWith(string, target, position) {
|
string = baseToString(string);
|
position = position == null
|
? 0
|
: nativeMin(position < 0 ? 0 : (+position || 0), string.length);
|
|
return string.lastIndexOf(target, position) == position;
|
}
|
|
/**
|
* Creates a compiled template function that can interpolate data properties
|
* in "interpolate" delimiters, HTML-escape interpolated data properties in
|
* "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
|
* properties may be accessed as free variables in the template. If a setting
|
* object is provided it takes precedence over `_.templateSettings` values.
|
*
|
* **Note:** In the development build `_.template` utilizes
|
* [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
|
* for easier debugging.
|
*
|
* For more information on precompiling templates see
|
* [lodash's custom builds documentation](https://lodash.com/custom-builds).
|
*
|
* For more information on Chrome extension sandboxes see
|
* [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The template string.
|
* @param {Object} [options] The options object.
|
* @param {RegExp} [options.escape] The HTML "escape" delimiter.
|
* @param {RegExp} [options.evaluate] The "evaluate" delimiter.
|
* @param {Object} [options.imports] An object to import into the template as free variables.
|
* @param {RegExp} [options.interpolate] The "interpolate" delimiter.
|
* @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
|
* @param {string} [options.variable] The data object variable name.
|
* @param- {Object} [otherOptions] Enables the legacy `options` param signature.
|
* @returns {Function} Returns the compiled template function.
|
* @example
|
*
|
* // using the "interpolate" delimiter to create a compiled template
|
* var compiled = _.template('hello <%= user %>!');
|
* compiled({ 'user': 'fred' });
|
* // => 'hello fred!'
|
*
|
* // using the HTML "escape" delimiter to escape data property values
|
* var compiled = _.template('<b><%- value %></b>');
|
* compiled({ 'value': '<script>' });
|
* // => '<b><script></b>'
|
*
|
* // using the "evaluate" delimiter to execute JavaScript and generate HTML
|
* var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
|
* compiled({ 'users': ['fred', 'barney'] });
|
* // => '<li>fred</li><li>barney</li>'
|
*
|
* // using the internal `print` function in "evaluate" delimiters
|
* var compiled = _.template('<% print("hello " + user); %>!');
|
* compiled({ 'user': 'barney' });
|
* // => 'hello barney!'
|
*
|
* // using the ES delimiter as an alternative to the default "interpolate" delimiter
|
* var compiled = _.template('hello ${ user }!');
|
* compiled({ 'user': 'pebbles' });
|
* // => 'hello pebbles!'
|
*
|
* // using custom template delimiters
|
* _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
* var compiled = _.template('hello {{ user }}!');
|
* compiled({ 'user': 'mustache' });
|
* // => 'hello mustache!'
|
*
|
* // using backslashes to treat delimiters as plain text
|
* var compiled = _.template('<%= "\\<%- value %\\>" %>');
|
* compiled({ 'value': 'ignored' });
|
* // => '<%- value %>'
|
*
|
* // using the `imports` option to import `jQuery` as `jq`
|
* var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
|
* var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
|
* compiled({ 'users': ['fred', 'barney'] });
|
* // => '<li>fred</li><li>barney</li>'
|
*
|
* // using the `sourceURL` option to specify a custom sourceURL for the template
|
* var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
|
* compiled(data);
|
* // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
|
*
|
* // using the `variable` option to ensure a with-statement isn't used in the compiled template
|
* var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
|
* compiled.source;
|
* // => function(data) {
|
* // var __t, __p = '';
|
* // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
|
* // return __p;
|
* // }
|
*
|
* // using the `source` property to inline compiled templates for meaningful
|
* // line numbers in error messages and a stack trace
|
* fs.writeFileSync(path.join(cwd, 'jst.js'), '\
|
* var JST = {\
|
* "main": ' + _.template(mainText).source + '\
|
* };\
|
* ');
|
*/
|
function template(string, options, otherOptions) {
|
// Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
|
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
|
var settings = lodash.templateSettings;
|
|
if (otherOptions && isIterateeCall(string, options, otherOptions)) {
|
options = otherOptions = undefined;
|
}
|
string = baseToString(string);
|
options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
|
|
var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
|
importsKeys = keys(imports),
|
importsValues = baseValues(imports, importsKeys);
|
|
var isEscaping,
|
isEvaluating,
|
index = 0,
|
interpolate = options.interpolate || reNoMatch,
|
source = "__p += '";
|
|
// Compile the regexp to match each delimiter.
|
var reDelimiters = RegExp(
|
(options.escape || reNoMatch).source + '|' +
|
interpolate.source + '|' +
|
(interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
|
(options.evaluate || reNoMatch).source + '|$'
|
, 'g');
|
|
// Use a sourceURL for easier debugging.
|
var sourceURL = '//# sourceURL=' +
|
('sourceURL' in options
|
? options.sourceURL
|
: ('lodash.templateSources[' + (++templateCounter) + ']')
|
) + '\n';
|
|
string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
|
interpolateValue || (interpolateValue = esTemplateValue);
|
|
// Escape characters that can't be included in string literals.
|
source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
|
|
// Replace delimiters with snippets.
|
if (escapeValue) {
|
isEscaping = true;
|
source += "' +\n__e(" + escapeValue + ") +\n'";
|
}
|
if (evaluateValue) {
|
isEvaluating = true;
|
source += "';\n" + evaluateValue + ";\n__p += '";
|
}
|
if (interpolateValue) {
|
source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
|
}
|
index = offset + match.length;
|
|
// The JS engine embedded in Adobe products requires returning the `match`
|
// string in order to produce the correct `offset` value.
|
return match;
|
});
|
|
source += "';\n";
|
|
// If `variable` is not specified wrap a with-statement around the generated
|
// code to add the data object to the top of the scope chain.
|
var variable = options.variable;
|
if (!variable) {
|
source = 'with (obj) {\n' + source + '\n}\n';
|
}
|
// Cleanup code by stripping empty strings.
|
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
|
.replace(reEmptyStringMiddle, '$1')
|
.replace(reEmptyStringTrailing, '$1;');
|
|
// Frame code as the function body.
|
source = 'function(' + (variable || 'obj') + ') {\n' +
|
(variable
|
? ''
|
: 'obj || (obj = {});\n'
|
) +
|
"var __t, __p = ''" +
|
(isEscaping
|
? ', __e = _.escape'
|
: ''
|
) +
|
(isEvaluating
|
? ', __j = Array.prototype.join;\n' +
|
"function print() { __p += __j.call(arguments, '') }\n"
|
: ';\n'
|
) +
|
source +
|
'return __p\n}';
|
|
var result = attempt(function() {
|
return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
|
});
|
|
// Provide the compiled function's source by its `toString` method or
|
// the `source` property as a convenience for inlining compiled templates.
|
result.source = source;
|
if (isError(result)) {
|
throw result;
|
}
|
return result;
|
}
|
|
/**
|
* Removes leading and trailing whitespace or specified characters from `string`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to trim.
|
* @param {string} [chars=whitespace] The characters to trim.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {string} Returns the trimmed string.
|
* @example
|
*
|
* _.trim(' abc ');
|
* // => 'abc'
|
*
|
* _.trim('-_-abc-_-', '_-');
|
* // => 'abc'
|
*
|
* _.map([' foo ', ' bar '], _.trim);
|
* // => ['foo', 'bar']
|
*/
|
function trim(string, chars, guard) {
|
var value = string;
|
string = baseToString(string);
|
if (!string) {
|
return string;
|
}
|
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
|
return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
|
}
|
chars = (chars + '');
|
return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
|
}
|
|
/**
|
* Removes leading whitespace or specified characters from `string`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to trim.
|
* @param {string} [chars=whitespace] The characters to trim.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {string} Returns the trimmed string.
|
* @example
|
*
|
* _.trimLeft(' abc ');
|
* // => 'abc '
|
*
|
* _.trimLeft('-_-abc-_-', '_-');
|
* // => 'abc-_-'
|
*/
|
function trimLeft(string, chars, guard) {
|
var value = string;
|
string = baseToString(string);
|
if (!string) {
|
return string;
|
}
|
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
|
return string.slice(trimmedLeftIndex(string));
|
}
|
return string.slice(charsLeftIndex(string, (chars + '')));
|
}
|
|
/**
|
* Removes trailing whitespace or specified characters from `string`.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to trim.
|
* @param {string} [chars=whitespace] The characters to trim.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {string} Returns the trimmed string.
|
* @example
|
*
|
* _.trimRight(' abc ');
|
* // => ' abc'
|
*
|
* _.trimRight('-_-abc-_-', '_-');
|
* // => '-_-abc'
|
*/
|
function trimRight(string, chars, guard) {
|
var value = string;
|
string = baseToString(string);
|
if (!string) {
|
return string;
|
}
|
if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
|
return string.slice(0, trimmedRightIndex(string) + 1);
|
}
|
return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
|
}
|
|
/**
|
* Truncates `string` if it's longer than the given maximum string length.
|
* The last characters of the truncated string are replaced with the omission
|
* string which defaults to "...".
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to truncate.
|
* @param {Object|number} [options] The options object or maximum string length.
|
* @param {number} [options.length=30] The maximum string length.
|
* @param {string} [options.omission='...'] The string to indicate text is omitted.
|
* @param {RegExp|string} [options.separator] The separator pattern to truncate to.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {string} Returns the truncated string.
|
* @example
|
*
|
* _.trunc('hi-diddly-ho there, neighborino');
|
* // => 'hi-diddly-ho there, neighbo...'
|
*
|
* _.trunc('hi-diddly-ho there, neighborino', 24);
|
* // => 'hi-diddly-ho there, n...'
|
*
|
* _.trunc('hi-diddly-ho there, neighborino', {
|
* 'length': 24,
|
* 'separator': ' '
|
* });
|
* // => 'hi-diddly-ho there,...'
|
*
|
* _.trunc('hi-diddly-ho there, neighborino', {
|
* 'length': 24,
|
* 'separator': /,? +/
|
* });
|
* // => 'hi-diddly-ho there...'
|
*
|
* _.trunc('hi-diddly-ho there, neighborino', {
|
* 'omission': ' [...]'
|
* });
|
* // => 'hi-diddly-ho there, neig [...]'
|
*/
|
function trunc(string, options, guard) {
|
if (guard && isIterateeCall(string, options, guard)) {
|
options = undefined;
|
}
|
var length = DEFAULT_TRUNC_LENGTH,
|
omission = DEFAULT_TRUNC_OMISSION;
|
|
if (options != null) {
|
if (isObject(options)) {
|
var separator = 'separator' in options ? options.separator : separator;
|
length = 'length' in options ? (+options.length || 0) : length;
|
omission = 'omission' in options ? baseToString(options.omission) : omission;
|
} else {
|
length = +options || 0;
|
}
|
}
|
string = baseToString(string);
|
if (length >= string.length) {
|
return string;
|
}
|
var end = length - omission.length;
|
if (end < 1) {
|
return omission;
|
}
|
var result = string.slice(0, end);
|
if (separator == null) {
|
return result + omission;
|
}
|
if (isRegExp(separator)) {
|
if (string.slice(end).search(separator)) {
|
var match,
|
newEnd,
|
substring = string.slice(0, end);
|
|
if (!separator.global) {
|
separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
|
}
|
separator.lastIndex = 0;
|
while ((match = separator.exec(substring))) {
|
newEnd = match.index;
|
}
|
result = result.slice(0, newEnd == null ? end : newEnd);
|
}
|
} else if (string.indexOf(separator, end) != end) {
|
var index = result.lastIndexOf(separator);
|
if (index > -1) {
|
result = result.slice(0, index);
|
}
|
}
|
return result + omission;
|
}
|
|
/**
|
* The inverse of `_.escape`; this method converts the HTML entities
|
* `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
|
* corresponding characters.
|
*
|
* **Note:** No other HTML entities are unescaped. To unescape additional HTML
|
* entities use a third-party library like [_he_](https://mths.be/he).
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to unescape.
|
* @returns {string} Returns the unescaped string.
|
* @example
|
*
|
* _.unescape('fred, barney, & pebbles');
|
* // => 'fred, barney, & pebbles'
|
*/
|
function unescape(string) {
|
string = baseToString(string);
|
return (string && reHasEscapedHtml.test(string))
|
? string.replace(reEscapedHtml, unescapeHtmlChar)
|
: string;
|
}
|
|
/**
|
* Splits `string` into an array of its words.
|
*
|
* @static
|
* @memberOf _
|
* @category String
|
* @param {string} [string=''] The string to inspect.
|
* @param {RegExp|string} [pattern] The pattern to match words.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Array} Returns the words of `string`.
|
* @example
|
*
|
* _.words('fred, barney, & pebbles');
|
* // => ['fred', 'barney', 'pebbles']
|
*
|
* _.words('fred, barney, & pebbles', /[^, ]+/g);
|
* // => ['fred', 'barney', '&', 'pebbles']
|
*/
|
function words(string, pattern, guard) {
|
if (guard && isIterateeCall(string, pattern, guard)) {
|
pattern = undefined;
|
}
|
string = baseToString(string);
|
return string.match(pattern || reWords) || [];
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Attempts to invoke `func`, returning either the result or the caught error
|
* object. Any additional arguments are provided to `func` when it is invoked.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Function} func The function to attempt.
|
* @returns {*} Returns the `func` result or error object.
|
* @example
|
*
|
* // avoid throwing errors for invalid selectors
|
* var elements = _.attempt(function(selector) {
|
* return document.querySelectorAll(selector);
|
* }, '>_>');
|
*
|
* if (_.isError(elements)) {
|
* elements = [];
|
* }
|
*/
|
var attempt = restParam(function(func, args) {
|
try {
|
return func.apply(undefined, args);
|
} catch(e) {
|
return isError(e) ? e : new Error(e);
|
}
|
});
|
|
/**
|
* Creates a function that invokes `func` with the `this` binding of `thisArg`
|
* and arguments of the created function. If `func` is a property name the
|
* created callback returns the property value for a given element. If `func`
|
* is an object the created callback returns `true` for elements that contain
|
* the equivalent object properties, otherwise it returns `false`.
|
*
|
* @static
|
* @memberOf _
|
* @alias iteratee
|
* @category Utility
|
* @param {*} [func=_.identity] The value to convert to a callback.
|
* @param {*} [thisArg] The `this` binding of `func`.
|
* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
|
* @returns {Function} Returns the callback.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'fred', 'age': 40 }
|
* ];
|
*
|
* // wrap to create custom callback shorthands
|
* _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
|
* var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
|
* if (!match) {
|
* return callback(func, thisArg);
|
* }
|
* return function(object) {
|
* return match[2] == 'gt'
|
* ? object[match[1]] > match[3]
|
* : object[match[1]] < match[3];
|
* };
|
* });
|
*
|
* _.filter(users, 'age__gt36');
|
* // => [{ 'user': 'fred', 'age': 40 }]
|
*/
|
function callback(func, thisArg, guard) {
|
if (guard && isIterateeCall(func, thisArg, guard)) {
|
thisArg = undefined;
|
}
|
return isObjectLike(func)
|
? matches(func)
|
: baseCallback(func, thisArg);
|
}
|
|
/**
|
* Creates a function that returns `value`.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {*} value The value to return from the new function.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var object = { 'user': 'fred' };
|
* var getter = _.constant(object);
|
*
|
* getter() === object;
|
* // => true
|
*/
|
function constant(value) {
|
return function() {
|
return value;
|
};
|
}
|
|
/**
|
* This method returns the first argument provided to it.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {*} value Any value.
|
* @returns {*} Returns `value`.
|
* @example
|
*
|
* var object = { 'user': 'fred' };
|
*
|
* _.identity(object) === object;
|
* // => true
|
*/
|
function identity(value) {
|
return value;
|
}
|
|
/**
|
* Creates a function that performs a deep comparison between a given object
|
* and `source`, returning `true` if the given object has equivalent property
|
* values, else `false`.
|
*
|
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
* numbers, `Object` objects, regexes, and strings. Objects are compared by
|
* their own, not inherited, enumerable properties. For comparing a single
|
* own or inherited property value see `_.matchesProperty`.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Object} source The object of property values to match.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36, 'active': true },
|
* { 'user': 'fred', 'age': 40, 'active': false }
|
* ];
|
*
|
* _.filter(users, _.matches({ 'age': 40, 'active': false }));
|
* // => [{ 'user': 'fred', 'age': 40, 'active': false }]
|
*/
|
function matches(source) {
|
return baseMatches(baseClone(source, true));
|
}
|
|
/**
|
* Creates a function that compares the property value of `path` on a given
|
* object to `value`.
|
*
|
* **Note:** This method supports comparing arrays, booleans, `Date` objects,
|
* numbers, `Object` objects, regexes, and strings. Objects are compared by
|
* their own, not inherited, enumerable properties.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Array|string} path The path of the property to get.
|
* @param {*} srcValue The value to match.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var users = [
|
* { 'user': 'barney' },
|
* { 'user': 'fred' }
|
* ];
|
*
|
* _.find(users, _.matchesProperty('user', 'fred'));
|
* // => { 'user': 'fred' }
|
*/
|
function matchesProperty(path, srcValue) {
|
return baseMatchesProperty(path, baseClone(srcValue, true));
|
}
|
|
/**
|
* Creates a function that invokes the method at `path` on a given object.
|
* Any additional arguments are provided to the invoked method.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Array|string} path The path of the method to invoke.
|
* @param {...*} [args] The arguments to invoke the method with.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var objects = [
|
* { 'a': { 'b': { 'c': _.constant(2) } } },
|
* { 'a': { 'b': { 'c': _.constant(1) } } }
|
* ];
|
*
|
* _.map(objects, _.method('a.b.c'));
|
* // => [2, 1]
|
*
|
* _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
|
* // => [1, 2]
|
*/
|
var method = restParam(function(path, args) {
|
return function(object) {
|
return invokePath(object, path, args);
|
};
|
});
|
|
/**
|
* The opposite of `_.method`; this method creates a function that invokes
|
* the method at a given path on `object`. Any additional arguments are
|
* provided to the invoked method.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Object} object The object to query.
|
* @param {...*} [args] The arguments to invoke the method with.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var array = _.times(3, _.constant),
|
* object = { 'a': array, 'b': array, 'c': array };
|
*
|
* _.map(['a[2]', 'c[0]'], _.methodOf(object));
|
* // => [2, 0]
|
*
|
* _.map([['a', '2'], ['c', '0']], _.methodOf(object));
|
* // => [2, 0]
|
*/
|
var methodOf = restParam(function(object, args) {
|
return function(path) {
|
return invokePath(object, path, args);
|
};
|
});
|
|
/**
|
* Adds all own enumerable function properties of a source object to the
|
* destination object. If `object` is a function then methods are added to
|
* its prototype as well.
|
*
|
* **Note:** Use `_.runInContext` to create a pristine `lodash` function to
|
* avoid conflicts caused by modifying the original.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Function|Object} [object=lodash] The destination object.
|
* @param {Object} source The object of functions to add.
|
* @param {Object} [options] The options object.
|
* @param {boolean} [options.chain=true] Specify whether the functions added
|
* are chainable.
|
* @returns {Function|Object} Returns `object`.
|
* @example
|
*
|
* function vowels(string) {
|
* return _.filter(string, function(v) {
|
* return /[aeiou]/i.test(v);
|
* });
|
* }
|
*
|
* _.mixin({ 'vowels': vowels });
|
* _.vowels('fred');
|
* // => ['e']
|
*
|
* _('fred').vowels().value();
|
* // => ['e']
|
*
|
* _.mixin({ 'vowels': vowels }, { 'chain': false });
|
* _('fred').vowels();
|
* // => ['e']
|
*/
|
function mixin(object, source, options) {
|
if (options == null) {
|
var isObj = isObject(source),
|
props = isObj ? keys(source) : undefined,
|
methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
|
|
if (!(methodNames ? methodNames.length : isObj)) {
|
methodNames = false;
|
options = source;
|
source = object;
|
object = this;
|
}
|
}
|
if (!methodNames) {
|
methodNames = baseFunctions(source, keys(source));
|
}
|
var chain = true,
|
index = -1,
|
isFunc = isFunction(object),
|
length = methodNames.length;
|
|
if (options === false) {
|
chain = false;
|
} else if (isObject(options) && 'chain' in options) {
|
chain = options.chain;
|
}
|
while (++index < length) {
|
var methodName = methodNames[index],
|
func = source[methodName];
|
|
object[methodName] = func;
|
if (isFunc) {
|
object.prototype[methodName] = (function(func) {
|
return function() {
|
var chainAll = this.__chain__;
|
if (chain || chainAll) {
|
var result = object(this.__wrapped__),
|
actions = result.__actions__ = arrayCopy(this.__actions__);
|
|
actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
|
result.__chain__ = chainAll;
|
return result;
|
}
|
return func.apply(object, arrayPush([this.value()], arguments));
|
};
|
}(func));
|
}
|
}
|
return object;
|
}
|
|
/**
|
* Reverts the `_` variable to its previous value and returns a reference to
|
* the `lodash` function.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @returns {Function} Returns the `lodash` function.
|
* @example
|
*
|
* var lodash = _.noConflict();
|
*/
|
function noConflict() {
|
root._ = oldDash;
|
return this;
|
}
|
|
/**
|
* A no-operation function that returns `undefined` regardless of the
|
* arguments it receives.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @example
|
*
|
* var object = { 'user': 'fred' };
|
*
|
* _.noop(object) === undefined;
|
* // => true
|
*/
|
function noop() {
|
// No operation performed.
|
}
|
|
/**
|
* Creates a function that returns the property value at `path` on a
|
* given object.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Array|string} path The path of the property to get.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var objects = [
|
* { 'a': { 'b': { 'c': 2 } } },
|
* { 'a': { 'b': { 'c': 1 } } }
|
* ];
|
*
|
* _.map(objects, _.property('a.b.c'));
|
* // => [2, 1]
|
*
|
* _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
|
* // => [1, 2]
|
*/
|
function property(path) {
|
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
}
|
|
/**
|
* The opposite of `_.property`; this method creates a function that returns
|
* the property value at a given path on `object`.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {Object} object The object to query.
|
* @returns {Function} Returns the new function.
|
* @example
|
*
|
* var array = [0, 1, 2],
|
* object = { 'a': array, 'b': array, 'c': array };
|
*
|
* _.map(['a[2]', 'c[0]'], _.propertyOf(object));
|
* // => [2, 0]
|
*
|
* _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
|
* // => [2, 0]
|
*/
|
function propertyOf(object) {
|
return function(path) {
|
return baseGet(object, toPath(path), path + '');
|
};
|
}
|
|
/**
|
* Creates an array of numbers (positive and/or negative) progressing from
|
* `start` up to, but not including, `end`. If `end` is not specified it is
|
* set to `start` with `start` then set to `0`. If `end` is less than `start`
|
* a zero-length range is created unless a negative `step` is specified.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {number} [start=0] The start of the range.
|
* @param {number} end The end of the range.
|
* @param {number} [step=1] The value to increment or decrement by.
|
* @returns {Array} Returns the new array of numbers.
|
* @example
|
*
|
* _.range(4);
|
* // => [0, 1, 2, 3]
|
*
|
* _.range(1, 5);
|
* // => [1, 2, 3, 4]
|
*
|
* _.range(0, 20, 5);
|
* // => [0, 5, 10, 15]
|
*
|
* _.range(0, -4, -1);
|
* // => [0, -1, -2, -3]
|
*
|
* _.range(1, 4, 0);
|
* // => [1, 1, 1]
|
*
|
* _.range(0);
|
* // => []
|
*/
|
function range(start, end, step) {
|
if (step && isIterateeCall(start, end, step)) {
|
end = step = undefined;
|
}
|
start = +start || 0;
|
step = step == null ? 1 : (+step || 0);
|
|
if (end == null) {
|
end = start;
|
start = 0;
|
} else {
|
end = +end || 0;
|
}
|
// Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
|
// See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
|
var index = -1,
|
length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
|
result = Array(length);
|
|
while (++index < length) {
|
result[index] = start;
|
start += step;
|
}
|
return result;
|
}
|
|
/**
|
* Invokes the iteratee function `n` times, returning an array of the results
|
* of each invocation. The `iteratee` is bound to `thisArg` and invoked with
|
* one argument; (index).
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {number} n The number of times to invoke `iteratee`.
|
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {Array} Returns the array of results.
|
* @example
|
*
|
* var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
|
* // => [3, 6, 4]
|
*
|
* _.times(3, function(n) {
|
* mage.castSpell(n);
|
* });
|
* // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
|
*
|
* _.times(3, function(n) {
|
* this.cast(n);
|
* }, mage);
|
* // => also invokes `mage.castSpell(n)` three times
|
*/
|
function times(n, iteratee, thisArg) {
|
n = nativeFloor(n);
|
|
// Exit early to avoid a JSC JIT bug in Safari 8
|
// where `Array(0)` is treated as `Array(1)`.
|
if (n < 1 || !nativeIsFinite(n)) {
|
return [];
|
}
|
var index = -1,
|
result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
|
|
iteratee = bindCallback(iteratee, thisArg, 1);
|
while (++index < n) {
|
if (index < MAX_ARRAY_LENGTH) {
|
result[index] = iteratee(index);
|
} else {
|
iteratee(index);
|
}
|
}
|
return result;
|
}
|
|
/**
|
* Generates a unique ID. If `prefix` is provided the ID is appended to it.
|
*
|
* @static
|
* @memberOf _
|
* @category Utility
|
* @param {string} [prefix] The value to prefix the ID with.
|
* @returns {string} Returns the unique ID.
|
* @example
|
*
|
* _.uniqueId('contact_');
|
* // => 'contact_104'
|
*
|
* _.uniqueId();
|
* // => '105'
|
*/
|
function uniqueId(prefix) {
|
var id = ++idCounter;
|
return baseToString(prefix) + id;
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* Adds two numbers.
|
*
|
* @static
|
* @memberOf _
|
* @category Math
|
* @param {number} augend The first number to add.
|
* @param {number} addend The second number to add.
|
* @returns {number} Returns the sum.
|
* @example
|
*
|
* _.add(6, 4);
|
* // => 10
|
*/
|
function add(augend, addend) {
|
return (+augend || 0) + (+addend || 0);
|
}
|
|
/**
|
* Calculates `n` rounded up to `precision`.
|
*
|
* @static
|
* @memberOf _
|
* @category Math
|
* @param {number} n The number to round up.
|
* @param {number} [precision=0] The precision to round up to.
|
* @returns {number} Returns the rounded up number.
|
* @example
|
*
|
* _.ceil(4.006);
|
* // => 5
|
*
|
* _.ceil(6.004, 2);
|
* // => 6.01
|
*
|
* _.ceil(6040, -2);
|
* // => 6100
|
*/
|
var ceil = createRound('ceil');
|
|
/**
|
* Calculates `n` rounded down to `precision`.
|
*
|
* @static
|
* @memberOf _
|
* @category Math
|
* @param {number} n The number to round down.
|
* @param {number} [precision=0] The precision to round down to.
|
* @returns {number} Returns the rounded down number.
|
* @example
|
*
|
* _.floor(4.006);
|
* // => 4
|
*
|
* _.floor(0.046, 2);
|
* // => 0.04
|
*
|
* _.floor(4060, -2);
|
* // => 4000
|
*/
|
var floor = createRound('floor');
|
|
/**
|
* Gets the maximum value of `collection`. If `collection` is empty or falsey
|
* `-Infinity` is returned. If an iteratee function is provided it is invoked
|
* for each value in `collection` to generate the criterion by which the value
|
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
|
* arguments: (value, index, collection).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Math
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {*} Returns the maximum value.
|
* @example
|
*
|
* _.max([4, 2, 8, 6]);
|
* // => 8
|
*
|
* _.max([]);
|
* // => -Infinity
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'fred', 'age': 40 }
|
* ];
|
*
|
* _.max(users, function(chr) {
|
* return chr.age;
|
* });
|
* // => { 'user': 'fred', 'age': 40 }
|
*
|
* // using the `_.property` callback shorthand
|
* _.max(users, 'age');
|
* // => { 'user': 'fred', 'age': 40 }
|
*/
|
var max = createExtremum(gt, NEGATIVE_INFINITY);
|
|
/**
|
* Gets the minimum value of `collection`. If `collection` is empty or falsey
|
* `Infinity` is returned. If an iteratee function is provided it is invoked
|
* for each value in `collection` to generate the criterion by which the value
|
* is ranked. The `iteratee` is bound to `thisArg` and invoked with three
|
* arguments: (value, index, collection).
|
*
|
* If a property name is provided for `iteratee` the created `_.property`
|
* style callback returns the property value of the given element.
|
*
|
* If a value is also provided for `thisArg` the created `_.matchesProperty`
|
* style callback returns `true` for elements that have a matching property
|
* value, else `false`.
|
*
|
* If an object is provided for `iteratee` the created `_.matches` style
|
* callback returns `true` for elements that have the properties of the given
|
* object, else `false`.
|
*
|
* @static
|
* @memberOf _
|
* @category Math
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {*} Returns the minimum value.
|
* @example
|
*
|
* _.min([4, 2, 8, 6]);
|
* // => 2
|
*
|
* _.min([]);
|
* // => Infinity
|
*
|
* var users = [
|
* { 'user': 'barney', 'age': 36 },
|
* { 'user': 'fred', 'age': 40 }
|
* ];
|
*
|
* _.min(users, function(chr) {
|
* return chr.age;
|
* });
|
* // => { 'user': 'barney', 'age': 36 }
|
*
|
* // using the `_.property` callback shorthand
|
* _.min(users, 'age');
|
* // => { 'user': 'barney', 'age': 36 }
|
*/
|
var min = createExtremum(lt, POSITIVE_INFINITY);
|
|
/**
|
* Calculates `n` rounded to `precision`.
|
*
|
* @static
|
* @memberOf _
|
* @category Math
|
* @param {number} n The number to round.
|
* @param {number} [precision=0] The precision to round to.
|
* @returns {number} Returns the rounded number.
|
* @example
|
*
|
* _.round(4.006);
|
* // => 4
|
*
|
* _.round(4.006, 2);
|
* // => 4.01
|
*
|
* _.round(4060, -2);
|
* // => 4100
|
*/
|
var round = createRound('round');
|
|
/**
|
* Gets the sum of the values in `collection`.
|
*
|
* @static
|
* @memberOf _
|
* @category Math
|
* @param {Array|Object|string} collection The collection to iterate over.
|
* @param {Function|Object|string} [iteratee] The function invoked per iteration.
|
* @param {*} [thisArg] The `this` binding of `iteratee`.
|
* @returns {number} Returns the sum.
|
* @example
|
*
|
* _.sum([4, 6]);
|
* // => 10
|
*
|
* _.sum({ 'a': 4, 'b': 6 });
|
* // => 10
|
*
|
* var objects = [
|
* { 'n': 4 },
|
* { 'n': 6 }
|
* ];
|
*
|
* _.sum(objects, function(object) {
|
* return object.n;
|
* });
|
* // => 10
|
*
|
* // using the `_.property` callback shorthand
|
* _.sum(objects, 'n');
|
* // => 10
|
*/
|
function sum(collection, iteratee, thisArg) {
|
if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
|
iteratee = undefined;
|
}
|
iteratee = getCallback(iteratee, thisArg, 3);
|
return iteratee.length == 1
|
? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
|
: baseSum(collection, iteratee);
|
}
|
|
/*------------------------------------------------------------------------*/
|
|
// Ensure wrappers are instances of `baseLodash`.
|
lodash.prototype = baseLodash.prototype;
|
|
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
|
LodashWrapper.prototype.constructor = LodashWrapper;
|
|
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
|
LazyWrapper.prototype.constructor = LazyWrapper;
|
|
// Add functions to the `Map` cache.
|
MapCache.prototype['delete'] = mapDelete;
|
MapCache.prototype.get = mapGet;
|
MapCache.prototype.has = mapHas;
|
MapCache.prototype.set = mapSet;
|
|
// Add functions to the `Set` cache.
|
SetCache.prototype.push = cachePush;
|
|
// Assign cache to `_.memoize`.
|
memoize.Cache = MapCache;
|
|
// Add functions that return wrapped values when chaining.
|
lodash.after = after;
|
lodash.ary = ary;
|
lodash.assign = assign;
|
lodash.at = at;
|
lodash.before = before;
|
lodash.bind = bind;
|
lodash.bindAll = bindAll;
|
lodash.bindKey = bindKey;
|
lodash.callback = callback;
|
lodash.chain = chain;
|
lodash.chunk = chunk;
|
lodash.compact = compact;
|
lodash.constant = constant;
|
lodash.countBy = countBy;
|
lodash.create = create;
|
lodash.curry = curry;
|
lodash.curryRight = curryRight;
|
lodash.debounce = debounce;
|
lodash.defaults = defaults;
|
lodash.defaultsDeep = defaultsDeep;
|
lodash.defer = defer;
|
lodash.delay = delay;
|
lodash.difference = difference;
|
lodash.drop = drop;
|
lodash.dropRight = dropRight;
|
lodash.dropRightWhile = dropRightWhile;
|
lodash.dropWhile = dropWhile;
|
lodash.fill = fill;
|
lodash.filter = filter;
|
lodash.flatten = flatten;
|
lodash.flattenDeep = flattenDeep;
|
lodash.flow = flow;
|
lodash.flowRight = flowRight;
|
lodash.forEach = forEach;
|
lodash.forEachRight = forEachRight;
|
lodash.forIn = forIn;
|
lodash.forInRight = forInRight;
|
lodash.forOwn = forOwn;
|
lodash.forOwnRight = forOwnRight;
|
lodash.functions = functions;
|
lodash.groupBy = groupBy;
|
lodash.indexBy = indexBy;
|
lodash.initial = initial;
|
lodash.intersection = intersection;
|
lodash.invert = invert;
|
lodash.invoke = invoke;
|
lodash.keys = keys;
|
lodash.keysIn = keysIn;
|
lodash.map = map;
|
lodash.mapKeys = mapKeys;
|
lodash.mapValues = mapValues;
|
lodash.matches = matches;
|
lodash.matchesProperty = matchesProperty;
|
lodash.memoize = memoize;
|
lodash.merge = merge;
|
lodash.method = method;
|
lodash.methodOf = methodOf;
|
lodash.mixin = mixin;
|
lodash.modArgs = modArgs;
|
lodash.negate = negate;
|
lodash.omit = omit;
|
lodash.once = once;
|
lodash.pairs = pairs;
|
lodash.partial = partial;
|
lodash.partialRight = partialRight;
|
lodash.partition = partition;
|
lodash.pick = pick;
|
lodash.pluck = pluck;
|
lodash.property = property;
|
lodash.propertyOf = propertyOf;
|
lodash.pull = pull;
|
lodash.pullAt = pullAt;
|
lodash.range = range;
|
lodash.rearg = rearg;
|
lodash.reject = reject;
|
lodash.remove = remove;
|
lodash.rest = rest;
|
lodash.restParam = restParam;
|
lodash.set = set;
|
lodash.shuffle = shuffle;
|
lodash.slice = slice;
|
lodash.sortBy = sortBy;
|
lodash.sortByAll = sortByAll;
|
lodash.sortByOrder = sortByOrder;
|
lodash.spread = spread;
|
lodash.take = take;
|
lodash.takeRight = takeRight;
|
lodash.takeRightWhile = takeRightWhile;
|
lodash.takeWhile = takeWhile;
|
lodash.tap = tap;
|
lodash.throttle = throttle;
|
lodash.thru = thru;
|
lodash.times = times;
|
lodash.toArray = toArray;
|
lodash.toPlainObject = toPlainObject;
|
lodash.transform = transform;
|
lodash.union = union;
|
lodash.uniq = uniq;
|
lodash.unzip = unzip;
|
lodash.unzipWith = unzipWith;
|
lodash.values = values;
|
lodash.valuesIn = valuesIn;
|
lodash.where = where;
|
lodash.without = without;
|
lodash.wrap = wrap;
|
lodash.xor = xor;
|
lodash.zip = zip;
|
lodash.zipObject = zipObject;
|
lodash.zipWith = zipWith;
|
|
// Add aliases.
|
lodash.backflow = flowRight;
|
lodash.collect = map;
|
lodash.compose = flowRight;
|
lodash.each = forEach;
|
lodash.eachRight = forEachRight;
|
lodash.extend = assign;
|
lodash.iteratee = callback;
|
lodash.methods = functions;
|
lodash.object = zipObject;
|
lodash.select = filter;
|
lodash.tail = rest;
|
lodash.unique = uniq;
|
|
// Add functions to `lodash.prototype`.
|
mixin(lodash, lodash);
|
|
/*------------------------------------------------------------------------*/
|
|
// Add functions that return unwrapped values when chaining.
|
lodash.add = add;
|
lodash.attempt = attempt;
|
lodash.camelCase = camelCase;
|
lodash.capitalize = capitalize;
|
lodash.ceil = ceil;
|
lodash.clone = clone;
|
lodash.cloneDeep = cloneDeep;
|
lodash.deburr = deburr;
|
lodash.endsWith = endsWith;
|
lodash.escape = escape;
|
lodash.escapeRegExp = escapeRegExp;
|
lodash.every = every;
|
lodash.find = find;
|
lodash.findIndex = findIndex;
|
lodash.findKey = findKey;
|
lodash.findLast = findLast;
|
lodash.findLastIndex = findLastIndex;
|
lodash.findLastKey = findLastKey;
|
lodash.findWhere = findWhere;
|
lodash.first = first;
|
lodash.floor = floor;
|
lodash.get = get;
|
lodash.gt = gt;
|
lodash.gte = gte;
|
lodash.has = has;
|
lodash.identity = identity;
|
lodash.includes = includes;
|
lodash.indexOf = indexOf;
|
lodash.inRange = inRange;
|
lodash.isArguments = isArguments;
|
lodash.isArray = isArray;
|
lodash.isBoolean = isBoolean;
|
lodash.isDate = isDate;
|
lodash.isElement = isElement;
|
lodash.isEmpty = isEmpty;
|
lodash.isEqual = isEqual;
|
lodash.isError = isError;
|
lodash.isFinite = isFinite;
|
lodash.isFunction = isFunction;
|
lodash.isMatch = isMatch;
|
lodash.isNaN = isNaN;
|
lodash.isNative = isNative;
|
lodash.isNull = isNull;
|
lodash.isNumber = isNumber;
|
lodash.isObject = isObject;
|
lodash.isPlainObject = isPlainObject;
|
lodash.isRegExp = isRegExp;
|
lodash.isString = isString;
|
lodash.isTypedArray = isTypedArray;
|
lodash.isUndefined = isUndefined;
|
lodash.kebabCase = kebabCase;
|
lodash.last = last;
|
lodash.lastIndexOf = lastIndexOf;
|
lodash.lt = lt;
|
lodash.lte = lte;
|
lodash.max = max;
|
lodash.min = min;
|
lodash.noConflict = noConflict;
|
lodash.noop = noop;
|
lodash.now = now;
|
lodash.pad = pad;
|
lodash.padLeft = padLeft;
|
lodash.padRight = padRight;
|
lodash.parseInt = parseInt;
|
lodash.random = random;
|
lodash.reduce = reduce;
|
lodash.reduceRight = reduceRight;
|
lodash.repeat = repeat;
|
lodash.result = result;
|
lodash.round = round;
|
lodash.runInContext = runInContext;
|
lodash.size = size;
|
lodash.snakeCase = snakeCase;
|
lodash.some = some;
|
lodash.sortedIndex = sortedIndex;
|
lodash.sortedLastIndex = sortedLastIndex;
|
lodash.startCase = startCase;
|
lodash.startsWith = startsWith;
|
lodash.sum = sum;
|
lodash.template = template;
|
lodash.trim = trim;
|
lodash.trimLeft = trimLeft;
|
lodash.trimRight = trimRight;
|
lodash.trunc = trunc;
|
lodash.unescape = unescape;
|
lodash.uniqueId = uniqueId;
|
lodash.words = words;
|
|
// Add aliases.
|
lodash.all = every;
|
lodash.any = some;
|
lodash.contains = includes;
|
lodash.eq = isEqual;
|
lodash.detect = find;
|
lodash.foldl = reduce;
|
lodash.foldr = reduceRight;
|
lodash.head = first;
|
lodash.include = includes;
|
lodash.inject = reduce;
|
|
mixin(lodash, (function() {
|
var source = {};
|
baseForOwn(lodash, function(func, methodName) {
|
if (!lodash.prototype[methodName]) {
|
source[methodName] = func;
|
}
|
});
|
return source;
|
}()), false);
|
|
/*------------------------------------------------------------------------*/
|
|
// Add functions capable of returning wrapped and unwrapped values when chaining.
|
lodash.sample = sample;
|
|
lodash.prototype.sample = function(n) {
|
if (!this.__chain__ && n == null) {
|
return sample(this.value());
|
}
|
return this.thru(function(value) {
|
return sample(value, n);
|
});
|
};
|
|
/*------------------------------------------------------------------------*/
|
|
/**
|
* The semantic version number.
|
*
|
* @static
|
* @memberOf _
|
* @type string
|
*/
|
lodash.VERSION = VERSION;
|
|
// Assign default placeholders.
|
arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
|
lodash[methodName].placeholder = lodash;
|
});
|
|
// Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
|
arrayEach(['drop', 'take'], function(methodName, index) {
|
LazyWrapper.prototype[methodName] = function(n) {
|
var filtered = this.__filtered__;
|
if (filtered && !index) {
|
return new LazyWrapper(this);
|
}
|
n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
|
|
var result = this.clone();
|
if (filtered) {
|
result.__takeCount__ = nativeMin(result.__takeCount__, n);
|
} else {
|
result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
|
}
|
return result;
|
};
|
|
LazyWrapper.prototype[methodName + 'Right'] = function(n) {
|
return this.reverse()[methodName](n).reverse();
|
};
|
});
|
|
// Add `LazyWrapper` methods that accept an `iteratee` value.
|
arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
|
var type = index + 1,
|
isFilter = type != LAZY_MAP_FLAG;
|
|
LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
|
var result = this.clone();
|
result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
|
result.__filtered__ = result.__filtered__ || isFilter;
|
return result;
|
};
|
});
|
|
// Add `LazyWrapper` methods for `_.first` and `_.last`.
|
arrayEach(['first', 'last'], function(methodName, index) {
|
var takeName = 'take' + (index ? 'Right' : '');
|
|
LazyWrapper.prototype[methodName] = function() {
|
return this[takeName](1).value()[0];
|
};
|
});
|
|
// Add `LazyWrapper` methods for `_.initial` and `_.rest`.
|
arrayEach(['initial', 'rest'], function(methodName, index) {
|
var dropName = 'drop' + (index ? '' : 'Right');
|
|
LazyWrapper.prototype[methodName] = function() {
|
return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
|
};
|
});
|
|
// Add `LazyWrapper` methods for `_.pluck` and `_.where`.
|
arrayEach(['pluck', 'where'], function(methodName, index) {
|
var operationName = index ? 'filter' : 'map',
|
createCallback = index ? baseMatches : property;
|
|
LazyWrapper.prototype[methodName] = function(value) {
|
return this[operationName](createCallback(value));
|
};
|
});
|
|
LazyWrapper.prototype.compact = function() {
|
return this.filter(identity);
|
};
|
|
LazyWrapper.prototype.reject = function(predicate, thisArg) {
|
predicate = getCallback(predicate, thisArg, 1);
|
return this.filter(function(value) {
|
return !predicate(value);
|
});
|
};
|
|
LazyWrapper.prototype.slice = function(start, end) {
|
start = start == null ? 0 : (+start || 0);
|
|
var result = this;
|
if (result.__filtered__ && (start > 0 || end < 0)) {
|
return new LazyWrapper(result);
|
}
|
if (start < 0) {
|
result = result.takeRight(-start);
|
} else if (start) {
|
result = result.drop(start);
|
}
|
if (end !== undefined) {
|
end = (+end || 0);
|
result = end < 0 ? result.dropRight(-end) : result.take(end - start);
|
}
|
return result;
|
};
|
|
LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
|
return this.reverse().takeWhile(predicate, thisArg).reverse();
|
};
|
|
LazyWrapper.prototype.toArray = function() {
|
return this.take(POSITIVE_INFINITY);
|
};
|
|
// Add `LazyWrapper` methods to `lodash.prototype`.
|
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
|
retUnwrapped = /^(?:first|last)$/.test(methodName),
|
lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
|
|
if (!lodashFunc) {
|
return;
|
}
|
lodash.prototype[methodName] = function() {
|
var args = retUnwrapped ? [1] : arguments,
|
chainAll = this.__chain__,
|
value = this.__wrapped__,
|
isHybrid = !!this.__actions__.length,
|
isLazy = value instanceof LazyWrapper,
|
iteratee = args[0],
|
useLazy = isLazy || isArray(value);
|
|
if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
|
// Avoid lazy use if the iteratee has a "length" value other than `1`.
|
isLazy = useLazy = false;
|
}
|
var interceptor = function(value) {
|
return (retUnwrapped && chainAll)
|
? lodashFunc(value, 1)[0]
|
: lodashFunc.apply(undefined, arrayPush([value], args));
|
};
|
|
var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
|
onlyLazy = isLazy && !isHybrid;
|
|
if (retUnwrapped && !chainAll) {
|
if (onlyLazy) {
|
value = value.clone();
|
value.__actions__.push(action);
|
return func.call(value);
|
}
|
return lodashFunc.call(undefined, this.value())[0];
|
}
|
if (!retUnwrapped && useLazy) {
|
value = onlyLazy ? value : new LazyWrapper(this);
|
var result = func.apply(value, args);
|
result.__actions__.push(action);
|
return new LodashWrapper(result, chainAll);
|
}
|
return this.thru(interceptor);
|
};
|
});
|
|
// Add `Array` and `String` methods to `lodash.prototype`.
|
arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
|
var func = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
|
chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
|
retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
|
|
lodash.prototype[methodName] = function() {
|
var args = arguments;
|
if (retUnwrapped && !this.__chain__) {
|
return func.apply(this.value(), args);
|
}
|
return this[chainName](function(value) {
|
return func.apply(value, args);
|
});
|
};
|
});
|
|
// Map minified function names to their real names.
|
baseForOwn(LazyWrapper.prototype, function(func, methodName) {
|
var lodashFunc = lodash[methodName];
|
if (lodashFunc) {
|
var key = lodashFunc.name,
|
names = realNames[key] || (realNames[key] = []);
|
|
names.push({ 'name': methodName, 'func': lodashFunc });
|
}
|
});
|
|
realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
|
|
// Add functions to the lazy wrapper.
|
LazyWrapper.prototype.clone = lazyClone;
|
LazyWrapper.prototype.reverse = lazyReverse;
|
LazyWrapper.prototype.value = lazyValue;
|
|
// Add chaining functions to the `lodash` wrapper.
|
lodash.prototype.chain = wrapperChain;
|
lodash.prototype.commit = wrapperCommit;
|
lodash.prototype.concat = wrapperConcat;
|
lodash.prototype.plant = wrapperPlant;
|
lodash.prototype.reverse = wrapperReverse;
|
lodash.prototype.toString = wrapperToString;
|
lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
|
|
// Add function aliases to the `lodash` wrapper.
|
lodash.prototype.collect = lodash.prototype.map;
|
lodash.prototype.head = lodash.prototype.first;
|
lodash.prototype.select = lodash.prototype.filter;
|
lodash.prototype.tail = lodash.prototype.rest;
|
|
return lodash;
|
}
|
|
/*--------------------------------------------------------------------------*/
|
|
// Export lodash.
|
var _ = runInContext();
|
|
// Some AMD build optimizers like r.js check for condition patterns like the following:
|
if (true) {
|
// Expose lodash to the global object when an AMD loader is present to avoid
|
// errors in cases where lodash is loaded by a script tag and not intended
|
// as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
|
// more details.
|
root._ = _;
|
|
// Define as an anonymous module so, through path mapping, it can be
|
// referenced as the "underscore" module.
|
!(__WEBPACK_AMD_DEFINE_RESULT__ = function() {
|
return _;
|
}.call(exports, __webpack_require__, exports, module), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
}
|
// Check for `exports` after `define` in case a build optimizer adds an `exports` object.
|
else if (freeExports && freeModule) {
|
// Export for Node.js or RingoJS.
|
if (moduleExports) {
|
(freeModule.exports = _)._ = _;
|
}
|
// Export for Rhino with CommonJS support.
|
else {
|
freeExports._ = _;
|
}
|
}
|
else {
|
// Export for a browser or Rhino.
|
root._ = _;
|
}
|
}.call(this));
|
|
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)(module), (function() { return this; }())))
|
|
/***/ },
|
/* 5 */
|
/***/ function(module, exports) {
|
|
module.exports = function(module) {
|
if(!module.webpackPolyfill) {
|
module.deprecate = function() {};
|
module.paths = [];
|
// module.parent = undefined by default
|
module.children = [];
|
module.webpackPolyfill = 1;
|
}
|
return module;
|
}
|
|
|
/***/ },
|
/* 6 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
/**
|
* Copyright (c) 2014, Chris Pettitt
|
* All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
* list of conditions and the following disclaimer.
|
*
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
* this list of conditions and the following disclaimer in the documentation
|
* and/or other materials provided with the distribution.
|
*
|
* 3. Neither the name of the copyright holder nor the names of its contributors
|
* may be used to endorse or promote products derived from this software without
|
* specific prior written permission.
|
*
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
*/
|
|
var lib = __webpack_require__(7);
|
|
module.exports = {
|
Graph: lib.Graph,
|
json: __webpack_require__(11),
|
alg: __webpack_require__(12),
|
version: lib.version
|
};
|
|
|
/***/ },
|
/* 7 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
// Includes only the "core" of graphlib
|
module.exports = {
|
Graph: __webpack_require__(8),
|
version: __webpack_require__(10)
|
};
|
|
|
/***/ },
|
/* 8 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(9);
|
|
module.exports = Graph;
|
|
var DEFAULT_EDGE_NAME = "\x00",
|
GRAPH_NODE = "\x00",
|
EDGE_KEY_DELIM = "\x01";
|
|
// Implementation notes:
|
//
|
// * Node id query functions should return string ids for the nodes
|
// * Edge id query functions should return an "edgeObj", edge object, that is
|
// composed of enough information to uniquely identify an edge: {v, w, name}.
|
// * Internally we use an "edgeId", a stringified form of the edgeObj, to
|
// reference edges. This is because we need a performant way to look these
|
// edges up and, object properties, which have string keys, are the closest
|
// we're going to get to a performant hashtable in JavaScript.
|
|
function Graph(opts) {
|
this._isDirected = _.has(opts, "directed") ? opts.directed : true;
|
this._isMultigraph = _.has(opts, "multigraph") ? opts.multigraph : false;
|
this._isCompound = _.has(opts, "compound") ? opts.compound : false;
|
|
// Label for the graph itself
|
this._label = undefined;
|
|
// Defaults to be set when creating a new node
|
this._defaultNodeLabelFn = _.constant(undefined);
|
|
// Defaults to be set when creating a new edge
|
this._defaultEdgeLabelFn = _.constant(undefined);
|
|
// v -> label
|
this._nodes = {};
|
|
if (this._isCompound) {
|
// v -> parent
|
this._parent = {};
|
|
// v -> children
|
this._children = {};
|
this._children[GRAPH_NODE] = {};
|
}
|
|
// v -> edgeObj
|
this._in = {};
|
|
// u -> v -> Number
|
this._preds = {};
|
|
// v -> edgeObj
|
this._out = {};
|
|
// v -> w -> Number
|
this._sucs = {};
|
|
// e -> edgeObj
|
this._edgeObjs = {};
|
|
// e -> label
|
this._edgeLabels = {};
|
}
|
|
/* Number of nodes in the graph. Should only be changed by the implementation. */
|
Graph.prototype._nodeCount = 0;
|
|
/* Number of edges in the graph. Should only be changed by the implementation. */
|
Graph.prototype._edgeCount = 0;
|
|
|
/* === Graph functions ========= */
|
|
Graph.prototype.isDirected = function() {
|
return this._isDirected;
|
};
|
|
Graph.prototype.isMultigraph = function() {
|
return this._isMultigraph;
|
};
|
|
Graph.prototype.isCompound = function() {
|
return this._isCompound;
|
};
|
|
Graph.prototype.setGraph = function(label) {
|
this._label = label;
|
return this;
|
};
|
|
Graph.prototype.graph = function() {
|
return this._label;
|
};
|
|
|
/* === Node functions ========== */
|
|
Graph.prototype.setDefaultNodeLabel = function(newDefault) {
|
if (!_.isFunction(newDefault)) {
|
newDefault = _.constant(newDefault);
|
}
|
this._defaultNodeLabelFn = newDefault;
|
return this;
|
};
|
|
Graph.prototype.nodeCount = function() {
|
return this._nodeCount;
|
};
|
|
Graph.prototype.nodes = function() {
|
return _.keys(this._nodes);
|
};
|
|
Graph.prototype.sources = function() {
|
return _.filter(this.nodes(), function(v) {
|
return _.isEmpty(this._in[v]);
|
}, this);
|
};
|
|
Graph.prototype.sinks = function() {
|
return _.filter(this.nodes(), function(v) {
|
return _.isEmpty(this._out[v]);
|
}, this);
|
};
|
|
Graph.prototype.setNodes = function(vs, value) {
|
var args = arguments;
|
_.each(vs, function(v) {
|
if (args.length > 1) {
|
this.setNode(v, value);
|
} else {
|
this.setNode(v);
|
}
|
}, this);
|
return this;
|
};
|
|
Graph.prototype.setNode = function(v, value) {
|
if (_.has(this._nodes, v)) {
|
if (arguments.length > 1) {
|
this._nodes[v] = value;
|
}
|
return this;
|
}
|
|
this._nodes[v] = arguments.length > 1 ? value : this._defaultNodeLabelFn(v);
|
if (this._isCompound) {
|
this._parent[v] = GRAPH_NODE;
|
this._children[v] = {};
|
this._children[GRAPH_NODE][v] = true;
|
}
|
this._in[v] = {};
|
this._preds[v] = {};
|
this._out[v] = {};
|
this._sucs[v] = {};
|
++this._nodeCount;
|
return this;
|
};
|
|
Graph.prototype.node = function(v) {
|
return this._nodes[v];
|
};
|
|
Graph.prototype.hasNode = function(v) {
|
return _.has(this._nodes, v);
|
};
|
|
Graph.prototype.removeNode = function(v) {
|
var self = this;
|
if (_.has(this._nodes, v)) {
|
var removeEdge = function(e) { self.removeEdge(self._edgeObjs[e]); };
|
delete this._nodes[v];
|
if (this._isCompound) {
|
this._removeFromParentsChildList(v);
|
delete this._parent[v];
|
_.each(this.children(v), function(child) {
|
this.setParent(child);
|
}, this);
|
delete this._children[v];
|
}
|
_.each(_.keys(this._in[v]), removeEdge);
|
delete this._in[v];
|
delete this._preds[v];
|
_.each(_.keys(this._out[v]), removeEdge);
|
delete this._out[v];
|
delete this._sucs[v];
|
--this._nodeCount;
|
}
|
return this;
|
};
|
|
Graph.prototype.setParent = function(v, parent) {
|
if (!this._isCompound) {
|
throw new Error("Cannot set parent in a non-compound graph");
|
}
|
|
if (_.isUndefined(parent)) {
|
parent = GRAPH_NODE;
|
} else {
|
// Coerce parent to string
|
parent += "";
|
for (var ancestor = parent;
|
!_.isUndefined(ancestor);
|
ancestor = this.parent(ancestor)) {
|
if (ancestor === v) {
|
throw new Error("Setting " + parent+ " as parent of " + v +
|
" would create create a cycle");
|
}
|
}
|
|
this.setNode(parent);
|
}
|
|
this.setNode(v);
|
this._removeFromParentsChildList(v);
|
this._parent[v] = parent;
|
this._children[parent][v] = true;
|
return this;
|
};
|
|
Graph.prototype._removeFromParentsChildList = function(v) {
|
delete this._children[this._parent[v]][v];
|
};
|
|
Graph.prototype.parent = function(v) {
|
if (this._isCompound) {
|
var parent = this._parent[v];
|
if (parent !== GRAPH_NODE) {
|
return parent;
|
}
|
}
|
};
|
|
Graph.prototype.children = function(v) {
|
if (_.isUndefined(v)) {
|
v = GRAPH_NODE;
|
}
|
|
if (this._isCompound) {
|
var children = this._children[v];
|
if (children) {
|
return _.keys(children);
|
}
|
} else if (v === GRAPH_NODE) {
|
return this.nodes();
|
} else if (this.hasNode(v)) {
|
return [];
|
}
|
};
|
|
Graph.prototype.predecessors = function(v) {
|
var predsV = this._preds[v];
|
if (predsV) {
|
return _.keys(predsV);
|
}
|
};
|
|
Graph.prototype.successors = function(v) {
|
var sucsV = this._sucs[v];
|
if (sucsV) {
|
return _.keys(sucsV);
|
}
|
};
|
|
Graph.prototype.neighbors = function(v) {
|
var preds = this.predecessors(v);
|
if (preds) {
|
return _.union(preds, this.successors(v));
|
}
|
};
|
|
Graph.prototype.filterNodes = function(filter) {
|
var copy = new this.constructor({
|
directed: this._isDirected,
|
multigraph: this._isMultigraph,
|
compound: this._isCompound
|
});
|
|
copy.setGraph(this.graph());
|
|
_.each(this._nodes, function(value, v) {
|
if (filter(v)) {
|
copy.setNode(v, value);
|
}
|
}, this);
|
|
_.each(this._edgeObjs, function(e) {
|
if (copy.hasNode(e.v) && copy.hasNode(e.w)) {
|
copy.setEdge(e, this.edge(e));
|
}
|
}, this);
|
|
var self = this;
|
var parents = {};
|
function findParent(v) {
|
var parent = self.parent(v);
|
if (parent === undefined || copy.hasNode(parent)) {
|
parents[v] = parent;
|
return parent;
|
} else if (parent in parents) {
|
return parents[parent];
|
} else {
|
return findParent(parent);
|
}
|
}
|
|
if (this._isCompound) {
|
_.each(copy.nodes(), function(v) {
|
copy.setParent(v, findParent(v));
|
});
|
}
|
|
return copy;
|
};
|
|
/* === Edge functions ========== */
|
|
Graph.prototype.setDefaultEdgeLabel = function(newDefault) {
|
if (!_.isFunction(newDefault)) {
|
newDefault = _.constant(newDefault);
|
}
|
this._defaultEdgeLabelFn = newDefault;
|
return this;
|
};
|
|
Graph.prototype.edgeCount = function() {
|
return this._edgeCount;
|
};
|
|
Graph.prototype.edges = function() {
|
return _.values(this._edgeObjs);
|
};
|
|
Graph.prototype.setPath = function(vs, value) {
|
var self = this,
|
args = arguments;
|
_.reduce(vs, function(v, w) {
|
if (args.length > 1) {
|
self.setEdge(v, w, value);
|
} else {
|
self.setEdge(v, w);
|
}
|
return w;
|
});
|
return this;
|
};
|
|
/*
|
* setEdge(v, w, [value, [name]])
|
* setEdge({ v, w, [name] }, [value])
|
*/
|
Graph.prototype.setEdge = function() {
|
var v, w, name, value,
|
valueSpecified = false,
|
arg0 = arguments[0];
|
|
if (typeof arg0 === "object" && arg0 !== null && "v" in arg0) {
|
v = arg0.v;
|
w = arg0.w;
|
name = arg0.name;
|
if (arguments.length === 2) {
|
value = arguments[1];
|
valueSpecified = true;
|
}
|
} else {
|
v = arg0;
|
w = arguments[1];
|
name = arguments[3];
|
if (arguments.length > 2) {
|
value = arguments[2];
|
valueSpecified = true;
|
}
|
}
|
|
v = "" + v;
|
w = "" + w;
|
if (!_.isUndefined(name)) {
|
name = "" + name;
|
}
|
|
var e = edgeArgsToId(this._isDirected, v, w, name);
|
if (_.has(this._edgeLabels, e)) {
|
if (valueSpecified) {
|
this._edgeLabels[e] = value;
|
}
|
return this;
|
}
|
|
if (!_.isUndefined(name) && !this._isMultigraph) {
|
throw new Error("Cannot set a named edge when isMultigraph = false");
|
}
|
|
// It didn't exist, so we need to create it.
|
// First ensure the nodes exist.
|
this.setNode(v);
|
this.setNode(w);
|
|
this._edgeLabels[e] = valueSpecified ? value : this._defaultEdgeLabelFn(v, w, name);
|
|
var edgeObj = edgeArgsToObj(this._isDirected, v, w, name);
|
// Ensure we add undirected edges in a consistent way.
|
v = edgeObj.v;
|
w = edgeObj.w;
|
|
Object.freeze(edgeObj);
|
this._edgeObjs[e] = edgeObj;
|
incrementOrInitEntry(this._preds[w], v);
|
incrementOrInitEntry(this._sucs[v], w);
|
this._in[w][e] = edgeObj;
|
this._out[v][e] = edgeObj;
|
this._edgeCount++;
|
return this;
|
};
|
|
Graph.prototype.edge = function(v, w, name) {
|
var e = (arguments.length === 1
|
? edgeObjToId(this._isDirected, arguments[0])
|
: edgeArgsToId(this._isDirected, v, w, name));
|
return this._edgeLabels[e];
|
};
|
|
Graph.prototype.hasEdge = function(v, w, name) {
|
var e = (arguments.length === 1
|
? edgeObjToId(this._isDirected, arguments[0])
|
: edgeArgsToId(this._isDirected, v, w, name));
|
return _.has(this._edgeLabels, e);
|
};
|
|
Graph.prototype.removeEdge = function(v, w, name) {
|
var e = (arguments.length === 1
|
? edgeObjToId(this._isDirected, arguments[0])
|
: edgeArgsToId(this._isDirected, v, w, name)),
|
edge = this._edgeObjs[e];
|
if (edge) {
|
v = edge.v;
|
w = edge.w;
|
delete this._edgeLabels[e];
|
delete this._edgeObjs[e];
|
decrementOrRemoveEntry(this._preds[w], v);
|
decrementOrRemoveEntry(this._sucs[v], w);
|
delete this._in[w][e];
|
delete this._out[v][e];
|
this._edgeCount--;
|
}
|
return this;
|
};
|
|
Graph.prototype.inEdges = function(v, u) {
|
var inV = this._in[v];
|
if (inV) {
|
var edges = _.values(inV);
|
if (!u) {
|
return edges;
|
}
|
return _.filter(edges, function(edge) { return edge.v === u; });
|
}
|
};
|
|
Graph.prototype.outEdges = function(v, w) {
|
var outV = this._out[v];
|
if (outV) {
|
var edges = _.values(outV);
|
if (!w) {
|
return edges;
|
}
|
return _.filter(edges, function(edge) { return edge.w === w; });
|
}
|
};
|
|
Graph.prototype.nodeEdges = function(v, w) {
|
var inEdges = this.inEdges(v, w);
|
if (inEdges) {
|
return inEdges.concat(this.outEdges(v, w));
|
}
|
};
|
|
function incrementOrInitEntry(map, k) {
|
if (map[k]) {
|
map[k]++;
|
} else {
|
map[k] = 1;
|
}
|
}
|
|
function decrementOrRemoveEntry(map, k) {
|
if (!--map[k]) { delete map[k]; }
|
}
|
|
function edgeArgsToId(isDirected, v_, w_, name) {
|
var v = "" + v_;
|
var w = "" + w_;
|
if (!isDirected && v > w) {
|
var tmp = v;
|
v = w;
|
w = tmp;
|
}
|
return v + EDGE_KEY_DELIM + w + EDGE_KEY_DELIM +
|
(_.isUndefined(name) ? DEFAULT_EDGE_NAME : name);
|
}
|
|
function edgeArgsToObj(isDirected, v_, w_, name) {
|
var v = "" + v_;
|
var w = "" + w_;
|
if (!isDirected && v > w) {
|
var tmp = v;
|
v = w;
|
w = tmp;
|
}
|
var edgeObj = { v: v, w: w };
|
if (name) {
|
edgeObj.name = name;
|
}
|
return edgeObj;
|
}
|
|
function edgeObjToId(isDirected, edgeObj) {
|
return edgeArgsToId(isDirected, edgeObj.v, edgeObj.w, edgeObj.name);
|
}
|
|
|
/***/ },
|
/* 9 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
/* global window */
|
|
var lodash;
|
|
if (true) {
|
try {
|
lodash = __webpack_require__(4);
|
} catch (e) {}
|
}
|
|
if (!lodash) {
|
lodash = window._;
|
}
|
|
module.exports = lodash;
|
|
|
/***/ },
|
/* 10 */
|
/***/ function(module, exports) {
|
|
module.exports = '1.0.7';
|
|
|
/***/ },
|
/* 11 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9),
|
Graph = __webpack_require__(8);
|
|
module.exports = {
|
write: write,
|
read: read
|
};
|
|
function write(g) {
|
var json = {
|
options: {
|
directed: g.isDirected(),
|
multigraph: g.isMultigraph(),
|
compound: g.isCompound()
|
},
|
nodes: writeNodes(g),
|
edges: writeEdges(g)
|
};
|
if (!_.isUndefined(g.graph())) {
|
json.value = _.clone(g.graph());
|
}
|
return json;
|
}
|
|
function writeNodes(g) {
|
return _.map(g.nodes(), function(v) {
|
var nodeValue = g.node(v),
|
parent = g.parent(v),
|
node = { v: v };
|
if (!_.isUndefined(nodeValue)) {
|
node.value = nodeValue;
|
}
|
if (!_.isUndefined(parent)) {
|
node.parent = parent;
|
}
|
return node;
|
});
|
}
|
|
function writeEdges(g) {
|
return _.map(g.edges(), function(e) {
|
var edgeValue = g.edge(e),
|
edge = { v: e.v, w: e.w };
|
if (!_.isUndefined(e.name)) {
|
edge.name = e.name;
|
}
|
if (!_.isUndefined(edgeValue)) {
|
edge.value = edgeValue;
|
}
|
return edge;
|
});
|
}
|
|
function read(json) {
|
var g = new Graph(json.options).setGraph(json.value);
|
_.each(json.nodes, function(entry) {
|
g.setNode(entry.v, entry.value);
|
if (entry.parent) {
|
g.setParent(entry.v, entry.parent);
|
}
|
});
|
_.each(json.edges, function(entry) {
|
g.setEdge({ v: entry.v, w: entry.w, name: entry.name }, entry.value);
|
});
|
return g;
|
}
|
|
|
/***/ },
|
/* 12 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
module.exports = {
|
components: __webpack_require__(13),
|
dijkstra: __webpack_require__(14),
|
dijkstraAll: __webpack_require__(16),
|
findCycles: __webpack_require__(17),
|
floydWarshall: __webpack_require__(19),
|
isAcyclic: __webpack_require__(20),
|
postorder: __webpack_require__(22),
|
preorder: __webpack_require__(24),
|
prim: __webpack_require__(25),
|
tarjan: __webpack_require__(18),
|
topsort: __webpack_require__(21)
|
};
|
|
|
/***/ },
|
/* 13 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9);
|
|
module.exports = components;
|
|
function components(g) {
|
var visited = {},
|
cmpts = [],
|
cmpt;
|
|
function dfs(v) {
|
if (_.has(visited, v)) return;
|
visited[v] = true;
|
cmpt.push(v);
|
_.each(g.successors(v), dfs);
|
_.each(g.predecessors(v), dfs);
|
}
|
|
_.each(g.nodes(), function(v) {
|
cmpt = [];
|
dfs(v);
|
if (cmpt.length) {
|
cmpts.push(cmpt);
|
}
|
});
|
|
return cmpts;
|
}
|
|
|
/***/ },
|
/* 14 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9),
|
PriorityQueue = __webpack_require__(15);
|
|
module.exports = dijkstra;
|
|
var DEFAULT_WEIGHT_FUNC = _.constant(1);
|
|
function dijkstra(g, source, weightFn, edgeFn) {
|
return runDijkstra(g, String(source),
|
weightFn || DEFAULT_WEIGHT_FUNC,
|
edgeFn || function(v) { return g.outEdges(v); });
|
}
|
|
function runDijkstra(g, source, weightFn, edgeFn) {
|
var results = {},
|
pq = new PriorityQueue(),
|
v, vEntry;
|
|
var updateNeighbors = function(edge) {
|
var w = edge.v !== v ? edge.v : edge.w,
|
wEntry = results[w],
|
weight = weightFn(edge),
|
distance = vEntry.distance + weight;
|
|
if (weight < 0) {
|
throw new Error("dijkstra does not allow negative edge weights. " +
|
"Bad edge: " + edge + " Weight: " + weight);
|
}
|
|
if (distance < wEntry.distance) {
|
wEntry.distance = distance;
|
wEntry.predecessor = v;
|
pq.decrease(w, distance);
|
}
|
};
|
|
g.nodes().forEach(function(v) {
|
var distance = v === source ? 0 : Number.POSITIVE_INFINITY;
|
results[v] = { distance: distance };
|
pq.add(v, distance);
|
});
|
|
while (pq.size() > 0) {
|
v = pq.removeMin();
|
vEntry = results[v];
|
if (vEntry.distance === Number.POSITIVE_INFINITY) {
|
break;
|
}
|
|
edgeFn(v).forEach(updateNeighbors);
|
}
|
|
return results;
|
}
|
|
|
/***/ },
|
/* 15 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9);
|
|
module.exports = PriorityQueue;
|
|
/**
|
* A min-priority queue data structure. This algorithm is derived from Cormen,
|
* et al., "Introduction to Algorithms". The basic idea of a min-priority
|
* queue is that you can efficiently (in O(1) time) get the smallest key in
|
* the queue. Adding and removing elements takes O(log n) time. A key can
|
* have its priority decreased in O(log n) time.
|
*/
|
function PriorityQueue() {
|
this._arr = [];
|
this._keyIndices = {};
|
}
|
|
/**
|
* Returns the number of elements in the queue. Takes `O(1)` time.
|
*/
|
PriorityQueue.prototype.size = function() {
|
return this._arr.length;
|
};
|
|
/**
|
* Returns the keys that are in the queue. Takes `O(n)` time.
|
*/
|
PriorityQueue.prototype.keys = function() {
|
return this._arr.map(function(x) { return x.key; });
|
};
|
|
/**
|
* Returns `true` if **key** is in the queue and `false` if not.
|
*/
|
PriorityQueue.prototype.has = function(key) {
|
return _.has(this._keyIndices, key);
|
};
|
|
/**
|
* Returns the priority for **key**. If **key** is not present in the queue
|
* then this function returns `undefined`. Takes `O(1)` time.
|
*
|
* @param {Object} key
|
*/
|
PriorityQueue.prototype.priority = function(key) {
|
var index = this._keyIndices[key];
|
if (index !== undefined) {
|
return this._arr[index].priority;
|
}
|
};
|
|
/**
|
* Returns the key for the minimum element in this queue. If the queue is
|
* empty this function throws an Error. Takes `O(1)` time.
|
*/
|
PriorityQueue.prototype.min = function() {
|
if (this.size() === 0) {
|
throw new Error("Queue underflow");
|
}
|
return this._arr[0].key;
|
};
|
|
/**
|
* Inserts a new key into the priority queue. If the key already exists in
|
* the queue this function returns `false`; otherwise it will return `true`.
|
* Takes `O(n)` time.
|
*
|
* @param {Object} key the key to add
|
* @param {Number} priority the initial priority for the key
|
*/
|
PriorityQueue.prototype.add = function(key, priority) {
|
var keyIndices = this._keyIndices;
|
key = String(key);
|
if (!_.has(keyIndices, key)) {
|
var arr = this._arr;
|
var index = arr.length;
|
keyIndices[key] = index;
|
arr.push({key: key, priority: priority});
|
this._decrease(index);
|
return true;
|
}
|
return false;
|
};
|
|
/**
|
* Removes and returns the smallest key in the queue. Takes `O(log n)` time.
|
*/
|
PriorityQueue.prototype.removeMin = function() {
|
this._swap(0, this._arr.length - 1);
|
var min = this._arr.pop();
|
delete this._keyIndices[min.key];
|
this._heapify(0);
|
return min.key;
|
};
|
|
/**
|
* Decreases the priority for **key** to **priority**. If the new priority is
|
* greater than the previous priority, this function will throw an Error.
|
*
|
* @param {Object} key the key for which to raise priority
|
* @param {Number} priority the new priority for the key
|
*/
|
PriorityQueue.prototype.decrease = function(key, priority) {
|
var index = this._keyIndices[key];
|
if (priority > this._arr[index].priority) {
|
throw new Error("New priority is greater than current priority. " +
|
"Key: " + key + " Old: " + this._arr[index].priority + " New: " + priority);
|
}
|
this._arr[index].priority = priority;
|
this._decrease(index);
|
};
|
|
PriorityQueue.prototype._heapify = function(i) {
|
var arr = this._arr;
|
var l = 2 * i,
|
r = l + 1,
|
largest = i;
|
if (l < arr.length) {
|
largest = arr[l].priority < arr[largest].priority ? l : largest;
|
if (r < arr.length) {
|
largest = arr[r].priority < arr[largest].priority ? r : largest;
|
}
|
if (largest !== i) {
|
this._swap(i, largest);
|
this._heapify(largest);
|
}
|
}
|
};
|
|
PriorityQueue.prototype._decrease = function(index) {
|
var arr = this._arr;
|
var priority = arr[index].priority;
|
var parent;
|
while (index !== 0) {
|
parent = index >> 1;
|
if (arr[parent].priority < priority) {
|
break;
|
}
|
this._swap(index, parent);
|
index = parent;
|
}
|
};
|
|
PriorityQueue.prototype._swap = function(i, j) {
|
var arr = this._arr;
|
var keyIndices = this._keyIndices;
|
var origArrI = arr[i];
|
var origArrJ = arr[j];
|
arr[i] = origArrJ;
|
arr[j] = origArrI;
|
keyIndices[origArrJ.key] = i;
|
keyIndices[origArrI.key] = j;
|
};
|
|
|
/***/ },
|
/* 16 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var dijkstra = __webpack_require__(14),
|
_ = __webpack_require__(9);
|
|
module.exports = dijkstraAll;
|
|
function dijkstraAll(g, weightFunc, edgeFunc) {
|
return _.transform(g.nodes(), function(acc, v) {
|
acc[v] = dijkstra(g, v, weightFunc, edgeFunc);
|
}, {});
|
}
|
|
|
/***/ },
|
/* 17 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9),
|
tarjan = __webpack_require__(18);
|
|
module.exports = findCycles;
|
|
function findCycles(g) {
|
return _.filter(tarjan(g), function(cmpt) {
|
return cmpt.length > 1 || (cmpt.length === 1 && g.hasEdge(cmpt[0], cmpt[0]));
|
});
|
}
|
|
|
/***/ },
|
/* 18 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9);
|
|
module.exports = tarjan;
|
|
function tarjan(g) {
|
var index = 0,
|
stack = [],
|
visited = {}, // node id -> { onStack, lowlink, index }
|
results = [];
|
|
function dfs(v) {
|
var entry = visited[v] = {
|
onStack: true,
|
lowlink: index,
|
index: index++
|
};
|
stack.push(v);
|
|
g.successors(v).forEach(function(w) {
|
if (!_.has(visited, w)) {
|
dfs(w);
|
entry.lowlink = Math.min(entry.lowlink, visited[w].lowlink);
|
} else if (visited[w].onStack) {
|
entry.lowlink = Math.min(entry.lowlink, visited[w].index);
|
}
|
});
|
|
if (entry.lowlink === entry.index) {
|
var cmpt = [],
|
w;
|
do {
|
w = stack.pop();
|
visited[w].onStack = false;
|
cmpt.push(w);
|
} while (v !== w);
|
results.push(cmpt);
|
}
|
}
|
|
g.nodes().forEach(function(v) {
|
if (!_.has(visited, v)) {
|
dfs(v);
|
}
|
});
|
|
return results;
|
}
|
|
|
/***/ },
|
/* 19 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9);
|
|
module.exports = floydWarshall;
|
|
var DEFAULT_WEIGHT_FUNC = _.constant(1);
|
|
function floydWarshall(g, weightFn, edgeFn) {
|
return runFloydWarshall(g,
|
weightFn || DEFAULT_WEIGHT_FUNC,
|
edgeFn || function(v) { return g.outEdges(v); });
|
}
|
|
function runFloydWarshall(g, weightFn, edgeFn) {
|
var results = {},
|
nodes = g.nodes();
|
|
nodes.forEach(function(v) {
|
results[v] = {};
|
results[v][v] = { distance: 0 };
|
nodes.forEach(function(w) {
|
if (v !== w) {
|
results[v][w] = { distance: Number.POSITIVE_INFINITY };
|
}
|
});
|
edgeFn(v).forEach(function(edge) {
|
var w = edge.v === v ? edge.w : edge.v,
|
d = weightFn(edge);
|
results[v][w] = { distance: d, predecessor: v };
|
});
|
});
|
|
nodes.forEach(function(k) {
|
var rowK = results[k];
|
nodes.forEach(function(i) {
|
var rowI = results[i];
|
nodes.forEach(function(j) {
|
var ik = rowI[k];
|
var kj = rowK[j];
|
var ij = rowI[j];
|
var altDistance = ik.distance + kj.distance;
|
if (altDistance < ij.distance) {
|
ij.distance = altDistance;
|
ij.predecessor = kj.predecessor;
|
}
|
});
|
});
|
});
|
|
return results;
|
}
|
|
|
/***/ },
|
/* 20 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var topsort = __webpack_require__(21);
|
|
module.exports = isAcyclic;
|
|
function isAcyclic(g) {
|
try {
|
topsort(g);
|
} catch (e) {
|
if (e instanceof topsort.CycleException) {
|
return false;
|
}
|
throw e;
|
}
|
return true;
|
}
|
|
|
/***/ },
|
/* 21 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9);
|
|
module.exports = topsort;
|
topsort.CycleException = CycleException;
|
|
function topsort(g) {
|
var visited = {},
|
stack = {},
|
results = [];
|
|
function visit(node) {
|
if (_.has(stack, node)) {
|
throw new CycleException();
|
}
|
|
if (!_.has(visited, node)) {
|
stack[node] = true;
|
visited[node] = true;
|
_.each(g.predecessors(node), visit);
|
delete stack[node];
|
results.push(node);
|
}
|
}
|
|
_.each(g.sinks(), visit);
|
|
if (_.size(visited) !== g.nodeCount()) {
|
throw new CycleException();
|
}
|
|
return results;
|
}
|
|
function CycleException() {}
|
|
|
/***/ },
|
/* 22 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var dfs = __webpack_require__(23);
|
|
module.exports = postorder;
|
|
function postorder(g, vs) {
|
return dfs(g, vs, "post");
|
}
|
|
|
/***/ },
|
/* 23 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9);
|
|
module.exports = dfs;
|
|
/*
|
* A helper that preforms a pre- or post-order traversal on the input graph
|
* and returns the nodes in the order they were visited. This algorithm treats
|
* the input as undirected.
|
*
|
* Order must be one of "pre" or "post".
|
*/
|
function dfs(g, vs, order) {
|
if (!_.isArray(vs)) {
|
vs = [vs];
|
}
|
|
var acc = [],
|
visited = {};
|
_.each(vs, function(v) {
|
if (!g.hasNode(v)) {
|
throw new Error("Graph does not have node: " + v);
|
}
|
|
doDfs(g, v, order === "post", visited, acc);
|
});
|
return acc;
|
}
|
|
function doDfs(g, v, postorder, visited, acc) {
|
if (!_.has(visited, v)) {
|
visited[v] = true;
|
|
if (!postorder) { acc.push(v); }
|
_.each(g.neighbors(v), function(w) {
|
doDfs(g, w, postorder, visited, acc);
|
});
|
if (postorder) { acc.push(v); }
|
}
|
}
|
|
|
/***/ },
|
/* 24 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var dfs = __webpack_require__(23);
|
|
module.exports = preorder;
|
|
function preorder(g, vs) {
|
return dfs(g, vs, "pre");
|
}
|
|
|
/***/ },
|
/* 25 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(9),
|
Graph = __webpack_require__(8),
|
PriorityQueue = __webpack_require__(15);
|
|
module.exports = prim;
|
|
function prim(g, weightFunc) {
|
var result = new Graph(),
|
parents = {},
|
pq = new PriorityQueue(),
|
v;
|
|
function updateNeighbors(edge) {
|
var w = edge.v === v ? edge.w : edge.v,
|
pri = pq.priority(w);
|
if (pri !== undefined) {
|
var edgeWeight = weightFunc(edge);
|
if (edgeWeight < pri) {
|
parents[w] = v;
|
pq.decrease(w, edgeWeight);
|
}
|
}
|
}
|
|
if (g.nodeCount() === 0) {
|
return result;
|
}
|
|
_.each(g.nodes(), function(v) {
|
pq.add(v, Number.POSITIVE_INFINITY);
|
result.setNode(v);
|
});
|
|
// Start from an arbitrary node
|
pq.decrease(g.nodes()[0], 0);
|
|
var init = false;
|
while (pq.size() > 0) {
|
v = pq.removeMin();
|
if (_.has(parents, v)) {
|
result.setEdge(v, parents[v]);
|
} else if (init) {
|
throw new Error("Input graph is not connected: " + g);
|
} else {
|
init = true;
|
}
|
|
g.nodeEdges(v).forEach(updateNeighbors);
|
}
|
|
return result;
|
}
|
|
|
/***/ },
|
/* 26 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
/*
|
Copyright (c) 2012-2014 Chris Pettitt
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
of this software and associated documentation files (the "Software"), to deal
|
in the Software without restriction, including without limitation the rights
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
copies of the Software, and to permit persons to whom the Software is
|
furnished to do so, subject to the following conditions:
|
|
The above copyright notice and this permission notice shall be included in
|
all copies or substantial portions of the Software.
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
THE SOFTWARE.
|
*/
|
|
module.exports = {
|
graphlib: __webpack_require__(27),
|
|
layout: __webpack_require__(28),
|
debug: __webpack_require__(54),
|
util: {
|
time: __webpack_require__(34).time,
|
notime: __webpack_require__(34).notime
|
},
|
version: __webpack_require__(55)
|
};
|
|
|
/***/ },
|
/* 27 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
/* global window */
|
|
var graphlib;
|
|
if (true) {
|
try {
|
graphlib = __webpack_require__(6);
|
} catch (e) {}
|
}
|
|
if (!graphlib) {
|
graphlib = window.graphlib;
|
}
|
|
module.exports = graphlib;
|
|
|
/***/ },
|
/* 28 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
acyclic = __webpack_require__(30),
|
normalize = __webpack_require__(33),
|
rank = __webpack_require__(35),
|
normalizeRanks = __webpack_require__(34).normalizeRanks,
|
parentDummyChains = __webpack_require__(39),
|
removeEmptyRanks = __webpack_require__(34).removeEmptyRanks,
|
nestingGraph = __webpack_require__(40),
|
addBorderSegments = __webpack_require__(41),
|
coordinateSystem = __webpack_require__(42),
|
order = __webpack_require__(43),
|
position = __webpack_require__(52),
|
util = __webpack_require__(34),
|
Graph = __webpack_require__(27).Graph;
|
|
module.exports = layout;
|
|
function layout(g, opts) {
|
var time = opts && opts.debugTiming ? util.time : util.notime;
|
time("layout", function() {
|
var layoutGraph = time(" buildLayoutGraph",
|
function() { return buildLayoutGraph(g); });
|
time(" runLayout", function() { runLayout(layoutGraph, time); });
|
time(" updateInputGraph", function() { updateInputGraph(g, layoutGraph); });
|
});
|
}
|
|
function runLayout(g, time) {
|
time(" makeSpaceForEdgeLabels", function() { makeSpaceForEdgeLabels(g); });
|
time(" removeSelfEdges", function() { removeSelfEdges(g); });
|
time(" acyclic", function() { acyclic.run(g); });
|
time(" nestingGraph.run", function() { nestingGraph.run(g); });
|
time(" rank", function() { rank(util.asNonCompoundGraph(g)); });
|
time(" injectEdgeLabelProxies", function() { injectEdgeLabelProxies(g); });
|
time(" removeEmptyRanks", function() { removeEmptyRanks(g); });
|
time(" nestingGraph.cleanup", function() { nestingGraph.cleanup(g); });
|
time(" normalizeRanks", function() { normalizeRanks(g); });
|
time(" assignRankMinMax", function() { assignRankMinMax(g); });
|
time(" removeEdgeLabelProxies", function() { removeEdgeLabelProxies(g); });
|
time(" normalize.run", function() { normalize.run(g); });
|
time(" parentDummyChains", function() { parentDummyChains(g); });
|
time(" addBorderSegments", function() { addBorderSegments(g); });
|
time(" order", function() { order(g); });
|
time(" insertSelfEdges", function() { insertSelfEdges(g); });
|
time(" adjustCoordinateSystem", function() { coordinateSystem.adjust(g); });
|
time(" position", function() { position(g); });
|
time(" positionSelfEdges", function() { positionSelfEdges(g); });
|
time(" removeBorderNodes", function() { removeBorderNodes(g); });
|
time(" normalize.undo", function() { normalize.undo(g); });
|
time(" fixupEdgeLabelCoords", function() { fixupEdgeLabelCoords(g); });
|
time(" undoCoordinateSystem", function() { coordinateSystem.undo(g); });
|
time(" translateGraph", function() { translateGraph(g); });
|
time(" assignNodeIntersects", function() { assignNodeIntersects(g); });
|
time(" reversePoints", function() { reversePointsForReversedEdges(g); });
|
time(" acyclic.undo", function() { acyclic.undo(g); });
|
}
|
|
/*
|
* Copies final layout information from the layout graph back to the input
|
* graph. This process only copies whitelisted attributes from the layout graph
|
* to the input graph, so it serves as a good place to determine what
|
* attributes can influence layout.
|
*/
|
function updateInputGraph(inputGraph, layoutGraph) {
|
_.each(inputGraph.nodes(), function(v) {
|
var inputLabel = inputGraph.node(v),
|
layoutLabel = layoutGraph.node(v);
|
|
if (inputLabel) {
|
inputLabel.x = layoutLabel.x;
|
inputLabel.y = layoutLabel.y;
|
|
if (layoutGraph.children(v).length) {
|
inputLabel.width = layoutLabel.width;
|
inputLabel.height = layoutLabel.height;
|
}
|
}
|
});
|
|
_.each(inputGraph.edges(), function(e) {
|
var inputLabel = inputGraph.edge(e),
|
layoutLabel = layoutGraph.edge(e);
|
|
inputLabel.points = layoutLabel.points;
|
if (_.has(layoutLabel, "x")) {
|
inputLabel.x = layoutLabel.x;
|
inputLabel.y = layoutLabel.y;
|
}
|
});
|
|
inputGraph.graph().width = layoutGraph.graph().width;
|
inputGraph.graph().height = layoutGraph.graph().height;
|
}
|
|
var graphNumAttrs = ["nodesep", "edgesep", "ranksep", "marginx", "marginy"],
|
graphDefaults = { ranksep: 50, edgesep: 20, nodesep: 50, rankdir: "tb" },
|
graphAttrs = ["acyclicer", "ranker", "rankdir", "align"],
|
nodeNumAttrs = ["width", "height"],
|
nodeDefaults = { width: 0, height: 0 },
|
edgeNumAttrs = ["minlen", "weight", "width", "height", "labeloffset"],
|
edgeDefaults = {
|
minlen: 1, weight: 1, width: 0, height: 0,
|
labeloffset: 10, labelpos: "r"
|
},
|
edgeAttrs = ["labelpos"];
|
|
/*
|
* Constructs a new graph from the input graph, which can be used for layout.
|
* This process copies only whitelisted attributes from the input graph to the
|
* layout graph. Thus this function serves as a good place to determine what
|
* attributes can influence layout.
|
*/
|
function buildLayoutGraph(inputGraph) {
|
var g = new Graph({ multigraph: true, compound: true }),
|
graph = canonicalize(inputGraph.graph());
|
|
g.setGraph(_.merge({},
|
graphDefaults,
|
selectNumberAttrs(graph, graphNumAttrs),
|
_.pick(graph, graphAttrs)));
|
|
_.each(inputGraph.nodes(), function(v) {
|
var node = canonicalize(inputGraph.node(v));
|
g.setNode(v, _.defaults(selectNumberAttrs(node, nodeNumAttrs), nodeDefaults));
|
g.setParent(v, inputGraph.parent(v));
|
});
|
|
_.each(inputGraph.edges(), function(e) {
|
var edge = canonicalize(inputGraph.edge(e));
|
g.setEdge(e, _.merge({},
|
edgeDefaults,
|
selectNumberAttrs(edge, edgeNumAttrs),
|
_.pick(edge, edgeAttrs)));
|
});
|
|
return g;
|
}
|
|
/*
|
* This idea comes from the Gansner paper: to account for edge labels in our
|
* layout we split each rank in half by doubling minlen and halving ranksep.
|
* Then we can place labels at these mid-points between nodes.
|
*
|
* We also add some minimal padding to the width to push the label for the edge
|
* away from the edge itself a bit.
|
*/
|
function makeSpaceForEdgeLabels(g) {
|
var graph = g.graph();
|
graph.ranksep /= 2;
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
edge.minlen *= 2;
|
if (edge.labelpos.toLowerCase() !== "c") {
|
if (graph.rankdir === "TB" || graph.rankdir === "BT") {
|
edge.width += edge.labeloffset;
|
} else {
|
edge.height += edge.labeloffset;
|
}
|
}
|
});
|
}
|
|
/*
|
* Creates temporary dummy nodes that capture the rank in which each edge's
|
* label is going to, if it has one of non-zero width and height. We do this
|
* so that we can safely remove empty ranks while preserving balance for the
|
* label's position.
|
*/
|
function injectEdgeLabelProxies(g) {
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
if (edge.width && edge.height) {
|
var v = g.node(e.v),
|
w = g.node(e.w),
|
label = { rank: (w.rank - v.rank) / 2 + v.rank, e: e };
|
util.addDummyNode(g, "edge-proxy", label, "_ep");
|
}
|
});
|
}
|
|
function assignRankMinMax(g) {
|
var maxRank = 0;
|
_.each(g.nodes(), function(v) {
|
var node = g.node(v);
|
if (node.borderTop) {
|
node.minRank = g.node(node.borderTop).rank;
|
node.maxRank = g.node(node.borderBottom).rank;
|
maxRank = _.max(maxRank, node.maxRank);
|
}
|
});
|
g.graph().maxRank = maxRank;
|
}
|
|
function removeEdgeLabelProxies(g) {
|
_.each(g.nodes(), function(v) {
|
var node = g.node(v);
|
if (node.dummy === "edge-proxy") {
|
g.edge(node.e).labelRank = node.rank;
|
g.removeNode(v);
|
}
|
});
|
}
|
|
function translateGraph(g) {
|
var minX = Number.POSITIVE_INFINITY,
|
maxX = 0,
|
minY = Number.POSITIVE_INFINITY,
|
maxY = 0,
|
graphLabel = g.graph(),
|
marginX = graphLabel.marginx || 0,
|
marginY = graphLabel.marginy || 0;
|
|
function getExtremes(attrs) {
|
var x = attrs.x,
|
y = attrs.y,
|
w = attrs.width,
|
h = attrs.height;
|
minX = Math.min(minX, x - w / 2);
|
maxX = Math.max(maxX, x + w / 2);
|
minY = Math.min(minY, y - h / 2);
|
maxY = Math.max(maxY, y + h / 2);
|
}
|
|
_.each(g.nodes(), function(v) { getExtremes(g.node(v)); });
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
if (_.has(edge, "x")) {
|
getExtremes(edge);
|
}
|
});
|
|
minX -= marginX;
|
minY -= marginY;
|
|
_.each(g.nodes(), function(v) {
|
var node = g.node(v);
|
node.x -= minX;
|
node.y -= minY;
|
});
|
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
_.each(edge.points, function(p) {
|
p.x -= minX;
|
p.y -= minY;
|
});
|
if (_.has(edge, "x")) { edge.x -= minX; }
|
if (_.has(edge, "y")) { edge.y -= minY; }
|
});
|
|
graphLabel.width = maxX - minX + marginX;
|
graphLabel.height = maxY - minY + marginY;
|
}
|
|
function assignNodeIntersects(g) {
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e),
|
nodeV = g.node(e.v),
|
nodeW = g.node(e.w),
|
p1, p2;
|
if (!edge.points) {
|
edge.points = [];
|
p1 = nodeW;
|
p2 = nodeV;
|
} else {
|
p1 = edge.points[0];
|
p2 = edge.points[edge.points.length - 1];
|
}
|
edge.points.unshift(util.intersectRect(nodeV, p1));
|
edge.points.push(util.intersectRect(nodeW, p2));
|
});
|
}
|
|
function fixupEdgeLabelCoords(g) {
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
if (_.has(edge, "x")) {
|
if (edge.labelpos === "l" || edge.labelpos === "r") {
|
edge.width -= edge.labeloffset;
|
}
|
switch (edge.labelpos) {
|
case "l": edge.x -= edge.width / 2 + edge.labeloffset; break;
|
case "r": edge.x += edge.width / 2 + edge.labeloffset; break;
|
}
|
}
|
});
|
}
|
|
function reversePointsForReversedEdges(g) {
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
if (edge.reversed) {
|
edge.points.reverse();
|
}
|
});
|
}
|
|
function removeBorderNodes(g) {
|
_.each(g.nodes(), function(v) {
|
if (g.children(v).length) {
|
var node = g.node(v),
|
t = g.node(node.borderTop),
|
b = g.node(node.borderBottom),
|
l = g.node(_.last(node.borderLeft)),
|
r = g.node(_.last(node.borderRight));
|
|
node.width = Math.abs(r.x - l.x);
|
node.height = Math.abs(b.y - t.y);
|
node.x = l.x + node.width / 2;
|
node.y = t.y + node.height / 2;
|
}
|
});
|
|
_.each(g.nodes(), function(v) {
|
if (g.node(v).dummy === "border") {
|
g.removeNode(v);
|
}
|
});
|
}
|
|
function removeSelfEdges(g) {
|
_.each(g.edges(), function(e) {
|
if (e.v === e.w) {
|
var node = g.node(e.v);
|
if (!node.selfEdges) {
|
node.selfEdges = [];
|
}
|
node.selfEdges.push({ e: e, label: g.edge(e) });
|
g.removeEdge(e);
|
}
|
});
|
}
|
|
function insertSelfEdges(g) {
|
var layers = util.buildLayerMatrix(g);
|
_.each(layers, function(layer) {
|
var orderShift = 0;
|
_.each(layer, function(v, i) {
|
var node = g.node(v);
|
node.order = i + orderShift;
|
_.each(node.selfEdges, function(selfEdge) {
|
util.addDummyNode(g, "selfedge", {
|
width: selfEdge.label.width,
|
height: selfEdge.label.height,
|
rank: node.rank,
|
order: i + (++orderShift),
|
e: selfEdge.e,
|
label: selfEdge.label
|
}, "_se");
|
});
|
delete node.selfEdges;
|
});
|
});
|
}
|
|
function positionSelfEdges(g) {
|
_.each(g.nodes(), function(v) {
|
var node = g.node(v);
|
if (node.dummy === "selfedge") {
|
var selfNode = g.node(node.e.v),
|
x = selfNode.x + selfNode.width / 2,
|
y = selfNode.y,
|
dx = node.x - x,
|
dy = selfNode.height / 2;
|
g.setEdge(node.e, node.label);
|
g.removeNode(v);
|
node.label.points = [
|
{ x: x + 2 * dx / 3, y: y - dy },
|
{ x: x + 5 * dx / 6, y: y - dy },
|
{ x: x + dx , y: y },
|
{ x: x + 5 * dx / 6, y: y + dy },
|
{ x: x + 2 * dx / 3, y: y + dy },
|
];
|
node.label.x = node.x;
|
node.label.y = node.y;
|
}
|
});
|
}
|
|
function selectNumberAttrs(obj, attrs) {
|
return _.mapValues(_.pick(obj, attrs), Number);
|
}
|
|
function canonicalize(attrs) {
|
var newAttrs = {};
|
_.each(attrs, function(v, k) {
|
newAttrs[k.toLowerCase()] = v;
|
});
|
return newAttrs;
|
}
|
|
|
/***/ },
|
/* 29 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
/* global window */
|
|
var lodash;
|
|
if (true) {
|
try {
|
lodash = __webpack_require__(4);
|
} catch (e) {}
|
}
|
|
if (!lodash) {
|
lodash = window._;
|
}
|
|
module.exports = lodash;
|
|
|
/***/ },
|
/* 30 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
greedyFAS = __webpack_require__(31);
|
|
module.exports = {
|
run: run,
|
undo: undo
|
};
|
|
function run(g) {
|
var fas = (g.graph().acyclicer === "greedy"
|
? greedyFAS(g, weightFn(g))
|
: dfsFAS(g));
|
_.each(fas, function(e) {
|
var label = g.edge(e);
|
g.removeEdge(e);
|
label.forwardName = e.name;
|
label.reversed = true;
|
g.setEdge(e.w, e.v, label, _.uniqueId("rev"));
|
});
|
|
function weightFn(g) {
|
return function(e) {
|
return g.edge(e).weight;
|
};
|
}
|
}
|
|
function dfsFAS(g) {
|
var fas = [],
|
stack = {},
|
visited = {};
|
|
function dfs(v) {
|
if (_.has(visited, v)) {
|
return;
|
}
|
visited[v] = true;
|
stack[v] = true;
|
_.each(g.outEdges(v), function(e) {
|
if (_.has(stack, e.w)) {
|
fas.push(e);
|
} else {
|
dfs(e.w);
|
}
|
});
|
delete stack[v];
|
}
|
|
_.each(g.nodes(), dfs);
|
return fas;
|
}
|
|
function undo(g) {
|
_.each(g.edges(), function(e) {
|
var label = g.edge(e);
|
if (label.reversed) {
|
g.removeEdge(e);
|
|
var forwardName = label.forwardName;
|
delete label.reversed;
|
delete label.forwardName;
|
g.setEdge(e.w, e.v, label, forwardName);
|
}
|
});
|
}
|
|
|
/***/ },
|
/* 31 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29),
|
Graph = __webpack_require__(27).Graph,
|
List = __webpack_require__(32);
|
|
/*
|
* A greedy heuristic for finding a feedback arc set for a graph. A feedback
|
* arc set is a set of edges that can be removed to make a graph acyclic.
|
* The algorithm comes from: P. Eades, X. Lin, and W. F. Smyth, "A fast and
|
* effective heuristic for the feedback arc set problem." This implementation
|
* adjusts that from the paper to allow for weighted edges.
|
*/
|
module.exports = greedyFAS;
|
|
var DEFAULT_WEIGHT_FN = _.constant(1);
|
|
function greedyFAS(g, weightFn) {
|
if (g.nodeCount() <= 1) {
|
return [];
|
}
|
var state = buildState(g, weightFn || DEFAULT_WEIGHT_FN);
|
var results = doGreedyFAS(state.graph, state.buckets, state.zeroIdx);
|
|
// Expand multi-edges
|
return _.flatten(_.map(results, function(e) {
|
return g.outEdges(e.v, e.w);
|
}), true);
|
}
|
|
function doGreedyFAS(g, buckets, zeroIdx) {
|
var results = [],
|
sources = buckets[buckets.length - 1],
|
sinks = buckets[0];
|
|
var entry;
|
while (g.nodeCount()) {
|
while ((entry = sinks.dequeue())) { removeNode(g, buckets, zeroIdx, entry); }
|
while ((entry = sources.dequeue())) { removeNode(g, buckets, zeroIdx, entry); }
|
if (g.nodeCount()) {
|
for (var i = buckets.length - 2; i > 0; --i) {
|
entry = buckets[i].dequeue();
|
if (entry) {
|
results = results.concat(removeNode(g, buckets, zeroIdx, entry, true));
|
break;
|
}
|
}
|
}
|
}
|
|
return results;
|
}
|
|
function removeNode(g, buckets, zeroIdx, entry, collectPredecessors) {
|
var results = collectPredecessors ? [] : undefined;
|
|
_.each(g.inEdges(entry.v), function(edge) {
|
var weight = g.edge(edge),
|
uEntry = g.node(edge.v);
|
|
if (collectPredecessors) {
|
results.push({ v: edge.v, w: edge.w });
|
}
|
|
uEntry.out -= weight;
|
assignBucket(buckets, zeroIdx, uEntry);
|
});
|
|
_.each(g.outEdges(entry.v), function(edge) {
|
var weight = g.edge(edge),
|
w = edge.w,
|
wEntry = g.node(w);
|
wEntry["in"] -= weight;
|
assignBucket(buckets, zeroIdx, wEntry);
|
});
|
|
g.removeNode(entry.v);
|
|
return results;
|
}
|
|
function buildState(g, weightFn) {
|
var fasGraph = new Graph(),
|
maxIn = 0,
|
maxOut = 0;
|
|
_.each(g.nodes(), function(v) {
|
fasGraph.setNode(v, { v: v, "in": 0, out: 0 });
|
});
|
|
// Aggregate weights on nodes, but also sum the weights across multi-edges
|
// into a single edge for the fasGraph.
|
_.each(g.edges(), function(e) {
|
var prevWeight = fasGraph.edge(e.v, e.w) || 0,
|
weight = weightFn(e),
|
edgeWeight = prevWeight + weight;
|
fasGraph.setEdge(e.v, e.w, edgeWeight);
|
maxOut = Math.max(maxOut, fasGraph.node(e.v).out += weight);
|
maxIn = Math.max(maxIn, fasGraph.node(e.w)["in"] += weight);
|
});
|
|
var buckets = _.range(maxOut + maxIn + 3).map(function() { return new List(); });
|
var zeroIdx = maxIn + 1;
|
|
_.each(fasGraph.nodes(), function(v) {
|
assignBucket(buckets, zeroIdx, fasGraph.node(v));
|
});
|
|
return { graph: fasGraph, buckets: buckets, zeroIdx: zeroIdx };
|
}
|
|
function assignBucket(buckets, zeroIdx, entry) {
|
if (!entry.out) {
|
buckets[0].enqueue(entry);
|
} else if (!entry["in"]) {
|
buckets[buckets.length - 1].enqueue(entry);
|
} else {
|
buckets[entry.out - entry["in"] + zeroIdx].enqueue(entry);
|
}
|
}
|
|
|
/***/ },
|
/* 32 */
|
/***/ function(module, exports) {
|
|
/*
|
* Simple doubly linked list implementation derived from Cormen, et al.,
|
* "Introduction to Algorithms".
|
*/
|
|
module.exports = List;
|
|
function List() {
|
var sentinel = {};
|
sentinel._next = sentinel._prev = sentinel;
|
this._sentinel = sentinel;
|
}
|
|
List.prototype.dequeue = function() {
|
var sentinel = this._sentinel,
|
entry = sentinel._prev;
|
if (entry !== sentinel) {
|
unlink(entry);
|
return entry;
|
}
|
};
|
|
List.prototype.enqueue = function(entry) {
|
var sentinel = this._sentinel;
|
if (entry._prev && entry._next) {
|
unlink(entry);
|
}
|
entry._next = sentinel._next;
|
sentinel._next._prev = entry;
|
sentinel._next = entry;
|
entry._prev = sentinel;
|
};
|
|
List.prototype.toString = function() {
|
var strs = [],
|
sentinel = this._sentinel,
|
curr = sentinel._prev;
|
while (curr !== sentinel) {
|
strs.push(JSON.stringify(curr, filterOutLinks));
|
curr = curr._prev;
|
}
|
return "[" + strs.join(", ") + "]";
|
};
|
|
function unlink(entry) {
|
entry._prev._next = entry._next;
|
entry._next._prev = entry._prev;
|
delete entry._next;
|
delete entry._prev;
|
}
|
|
function filterOutLinks(k, v) {
|
if (k !== "_next" && k !== "_prev") {
|
return v;
|
}
|
}
|
|
|
/***/ },
|
/* 33 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
util = __webpack_require__(34);
|
|
module.exports = {
|
run: run,
|
undo: undo
|
};
|
|
/*
|
* Breaks any long edges in the graph into short segments that span 1 layer
|
* each. This operation is undoable with the denormalize function.
|
*
|
* Pre-conditions:
|
*
|
* 1. The input graph is a DAG.
|
* 2. Each node in the graph has a "rank" property.
|
*
|
* Post-condition:
|
*
|
* 1. All edges in the graph have a length of 1.
|
* 2. Dummy nodes are added where edges have been split into segments.
|
* 3. The graph is augmented with a "dummyChains" attribute which contains
|
* the first dummy in each chain of dummy nodes produced.
|
*/
|
function run(g) {
|
g.graph().dummyChains = [];
|
_.each(g.edges(), function(edge) { normalizeEdge(g, edge); });
|
}
|
|
function normalizeEdge(g, e) {
|
var v = e.v,
|
vRank = g.node(v).rank,
|
w = e.w,
|
wRank = g.node(w).rank,
|
name = e.name,
|
edgeLabel = g.edge(e),
|
labelRank = edgeLabel.labelRank;
|
|
if (wRank === vRank + 1) return;
|
|
g.removeEdge(e);
|
|
var dummy, attrs, i;
|
for (i = 0, ++vRank; vRank < wRank; ++i, ++vRank) {
|
edgeLabel.points = [];
|
attrs = {
|
width: 0, height: 0,
|
edgeLabel: edgeLabel, edgeObj: e,
|
rank: vRank
|
};
|
dummy = util.addDummyNode(g, "edge", attrs, "_d");
|
if (vRank === labelRank) {
|
attrs.width = edgeLabel.width;
|
attrs.height = edgeLabel.height;
|
attrs.dummy = "edge-label";
|
attrs.labelpos = edgeLabel.labelpos;
|
}
|
g.setEdge(v, dummy, { weight: edgeLabel.weight }, name);
|
if (i === 0) {
|
g.graph().dummyChains.push(dummy);
|
}
|
v = dummy;
|
}
|
|
g.setEdge(v, w, { weight: edgeLabel.weight }, name);
|
}
|
|
function undo(g) {
|
_.each(g.graph().dummyChains, function(v) {
|
var node = g.node(v),
|
origLabel = node.edgeLabel,
|
w;
|
g.setEdge(node.edgeObj, origLabel);
|
while (node.dummy) {
|
w = g.successors(v)[0];
|
g.removeNode(v);
|
origLabel.points.push({ x: node.x, y: node.y });
|
if (node.dummy === "edge-label") {
|
origLabel.x = node.x;
|
origLabel.y = node.y;
|
origLabel.width = node.width;
|
origLabel.height = node.height;
|
}
|
v = w;
|
node = g.node(v);
|
}
|
});
|
}
|
|
|
/***/ },
|
/* 34 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
Graph = __webpack_require__(27).Graph;
|
|
module.exports = {
|
addDummyNode: addDummyNode,
|
simplify: simplify,
|
asNonCompoundGraph: asNonCompoundGraph,
|
successorWeights: successorWeights,
|
predecessorWeights: predecessorWeights,
|
intersectRect: intersectRect,
|
buildLayerMatrix: buildLayerMatrix,
|
normalizeRanks: normalizeRanks,
|
removeEmptyRanks: removeEmptyRanks,
|
addBorderNode: addBorderNode,
|
maxRank: maxRank,
|
partition: partition,
|
time: time,
|
notime: notime
|
};
|
|
/*
|
* Adds a dummy node to the graph and return v.
|
*/
|
function addDummyNode(g, type, attrs, name) {
|
var v;
|
do {
|
v = _.uniqueId(name);
|
} while (g.hasNode(v));
|
|
attrs.dummy = type;
|
g.setNode(v, attrs);
|
return v;
|
}
|
|
/*
|
* Returns a new graph with only simple edges. Handles aggregation of data
|
* associated with multi-edges.
|
*/
|
function simplify(g) {
|
var simplified = new Graph().setGraph(g.graph());
|
_.each(g.nodes(), function(v) { simplified.setNode(v, g.node(v)); });
|
_.each(g.edges(), function(e) {
|
var simpleLabel = simplified.edge(e.v, e.w) || { weight: 0, minlen: 1 },
|
label = g.edge(e);
|
simplified.setEdge(e.v, e.w, {
|
weight: simpleLabel.weight + label.weight,
|
minlen: Math.max(simpleLabel.minlen, label.minlen)
|
});
|
});
|
return simplified;
|
}
|
|
function asNonCompoundGraph(g) {
|
var simplified = new Graph({ multigraph: g.isMultigraph() }).setGraph(g.graph());
|
_.each(g.nodes(), function(v) {
|
if (!g.children(v).length) {
|
simplified.setNode(v, g.node(v));
|
}
|
});
|
_.each(g.edges(), function(e) {
|
simplified.setEdge(e, g.edge(e));
|
});
|
return simplified;
|
}
|
|
function successorWeights(g) {
|
var weightMap = _.map(g.nodes(), function(v) {
|
var sucs = {};
|
_.each(g.outEdges(v), function(e) {
|
sucs[e.w] = (sucs[e.w] || 0) + g.edge(e).weight;
|
});
|
return sucs;
|
});
|
return _.zipObject(g.nodes(), weightMap);
|
}
|
|
function predecessorWeights(g) {
|
var weightMap = _.map(g.nodes(), function(v) {
|
var preds = {};
|
_.each(g.inEdges(v), function(e) {
|
preds[e.v] = (preds[e.v] || 0) + g.edge(e).weight;
|
});
|
return preds;
|
});
|
return _.zipObject(g.nodes(), weightMap);
|
}
|
|
/*
|
* Finds where a line starting at point ({x, y}) would intersect a rectangle
|
* ({x, y, width, height}) if it were pointing at the rectangle's center.
|
*/
|
function intersectRect(rect, point) {
|
var x = rect.x;
|
var y = rect.y;
|
|
// Rectangle intersection algorithm from:
|
// http://math.stackexchange.com/questions/108113/find-edge-between-two-boxes
|
var dx = point.x - x;
|
var dy = point.y - y;
|
var w = rect.width / 2;
|
var h = rect.height / 2;
|
|
if (!dx && !dy) {
|
throw new Error("Not possible to find intersection inside of the rectangle");
|
}
|
|
var sx, sy;
|
if (Math.abs(dy) * w > Math.abs(dx) * h) {
|
// Intersection is top or bottom of rect.
|
if (dy < 0) {
|
h = -h;
|
}
|
sx = h * dx / dy;
|
sy = h;
|
} else {
|
// Intersection is left or right of rect.
|
if (dx < 0) {
|
w = -w;
|
}
|
sx = w;
|
sy = w * dy / dx;
|
}
|
|
return { x: x + sx, y: y + sy };
|
}
|
|
/*
|
* Given a DAG with each node assigned "rank" and "order" properties, this
|
* function will produce a matrix with the ids of each node.
|
*/
|
function buildLayerMatrix(g) {
|
var layering = _.map(_.range(maxRank(g) + 1), function() { return []; });
|
_.each(g.nodes(), function(v) {
|
var node = g.node(v),
|
rank = node.rank;
|
if (!_.isUndefined(rank)) {
|
layering[rank][node.order] = v;
|
}
|
});
|
return layering;
|
}
|
|
/*
|
* Adjusts the ranks for all nodes in the graph such that all nodes v have
|
* rank(v) >= 0 and at least one node w has rank(w) = 0.
|
*/
|
function normalizeRanks(g) {
|
var min = _.min(_.map(g.nodes(), function(v) { return g.node(v).rank; }));
|
_.each(g.nodes(), function(v) {
|
var node = g.node(v);
|
if (_.has(node, "rank")) {
|
node.rank -= min;
|
}
|
});
|
}
|
|
function removeEmptyRanks(g) {
|
// Ranks may not start at 0, so we need to offset them
|
var offset = _.min(_.map(g.nodes(), function(v) { return g.node(v).rank; }));
|
|
var layers = [];
|
_.each(g.nodes(), function(v) {
|
var rank = g.node(v).rank - offset;
|
if (!layers[rank]) {
|
layers[rank] = [];
|
}
|
layers[rank].push(v);
|
});
|
|
var delta = 0,
|
nodeRankFactor = g.graph().nodeRankFactor;
|
_.each(layers, function(vs, i) {
|
if (_.isUndefined(vs) && i % nodeRankFactor !== 0) {
|
--delta;
|
} else if (delta) {
|
_.each(vs, function(v) { g.node(v).rank += delta; });
|
}
|
});
|
}
|
|
function addBorderNode(g, prefix, rank, order) {
|
var node = {
|
width: 0,
|
height: 0
|
};
|
if (arguments.length >= 4) {
|
node.rank = rank;
|
node.order = order;
|
}
|
return addDummyNode(g, "border", node, prefix);
|
}
|
|
function maxRank(g) {
|
return _.max(_.map(g.nodes(), function(v) {
|
var rank = g.node(v).rank;
|
if (!_.isUndefined(rank)) {
|
return rank;
|
}
|
}));
|
}
|
|
/*
|
* Partition a collection into two groups: `lhs` and `rhs`. If the supplied
|
* function returns true for an entry it goes into `lhs`. Otherwise it goes
|
* into `rhs.
|
*/
|
function partition(collection, fn) {
|
var result = { lhs: [], rhs: [] };
|
_.each(collection, function(value) {
|
if (fn(value)) {
|
result.lhs.push(value);
|
} else {
|
result.rhs.push(value);
|
}
|
});
|
return result;
|
}
|
|
/*
|
* Returns a new function that wraps `fn` with a timer. The wrapper logs the
|
* time it takes to execute the function.
|
*/
|
function time(name, fn) {
|
var start = _.now();
|
try {
|
return fn();
|
} finally {
|
console.log(name + " time: " + (_.now() - start) + "ms");
|
}
|
}
|
|
function notime(name, fn) {
|
return fn();
|
}
|
|
|
/***/ },
|
/* 35 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var rankUtil = __webpack_require__(36),
|
longestPath = rankUtil.longestPath,
|
feasibleTree = __webpack_require__(37),
|
networkSimplex = __webpack_require__(38);
|
|
module.exports = rank;
|
|
/*
|
* Assigns a rank to each node in the input graph that respects the "minlen"
|
* constraint specified on edges between nodes.
|
*
|
* This basic structure is derived from Gansner, et al., "A Technique for
|
* Drawing Directed Graphs."
|
*
|
* Pre-conditions:
|
*
|
* 1. Graph must be a connected DAG
|
* 2. Graph nodes must be objects
|
* 3. Graph edges must have "weight" and "minlen" attributes
|
*
|
* Post-conditions:
|
*
|
* 1. Graph nodes will have a "rank" attribute based on the results of the
|
* algorithm. Ranks can start at any index (including negative), we'll
|
* fix them up later.
|
*/
|
function rank(g) {
|
switch(g.graph().ranker) {
|
case "network-simplex": networkSimplexRanker(g); break;
|
case "tight-tree": tightTreeRanker(g); break;
|
case "longest-path": longestPathRanker(g); break;
|
default: networkSimplexRanker(g);
|
}
|
}
|
|
// A fast and simple ranker, but results are far from optimal.
|
var longestPathRanker = longestPath;
|
|
function tightTreeRanker(g) {
|
longestPath(g);
|
feasibleTree(g);
|
}
|
|
function networkSimplexRanker(g) {
|
networkSimplex(g);
|
}
|
|
|
/***/ },
|
/* 36 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29);
|
|
module.exports = {
|
longestPath: longestPath,
|
slack: slack
|
};
|
|
/*
|
* Initializes ranks for the input graph using the longest path algorithm. This
|
* algorithm scales well and is fast in practice, it yields rather poor
|
* solutions. Nodes are pushed to the lowest layer possible, leaving the bottom
|
* ranks wide and leaving edges longer than necessary. However, due to its
|
* speed, this algorithm is good for getting an initial ranking that can be fed
|
* into other algorithms.
|
*
|
* This algorithm does not normalize layers because it will be used by other
|
* algorithms in most cases. If using this algorithm directly, be sure to
|
* run normalize at the end.
|
*
|
* Pre-conditions:
|
*
|
* 1. Input graph is a DAG.
|
* 2. Input graph node labels can be assigned properties.
|
*
|
* Post-conditions:
|
*
|
* 1. Each node will be assign an (unnormalized) "rank" property.
|
*/
|
function longestPath(g) {
|
var visited = {};
|
|
function dfs(v) {
|
var label = g.node(v);
|
if (_.has(visited, v)) {
|
return label.rank;
|
}
|
visited[v] = true;
|
|
var rank = _.min(_.map(g.outEdges(v), function(e) {
|
return dfs(e.w) - g.edge(e).minlen;
|
}));
|
|
if (rank === Number.POSITIVE_INFINITY) {
|
rank = 0;
|
}
|
|
return (label.rank = rank);
|
}
|
|
_.each(g.sources(), dfs);
|
}
|
|
/*
|
* Returns the amount of slack for the given edge. The slack is defined as the
|
* difference between the length of the edge and its minimum length.
|
*/
|
function slack(g, e) {
|
return g.node(e.w).rank - g.node(e.v).rank - g.edge(e).minlen;
|
}
|
|
|
/***/ },
|
/* 37 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
Graph = __webpack_require__(27).Graph,
|
slack = __webpack_require__(36).slack;
|
|
module.exports = feasibleTree;
|
|
/*
|
* Constructs a spanning tree with tight edges and adjusted the input node's
|
* ranks to achieve this. A tight edge is one that is has a length that matches
|
* its "minlen" attribute.
|
*
|
* The basic structure for this function is derived from Gansner, et al., "A
|
* Technique for Drawing Directed Graphs."
|
*
|
* Pre-conditions:
|
*
|
* 1. Graph must be a DAG.
|
* 2. Graph must be connected.
|
* 3. Graph must have at least one node.
|
* 5. Graph nodes must have been previously assigned a "rank" property that
|
* respects the "minlen" property of incident edges.
|
* 6. Graph edges must have a "minlen" property.
|
*
|
* Post-conditions:
|
*
|
* - Graph nodes will have their rank adjusted to ensure that all edges are
|
* tight.
|
*
|
* Returns a tree (undirected graph) that is constructed using only "tight"
|
* edges.
|
*/
|
function feasibleTree(g) {
|
var t = new Graph({ directed: false });
|
|
// Choose arbitrary node from which to start our tree
|
var start = g.nodes()[0],
|
size = g.nodeCount();
|
t.setNode(start, {});
|
|
var edge, delta;
|
while (tightTree(t, g) < size) {
|
edge = findMinSlackEdge(t, g);
|
delta = t.hasNode(edge.v) ? slack(g, edge) : -slack(g, edge);
|
shiftRanks(t, g, delta);
|
}
|
|
return t;
|
}
|
|
/*
|
* Finds a maximal tree of tight edges and returns the number of nodes in the
|
* tree.
|
*/
|
function tightTree(t, g) {
|
function dfs(v) {
|
_.each(g.nodeEdges(v), function(e) {
|
var edgeV = e.v,
|
w = (v === edgeV) ? e.w : edgeV;
|
if (!t.hasNode(w) && !slack(g, e)) {
|
t.setNode(w, {});
|
t.setEdge(v, w, {});
|
dfs(w);
|
}
|
});
|
}
|
|
_.each(t.nodes(), dfs);
|
return t.nodeCount();
|
}
|
|
/*
|
* Finds the edge with the smallest slack that is incident on tree and returns
|
* it.
|
*/
|
function findMinSlackEdge(t, g) {
|
return _.min(g.edges(), function(e) {
|
if (t.hasNode(e.v) !== t.hasNode(e.w)) {
|
return slack(g, e);
|
}
|
});
|
}
|
|
function shiftRanks(t, g, delta) {
|
_.each(t.nodes(), function(v) {
|
g.node(v).rank += delta;
|
});
|
}
|
|
|
/***/ },
|
/* 38 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
feasibleTree = __webpack_require__(37),
|
slack = __webpack_require__(36).slack,
|
initRank = __webpack_require__(36).longestPath,
|
preorder = __webpack_require__(27).alg.preorder,
|
postorder = __webpack_require__(27).alg.postorder,
|
simplify = __webpack_require__(34).simplify;
|
|
module.exports = networkSimplex;
|
|
// Expose some internals for testing purposes
|
networkSimplex.initLowLimValues = initLowLimValues;
|
networkSimplex.initCutValues = initCutValues;
|
networkSimplex.calcCutValue = calcCutValue;
|
networkSimplex.leaveEdge = leaveEdge;
|
networkSimplex.enterEdge = enterEdge;
|
networkSimplex.exchangeEdges = exchangeEdges;
|
|
/*
|
* The network simplex algorithm assigns ranks to each node in the input graph
|
* and iteratively improves the ranking to reduce the length of edges.
|
*
|
* Preconditions:
|
*
|
* 1. The input graph must be a DAG.
|
* 2. All nodes in the graph must have an object value.
|
* 3. All edges in the graph must have "minlen" and "weight" attributes.
|
*
|
* Postconditions:
|
*
|
* 1. All nodes in the graph will have an assigned "rank" attribute that has
|
* been optimized by the network simplex algorithm. Ranks start at 0.
|
*
|
*
|
* A rough sketch of the algorithm is as follows:
|
*
|
* 1. Assign initial ranks to each node. We use the longest path algorithm,
|
* which assigns ranks to the lowest position possible. In general this
|
* leads to very wide bottom ranks and unnecessarily long edges.
|
* 2. Construct a feasible tight tree. A tight tree is one such that all
|
* edges in the tree have no slack (difference between length of edge
|
* and minlen for the edge). This by itself greatly improves the assigned
|
* rankings by shorting edges.
|
* 3. Iteratively find edges that have negative cut values. Generally a
|
* negative cut value indicates that the edge could be removed and a new
|
* tree edge could be added to produce a more compact graph.
|
*
|
* Much of the algorithms here are derived from Gansner, et al., "A Technique
|
* for Drawing Directed Graphs." The structure of the file roughly follows the
|
* structure of the overall algorithm.
|
*/
|
function networkSimplex(g) {
|
g = simplify(g);
|
initRank(g);
|
var t = feasibleTree(g);
|
initLowLimValues(t);
|
initCutValues(t, g);
|
|
var e, f;
|
while ((e = leaveEdge(t))) {
|
f = enterEdge(t, g, e);
|
exchangeEdges(t, g, e, f);
|
}
|
}
|
|
/*
|
* Initializes cut values for all edges in the tree.
|
*/
|
function initCutValues(t, g) {
|
var vs = postorder(t, t.nodes());
|
vs = vs.slice(0, vs.length - 1);
|
_.each(vs, function(v) {
|
assignCutValue(t, g, v);
|
});
|
}
|
|
function assignCutValue(t, g, child) {
|
var childLab = t.node(child),
|
parent = childLab.parent;
|
t.edge(child, parent).cutvalue = calcCutValue(t, g, child);
|
}
|
|
/*
|
* Given the tight tree, its graph, and a child in the graph calculate and
|
* return the cut value for the edge between the child and its parent.
|
*/
|
function calcCutValue(t, g, child) {
|
var childLab = t.node(child),
|
parent = childLab.parent,
|
// True if the child is on the tail end of the edge in the directed graph
|
childIsTail = true,
|
// The graph's view of the tree edge we're inspecting
|
graphEdge = g.edge(child, parent),
|
// The accumulated cut value for the edge between this node and its parent
|
cutValue = 0;
|
|
if (!graphEdge) {
|
childIsTail = false;
|
graphEdge = g.edge(parent, child);
|
}
|
|
cutValue = graphEdge.weight;
|
|
_.each(g.nodeEdges(child), function(e) {
|
var isOutEdge = e.v === child,
|
other = isOutEdge ? e.w : e.v;
|
|
if (other !== parent) {
|
var pointsToHead = isOutEdge === childIsTail,
|
otherWeight = g.edge(e).weight;
|
|
cutValue += pointsToHead ? otherWeight : -otherWeight;
|
if (isTreeEdge(t, child, other)) {
|
var otherCutValue = t.edge(child, other).cutvalue;
|
cutValue += pointsToHead ? -otherCutValue : otherCutValue;
|
}
|
}
|
});
|
|
return cutValue;
|
}
|
|
function initLowLimValues(tree, root) {
|
if (arguments.length < 2) {
|
root = tree.nodes()[0];
|
}
|
dfsAssignLowLim(tree, {}, 1, root);
|
}
|
|
function dfsAssignLowLim(tree, visited, nextLim, v, parent) {
|
var low = nextLim,
|
label = tree.node(v);
|
|
visited[v] = true;
|
_.each(tree.neighbors(v), function(w) {
|
if (!_.has(visited, w)) {
|
nextLim = dfsAssignLowLim(tree, visited, nextLim, w, v);
|
}
|
});
|
|
label.low = low;
|
label.lim = nextLim++;
|
if (parent) {
|
label.parent = parent;
|
} else {
|
// TODO should be able to remove this when we incrementally update low lim
|
delete label.parent;
|
}
|
|
return nextLim;
|
}
|
|
function leaveEdge(tree) {
|
return _.find(tree.edges(), function(e) {
|
return tree.edge(e).cutvalue < 0;
|
});
|
}
|
|
function enterEdge(t, g, edge) {
|
var v = edge.v,
|
w = edge.w;
|
|
// For the rest of this function we assume that v is the tail and w is the
|
// head, so if we don't have this edge in the graph we should flip it to
|
// match the correct orientation.
|
if (!g.hasEdge(v, w)) {
|
v = edge.w;
|
w = edge.v;
|
}
|
|
var vLabel = t.node(v),
|
wLabel = t.node(w),
|
tailLabel = vLabel,
|
flip = false;
|
|
// If the root is in the tail of the edge then we need to flip the logic that
|
// checks for the head and tail nodes in the candidates function below.
|
if (vLabel.lim > wLabel.lim) {
|
tailLabel = wLabel;
|
flip = true;
|
}
|
|
var candidates = _.filter(g.edges(), function(edge) {
|
return flip === isDescendant(t, t.node(edge.v), tailLabel) &&
|
flip !== isDescendant(t, t.node(edge.w), tailLabel);
|
});
|
|
return _.min(candidates, function(edge) { return slack(g, edge); });
|
}
|
|
function exchangeEdges(t, g, e, f) {
|
var v = e.v,
|
w = e.w;
|
t.removeEdge(v, w);
|
t.setEdge(f.v, f.w, {});
|
initLowLimValues(t);
|
initCutValues(t, g);
|
updateRanks(t, g);
|
}
|
|
function updateRanks(t, g) {
|
var root = _.find(t.nodes(), function(v) { return !g.node(v).parent; }),
|
vs = preorder(t, root);
|
vs = vs.slice(1);
|
_.each(vs, function(v) {
|
var parent = t.node(v).parent,
|
edge = g.edge(v, parent),
|
flipped = false;
|
|
if (!edge) {
|
edge = g.edge(parent, v);
|
flipped = true;
|
}
|
|
g.node(v).rank = g.node(parent).rank + (flipped ? edge.minlen : -edge.minlen);
|
});
|
}
|
|
/*
|
* Returns true if the edge is in the tree.
|
*/
|
function isTreeEdge(tree, u, v) {
|
return tree.hasEdge(u, v);
|
}
|
|
/*
|
* Returns true if the specified node is descendant of the root node per the
|
* assigned low and lim attributes in the tree.
|
*/
|
function isDescendant(tree, vLabel, rootLabel) {
|
return rootLabel.low <= vLabel.lim && vLabel.lim <= rootLabel.lim;
|
}
|
|
|
/***/ },
|
/* 39 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29);
|
|
module.exports = parentDummyChains;
|
|
function parentDummyChains(g) {
|
var postorderNums = postorder(g);
|
|
_.each(g.graph().dummyChains, function(v) {
|
var node = g.node(v),
|
edgeObj = node.edgeObj,
|
pathData = findPath(g, postorderNums, edgeObj.v, edgeObj.w),
|
path = pathData.path,
|
lca = pathData.lca,
|
pathIdx = 0,
|
pathV = path[pathIdx],
|
ascending = true;
|
|
while (v !== edgeObj.w) {
|
node = g.node(v);
|
|
if (ascending) {
|
while ((pathV = path[pathIdx]) !== lca &&
|
g.node(pathV).maxRank < node.rank) {
|
pathIdx++;
|
}
|
|
if (pathV === lca) {
|
ascending = false;
|
}
|
}
|
|
if (!ascending) {
|
while (pathIdx < path.length - 1 &&
|
g.node(pathV = path[pathIdx + 1]).minRank <= node.rank) {
|
pathIdx++;
|
}
|
pathV = path[pathIdx];
|
}
|
|
g.setParent(v, pathV);
|
v = g.successors(v)[0];
|
}
|
});
|
}
|
|
// Find a path from v to w through the lowest common ancestor (LCA). Return the
|
// full path and the LCA.
|
function findPath(g, postorderNums, v, w) {
|
var vPath = [],
|
wPath = [],
|
low = Math.min(postorderNums[v].low, postorderNums[w].low),
|
lim = Math.max(postorderNums[v].lim, postorderNums[w].lim),
|
parent,
|
lca;
|
|
// Traverse up from v to find the LCA
|
parent = v;
|
do {
|
parent = g.parent(parent);
|
vPath.push(parent);
|
} while (parent &&
|
(postorderNums[parent].low > low || lim > postorderNums[parent].lim));
|
lca = parent;
|
|
// Traverse from w to LCA
|
parent = w;
|
while ((parent = g.parent(parent)) !== lca) {
|
wPath.push(parent);
|
}
|
|
return { path: vPath.concat(wPath.reverse()), lca: lca };
|
}
|
|
function postorder(g) {
|
var result = {},
|
lim = 0;
|
|
function dfs(v) {
|
var low = lim;
|
_.each(g.children(v), dfs);
|
result[v] = { low: low, lim: lim++ };
|
}
|
_.each(g.children(), dfs);
|
|
return result;
|
}
|
|
|
/***/ },
|
/* 40 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29),
|
util = __webpack_require__(34);
|
|
module.exports = {
|
run: run,
|
cleanup: cleanup
|
};
|
|
/*
|
* A nesting graph creates dummy nodes for the tops and bottoms of subgraphs,
|
* adds appropriate edges to ensure that all cluster nodes are placed between
|
* these boundries, and ensures that the graph is connected.
|
*
|
* In addition we ensure, through the use of the minlen property, that nodes
|
* and subgraph border nodes to not end up on the same rank.
|
*
|
* Preconditions:
|
*
|
* 1. Input graph is a DAG
|
* 2. Nodes in the input graph has a minlen attribute
|
*
|
* Postconditions:
|
*
|
* 1. Input graph is connected.
|
* 2. Dummy nodes are added for the tops and bottoms of subgraphs.
|
* 3. The minlen attribute for nodes is adjusted to ensure nodes do not
|
* get placed on the same rank as subgraph border nodes.
|
*
|
* The nesting graph idea comes from Sander, "Layout of Compound Directed
|
* Graphs."
|
*/
|
function run(g) {
|
var root = util.addDummyNode(g, "root", {}, "_root"),
|
depths = treeDepths(g),
|
height = _.max(depths) - 1,
|
nodeSep = 2 * height + 1;
|
|
g.graph().nestingRoot = root;
|
|
// Multiply minlen by nodeSep to align nodes on non-border ranks.
|
_.each(g.edges(), function(e) { g.edge(e).minlen *= nodeSep; });
|
|
// Calculate a weight that is sufficient to keep subgraphs vertically compact
|
var weight = sumWeights(g) + 1;
|
|
// Create border nodes and link them up
|
_.each(g.children(), function(child) {
|
dfs(g, root, nodeSep, weight, height, depths, child);
|
});
|
|
// Save the multiplier for node layers for later removal of empty border
|
// layers.
|
g.graph().nodeRankFactor = nodeSep;
|
}
|
|
function dfs(g, root, nodeSep, weight, height, depths, v) {
|
var children = g.children(v);
|
if (!children.length) {
|
if (v !== root) {
|
g.setEdge(root, v, { weight: 0, minlen: nodeSep });
|
}
|
return;
|
}
|
|
var top = util.addBorderNode(g, "_bt"),
|
bottom = util.addBorderNode(g, "_bb"),
|
label = g.node(v);
|
|
g.setParent(top, v);
|
label.borderTop = top;
|
g.setParent(bottom, v);
|
label.borderBottom = bottom;
|
|
_.each(children, function(child) {
|
dfs(g, root, nodeSep, weight, height, depths, child);
|
|
var childNode = g.node(child),
|
childTop = childNode.borderTop ? childNode.borderTop : child,
|
childBottom = childNode.borderBottom ? childNode.borderBottom : child,
|
thisWeight = childNode.borderTop ? weight : 2 * weight,
|
minlen = childTop !== childBottom ? 1 : height - depths[v] + 1;
|
|
g.setEdge(top, childTop, {
|
weight: thisWeight,
|
minlen: minlen,
|
nestingEdge: true
|
});
|
|
g.setEdge(childBottom, bottom, {
|
weight: thisWeight,
|
minlen: minlen,
|
nestingEdge: true
|
});
|
});
|
|
if (!g.parent(v)) {
|
g.setEdge(root, top, { weight: 0, minlen: height + depths[v] });
|
}
|
}
|
|
function treeDepths(g) {
|
var depths = {};
|
function dfs(v, depth) {
|
var children = g.children(v);
|
if (children && children.length) {
|
_.each(children, function(child) {
|
dfs(child, depth + 1);
|
});
|
}
|
depths[v] = depth;
|
}
|
_.each(g.children(), function(v) { dfs(v, 1); });
|
return depths;
|
}
|
|
function sumWeights(g) {
|
return _.reduce(g.edges(), function(acc, e) {
|
return acc + g.edge(e).weight;
|
}, 0);
|
}
|
|
function cleanup(g) {
|
var graphLabel = g.graph();
|
g.removeNode(graphLabel.nestingRoot);
|
delete graphLabel.nestingRoot;
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
if (edge.nestingEdge) {
|
g.removeEdge(e);
|
}
|
});
|
}
|
|
|
/***/ },
|
/* 41 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29),
|
util = __webpack_require__(34);
|
|
module.exports = addBorderSegments;
|
|
function addBorderSegments(g) {
|
function dfs(v) {
|
var children = g.children(v),
|
node = g.node(v);
|
if (children.length) {
|
_.each(children, dfs);
|
}
|
|
if (_.has(node, "minRank")) {
|
node.borderLeft = [];
|
node.borderRight = [];
|
for (var rank = node.minRank, maxRank = node.maxRank + 1;
|
rank < maxRank;
|
++rank) {
|
addBorderNode(g, "borderLeft", "_bl", v, node, rank);
|
addBorderNode(g, "borderRight", "_br", v, node, rank);
|
}
|
}
|
}
|
|
_.each(g.children(), dfs);
|
}
|
|
function addBorderNode(g, prop, prefix, sg, sgNode, rank) {
|
var label = { width: 0, height: 0, rank: rank, borderType: prop },
|
prev = sgNode[prop][rank - 1],
|
curr = util.addDummyNode(g, "border", label, prefix);
|
sgNode[prop][rank] = curr;
|
g.setParent(curr, sg);
|
if (prev) {
|
g.setEdge(prev, curr, { weight: 1 });
|
}
|
}
|
|
|
/***/ },
|
/* 42 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29);
|
|
module.exports = {
|
adjust: adjust,
|
undo: undo
|
};
|
|
function adjust(g) {
|
var rankDir = g.graph().rankdir.toLowerCase();
|
if (rankDir === "lr" || rankDir === "rl") {
|
swapWidthHeight(g);
|
}
|
}
|
|
function undo(g) {
|
var rankDir = g.graph().rankdir.toLowerCase();
|
if (rankDir === "bt" || rankDir === "rl") {
|
reverseY(g);
|
}
|
|
if (rankDir === "lr" || rankDir === "rl") {
|
swapXY(g);
|
swapWidthHeight(g);
|
}
|
}
|
|
function swapWidthHeight(g) {
|
_.each(g.nodes(), function(v) { swapWidthHeightOne(g.node(v)); });
|
_.each(g.edges(), function(e) { swapWidthHeightOne(g.edge(e)); });
|
}
|
|
function swapWidthHeightOne(attrs) {
|
var w = attrs.width;
|
attrs.width = attrs.height;
|
attrs.height = w;
|
}
|
|
function reverseY(g) {
|
_.each(g.nodes(), function(v) { reverseYOne(g.node(v)); });
|
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
_.each(edge.points, reverseYOne);
|
if (_.has(edge, "y")) {
|
reverseYOne(edge);
|
}
|
});
|
}
|
|
function reverseYOne(attrs) {
|
attrs.y = -attrs.y;
|
}
|
|
function swapXY(g) {
|
_.each(g.nodes(), function(v) { swapXYOne(g.node(v)); });
|
|
_.each(g.edges(), function(e) {
|
var edge = g.edge(e);
|
_.each(edge.points, swapXYOne);
|
if (_.has(edge, "x")) {
|
swapXYOne(edge);
|
}
|
});
|
}
|
|
function swapXYOne(attrs) {
|
var x = attrs.x;
|
attrs.x = attrs.y;
|
attrs.y = x;
|
}
|
|
|
/***/ },
|
/* 43 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
initOrder = __webpack_require__(44),
|
crossCount = __webpack_require__(45),
|
sortSubgraph = __webpack_require__(46),
|
buildLayerGraph = __webpack_require__(50),
|
addSubgraphConstraints = __webpack_require__(51),
|
Graph = __webpack_require__(27).Graph,
|
util = __webpack_require__(34);
|
|
module.exports = order;
|
|
/*
|
* Applies heuristics to minimize edge crossings in the graph and sets the best
|
* order solution as an order attribute on each node.
|
*
|
* Pre-conditions:
|
*
|
* 1. Graph must be DAG
|
* 2. Graph nodes must be objects with a "rank" attribute
|
* 3. Graph edges must have the "weight" attribute
|
*
|
* Post-conditions:
|
*
|
* 1. Graph nodes will have an "order" attribute based on the results of the
|
* algorithm.
|
*/
|
function order(g) {
|
var maxRank = util.maxRank(g),
|
downLayerGraphs = buildLayerGraphs(g, _.range(1, maxRank + 1), "inEdges"),
|
upLayerGraphs = buildLayerGraphs(g, _.range(maxRank - 1, -1, -1), "outEdges");
|
|
var layering = initOrder(g);
|
assignOrder(g, layering);
|
|
var bestCC = Number.POSITIVE_INFINITY,
|
best;
|
|
for (var i = 0, lastBest = 0; lastBest < 4; ++i, ++lastBest) {
|
sweepLayerGraphs(i % 2 ? downLayerGraphs : upLayerGraphs, i % 4 >= 2);
|
|
layering = util.buildLayerMatrix(g);
|
var cc = crossCount(g, layering);
|
if (cc < bestCC) {
|
lastBest = 0;
|
best = _.cloneDeep(layering);
|
bestCC = cc;
|
}
|
}
|
|
assignOrder(g, best);
|
}
|
|
function buildLayerGraphs(g, ranks, relationship) {
|
return _.map(ranks, function(rank) {
|
return buildLayerGraph(g, rank, relationship);
|
});
|
}
|
|
function sweepLayerGraphs(layerGraphs, biasRight) {
|
var cg = new Graph();
|
_.each(layerGraphs, function(lg) {
|
var root = lg.graph().root;
|
var sorted = sortSubgraph(lg, root, cg, biasRight);
|
_.each(sorted.vs, function(v, i) {
|
lg.node(v).order = i;
|
});
|
addSubgraphConstraints(lg, cg, sorted.vs);
|
});
|
}
|
|
function assignOrder(g, layering) {
|
_.each(layering, function(layer) {
|
_.each(layer, function(v, i) {
|
g.node(v).order = i;
|
});
|
});
|
}
|
|
|
/***/ },
|
/* 44 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29);
|
|
module.exports = initOrder;
|
|
/*
|
* Assigns an initial order value for each node by performing a DFS search
|
* starting from nodes in the first rank. Nodes are assigned an order in their
|
* rank as they are first visited.
|
*
|
* This approach comes from Gansner, et al., "A Technique for Drawing Directed
|
* Graphs."
|
*
|
* Returns a layering matrix with an array per layer and each layer sorted by
|
* the order of its nodes.
|
*/
|
function initOrder(g) {
|
var visited = {},
|
simpleNodes = _.filter(g.nodes(), function(v) {
|
return !g.children(v).length;
|
}),
|
maxRank = _.max(_.map(simpleNodes, function(v) { return g.node(v).rank; })),
|
layers = _.map(_.range(maxRank + 1), function() { return []; });
|
|
function dfs(v) {
|
if (_.has(visited, v)) return;
|
visited[v] = true;
|
var node = g.node(v);
|
layers[node.rank].push(v);
|
_.each(g.successors(v), dfs);
|
}
|
|
var orderedVs = _.sortBy(simpleNodes, function(v) { return g.node(v).rank; });
|
_.each(orderedVs, dfs);
|
|
return layers;
|
}
|
|
|
/***/ },
|
/* 45 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29);
|
|
module.exports = crossCount;
|
|
/*
|
* A function that takes a layering (an array of layers, each with an array of
|
* ordererd nodes) and a graph and returns a weighted crossing count.
|
*
|
* Pre-conditions:
|
*
|
* 1. Input graph must be simple (not a multigraph), directed, and include
|
* only simple edges.
|
* 2. Edges in the input graph must have assigned weights.
|
*
|
* Post-conditions:
|
*
|
* 1. The graph and layering matrix are left unchanged.
|
*
|
* This algorithm is derived from Barth, et al., "Bilayer Cross Counting."
|
*/
|
function crossCount(g, layering) {
|
var cc = 0;
|
for (var i = 1; i < layering.length; ++i) {
|
cc += twoLayerCrossCount(g, layering[i-1], layering[i]);
|
}
|
return cc;
|
}
|
|
function twoLayerCrossCount(g, northLayer, southLayer) {
|
// Sort all of the edges between the north and south layers by their position
|
// in the north layer and then the south. Map these edges to the position of
|
// their head in the south layer.
|
var southPos = _.zipObject(southLayer,
|
_.map(southLayer, function (v, i) { return i; }));
|
var southEntries = _.flatten(_.map(northLayer, function(v) {
|
return _.chain(g.outEdges(v))
|
.map(function(e) {
|
return { pos: southPos[e.w], weight: g.edge(e).weight };
|
})
|
.sortBy("pos")
|
.value();
|
}), true);
|
|
// Build the accumulator tree
|
var firstIndex = 1;
|
while (firstIndex < southLayer.length) firstIndex <<= 1;
|
var treeSize = 2 * firstIndex - 1;
|
firstIndex -= 1;
|
var tree = _.map(new Array(treeSize), function() { return 0; });
|
|
// Calculate the weighted crossings
|
var cc = 0;
|
_.each(southEntries.forEach(function(entry) {
|
var index = entry.pos + firstIndex;
|
tree[index] += entry.weight;
|
var weightSum = 0;
|
while (index > 0) {
|
if (index % 2) {
|
weightSum += tree[index + 1];
|
}
|
index = (index - 1) >> 1;
|
tree[index] += entry.weight;
|
}
|
cc += entry.weight * weightSum;
|
}));
|
|
return cc;
|
}
|
|
|
/***/ },
|
/* 46 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29),
|
barycenter = __webpack_require__(47),
|
resolveConflicts = __webpack_require__(48),
|
sort = __webpack_require__(49);
|
|
module.exports = sortSubgraph;
|
|
function sortSubgraph(g, v, cg, biasRight) {
|
var movable = g.children(v),
|
node = g.node(v),
|
bl = node ? node.borderLeft : undefined,
|
br = node ? node.borderRight: undefined,
|
subgraphs = {};
|
|
if (bl) {
|
movable = _.filter(movable, function(w) {
|
return w !== bl && w !== br;
|
});
|
}
|
|
var barycenters = barycenter(g, movable);
|
_.each(barycenters, function(entry) {
|
if (g.children(entry.v).length) {
|
var subgraphResult = sortSubgraph(g, entry.v, cg, biasRight);
|
subgraphs[entry.v] = subgraphResult;
|
if (_.has(subgraphResult, "barycenter")) {
|
mergeBarycenters(entry, subgraphResult);
|
}
|
}
|
});
|
|
var entries = resolveConflicts(barycenters, cg);
|
expandSubgraphs(entries, subgraphs);
|
|
var result = sort(entries, biasRight);
|
|
if (bl) {
|
result.vs = _.flatten([bl, result.vs, br], true);
|
if (g.predecessors(bl).length) {
|
var blPred = g.node(g.predecessors(bl)[0]),
|
brPred = g.node(g.predecessors(br)[0]);
|
if (!_.has(result, "barycenter")) {
|
result.barycenter = 0;
|
result.weight = 0;
|
}
|
result.barycenter = (result.barycenter * result.weight +
|
blPred.order + brPred.order) / (result.weight + 2);
|
result.weight += 2;
|
}
|
}
|
|
return result;
|
}
|
|
function expandSubgraphs(entries, subgraphs) {
|
_.each(entries, function(entry) {
|
entry.vs = _.flatten(entry.vs.map(function(v) {
|
if (subgraphs[v]) {
|
return subgraphs[v].vs;
|
}
|
return v;
|
}), true);
|
});
|
}
|
|
function mergeBarycenters(target, other) {
|
if (!_.isUndefined(target.barycenter)) {
|
target.barycenter = (target.barycenter * target.weight +
|
other.barycenter * other.weight) /
|
(target.weight + other.weight);
|
target.weight += other.weight;
|
} else {
|
target.barycenter = other.barycenter;
|
target.weight = other.weight;
|
}
|
}
|
|
|
/***/ },
|
/* 47 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29);
|
|
module.exports = barycenter;
|
|
function barycenter(g, movable) {
|
return _.map(movable, function(v) {
|
var inV = g.inEdges(v);
|
if (!inV.length) {
|
return { v: v };
|
} else {
|
var result = _.reduce(inV, function(acc, e) {
|
var edge = g.edge(e),
|
nodeU = g.node(e.v);
|
return {
|
sum: acc.sum + (edge.weight * nodeU.order),
|
weight: acc.weight + edge.weight
|
};
|
}, { sum: 0, weight: 0 });
|
|
return {
|
v: v,
|
barycenter: result.sum / result.weight,
|
weight: result.weight
|
};
|
}
|
});
|
}
|
|
|
|
/***/ },
|
/* 48 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29);
|
|
module.exports = resolveConflicts;
|
|
/*
|
* Given a list of entries of the form {v, barycenter, weight} and a
|
* constraint graph this function will resolve any conflicts between the
|
* constraint graph and the barycenters for the entries. If the barycenters for
|
* an entry would violate a constraint in the constraint graph then we coalesce
|
* the nodes in the conflict into a new node that respects the contraint and
|
* aggregates barycenter and weight information.
|
*
|
* This implementation is based on the description in Forster, "A Fast and
|
* Simple Hueristic for Constrained Two-Level Crossing Reduction," thought it
|
* differs in some specific details.
|
*
|
* Pre-conditions:
|
*
|
* 1. Each entry has the form {v, barycenter, weight}, or if the node has
|
* no barycenter, then {v}.
|
*
|
* Returns:
|
*
|
* A new list of entries of the form {vs, i, barycenter, weight}. The list
|
* `vs` may either be a singleton or it may be an aggregation of nodes
|
* ordered such that they do not violate constraints from the constraint
|
* graph. The property `i` is the lowest original index of any of the
|
* elements in `vs`.
|
*/
|
function resolveConflicts(entries, cg) {
|
var mappedEntries = {};
|
_.each(entries, function(entry, i) {
|
var tmp = mappedEntries[entry.v] = {
|
indegree: 0,
|
"in": [],
|
out: [],
|
vs: [entry.v],
|
i: i
|
};
|
if (!_.isUndefined(entry.barycenter)) {
|
tmp.barycenter = entry.barycenter;
|
tmp.weight = entry.weight;
|
}
|
});
|
|
_.each(cg.edges(), function(e) {
|
var entryV = mappedEntries[e.v],
|
entryW = mappedEntries[e.w];
|
if (!_.isUndefined(entryV) && !_.isUndefined(entryW)) {
|
entryW.indegree++;
|
entryV.out.push(mappedEntries[e.w]);
|
}
|
});
|
|
var sourceSet = _.filter(mappedEntries, function(entry) {
|
return !entry.indegree;
|
});
|
|
return doResolveConflicts(sourceSet);
|
}
|
|
function doResolveConflicts(sourceSet) {
|
var entries = [];
|
|
function handleIn(vEntry) {
|
return function(uEntry) {
|
if (uEntry.merged) {
|
return;
|
}
|
if (_.isUndefined(uEntry.barycenter) ||
|
_.isUndefined(vEntry.barycenter) ||
|
uEntry.barycenter >= vEntry.barycenter) {
|
mergeEntries(vEntry, uEntry);
|
}
|
};
|
}
|
|
function handleOut(vEntry) {
|
return function(wEntry) {
|
wEntry["in"].push(vEntry);
|
if (--wEntry.indegree === 0) {
|
sourceSet.push(wEntry);
|
}
|
};
|
}
|
|
while (sourceSet.length) {
|
var entry = sourceSet.pop();
|
entries.push(entry);
|
_.each(entry["in"].reverse(), handleIn(entry));
|
_.each(entry.out, handleOut(entry));
|
}
|
|
return _.chain(entries)
|
.filter(function(entry) { return !entry.merged; })
|
.map(function(entry) {
|
return _.pick(entry, ["vs", "i", "barycenter", "weight"]);
|
})
|
.value();
|
}
|
|
function mergeEntries(target, source) {
|
var sum = 0,
|
weight = 0;
|
|
if (target.weight) {
|
sum += target.barycenter * target.weight;
|
weight += target.weight;
|
}
|
|
if (source.weight) {
|
sum += source.barycenter * source.weight;
|
weight += source.weight;
|
}
|
|
target.vs = source.vs.concat(target.vs);
|
target.barycenter = sum / weight;
|
target.weight = weight;
|
target.i = Math.min(source.i, target.i);
|
source.merged = true;
|
}
|
|
|
/***/ },
|
/* 49 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29),
|
util = __webpack_require__(34);
|
|
module.exports = sort;
|
|
function sort(entries, biasRight) {
|
var parts = util.partition(entries, function(entry) {
|
return _.has(entry, "barycenter");
|
});
|
var sortable = parts.lhs,
|
unsortable = _.sortBy(parts.rhs, function(entry) { return -entry.i; }),
|
vs = [],
|
sum = 0,
|
weight = 0,
|
vsIndex = 0;
|
|
sortable.sort(compareWithBias(!!biasRight));
|
|
vsIndex = consumeUnsortable(vs, unsortable, vsIndex);
|
|
_.each(sortable, function (entry) {
|
vsIndex += entry.vs.length;
|
vs.push(entry.vs);
|
sum += entry.barycenter * entry.weight;
|
weight += entry.weight;
|
vsIndex = consumeUnsortable(vs, unsortable, vsIndex);
|
});
|
|
var result = { vs: _.flatten(vs, true) };
|
if (weight) {
|
result.barycenter = sum / weight;
|
result.weight = weight;
|
}
|
return result;
|
}
|
|
function consumeUnsortable(vs, unsortable, index) {
|
var last;
|
while (unsortable.length && (last = _.last(unsortable)).i <= index) {
|
unsortable.pop();
|
vs.push(last.vs);
|
index++;
|
}
|
return index;
|
}
|
|
function compareWithBias(bias) {
|
return function(entryV, entryW) {
|
if (entryV.barycenter < entryW.barycenter) {
|
return -1;
|
} else if (entryV.barycenter > entryW.barycenter) {
|
return 1;
|
}
|
|
return !bias ? entryV.i - entryW.i : entryW.i - entryV.i;
|
};
|
}
|
|
|
/***/ },
|
/* 50 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29),
|
Graph = __webpack_require__(27).Graph;
|
|
module.exports = buildLayerGraph;
|
|
/*
|
* Constructs a graph that can be used to sort a layer of nodes. The graph will
|
* contain all base and subgraph nodes from the request layer in their original
|
* hierarchy and any edges that are incident on these nodes and are of the type
|
* requested by the "relationship" parameter.
|
*
|
* Nodes from the requested rank that do not have parents are assigned a root
|
* node in the output graph, which is set in the root graph attribute. This
|
* makes it easy to walk the hierarchy of movable nodes during ordering.
|
*
|
* Pre-conditions:
|
*
|
* 1. Input graph is a DAG
|
* 2. Base nodes in the input graph have a rank attribute
|
* 3. Subgraph nodes in the input graph has minRank and maxRank attributes
|
* 4. Edges have an assigned weight
|
*
|
* Post-conditions:
|
*
|
* 1. Output graph has all nodes in the movable rank with preserved
|
* hierarchy.
|
* 2. Root nodes in the movable layer are made children of the node
|
* indicated by the root attribute of the graph.
|
* 3. Non-movable nodes incident on movable nodes, selected by the
|
* relationship parameter, are included in the graph (without hierarchy).
|
* 4. Edges incident on movable nodes, selected by the relationship
|
* parameter, are added to the output graph.
|
* 5. The weights for copied edges are aggregated as need, since the output
|
* graph is not a multi-graph.
|
*/
|
function buildLayerGraph(g, rank, relationship) {
|
var root = createRootNode(g),
|
result = new Graph({ compound: true }).setGraph({ root: root })
|
.setDefaultNodeLabel(function(v) { return g.node(v); });
|
|
_.each(g.nodes(), function(v) {
|
var node = g.node(v),
|
parent = g.parent(v);
|
|
if (node.rank === rank || node.minRank <= rank && rank <= node.maxRank) {
|
result.setNode(v);
|
result.setParent(v, parent || root);
|
|
// This assumes we have only short edges!
|
_.each(g[relationship](v), function(e) {
|
var u = e.v === v ? e.w : e.v,
|
edge = result.edge(u, v),
|
weight = !_.isUndefined(edge) ? edge.weight : 0;
|
result.setEdge(u, v, { weight: g.edge(e).weight + weight });
|
});
|
|
if (_.has(node, "minRank")) {
|
result.setNode(v, {
|
borderLeft: node.borderLeft[rank],
|
borderRight: node.borderRight[rank]
|
});
|
}
|
}
|
});
|
|
return result;
|
}
|
|
function createRootNode(g) {
|
var v;
|
while (g.hasNode((v = _.uniqueId("_root"))));
|
return v;
|
}
|
|
|
/***/ },
|
/* 51 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29);
|
|
module.exports = addSubgraphConstraints;
|
|
function addSubgraphConstraints(g, cg, vs) {
|
var prev = {},
|
rootPrev;
|
|
_.each(vs, function(v) {
|
var child = g.parent(v),
|
parent,
|
prevChild;
|
while (child) {
|
parent = g.parent(child);
|
if (parent) {
|
prevChild = prev[parent];
|
prev[parent] = child;
|
} else {
|
prevChild = rootPrev;
|
rootPrev = child;
|
}
|
if (prevChild && prevChild !== child) {
|
cg.setEdge(prevChild, child);
|
return;
|
}
|
child = parent;
|
}
|
});
|
|
/*
|
function dfs(v) {
|
var children = v ? g.children(v) : g.children();
|
if (children.length) {
|
var min = Number.POSITIVE_INFINITY,
|
subgraphs = [];
|
_.each(children, function(child) {
|
var childMin = dfs(child);
|
if (g.children(child).length) {
|
subgraphs.push({ v: child, order: childMin });
|
}
|
min = Math.min(min, childMin);
|
});
|
_.reduce(_.sortBy(subgraphs, "order"), function(prev, curr) {
|
cg.setEdge(prev.v, curr.v);
|
return curr;
|
});
|
return min;
|
}
|
return g.node(v).order;
|
}
|
dfs(undefined);
|
*/
|
}
|
|
|
/***/ },
|
/* 52 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
util = __webpack_require__(34),
|
positionX = __webpack_require__(53).positionX;
|
|
module.exports = position;
|
|
function position(g) {
|
g = util.asNonCompoundGraph(g);
|
|
positionY(g);
|
_.each(positionX(g), function(x, v) {
|
g.node(v).x = x;
|
});
|
}
|
|
function positionY(g) {
|
var layering = util.buildLayerMatrix(g),
|
rankSep = g.graph().ranksep,
|
prevY = 0;
|
_.each(layering, function(layer) {
|
var maxHeight = _.max(_.map(layer, function(v) { return g.node(v).height; }));
|
_.each(layer, function(v) {
|
g.node(v).y = prevY + maxHeight / 2;
|
});
|
prevY += maxHeight + rankSep;
|
});
|
}
|
|
|
|
/***/ },
|
/* 53 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
"use strict";
|
|
var _ = __webpack_require__(29),
|
Graph = __webpack_require__(27).Graph,
|
util = __webpack_require__(34);
|
|
/*
|
* This module provides coordinate assignment based on Brandes and Köpf, "Fast
|
* and Simple Horizontal Coordinate Assignment."
|
*/
|
|
module.exports = {
|
positionX: positionX,
|
findType1Conflicts: findType1Conflicts,
|
findType2Conflicts: findType2Conflicts,
|
addConflict: addConflict,
|
hasConflict: hasConflict,
|
verticalAlignment: verticalAlignment,
|
horizontalCompaction: horizontalCompaction,
|
alignCoordinates: alignCoordinates,
|
findSmallestWidthAlignment: findSmallestWidthAlignment,
|
balance: balance
|
};
|
|
/*
|
* Marks all edges in the graph with a type-1 conflict with the "type1Conflict"
|
* property. A type-1 conflict is one where a non-inner segment crosses an
|
* inner segment. An inner segment is an edge with both incident nodes marked
|
* with the "dummy" property.
|
*
|
* This algorithm scans layer by layer, starting with the second, for type-1
|
* conflicts between the current layer and the previous layer. For each layer
|
* it scans the nodes from left to right until it reaches one that is incident
|
* on an inner segment. It then scans predecessors to determine if they have
|
* edges that cross that inner segment. At the end a final scan is done for all
|
* nodes on the current rank to see if they cross the last visited inner
|
* segment.
|
*
|
* This algorithm (safely) assumes that a dummy node will only be incident on a
|
* single node in the layers being scanned.
|
*/
|
function findType1Conflicts(g, layering) {
|
var conflicts = {};
|
|
function visitLayer(prevLayer, layer) {
|
var
|
// last visited node in the previous layer that is incident on an inner
|
// segment.
|
k0 = 0,
|
// Tracks the last node in this layer scanned for crossings with a type-1
|
// segment.
|
scanPos = 0,
|
prevLayerLength = prevLayer.length,
|
lastNode = _.last(layer);
|
|
_.each(layer, function(v, i) {
|
var w = findOtherInnerSegmentNode(g, v),
|
k1 = w ? g.node(w).order : prevLayerLength;
|
|
if (w || v === lastNode) {
|
_.each(layer.slice(scanPos, i +1), function(scanNode) {
|
_.each(g.predecessors(scanNode), function(u) {
|
var uLabel = g.node(u),
|
uPos = uLabel.order;
|
if ((uPos < k0 || k1 < uPos) &&
|
!(uLabel.dummy && g.node(scanNode).dummy)) {
|
addConflict(conflicts, u, scanNode);
|
}
|
});
|
});
|
scanPos = i + 1;
|
k0 = k1;
|
}
|
});
|
|
return layer;
|
}
|
|
_.reduce(layering, visitLayer);
|
return conflicts;
|
}
|
|
function findType2Conflicts(g, layering) {
|
var conflicts = {};
|
|
function scan(south, southPos, southEnd, prevNorthBorder, nextNorthBorder) {
|
var v;
|
_.each(_.range(southPos, southEnd), function(i) {
|
v = south[i];
|
if (g.node(v).dummy) {
|
_.each(g.predecessors(v), function(u) {
|
var uNode = g.node(u);
|
if (uNode.dummy &&
|
(uNode.order < prevNorthBorder || uNode.order > nextNorthBorder)) {
|
addConflict(conflicts, u, v);
|
}
|
});
|
}
|
});
|
}
|
|
|
function visitLayer(north, south) {
|
var prevNorthPos = -1,
|
nextNorthPos,
|
southPos = 0;
|
|
_.each(south, function(v, southLookahead) {
|
if (g.node(v).dummy === "border") {
|
var predecessors = g.predecessors(v);
|
if (predecessors.length) {
|
nextNorthPos = g.node(predecessors[0]).order;
|
scan(south, southPos, southLookahead, prevNorthPos, nextNorthPos);
|
southPos = southLookahead;
|
prevNorthPos = nextNorthPos;
|
}
|
}
|
scan(south, southPos, south.length, nextNorthPos, north.length);
|
});
|
|
return south;
|
}
|
|
_.reduce(layering, visitLayer);
|
return conflicts;
|
}
|
|
function findOtherInnerSegmentNode(g, v) {
|
if (g.node(v).dummy) {
|
return _.find(g.predecessors(v), function(u) {
|
return g.node(u).dummy;
|
});
|
}
|
}
|
|
function addConflict(conflicts, v, w) {
|
if (v > w) {
|
var tmp = v;
|
v = w;
|
w = tmp;
|
}
|
|
var conflictsV = conflicts[v];
|
if (!conflictsV) {
|
conflicts[v] = conflictsV = {};
|
}
|
conflictsV[w] = true;
|
}
|
|
function hasConflict(conflicts, v, w) {
|
if (v > w) {
|
var tmp = v;
|
v = w;
|
w = tmp;
|
}
|
return _.has(conflicts[v], w);
|
}
|
|
/*
|
* Try to align nodes into vertical "blocks" where possible. This algorithm
|
* attempts to align a node with one of its median neighbors. If the edge
|
* connecting a neighbor is a type-1 conflict then we ignore that possibility.
|
* If a previous node has already formed a block with a node after the node
|
* we're trying to form a block with, we also ignore that possibility - our
|
* blocks would be split in that scenario.
|
*/
|
function verticalAlignment(g, layering, conflicts, neighborFn) {
|
var root = {},
|
align = {},
|
pos = {};
|
|
// We cache the position here based on the layering because the graph and
|
// layering may be out of sync. The layering matrix is manipulated to
|
// generate different extreme alignments.
|
_.each(layering, function(layer) {
|
_.each(layer, function(v, order) {
|
root[v] = v;
|
align[v] = v;
|
pos[v] = order;
|
});
|
});
|
|
_.each(layering, function(layer) {
|
var prevIdx = -1;
|
_.each(layer, function(v) {
|
var ws = neighborFn(v);
|
if (ws.length) {
|
ws = _.sortBy(ws, function(w) { return pos[w]; });
|
var mp = (ws.length - 1) / 2;
|
for (var i = Math.floor(mp), il = Math.ceil(mp); i <= il; ++i) {
|
var w = ws[i];
|
if (align[v] === v &&
|
prevIdx < pos[w] &&
|
!hasConflict(conflicts, v, w)) {
|
align[w] = v;
|
align[v] = root[v] = root[w];
|
prevIdx = pos[w];
|
}
|
}
|
}
|
});
|
});
|
|
return { root: root, align: align };
|
}
|
|
function horizontalCompaction(g, layering, root, align, reverseSep) {
|
// This portion of the algorithm differs from BK due to a number of problems.
|
// Instead of their algorithm we construct a new block graph and do two
|
// sweeps. The first sweep places blocks with the smallest possible
|
// coordinates. The second sweep removes unused space by moving blocks to the
|
// greatest coordinates without violating separation.
|
var xs = {},
|
blockG = buildBlockGraph(g, layering, root, reverseSep);
|
|
// First pass, assign smallest coordinates via DFS
|
var visited = {};
|
function pass1(v) {
|
if (!_.has(visited, v)) {
|
visited[v] = true;
|
xs[v] = _.reduce(blockG.inEdges(v), function(max, e) {
|
pass1(e.v);
|
return Math.max(max, xs[e.v] + blockG.edge(e));
|
}, 0);
|
}
|
}
|
_.each(blockG.nodes(), pass1);
|
|
var borderType = reverseSep ? "borderLeft" : "borderRight";
|
function pass2(v) {
|
if (visited[v] !== 2) {
|
visited[v]++;
|
var node = g.node(v);
|
var min = _.reduce(blockG.outEdges(v), function(min, e) {
|
pass2(e.w);
|
return Math.min(min, xs[e.w] - blockG.edge(e));
|
}, Number.POSITIVE_INFINITY);
|
if (min !== Number.POSITIVE_INFINITY && node.borderType !== borderType) {
|
xs[v] = Math.max(xs[v], min);
|
}
|
}
|
}
|
_.each(blockG.nodes(), pass2);
|
|
// Assign x coordinates to all nodes
|
_.each(align, function(v) {
|
xs[v] = xs[root[v]];
|
});
|
|
return xs;
|
}
|
|
|
function buildBlockGraph(g, layering, root, reverseSep) {
|
var blockGraph = new Graph(),
|
graphLabel = g.graph(),
|
sepFn = sep(graphLabel.nodesep, graphLabel.edgesep, reverseSep);
|
|
_.each(layering, function(layer) {
|
var u;
|
_.each(layer, function(v) {
|
var vRoot = root[v];
|
blockGraph.setNode(vRoot);
|
if (u) {
|
var uRoot = root[u],
|
prevMax = blockGraph.edge(uRoot, vRoot);
|
blockGraph.setEdge(uRoot, vRoot, Math.max(sepFn(g, v, u), prevMax || 0));
|
}
|
u = v;
|
});
|
});
|
|
return blockGraph;
|
}
|
|
/*
|
* Returns the alignment that has the smallest width of the given alignments.
|
*/
|
function findSmallestWidthAlignment(g, xss) {
|
return _.min(xss, function(xs) {
|
var min = _.min(xs, function(x, v) { return x - width(g, v) / 2; }),
|
max = _.max(xs, function(x, v) { return x + width(g, v) / 2; });
|
return max - min;
|
});
|
}
|
|
/*
|
* Align the coordinates of each of the layout alignments such that
|
* left-biased alignments have their minimum coordinate at the same point as
|
* the minimum coordinate of the smallest width alignment and right-biased
|
* alignments have their maximum coordinate at the same point as the maximum
|
* coordinate of the smallest width alignment.
|
*/
|
function alignCoordinates(xss, alignTo) {
|
var alignToMin = _.min(alignTo),
|
alignToMax = _.max(alignTo);
|
|
_.each(["u", "d"], function(vert) {
|
_.each(["l", "r"], function(horiz) {
|
var alignment = vert + horiz,
|
xs = xss[alignment],
|
delta;
|
if (xs === alignTo) return;
|
|
delta = horiz === "l" ? alignToMin - _.min(xs) : alignToMax - _.max(xs);
|
|
if (delta) {
|
xss[alignment] = _.mapValues(xs, function(x) { return x + delta; });
|
}
|
});
|
});
|
}
|
|
function balance(xss, align) {
|
return _.mapValues(xss.ul, function(ignore, v) {
|
if (align) {
|
return xss[align.toLowerCase()][v];
|
} else {
|
var xs = _.sortBy(_.pluck(xss, v));
|
return (xs[1] + xs[2]) / 2;
|
}
|
});
|
}
|
|
function positionX(g) {
|
var layering = util.buildLayerMatrix(g),
|
conflicts = _.merge(findType1Conflicts(g, layering),
|
findType2Conflicts(g, layering));
|
|
var xss = {},
|
adjustedLayering;
|
_.each(["u", "d"], function(vert) {
|
adjustedLayering = vert === "u" ? layering : _.values(layering).reverse();
|
_.each(["l", "r"], function(horiz) {
|
if (horiz === "r") {
|
adjustedLayering = _.map(adjustedLayering, function(inner) {
|
return _.values(inner).reverse();
|
});
|
}
|
|
var neighborFn = _.bind(vert === "u" ? g.predecessors : g.successors, g);
|
var align = verticalAlignment(g, adjustedLayering, conflicts, neighborFn);
|
var xs = horizontalCompaction(g, adjustedLayering,
|
align.root, align.align,
|
horiz === "r");
|
if (horiz === "r") {
|
xs = _.mapValues(xs, function(x) { return -x; });
|
}
|
xss[vert + horiz] = xs;
|
});
|
});
|
|
var smallestWidth = findSmallestWidthAlignment(g, xss);
|
alignCoordinates(xss, smallestWidth);
|
return balance(xss, g.graph().align);
|
}
|
|
function sep(nodeSep, edgeSep, reverseSep) {
|
return function(g, v, w) {
|
var vLabel = g.node(v),
|
wLabel = g.node(w),
|
sum = 0,
|
delta;
|
|
sum += vLabel.width / 2;
|
if (_.has(vLabel, "labelpos")) {
|
switch (vLabel.labelpos.toLowerCase()) {
|
case "l": delta = -vLabel.width / 2; break;
|
case "r": delta = vLabel.width / 2; break;
|
}
|
}
|
if (delta) {
|
sum += reverseSep ? delta : -delta;
|
}
|
delta = 0;
|
|
sum += (vLabel.dummy ? edgeSep : nodeSep) / 2;
|
sum += (wLabel.dummy ? edgeSep : nodeSep) / 2;
|
|
sum += wLabel.width / 2;
|
if (_.has(wLabel, "labelpos")) {
|
switch (wLabel.labelpos.toLowerCase()) {
|
case "l": delta = wLabel.width / 2; break;
|
case "r": delta = -wLabel.width / 2; break;
|
}
|
}
|
if (delta) {
|
sum += reverseSep ? delta : -delta;
|
}
|
delta = 0;
|
|
return sum;
|
};
|
}
|
|
function width(g, v) {
|
return g.node(v).width;
|
}
|
|
|
/***/ },
|
/* 54 */
|
/***/ function(module, exports, __webpack_require__) {
|
|
var _ = __webpack_require__(29),
|
util = __webpack_require__(34),
|
Graph = __webpack_require__(27).Graph;
|
|
module.exports = {
|
debugOrdering: debugOrdering
|
};
|
|
/* istanbul ignore next */
|
function debugOrdering(g) {
|
var layerMatrix = util.buildLayerMatrix(g);
|
|
var h = new Graph({ compound: true, multigraph: true }).setGraph({});
|
|
_.each(g.nodes(), function(v) {
|
h.setNode(v, { label: v });
|
h.setParent(v, "layer" + g.node(v).rank);
|
});
|
|
_.each(g.edges(), function(e) {
|
h.setEdge(e.v, e.w, {}, e.name);
|
});
|
|
_.each(layerMatrix, function(layer, i) {
|
var layerV = "layer" + i;
|
h.setNode(layerV, { rank: "same" });
|
_.reduce(layer, function(u, v) {
|
h.setEdge(u, v, { style: "invis" });
|
return v;
|
});
|
});
|
|
return h;
|
}
|
|
|
/***/ },
|
/* 55 */
|
/***/ function(module, exports) {
|
|
module.exports = "0.7.4";
|
|
|
/***/ }
|
/******/ ]);
|