@rnacanvas/draw.floating 3.3.0 → 3.3.1

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
@@ -12,7 +12,7 @@ All exports of this package can be accessed as named imports.
12
12
 
13
13
  ```javascript
14
14
  // some example imports
15
- import { Text, Circle, Rectangle } from '@rnacanvas/draw.floating';
15
+ import { Text, Circle, Rectangle, Triangle } from '@rnacanvas/draw.floating';
16
16
  ```
17
17
 
18
18
  ## `class Text`
@@ -678,6 +678,10 @@ var rectangle = Rectangle.create();
678
678
  var savedRectangle = rectangle.serialized();
679
679
  ```
680
680
 
681
+ Throws if the ID of the rectangle is falsy.
682
+
683
+ <b>Rectangles must have an ID to be serializable.</b>
684
+
681
685
  ### `static recreate()`
682
686
 
683
687
  Recreates a saved rectangle given the parent drawing that its DOM node is in.
@@ -697,3 +701,276 @@ rectangle2.domNode === rectangle1.domNode; // true
697
701
 
698
702
  rectangle2 === rectangle1; // false
699
703
  ```
704
+
705
+ ## `class Triangle`
706
+
707
+ A triangle element.
708
+
709
+ ```javascript
710
+ var triangle = Triangle.create();
711
+
712
+ // set center coordinates
713
+ triangle.centerX = 10;
714
+ triangle.centerY = 20;
715
+
716
+ triangle.width = 15;
717
+ triangle.height = 25;
718
+
719
+ // black stroke
720
+ triangle.domNode.setAttribute('stroke', 'black');
721
+ triangle.domNode.setAttribute('stroke-width', '1');
722
+
723
+ // white filling
724
+ triangle.domNode.setAttribute('fill', 'white');
725
+ ```
726
+
727
+ ### `static create()`
728
+
729
+ Creates a new triangle from scratch.
730
+
731
+ ```javascript
732
+ var triangle = Triangle.create();
733
+ ```
734
+
735
+ The triangle will be created with a UUID
736
+ and with some default values
737
+ (e.g., width and height, stroke and fill colors).
738
+
739
+ ### `constructor()`
740
+
741
+ Constructs a new triangle instance wrapping the specified SVG path element.
742
+
743
+ ```javascript
744
+ var domNode = document.createElementNS('http://www.w3.org/2000/svg', 'path');
745
+
746
+ var triangle = new Triangle(domNode);
747
+
748
+ triangle.domNode === domNode; // true
749
+ ```
750
+
751
+ The input SVG path element is not modified in any way by this constructor.
752
+
753
+ This constructor is more meant for internal use
754
+ (e.g., when recreating saved triangle elements).
755
+
756
+ ### `readonly domNode`
757
+
758
+ The SVG path element corresponding to the triangle element.
759
+
760
+ ```javascript
761
+ var triangle = Triangle.create();
762
+
763
+ triangle.domNode instanceof SVGPathElement; // true
764
+ ```
765
+
766
+ ### `readonly id`
767
+
768
+ The ID of the triangle.
769
+
770
+ Is equal to the `id` attribute of the underlying SVG path element.
771
+
772
+ ```javascript
773
+ var triangle = Triangle.create();
774
+
775
+ triangle.domNode.setAttribute('id', 'id-12345');
776
+
777
+ triangle.id; // "id-12345"
778
+ ```
779
+
780
+ <b>All drawing elements must have a unique ID for RNAcanvas drawings to be savable
781
+ and for undo / redo functionality to work.</b>
782
+
783
+ Note that the `create()` static method already creates triangles with a UUID.
784
+
785
+ (IDs should generally not be changed after being initialized.)
786
+
787
+ ### `centerX`
788
+
789
+ Center X coordinate.
790
+
791
+ ```javascript
792
+ var triangle = Triangle.create();
793
+
794
+ triangle.centerX = 10;
795
+
796
+ // is stored under the `data-center-x` attribute
797
+ triangle.domNode.dataset.centerX; // "10"
798
+ ```
799
+
800
+ This value is stored under the `data-center-x` attribute,
801
+ which allows for watching for changes to it using mutation observers.
802
+
803
+ ### `centerY`
804
+
805
+ Center Y coordinate.
806
+
807
+ ```javascript
808
+ var triangle = Triangle.create();
809
+
810
+ triangle.centerY = 20;
811
+
812
+ // is stored under the `data-center-y` attribute
813
+ triangle.domNode.dataset.centerY; // "20"
814
+ ```
815
+
816
+ This value is stored under the `data-center-y` attribute,
817
+ which allows for watching for changes to it using mutation observers.
818
+
819
+ ### `drag()`
820
+
821
+ Move the center coordinates of a triangle by the specified X and Y amounts.
822
+
823
+ ```javascript
824
+ var triangle = Triangle.create();
825
+
826
+ triangle.centerX = 10;
827
+ triangle.centerY = 20;
828
+
829
+ triangle.drag(5, -2);
830
+
831
+ triangle.centerX; // 15
832
+ triangle.centerY; // 18
833
+ ```
834
+
835
+ ### `direction`
836
+
837
+ The direction of the triangle (in radians).
838
+
839
+ ```javascript
840
+ var triangle = Triangle.create();
841
+
842
+ // triangles are created upright by default
843
+ triangle.direction; // -Math.PI / 2
844
+
845
+ // "pointing" to the left
846
+ triangle.direction = Math.PI;
847
+
848
+ // "pointing" to the right
849
+ triangle.direction = 0;
850
+
851
+ // is stored under the `data-direction` attribute
852
+ triangle.domNode.dataset.direction; // "0"
853
+ ```
854
+
855
+ This value is stored under the `data-direction` attribute,
856
+ which allows for watching for changes to it using mutation observers.
857
+
858
+ ### `width`
859
+
860
+ The width of a triangle.
861
+
862
+ ```javascript
863
+ var triangle = Triangle.create();
864
+
865
+ triangle.width = 30;
866
+
867
+ // is stored under the `data-width` attribute
868
+ triangle.domNode.dataset.width; // "30"
869
+ ```
870
+
871
+ This value is stored under the `data-width` attribute,
872
+ which allows for watching for changes to it using mutation observers.
873
+
874
+ ### `height`
875
+
876
+ The height of a triangle.
877
+
878
+ ```javascript
879
+ var triangle = Triangle.create();
880
+
881
+ triangle.height = 50;
882
+
883
+ // is stored under the `data-height` attribute
884
+ triangle.domNode.dataset.height; // "50"
885
+ ```
886
+
887
+ This value is stored under the `data-height` attribute,
888
+ which allows for watching for changes to it using mutation observers.
889
+
890
+ ### `tailsHeight`
891
+
892
+ Controls the height between the bottom corners of a triangle
893
+ and the midpoint of its base.
894
+
895
+ A positive tails height results in a triangle appearing as a "barbed" arrow.
896
+
897
+ A negative tails height results in a triangle appearing as a diamond arrow.
898
+
899
+ ```javascript
900
+ var triangle = Triangle.create();
901
+
902
+ triangle.tailsHeight = 5;
903
+
904
+ // is stored under the `data-tails-height` attribute
905
+ triangle.domNode.dataset.tailsHeight; // "5"
906
+ ```
907
+
908
+ This value is stored under the `data-tails-height` attribute,
909
+ which allows for watching for changes to it using mutation observers.
910
+
911
+ ### `readonly bbox`
912
+
913
+ The bounding box of a triangle.
914
+
915
+ <b>Bounding boxes can only be calculated
916
+ when drawing elements have been added to the document body.</b>
917
+
918
+ ```javascript
919
+ var triangle = Triangle.create();
920
+
921
+ var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
922
+
923
+ svg.append(triangle.domNode);
924
+
925
+ // add everything to the document body
926
+ document.body.append(svg);
927
+
928
+ triangle.centerX = 0;
929
+ triangle.centerY = 0;
930
+
931
+ triangle.width = 10;
932
+ triangle.height = 20;
933
+
934
+ triangle.bbox.x; // -5
935
+ triangle.bbox.y; // -10
936
+ triangle.bbox.width; // 10
937
+ triangle.bbox.height; // 20
938
+ ```
939
+
940
+ See [Box](https://pzhaojohnson.github.io/rnacanvas.boxes/) class documentation
941
+ for a full list of bounding box methods and properties.
942
+
943
+ ### `serialized()`
944
+
945
+ Returns the serialized form of a triangle,
946
+ which is a JSON-serializable object.
947
+
948
+ ```javascript
949
+ var triangle = Triangle.create();
950
+
951
+ var savedTriangle = triangle.serialized();
952
+ ```
953
+
954
+ Throws if the ID of the triangle is falsy.
955
+
956
+ <b>Triangles must have an ID to be serializable.</b>
957
+
958
+ ### `static recreate()`
959
+
960
+ Recreates a saved triangle given the parent drawing that its DOM node is in.
961
+
962
+ ```javascript
963
+ var triangle1 = Triangle.create();
964
+
965
+ var savedTriangle = triangle1.serialized();
966
+
967
+ // an RNAcanvas drawing
968
+ parentDrawing;
969
+
970
+ var triangle2 = Triangle.recreate(savedTriangle, parentDrawing);
971
+
972
+ // share the same DOM node
973
+ triangle2.domNode === triangle1.domNode; // true
974
+
975
+ triangle2 === triangle1; // false
976
+ ```
package/dist/index.d.ts CHANGED
@@ -4,4 +4,6 @@ import { Circle } from './Circle';
4
4
  export { Circle };
5
5
  import { Rectangle } from './Rectangle';
6
6
  export { Rectangle };
7
+ import { Triangle } from './Triangle';
8
+ export { Triangle };
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,CAAC;AAEhB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,QAAQ,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.floating"]=e():t["draw.floating"]=e()}(this,()=>(()=>{var t={645(t){var e;e=()=>(()=>{var t={986(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},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={};function r(t){var e=0;return t.forEach(function(t){return e+=t}),e}function i(t){return r(t)/t.length}function n(t){t.sort(function(t,e){return t-e})}t.r(e),t.d(e,{areWithin:()=>m,average:()=>i,clamp:()=>l,degrees:()=>b,flipAway:()=>v,isBetween:()=>h,isBetweenExclusive:()=>u,isBetweenInclusive:()=>h,max:()=>d,mean:()=>i,median:()=>a,min:()=>c,normalizeAngle:()=>w,radians:()=>y,round:()=>p,sortNumbers:()=>n,sortNumbersAscending:()=>n,sortNumbersDescending:()=>f,sortedNumbers:()=>s,sortedNumbersAscending:()=>s,sortedNumbersDescending:()=>g,sum:()=>r});var o=function(t,e,r){if(r||2===arguments.length)for(var i,n=0,o=e.length;n<o;n++)!i&&n in e||(i||(i=Array.prototype.slice.call(e,0,n)),i[n]=e[n]);return t.concat(i||Array.prototype.slice.call(e))};function s(t){var e=o([],t,!0);return n(e),e}function a(t){if(0==t.length)return NaN;var e=s(t);if(e.length%2!=0)return e[Math.floor(e.length/2)];var r=e.length/2,n=r-1;return i([e[r],e[n]])}function c(t){if(0==t.length)return 1/0;var e=t[0];return t.slice(1).forEach(function(t){e=Math.min(e,t)}),e}function d(t){if(0==t.length)return-1/0;var e=t[0];return t.slice(1).forEach(function(t){e=Math.max(e,t)}),e}function h(t,e,r){return t>=e&&t<=r}function u(t,e,r){return t>e&&t<r}function l(t,e,r){return t<e?e:t>r?r:t}function m(t,e,r){return Math.abs(t-e)<=r}function f(t){n(t),t.reverse()}function g(t){var e=s(t);return e.reverse(),e}function p(t,e){return Number.parseFloat(t.toFixed(null!=e?e:0))}function b(t){return t*(180/Math.PI)}function y(t){return t*(Math.PI/180)}function w(t,e){void 0===e&&(e=-Math.PI);var r=t-e;return e+((r%=2*Math.PI)>=0?r:r+2*Math.PI)}function v(t,e){var r=(e=w(e,t))-t;return(r<Math.PI/2||r>3*Math.PI/2)&&(t+=Math.PI),t}return e})()}},e={};function r(i){var n=e[i];if(void 0!==n)return n.exports;var o=e[i]={exports:{}};return t[i].call(o.exports,o,o.exports,r),o.exports}r.d=(t,e)=>{for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{"use strict";r.r(i),r.d(i,{Box:()=>e});var t=r(986);class e{static matching(t){let{x:r,y:i,width:n,height:o}=t;return new e(r,i,n,o)}static bounding(r){let i=[...r];if(0==i.length)throw new Error("An empty collection of boxes doesn't have a bounding box.");let n=i.map(t=>e.matching(t)),o=(0,t.min)(n.map(t=>t.left)),s=(0,t.min)(n.map(t=>t.top)),a=(0,t.max)(n.map(t=>t.right))-o,c=(0,t.max)(n.map(t=>t.bottom))-s;return new e(o,s,a,c)}constructor(t,e,r,i){this.x=t,this.y=e,this.width=r,this.height=i}get centerX(){return this.minX+this.width/2}get centerY(){return this.minY+this.height/2}get minX(){return this.x}get minY(){return this.y}get maxX(){return this.minX+this.width}get maxY(){return this.minY+this.height}get top(){return this.minY}get right(){return this.maxX}get bottom(){return this.maxY}get left(){return this.minX}bounds(t){let r=e.matching(t);return this.minX<=r.minX&&this.minY<=r.minY&&this.maxX>=r.maxX&&this.maxY>=r.maxY}padded(...t){let r="number"==typeof t[0]?t[0]:"factor"in t[0]?t[0].factor*this.width:t[0].percentage/100*this.width,i="number"==typeof t[0]&&"number"==typeof t[1]?t[1]:"number"==typeof t[0]?t[0]:"factor"in t[0]?t[0].factor*this.height:t[0].percentage/100*this.height;return new e(this.x-r,this.y-i,this.width+2*r,this.height+2*i)}get periphery(){return{atAngle:t=>{let e=this.width/2,r=this.height/2,i=Math.pow(Math.pow(e,2)+Math.pow(r,2),.5),n=this.centerX+i*Math.cos(t),o=this.centerY+i*Math.sin(t),s=i;return Math.abs(this.centerX-n)>e&&(s=Math.abs(e/Math.cos(t)),s=Number.isFinite(s)?s:r),Math.abs(this.centerY-o)>r&&(s=Math.abs(r/Math.sin(t)),s=Number.isFinite(s)?s:e),{x:this.centerX+s*Math.cos(t),y:this.centerY+s*Math.sin(t)}}}}}})(),i})(),t.exports=e()},731(t){var e;e=()=>(()=>{"use strict";var t={d:(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},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,{CenterPoint:()=>d});var r,i,n,o,s,a=function(t,e,r,i,n){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?n.call(t,r):n?n.value=r:e.set(t,r),r},c=function(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)};class d{constructor(t){r.add(this),i.set(this,void 0),n.set(this,{move:[]}),o.set(this,void 0),a(this,i,t,"f"),a(this,o,new MutationObserver(()=>c(this,r,"m",s).call(this,"move")),"f"),c(this,o,"f").observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0})}get x(){let t=c(this,i,"f").getBBox();return t.x+t.width/2}set x(t){let e=this.x,r=[...c(this,i,"f").x.baseVal].map(t=>t.value);0!=r.length||r.push(0),r=r.map(r=>r+(t-e)),c(this,i,"f").setAttribute("x",r.join(", "))}get y(){let t=c(this,i,"f").getBBox();return t.y+t.height/2}set y(t){let e=this.y,r=[...c(this,i,"f").y.baseVal].map(t=>t.value);0!=r.length||r.push(0),r=r.map(r=>r+(t-e)),c(this,i,"f").setAttribute("y",r.join(", "))}addEventListener(t,e){c(this,n,"f")[t].push(e)}removeEventListener(t,e){c(this,n,"f")[t]=c(this,n,"f")[t].filter(t=>t!==e)}}return i=new WeakMap,n=new WeakMap,o=new WeakMap,r=new WeakSet,s=function(t){c(this,n,"f")[t].forEach(t=>t())},e})(),t.exports=e()},456(t){var e;e=()=>(()=>{var t={277(t){var e;e=()=>(()=>{"use strict";var t={d:(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},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,{Vector:()=>r});class r{static matching(t){let e="x"in t?t.x:t.magnitude*Math.cos(t.direction),i="y"in t?t.y:t.magnitude*Math.sin(t.direction);return new r(e,i)}constructor(t,e){this.x=t,this.y=e}[Symbol.iterator](){return[this.x,this.y].values()}get magnitude(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))}set magnitude(t){let e=this.direction;this.x=t*Math.cos(e),this.y=t*Math.sin(e)}get direction(){return Math.atan2(this.y,this.x)}set direction(t){let e=this.magnitude;this.x=e*Math.cos(t),this.y=e*Math.sin(t)}}return e})(),t.exports=e()}},e={};function r(i){var n=e[i];if(void 0!==n)return n.exports;var o=e[i]={exports:{}};return t[i].call(o.exports,o,o.exports,r),o.exports}r.d=(t,e)=>{for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{"use strict";r.r(i),r.d(i,{Point:()=>e,RelativePoint:()=>h});var t=r(277);class e{static matching(t){return new e(t.x,t.y)}constructor(t,e){this.x=t,this.y=e}[Symbol.iterator](){return[this.x,this.y].values()}displace(e){let r=t.Vector.matching(e);this.x+=r.x,this.y+=r.y}displaced(t){let r=e.matching(this);return r.displace(t),r}displacementTo(e){return new t.Vector(e.x-this.x,e.y-this.y)}displacementFrom(e){return new t.Vector(this.x-e.x,this.y-e.y)}distanceTo(t){return this.displacementTo(t).magnitude}distanceFrom(t){return this.distanceTo(t)}directionTo(t){return this.displacementTo(t).direction}directionFrom(t){return this.displacementFrom(t).direction}}var n,o,s,a,c,d=function(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)};class h{constructor(e){n.add(this),o.set(this,void 0),s.set(this,new t.Vector(0,0)),a.set(this,{move:[]}),function(t,e,r){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");e.set(t,r)}(this,o,e),e.addEventListener("move",()=>d(this,n,"m",c).call(this,"move"))}get x(){return d(this,o,"f").x+d(this,s,"f").x}set x(t){d(this,s,"f").x=t-d(this,o,"f").x,d(this,n,"m",c).call(this,"move")}get y(){return d(this,o,"f").y+d(this,s,"f").y}set y(t){d(this,s,"f").y=t-d(this,o,"f").y,d(this,n,"m",c).call(this,"move")}addEventListener(t,e){d(this,a,"f")[t].push(e)}removeEventListener(t,e){d(this,a,"f")[t]=d(this,a,"f")[t].filter(t=>t!==e)}}o=new WeakMap,s=new WeakMap,a=new WeakMap,n=new WeakSet,c=function(t){d(this,a,"f")[t].forEach(t=>t())}})(),i})(),t.exports=e()},854(t){t.exports=(()=>{"use strict";var t={d:(e,r)=>{for(var i in r)t.o(r,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:r[i]})},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={};function r(t){return"number"==typeof t}function i(t){return r(t)&&Number.isFinite(t)}function n(t){return r(t)&&!Number.isFinite(t)}function o(t){return i(t)&&t>0}function s(t){return i(t)&&t>=0}function a(t){return"string"==typeof t}function c(t){return null==t}function d(t){return"object"==typeof t&&null!==t}function h(t){return Array.isArray(t)}function u(t){return h(t)&&0==t.length}function l(t){return h(t)&&t.length>0}function m(t){return h(t)&&t.every(r)}function f(t){return m(t)&&t.length>0}function g(t){return h(t)&&t.every(i)}function p(t){return h(t)&&t.every(n)}function b(t){return h(t)&&t.every(a)}function y(t){return b(t)&&t.length>0}return t.r(e),t.d(e,{isArray:()=>h,isEmptyArray:()=>u,isFiniteNumber:()=>i,isFiniteNumbersArray:()=>g,isNonEmptyArray:()=>l,isNonEmptyNumbersArray:()=>f,isNonEmptyStringsArray:()=>y,isNonFiniteNumber:()=>n,isNonFiniteNumbersArray:()=>p,isNonNegativeFiniteNumber:()=>s,isNonNullObject:()=>d,isNullish:()=>c,isNumber:()=>r,isNumbersArray:()=>m,isPositiveFiniteNumber:()=>o,isString:()=>a,isStringsArray:()=>b}),e})()}},e={};function r(i){var n=e[i];if(void 0!==n)return n.exports;var o=e[i]={exports:{}};return t[i].call(o.exports,o,o.exports,r),o.exports}r.d=(t,e)=>{for(var i in e)r.o(e,i)&&!r.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{"use strict";r.r(i),r.d(i,{Circle:()=>l,Rectangle:()=>v,Text:()=>u});const t={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let e;const n=new Uint8Array(16),o=[];for(let t=0;t<256;++t)o.push((t+256).toString(16).slice(1));function s(t,r,i){const s=(t=t||{}).random??t.rng?.()??function(){if(!e){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");e=crypto.getRandomValues.bind(crypto)}return e(n)}();if(s.length<16)throw new Error("Random bytes length must be >= 16");if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,r){if((i=i||0)<0||i+16>r.length)throw new RangeError(`UUID byte range ${i}:${i+15} is out of buffer bounds`);for(let t=0;t<16;++t)r[i+t]=s[t];return r}return function(t,e=0){return(o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]).toLowerCase()}(s)}const a=function(e,r,i){return!t.randomUUID||r||e?s(e,r,i):t.randomUUID()};var c=r(645),d=r(731),h=r(854);class u{static create(t){let e=document.createElementNS("http://www.w3.org/2000/svg","text");return e.id="id-"+a(),e.textContent=null!=t?t:"",e.setAttribute("font-family","Arial"),e.setAttribute("font-size","9"),e.setAttribute("font-weight","700"),e.setAttribute("font-style","normal"),e.setAttribute("fill","black"),e.setAttribute("fill-opacity","1"),new u(e)}constructor(t){this.domNode=t}get id(){return this.domNode.id}get bbox(){return c.Box.matching(this.domNode.getBBox())}get centerX(){return this.bbox.centerX}set centerX(t){new d.CenterPoint(this.domNode).x=t}get centerY(){return this.bbox.centerY}set centerY(t){new d.CenterPoint(this.domNode).y=t}drag(t,e){this.centerX+=t,this.centerY+=e}serialized(){if(!this.id)throw new Error("Text element ID is falsy.");return{id:this.id}}static recreate(t,e){if(!(0,h.isNonNullObject)(t))throw new Error(`Saved text element is not an object: ${t}.`);if(!t.id)throw new Error("Saved text element ID is falsy.");if(!(0,h.isString)(t.id))throw new Error(`Saved text element ID is not a string: ${t.id}.`);let r=e.domNode.querySelector("#"+t.id);if(!r)throw new Error("Unable to find text element DOM node in parent drawing by ID.");if(!(r instanceof SVGTextElement))throw new Error(`Text element DOM node is not an SVG text element: ${r}.`);return new u(r)}}class l{static create(){let t=document.createElementNS("http://www.w3.org/2000/svg","circle");return t.id="id-"+a(),t.setAttribute("r","6"),t.setAttribute("stroke","black"),t.setAttribute("stroke-width","1"),t.setAttribute("stroke-opacity","1"),t.setAttribute("stroke-dasharray",""),t.setAttribute("stroke-linecap",""),t.setAttribute("fill","white"),t.setAttribute("fill-opacity","1"),new l(t)}constructor(t){this.domNode=t}get id(){return this.domNode.id}get centerX(){return this.domNode.cx.baseVal.value}set centerX(t){this.domNode.setAttribute("cx",`${t}`)}get centerY(){return this.domNode.cy.baseVal.value}set centerY(t){this.domNode.setAttribute("cy",`${t}`)}drag(t,e){this.centerX+=t,this.centerY+=e}serialized(){if(!this.id)throw new Error("Circle ID is falsy.");return{id:this.id}}static recreate(t,e){if(!(0,h.isNonNullObject)(t))throw new Error(`Saved circle must be an object: ${t}.`);if(!t.id)throw new Error("Saved circle ID is falsy.");if(!(0,h.isString)(t.id))throw new Error(`Saved circle ID must be a string: ${t.id}.`);let r=e.domNode.querySelector("#"+t.id);if(!r)throw new Error("Unable to find circle element DOM node by ID.");if(!(r instanceof SVGCircleElement))throw new Error(`Circle element DOM node is not an SVG circle element: ${r}.`);return new l(r)}}var m=r(456);class f{constructor(){this.centerX=0,this.centerY=0,this.direction=-Math.PI/2,this.width=0,this.height=0,this.cornerRadius=0}static matching(t){let e=new f;return e.centerX=t.centerX,e.centerY=t.centerY,e.direction=t.direction,e.width=t.width,e.height=t.height,e.cornerRadius=t.cornerRadius,e}toString(){let t=new m.Point(this.centerX,this.centerY);t.displace({magnitude:this.height/2,direction:this.direction}),t.displace({magnitude:this.width/2-this.cornerRadius,direction:this.direction+Math.PI/2});let e=`M ${t.x} ${t.y}`;return t.displace({magnitude:Math.SQRT2*this.cornerRadius,direction:this.direction+3*Math.PI/4}),e+=` A ${this.cornerRadius} ${this.cornerRadius} 90 0 1 ${t.x} ${t.y}`,t.displace({magnitude:this.height-2*this.cornerRadius,direction:this.direction+Math.PI}),e+=` L ${t.x} ${t.y}`,t.displace({magnitude:Math.SQRT2*this.cornerRadius,direction:this.direction+5*Math.PI/4}),e+=` A ${this.cornerRadius} ${this.cornerRadius} 90 0 1 ${t.x} ${t.y}`,t.displace({magnitude:this.width-2*this.cornerRadius,direction:this.direction+3*Math.PI/2}),e+=` L ${t.x} ${t.y}`,t.displace({magnitude:Math.SQRT2*this.cornerRadius,direction:this.direction+7*Math.PI/4}),e+=` A ${this.cornerRadius} ${this.cornerRadius} 90 0 1 ${t.x} ${t.y}`,t.displace({magnitude:this.height-2*this.cornerRadius,direction:this.direction}),e+=` L ${t.x} ${t.y}`,t.displace({magnitude:Math.SQRT2*this.cornerRadius,direction:this.direction+9*Math.PI/4}),e+=` A ${this.cornerRadius} ${this.cornerRadius} 90 0 1 ${t.x} ${t.y}`,e+=" Z",e}}var g,p,b,y,w=function(t,e,r,i){if("a"===r&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!i:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?i:"a"===r?i.call(t):i?i.value:e.get(t)};class v{static create(){let t=document.createElementNS("http://www.w3.org/2000/svg","path");t.id="id-"+a();let e=new v(t);return e.centerX=0,e.centerY=0,e.direction=-Math.PI/2,e.width=5.5,e.height=5.5,e.cornerRadius=0,e.domNode.setAttribute("stroke","black"),e.domNode.setAttribute("stroke-width","1"),e.domNode.setAttribute("stroke-opacity","1"),e.domNode.setAttribute("stroke-linejoin",""),e.domNode.setAttribute("stroke-dasharray",""),e.domNode.setAttribute("stroke-linecap",""),e.domNode.setAttribute("fill","white"),e.domNode.setAttribute("fill-opacity","1"),e}constructor(t){g.add(this),this.domNode=t,t.dataset.centerX||w(this,g,"m",p).call(this),t.dataset.centerY||w(this,g,"m",b).call(this)}get id(){return this.domNode.id}get centerX(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.centerX)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set centerX(t){Number.isFinite(t)?(this.domNode.dataset.centerX=`${t}`,w(this,g,"m",y).call(this)):console.error(`The specified center X coordinate is nonfinite: ${t}.`)}get centerY(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.centerY)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set centerY(t){Number.isFinite(t)?(this.domNode.dataset.centerY=`${t}`,w(this,g,"m",y).call(this)):console.error(`The specified center Y coordinate is nonfinite: ${t}.`)}drag(t,e){this.centerX+=t,this.centerY+=e}get direction(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.direction)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set direction(t){Number.isFinite(t)?(this.domNode.dataset.direction=`${t}`,w(this,g,"m",y).call(this)):console.error(`The specified direction angle is nonfinite: ${t}.`)}get width(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.width)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set width(t){Number.isFinite(t)?(this.domNode.dataset.width=`${t}`,w(this,g,"m",y).call(this)):console.error(`The specified width is nonfinite: ${t}.`)}get height(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.height)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set height(t){Number.isFinite(t)?(this.domNode.dataset.height=`${t}`,w(this,g,"m",y).call(this)):console.error(`The specified height is nonfinite: ${t}.`)}get cornerRadius(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.cornerRadius)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set cornerRadius(t){Number.isFinite(t)?(this.domNode.dataset.cornerRadius=`${t}`,w(this,g,"m",y).call(this)):console.error(`The specified corner radius is nonfinite: ${t}.`)}get bbox(){return c.Box.matching(this.domNode.getBBox())}serialized(){if(!this.id)throw new Error("Rectangle ID is falsy.");return{id:this.id}}static recreate(t,e){if(!(0,h.isNonNullObject)(t))throw new Error(`Saved rectangle is not an object: ${t}.`);if(!t.id)throw new Error("Saved rectangle ID is falsy.");if(!(0,h.isString)(t.id))throw new Error(`Saved rectangle ID is not a string: ${t.id}.`);let r=e.domNode.querySelector("#"+t.id);if(!r)throw new Error("Unable to find saved rectangle DOM node in parent drawing by ID.");if(!(r instanceof SVGPathElement))throw new Error(`DOM node found for saved rectangle is not an SVG path element: ${r}.`);let i=new v(r);return(0,h.isFiniteNumber)(t.width)&&(i.width=t.width),(0,h.isFiniteNumber)(t.height)&&(i.height=t.height),(0,h.isFiniteNumber)(t.borderRadius)&&(i.cornerRadius=t.borderRadius),(0,h.isFiniteNumber)(t.rotation)&&(i.direction=t.rotation-Math.PI/2),i}}g=new WeakSet,p=function(){let t=c.Box.matching(this.domNode.getBBox());this.domNode.dataset.centerX=`${t.centerX}`},b=function(){let t=c.Box.matching(this.domNode.getBBox());this.domNode.dataset.centerY=`${t.centerY}`},y=function(){let t=new f;t.centerX=this.centerX,t.centerY=this.centerY,t.direction=this.direction,t.width=this.width,t.height=this.height,t.cornerRadius=this.cornerRadius,this.domNode.setAttribute("d",t.toString())}})(),i})());
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.floating"]=e():t["draw.floating"]=e()}(this,()=>(()=>{var t={645(t){var e;e=()=>(()=>{var t={986(t){t.exports=(()=>{"use strict";var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},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={};function i(t){var e=0;return t.forEach(function(t){return e+=t}),e}function r(t){return i(t)/t.length}function n(t){t.sort(function(t,e){return t-e})}t.r(e),t.d(e,{areWithin:()=>m,average:()=>r,clamp:()=>l,degrees:()=>p,flipAway:()=>v,isBetween:()=>c,isBetweenExclusive:()=>u,isBetweenInclusive:()=>c,max:()=>h,mean:()=>r,median:()=>a,min:()=>d,normalizeAngle:()=>y,radians:()=>w,round:()=>b,sortNumbers:()=>n,sortNumbersAscending:()=>n,sortNumbersDescending:()=>f,sortedNumbers:()=>s,sortedNumbersAscending:()=>s,sortedNumbersDescending:()=>g,sum:()=>i});var o=function(t,e,i){if(i||2===arguments.length)for(var r,n=0,o=e.length;n<o;n++)!r&&n in e||(r||(r=Array.prototype.slice.call(e,0,n)),r[n]=e[n]);return t.concat(r||Array.prototype.slice.call(e))};function s(t){var e=o([],t,!0);return n(e),e}function a(t){if(0==t.length)return NaN;var e=s(t);if(e.length%2!=0)return e[Math.floor(e.length/2)];var i=e.length/2,n=i-1;return r([e[i],e[n]])}function d(t){if(0==t.length)return 1/0;var e=t[0];return t.slice(1).forEach(function(t){e=Math.min(e,t)}),e}function h(t){if(0==t.length)return-1/0;var e=t[0];return t.slice(1).forEach(function(t){e=Math.max(e,t)}),e}function c(t,e,i){return t>=e&&t<=i}function u(t,e,i){return t>e&&t<i}function l(t,e,i){return t<e?e:t>i?i:t}function m(t,e,i){return Math.abs(t-e)<=i}function f(t){n(t),t.reverse()}function g(t){var e=s(t);return e.reverse(),e}function b(t,e){return Number.parseFloat(t.toFixed(null!=e?e:0))}function p(t){return t*(180/Math.PI)}function w(t){return t*(Math.PI/180)}function y(t,e){void 0===e&&(e=-Math.PI);var i=t-e;return e+((i%=2*Math.PI)>=0?i:i+2*Math.PI)}function v(t,e){var i=(e=y(e,t))-t;return(i<Math.PI/2||i>3*Math.PI/2)&&(t+=Math.PI),t}return e})()}},e={};function i(r){var n=e[r];if(void 0!==n)return n.exports;var o=e[r]={exports:{}};return t[r].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{"use strict";i.r(r),i.d(r,{Box:()=>e});var t=i(986);class e{static matching(t){let{x:i,y:r,width:n,height:o}=t;return new e(i,r,n,o)}static bounding(i){let r=[...i];if(0==r.length)throw new Error("An empty collection of boxes doesn't have a bounding box.");let n=r.map(t=>e.matching(t)),o=(0,t.min)(n.map(t=>t.left)),s=(0,t.min)(n.map(t=>t.top)),a=(0,t.max)(n.map(t=>t.right))-o,d=(0,t.max)(n.map(t=>t.bottom))-s;return new e(o,s,a,d)}constructor(t,e,i,r){this.x=t,this.y=e,this.width=i,this.height=r}get centerX(){return this.minX+this.width/2}get centerY(){return this.minY+this.height/2}get minX(){return this.x}get minY(){return this.y}get maxX(){return this.minX+this.width}get maxY(){return this.minY+this.height}get top(){return this.minY}get right(){return this.maxX}get bottom(){return this.maxY}get left(){return this.minX}bounds(t){let i=e.matching(t);return this.minX<=i.minX&&this.minY<=i.minY&&this.maxX>=i.maxX&&this.maxY>=i.maxY}padded(...t){let i="number"==typeof t[0]?t[0]:"factor"in t[0]?t[0].factor*this.width:t[0].percentage/100*this.width,r="number"==typeof t[0]&&"number"==typeof t[1]?t[1]:"number"==typeof t[0]?t[0]:"factor"in t[0]?t[0].factor*this.height:t[0].percentage/100*this.height;return new e(this.x-i,this.y-r,this.width+2*i,this.height+2*r)}get periphery(){return{atAngle:t=>{let e=this.width/2,i=this.height/2,r=Math.pow(Math.pow(e,2)+Math.pow(i,2),.5),n=this.centerX+r*Math.cos(t),o=this.centerY+r*Math.sin(t),s=r;return Math.abs(this.centerX-n)>e&&(s=Math.abs(e/Math.cos(t)),s=Number.isFinite(s)?s:i),Math.abs(this.centerY-o)>i&&(s=Math.abs(i/Math.sin(t)),s=Number.isFinite(s)?s:e),{x:this.centerX+s*Math.cos(t),y:this.centerY+s*Math.sin(t)}}}}}})(),r})(),t.exports=e()},731(t){var e;e=()=>(()=>{"use strict";var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},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,{CenterPoint:()=>h});var i,r,n,o,s,a=function(t,e,i,r,n){if("m"===r)throw new TypeError("Private method is not writable");if("a"===r&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof e?t!==e||!n:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===r?n.call(t,i):n?n.value=i:e.set(t,i),i},d=function(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)};class h{constructor(t){i.add(this),r.set(this,void 0),n.set(this,{move:[]}),o.set(this,void 0),a(this,r,t,"f"),a(this,o,new MutationObserver(()=>d(this,i,"m",s).call(this,"move")),"f"),d(this,o,"f").observe(t,{attributes:!0,childList:!0,characterData:!0,subtree:!0})}get x(){let t=d(this,r,"f").getBBox();return t.x+t.width/2}set x(t){let e=this.x,i=[...d(this,r,"f").x.baseVal].map(t=>t.value);0!=i.length||i.push(0),i=i.map(i=>i+(t-e)),d(this,r,"f").setAttribute("x",i.join(", "))}get y(){let t=d(this,r,"f").getBBox();return t.y+t.height/2}set y(t){let e=this.y,i=[...d(this,r,"f").y.baseVal].map(t=>t.value);0!=i.length||i.push(0),i=i.map(i=>i+(t-e)),d(this,r,"f").setAttribute("y",i.join(", "))}addEventListener(t,e){d(this,n,"f")[t].push(e)}removeEventListener(t,e){d(this,n,"f")[t]=d(this,n,"f")[t].filter(t=>t!==e)}}return r=new WeakMap,n=new WeakMap,o=new WeakMap,i=new WeakSet,s=function(t){d(this,n,"f")[t].forEach(t=>t())},e})(),t.exports=e()},456(t){var e;e=()=>(()=>{var t={277(t){var e;e=()=>(()=>{"use strict";var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},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,{Vector:()=>i});class i{static matching(t){let e="x"in t?t.x:t.magnitude*Math.cos(t.direction),r="y"in t?t.y:t.magnitude*Math.sin(t.direction);return new i(e,r)}constructor(t,e){this.x=t,this.y=e}[Symbol.iterator](){return[this.x,this.y].values()}get magnitude(){return Math.sqrt(Math.pow(this.x,2)+Math.pow(this.y,2))}set magnitude(t){let e=this.direction;this.x=t*Math.cos(e),this.y=t*Math.sin(e)}get direction(){return Math.atan2(this.y,this.x)}set direction(t){let e=this.magnitude;this.x=e*Math.cos(t),this.y=e*Math.sin(t)}}return e})(),t.exports=e()}},e={};function i(r){var n=e[r];if(void 0!==n)return n.exports;var o=e[r]={exports:{}};return t[r].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{"use strict";i.r(r),i.d(r,{Point:()=>e,RelativePoint:()=>c});var t=i(277);class e{static matching(t){return new e(t.x,t.y)}constructor(t,e){this.x=t,this.y=e}[Symbol.iterator](){return[this.x,this.y].values()}displace(e){let i=t.Vector.matching(e);this.x+=i.x,this.y+=i.y}displaced(t){let i=e.matching(this);return i.displace(t),i}displacementTo(e){return new t.Vector(e.x-this.x,e.y-this.y)}displacementFrom(e){return new t.Vector(this.x-e.x,this.y-e.y)}distanceTo(t){return this.displacementTo(t).magnitude}distanceFrom(t){return this.distanceTo(t)}directionTo(t){return this.displacementTo(t).direction}directionFrom(t){return this.displacementFrom(t).direction}}var n,o,s,a,d,h=function(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)};class c{constructor(e){n.add(this),o.set(this,void 0),s.set(this,new t.Vector(0,0)),a.set(this,{move:[]}),function(t,e,i){if("function"==typeof e||!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");e.set(t,i)}(this,o,e),e.addEventListener("move",()=>h(this,n,"m",d).call(this,"move"))}get x(){return h(this,o,"f").x+h(this,s,"f").x}set x(t){h(this,s,"f").x=t-h(this,o,"f").x,h(this,n,"m",d).call(this,"move")}get y(){return h(this,o,"f").y+h(this,s,"f").y}set y(t){h(this,s,"f").y=t-h(this,o,"f").y,h(this,n,"m",d).call(this,"move")}addEventListener(t,e){h(this,a,"f")[t].push(e)}removeEventListener(t,e){h(this,a,"f")[t]=h(this,a,"f")[t].filter(t=>t!==e)}}o=new WeakMap,s=new WeakMap,a=new WeakMap,n=new WeakSet,d=function(t){h(this,a,"f")[t].forEach(t=>t())}})(),r})(),t.exports=e()},854(t){t.exports=(()=>{"use strict";var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},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={};function i(t){return"number"==typeof t}function r(t){return i(t)&&Number.isFinite(t)}function n(t){return i(t)&&!Number.isFinite(t)}function o(t){return r(t)&&t>0}function s(t){return r(t)&&t>=0}function a(t){return"string"==typeof t}function d(t){return null==t}function h(t){return"object"==typeof t&&null!==t}function c(t){return Array.isArray(t)}function u(t){return c(t)&&0==t.length}function l(t){return c(t)&&t.length>0}function m(t){return c(t)&&t.every(i)}function f(t){return m(t)&&t.length>0}function g(t){return c(t)&&t.every(r)}function b(t){return c(t)&&t.every(n)}function p(t){return c(t)&&t.every(a)}function w(t){return p(t)&&t.length>0}return t.r(e),t.d(e,{isArray:()=>c,isEmptyArray:()=>u,isFiniteNumber:()=>r,isFiniteNumbersArray:()=>g,isNonEmptyArray:()=>l,isNonEmptyNumbersArray:()=>f,isNonEmptyStringsArray:()=>w,isNonFiniteNumber:()=>n,isNonFiniteNumbersArray:()=>b,isNonNegativeFiniteNumber:()=>s,isNonNullObject:()=>h,isNullish:()=>d,isNumber:()=>i,isNumbersArray:()=>m,isPositiveFiniteNumber:()=>o,isString:()=>a,isStringsArray:()=>p}),e})()}},e={};function i(r){var n=e[r];if(void 0!==n)return n.exports;var o=e[r]={exports:{}};return t[r].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{"use strict";i.r(r),i.d(r,{Circle:()=>l,Rectangle:()=>v,Text:()=>u,Triangle:()=>E});const t={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let e;const n=new Uint8Array(16),o=[];for(let t=0;t<256;++t)o.push((t+256).toString(16).slice(1));function s(t,i,r){const s=(t=t||{}).random??t.rng?.()??function(){if(!e){if("undefined"==typeof crypto||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");e=crypto.getRandomValues.bind(crypto)}return e(n)}();if(s.length<16)throw new Error("Random bytes length must be >= 16");if(s[6]=15&s[6]|64,s[8]=63&s[8]|128,i){if((r=r||0)<0||r+16>i.length)throw new RangeError(`UUID byte range ${r}:${r+15} is out of buffer bounds`);for(let t=0;t<16;++t)i[r+t]=s[t];return i}return function(t,e=0){return(o[t[e+0]]+o[t[e+1]]+o[t[e+2]]+o[t[e+3]]+"-"+o[t[e+4]]+o[t[e+5]]+"-"+o[t[e+6]]+o[t[e+7]]+"-"+o[t[e+8]]+o[t[e+9]]+"-"+o[t[e+10]]+o[t[e+11]]+o[t[e+12]]+o[t[e+13]]+o[t[e+14]]+o[t[e+15]]).toLowerCase()}(s)}const a=function(e,i,r){return!t.randomUUID||i||e?s(e,i,r):t.randomUUID()};var d=i(645),h=i(731),c=i(854);class u{static create(t){let e=document.createElementNS("http://www.w3.org/2000/svg","text");return e.id="id-"+a(),e.textContent=null!=t?t:"",e.setAttribute("font-family","Arial"),e.setAttribute("font-size","9"),e.setAttribute("font-weight","700"),e.setAttribute("font-style","normal"),e.setAttribute("fill","black"),e.setAttribute("fill-opacity","1"),new u(e)}constructor(t){this.domNode=t}get id(){return this.domNode.id}get bbox(){return d.Box.matching(this.domNode.getBBox())}get centerX(){return this.bbox.centerX}set centerX(t){new h.CenterPoint(this.domNode).x=t}get centerY(){return this.bbox.centerY}set centerY(t){new h.CenterPoint(this.domNode).y=t}drag(t,e){this.centerX+=t,this.centerY+=e}serialized(){if(!this.id)throw new Error("Text element ID is falsy.");return{id:this.id}}static recreate(t,e){if(!(0,c.isNonNullObject)(t))throw new Error(`Saved text element is not an object: ${t}.`);if(!t.id)throw new Error("Saved text element ID is falsy.");if(!(0,c.isString)(t.id))throw new Error(`Saved text element ID is not a string: ${t.id}.`);let i=e.domNode.querySelector("#"+t.id);if(!i)throw new Error("Unable to find text element DOM node in parent drawing by ID.");if(!(i instanceof SVGTextElement))throw new Error(`Text element DOM node is not an SVG text element: ${i}.`);return new u(i)}}class l{static create(){let t=document.createElementNS("http://www.w3.org/2000/svg","circle");return t.id="id-"+a(),t.setAttribute("r","6"),t.setAttribute("stroke","black"),t.setAttribute("stroke-width","1"),t.setAttribute("stroke-opacity","1"),t.setAttribute("stroke-dasharray",""),t.setAttribute("stroke-linecap",""),t.setAttribute("fill","white"),t.setAttribute("fill-opacity","1"),new l(t)}constructor(t){this.domNode=t}get id(){return this.domNode.id}get centerX(){return this.domNode.cx.baseVal.value}set centerX(t){this.domNode.setAttribute("cx",`${t}`)}get centerY(){return this.domNode.cy.baseVal.value}set centerY(t){this.domNode.setAttribute("cy",`${t}`)}drag(t,e){this.centerX+=t,this.centerY+=e}serialized(){if(!this.id)throw new Error("Circle ID is falsy.");return{id:this.id}}static recreate(t,e){if(!(0,c.isNonNullObject)(t))throw new Error(`Saved circle must be an object: ${t}.`);if(!t.id)throw new Error("Saved circle ID is falsy.");if(!(0,c.isString)(t.id))throw new Error(`Saved circle ID must be a string: ${t.id}.`);let i=e.domNode.querySelector("#"+t.id);if(!i)throw new Error("Unable to find circle element DOM node by ID.");if(!(i instanceof SVGCircleElement))throw new Error(`Circle element DOM node is not an SVG circle element: ${i}.`);return new l(i)}}var m=i(456);class f{constructor(){this.centerX=0,this.centerY=0,this.direction=-Math.PI/2,this.width=0,this.height=0,this.cornerRadius=0}static matching(t){let e=new f;return e.centerX=t.centerX,e.centerY=t.centerY,e.direction=t.direction,e.width=t.width,e.height=t.height,e.cornerRadius=t.cornerRadius,e}toString(){let t=new m.Point(this.centerX,this.centerY);t.displace({magnitude:this.height/2,direction:this.direction}),t.displace({magnitude:this.width/2-this.cornerRadius,direction:this.direction+Math.PI/2});let e=`M ${t.x} ${t.y}`;return t.displace({magnitude:Math.SQRT2*this.cornerRadius,direction:this.direction+3*Math.PI/4}),e+=` A ${this.cornerRadius} ${this.cornerRadius} 90 0 1 ${t.x} ${t.y}`,t.displace({magnitude:this.height-2*this.cornerRadius,direction:this.direction+Math.PI}),e+=` L ${t.x} ${t.y}`,t.displace({magnitude:Math.SQRT2*this.cornerRadius,direction:this.direction+5*Math.PI/4}),e+=` A ${this.cornerRadius} ${this.cornerRadius} 90 0 1 ${t.x} ${t.y}`,t.displace({magnitude:this.width-2*this.cornerRadius,direction:this.direction+3*Math.PI/2}),e+=` L ${t.x} ${t.y}`,t.displace({magnitude:Math.SQRT2*this.cornerRadius,direction:this.direction+7*Math.PI/4}),e+=` A ${this.cornerRadius} ${this.cornerRadius} 90 0 1 ${t.x} ${t.y}`,t.displace({magnitude:this.height-2*this.cornerRadius,direction:this.direction}),e+=` L ${t.x} ${t.y}`,t.displace({magnitude:Math.SQRT2*this.cornerRadius,direction:this.direction+9*Math.PI/4}),e+=` A ${this.cornerRadius} ${this.cornerRadius} 90 0 1 ${t.x} ${t.y}`,e+=" Z",e}}var g,b,p,w,y=function(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)};class v{static create(){let t=document.createElementNS("http://www.w3.org/2000/svg","path");t.id="id-"+a();let e=new v(t);return e.centerX=0,e.centerY=0,e.direction=-Math.PI/2,e.width=5.5,e.height=5.5,e.cornerRadius=0,e.domNode.setAttribute("stroke","black"),e.domNode.setAttribute("stroke-width","1"),e.domNode.setAttribute("stroke-opacity","1"),e.domNode.setAttribute("stroke-linejoin",""),e.domNode.setAttribute("stroke-dasharray",""),e.domNode.setAttribute("stroke-linecap",""),e.domNode.setAttribute("fill","white"),e.domNode.setAttribute("fill-opacity","1"),e}constructor(t){g.add(this),this.domNode=t,t.dataset.centerX||y(this,g,"m",b).call(this),t.dataset.centerY||y(this,g,"m",p).call(this)}get id(){return this.domNode.id}get centerX(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.centerX)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set centerX(t){Number.isFinite(t)?(this.domNode.dataset.centerX=`${t}`,y(this,g,"m",w).call(this)):console.error(`The specified center X coordinate is nonfinite: ${t}.`)}get centerY(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.centerY)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set centerY(t){Number.isFinite(t)?(this.domNode.dataset.centerY=`${t}`,y(this,g,"m",w).call(this)):console.error(`The specified center Y coordinate is nonfinite: ${t}.`)}drag(t,e){this.centerX+=t,this.centerY+=e}get direction(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.direction)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set direction(t){Number.isFinite(t)?(this.domNode.dataset.direction=`${t}`,y(this,g,"m",w).call(this)):console.error(`The specified direction angle is nonfinite: ${t}.`)}get width(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.width)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set width(t){Number.isFinite(t)?(this.domNode.dataset.width=`${t}`,y(this,g,"m",w).call(this)):console.error(`The specified width is nonfinite: ${t}.`)}get height(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.height)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set height(t){Number.isFinite(t)?(this.domNode.dataset.height=`${t}`,y(this,g,"m",w).call(this)):console.error(`The specified height is nonfinite: ${t}.`)}get cornerRadius(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.cornerRadius)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set cornerRadius(t){Number.isFinite(t)?(this.domNode.dataset.cornerRadius=`${t}`,y(this,g,"m",w).call(this)):console.error(`The specified corner radius is nonfinite: ${t}.`)}get bbox(){return d.Box.matching(this.domNode.getBBox())}serialized(){if(!this.id)throw new Error("Rectangle ID is falsy.");return{id:this.id}}static recreate(t,e){if(!(0,c.isNonNullObject)(t))throw new Error(`Saved rectangle is not an object: ${t}.`);if(!t.id)throw new Error("Saved rectangle ID is falsy.");if(!(0,c.isString)(t.id))throw new Error(`Saved rectangle ID is not a string: ${t.id}.`);let i=e.domNode.querySelector("#"+t.id);if(!i)throw new Error("Unable to find saved rectangle DOM node in parent drawing by ID.");if(!(i instanceof SVGPathElement))throw new Error(`DOM node found for saved rectangle is not an SVG path element: ${i}.`);let r=new v(i);return(0,c.isFiniteNumber)(t.width)&&(r.width=t.width),(0,c.isFiniteNumber)(t.height)&&(r.height=t.height),(0,c.isFiniteNumber)(t.borderRadius)&&(r.cornerRadius=t.borderRadius),(0,c.isFiniteNumber)(t.rotation)&&(r.direction=t.rotation-Math.PI/2),r}}g=new WeakSet,b=function(){let t=d.Box.matching(this.domNode.getBBox());this.domNode.dataset.centerX=`${t.centerX}`},p=function(){let t=d.Box.matching(this.domNode.getBBox());this.domNode.dataset.centerY=`${t.centerY}`},w=function(){let t=new f;t.centerX=this.centerX,t.centerY=this.centerY,t.direction=this.direction,t.width=this.width,t.height=this.height,t.cornerRadius=this.cornerRadius,this.domNode.setAttribute("d",t.toString())};class N{constructor(){this.centerX=0,this.centerY=0,this.direction=-Math.PI/2,this.width=0,this.height=0,this.tailsHeight=0}static matching(t){let e=new N;return e.centerX=t.centerX,e.centerY=t.centerY,e.direction=t.direction,e.width=t.width,e.height=t.height,e.tailsHeight=t.tailsHeight,e}toString(){let t=new m.Point(this.centerX,this.centerY),e=t.displaced({magnitude:this.height/2,direction:this.direction}),i=t.displaced({magnitude:this.width/2,direction:this.direction-Math.PI/2}).displaced({magnitude:this.height/2,direction:this.direction+Math.PI}),r=t.displaced({magnitude:this.width/2,direction:this.direction+Math.PI/2}).displaced({magnitude:this.height/2,direction:this.direction+Math.PI}),n=t.displaced({magnitude:this.height/2-this.tailsHeight,direction:this.direction+Math.PI});return`M ${e.x} ${e.y} L ${r.x} ${r.y} L ${n.x} ${n.y} L ${i.x} ${i.y} Z`}}var x,M,S,$,P=function(t,e,i,r){if("a"===i&&!r)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof e?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?r:"a"===i?r.call(t):r?r.value:e.get(t)};class E{static create(){let t=document.createElementNS("http://www.w3.org/2000/svg","path");t.id="id-"+a();let e=new E(t);return e.centerX=0,e.centerY=0,e.direction=-Math.PI/2,e.width=6.5,e.height=6.5,e.tailsHeight=0,e.domNode.setAttribute("stroke","black"),e.domNode.setAttribute("stroke-width","1"),e.domNode.setAttribute("stroke-opacity","1"),e.domNode.setAttribute("stroke-linejoin",""),e.domNode.setAttribute("stroke-dasharray",""),e.domNode.setAttribute("stroke-linecap",""),e.domNode.setAttribute("fill","white"),e.domNode.setAttribute("fill-opacity","1"),e}constructor(t){x.add(this),this.domNode=t,t.dataset.centerX||P(this,x,"m",M).call(this),t.dataset.centerY||P(this,x,"m",S).call(this)}get id(){return this.domNode.id}get centerX(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.centerX)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set centerX(t){Number.isFinite(t)?(this.domNode.dataset.centerX=`${t}`,P(this,x,"m",$).call(this)):console.error(`The specified center X coordinate is nonfinite: ${t}.`)}get centerY(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.centerY)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set centerY(t){Number.isFinite(t)?(this.domNode.dataset.centerY=`${t}`,P(this,x,"m",$).call(this)):console.error(`The specified center Y coordinate is nonfinite: ${t}.`)}drag(t,e){this.centerX+=t,this.centerY+=e}get direction(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.direction)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set direction(t){Number.isFinite(t)?(this.domNode.dataset.direction=`${t}`,P(this,x,"m",$).call(this)):console.error(`The specified direction angle is nonfinite: ${t}.`)}get width(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.width)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set width(t){Number.isFinite(t)?(this.domNode.dataset.width=`${t}`,P(this,x,"m",$).call(this)):console.error(`The specified width is nonfinite: ${t}.`)}get height(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.height)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set height(t){Number.isFinite(t)?(this.domNode.dataset.height=`${t}`,P(this,x,"m",$).call(this)):console.error(`The specified height is nonfinite: ${t}.`)}get tailsHeight(){var t;let e=Number.parseFloat(null!==(t=this.domNode.dataset.tailsHeight)&&void 0!==t?t:"");return Number.isFinite(e)?e:0}set tailsHeight(t){Number.isFinite(t)?(this.domNode.dataset.tailsHeight=`${t}`,P(this,x,"m",$).call(this)):console.error(`The specified tails height is nonfinite: ${t}.`)}get bbox(){return d.Box.matching(this.domNode.getBBox())}serialized(){if(!this.id)throw new Error("Triangle ID is falsy.");return{id:this.id}}static recreate(t,e){if(!(0,c.isNonNullObject)(t))throw new Error(`Saved triangle is not an object: ${t}.`);if(!t.id)throw new Error("Saved triangle ID is falsy.");if(!(0,c.isString)(t.id))throw new Error(`Saved triangle ID is not a string: ${t.id}.`);let i=e.domNode.querySelector("#"+t.id);if(!i)throw new Error("Unable to find saved triangle DOM node in parent drawing by ID.");if(!(i instanceof SVGPathElement))throw new Error(`DOM node found for saved triangle is not an SVG path element: ${i}.`);let r=new E(i);return(0,c.isFiniteNumber)(t.width)&&(r.width=t.width),(0,c.isFiniteNumber)(t.height)&&(r.height=t.height),(0,c.isFiniteNumber)(t.tailsHeight)&&(r.tailsHeight=t.tailsHeight),(0,c.isFiniteNumber)(t.rotation)&&(r.direction=t.rotation-Math.PI/2),r}}x=new WeakSet,M=function(){let t=d.Box.matching(this.domNode.getBBox());this.domNode.dataset.centerX=`${t.centerX}`},S=function(){let t=d.Box.matching(this.domNode.getBBox());this.domNode.dataset.centerY=`${t.centerY}`},$=function(){let t=new N;t.centerX=this.centerX,t.centerY=this.centerY,t.direction=this.direction,t.width=this.width,t.height=this.height,t.tailsHeight=this.tailsHeight,this.domNode.setAttribute("d",t.toString())}})(),r})());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rnacanvas/draw.floating",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
4
4
  "description": "Draw floating elements",
5
5
  "repository": {
6
6
  "type": "git",