Add yet-another-react-lightbox package and update .gitignore to exclude node_modules

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-12 18:50:30 +00:00
parent bd2a5570a9
commit c92f4a5edd
9304 changed files with 29 additions and 2008667 deletions

View File

@@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2017 Ulrich-Matthias Schäfer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -1,89 +0,0 @@
# svg.resize.js
An extension of [svg.js](https://github.com/svgdotjs/svg.js) which allows to resize elements which are selected with [svg.select.js](https://github.com/svgdotjs/svg.select.js)
# Demo
For a demo see http://svgdotjs.github.io/svg.resize.js/
# Get Started
Install `svg.js`, `svg.select.js` and `svg.resize.js` using npm:
```bash
npm i @svgdotjs/svg.js @svgdotjs/svg.select.js @svgdotjs/svg.resize.js
```
Or get it from a cnd:
```html
<link rel="stylesheet" href="https://unpkg.com/@svgdotjs/svg.resize.js@latest/dist/svg.resize.css" />
<script src="https://unpkg.com/@svgdotjs/svg.js"></script>
<!-- the select plugin comes bundled with the resize plugin -->
<!-- <script src="https://unpkg.com/@svgdotjs/svg.select.js"></script> -->
<script src="https://unpkg.com/@svgdotjs/svg.resize.js"></script>
```
Select and resize a rectangle using this simple piece of code:
```ts
var canvas = new SVG().addTo('body').size(500, 500)
canvas.rect(50, 50).fill('red').select().resize()
```
# Usage
Activate resizing
```ts
rect.select().resize()
```
Deactivate resizing
```ts
rect.resize(false)
```
Preserve aspect ratio, resize around center and snap to grid:
```ts
rect.resize({ preserveAspectRatio: true, aroundCenter: true, grid: 10, degree: 0.1 })
```
# Options
- `preserveAspectRatio`: Preserve the aspect ratio of the element while resizing
- `aroundCenter`: Resize around the center of the element
- `grid`: Snaps the shape to a virtual grid while resizing
- `degree`: Snaps to an angle when rotating
# Events
While resizing, a `resize` event is fired. It contains the following properties (in `event.detail`):
- `box`: The resulting bounding box after the resize operation
- `angle`: The resulting rotation angle after the resize operation
- `eventType`: The type of resize operation (the event fired by the select plugin)
- `event`: The original event
- `handler`: The resize handler
```ts
rect.on('resize', (event) => {
console.log(event.detail)
})
```
# Contributing
```bash
git clone https://github.com/svgdotjs/svg.resize.js.git
cd svg.resize.js
npm install
npm run dev
```
# Migration from svg.js v2
- The option naming changed a bit. Please double check
- The former events were removed. The resize event now serves the same purpose

View File

@@ -1 +0,0 @@
.svg_select_shape{stroke-width:1;stroke-dasharray:10 10;stroke:#000;stroke-opacity:.1;pointer-events:none;fill:none}.svg_select_shape_pointSelect{stroke-width:1;fill:none;stroke-dasharray:10 10;stroke:#000;stroke-opacity:.8;pointer-events:none}.svg_select_handle{stroke-width:3;stroke:#000;fill:none}.svg_select_handle_rot{fill:#fff;stroke:#000;stroke-width:1;cursor:move}.svg_select_handle_lt{cursor:nw-resize}.svg_select_handle_rt{cursor:ne-resize}.svg_select_handle_rb{cursor:se-resize}.svg_select_handle_lb{cursor:sw-resize}.svg_select_handle_t{cursor:n-resize}.svg_select_handle_r{cursor:e-resize}.svg_select_handle_b{cursor:s-resize}.svg_select_handle_l{cursor:w-resize}.svg_select_handle_point{stroke:#000;stroke-width:1;cursor:move;fill:#fff}

View File

@@ -1,3 +0,0 @@
/*! @svgdotjs/svg.resize.js v2.0.5 MIT*/;
this.svg=this.svg||{},this.svg.resize=this.svg.resize||{},this.svg.resize.js=function(e,t,i){"use strict";const s=e=>(e.changedTouches&&(e=e.changedTouches[0]),{x:e.clientX,y:e.clientY}),h=e=>{let t=1/0,s=1/0,h=-1/0,n=-1/0;for(let i=0;i<e.length;i++){const o=e[i];t=Math.min(t,o[0]),s=Math.min(s,o[1]),h=Math.max(h,o[0]),n=Math.max(n,o[1])}return new i.Box(t,s,h-t,n-s)};class n{constructor(e){this.el=e,e.remember("_ResizeHandler",this),this.lastCoordinates=null,this.eventType="",this.lastEvent=null,this.handleResize=this.handleResize.bind(this),this.resize=this.resize.bind(this),this.endResize=this.endResize.bind(this),this.rotate=this.rotate.bind(this),this.movePoint=this.movePoint.bind(this)}active(e,t){this.preserveAspectRatio=t.preserveAspectRatio??!1,this.aroundCenter=t.aroundCenter??!1,this.grid=t.grid??0,this.degree=t.degree??0,this.el.off(".resize"),e&&(this.el.on(["lt.resize","rt.resize","rb.resize","lb.resize","t.resize","r.resize","b.resize","l.resize","rot.resize","point.resize"],this.handleResize),this.lastEvent&&("rot"===this.eventType?this.rotate(this.lastEvent):"point"===this.eventType?this.movePoint(this.lastEvent):this.resize(this.lastEvent)))}handleResize(e){this.eventType=e.type;const{event:t,index:h,points:n}=e.detail,o=!t.type.indexOf("mouse");if(o&&1!==(t.which||t.buttons))return;if(this.el.dispatch("beforeresize",{event:e,handler:this}).defaultPrevented)return;this.box=this.el.bbox(),this.startPoint=this.el.point(s(t)),this.index=h,this.points=n.slice();const r=(o?"mousemove":"touchmove")+".resize",a=(o?"mouseup":"touchcancel.resize touchend")+".resize";"point"===e.type?i.on(window,r,this.movePoint):"rot"===e.type?i.on(window,r,this.rotate):i.on(window,r,this.resize),i.on(window,a,this.endResize)}resize(e){this.lastEvent=e;const t=this.snapToGrid(this.el.point(s(e)));let n=t.x-this.startPoint.x,o=t.y-this.startPoint.y;this.preserveAspectRatio&&this.aroundCenter&&(n*=2,o*=2);const r=this.box.x+n,a=this.box.y+o,l=this.box.x2+n,d=this.box.y2+o;let x=new i.Box(this.box);if(this.eventType.includes("l")&&(x.x=Math.min(r,this.box.x2),x.x2=Math.max(r,this.box.x2)),this.eventType.includes("r")&&(x.x=Math.min(l,this.box.x),x.x2=Math.max(l,this.box.x)),this.eventType.includes("t")&&(x.y=Math.min(a,this.box.y2),x.y2=Math.max(a,this.box.y2)),this.eventType.includes("b")&&(x.y=Math.min(d,this.box.y),x.y2=Math.max(d,this.box.y)),x.width=x.x2-x.x,x.height=x.y2-x.y,this.preserveAspectRatio){const e=x.width/this.box.width,t=x.height/this.box.height,i=["lt","t","rt","r","rb","b","lb","l"],s=(i.indexOf(this.eventType)+4)%i.length,n=this.aroundCenter?[this.box.cx,this.box.cy]:this.points[s];let o=this.eventType.includes("t")||this.eventType.includes("b")?t:e;o=2===this.eventType.length?Math.max(e,t):o,x=function(e,t,i){const s=[[e.x,e.y],[e.x+e.width,e.y],[e.x+e.width,e.y+e.height],[e.x,e.y+e.height]].map((([e,s])=>{const h=e-t[0],n=(s-t[1])*i;return[h*i+t[0],n+t[1]]}));return h(s)}(this.box,n,o)}this.el.dispatch("resize",{box:new i.Box(x),angle:0,eventType:this.eventType,event:e,handler:this}).defaultPrevented||this.el.size(x.width,x.height).move(x.x,x.y)}movePoint(e){this.lastEvent=e;const{x:t,y:i}=this.snapToGrid(this.el.point(s(e))),n=this.el.array().slice();n[this.index]=[t,i],this.el.dispatch("resize",{box:h(n),angle:0,eventType:this.eventType,event:e,handler:this}).defaultPrevented||this.el.plot(n)}rotate(e){this.lastEvent=e;const t=this.startPoint,h=this.el.point(s(e)),{cx:n,cy:o}=this.box,r=t.x-n,a=t.y-o,l=h.x-n,d=h.y-o,x=Math.sqrt(r*r+a*a)*Math.sqrt(l*l+d*d);if(0===x)return;let p=Math.acos((r*l+a*d)/x)/Math.PI*180;if(!p)return;h.x<t.x&&(p=-p);const v=new i.Matrix(this.el),{x:c,y:y}=new i.Point(n,o).transformO(v),{rotate:u}=v.decompose(),b=this.snapToAngle(u+p)-u;this.el.dispatch("resize",{box:this.box,angle:b,eventType:this.eventType,event:e,handler:this}).defaultPrevented||this.el.transform(v.rotateO(b,c,y))}endResize(e){"rot"!==this.eventType&&"point"!==this.eventType&&this.resize(e),this.lastEvent=null,this.eventType="",i.off(window,"mousemove.resize touchmove.resize"),i.off(window,"mouseup.resize touchend.resize")}snapToGrid(e){return this.grid&&(e.x=Math.round(e.x/this.grid)*this.grid,e.y=Math.round(e.y/this.grid)*this.grid),e}snapToAngle(e){return this.degree&&(e=Math.round(e/this.degree)*this.degree),e}}return i.extend(i.Element,{resize:function(e=!0,t={}){"object"==typeof e&&(t=e,e=!0);let i=this.remember("_ResizeHandler");return i||(e.prototype instanceof n?(i=new e(this),e=!0):i=new n(this),this.remember("_resizeHandler",i)),i.active(e,t),this}}),e.ResizeHandler=n,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),e}({},0,SVG);
//# sourceMappingURL=svg.resize.iife.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1,270 +0,0 @@
/*!
* @svgdotjs/svg.resize.js - An extension for svg.js which allows to resize elements which are selected
* @version 2.0.5
* https://github.com/svgdotjs/svg.resize.js
*
* @copyright [object Object]
* @license MIT
*
* BUILT: Wed Nov 20 2024 23:15:57 GMT+0100 (Central European Standard Time)
*/
;
import "@svgdotjs/svg.select.js";
import { on, Box, Matrix, Point, off, extend, Element } from "@svgdotjs/svg.js";
const getCoordsFromEvent = (ev) => {
if (ev.changedTouches) {
ev = ev.changedTouches[0];
}
return { x: ev.clientX, y: ev.clientY };
};
const maxBoxFromPoints = (points) => {
let x = Infinity;
let y = Infinity;
let x2 = -Infinity;
let y2 = -Infinity;
for (let i = 0; i < points.length; i++) {
const p = points[i];
x = Math.min(x, p[0]);
y = Math.min(y, p[1]);
x2 = Math.max(x2, p[0]);
y2 = Math.max(y2, p[1]);
}
return new Box(x, y, x2 - x, y2 - y);
};
function scaleBox(box, origin, scale) {
const points = [
[box.x, box.y],
[box.x + box.width, box.y],
[box.x + box.width, box.y + box.height],
[box.x, box.y + box.height]
];
const newPoints = points.map(([x, y]) => {
const translatedX = x - origin[0];
const translatedY = y - origin[1];
const scaledX = translatedX * scale;
const scaledY = translatedY * scale;
return [scaledX + origin[0], scaledY + origin[1]];
});
return maxBoxFromPoints(newPoints);
}
class ResizeHandler {
constructor(el) {
this.el = el;
el.remember("_ResizeHandler", this);
this.lastCoordinates = null;
this.eventType = "";
this.lastEvent = null;
this.handleResize = this.handleResize.bind(this);
this.resize = this.resize.bind(this);
this.endResize = this.endResize.bind(this);
this.rotate = this.rotate.bind(this);
this.movePoint = this.movePoint.bind(this);
}
active(value, options) {
this.preserveAspectRatio = options.preserveAspectRatio ?? false;
this.aroundCenter = options.aroundCenter ?? false;
this.grid = options.grid ?? 0;
this.degree = options.degree ?? 0;
this.el.off(".resize");
if (!value) return;
this.el.on(
[
"lt.resize",
"rt.resize",
"rb.resize",
"lb.resize",
"t.resize",
"r.resize",
"b.resize",
"l.resize",
"rot.resize",
"point.resize"
],
this.handleResize
);
if (this.lastEvent) {
if (this.eventType === "rot") {
this.rotate(this.lastEvent);
} else if (this.eventType === "point") {
this.movePoint(this.lastEvent);
} else {
this.resize(this.lastEvent);
}
}
}
// This is called when a user clicks on one of the resize points
handleResize(e) {
this.eventType = e.type;
const { event, index, points } = e.detail;
const isMouse = !event.type.indexOf("mouse");
if (isMouse && (event.which || event.buttons) !== 1) {
return;
}
if (this.el.dispatch("beforeresize", { event: e, handler: this }).defaultPrevented) {
return;
}
this.box = this.el.bbox();
this.startPoint = this.el.point(getCoordsFromEvent(event));
this.index = index;
this.points = points.slice();
const eventMove = (isMouse ? "mousemove" : "touchmove") + ".resize";
const eventEnd = (isMouse ? "mouseup" : "touchcancel.resize touchend") + ".resize";
if (e.type === "point") {
on(window, eventMove, this.movePoint);
} else if (e.type === "rot") {
on(window, eventMove, this.rotate);
} else {
on(window, eventMove, this.resize);
}
on(window, eventEnd, this.endResize);
}
resize(e) {
this.lastEvent = e;
const endPoint = this.snapToGrid(this.el.point(getCoordsFromEvent(e)));
let dx = endPoint.x - this.startPoint.x;
let dy = endPoint.y - this.startPoint.y;
if (this.preserveAspectRatio && this.aroundCenter) {
dx *= 2;
dy *= 2;
}
const x = this.box.x + dx;
const y = this.box.y + dy;
const x2 = this.box.x2 + dx;
const y2 = this.box.y2 + dy;
let box = new Box(this.box);
if (this.eventType.includes("l")) {
box.x = Math.min(x, this.box.x2);
box.x2 = Math.max(x, this.box.x2);
}
if (this.eventType.includes("r")) {
box.x = Math.min(x2, this.box.x);
box.x2 = Math.max(x2, this.box.x);
}
if (this.eventType.includes("t")) {
box.y = Math.min(y, this.box.y2);
box.y2 = Math.max(y, this.box.y2);
}
if (this.eventType.includes("b")) {
box.y = Math.min(y2, this.box.y);
box.y2 = Math.max(y2, this.box.y);
}
box.width = box.x2 - box.x;
box.height = box.y2 - box.y;
if (this.preserveAspectRatio) {
const scaleX = box.width / this.box.width;
const scaleY = box.height / this.box.height;
const order = ["lt", "t", "rt", "r", "rb", "b", "lb", "l"];
const origin = (order.indexOf(this.eventType) + 4) % order.length;
const constantPoint = this.aroundCenter ? [this.box.cx, this.box.cy] : this.points[origin];
let scale = this.eventType.includes("t") || this.eventType.includes("b") ? scaleY : scaleX;
scale = this.eventType.length === 2 ? Math.max(scaleX, scaleY) : scale;
box = scaleBox(this.box, constantPoint, scale);
}
if (this.el.dispatch("resize", {
box: new Box(box),
angle: 0,
eventType: this.eventType,
event: e,
handler: this
}).defaultPrevented) {
return;
}
this.el.size(box.width, box.height).move(box.x, box.y);
}
movePoint(e) {
this.lastEvent = e;
const { x, y } = this.snapToGrid(this.el.point(getCoordsFromEvent(e)));
const pointArr = this.el.array().slice();
pointArr[this.index] = [x, y];
if (this.el.dispatch("resize", {
box: maxBoxFromPoints(pointArr),
angle: 0,
eventType: this.eventType,
event: e,
handler: this
}).defaultPrevented) {
return;
}
this.el.plot(pointArr);
}
rotate(e) {
this.lastEvent = e;
const startPoint = this.startPoint;
const endPoint = this.el.point(getCoordsFromEvent(e));
const { cx, cy } = this.box;
const dx1 = startPoint.x - cx;
const dy1 = startPoint.y - cy;
const dx2 = endPoint.x - cx;
const dy2 = endPoint.y - cy;
const c = Math.sqrt(dx1 * dx1 + dy1 * dy1) * Math.sqrt(dx2 * dx2 + dy2 * dy2);
if (c === 0) {
return;
}
let angle = Math.acos((dx1 * dx2 + dy1 * dy2) / c) / Math.PI * 180;
if (!angle) return;
if (endPoint.x < startPoint.x) {
angle = -angle;
}
const matrix = new Matrix(this.el);
const { x: ox, y: oy } = new Point(cx, cy).transformO(matrix);
const { rotate } = matrix.decompose();
const resultAngle = this.snapToAngle(rotate + angle) - rotate;
if (this.el.dispatch("resize", {
box: this.box,
angle: resultAngle,
eventType: this.eventType,
event: e,
handler: this
}).defaultPrevented) {
return;
}
this.el.transform(matrix.rotateO(resultAngle, ox, oy));
}
endResize(ev) {
if (this.eventType !== "rot" && this.eventType !== "point") {
this.resize(ev);
}
this.lastEvent = null;
this.eventType = "";
off(window, "mousemove.resize touchmove.resize");
off(window, "mouseup.resize touchend.resize");
}
snapToGrid(point) {
if (this.grid) {
point.x = Math.round(point.x / this.grid) * this.grid;
point.y = Math.round(point.y / this.grid) * this.grid;
}
return point;
}
snapToAngle(angle) {
if (this.degree) {
angle = Math.round(angle / this.degree) * this.degree;
}
return angle;
}
}
extend(Element, {
// Resize element with mouse
resize: function(enabled = true, options = {}) {
if (typeof enabled === "object") {
options = enabled;
enabled = true;
}
let resizeHandler = this.remember("_ResizeHandler");
if (!resizeHandler) {
if (enabled.prototype instanceof ResizeHandler) {
resizeHandler = new enabled(this);
enabled = true;
} else {
resizeHandler = new ResizeHandler(this);
}
this.remember("_resizeHandler", resizeHandler);
}
resizeHandler.active(enabled, options);
return this;
}
});
export {
ResizeHandler
};
//# sourceMappingURL=svg.resize.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +0,0 @@
/*! @svgdotjs/svg.resize.js v2.0.5 MIT*/;
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@svgdotjs/svg.select.js"),require("@svgdotjs/svg.js")):"function"==typeof define&&define.amd?define(["exports","@svgdotjs/svg.select.js","@svgdotjs/svg.js"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).svg=e.svg||{},e.svg.resize=e.svg.resize||{},e.svg.resize.js={}),null,e.SVG)}(this,(function(e,t,i){"use strict";const s=e=>(e.changedTouches&&(e=e.changedTouches[0]),{x:e.clientX,y:e.clientY}),n=e=>{let t=1/0,s=1/0,n=-1/0,h=-1/0;for(let i=0;i<e.length;i++){const o=e[i];t=Math.min(t,o[0]),s=Math.min(s,o[1]),n=Math.max(n,o[0]),h=Math.max(h,o[1])}return new i.Box(t,s,n-t,h-s)};class h{constructor(e){this.el=e,e.remember("_ResizeHandler",this),this.lastCoordinates=null,this.eventType="",this.lastEvent=null,this.handleResize=this.handleResize.bind(this),this.resize=this.resize.bind(this),this.endResize=this.endResize.bind(this),this.rotate=this.rotate.bind(this),this.movePoint=this.movePoint.bind(this)}active(e,t){this.preserveAspectRatio=t.preserveAspectRatio??!1,this.aroundCenter=t.aroundCenter??!1,this.grid=t.grid??0,this.degree=t.degree??0,this.el.off(".resize"),e&&(this.el.on(["lt.resize","rt.resize","rb.resize","lb.resize","t.resize","r.resize","b.resize","l.resize","rot.resize","point.resize"],this.handleResize),this.lastEvent&&("rot"===this.eventType?this.rotate(this.lastEvent):"point"===this.eventType?this.movePoint(this.lastEvent):this.resize(this.lastEvent)))}handleResize(e){this.eventType=e.type;const{event:t,index:n,points:h}=e.detail,o=!t.type.indexOf("mouse");if(o&&1!==(t.which||t.buttons))return;if(this.el.dispatch("beforeresize",{event:e,handler:this}).defaultPrevented)return;this.box=this.el.bbox(),this.startPoint=this.el.point(s(t)),this.index=n,this.points=h.slice();const r=(o?"mousemove":"touchmove")+".resize",a=(o?"mouseup":"touchcancel.resize touchend")+".resize";"point"===e.type?i.on(window,r,this.movePoint):"rot"===e.type?i.on(window,r,this.rotate):i.on(window,r,this.resize),i.on(window,a,this.endResize)}resize(e){this.lastEvent=e;const t=this.snapToGrid(this.el.point(s(e)));let h=t.x-this.startPoint.x,o=t.y-this.startPoint.y;this.preserveAspectRatio&&this.aroundCenter&&(h*=2,o*=2);const r=this.box.x+h,a=this.box.y+o,d=this.box.x2+h,l=this.box.y2+o;let x=new i.Box(this.box);if(this.eventType.includes("l")&&(x.x=Math.min(r,this.box.x2),x.x2=Math.max(r,this.box.x2)),this.eventType.includes("r")&&(x.x=Math.min(d,this.box.x),x.x2=Math.max(d,this.box.x)),this.eventType.includes("t")&&(x.y=Math.min(a,this.box.y2),x.y2=Math.max(a,this.box.y2)),this.eventType.includes("b")&&(x.y=Math.min(l,this.box.y),x.y2=Math.max(l,this.box.y)),x.width=x.x2-x.x,x.height=x.y2-x.y,this.preserveAspectRatio){const e=x.width/this.box.width,t=x.height/this.box.height,i=["lt","t","rt","r","rb","b","lb","l"],s=(i.indexOf(this.eventType)+4)%i.length,h=this.aroundCenter?[this.box.cx,this.box.cy]:this.points[s];let o=this.eventType.includes("t")||this.eventType.includes("b")?t:e;o=2===this.eventType.length?Math.max(e,t):o,x=function(e,t,i){const s=[[e.x,e.y],[e.x+e.width,e.y],[e.x+e.width,e.y+e.height],[e.x,e.y+e.height]].map((([e,s])=>{const n=e-t[0],h=(s-t[1])*i;return[n*i+t[0],h+t[1]]}));return n(s)}(this.box,h,o)}this.el.dispatch("resize",{box:new i.Box(x),angle:0,eventType:this.eventType,event:e,handler:this}).defaultPrevented||this.el.size(x.width,x.height).move(x.x,x.y)}movePoint(e){this.lastEvent=e;const{x:t,y:i}=this.snapToGrid(this.el.point(s(e))),h=this.el.array().slice();h[this.index]=[t,i],this.el.dispatch("resize",{box:n(h),angle:0,eventType:this.eventType,event:e,handler:this}).defaultPrevented||this.el.plot(h)}rotate(e){this.lastEvent=e;const t=this.startPoint,n=this.el.point(s(e)),{cx:h,cy:o}=this.box,r=t.x-h,a=t.y-o,d=n.x-h,l=n.y-o,x=Math.sqrt(r*r+a*a)*Math.sqrt(d*d+l*l);if(0===x)return;let p=Math.acos((r*d+a*l)/x)/Math.PI*180;if(!p)return;n.x<t.x&&(p=-p);const v=new i.Matrix(this.el),{x:c,y:y}=new i.Point(h,o).transformO(v),{rotate:u}=v.decompose(),b=this.snapToAngle(u+p)-u;this.el.dispatch("resize",{box:this.box,angle:b,eventType:this.eventType,event:e,handler:this}).defaultPrevented||this.el.transform(v.rotateO(b,c,y))}endResize(e){"rot"!==this.eventType&&"point"!==this.eventType&&this.resize(e),this.lastEvent=null,this.eventType="",i.off(window,"mousemove.resize touchmove.resize"),i.off(window,"mouseup.resize touchend.resize")}snapToGrid(e){return this.grid&&(e.x=Math.round(e.x/this.grid)*this.grid,e.y=Math.round(e.y/this.grid)*this.grid),e}snapToAngle(e){return this.degree&&(e=Math.round(e/this.degree)*this.degree),e}}i.extend(i.Element,{resize:function(e=!0,t={}){"object"==typeof e&&(t=e,e=!0);let i=this.remember("_ResizeHandler");return i||(e.prototype instanceof h?(i=new e(this),e=!0):i=new h(this),this.remember("_resizeHandler",i)),i.active(e,t),this}}),e.ResizeHandler=h,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}));
//# sourceMappingURL=svg.resize.umd.cjs.map

File diff suppressed because one or more lines are too long

View File

@@ -1,70 +0,0 @@
{
"name": "@svgdotjs/svg.resize.js",
"version": "2.0.5",
"description": "An extension for svg.js which allows to resize elements which are selected",
"type": "module",
"keywords": [
"svg.js",
"resize",
"mouse"
],
"bugs": "https://github.com/svgdotjs/svg.resize.js/issues",
"license": "MIT",
"author": {
"name": "Ulrich-Matthias Schäfer"
},
"homepage": "https://github.com/svgdotjs/svg.resize.js",
"main": "dist/svg.resize.umd.cjs",
"unpkg": "dist/svg.resize.iife.js",
"jsdelivr": "dist/svg.resize.iife.js",
"module": "dist/svg.resize.js",
"typings": "./svg.resize.js.d.ts",
"exports": {
".": {
"import": {
"types": "./svg.resize.js.d.ts",
"default": "./dist/svg.resize.js"
},
"require": {
"types": "./svg.resize.js.d.cts",
"default": "./dist/svg.resize.umd.cjs"
},
"browser": {
"types": "./svg.resize.js.d.ts",
"default": "./dist/svg.resize.js"
}
}
},
"files": [
"/dist",
"/src",
"/svg.resize.js.d.ts"
],
"scripts": {
"dev": "vite",
"build": "tsc && prettier --write . && eslint ./src && vite build",
"zip": "zip -j dist/svg.resize.js.zip -- LICENSE README.md dist/svg.resize.iife.js dist/svg.resize.iife.js.map dist/svg.resize.js dist/svg.resize.js.map dist/svg.resize.umd.cjs dist/svg.resize.umd.cjs.map",
"prepublishOnly": "rm -rf ./dist && npm run build",
"postpublish": "npm run zip"
},
"repository": {
"type": "git",
"url": "git+https://github.com/svgdotjs/svg.resize.js.git"
},
"engines": {
"node": ">= 14.18"
},
"devDependencies": {
"@types/node": "^20.14.10",
"eslint": "^9.7.0",
"eslint-plugin-import-x": "^3.0.1",
"prettier": "^3.3.3",
"terser": "^5.31.2",
"typescript": "^5.5.3",
"vite": "^5.3.4"
},
"peerDependencies": {
"@svgdotjs/svg.js": "^3.2.4",
"@svgdotjs/svg.select.js": "^4.0.1"
}
}

View File

@@ -1,318 +0,0 @@
import { Point } from '@svgdotjs/svg.js'
import { Matrix } from '@svgdotjs/svg.js'
import { on, off, Box } from '@svgdotjs/svg.js'
const getCoordsFromEvent = (ev) => {
if (ev.changedTouches) {
ev = ev.changedTouches[0]
}
return { x: ev.clientX, y: ev.clientY }
}
const maxBoxFromPoints = (points) => {
let x = Infinity
let y = Infinity
let x2 = -Infinity
let y2 = -Infinity
for (let i = 0; i < points.length; i++) {
const p = points[i]
x = Math.min(x, p[0])
y = Math.min(y, p[1])
x2 = Math.max(x2, p[0])
y2 = Math.max(y2, p[1])
}
return new Box(x, y, x2 - x, y2 - y)
}
function scaleBox(box, origin, scale) {
const points = [
[box.x, box.y],
[box.x + box.width, box.y],
[box.x + box.width, box.y + box.height],
[box.x, box.y + box.height],
]
const newPoints = points.map(([x, y]) => {
// Translate to origin
const translatedX = x - origin[0]
const translatedY = y - origin[1]
// Scale
const scaledX = translatedX * scale
const scaledY = translatedY * scale
// Translate back
return [scaledX + origin[0], scaledY + origin[1]]
})
return maxBoxFromPoints(newPoints)
}
export class ResizeHandler {
constructor(el) {
this.el = el
el.remember('_ResizeHandler', this)
this.lastCoordinates = null
this.eventType = ''
this.lastEvent = null
this.handleResize = this.handleResize.bind(this)
this.resize = this.resize.bind(this)
this.endResize = this.endResize.bind(this)
this.rotate = this.rotate.bind(this)
this.movePoint = this.movePoint.bind(this)
}
active(value, options) {
this.preserveAspectRatio = options.preserveAspectRatio ?? false
this.aroundCenter = options.aroundCenter ?? false
this.grid = options.grid ?? 0
this.degree = options.degree ?? 0
// remove all resize events
this.el.off('.resize')
if (!value) return
this.el.on(
[
'lt.resize',
'rt.resize',
'rb.resize',
'lb.resize',
't.resize',
'r.resize',
'b.resize',
'l.resize',
'rot.resize',
'point.resize',
],
this.handleResize
)
// in case the options were changed mid-resize,
// we have to replay the last event to see the immediate effect of the option change
if (this.lastEvent) {
if (this.eventType === 'rot') {
this.rotate(this.lastEvent)
} else if (this.eventType === 'point') {
this.movePoint(this.lastEvent)
} else {
this.resize(this.lastEvent)
}
}
}
// This is called when a user clicks on one of the resize points
handleResize(e) {
this.eventType = e.type
const { event, index, points } = e.detail
const isMouse = !event.type.indexOf('mouse')
// Check for left button
if (isMouse && (event.which || event.buttons) !== 1) {
return
}
// Fire beforedrag event
if (this.el.dispatch('beforeresize', { event: e, handler: this }).defaultPrevented) {
return
}
this.box = this.el.bbox()
this.startPoint = this.el.point(getCoordsFromEvent(event))
this.index = index
this.points = points.slice()
// We consider the resize done, when a touch is canceled, too
const eventMove = (isMouse ? 'mousemove' : 'touchmove') + '.resize'
const eventEnd = (isMouse ? 'mouseup' : 'touchcancel.resize touchend') + '.resize'
if (e.type === 'point') {
on(window, eventMove, this.movePoint)
} else if (e.type === 'rot') {
on(window, eventMove, this.rotate)
} else {
on(window, eventMove, this.resize)
}
on(window, eventEnd, this.endResize)
}
resize(e) {
this.lastEvent = e
const endPoint = this.snapToGrid(this.el.point(getCoordsFromEvent(e)))
let dx = endPoint.x - this.startPoint.x
let dy = endPoint.y - this.startPoint.y
if (this.preserveAspectRatio && this.aroundCenter) {
dx *= 2
dy *= 2
}
const x = this.box.x + dx
const y = this.box.y + dy
const x2 = this.box.x2 + dx
const y2 = this.box.y2 + dy
let box = new Box(this.box)
if (this.eventType.includes('l')) {
box.x = Math.min(x, this.box.x2)
box.x2 = Math.max(x, this.box.x2)
}
if (this.eventType.includes('r')) {
box.x = Math.min(x2, this.box.x)
box.x2 = Math.max(x2, this.box.x)
}
if (this.eventType.includes('t')) {
box.y = Math.min(y, this.box.y2)
box.y2 = Math.max(y, this.box.y2)
}
if (this.eventType.includes('b')) {
box.y = Math.min(y2, this.box.y)
box.y2 = Math.max(y2, this.box.y)
}
box.width = box.x2 - box.x
box.height = box.y2 - box.y
// after figuring out the resulting box,
// we have to check if the aspect ratio should be preserved
// if so, we have to find the correct scaling factor and scale the box around a fixed point (usually the opposite of the handle)
// in case aroundCenter is active, the fixed point is the center of the box
if (this.preserveAspectRatio) {
const scaleX = box.width / this.box.width
const scaleY = box.height / this.box.height
const order = ['lt', 't', 'rt', 'r', 'rb', 'b', 'lb', 'l']
const origin = (order.indexOf(this.eventType) + 4) % order.length
const constantPoint = this.aroundCenter ? [this.box.cx, this.box.cy] : this.points[origin]
let scale = this.eventType.includes('t') || this.eventType.includes('b') ? scaleY : scaleX
scale = this.eventType.length === 2 ? Math.max(scaleX, scaleY) : scale
box = scaleBox(this.box, constantPoint, scale)
}
if (
this.el.dispatch('resize', {
box: new Box(box),
angle: 0,
eventType: this.eventType,
event: e,
handler: this,
}).defaultPrevented
) {
return
}
this.el.size(box.width, box.height).move(box.x, box.y)
}
movePoint(e) {
this.lastEvent = e
const { x, y } = this.snapToGrid(this.el.point(getCoordsFromEvent(e)))
const pointArr = this.el.array().slice()
pointArr[this.index] = [x, y]
if (
this.el.dispatch('resize', {
box: maxBoxFromPoints(pointArr),
angle: 0,
eventType: this.eventType,
event: e,
handler: this,
}).defaultPrevented
) {
return
}
this.el.plot(pointArr)
}
rotate(e) {
this.lastEvent = e
const startPoint = this.startPoint
const endPoint = this.el.point(getCoordsFromEvent(e))
const { cx, cy } = this.box
const dx1 = startPoint.x - cx
const dy1 = startPoint.y - cy
const dx2 = endPoint.x - cx
const dy2 = endPoint.y - cy
const c = Math.sqrt(dx1 * dx1 + dy1 * dy1) * Math.sqrt(dx2 * dx2 + dy2 * dy2)
if (c === 0) {
return
}
let angle = (Math.acos((dx1 * dx2 + dy1 * dy2) / c) / Math.PI) * 180
// catches 0 angle and NaN angle that are zero as well (but numerically instable)
if (!angle) return
if (endPoint.x < startPoint.x) {
angle = -angle
}
const matrix = new Matrix(this.el)
const { x: ox, y: oy } = new Point(cx, cy).transformO(matrix)
const { rotate } = matrix.decompose()
const resultAngle = this.snapToAngle(rotate + angle) - rotate
if (
this.el.dispatch('resize', {
box: this.box,
angle: resultAngle,
eventType: this.eventType,
event: e,
handler: this,
}).defaultPrevented
) {
return
}
this.el.transform(matrix.rotateO(resultAngle, ox, oy))
}
endResize(ev) {
// Unbind resize and end events to window
if (this.eventType !== 'rot' && this.eventType !== 'point') {
this.resize(ev)
}
this.lastEvent = null
this.eventType = ''
off(window, 'mousemove.resize touchmove.resize')
off(window, 'mouseup.resize touchend.resize')
}
snapToGrid(point) {
if (this.grid) {
point.x = Math.round(point.x / this.grid) * this.grid
point.y = Math.round(point.y / this.grid) * this.grid
}
return point
}
snapToAngle(angle) {
if (this.degree) {
angle = Math.round(angle / this.degree) * this.degree
}
return angle
}
}

View File

@@ -1,4 +0,0 @@
import '@svgdotjs/svg.select.js'
import '@svgdotjs/svg.select.js/src/svg.select.css'
export * from './svg.resize'

View File

@@ -1,32 +0,0 @@
import { extend, Element } from '@svgdotjs/svg.js'
import { ResizeHandler } from './ResizeHandler'
extend(Element, {
// Resize element with mouse
resize: function (enabled = true, options = {}) {
if (typeof enabled === 'object') {
options = enabled
enabled = true
}
let resizeHandler = this.remember('_ResizeHandler')
if (!resizeHandler) {
if (enabled.prototype instanceof ResizeHandler) {
/* eslint new-cap: ["error", { "newIsCap": false }] */
resizeHandler = new enabled(this)
enabled = true
} else {
resizeHandler = new ResizeHandler(this)
}
this.remember('_resizeHandler', resizeHandler)
}
resizeHandler.active(enabled, options)
return this
},
})
export { ResizeHandler }

View File

@@ -1,19 +0,0 @@
import { ResizeHandler } from './src/ResizeHandler.js'
interface ResizeOptions {
preserveAspectRatio: boolean
aroundCenter: boolean
grid: number
degree: number
}
declare module '@svgdotjs/svg.js' {
interface Element {
resize(): this
resize(enable: boolean): this
resize(options: ResizeOptions): this
resize(handler: ResizeHandler): this
resize(attr?: ResizeHandler | ResizeOptions | boolean): this
}
}