@rnacanvas/draw.svg 2.1.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CoordinateSystem.d.ts +129 -0
- package/dist/CoordinateSystem.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Represents the coordinate system of a target SVG document.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CoordinateSystem {
|
|
9
|
+
private targetSVGDoc;
|
|
10
|
+
constructor(targetSVGDoc: SVGSVGElement);
|
|
11
|
+
/**
|
|
12
|
+
* The width of the coordinate system of the target SVG document
|
|
13
|
+
* (i.e., the width of its view box).
|
|
14
|
+
*/
|
|
15
|
+
get width(): number;
|
|
16
|
+
/**
|
|
17
|
+
* The height of the coordinate system of the target SVG document
|
|
18
|
+
* (i.e., the height of its view box).
|
|
19
|
+
*/
|
|
20
|
+
get height(): number;
|
|
21
|
+
/**
|
|
22
|
+
* The minimum X coordinate of the view box of the target SVG document.
|
|
23
|
+
*/
|
|
24
|
+
get minX(): number;
|
|
25
|
+
/**
|
|
26
|
+
* The maximum X coordinate of the view box of the target SVG document.
|
|
27
|
+
*/
|
|
28
|
+
get maxX(): number;
|
|
29
|
+
/**
|
|
30
|
+
* The minimum Y coordinate of the view box of the target SVG document.
|
|
31
|
+
*/
|
|
32
|
+
get minY(): number;
|
|
33
|
+
/**
|
|
34
|
+
* The maximum Y coordinate of the view box of the target SVG document.
|
|
35
|
+
*/
|
|
36
|
+
get maxY(): number;
|
|
37
|
+
/**
|
|
38
|
+
* The width of the bounding client rect for the target SVG document.
|
|
39
|
+
*/
|
|
40
|
+
get clientWidth(): number;
|
|
41
|
+
/**
|
|
42
|
+
* The height of the bounding client rect for the target SVG document.
|
|
43
|
+
*/
|
|
44
|
+
get clientHeight(): number;
|
|
45
|
+
/**
|
|
46
|
+
* The horizontal scaling factor going from the coordinate system of the target SVG document
|
|
47
|
+
* (i.e., as defined by its view box)
|
|
48
|
+
* to the client coordinate system
|
|
49
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`).
|
|
50
|
+
*/
|
|
51
|
+
get horizontalClientScaling(): number;
|
|
52
|
+
/**
|
|
53
|
+
* The vertical scaling factor going from the coordinate system of the target SVG document
|
|
54
|
+
* (i.e., as defined by its view box)
|
|
55
|
+
* to the client coordinate system
|
|
56
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`).
|
|
57
|
+
*/
|
|
58
|
+
get verticalClientScaling(): number;
|
|
59
|
+
/**
|
|
60
|
+
* The minimum X coordinate of the bounding client rect for the target SVG document.
|
|
61
|
+
*/
|
|
62
|
+
get minClientX(): number;
|
|
63
|
+
/**
|
|
64
|
+
* The minimum Y coordinate of the bounding client rect for the target SVG document.
|
|
65
|
+
*/
|
|
66
|
+
get minClientY(): number;
|
|
67
|
+
/**
|
|
68
|
+
* Converts an X coordinate in the client coordinate system
|
|
69
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`)
|
|
70
|
+
* to the coordinate system of the target SVG document
|
|
71
|
+
* (i.e., as defined by its view box).
|
|
72
|
+
*/
|
|
73
|
+
fromClientX(clientX: number): number;
|
|
74
|
+
/**
|
|
75
|
+
* Converts a Y coordinate in the client coordinate system
|
|
76
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`)
|
|
77
|
+
* to the coordinate system of the target SVG document
|
|
78
|
+
* (i.e., as defined by its view box).
|
|
79
|
+
*/
|
|
80
|
+
fromClientY(clientY: number): number;
|
|
81
|
+
/**
|
|
82
|
+
* Converts a pair of X and Y coordinates in the client coordinate system
|
|
83
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`)
|
|
84
|
+
* to the coordinate system of the target SVG document
|
|
85
|
+
* (i.e., as defined by its view box).
|
|
86
|
+
*
|
|
87
|
+
* @returns A tuple of X and Y coordinates.
|
|
88
|
+
*/
|
|
89
|
+
fromClientCoordinates(clientX: number, clientY: number): [number, number];
|
|
90
|
+
/**
|
|
91
|
+
* Converts a point in the client coordinate system
|
|
92
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`)
|
|
93
|
+
* to the coordinate system of the target SVG document
|
|
94
|
+
* (i.e., as defined by its view box).
|
|
95
|
+
*/
|
|
96
|
+
fromClientPoint(clientPoint: Point): Point;
|
|
97
|
+
/**
|
|
98
|
+
* Converts an X coordinate in the coordinate system of the target SVG document
|
|
99
|
+
* (i.e., as defined by its view box)
|
|
100
|
+
* to the client coordinate system
|
|
101
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`).
|
|
102
|
+
*/
|
|
103
|
+
toClientX(x: number): number;
|
|
104
|
+
/**
|
|
105
|
+
* Converts a Y coordinate in the coordinate system of the target SVG document
|
|
106
|
+
* (i.e., as defined by its view box)
|
|
107
|
+
* to the client coordinate system
|
|
108
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`).
|
|
109
|
+
*/
|
|
110
|
+
toClientY(y: number): number;
|
|
111
|
+
/**
|
|
112
|
+
* Converts a pair of X and Y coordinates in the coordinate system of the target SVG document
|
|
113
|
+
* (i.e., as defined by its view box)
|
|
114
|
+
* to the client coordinate system
|
|
115
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`).
|
|
116
|
+
*
|
|
117
|
+
* @returns A tuple of client X and Y coordinates.
|
|
118
|
+
*/
|
|
119
|
+
toClientCoordinates(x: number, y: number): [number, number];
|
|
120
|
+
/**
|
|
121
|
+
* Converts a point in the coordinate system of the target SVG document
|
|
122
|
+
* (i.e., as defined by its view box)
|
|
123
|
+
* to the client coordinate system
|
|
124
|
+
* (i.e., the coordinate system used by methods such as `getBoundingClientRect`).
|
|
125
|
+
*/
|
|
126
|
+
toClientPoint(point: Point): Point;
|
|
127
|
+
}
|
|
128
|
+
export {};
|
|
129
|
+
//# sourceMappingURL=CoordinateSystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CoordinateSystem.d.ts","sourceRoot":"","sources":["../src/CoordinateSystem.ts"],"names":[],"mappings":"AAAA,KAAK,KAAK,GAAG;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF;;GAEG;AACH,qBAAa,gBAAgB;IACf,OAAO,CAAC,YAAY;gBAAZ,YAAY,EAAE,aAAa;IAE/C;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;OAGG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;;;;OAKG;IACH,IAAI,uBAAuB,IAAI,MAAM,CAEpC;IAED;;;;;OAKG;IACH,IAAI,qBAAqB,IAAI,MAAM,CAElC;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAIpC;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAIpC;;;;;;;OAOG;IACH,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAOzE;;;;;OAKG;IACH,eAAe,CAAC,WAAW,EAAE,KAAK,GAAG,KAAK;IAO1C;;;;;OAKG;IACH,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAI5B;;;;;OAKG;IACH,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM;IAI5B;;;;;;;OAOG;IACH,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAO3D;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK;CAMnC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { assignUUID } from './assignUUID';
|
|
2
2
|
export { assignUUID };
|
|
3
|
+
import { CoordinateSystem } from './CoordinateSystem';
|
|
4
|
+
export { CoordinateSystem };
|
|
3
5
|
import { Scaling } from './Scaling';
|
|
4
6
|
export { Scaling };
|
|
5
7
|
import { HorizontalClientScaling } from './HorizontalClientScaling';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["draw.svg"]=e():t["draw.svg"]=e()}(this,(()=>(()=>{"use strict";var t={d:(e,
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["draw.svg"]=e():t["draw.svg"]=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{CoordinateSystem:()=>l,HorizontalClientScaling:()=>f,Scaling:()=>p,VerticalClientScaling:()=>g,assignUUID:()=>a,bringToFront:()=>s,sendToBack:()=>h});const n={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let o;const i=new Uint8Array(16);function r(){if(!o&&(o="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!o))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return o(i)}const c=[];for(let t=0;t<256;++t)c.push((t+256).toString(16).slice(1));const u=function(t,e,o){if(n.randomUUID&&!e&&!t)return n.randomUUID();const i=(t=t||{}).random||(t.rng||r)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,e){o=o||0;for(let t=0;t<16;++t)e[o+t]=i[t];return e}return function(t,e=0){return c[t[e+0]]+c[t[e+1]]+c[t[e+2]]+c[t[e+3]]+"-"+c[t[e+4]]+c[t[e+5]]+"-"+c[t[e+6]]+c[t[e+7]]+"-"+c[t[e+8]]+c[t[e+9]]+"-"+c[t[e+10]]+c[t[e+11]]+c[t[e+12]]+c[t[e+13]]+c[t[e+14]]+c[t[e+15]]}(i)};function a(t){t.id="uuid-"+u()}var l=function(){function t(t){this.targetSVGDoc=t}return Object.defineProperty(t.prototype,"width",{get:function(){return this.targetSVGDoc.viewBox.baseVal.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this.targetSVGDoc.viewBox.baseVal.height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minX",{get:function(){return this.targetSVGDoc.viewBox.baseVal.x},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxX",{get:function(){return this.minX+this.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minY",{get:function(){return this.targetSVGDoc.viewBox.baseVal.y},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"maxY",{get:function(){return this.minY+this.height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"clientWidth",{get:function(){return this.targetSVGDoc.getBoundingClientRect().width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"clientHeight",{get:function(){return this.targetSVGDoc.getBoundingClientRect().height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"horizontalClientScaling",{get:function(){return this.clientWidth/this.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"verticalClientScaling",{get:function(){return this.clientHeight/this.height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minClientX",{get:function(){return this.targetSVGDoc.getBoundingClientRect().x},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"minClientY",{get:function(){return this.targetSVGDoc.getBoundingClientRect().y},enumerable:!1,configurable:!0}),t.prototype.fromClientX=function(t){return(t-this.minClientX)/this.horizontalClientScaling},t.prototype.fromClientY=function(t){return(t-this.minClientY)/this.verticalClientScaling},t.prototype.fromClientCoordinates=function(t,e){return[this.fromClientX(t),this.fromClientY(e)]},t.prototype.fromClientPoint=function(t){return{x:this.fromClientX(t.x),y:this.fromClientY(t.y)}},t.prototype.toClientX=function(t){return this.horizontalClientScaling*(t-this.minX)},t.prototype.toClientY=function(t){return this.verticalClientScaling*(t-this.minY)},t.prototype.toClientCoordinates=function(t,e){return[this.toClientX(t),this.toClientY(e)]},t.prototype.toClientPoint=function(t){return{x:this.toClientX(t.x),y:this.toClientY(t.y)}},t}(),p=function(){function t(t){this.targetSVGDoc=t}return t.prototype.set=function(t){var e=this.targetSVGDoc.viewBox.baseVal;this.targetSVGDoc.setAttribute("width",t*e.width+"px"),this.targetSVGDoc.setAttribute("height",t*e.height+"px")},t}(),f=function(){function t(t){this.targetSVGDoc=t}return t.prototype.get=function(){var t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.width/e.width},t}(),g=function(){function t(t){this.targetSVGDoc=t}return t.prototype.get=function(){var t=this.targetSVGDoc.getBoundingClientRect(),e=this.targetSVGDoc.viewBox.baseVal;return t.height/e.height},t}();function s(t){var e=t.parentNode;e&&e.appendChild(t)}function h(t){var e=t.parentNode;e&&e.prepend(t)}return e})()));
|