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

svg.resize.js

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg.resize.js - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

59

dist/svg.resize.js

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

/*! svg.resize.js - v1.1.0 - 2015-06-22
/*! svg.resize.js - v1.1.1 - 2016-03-07
* https://github.com/Fuzzyma/svg.resize.js
* Copyright (c) 2015 Ulrich-Matthias Schäfer; Licensed MIT */
* Copyright (c) 2016 Ulrich-Matthias Schäfer; Licensed MIT */
;(function () {

@@ -91,2 +91,3 @@

this.parameters = {
type: this.el.type, // the type of element
p: this.transformPoint(event.detail.event.clientX,event.detail.event.clientY),

@@ -99,2 +100,7 @@ x: event.detail.x, // x-position of the mouse when resizing started

// Add font-size parameter if the element type is text
if (this.el.type === "text") {
this.parameters.fontSize = this.el.attr()["font-size"];
}
// the i-param in the event holds the index of the point which is moved, when using `deepSelect`

@@ -125,2 +131,14 @@ if (event.detail.i !== undefined) {

// ...if valid, we resize the this.el (which can include moving because the coord-system starts at the left-top and this edge is moving sometimes when resized)
/*
* but first check if the element is text box, so we can change the font size instead of
* the width and height
*/
if (this.parameters.type === "text") {
this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y);
this.el.attr("font-size", this.parameters.fontSize - snap[0]);
return;
}
this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y + snap[1]).size(this.parameters.box.width - snap[0], this.parameters.box.height - snap[1]);

@@ -137,2 +155,8 @@ }

if (this.parameters.box.width + snap[0] > 0 && this.parameters.box.height - snap[1] > 0) {
if (this.parameters.type === "text") {
this.el.move(this.parameters.box.x - snap[0], this.parameters.box.y);
this.el.attr("font-size", this.parameters.fontSize + snap[0]);
return;
}
this.el.move(this.parameters.box.x, this.parameters.box.y + snap[1]).size(this.parameters.box.width + snap[0], this.parameters.box.height - snap[1]);

@@ -149,2 +173,8 @@ }

if (this.parameters.box.width + snap[0] > 0 && this.parameters.box.height + snap[1] > 0) {
if (this.parameters.type === "text") {
this.el.move(this.parameters.box.x - snap[0], this.parameters.box.y);
this.el.attr("font-size", this.parameters.fontSize + snap[0]);
return;
}
this.el.move(this.parameters.box.x, this.parameters.box.y).size(this.parameters.box.width + snap[0], this.parameters.box.height + snap[1]);

@@ -161,2 +191,8 @@ }

if (this.parameters.box.width - snap[0] > 0 && this.parameters.box.height + snap[1] > 0) {
if (this.parameters.type === "text") {
this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y);
this.el.attr("font-size", this.parameters.fontSize - snap[0]);
return;
}
this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y).size(this.parameters.box.width - snap[0], this.parameters.box.height + snap[1]);

@@ -173,2 +209,7 @@ }

if (this.parameters.box.height - snap[1] > 0) {
// Disable the font-resizing if it is not from the corner of bounding-box
if (this.parameters.type === "text") {
return;
}
this.el.move(this.parameters.box.x, this.parameters.box.y + snap[1]).height(this.parameters.box.height - snap[1]);

@@ -185,2 +226,6 @@ }

if (this.parameters.box.width + snap[0] > 0) {
if (this.parameters.type === "text") {
return;
}
this.el.move(this.parameters.box.x, this.parameters.box.y).width(this.parameters.box.width + snap[0]);

@@ -197,2 +242,6 @@ }

if (this.parameters.box.height + snap[1] > 0) {
if (this.parameters.type === "text") {
return;
}
this.el.move(this.parameters.box.x, this.parameters.box.y).height(this.parameters.box.height + snap[1]);

@@ -209,2 +258,6 @@ }

if (this.parameters.box.width - snap[0] > 0) {
if (this.parameters.type === "text") {
return;
}
this.el.move(this.parameters.box.x + snap[0], this.parameters.box.y).width(this.parameters.box.width - snap[0]);

@@ -336,2 +389,2 @@ }

}).call(this);
}).call(this);

