L.Clipper=L.Evented.extend({options:{selectedPathOptions:{color:"#FF3399"}},initialize:function(e,t){L.Handler.prototype.initialize.call(this,e);L.Util.setOptions(this,t);if(!(this.options.featureGroup instanceof L.FeatureGroup)){throw new Error("options.featureGroup must be a L.FeatureGroup")}},enable:function(){if(this._enabled||!this._hasAvailableLayers()){return}this.fire("enabled",{handler:this.type});this._map.fire("draw:joinstart",{handler:this.type});L.Handler.prototype.enable.call(this);this.options.featureGroup.on("layeradd",this._enableLayerEdit,this).on("layerremove",this._disableLayerEdit,this)},disable:function(){if(!this._enabled){return}this.options.featureGroup.off("layeradd",this._enableLayerJoin,this).off("layerremove",this._disableLayerJoin,this);L.Handler.prototype.disable.call(this);this._map.fire("draw:editstop",{handler:this.type});this.fire("disabled",{handler:this.type})},addHooks:function(){var e=this._map;if(e){e.getContainer().focus();this.options.featureGroup.eachLayer(this._enableLayerEdit,this)}},removeHooks:function(){if(this._map){this.options.featureGroup.eachLayer(this._disableLayerEdit,this);this._uneditedLayerProps={};this._tooltip.dispose();this._tooltip=null;this._map.off("mousemove",this._onMouseMove,this)}},revertLayers:function(){this.options.featureGroup.eachLayer(function(e){this._revertLayer(e)},this)},save:function(){var e=new L.LayerGroup;this.options.featureGroup.eachLayer(function(t){if(t.edited){e.addLayer(t);t.edited=false}});this._map.fire("draw:edited",{layers:e})},_revertLayer:function(e){var t=L.Util.stamp(e);e.edited=false;if(this._uneditedLayerProps.hasOwnProperty(t)){if(e instanceof L.Polyline||e instanceof L.Polygon||e instanceof L.Rectangle){e.setLatLngs(this._uneditedLayerProps[t].latlngs)}else if(e instanceof L.Circle){e.setLatLng(this._uneditedLayerProps[t].latlng);e.setRadius(this._uneditedLayerProps[t].radius)}else if(e instanceof L.Marker){e.setLatLng(this._uneditedLayerProps[t].latlng)}}},_enableLayerEdit:function(e){var t=e.layer||e.target||e;t.on("click",this._subjectLayer,this)},_disableLayerEdit:function(e){var t=e.layer||e.target||e;t.off("click")},_onMouseMove:function(e){this._tooltip.updatePosition(e.latlng)},_hasAvailableLayers:function(){return this.options.featureGroup.getLayers().length!==0},_subjectLayer:function(e){var t=e.layer||e.target||e;if(!this._subject){this._subject=t}else{this._clipperLayer(e)}t.setStyle(this.options.selectedPathOptions)},_clipperLayer:function(e){var t=e.layer||e.target||e;this._clipper=t;t.setStyle(this.options.selectedPathOptions);this._layerClip()},_layerClip:function(){var e=this._subject.getLatLngs();var t=this._clipper.getLatLngs();var i=this._coordsToPoints(e);var r=this._coordsToPoints(t);var s=ClipperLib.Paths();var o=new ClipperLib.Clipper;for(var a=0,n=i.length;a