text: ;(function(){ 'use strict';
    
    var bendPointUtilities = require('./bendPointUtilities');
    var debounce = require("./debounce");
    
    // registers the extension on a cytoscape lib ref
    var register = function( cytoscape ){
      var uiUtilities = require('./UIUtilities');
      
      if( !cytoscape ){ return; } // can't register if cytoscape unspecified
  
      var defaults = {
        // this function specifies the poitions of bend points
        bendPositionsFunction: function(ele) {
          return ele.data('bendPointPositions');
        },
        // whether to initilize bend points on creation of this extension automatically
        initBendPointsAutomatically: true,
        // the classes of those edges that should be ignored
        ignoredClasses: [],
        // whether the bend editing operations are undoable (requires cytoscape-undo-redo.js)
        undoable: false,
        // the size of bend shape is obtained by multipling width of edge with this parameter
        bendShapeSizeFactor: 3,
        // z-index value of the canvas in which bend points are drawn
        zIndex: 999,      
        // whether to start the plugin in the enabled state
        enabled: true,
        //An option that controls the distance within which a bend point is considered "near" the line segment between its two neighbors and will be automatically removed
        bendRemovalSensitivity : 8,
        // title of add bend point menu item (User may need to adjust width of menu items according to length of this option)
        addBendMenuItemTitle: "Add Bend Point",
        // title of remove bend point menu item (User may need to adjust width of menu items according to length of this option)
        removeBendMenuItemTitle: "Remove Bend Point",
        // whether the bend point can be moved by arrows
        moveSelectedBendPointsOnKeyEvents: function () {
            return true;
        }
      };
      
      var options;
      var initialized = false;
      
      // Merge default options with the ones coming from parameter
      function extend(defaults, options) {
        var obj = {};
  
        for (var i in defaults) {
          obj[i] = defaults[i];
        }
  
        for (var i in options) {
          if(i == "bendRemovalSensitivity"){
            var value = options[i];
             if(!isNaN(value))
             {
                if(value >= 0 && value <= 20){
                  obj[i] = options[i];
                }else if(value < 0){
                  obj[i] = 0
                }else{
                  obj[i] = 20
                }
             }
          }else{
            obj[i] = options[i];
          }
  
        }
  
        return obj;
      };
      
      cytoscape( 'core', 'edgeEditing', function(opts){
        var cy = this;
        
        if( opts === 'initialized' ) {
          return initialized;
        }
        
        if( opts !== 'get' ) {
          // merge the options with default ones
          options = extend(defaults, opts);
          initialized = true;
  
          // define edgebendediting-hasbendpoints css class
          cy.style().selector('.edgebendediting-hasbendpoints').css({
            'curve-style': 'segments',
            'segment-distances': function (ele) {
              return bendPointUtilities.getSegmentDistancesString(ele);
            },
            'segment-weights': function (ele) {
              return bendPointUtilities.getSegmentWeightsString(ele);
            },
            'edge-distances': 'node-position'
          });
  
          bendPointUtilities.setIgnoredClasses(options.ignoredClasses);
  
          // init bend positions conditionally
          if (options.initBendPointsAutomatically) {
            bendPointUtilities.initBendPoints(options.bendPositionsFunction, cy.edges(), options.ignoredClasses);
          }
  
          if(options.enabled)
            uiUtilities(options, cy);
          else
            uiUtilities("unbind", cy);
        }
        
        var instance = initialized ? {
          /*
          * get segment points of the given edge in an array A,
          * A[2 * i] is the x coordinate and A[2 * i + 1] is the y coordinate
          * of the ith bend point. (Returns undefined if the curve style is not segments)
          */
          getSegmentPoints: function(ele) {
            return bendPointUtilities.getSegmentPoints(ele);
          },
          // Initilize bend points for the given edges using 'options.bendPositionsFunction'
          initBendPoints: function(eles) {
            bendPointUtilities.initBendPoints(options.bendPositionsFunction, eles);
          },
          deleteSelectedBendPoint: function(ele, index) {
            bendPointUtilities.removeBendPoint(ele,index);
          }
        } : undefined;
  
        return instance; // chainability
      } );
  
    };
  
    if( typeof module !== 'undefined' && module.exports ){ // expose as a commonjs module
      module.exports = register;
    }
  
    if( typeof define !== 'undefined' && define.amd ){ // expose as an amd/requirejs module
      define('cytoscape-edge-editing', function(){
        return register;
      });
    }
  
    if( typeof cytoscape !== 'undefined' ){ // expose to global cytoscape (i.e. window.cytoscape)
      register( cytoscape );
    }
  
  })();
  