Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

svg.select.js

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg.select.js - npm Package Compare versions

Comparing version 1.0.0 to 1.0.3

126

dist/svg.select.js

@@ -1,2 +0,2 @@

/*! svg.select.js - v1.0.0 - 2015-05-27
/*! svg.select.js - v1.0.3 - 2015-06-22
* https://github.com/Fuzzyma/svg.select.js

@@ -7,13 +7,13 @@ * Copyright (c) 2015 Ulrich-Matthias Schäfer; Licensed MIT */

function SelectHandler(el){
function SelectHandler(el) {
this.el = el;
this.parent = el.parent._parent(SVG.Nested) || el._parent(SVG.Doc);
this.parent = el.parent(SVG.Nested) || el.parent(SVG.Doc);
el.remember('_selectHandler', this);
this.pointSelection = {isSelected:false};
this.rectSelection = {isSelected:false};
this.pointSelection = {isSelected: false};
this.rectSelection = {isSelected: false};
}
SelectHandler.prototype.init = function(value, options){
SelectHandler.prototype.init = function (value, options) {

@@ -26,3 +26,3 @@ var bbox = this.el.bbox();

this.options[i] = this.el.select.defaults[i];
if(options[i] !== undefined){
if (options[i] !== undefined) {
this.options[i] = options[i];

@@ -32,8 +32,8 @@ }

this.nested = (this.nested || this.parent.nested()).size(bbox.width, bbox.height).transform(this.el.transform).move(bbox.x, bbox.y);
this.nested = (this.nested || this.parent.nested()).size(bbox.width || 1, bbox.height || 1).transform(this.el.ctm()).move(bbox.x, bbox.y);
// When deepSelect is enabled and the element is a line/polyline/polygon, draw only points for moving
if(this.options.deepSelect && ['line', 'polyline', 'polygon'].indexOf(this.el.type) !== -1){
if (this.options.deepSelect && ['line', 'polyline', 'polygon'].indexOf(this.el.type) !== -1) {
this.selectPoints(value);
}else{
} else {
this.selectRect(value);

@@ -47,3 +47,3 @@ }

SelectHandler.prototype.selectPoints = function(value){
SelectHandler.prototype.selectPoints = function (value) {

@@ -53,3 +53,5 @@ this.pointSelection.isSelected = value;

// When set is already there we dont have to create one
if (this.pointSelection.set){ return this; }
if (this.pointSelection.set) {
return this;
}

@@ -66,9 +68,8 @@ // Create our set of elements

// create the point-array which contains the 2 points of a line or simply the points-array of polyline/polygon
SelectHandler.prototype.getPointArray = function(){
SelectHandler.prototype.getPointArray = function () {
var bbox = this.el.bbox();
return this.el.type === 'line' ? [
[this.el.attr('x1')-bbox.x, this.el.attr('y1')]-bbox.y,
[this.el.attr('x2')-bbox.x, this.el.attr('y2')]-bbox.y
] : this.el.array.value.map(function(el){ return [el[0]-bbox.x, el[1]-bbox.y]; });
return this.el.array().valueOf().map(function (el) {
return [el[0] - bbox.x, el[1] - bbox.y];
});
};

@@ -97,3 +98,3 @@

ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
_this.el.fire('point', {x: ev.pageX, y: ev.pageY, i: k, event:ev});
_this.el.fire('point', {x: ev.pageX, y: ev.pageY, i: k, event: ev});
};

@@ -112,10 +113,12 @@ })(i)

this.pointSelection.set.each(function (i) {
if (this.cx() === array[i][0] && this.cy() === array[i][1]){ return; }
if (this.cx() === array[i][0] && this.cy() === array[i][1]) {
return;
}
this.center(array[i][0], array[i][1]);
});
};
SelectHandler.prototype.updateRectSelection = function(){
SelectHandler.prototype.updateRectSelection = function () {
var bbox = this.el.bbox();
this.rectSelection.set.get(0).attr({

@@ -143,3 +146,3 @@ width: bbox.width,

SelectHandler.prototype.selectRect = function(value){
SelectHandler.prototype.selectRect = function (value) {

@@ -163,3 +166,3 @@ var _this = this, bbox = this.el.bbox();

// create the selection-rectangle and add the css-class
if(!this.rectSelection.set.get(0)){
if (!this.rectSelection.set.get(0)) {
this.rectSelection.set.add(this.nested.rect(bbox.width, bbox.height).addClass(this.options.classRect));

@@ -199,12 +202,12 @@ }

SelectHandler.prototype.handler = function(){
SelectHandler.prototype.handler = function () {
var bbox = this.el.bbox();
this.nested.size(bbox.width, bbox.height).transform(this.el.transform()).move(bbox.x, bbox.y);
this.nested.size(bbox.width || 1, bbox.height || 1).transform(this.el.ctm()).move(bbox.x, bbox.y);
if(this.rectSelection.isSelected){
if (this.rectSelection.isSelected) {
this.updateRectSelection();
}
if(this.pointSelection.isSelected){
if (this.pointSelection.isSelected) {
this.updatePointSelection();

@@ -215,20 +218,25 @@ }

SelectHandler.prototype.observe = function(){
SelectHandler.prototype.observe = function () {
var _this = this;
if(MutationObserver){
if(this.rectSelection.isSelected || this.pointSelection.isSelected){
this.observerInst = this.observerInst || new MutationObserver(function(){ _this.handler(); });
if (MutationObserver) {
if (this.rectSelection.isSelected || this.pointSelection.isSelected) {
this.observerInst = this.observerInst || new MutationObserver(function () {
_this.handler();
});
this.observerInst.observe(this.el.node, {attributes: true});
}else{
try{
} else {
try {
this.observerInst.disconnect();
delete this.observerInst;
}catch(e){}
} catch (e) {
}
}
}else{
} else {
this.el.off('DOMAttrModified.select');
if(this.rectSelection.isSelected || this.pointSelection.isSelected){
this.el.on('DOMAttrModified.select', function(){ _this.handler(); } );
if (this.rectSelection.isSelected || this.pointSelection.isSelected) {
this.el.on('DOMAttrModified.select', function () {
_this.handler();
});
}

@@ -238,7 +246,7 @@ }

SelectHandler.prototype.cleanup = function(){
SelectHandler.prototype.cleanup = function () {
//var _this = this;
if(!this.rectSelection.isSelected && this.rectSelection.set){
if (!this.rectSelection.isSelected && this.rectSelection.set) {
// stop watching the element, remove the selection

@@ -253,3 +261,3 @@ this.rectSelection.set.each(function () {

if(!this.pointSelection.isSelected && this.pointSelection.set){
if (!this.pointSelection.isSelected && this.pointSelection.set) {
// Remove all points, clear the set, stop watching the element

@@ -264,22 +272,22 @@ this.pointSelection.set.each(function () {

if(!this.pointSelection.isSelected && !this.rectSelection.isSelected){
if (!this.pointSelection.isSelected && !this.rectSelection.isSelected) {
this.nested.remove();
delete this.nested;
/*try{
this.observerInst.disconnect();
delete this.observerInst;
}catch(e){}
this.el.off('DOMAttrModified.select');
}else{
if(MutationObserver){
this.observerInst = this.observerInst || new MutationObserver(function(){ _this.handler(); });
this.observerInst.observe(this.el.node, {attributes: true});
}else{
this.el.on('DOMAttrModified.select', function(){ _this.handler(); } )
}
*/
this.observerInst.disconnect();
delete this.observerInst;
}catch(e){}
this.el.off('DOMAttrModified.select');
}else{
if(MutationObserver){
this.observerInst = this.observerInst || new MutationObserver(function(){ _this.handler(); });
this.observerInst.observe(this.el.node, {attributes: true});
}else{
this.el.on('DOMAttrModified.select', function(){ _this.handler(); } )
}
*/
}

@@ -286,0 +294,0 @@ };

@@ -1,4 +0,4 @@

/*! svg.select.js - v1.0.0 - 2015-05-27
/*! svg.select.js - v1.0.3 - 2015-06-22
* https://github.com/Fuzzyma/svg.select.js
* Copyright (c) 2015 Ulrich-Matthias Schäfer; Licensed MIT */
(function(a){function b(a){this.el=a,this.parent=a.parent._parent(SVG.Nested)||a._parent(SVG.Doc),a.remember("_selectHandler",this),this.pointSelection={isSelected:!1},this.rectSelection={isSelected:!1}}b.prototype.init=function(b,c){var d=this.el.bbox();this.options={};for(var e in this.el.select.defaults)this.options[e]=this.el.select.defaults[e],c[e]!==a&&(this.options[e]=c[e]);this.nested=(this.nested||this.parent.nested()).size(d.width,d.height).transform(this.el.transform).move(d.x,d.y),this.options.deepSelect&&-1!==["line","polyline","polygon"].indexOf(this.el.type)?this.selectPoints(b):this.selectRect(b),this.observe(),this.cleanup()},b.prototype.selectPoints=function(a){return this.pointSelection.isSelected=a,this.pointSelection.set?this:(this.pointSelection.set=this.parent.set(),this.drawCircles(),this)},b.prototype.getPointArray=function(){var a=this.el.bbox();return"line"===this.el.type?[[this.el.attr("x1")-a.x,this.el.attr("y1")]-a.y,[this.el.attr("x2")-a.x,this.el.attr("y2")]-a.y]:this.el.array.value.map(function(b){return[b[0]-a.x,b[1]-a.y]})},b.prototype.drawCircles=function(){for(var a=this,b=this.getPointArray(),c=0,d=b.length;d>c;++c)this.pointSelection.set.add(this.nested.circle(this.options.radius).center(b[c][0],b[c][1]).addClass(this.options.classPoints).addClass(this.options.classPoints+"_point").mousedown(function(b){return function(c){c=c||window.event,c.preventDefault?c.preventDefault():c.returnValue=!1,a.el.fire("point",{x:c.pageX,y:c.pageY,i:b,event:c})}}(c)))},b.prototype.updatePointSelection=function(){var a=this.getPointArray();this.pointSelection.set.each(function(b){(this.cx()!==a[b][0]||this.cy()!==a[b][1])&&this.center(a[b][0],a[b][1])})},b.prototype.updateRectSelection=function(){var a=this.el.bbox();this.rectSelection.set.get(0).attr({width:a.width,height:a.height}),this.options.points&&(this.rectSelection.set.get(2).center(a.width,0),this.rectSelection.set.get(3).center(a.width,a.height),this.rectSelection.set.get(4).center(0,a.height),this.rectSelection.set.get(5).center(a.width/2,0),this.rectSelection.set.get(6).center(a.width,a.height/2),this.rectSelection.set.get(7).center(a.width/2,a.height),this.rectSelection.set.get(8).center(0,a.height/2)),this.options.rotationPoint&&this.rectSelection.set.get(9).center(a.width/2,20)},b.prototype.selectRect=function(a){function b(a){return function(b){b=b||window.event,b.preventDefault?b.preventDefault():b.returnValue=!1,c.el.fire(a,{x:b.pageX,y:b.pageY})}}var c=this,d=this.el.bbox();this.rectSelection.isSelected=a,this.rectSelection.set=this.rectSelection.set||this.parent.set(),this.rectSelection.set.get(0)||this.rectSelection.set.add(this.nested.rect(d.width,d.height).addClass(this.options.classRect)),this.options.points&&!this.rectSelection.set.get(1)&&(this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,0).attr("class",this.options.classPoints+"_lt").mousedown(b("lt"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,0).attr("class",this.options.classPoints+"_rt").mousedown(b("rt"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,d.height).attr("class",this.options.classPoints+"_rb").mousedown(b("rb"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,d.height).attr("class",this.options.classPoints+"_lb").mousedown(b("lb"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,0).attr("class",this.options.classPoints+"_t").mousedown(b("t"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,d.height/2).attr("class",this.options.classPoints+"_r").mousedown(b("r"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,d.height).attr("class",this.options.classPoints+"_b").mousedown(b("b"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,d.height/2).attr("class",this.options.classPoints+"_l").mousedown(b("l"))),this.rectSelection.set.each(function(){this.addClass(c.options.classPoints)})),this.options.rotationPoint&&!this.rectSelection.set.get(9)&&this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,20).attr("class",this.options.classPoints+"_rot").mousedown(function(a){a=a||window.event,a.preventDefault?a.preventDefault():a.returnValue=!1,c.el.fire("rot",{x:a.pageX,y:a.pageY})}))},b.prototype.handler=function(){var a=this.el.bbox();this.nested.size(a.width,a.height).transform(this.el.transform()).move(a.x,a.y),this.rectSelection.isSelected&&this.updateRectSelection(),this.pointSelection.isSelected&&this.updatePointSelection()},b.prototype.observe=function(){var a=this;if(MutationObserver)if(this.rectSelection.isSelected||this.pointSelection.isSelected)this.observerInst=this.observerInst||new MutationObserver(function(){a.handler()}),this.observerInst.observe(this.el.node,{attributes:!0});else try{this.observerInst.disconnect(),delete this.observerInst}catch(b){}else this.el.off("DOMAttrModified.select"),(this.rectSelection.isSelected||this.pointSelection.isSelected)&&this.el.on("DOMAttrModified.select",function(){a.handler()})},b.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,{select:function(c,d){"object"==typeof c&&(d=c,c=!0);var e=this.remember("_selectHandler")||new b(this);return e.init(c===a?!0:c,d||{}),this}}),SVG.Element.prototype.select.defaults={points:!0,classRect:"svg_select_boundingRect",classPoints:"svg_select_points",radius:7,rotationPoint:!0,deepSelect:!1}}).call(this);
(function(a){function b(a){this.el=a,this.parent=a.parent(SVG.Nested)||a.parent(SVG.Doc),a.remember("_selectHandler",this),this.pointSelection={isSelected:!1},this.rectSelection={isSelected:!1}}b.prototype.init=function(b,c){var d=this.el.bbox();this.options={};for(var e in this.el.select.defaults)this.options[e]=this.el.select.defaults[e],c[e]!==a&&(this.options[e]=c[e]);this.nested=(this.nested||this.parent.nested()).size(d.width||1,d.height||1).transform(this.el.ctm()).move(d.x,d.y),this.options.deepSelect&&-1!==["line","polyline","polygon"].indexOf(this.el.type)?this.selectPoints(b):this.selectRect(b),this.observe(),this.cleanup()},b.prototype.selectPoints=function(a){return this.pointSelection.isSelected=a,this.pointSelection.set?this:(this.pointSelection.set=this.parent.set(),this.drawCircles(),this)},b.prototype.getPointArray=function(){var a=this.el.bbox();return this.el.array().valueOf().map(function(b){return[b[0]-a.x,b[1]-a.y]})},b.prototype.drawCircles=function(){for(var a=this,b=this.getPointArray(),c=0,d=b.length;d>c;++c)this.pointSelection.set.add(this.nested.circle(this.options.radius).center(b[c][0],b[c][1]).addClass(this.options.classPoints).addClass(this.options.classPoints+"_point").mousedown(function(b){return function(c){c=c||window.event,c.preventDefault?c.preventDefault():c.returnValue=!1,a.el.fire("point",{x:c.pageX,y:c.pageY,i:b,event:c})}}(c)))},b.prototype.updatePointSelection=function(){var a=this.getPointArray();this.pointSelection.set.each(function(b){(this.cx()!==a[b][0]||this.cy()!==a[b][1])&&this.center(a[b][0],a[b][1])})},b.prototype.updateRectSelection=function(){var a=this.el.bbox();this.rectSelection.set.get(0).attr({width:a.width,height:a.height}),this.options.points&&(this.rectSelection.set.get(2).center(a.width,0),this.rectSelection.set.get(3).center(a.width,a.height),this.rectSelection.set.get(4).center(0,a.height),this.rectSelection.set.get(5).center(a.width/2,0),this.rectSelection.set.get(6).center(a.width,a.height/2),this.rectSelection.set.get(7).center(a.width/2,a.height),this.rectSelection.set.get(8).center(0,a.height/2)),this.options.rotationPoint&&this.rectSelection.set.get(9).center(a.width/2,20)},b.prototype.selectRect=function(a){function b(a){return function(b){b=b||window.event,b.preventDefault?b.preventDefault():b.returnValue=!1,c.el.fire(a,{x:b.pageX,y:b.pageY})}}var c=this,d=this.el.bbox();this.rectSelection.isSelected=a,this.rectSelection.set=this.rectSelection.set||this.parent.set(),this.rectSelection.set.get(0)||this.rectSelection.set.add(this.nested.rect(d.width,d.height).addClass(this.options.classRect)),this.options.points&&!this.rectSelection.set.get(1)&&(this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,0).attr("class",this.options.classPoints+"_lt").mousedown(b("lt"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,0).attr("class",this.options.classPoints+"_rt").mousedown(b("rt"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,d.height).attr("class",this.options.classPoints+"_rb").mousedown(b("rb"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,d.height).attr("class",this.options.classPoints+"_lb").mousedown(b("lb"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,0).attr("class",this.options.classPoints+"_t").mousedown(b("t"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width,d.height/2).attr("class",this.options.classPoints+"_r").mousedown(b("r"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,d.height).attr("class",this.options.classPoints+"_b").mousedown(b("b"))),this.rectSelection.set.add(this.nested.circle(this.options.radius).center(0,d.height/2).attr("class",this.options.classPoints+"_l").mousedown(b("l"))),this.rectSelection.set.each(function(){this.addClass(c.options.classPoints)})),this.options.rotationPoint&&!this.rectSelection.set.get(9)&&this.rectSelection.set.add(this.nested.circle(this.options.radius).center(d.width/2,20).attr("class",this.options.classPoints+"_rot").mousedown(function(a){a=a||window.event,a.preventDefault?a.preventDefault():a.returnValue=!1,c.el.fire("rot",{x:a.pageX,y:a.pageY})}))},b.prototype.handler=function(){var a=this.el.bbox();this.nested.size(a.width||1,a.height||1).transform(this.el.ctm()).move(a.x,a.y),this.rectSelection.isSelected&&this.updateRectSelection(),this.pointSelection.isSelected&&this.updatePointSelection()},b.prototype.observe=function(){var a=this;if(MutationObserver)if(this.rectSelection.isSelected||this.pointSelection.isSelected)this.observerInst=this.observerInst||new MutationObserver(function(){a.handler()}),this.observerInst.observe(this.el.node,{attributes:!0});else try{this.observerInst.disconnect(),delete this.observerInst}catch(b){}else this.el.off("DOMAttrModified.select"),(this.rectSelection.isSelected||this.pointSelection.isSelected)&&this.el.on("DOMAttrModified.select",function(){a.handler()})},b.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,{select:function(c,d){"object"==typeof c&&(d=c,c=!0);var e=this.remember("_selectHandler")||new b(this);return e.init(c===a?!0:c,d||{}),this}}),SVG.Element.prototype.select.defaults={points:!0,classRect:"svg_select_boundingRect",classPoints:"svg_select_points",radius:7,rotationPoint:!0,deepSelect:!1}}).call(this);
{
"name": "svg.select.js",
"version": "1.0.0",
"version": "1.0.3",
"description": "An extension of svg.js which allows to select elements with mouse",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc