@rnacanvas/draw.floating 2.1.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 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 CHANGED
@@ -18,11 +18,6 @@ export declare class Circle {
18
18
  get centerY(): number;
19
19
  set centerY(centerY: number);
20
20
  drag(x: number, y: number): void;
21
- /**
22
- * Circles don't have a direction (always evaluates to zero).
23
- */
24
- get direction(): number;
25
- set direction(direction: number);
26
21
  serialized(): {
27
22
  id: string;
28
23
  };
@@ -1 +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;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,SAAS,CAAC,SAAS,EAJN,MAIM,EAEtB;IAED,UAAU;;;IAUV;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,OAAO,GAAG,MAAM,GAAG,KAAK;CAqB9E"}
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"}
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,()=>(()=>{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}get direction(){return 0}set direction(e){}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})());
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": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "Draw floating elements",
5
5
  "repository": {
6
6
  "type": "git",