svg.select.js
Advanced tools
Comparing version 3.0.0 to 3.0.1
/*! | ||
* svg.select.js - An extension of svg.js which allows to select elements with mouse | ||
* @version 3.0.0 | ||
* @version 3.0.1 | ||
* https://github.com/svgdotjs/svg.select.js | ||
@@ -25,11 +25,13 @@ * | ||
lb: [ 0, 'height' ], | ||
t: [ 'width / 2', 0 ], | ||
r: [ 'width', 'height / 2' ], | ||
b: [ 'width / 2', 'height' ], | ||
l: [ 0, 'height / 2' ] | ||
t: [ 'width', 0 ], | ||
r: [ 'width', 'height' ], | ||
b: [ 'width', 'height' ], | ||
l: [ 0, 'height' ] | ||
}; | ||
// helper function to evaluate point coordinates based on settings above and an object (bbox in our case) | ||
this.pointCoord = function (setting, object) { | ||
return typeof setting !== 'string' ? setting : eval('object.' + setting) | ||
// helper function to get point coordinates based on settings above and an object (bbox in our case) | ||
this.pointCoord = function (setting, object, isPointCentered) { | ||
var coord = typeof setting !== 'string' ? setting : object[setting]; | ||
// Top, bottom, right and left points are placed in the center of element width/height | ||
return isPointCentered ? coord / 2 : coord | ||
} | ||
@@ -41,4 +43,4 @@ | ||
return { | ||
x: this.pointCoord(settings[0], object), | ||
y: this.pointCoord(settings[1], object) | ||
x: this.pointCoord(settings[0], object, (point === 't' || point === 'b')), | ||
y: this.pointCoord(settings[1], object, (point === 'r' || point === 'l')) | ||
} | ||
@@ -45,0 +47,0 @@ } |
@@ -1,1 +0,1 @@ | ||
/*! svg.select.js v3.0.0 MIT*/;!function(){"use strict";function SelectHandler(el){this.el=el,el.remember("_selectHandler",this),this.pointSelection={isSelected:!1},this.rectSelection={isSelected:!1},this.pointsList={lt:[0,0],rt:["width",0],rb:["width","height"],lb:[0,"height"],t:["width / 2",0],r:["width","height / 2"],b:["width / 2","height"],l:[0,"height / 2"]},this.pointCoord=function(setting,object){return"string"!=typeof setting?setting:eval("object."+setting)},this.pointCoords=function(t,e){var i=this.pointsList[t];return{x:this.pointCoord(i[0],e),y:this.pointCoord(i[1],e)}}}SelectHandler.prototype.init=function(t,e){var i=this.el.bbox();this.options={};var n=this.el.selectize.defaults.points;for(var s in this.el.selectize.defaults)this.options[s]=this.el.selectize.defaults[s],void 0!==e[s]&&(this.options[s]=e[s]);var o=["points","pointsExclude"];for(var s in o){var r=this.options[o[s]];"string"==typeof r?r=r.length>0?r.split(/\s*,\s*/i):[]:"boolean"==typeof r&&"points"===o[s]&&(r=r?n:[]),this.options[o[s]]=r}this.options.points=[n,this.options.points].reduce(function(t,e){return t.filter(function(t){return e.indexOf(t)>-1})}),this.options.points=[this.options.points,this.options.pointsExclude].reduce(function(t,e){return t.filter(function(t){return e.indexOf(t)<0})}),this.parent=this.el.parent(),this.nested=this.nested||this.parent.group(),this.nested.matrix(new SVG.Matrix(this.el).translate(i.x,i.y)),this.options.deepSelect&&-1!==["line","polyline","polygon"].indexOf(this.el.type)?this.selectPoints(t):this.selectRect(t),this.observe(),this.cleanup()},SelectHandler.prototype.selectPoints=function(t){return this.pointSelection.isSelected=t,this.pointSelection.set?this:(this.pointSelection.set=this.parent.set(),this.drawPoints(),this)},SelectHandler.prototype.getPointArray=function(){var t=this.el.bbox();return this.el.array().valueOf().map(function(e){return[e[0]-t.x,e[1]-t.y]})},SelectHandler.prototype.drawPoints=function(){for(var t=this,e=this.getPointArray(),i=0,n=e.length;i<n;++i){var s=function(e){return function(i){i=i||window.event,i.preventDefault?i.preventDefault():i.returnValue=!1,i.stopPropagation();var n=i.pageX||i.touches[0].pageX,s=i.pageY||i.touches[0].pageY;t.el.fire("point",{x:n,y:s,i:e,event:i})}}(i),o=this.drawPoint(e[i][0],e[i][1]).addClass(this.options.classPoints).addClass(this.options.classPoints+"_point").on("touchstart",s).on("mousedown",s);this.pointSelection.set.add(o)}},SelectHandler.prototype.drawPoint=function(t,e){var i=this.options.pointType;switch(i){case"circle":return this.drawCircle(t,e);case"rect":return this.drawRect(t,e);default:if("function"==typeof i)return i.call(this,t,e);throw new Error("Unknown "+i+" point type!")}},SelectHandler.prototype.drawCircle=function(t,e){return this.nested.circle(this.options.pointSize).center(t,e)},SelectHandler.prototype.drawRect=function(t,e){return this.nested.rect(this.options.pointSize,this.options.pointSize).center(t,e)},SelectHandler.prototype.updatePointSelection=function(){var t=this.getPointArray();this.pointSelection.set.each(function(e){this.cx()===t[e][0]&&this.cy()===t[e][1]||this.center(t[e][0],t[e][1])})},SelectHandler.prototype.updateRectSelection=function(){var t=this,e=this.el.bbox();if(this.rectSelection.set.get(0).attr({width:e.width,height:e.height}),this.options.points.length&&this.options.points.map(function(i,n){var s=t.pointCoords(i,e);t.rectSelection.set.get(n+1).center(s.x,s.y)}),this.options.rotationPoint){var i=this.rectSelection.set.length();this.rectSelection.set.get(i-1).center(e.width/2,20)}},SelectHandler.prototype.selectRect=function(t){function e(t){return function(e){e=e||window.event,e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation();var n=e.pageX||e.touches[0].pageX,s=e.pageY||e.touches[0].pageY;i.el.fire(t,{x:n,y:s,event:e})}}var i=this,n=this.el.bbox();if(this.rectSelection.isSelected=t,this.rectSelection.set=this.rectSelection.set||this.parent.set(),this.rectSelection.set.get(0)||this.rectSelection.set.add(this.nested.rect(n.width,n.height).addClass(this.options.classRect)),this.options.points.length&&this.rectSelection.set.length()<2){this.options.points.map(function(t,s){var o=i.pointCoords(t,n),r=i.drawPoint(o.x,o.y).attr("class",i.options.classPoints+"_"+t).on("mousedown",e(t)).on("touchstart",e(t));i.rectSelection.set.add(r)}),this.rectSelection.set.each(function(){this.addClass(i.options.classPoints)})}if(this.options.rotationPoint&&(this.options.points&&!this.rectSelection.set.get(9)||!this.options.points&&!this.rectSelection.set.get(1))){var s=function(t){t=t||window.event,t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation();var e=t.pageX||t.touches[0].pageX,n=t.pageY||t.touches[0].pageY;i.el.fire("rot",{x:e,y:n,event:t})},o=this.drawPoint(n.width/2,20).attr("class",this.options.classPoints+"_rot").on("touchstart",s).on("mousedown",s);this.rectSelection.set.add(o)}},SelectHandler.prototype.handler=function(){var t=this.el.bbox();this.nested.matrix(new SVG.Matrix(this.el).translate(t.x,t.y)),this.rectSelection.isSelected&&this.updateRectSelection(),this.pointSelection.isSelected&&this.updatePointSelection()},SelectHandler.prototype.observe=function(){var t=this;if(MutationObserver)if(this.rectSelection.isSelected||this.pointSelection.isSelected)this.observerInst=this.observerInst||new MutationObserver(function(){t.handler()}),this.observerInst.observe(this.el.node,{attributes:!0});else try{this.observerInst.disconnect(),delete this.observerInst}catch(t){}else this.el.off("DOMAttrModified.select"),(this.rectSelection.isSelected||this.pointSelection.isSelected)&&this.el.on("DOMAttrModified.select",function(){t.handler()})},SelectHandler.prototype.cleanup=function(){!this.rectSelection.isSelected&&this.rectSelection.set&&(this.rectSelection.set.each(function(){this.remove()}),this.rectSelection.set.clear(),delete this.rectSelection.set),!this.pointSelection.isSelected&&this.pointSelection.set&&(this.pointSelection.set.each(function(){this.remove()}),this.pointSelection.set.clear(),delete this.pointSelection.set),this.pointSelection.isSelected||this.rectSelection.isSelected||(this.nested.remove(),delete this.nested)},SVG.extend(SVG.Element,{selectize:function(t,e){return"object"==typeof t&&(e=t,t=!0),(this.remember("_selectHandler")||new SelectHandler(this)).init(void 0===t||t,e||{}),this}}),SVG.Element.prototype.selectize.defaults={points:["lt","rt","rb","lb","t","r","b","l"],pointsExclude:[],classRect:"svg_select_boundingRect",classPoints:"svg_select_points",pointSize:7,rotationPoint:!0,deepSelect:!1,pointType:"circle"}}(); | ||
/*! svg.select.js v3.0.1 MIT*/;!function(){"use strict";function i(t){(this.el=t).remember("_selectHandler",this),this.pointSelection={isSelected:!1},this.rectSelection={isSelected:!1},this.pointsList={lt:[0,0],rt:["width",0],rb:["width","height"],lb:[0,"height"],t:["width",0],r:["width","height"],b:["width","height"],l:[0,"height"]},this.pointCoord=function(t,e,i){var s="string"!=typeof t?t:e[t];return i?s/2:s},this.pointCoords=function(t,e){var i=this.pointsList[t];return{x:this.pointCoord(i[0],e,"t"===t||"b"===t),y:this.pointCoord(i[1],e,"r"===t||"l"===t)}}}i.prototype.init=function(t,e){var i=this.el.bbox();this.options={};var s=this.el.selectize.defaults.points;for(var n in this.el.selectize.defaults)this.options[n]=this.el.selectize.defaults[n],void 0!==e[n]&&(this.options[n]=e[n]);var o=["points","pointsExclude"];for(var n in o){var r=this.options[o[n]];"string"==typeof r?r=0<r.length?r.split(/\s*,\s*/i):[]:"boolean"==typeof r&&"points"===o[n]&&(r=r?s:[]),this.options[o[n]]=r}this.options.points=[s,this.options.points].reduce(function(t,e){return t.filter(function(t){return-1<e.indexOf(t)})}),this.options.points=[this.options.points,this.options.pointsExclude].reduce(function(t,e){return t.filter(function(t){return e.indexOf(t)<0})}),this.parent=this.el.parent(),this.nested=this.nested||this.parent.group(),this.nested.matrix(new SVG.Matrix(this.el).translate(i.x,i.y)),this.options.deepSelect&&-1!==["line","polyline","polygon"].indexOf(this.el.type)?this.selectPoints(t):this.selectRect(t),this.observe(),this.cleanup()},i.prototype.selectPoints=function(t){return this.pointSelection.isSelected=t,this.pointSelection.set||(this.pointSelection.set=this.parent.set(),this.drawPoints()),this},i.prototype.getPointArray=function(){var e=this.el.bbox();return this.el.array().valueOf().map(function(t){return[t[0]-e.x,t[1]-e.y]})},i.prototype.drawPoints=function(){for(var n=this,t=this.getPointArray(),e=0,i=t.length;e<i;++e){var s=function(s){return function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation();var e=t.pageX||t.touches[0].pageX,i=t.pageY||t.touches[0].pageY;n.el.fire("point",{x:e,y:i,i:s,event:t})}}(e),o=this.drawPoint(t[e][0],t[e][1]).addClass(this.options.classPoints).addClass(this.options.classPoints+"_point").on("touchstart",s).on("mousedown",s);this.pointSelection.set.add(o)}},i.prototype.drawPoint=function(t,e){var i=this.options.pointType;switch(i){case"circle":return this.drawCircle(t,e);case"rect":return this.drawRect(t,e);default:if("function"==typeof i)return i.call(this,t,e);throw new Error("Unknown "+i+" point type!")}},i.prototype.drawCircle=function(t,e){return this.nested.circle(this.options.pointSize).center(t,e)},i.prototype.drawRect=function(t,e){return this.nested.rect(this.options.pointSize,this.options.pointSize).center(t,e)},i.prototype.updatePointSelection=function(){var e=this.getPointArray();this.pointSelection.set.each(function(t){this.cx()===e[t][0]&&this.cy()===e[t][1]||this.center(e[t][0],e[t][1])})},i.prototype.updateRectSelection=function(){var s=this,n=this.el.bbox();if(this.rectSelection.set.get(0).attr({width:n.width,height:n.height}),this.options.points.length&&this.options.points.map(function(t,e){var i=s.pointCoords(t,n);s.rectSelection.set.get(e+1).center(i.x,i.y)}),this.options.rotationPoint){var t=this.rectSelection.set.length();this.rectSelection.set.get(t-1).center(n.width/2,20)}},i.prototype.selectRect=function(t){var n=this,o=this.el.bbox();function r(s){return function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation();var e=t.pageX||t.touches[0].pageX,i=t.pageY||t.touches[0].pageY;n.el.fire(s,{x:e,y:i,event:t})}}if(this.rectSelection.isSelected=t,this.rectSelection.set=this.rectSelection.set||this.parent.set(),this.rectSelection.set.get(0)||this.rectSelection.set.add(this.nested.rect(o.width,o.height).addClass(this.options.classRect)),this.options.points.length&&this.rectSelection.set.length()<2){this.options.points.map(function(t,e){var i=n.pointCoords(t,o),s=n.drawPoint(i.x,i.y).attr("class",n.options.classPoints+"_"+t).on("mousedown",r(t)).on("touchstart",r(t));n.rectSelection.set.add(s)}),this.rectSelection.set.each(function(){this.addClass(n.options.classPoints)})}if(this.options.rotationPoint&&(this.options.points&&!this.rectSelection.set.get(9)||!this.options.points&&!this.rectSelection.set.get(1))){var e=function(t){(t=t||window.event).preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation();var e=t.pageX||t.touches[0].pageX,i=t.pageY||t.touches[0].pageY;n.el.fire("rot",{x:e,y:i,event:t})},i=this.drawPoint(o.width/2,20).attr("class",this.options.classPoints+"_rot").on("touchstart",e).on("mousedown",e);this.rectSelection.set.add(i)}},i.prototype.handler=function(){var t=this.el.bbox();this.nested.matrix(new SVG.Matrix(this.el).translate(t.x,t.y)),this.rectSelection.isSelected&&this.updateRectSelection(),this.pointSelection.isSelected&&this.updatePointSelection()},i.prototype.observe=function(){var t=this;if(MutationObserver)if(this.rectSelection.isSelected||this.pointSelection.isSelected)this.observerInst=this.observerInst||new MutationObserver(function(){t.handler()}),this.observerInst.observe(this.el.node,{attributes:!0});else try{this.observerInst.disconnect(),delete this.observerInst}catch(t){}else this.el.off("DOMAttrModified.select"),(this.rectSelection.isSelected||this.pointSelection.isSelected)&&this.el.on("DOMAttrModified.select",function(){t.handler()})},i.prototype.cleanup=function(){!this.rectSelection.isSelected&&this.rectSelection.set&&(this.rectSelection.set.each(function(){this.remove()}),this.rectSelection.set.clear(),delete this.rectSelection.set),!this.pointSelection.isSelected&&this.pointSelection.set&&(this.pointSelection.set.each(function(){this.remove()}),this.pointSelection.set.clear(),delete this.pointSelection.set),this.pointSelection.isSelected||this.rectSelection.isSelected||(this.nested.remove(),delete this.nested)},SVG.extend(SVG.Element,{selectize:function(t,e){return"object"==typeof t&&(e=t,t=!0),(this.remember("_selectHandler")||new i(this)).init(void 0===t||t,e||{}),this}}),SVG.Element.prototype.selectize.defaults={points:["lt","rt","rb","lb","t","r","b","l"],pointsExclude:[],classRect:"svg_select_boundingRect",classPoints:"svg_select_points",pointSize:7,rotationPoint:!0,deepSelect:!1,pointType:"circle"}}(); |
{ | ||
"name": "svg.select.js", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "An extension of svg.js which allows to select elements with mouse", | ||
@@ -37,11 +37,12 @@ "keywords": [ | ||
"gulp-iife": "^0.3.0", | ||
"gulp-rename": "^1.2.2", | ||
"gulp-standard": "^10.0.0", | ||
"gulp-rename": "^1.3.0", | ||
"gulp-standard": "^10.1.2", | ||
"gulp-trimlines": "^1.0.1", | ||
"gulp-uglify": "^3.0.0", | ||
"gulp-wrap-iife": "0.0.1" | ||
"gulp-wrap-iife": "0.0.1", | ||
"natives": "1.1.3" | ||
}, | ||
"dependencies": { | ||
"svg.js": "^2.2.5" | ||
"svg.js": "^2.6.5" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27053
372
11
Updatedsvg.js@^2.6.5