6

dist/svg.resize.min.js

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

/*! svg.resize.js - v1.1.0 - 2015-06-22
/*! svg.resize.js - v1.1.1 - 2016-03-07
* https://github.com/Fuzzyma/svg.resize.js
* Copyright (c) 2015 Ulrich-Matthias Schäfer; Licensed MIT */
(function(){function a(a){a.remember("_resizeHandler",this),this.el=a,this.parameters={},this.lastUpdateCall=null,this.p=a.doc().node.createSVGPoint()}a.prototype.transformPoint=function(a,b,c){return this.p.x=a-(this.offset.x-window.pageXOffset),this.p.y=b-(this.offset.y-window.pageYOffset),this.p.matrixTransform(c||this.m)},a.prototype.init=function(a){var b=this;if(this.stop(),"stop"!==a){this.options={};for(var c in this.el.resize.defaults)this.options[c]=this.el.resize.defaults[c],"undefined"!=typeof a[c]&&(this.options[c]=a[c]);this.el.on("lt.resize",function(a){b.resize(a||window.event)}),this.el.on("rt.resize",function(a){b.resize(a||window.event)}),this.el.on("rb.resize",function(a){b.resize(a||window.event)}),this.el.on("lb.resize",function(a){b.resize(a||window.event)}),this.el.on("t.resize",function(a){b.resize(a||window.event)}),this.el.on("r.resize",function(a){b.resize(a||window.event)}),this.el.on("b.resize",function(a){b.resize(a||window.event)}),this.el.on("l.resize",function(a){b.resize(a||window.event)}),this.el.on("rot.resize",function(a){b.resize(a||window.event)}),this.el.on("point.resize",function(a){b.resize(a||window.event)}),this.update()}},a.prototype.stop=function(){return this.el.off("lt.resize"),this.el.off("rt.resize"),this.el.off("rb.resize"),this.el.off("lb.resize"),this.el.off("t.resize"),this.el.off("r.resize"),this.el.off("b.resize"),this.el.off("l.resize"),this.el.off("rot.resize"),this.el.off("point.resize"),this},a.prototype.resize=function(a){var b=this;if(this.m=this.el.node.getScreenCTM().inverse(),this.offset={x:window.pageXOffset,y:window.pageYOffset},this.parameters={p:this.transformPoint(a.detail.event.clientX,a.detail.event.clientY),x:a.detail.x,y:a.detail.y,box:this.el.bbox(),rotation:this.el.transform().rotation},void 0!==a.detail.i){var c=this.el.array().valueOf();this.parameters.i=a.detail.i,this.parameters.pointCoords=[c[a.detail.i][0],c[a.detail.i][1]]}switch(a.type){case"lt":this.calc=function(a,b){var c=this.snapToGrid(a,b);this.parameters.box.width-c[0]>0&&this.parameters.box.height-c[1]>0&&this.el.move(this.parameters.box.x+c[0],this.parameters.box.y+c[1]).size(this.parameters.box.width-c[0],this.parameters.box.height-c[1])};break;case"rt":this.calc=function(a,b){var c=this.snapToGrid(a,b,2);this.parameters.box.width+c[0]>0&&this.parameters.box.height-c[1]>0&&this.el.move(this.parameters.box.x,this.parameters.box.y+c[1]).size(this.parameters.box.width+c[0],this.parameters.box.height-c[1])};break;case"rb":this.calc=function(a,b){var c=this.snapToGrid(a,b,0);this.parameters.box.width+c[0]>0&&this.parameters.box.height+c[1]>0&&this.el.move(this.parameters.box.x,this.parameters.box.y).size(this.parameters.box.width+c[0],this.parameters.box.height+c[1])};break;case"lb":this.calc=function(a,b){var c=this.snapToGrid(a,b,1);this.parameters.box.width-c[0]>0&&this.parameters.box.height+c[1]>0&&this.el.move(this.parameters.box.x+c[0],this.parameters.box.y).size(this.parameters.box.width-c[0],this.parameters.box.height+c[1])};break;case"t":this.calc=function(a,b){var c=this.snapToGrid(a,b,2);this.parameters.box.height-c[1]>0&&this.el.move(this.parameters.box.x,this.parameters.box.y+c[1]).height(this.parameters.box.height-c[1])};break;case"r":this.calc=function(a,b){var c=this.snapToGrid(a,b,0);this.parameters.box.width+c[0]>0&&this.el.move(this.parameters.box.x,this.parameters.box.y).width(this.parameters.box.width+c[0])};break;case"b":this.calc=function(a,b){var c=this.snapToGrid(a,b,0);this.parameters.box.height+c[1]>0&&this.el.move(this.parameters.box.x,this.parameters.box.y).height(this.parameters.box.height+c[1])};break;case"l":this.calc=function(a,b){var c=this.snapToGrid(a,b,1);this.parameters.box.width-c[0]>0&&this.el.move(this.parameters.box.x+c[0],this.parameters.box.y).width(this.parameters.box.width-c[0])};break;case"rot":this.calc=function(a,b){var c={x:a+this.parameters.p.x,y:b+this.parameters.p.y},d=Math.atan2(this.parameters.p.y-this.parameters.box.y-this.parameters.box.height/2,this.parameters.p.x-this.parameters.box.x-this.parameters.box.width/2),e=Math.atan2(c.y-this.parameters.box.y-this.parameters.box.height/2,c.x-this.parameters.box.x-this.parameters.box.width/2),f=180*(e-d)/Math.PI;this.el.center(this.parameters.box.cx,this.parameters.box.cy).rotate(this.parameters.rotation+f-f%this.options.snapToAngle,this.parameters.box.cx,this.parameters.box.cy)};break;case"point":this.calc=function(a,b){var c=this.snapToGrid(a,b,this.parameters.pointCoords[0],this.parameters.pointCoords[1]),d=this.el.array().valueOf();d[this.parameters.i][0]=this.parameters.pointCoords[0]+c[0],d[this.parameters.i][1]=this.parameters.pointCoords[1]+c[1],this.el.plot(d)}}SVG.on(window,"mousemove.resize",function(a){b.update(a||window.event)}),SVG.on(window,"mouseup.resize",function(){b.done()})},a.prototype.update=function(a){if(!a)return void(this.lastUpdateCall&&this.calc(this.lastUpdateCall[0],this.lastUpdateCall[1]));var b=this.transformPoint(a.clientX,a.clientY),c=b.x-this.parameters.p.x,d=b.y-this.parameters.p.y;this.lastUpdateCall=[c,d],this.calc(c,d)},a.prototype.done=function(){this.lastUpdateCall=null,SVG.off(window,"mousemove.resize"),SVG.off(window,"mouseup.resize"),this.el.fire("resizedone")},a.prototype.snapToGrid=function(a,b,c,d){var e;return d?e=[(c+a)%this.options.snapToGrid,(d+b)%this.options.snapToGrid]:(c=null==c?3:c,e=[(this.parameters.box.x+a+(1&c?0:this.parameters.box.width))%this.options.snapToGrid,(this.parameters.box.y+b+(2&c?0:this.parameters.box.height))%this.options.snapToGrid]),a-=(Math.abs(e[0])<this.options.snapToGrid/2?e[0]:e[0]-this.options.snapToGrid)+(e[0]<0?this.options.snapToGrid:0),b-=(Math.abs(e[1])<this.options.snapToGrid/2?e[1]:e[1]-this.options.snapToGrid)+(e[1]<0?this.options.snapToGrid:0),[a,b]},SVG.extend(SVG.Element,{resize:function(b){return(this.remember("_resizeHandler")||new a(this)).init(b||{}),this}}),SVG.Element.prototype.resize.defaults={snapToAngle:.1,snapToGrid:1}}).call(this);
* Copyright (c) 2016 Ulrich-Matthias Schäfer; Licensed MIT */
(function(){function a(a){a.remember("_resizeHandler",this),this.el=a,this.parameters={},this.lastUpdateCall=null,this.p=a.doc().node.createSVGPoint()}a.prototype.transformPoint=function(a,b,c){return this.p.x=a-(this.offset.x-window.pageXOffset),this.p.y=b-(this.offset.y-window.pageYOffset),this.p.matrixTransform(c||this.m)},a.prototype.init=function(a){var b=this;if(this.stop(),"stop"!==a){this.options={};for(var c in this.el.resize.defaults)this.options[c]=this.el.resize.defaults[c],"undefined"!=typeof a[c]&&(this.options[c]=a[c]);this.el.on("lt.resize",function(a){b.resize(a||window.event)}),this.el.on("rt.resize",function(a){b.resize(a||window.event)}),this.el.on("rb.resize",function(a){b.resize(a||window.event)}),this.el.on("lb.resize",function(a){b.resize(a||window.event)}),this.el.on("t.resize",function(a){b.resize(a||window.event)}),this.el.on("r.resize",function(a){b.resize(a||window.event)}),this.el.on("b.resize",function(a){b.resize(a||window.event)}),this.el.on("l.resize",function(a){b.resize(a||window.event)}),this.el.on("rot.resize",function(a){b.resize(a||window.event)}),this.el.on("point.resize",function(a){b.resize(a||window.event)}),this.update()}},a.prototype.stop=function(){return this.el.off("lt.resize"),this.el.off("rt.resize"),this.el.off("rb.resize"),this.el.off("lb.resize"),this.el.off("t.resize"),this.el.off("r.resize"),this.el.off("b.resize"),this.el.off("l.resize"),this.el.off("rot.resize"),this.el.off("point.resize"),this},a.prototype.resize=function(a){var b=this;if(this.m=this.el.node.getScreenCTM().inverse(),this.offset={x:window.pageXOffset,y:window.pageYOffset},this.parameters={type:this.el.type,p:this.transformPoint(a.detail.event.clientX,a.detail.event.clientY),x:a.detail.x,y:a.detail.y,box:this.el.bbox(),rotation:this.el.transform().rotation},"text"===this.el.type&&(this.parameters.fontSize=this.el.attr()["font-size"]),void 0!==a.detail.i){var c=this.el.array().valueOf();this.parameters.i=a.detail.i,this.parameters.pointCoords=[c[a.detail.i][0],c[a.detail.i][1]]}switch(a.type){case"lt":this.calc=function(a,b){var c=this.snapToGrid(a,b);if(this.parameters.box.width-c[0]>0&&this.parameters.box.height-c[1]>0){if("text"===this.parameters.type)return this.el.move(this.parameters.box.x+c[0],this.parameters.box.y),void this.el.attr("font-size",this.parameters.fontSize-c[0]);this.el.move(this.parameters.box.x+c[0],this.parameters.box.y+c[1]).size(this.parameters.box.width-c[0],this.parameters.box.height-c[1])}};break;case"rt":this.calc=function(a,b){var c=this.snapToGrid(a,b,2);if(this.parameters.box.width+c[0]>0&&this.parameters.box.height-c[1]>0){if("text"===this.parameters.type)return this.el.move(this.parameters.box.x-c[0],this.parameters.box.y),void this.el.attr("font-size",this.parameters.fontSize+c[0]);this.el.move(this.parameters.box.x,this.parameters.box.y+c[1]).size(this.parameters.box.width+c[0],this.parameters.box.height-c[1])}};break;case"rb":this.calc=function(a,b){var c=this.snapToGrid(a,b,0);if(this.parameters.box.width+c[0]>0&&this.parameters.box.height+c[1]>0){if("text"===this.parameters.type)return this.el.move(this.parameters.box.x-c[0],this.parameters.box.y),void this.el.attr("font-size",this.parameters.fontSize+c[0]);this.el.move(this.parameters.box.x,this.parameters.box.y).size(this.parameters.box.width+c[0],this.parameters.box.height+c[1])}};break;case"lb":this.calc=function(a,b){var c=this.snapToGrid(a,b,1);if(this.parameters.box.width-c[0]>0&&this.parameters.box.height+c[1]>0){if("text"===this.parameters.type)return this.el.move(this.parameters.box.x+c[0],this.parameters.box.y),void this.el.attr("font-size",this.parameters.fontSize-c[0]);this.el.move(this.parameters.box.x+c[0],this.parameters.box.y).size(this.parameters.box.width-c[0],this.parameters.box.height+c[1])}};break;case"t":this.calc=function(a,b){var c=this.snapToGrid(a,b,2);if(this.parameters.box.height-c[1]>0){if("text"===this.parameters.type)return;this.el.move(this.parameters.box.x,this.parameters.box.y+c[1]).height(this.parameters.box.height-c[1])}};break;case"r":this.calc=function(a,b){var c=this.snapToGrid(a,b,0);if(this.parameters.box.width+c[0]>0){if("text"===this.parameters.type)return;this.el.move(this.parameters.box.x,this.parameters.box.y).width(this.parameters.box.width+c[0])}};break;case"b":this.calc=function(a,b){var c=this.snapToGrid(a,b,0);if(this.parameters.box.height+c[1]>0){if("text"===this.parameters.type)return;this.el.move(this.parameters.box.x,this.parameters.box.y).height(this.parameters.box.height+c[1])}};break;case"l":this.calc=function(a,b){var c=this.snapToGrid(a,b,1);if(this.parameters.box.width-c[0]>0){if("text"===this.parameters.type)return;this.el.move(this.parameters.box.x+c[0],this.parameters.box.y).width(this.parameters.box.width-c[0])}};break;case"rot":this.calc=function(a,b){var c={x:a+this.parameters.p.x,y:b+this.parameters.p.y},d=Math.atan2(this.parameters.p.y-this.parameters.box.y-this.parameters.box.height/2,this.parameters.p.x-this.parameters.box.x-this.parameters.box.width/2),e=Math.atan2(c.y-this.parameters.box.y-this.parameters.box.height/2,c.x-this.parameters.box.x-this.parameters.box.width/2),f=180*(e-d)/Math.PI;this.el.center(this.parameters.box.cx,this.parameters.box.cy).rotate(this.parameters.rotation+f-f%this.options.snapToAngle,this.parameters.box.cx,this.parameters.box.cy)};break;case"point":this.calc=function(a,b){var c=this.snapToGrid(a,b,this.parameters.pointCoords[0],this.parameters.pointCoords[1]),d=this.el.array().valueOf();d[this.parameters.i][0]=this.parameters.pointCoords[0]+c[0],d[this.parameters.i][1]=this.parameters.pointCoords[1]+c[1],this.el.plot(d)}}SVG.on(window,"mousemove.resize",function(a){b.update(a||window.event)}),SVG.on(window,"mouseup.resize",function(){b.done()})},a.prototype.update=function(a){if(!a)return void(this.lastUpdateCall&&this.calc(this.lastUpdateCall[0],this.lastUpdateCall[1]));var b=this.transformPoint(a.clientX,a.clientY),c=b.x-this.parameters.p.x,d=b.y-this.parameters.p.y;this.lastUpdateCall=[c,d],this.calc(c,d)},a.prototype.done=function(){this.lastUpdateCall=null,SVG.off(window,"mousemove.resize"),SVG.off(window,"mouseup.resize"),this.el.fire("resizedone")},a.prototype.snapToGrid=function(a,b,c,d){var e;return d?e=[(c+a)%this.options.snapToGrid,(d+b)%this.options.snapToGrid]:(c=null==c?3:c,e=[(this.parameters.box.x+a+(1&c?0:this.parameters.box.width))%this.options.snapToGrid,(this.parameters.box.y+b+(2&c?0:this.parameters.box.height))%this.options.snapToGrid]),a-=(Math.abs(e[0])<this.options.snapToGrid/2?e[0]:e[0]-this.options.snapToGrid)+(e[0]<0?this.options.snapToGrid:0),b-=(Math.abs(e[1])<this.options.snapToGrid/2?e[1]:e[1]-this.options.snapToGrid)+(e[1]<0?this.options.snapToGrid:0),[a,b]},SVG.extend(SVG.Element,{resize:function(b){return(this.remember("_resizeHandler")||new a(this)).init(b||{}),this}}),SVG.Element.prototype.resize.defaults={snapToAngle:.1,snapToGrid:1}}).call(this);
{
"name": "svg.resize.js",
"version": "1.1.0",
"version": "1.1.1",
"description": "An extension for svn.js which allows to resize elements which are selected",

@@ -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