@rnacanvas/draw.floating 2.0.0 → 3.0.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/README.md +200 -0
- package/dist/Circle.d.ts +29 -0
- package/dist/Circle.d.ts.map +1 -0
- package/dist/Drawing.d.ts +7 -0
- package/dist/Drawing.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 +2 -1
package/README.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
With `npm`:
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @rnacanvas/draw.floating
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
# Usage
|
|
10
|
+
|
|
11
|
+
All exports of this package can be accessed as named imports.
|
|
12
|
+
|
|
13
|
+
```javascript
|
|
14
|
+
// an example import
|
|
15
|
+
import { Circle } from '@rnacanvas/draw.floating';
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## `class Circle`
|
|
19
|
+
|
|
20
|
+
A circle element.
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
var circle = Circle.create();
|
|
24
|
+
|
|
25
|
+
// set radius
|
|
26
|
+
circle.domNode.setAttribute('r', '6');
|
|
27
|
+
|
|
28
|
+
// set line color and width
|
|
29
|
+
circle.domNode.setAttribute('stroke', 'black');
|
|
30
|
+
circle.domNode.setAttribute('stroke-width', '1');
|
|
31
|
+
|
|
32
|
+
// set center coordinates
|
|
33
|
+
circle.centerX = 50;
|
|
34
|
+
circle.centerY = 10;
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### `static create()`
|
|
38
|
+
|
|
39
|
+
Creates a circle element from scratch.
|
|
40
|
+
|
|
41
|
+
Circle elements will be created with a UUID
|
|
42
|
+
and some default values (e.g., radius, line color and width, fill color).
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
var circle = Circle.create();
|
|
46
|
+
|
|
47
|
+
circle.id.length >= 36; // has a UUID
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### `constructor()`
|
|
51
|
+
|
|
52
|
+
Creates a circle element wrapping an SVG circle element.
|
|
53
|
+
|
|
54
|
+
The input SVG circle element is not modified at all during construction of a circle element.
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
var domNode = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
|
|
58
|
+
|
|
59
|
+
var circle = new Circle(domNode);
|
|
60
|
+
|
|
61
|
+
circle.domNode === domNode; // true
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This constructor is more meant for internal use
|
|
65
|
+
(e.g., when recrating saved circle elements).
|
|
66
|
+
|
|
67
|
+
### `readonly domNode`
|
|
68
|
+
|
|
69
|
+
The underlying SVG circle element corresponding to the circle element.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
var circle = Circle.create();
|
|
73
|
+
|
|
74
|
+
circle.domNode instanceof SVGCircleElement; // true
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### `readonly id`
|
|
78
|
+
|
|
79
|
+
The ID of the circle element
|
|
80
|
+
(as defined by the `id` attribute of its underlying DOM node).
|
|
81
|
+
|
|
82
|
+
```javascript
|
|
83
|
+
var circle = Circle.create();
|
|
84
|
+
|
|
85
|
+
// the `create()` static method automatically assigns a UUID
|
|
86
|
+
circle.id.length >= 36; // true
|
|
87
|
+
|
|
88
|
+
circle.domNode.getAttribute('id').length >= 36; // true
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
<b>All drawing elements must have a unique ID for RNAcanvas drawings to be savable
|
|
92
|
+
and for undo / redo functionality to work.</b>
|
|
93
|
+
|
|
94
|
+
### `centerX`
|
|
95
|
+
|
|
96
|
+
Center X coordinate.
|
|
97
|
+
|
|
98
|
+
Corresponds to the `cx` attribute of the underlying DOM node.
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
var circle = Circle.create();
|
|
102
|
+
|
|
103
|
+
circle.centerX = 23;
|
|
104
|
+
|
|
105
|
+
circle.domNode.getAttribute('cx'); // "23"
|
|
106
|
+
|
|
107
|
+
circle.domNode.setAttribute('cx', '12');
|
|
108
|
+
|
|
109
|
+
circle.centerX; // 12
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
### `centerY`
|
|
114
|
+
|
|
115
|
+
Center Y coordinate.
|
|
116
|
+
|
|
117
|
+
Corresponds to the `cy` attribute of the underlying DOM node.
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
var circle = Circle.create();
|
|
121
|
+
|
|
122
|
+
circle.centerY = -12;
|
|
123
|
+
|
|
124
|
+
circle.domNode.getAttribute('cy'); // "-12"
|
|
125
|
+
|
|
126
|
+
circle.domNode.setAttribute('cy', '22');
|
|
127
|
+
|
|
128
|
+
circle.centerY; // 22
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### `drag()`
|
|
132
|
+
|
|
133
|
+
Moves the circle element by the specified X and Y amounts.
|
|
134
|
+
|
|
135
|
+
```javascript
|
|
136
|
+
var circle = Circle.create();
|
|
137
|
+
|
|
138
|
+
circle.centerX = 10;
|
|
139
|
+
circle.centerY = 20;
|
|
140
|
+
|
|
141
|
+
circle.drag(100, 200);
|
|
142
|
+
|
|
143
|
+
circle.centerX; // 110
|
|
144
|
+
circle.centerY; // 220
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `direction`
|
|
148
|
+
|
|
149
|
+
Circle elements don't actually have a direction associated with them.
|
|
150
|
+
|
|
151
|
+
This property is included primarily for compatibilty with other interfaces within RNAcanvas
|
|
152
|
+
(e.g., those involving strung elements).
|
|
153
|
+
|
|
154
|
+
This property will always have a value of 0.
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
var circle = Circle.create();
|
|
158
|
+
|
|
159
|
+
circle.direction; // 0
|
|
160
|
+
|
|
161
|
+
circle.direction = 1;
|
|
162
|
+
|
|
163
|
+
// still zero
|
|
164
|
+
circle.direction; // 0
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### `serialized()`
|
|
168
|
+
|
|
169
|
+
Returns the serialized form of the circle element,
|
|
170
|
+
which is a JSON-serializable object.
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
var circle = Circle.create();
|
|
174
|
+
|
|
175
|
+
var savedCircle = circle.serialized();
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### `static recreate()`
|
|
179
|
+
|
|
180
|
+
Recreates a saved circle element given its JSON-serializable form
|
|
181
|
+
and the parent drawing that its DOM node is in.
|
|
182
|
+
|
|
183
|
+
```javascript
|
|
184
|
+
var circle1 = Circle.create();
|
|
185
|
+
|
|
186
|
+
// an RNAcanvas drawing
|
|
187
|
+
parentDrawing;
|
|
188
|
+
|
|
189
|
+
// add the circle element to the drawing
|
|
190
|
+
parentDrawing.domNode.append(circle1.domNode);
|
|
191
|
+
|
|
192
|
+
var savedCircle = circle1.serialized();
|
|
193
|
+
|
|
194
|
+
// recreate
|
|
195
|
+
var circle2 = Circle.create(savedCircle, parentDrawing);
|
|
196
|
+
|
|
197
|
+
circle2.domNode === circle1.domNode; // true
|
|
198
|
+
|
|
199
|
+
circle2 === circle1 // false
|
|
200
|
+
```
|
package/dist/Circle.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Drawing } from './Drawing';
|
|
2
|
+
export declare class Circle {
|
|
3
|
+
readonly domNode: SVGCircleElement;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a circle element with a UUID and other default values.
|
|
6
|
+
*/
|
|
7
|
+
static create(): Circle;
|
|
8
|
+
constructor(domNode: SVGCircleElement);
|
|
9
|
+
get id(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Center X coordinate.
|
|
12
|
+
*/
|
|
13
|
+
get centerX(): number;
|
|
14
|
+
set centerX(centerX: number);
|
|
15
|
+
/**
|
|
16
|
+
* Center Y coordinate.
|
|
17
|
+
*/
|
|
18
|
+
get centerY(): number;
|
|
19
|
+
set centerY(centerY: number);
|
|
20
|
+
drag(x: number, y: number): void;
|
|
21
|
+
serialized(): {
|
|
22
|
+
id: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Recreates a saved circle given the parent drawing that its DOM node is in.
|
|
26
|
+
*/
|
|
27
|
+
static recreate(savedCircle: unknown, parentDrawing: Drawing): Circle | never;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=Circle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Circle.d.ts","sourceRoot":"","sources":["../src/Circle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMzC,qBAAa,MAAM;IAuBL,QAAQ,CAAC,OAAO,EAAE,gBAAgB;IAtB9C;;OAEG;IACH,MAAM,CAAC,MAAM;gBAmBQ,OAAO,EAAE,gBAAgB;IAE9C,IAAI,EAAE,IAAI,MAAM,CAEf;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,OAAO,CAAC,OAAO,EAJJ,MAII,EAElB;IAED;;OAEG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,IAAI,OAAO,CAAC,OAAO,EAJJ,MAII,EAElB;IAED,IAAI,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAKhC,UAAU;;;IAUV;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK;CAqB9E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Drawing.d.ts","sourceRoot":"","sources":["../src/Drawing.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;CACjC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["draw.floating"]=t():e["draw.floating"]=t()}(this,()=>(()=>{"use strict";return{}})());
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["draw.floating"]=t():e["draw.floating"]=t()}(this,()=>(()=>{var e={854(e){e.exports=(()=>{"use strict";var e={d:(t,r)=>{for(var i in r)e.o(r,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:r[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return"number"==typeof e}function i(e){return r(e)&&Number.isFinite(e)}function n(e){return r(e)&&!Number.isFinite(e)}function o(e){return i(e)&&e>0}function s(e){return i(e)&&e>=0}function u(e){return"string"==typeof e}function c(e){return null==e}function l(e){return"object"==typeof e&&null!==e}function a(e){return Array.isArray(e)}function d(e){return a(e)&&0==e.length}function f(e){return a(e)&&e.length>0}function y(e){return a(e)&&e.every(r)}function b(e){return y(e)&&e.length>0}function m(e){return a(e)&&e.every(i)}function p(e){return a(e)&&e.every(n)}function N(e){return a(e)&&e.every(u)}function g(e){return N(e)&&e.length>0}return e.r(t),e.d(t,{isArray:()=>a,isEmptyArray:()=>d,isFiniteNumber:()=>i,isFiniteNumbersArray:()=>m,isNonEmptyArray:()=>f,isNonEmptyNumbersArray:()=>b,isNonEmptyStringsArray:()=>g,isNonFiniteNumber:()=>n,isNonFiniteNumbersArray:()=>p,isNonNegativeFiniteNumber:()=>s,isNonNullObject:()=>l,isNullish:()=>c,isNumber:()=>r,isNumbersArray:()=>y,isPositiveFiniteNumber:()=>o,isString:()=>u,isStringsArray:()=>N}),t})()}},t={};function r(i){var n=t[i];if(void 0!==n)return n.exports;var o=t[i]={exports:{}};return e[i].call(o.exports,o,o.exports,r),o.exports}r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return(()=>{"use strict";r.r(i),r.d(i,{Circle:()=>t});var e=r(854);class t{static create(){let e=document.createElementNS("http://www.w3.org/2000/svg","circle");return e.id="id-"+self.crypto.randomUUID(),e.setAttribute("r","6"),e.setAttribute("stroke","black"),e.setAttribute("stroke-width","1"),e.setAttribute("stroke-opacity","1"),e.setAttribute("stroke-dasharray",""),e.setAttribute("stroke-linecap",""),e.setAttribute("fill","white"),e.setAttribute("fill-opacity","1"),new t(e)}constructor(e){this.domNode=e}get id(){return this.domNode.id}get centerX(){return this.domNode.cx.baseVal.value}set centerX(e){this.domNode.setAttribute("cx",`${e}`)}get centerY(){return this.domNode.cy.baseVal.value}set centerY(e){this.domNode.setAttribute("cy",`${e}`)}drag(e,t){this.centerX+=e,this.centerY+=t}serialized(){if(!this.id)throw new Error("Circle ID is falsy.");return{id:this.id}}static recreate(r,i){if(!(0,e.isNonNullObject)(r))throw new Error(`Saved circle must be an object: ${r}.`);if(!r.id)throw new Error("Saved circle ID is falsy.");if(!(0,e.isString)(r.id))throw new Error(`Saved circle ID must be a string: ${r.id}.`);let n=i.domNode.querySelector("#"+r.id);if(!n)throw new Error("Unable to find circle element DOM node by ID.");if(!(n instanceof SVGCircleElement))throw new Error(`Circle element DOM node is not an SVG circle element: ${n}.`);return new t(n)}}})(),i})());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rnacanvas/draw.floating",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Draw floating elements",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"webpack-cli": "^7.0.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
+
"@rnacanvas/value-check": "^1.14.1",
|
|
32
33
|
"jquery": "^4.0.0"
|
|
33
34
|
}
|
|
34
35
|
}
|