@rnacanvas/draw.floating 3.1.0 → 3.1.2

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 CHANGED
@@ -11,10 +11,242 @@ npm install @rnacanvas/draw.floating
11
11
  All exports of this package can be accessed as named imports.
12
12
 
13
13
  ```javascript
14
- // an example import
15
- import { Circle } from '@rnacanvas/draw.floating';
14
+ // some example imports
15
+ import { Text, Circle } from '@rnacanvas/draw.floating';
16
16
  ```
17
17
 
18
+ ## `class Text`
19
+
20
+ A text element.
21
+
22
+ ```javascript
23
+ var text = Text.create('A');
24
+
25
+ text.domNode.textContent; // "A"
26
+
27
+ // set font attributes
28
+ text.domNode.setAttribute('font-family', 'Arial');
29
+ text.domNode.setAttribute('font-size', '9');
30
+
31
+ // set color
32
+ text.domNode.setAttribute('fill', 'black');
33
+
34
+ // set center coordinates
35
+ text.centerX = 10;
36
+ text.centerY = 20;
37
+ ```
38
+
39
+ ### `static create()`
40
+
41
+ Creates a text element with specified content.
42
+
43
+ ```javascript
44
+ var text = Text.create('A');
45
+
46
+ text.domNode.textContent; // "A"
47
+ ```
48
+
49
+ This method will assign created text elements a UUID.
50
+
51
+ ```javascript
52
+ var text = Text.create('A');
53
+
54
+ // text element has a UUID
55
+ text.domNode.id.length >= 36; // true
56
+ ```
57
+
58
+ Text elements can be created with empty text content.
59
+
60
+ ```javascript
61
+ var text = Text.create();
62
+
63
+ text.domNode.textContent; // ""
64
+ ```
65
+
66
+ ### `constructor()`
67
+
68
+ Constructs a text element wrapping the specified SVG text element.
69
+
70
+ ```javascript
71
+ var domNode = document.createElementNS('http://www.w3.org/2000/svg', 'text');
72
+
73
+ var text = new Text(domNode);
74
+
75
+ text.domNode === domNode; // true
76
+ ```
77
+
78
+ The input SVG text element is not modified at all during construction of a text element.
79
+
80
+ This constructor is more meant for internal use
81
+ (e.g., when recreating saved text elements).
82
+
83
+ ### `readonly domNode`
84
+
85
+ The underlying SVG text element corresponding to a text element.
86
+
87
+ ```javascript
88
+ var domNode = document.createElementNS('http://www.w3.org/2000/svg', 'text');
89
+
90
+ var text = new Text(domNode);
91
+
92
+ text.domNode === domNode; // true
93
+ ```
94
+
95
+ ### `readonly id`
96
+
97
+ The ID of the text element.
98
+
99
+ Corresponds to the `id` attribute of the underlying SVG text element.
100
+
101
+ ```javascript
102
+ var text = Text.create('A');
103
+
104
+ text.domNode.setAttribute('id', 'id-12345');
105
+
106
+ text.id; // "id-12345"
107
+ ```
108
+
109
+ ### `readonly bbox`
110
+
111
+ The bounding box of the text element.
112
+
113
+ <b>Note that this method only works correctly if the text element has been added to the document body.</b>
114
+
115
+ Bounding box calculations in general only work when elements are part of the document body.
116
+
117
+ ```javascript
118
+ var text = Text.create('A');
119
+
120
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
121
+
122
+ svg.setAttribute('viewBox', '0 0 100 200');
123
+
124
+ svg.append(text.domNode);
125
+
126
+ document.body.append(svg);
127
+
128
+ text.centerX = 10;
129
+ text.centerY = 20;
130
+
131
+ // leftmost coordinate
132
+ text.bbox.x;
133
+
134
+ // topmost coordinate
135
+ text.bbox.y;
136
+
137
+ text.bbox.width;
138
+ text.bbox.height;
139
+ ```
140
+
141
+ See the [Box](https://pzhaojohnson.github.io/rnacanvas.draw.floating/) class
142
+ for a full list of bounding box methods and properties.
143
+
144
+ ### `centerX`
145
+
146
+ Center X coordinate.
147
+
148
+ <b>This property only works correctly when a text element has been added to the documnt body.</b>
149
+
150
+ ```javascript
151
+ var text = Text.create('A');
152
+
153
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
154
+
155
+ svg.setAttribute('viewBox', '0 0 100 200');
156
+
157
+ svg.append(text.domNode);
158
+
159
+ document.body.append(svg);
160
+
161
+ text.centerX = 25;
162
+
163
+ text.centerX; // 25
164
+ ```
165
+
166
+ ### `centerY`
167
+
168
+ Center Y coordinate.
169
+
170
+ <b>This property only works correctly when a text element has been added to the documnt body.</b>
171
+
172
+ ```javascript
173
+ var text = Text.create('A');
174
+
175
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
176
+
177
+ svg.setAttribute('viewBox', '0 0 100 200');
178
+
179
+ svg.append(text.domNode);
180
+
181
+ document.body.append(svg);
182
+
183
+ text.centerY = 50;
184
+
185
+ text.centerY; // 50
186
+ ```
187
+
188
+ ### `drag()`
189
+
190
+ Shifs a text element by the specified X and Y amounts.
191
+
192
+ ```javascript
193
+ var text = Text.create('A');
194
+
195
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
196
+
197
+ svg.setAttribute('viewBox', '0 0 100 200');
198
+
199
+ svg.append(text.domNode);
200
+
201
+ document.body.append(svg);
202
+
203
+ text.centerX = 10;
204
+ text.centerY = 20;
205
+
206
+ text.drag(70, 90);
207
+
208
+ text.centerX; // 80;
209
+ text.centerY; // 110
210
+ ```
211
+
212
+ ### `serialized()`
213
+
214
+ Returns the serialized form of a strung element,
215
+ which is a JOSN-serializable object.
216
+
217
+ ```javascript
218
+ var text = Text.create('A');
219
+
220
+ var savedText = text.serialized();
221
+ ```
222
+
223
+ ### `static recreate()`
224
+
225
+ Recreates a saved text element given the parent drawing that its DOM node is in.
226
+
227
+ ```javascript
228
+ var text1 = Text.create('A');
229
+
230
+ // an RNAcanvas drawing
231
+ var parentDrawing;
232
+
233
+ // add the text element
234
+ parentDrawing.domNode.append(text1.domNode);
235
+
236
+ var savedText = text1.serialized();
237
+
238
+ var text2 = Text.recreate(savedText, parentDrawing);
239
+
240
+ // same DOM node
241
+ text2.domNode === text1.domNode; // true
242
+
243
+ // different objects
244
+ text2 === text1; // false
245
+ ```
246
+
247
+ <b>All drawing elements in RNAcanvas must have a unique ID for drawings to be savable
248
+ and for undo / redo functionality to work.</b>
249
+
18
250
  ## `class Circle`
19
251
 
20
252
  A circle element.
@@ -49,7 +281,7 @@ circle.id.length >= 36; // has a UUID
49
281
 
50
282
  ### `constructor()`
51
283
 
52
- Creates a circle element wrapping an SVG circle element.
284
+ Constructs a circle element wrapping an SVG circle element.
53
285
 
54
286
  The input SVG circle element is not modified at all during construction of a circle element.
55
287
 
@@ -0,0 +1,16 @@
1
+ export declare class RectangleDefinition {
2
+ centerX: number;
3
+ centerY: number;
4
+ /**
5
+ * Have rectangles be upright by default.
6
+ */
7
+ direction: number;
8
+ width: number;
9
+ height: number;
10
+ cornerRadius: number;
11
+ /**
12
+ * Returns an SVG path definition.
13
+ */
14
+ toString(): string;
15
+ }
16
+ //# sourceMappingURL=RectangleDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RectangleDefinition.d.ts","sourceRoot":"","sources":["../src/RectangleDefinition.ts"],"names":[],"mappings":"AAEA,qBAAa,mBAAmB;IAC9B,OAAO,SAAK;IACZ,OAAO,SAAK;IAEZ;;OAEG;IACH,SAAS,SAAgB;IAEzB,KAAK,SAAK;IACV,MAAM,SAAK;IAEX,YAAY,SAAK;IAEjB;;OAEG;IACH,QAAQ,IAAI,MAAM;CAoEnB"}
@@ -0,0 +1,16 @@
1
+ export declare class TriangleDefinition {
2
+ centerX: number;
3
+ centerY: number;
4
+ /**
5
+ * Make triangles upright by default.
6
+ */
7
+ direction: number;
8
+ width: number;
9
+ height: number;
10
+ tailsHeight: number;
11
+ /**
12
+ * Returns an SVG path definition.
13
+ */
14
+ toString(): string;
15
+ }
16
+ //# sourceMappingURL=TriangleDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TriangleDefinition.d.ts","sourceRoot":"","sources":["../src/TriangleDefinition.ts"],"names":[],"mappings":"AAEA,qBAAa,kBAAkB;IAC7B,OAAO,SAAK;IACZ,OAAO,SAAK;IAEZ;;OAEG;IACH,SAAS,SAAgB;IAEzB,KAAK,SAAK;IACV,MAAM,SAAK;IAEX,WAAW,SAAK;IAEhB;;OAEG;IACH,QAAQ,IAAI,MAAM;CA6CnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnacanvas/draw.floating",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "Draw floating elements",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,6 +31,7 @@
31
31
  "dependencies": {
32
32
  "@rnacanvas/boxes": "^5.0.1",
33
33
  "@rnacanvas/draw.svg.text": "^1.3.0",
34
+ "@rnacanvas/points.oopified": "^2.1.0",
34
35
  "@rnacanvas/value-check": "^1.14.1",
35
36
  "jquery": "^4.0.0"
36
37
  }